summaryrefslogtreecommitdiff
path: root/libexec/bundle
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/bundle')
-rwxr-xr-xlibexec/bundle31
1 files changed, 5 insertions, 26 deletions
diff --git a/libexec/bundle b/libexec/bundle
index 1168e5a361..92387bc2cf 100755
--- a/libexec/bundle
+++ b/libexec/bundle
@@ -10,41 +10,20 @@ end
base_path = File.expand_path("../lib", __dir__)
if File.exist?(base_path)
- require_relative "../lib/bundler"
-else
- require "bundler"
+ $LOAD_PATH.unshift(base_path)
end
-# Workaround for non-activated bundler spec due to missing https://github.com/rubygems/rubygems/commit/4e306d7bcdee924b8d80ca9db6125aa59ee4e5a3
-gem "bundler", Bundler::VERSION if Gem.rubygems_version < Gem::Version.new("2.6.2")
-
-# Check if an older version of bundler is installed
-$LOAD_PATH.each do |path|
- next unless path =~ %r{/bundler-0\.(\d+)} && $1.to_i < 9
- err = String.new
- err << "Looks like you have a version of bundler that's older than 0.9.\n"
- err << "Please remove your old versions.\n"
- err << "An easy way to do this is by running `gem cleanup bundler`."
- abort(err)
-end
+require "bundler"
-if File.exist?(base_path)
- require_relative "../lib/bundler/friendly_errors"
-else
- require "bundler/friendly_errors"
-end
+require "bundler/friendly_errors"
Bundler.with_friendly_errors do
- if File.exist?(base_path)
- require_relative "../lib/bundler/cli"
- else
- require "bundler/cli"
- end
+ require "bundler/cli"
# Allow any command to use --help flag to show help for that command
help_flags = %w[--help -h]
help_flag_used = ARGV.any? {|a| help_flags.include? a }
args = help_flag_used ? Bundler::CLI.reformatted_help_args(ARGV) : ARGV
- Bundler::CLI.start(args, :debug => true)
+ Bundler::CLI.start(args, debug: true)
end
class='none' style='width: 99.9%;'/> -rw-r--r--ToDo14
-rw-r--r--array.c1590
-rw-r--r--ascii.c67
-rw-r--r--bcc32/Makefile.sub60
-rw-r--r--bcc32/README.bcc3225
-rwxr-xr-x[-rw-r--r--]bcc32/configure.bat4
-rwxr-xr-x[-rw-r--r--]bcc32/mkexports.rb39
-rw-r--r--bcc32/setup.mak16
-rw-r--r--bignum.c598
-rw-r--r--class.c323
-rw-r--r--common.mk54
-rw-r--r--compar.c42
-rw-r--r--config.sub6
-rw-r--r--configure.in352
-rw-r--r--cygwin/GNUmakefile.in6
-rw-r--r--defines.h30
-rw-r--r--dir.c318
-rw-r--r--distruby.rb59
-rwxr-xr-x[-rw-r--r--]djgpp/configure.bat0
-rw-r--r--dln.c264
-rw-r--r--dln.h6
-rw-r--r--dmyext.c2
-rw-r--r--doc/NEWS-1.8.0 (renamed from doc/NEWS)0
-rw-r--r--enum.c622
-rw-r--r--enumerator.c364
-rw-r--r--env.h54
-rw-r--r--error.c372
-rw-r--r--euc_jp.c228
-rw-r--r--eval.c5822
-rw-r--r--ext/.document6
-rw-r--r--ext/Setup6
-rw-r--r--ext/Setup.atheos5
-rw-r--r--ext/Setup.dj5
-rw-r--r--ext/Setup.emx5
-rw-r--r--ext/Setup.nt5
-rw-r--r--ext/Setup.x685
-rw-r--r--ext/Win32API/Win32API.c28
-rw-r--r--ext/Win32API/lib/win32/registry.rb2
-rw-r--r--ext/Win32API/lib/win32/resolv.rb2
-rw-r--r--ext/bigdecimal/.cvsignore1
-rw-r--r--ext/bigdecimal/bigdecimal.c145
-rw-r--r--ext/bigdecimal/extconf.rb10
-rw-r--r--ext/curses/.cvsignore1
-rw-r--r--ext/curses/curses.c220
-rw-r--r--ext/curses/extconf.rb2
-rw-r--r--ext/dbm/.cvsignore1
-rw-r--r--ext/dbm/dbm.c258
-rw-r--r--ext/digest/.cvsignore1
-rw-r--r--ext/digest/bubblebabble/.cvsignore1
-rw-r--r--ext/digest/digest.c25
-rw-r--r--ext/digest/lib/digest.rb22
-rw-r--r--ext/digest/lib/digest/hmac.rb269
-rw-r--r--ext/digest/lib/md5.rb23
-rw-r--r--ext/digest/lib/sha1.rb23
-rw-r--r--ext/digest/md5/.cvsignore1
-rw-r--r--ext/digest/rmd160/.cvsignore1
-rw-r--r--ext/digest/rmd160/rmd160ossl.c2
-rw-r--r--ext/digest/sha1/.cvsignore1
-rw-r--r--ext/digest/sha1/sha1ossl.c2
-rw-r--r--ext/digest/sha2/.cvsignore1
-rw-r--r--ext/digest/sha2/lib/sha2.rb (renamed from ext/digest/sha2/lib/digest/sha2.rb)0
-rw-r--r--ext/dl/.cvsignore2
-rw-r--r--ext/dl/cfunc.c509
-rw-r--r--ext/dl/cptr.c483
-rw-r--r--ext/dl/depend49
-rw-r--r--ext/dl/dl.c787
-rw-r--r--ext/dl/dl.def59
-rw-r--r--ext/dl/dl.h361
-rw-r--r--ext/dl/doc/dl.txt266
-rw-r--r--ext/dl/extconf.rb197
-rw-r--r--ext/dl/h2rb500
-rw-r--r--ext/dl/handle.c178
-rw-r--r--ext/dl/install.rb49
-rw-r--r--ext/dl/lib/dl/callback.rb69
-rw-r--r--ext/dl/lib/dl/cparser.rb109
-rw-r--r--ext/dl/lib/dl/func.rb141
-rw-r--r--ext/dl/lib/dl/import.rb416
-rw-r--r--ext/dl/lib/dl/pack.rb173
-rw-r--r--ext/dl/lib/dl/stack.rb140
-rw-r--r--ext/dl/lib/dl/struct.rb346
-rw-r--r--ext/dl/lib/dl/types.rb273
-rw-r--r--ext/dl/lib/dl/value.rb108
-rw-r--r--ext/dl/lib/dl/win32.rb25
-rw-r--r--ext/dl/mkcall.rb62
-rw-r--r--ext/dl/mkcallback.rb227
-rw-r--r--ext/dl/mkcbtable.rb18
-rw-r--r--ext/dl/ptr.c1058
-rw-r--r--ext/dl/sample/c++sample.C35
-rw-r--r--ext/dl/sample/c++sample.rb60
-rw-r--r--ext/dl/sample/drives.rb70
-rw-r--r--ext/dl/sample/getch.rb5
-rw-r--r--ext/dl/sample/libc.rb69
-rw-r--r--ext/dl/sample/msgbox.rb19
-rw-r--r--ext/dl/sample/msgbox2.rb18
-rw-r--r--ext/dl/sample/stream.rb87
-rw-r--r--ext/dl/sym.c993
-rw-r--r--ext/dl/test/libtest.def28
-rw-r--r--ext/dl/test/test.c247
-rw-r--r--ext/dl/test/test.rb306
-rw-r--r--ext/dl/test/test_all.rb11
-rw-r--r--ext/dl/test/test_base.rb52
-rw-r--r--ext/dl/test/test_dl2.rb111
-rw-r--r--ext/dl/test/test_func.rb62
-rw-r--r--ext/dl/test/test_import.rb154
-rw-r--r--ext/dl/test/test_win32.rb53
-rw-r--r--ext/dl/type.rb115
-rw-r--r--ext/enumerator/.cvsignore2
-rw-r--r--ext/enumerator/enumerator.c298
-rw-r--r--ext/enumerator/enumerator.txt102
-rw-r--r--ext/enumerator/extconf.rb2
-rw-r--r--ext/etc/.cvsignore1
-rw-r--r--ext/etc/etc.c75
-rw-r--r--ext/etc/extconf.rb4
-rw-r--r--ext/extmk.rb113
-rw-r--r--ext/fcntl/.cvsignore1
-rw-r--r--ext/gdbm/.cvsignore1
-rw-r--r--ext/gdbm/gdbm.c410
-rw-r--r--ext/iconv/.cvsignore1
-rw-r--r--ext/iconv/charset_alias.rb4
-rw-r--r--ext/iconv/extconf.rb1
-rw-r--r--ext/iconv/iconv.c631
-rw-r--r--ext/iconv/mkwrapper.rb53
-rw-r--r--ext/io/wait/.cvsignore1
-rw-r--r--ext/io/wait/wait.c97
-rw-r--r--ext/nkf/.cvsignore1
-rw-r--r--ext/nkf/lib/kconv.rb29
-rw-r--r--ext/nkf/nkf-utf8/nkf.c313
-rw-r--r--ext/nkf/nkf-utf8/utf8tbl.c2
-rw-r--r--ext/nkf/nkf.c74
-rw-r--r--ext/openssl/extconf.rb2
-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/buffering.rb8
-rw-r--r--ext/openssl/lib/openssl/ssl.rb2
-rw-r--r--ext/openssl/openssl_missing.h4
-rw-r--r--ext/openssl/ossl.c8
-rw-r--r--ext/openssl/ossl.h14
-rw-r--r--ext/openssl/ossl_asn1.c56
-rw-r--r--ext/openssl/ossl_bio.c21
-rw-r--r--ext/openssl/ossl_bn.c16
-rw-r--r--ext/openssl/ossl_cipher.c64
-rw-r--r--ext/openssl/ossl_config.c17
-rw-r--r--ext/openssl/ossl_digest.c10
-rw-r--r--ext/openssl/ossl_engine.c10
-rw-r--r--ext/openssl/ossl_hmac.c16
-rw-r--r--ext/openssl/ossl_ns_spki.c12
-rw-r--r--ext/openssl/ossl_ocsp.c26
-rw-r--r--ext/openssl/ossl_pkcs12.c2
-rw-r--r--ext/openssl/ossl_pkcs5.h6
-rw-r--r--ext/openssl/ossl_pkcs7.c8
-rw-r--r--ext/openssl/ossl_pkey.c21
-rw-r--r--ext/openssl/ossl_pkey_dh.c16
-rw-r--r--ext/openssl/ossl_pkey_dsa.c16
-rw-r--r--ext/openssl/ossl_pkey_rsa.c35
-rw-r--r--ext/openssl/ossl_rand.c18
-rw-r--r--ext/openssl/ossl_ssl.c59
-rw-r--r--ext/openssl/ossl_x509attr.c12
-rw-r--r--ext/openssl/ossl_x509cert.c12
-rw-r--r--ext/openssl/ossl_x509crl.c16
-rw-r--r--ext/openssl/ossl_x509ext.c24
-rw-r--r--ext/openssl/ossl_x509name.c18
-rw-r--r--ext/openssl/ossl_x509req.c10
-rw-r--r--ext/openssl/ossl_x509revoked.c8
-rw-r--r--ext/openssl/ossl_x509store.c4
-rw-r--r--ext/pty/.cvsignore1
-rw-r--r--ext/pty/lib/expect.rb2
-rw-r--r--ext/pty/pty.c56
-rw-r--r--ext/purelib.rb3
-rw-r--r--ext/racc/cparse/.cvsignore1
-rw-r--r--ext/racc/cparse/README10
-rw-r--r--ext/racc/cparse/cparse.c68
-rw-r--r--ext/readline/.cvsignore1
-rw-r--r--ext/readline/extconf.rb5
-rw-r--r--ext/readline/readline.c250
-rw-r--r--ext/ripper/.cvsignore8
-rw-r--r--ext/ripper/README30
-rw-r--r--ext/ripper/depend32
-rw-r--r--ext/ripper/eventids2.c277
-rw-r--r--ext/ripper/extconf.rb20
-rw-r--r--ext/ripper/lib/ripper.rb4
-rw-r--r--ext/ripper/lib/ripper/core.rb70
-rw-r--r--ext/ripper/lib/ripper/filter.rb70
-rw-r--r--ext/ripper/lib/ripper/lexer.rb179
-rw-r--r--ext/ripper/lib/ripper/sexp.rb100
-rwxr-xr-xext/ripper/tools/generate-param-macros.rb14
-rwxr-xr-xext/ripper/tools/generate.rb152
-rwxr-xr-xext/ripper/tools/preproc.rb91
-rwxr-xr-xext/ripper/tools/strip.rb12
-rw-r--r--ext/sdbm/.cvsignore1
-rw-r--r--ext/sdbm/_sdbm.c99
-rw-r--r--ext/sdbm/init.c287
-rw-r--r--ext/socket/.cvsignore2
-rw-r--r--ext/socket/depend6
-rw-r--r--ext/socket/extconf.rb27
-rw-r--r--ext/socket/getaddrinfo.c43
-rw-r--r--ext/socket/getnameinfo.c20
-rw-r--r--ext/socket/mkconstants.rb262
-rw-r--r--ext/socket/socket.c1773
-rw-r--r--ext/stringio/.cvsignore1
-rw-r--r--ext/stringio/stringio.c297
-rw-r--r--ext/strscan/.cvsignore1
-rw-r--r--ext/strscan/depend4
-rw-r--r--ext/strscan/strscan.c98
-rw-r--r--ext/syck/.cvsignore1
-rw-r--r--ext/syck/emitter.c16
-rw-r--r--ext/syck/handler.c2
-rw-r--r--ext/syck/implicit.c2
-rw-r--r--ext/syck/node.c4
-rw-r--r--ext/syck/rubyext.c277
-rw-r--r--ext/syck/syck.c2
-rw-r--r--ext/syck/syck.h18
-rw-r--r--ext/syck/yaml2byte.c2
-rw-r--r--ext/syslog/.cvsignore1
-rw-r--r--ext/syslog/syslog.c7
-rw-r--r--ext/thread/extconf.rb9
-rw-r--r--ext/thread/lib/thread.rb5
-rw-r--r--ext/thread/thread.c1203
-rw-r--r--ext/tk/.cvsignore2
-rw-r--r--ext/tk/ChangeLog.tkextlib20
-rw-r--r--ext/tk/README.1st13
-rw-r--r--ext/tk/README.tcltklib9
-rw-r--r--ext/tk/extconf.rb7
-rw-r--r--ext/tk/lib/tk.rb5
-rw-r--r--ext/tk/lib/tk/canvas.rb6
-rw-r--r--ext/tk/lib/tk/scrollable.rb11
-rw-r--r--ext/tk/lib/tk/txtwin_abst.rb2
-rw-r--r--ext/tk/lib/tkextlib/blt/tile/checkbutton.rb4
-rw-r--r--ext/tk/lib/tkextlib/blt/tile/radiobutton.rb4
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/checkbox.rb2
-rw-r--r--ext/tk/lib/tkextlib/iwidgets/radiobox.rb2
-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/sample/images/teapot.ppm49
-rw-r--r--ext/tk/sample/irbtkw.rbw7
-rw-r--r--ext/tk/sample/tcltklib/sample2.rb2
-rw-r--r--ext/tk/sample/tktextio.rb2
-rw-r--r--ext/tk/stubs.c54
-rw-r--r--ext/tk/tcltklib.c266
-rw-r--r--ext/tk/tkutil/extconf.rb9
-rw-r--r--ext/tk/tkutil/tkutil.c229
-rw-r--r--ext/win32ole/extconf.rb1
-rw-r--r--ext/win32ole/sample/excel2.rb10
-rw-r--r--ext/win32ole/tests/testNIL2VTEMPTY.rb28
-rw-r--r--ext/win32ole/tests/testOLEMETHOD.rb92
-rw-r--r--ext/win32ole/tests/testOLEPARAM.rb65
-rw-r--r--ext/win32ole/tests/testOLETYPE.rb96
-rw-r--r--ext/win32ole/tests/testOLEVARIABLE.rb49
-rw-r--r--ext/win32ole/tests/testVARIANT.rb32
-rw-r--r--ext/win32ole/tests/testWIN32OLE.rb58
-rw-r--r--ext/win32ole/tests/test_ole_methods.rb (renamed from test/win32ole/test_ole_methods.rb)0
-rw-r--r--ext/win32ole/tests/test_propertyputref.rb19
-rw-r--r--ext/win32ole/tests/test_win32ole_event.rb (renamed from test/win32ole/test_win32ole_event.rb)56
-rw-r--r--ext/win32ole/tests/test_word.rb (renamed from test/win32ole/test_word.rb)0
-rw-r--r--ext/win32ole/tests/testall.rb14
-rw-r--r--ext/win32ole/win32ole.c2453
-rw-r--r--ext/zlib/.cvsignore1
-rw-r--r--ext/zlib/extconf.rb4
-rw-r--r--ext/zlib/zlib.c813
-rw-r--r--file.c1265
-rw-r--r--gc.c544
-rw-r--r--hash.c924
-rw-r--r--inits.c70
-rwxr-xr-x[-rw-r--r--]instruby.rb2
-rw-r--r--intern.h961
-rw-r--r--io.c3311
-rw-r--r--keywords87
-rw-r--r--lex.c227
-rw-r--r--lib/.document4
-rw-r--r--lib/README2
-rw-r--r--lib/base64.rb19
-rw-r--r--lib/benchmark.rb7
-rw-r--r--lib/cgi-lib.rb272
-rw-r--r--lib/cgi.rb150
-rw-r--r--lib/cgi/.document3
-rw-r--r--lib/cgi/session.rb59
-rw-r--r--lib/cgi/session/pstore.rb2
-rw-r--r--lib/complex.rb17
-rw-r--r--lib/csv.rb24
-rw-r--r--lib/date.rb446
-rw-r--r--lib/date/format.rb26
-rw-r--r--lib/delegate.rb205
-rw-r--r--lib/drb/acl.rb2
-rw-r--r--lib/drb/drb.rb14
-rw-r--r--lib/drb/extservm.rb7
-rw-r--r--lib/drb/invokemethod.rb2
-rw-r--r--lib/drb/observer.rb21
-rw-r--r--lib/drb/ssl.rb1
-rw-r--r--lib/drb/unix.rb2
-rw-r--r--lib/e2mmap.rb2
-rw-r--r--lib/erb.rb35
-rw-r--r--lib/fileutils.rb53
-rw-r--r--lib/find.rb4
-rw-r--r--lib/forwardable.rb138
-rw-r--r--lib/generator.rb91
-rw-r--r--lib/getoptlong.rb23
-rw-r--r--lib/getopts.rb2
-rw-r--r--lib/ipaddr.rb4
-rw-r--r--lib/irb.rb18
-rw-r--r--lib/irb/init.rb6
-rw-r--r--lib/irb/input-method.rb4
-rw-r--r--lib/irb/locale.rb6
-rw-r--r--lib/irb/ruby-lex.rb2
-rw-r--r--lib/irb/ruby-token.rb6
-rw-r--r--lib/irb/slex.rb2
-rw-r--r--lib/jcode.rb19
-rw-r--r--lib/logger.rb2
-rw-r--r--lib/mathn.rb84
-rw-r--r--lib/matrix.rb164
-rw-r--r--lib/mkmf.rb143
-rw-r--r--lib/monitor.rb31
-rw-r--r--lib/net/.document8
-rw-r--r--lib/net/ftp.rb206
-rw-r--r--lib/net/http.rb3
-rw-r--r--lib/net/https.rb6
-rw-r--r--lib/net/imap.rb318
-rw-r--r--lib/net/pop.rb215
-rw-r--r--lib/net/protocol.rb14
-rw-r--r--lib/net/smtp.rb451
-rw-r--r--lib/net/telnet.rb18
-rw-r--r--lib/observer.rb19
-rw-r--r--lib/open-uri.rb117
-rw-r--r--lib/optparse.rb46
-rw-r--r--lib/ostruct.rb7
-rw-r--r--lib/pp.rb60
-rw-r--r--lib/prettyprint.rb12
-rw-r--r--lib/profiler.rb2
-rw-r--r--lib/rational.rb7
-rw-r--r--lib/rdoc/markup/simple_markup/inline.rb4
-rw-r--r--lib/rdoc/options.rb4
-rw-r--r--lib/rdoc/parsers/parse_c.rb274
-rw-r--r--lib/rdoc/parsers/parse_rb.rb29
-rw-r--r--lib/rdoc/ri/ri_display.rb1
-rw-r--r--lib/rdoc/ri/ri_paths.rb4
-rw-r--r--lib/rdoc/ri/ri_writer.rb2
-rw-r--r--lib/resolv-replace.rb3
-rw-r--r--lib/resolv.rb1263
-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.rb91
-rw-r--r--lib/rexml/dtd/dtd.rb2
-rw-r--r--lib/rexml/element.rb2281
-rw-r--r--lib/rexml/encoding.rb37
-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/UNILE.rb2
-rw-r--r--lib/rexml/entity.rb6
-rw-r--r--lib/rexml/formatters/default.rb109
-rw-r--r--lib/rexml/formatters/pretty.rb137
-rw-r--r--lib/rexml/formatters/transitive.rb56
-rw-r--r--lib/rexml/functions.rb25
-rw-r--r--lib/rexml/instruction.rb4
-rw-r--r--lib/rexml/node.rb25
-rw-r--r--lib/rexml/parsers/baseparser.rb70
-rw-r--r--lib/rexml/parsers/sax2parser.rb8
-rw-r--r--lib/rexml/parsers/treeparser.rb9
-rw-r--r--lib/rexml/parsers/xpathparser.rb2
-rw-r--r--lib/rexml/rexml.rb13
-rw-r--r--lib/rexml/sax2listener.rb2
-rw-r--r--lib/rexml/source.rb376
-rw-r--r--lib/rexml/text.rb64
-rw-r--r--lib/rexml/undefinednamespaceexception.rb8
-rw-r--r--lib/rexml/xmldecl.rb11
-rw-r--r--lib/rexml/xpath_parser.rb65
-rw-r--r--lib/rinda/.document3
-rw-r--r--lib/rinda/ring.rb2
-rw-r--r--lib/rinda/tuplespace.rb13
-rw-r--r--lib/rss/0.9.rb512
-rw-r--r--lib/rss/1.0.rb473
-rw-r--r--lib/rss/2.0.rb97
-rw-r--r--lib/rss/content.rb23
-rw-r--r--lib/rss/converter.rb15
-rw-r--r--lib/rss/dublincore.rb26
-rw-r--r--lib/rss/image.rb114
-rw-r--r--lib/rss/maker/base.rb36
-rw-r--r--lib/rss/maker/dublincore.rb6
-rw-r--r--lib/rss/maker/taxonomy.rb6
-rw-r--r--lib/rss/maker/trackback.rb8
-rw-r--r--lib/rss/parser.rb108
-rw-r--r--lib/rss/rss.rb319
-rw-r--r--lib/rss/syndication.rb27
-rw-r--r--lib/rss/taxonomy.rb126
-rw-r--r--lib/rss/trackback.rb106
-rw-r--r--lib/rss/utils.rb12
-rw-r--r--lib/runit/assert.rb7
-rw-r--r--lib/runit/testcase.rb2
-rw-r--r--lib/scanf.rb8
-rw-r--r--lib/set.rb47
-rw-r--r--lib/shell.rb11
-rw-r--r--lib/shell/process-controller.rb8
-rw-r--r--lib/shellwords.rb32
-rw-r--r--lib/singleton.rb3
-rw-r--r--lib/soap/baseData.rb2
-rw-r--r--lib/soap/generator.rb20
-rw-r--r--lib/soap/mapping/registry.rb2
-rw-r--r--lib/soap/mapping/rubytypeFactory.rb18
-rw-r--r--lib/soap/mimemessage.rb2
-rw-r--r--lib/soap/property.rb2
-rw-r--r--lib/soap/rpc/proxy.rb11
-rw-r--r--lib/sync.rb14
-rw-r--r--lib/tempfile.rb10
-rw-r--r--lib/test/unit/assertions.rb8
-rw-r--r--lib/test/unit/autorunner.rb1
-rw-r--r--lib/test/unit/collector/dir.rb2
-rw-r--r--lib/test/unit/collector/objectspace.rb2
-rw-r--r--lib/test/unit/testcase.rb14
-rw-r--r--lib/test/unit/testresult.rb1
-rw-r--r--lib/test/unit/ui/console/testrunner.rb14
-rw-r--r--lib/test/unit/ui/fox/testrunner.rb50
-rw-r--r--lib/test/unit/ui/gtk/testrunner.rb84
-rw-r--r--lib/test/unit/ui/gtk2/testrunner.rb84
-rw-r--r--lib/test/unit/ui/testrunnermediator.rb2
-rw-r--r--lib/test/unit/ui/tk/testrunner.rb30
-rw-r--r--lib/test/unit/util/observable.rb4
-rw-r--r--lib/test/unit/util/procwrapper.rb6
-rw-r--r--lib/thread.rb24
-rw-r--r--lib/time.rb21
-rw-r--r--lib/timeout.rb23
-rw-r--r--lib/tmpdir.rb19
-rw-r--r--lib/tracer.rb4
-rw-r--r--lib/uri/.document7
-rw-r--r--lib/uri/common.rb2
-rw-r--r--lib/uri/ftp.rb86
-rw-r--r--lib/uri/generic.rb17
-rw-r--r--lib/weakref.rb42
-rw-r--r--lib/webrick/cgi.rb19
-rw-r--r--lib/webrick/config.rb6
-rw-r--r--lib/webrick/httpauth/basicauth.rb2
-rw-r--r--lib/webrick/httpauth/digestauth.rb1
-rw-r--r--lib/webrick/httpauth/htpasswd.rb2
-rw-r--r--lib/webrick/httpproxy.rb4
-rw-r--r--lib/webrick/httprequest.rb18
-rw-r--r--lib/webrick/httpresponse.rb13
-rw-r--r--lib/webrick/httpserver.rb15
-rw-r--r--lib/webrick/httpservlet/abstract.rb2
-rw-r--r--lib/webrick/httpservlet/cgi_runner.rb4
-rw-r--r--lib/webrick/httpservlet/cgihandler.rb10
-rw-r--r--lib/webrick/httpservlet/erbhandler.rb2
-rw-r--r--lib/webrick/httpservlet/filehandler.rb73
-rw-r--r--lib/webrick/httputils.rb23
-rw-r--r--lib/webrick/server.rb3
-rw-r--r--lib/webrick/utils.rb75
-rw-r--r--lib/xmlrpc/README.rdoc300
-rw-r--r--lib/xmlrpc/client.rb9
-rw-r--r--lib/xmlrpc/create.rb8
-rw-r--r--lib/xmlrpc/datetime.rb2
-rw-r--r--lib/xmlrpc/parser.rb4
-rw-r--r--lib/xmlrpc/server.rb6
-rw-r--r--lib/xmlrpc/utils.rb2
-rw-r--r--lib/xsd/codegen/gensupport.rb8
-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--main.c17
-rw-r--r--marshal.c335
-rw-r--r--math.c125
-rw-r--r--misc/README13
-rw-r--r--misc/rdebug.el136
-rw-r--r--misc/ruby-mode.el8
-rw-r--r--missing.h72
-rw-r--r--missing/acosh.c9
-rw-r--r--missing/dup2.c3
-rw-r--r--missing/erf.c12
-rw-r--r--missing/finite.c3
-rw-r--r--missing/flock.c17
-rw-r--r--missing/hypot.c3
-rw-r--r--missing/isinf.c22
-rw-r--r--missing/isnan.c8
-rw-r--r--missing/memcmp.c9
-rw-r--r--missing/memmove.c17
-rw-r--r--missing/os2.c25
-rw-r--r--missing/strcasecmp.c3
-rw-r--r--missing/strchr.c18
-rw-r--r--missing/strerror.c3
-rw-r--r--missing/strftime.c58
-rw-r--r--missing/strncasecmp.c6
-rw-r--r--missing/strstr.c11
-rw-r--r--missing/strtol.c9
-rw-r--r--missing/strtoul.c14
-rw-r--r--missing/vsnprintf.c149
-rwxr-xr-x[-rw-r--r--]mkconfig.rb47
-rw-r--r--node.h119
-rw-r--r--numeric.c850
-rw-r--r--object.c915
-rw-r--r--oniguruma.h909
-rw-r--r--pack.c295
-rw-r--r--parse.y5730
-rw-r--r--prec.c17
-rw-r--r--process.c902
-rw-r--r--random.c39
-rw-r--r--range.c257
-rw-r--r--re.c1037
-rw-r--r--re.h15
-rw-r--r--regcomp.c6017
-rw-r--r--regenc.c1028
-rw-r--r--regenc.h147
-rw-r--r--regerror.c371
-rw-r--r--regex.c4687
-rw-r--r--regex.h219
-rw-r--r--regexec.c3920
-rw-r--r--regint.h829
-rw-r--r--regparse.c5352
-rw-r--r--regparse.h328
-rw-r--r--ruby.c500
-rw-r--r--ruby.h431
-rw-r--r--rubyio.h77
-rw-r--r--rubysig.h22
-rwxr-xr-x[-rw-r--r--]rubytest.rb8
-rwxr-xr-xrunruby.rb14
-rw-r--r--sample/cal.rb36
-rw-r--r--sample/occur.rb4
-rw-r--r--sample/openssl/cipher.rb73
-rw-r--r--sample/openssl/gen_csr.rb1
-rw-r--r--sample/optparse/opttest.rb28
-rw-r--r--sample/ripper/ruby2html.rb112
-rw-r--r--sample/ripper/strip-comment.rb19
-rwxr-xr-xsample/rss/convert.rb69
-rw-r--r--sample/test.rb696
-rw-r--r--signal.c336
-rw-r--r--sjis.c238
-rw-r--r--sprintf.c366
-rw-r--r--st.c209
-rw-r--r--st.h40
-rw-r--r--string.c2496
-rw-r--r--struct.c355
-rw-r--r--test/dbm/test_dbm.rb39
-rw-r--r--test/digest/test_digest_hmac.rb3
-rw-r--r--test/erb/hello.erb4
-rw-r--r--test/erb/test_erb.rb384
-rw-r--r--test/fileutils/test_fileutils.rb5
-rw-r--r--test/gdbm/test_gdbm.rb39
-rw-r--r--test/inlinetest.rb59
-rw-r--r--test/io/nonblock/test_flush.rb1
-rw-r--r--test/net/http/test_http.rb382
-rw-r--r--test/net/imap/test_imap.rb13
-rw-r--r--test/openssl/test_asn1.rb2
-rw-r--r--test/openssl/test_ssl.rb14
-rw-r--r--test/rdoc/parsers/test_parse_c.rb261
-rw-r--r--test/readline/test_readline.rb2
-rw-r--r--test/rinda/test_rinda.rb22
-rw-r--r--test/rinda/test_tuplebag.rb172
-rw-r--r--test/ripper/dummyparser.rb517
-rw-r--r--test/ripper/test_files.rb19
-rw-r--r--test/ripper/test_parser_events.rb493
-rw-r--r--test/ripper/test_scanner_events.rb803
-rw-r--r--test/rss/rss-assertions.rb7
-rw-r--r--test/rss/rss-testcase.rb26
-rw-r--r--test/rss/test_1.0.rb20
-rw-r--r--test/rss/test_2.0.rb28
-rw-r--r--test/rss/test_content.rb2
-rw-r--r--test/rss/test_dublincore.rb4
-rw-r--r--test/rss/test_image.rb35
-rw-r--r--test/rss/test_maker_0.9.rb37
-rw-r--r--test/rss/test_maker_1.0.rb68
-rw-r--r--test/rss/test_maker_2.0.rb57
-rw-r--r--test/rss/test_maker_dc.rb20
-rw-r--r--test/rss/test_maker_taxo.rb10
-rw-r--r--test/rss/test_maker_trackback.rb5
-rw-r--r--test/rss/test_maker_xml-stylesheet.rb42
-rw-r--r--test/rss/test_parser.rb586
-rw-r--r--test/rss/test_parser_1.0.rb512
-rw-r--r--test/rss/test_parser_2.0.rb122
-rw-r--r--test/rss/test_setup_maker_0.9.rb36
-rw-r--r--test/rss/test_setup_maker_1.0.rb106
-rw-r--r--test/rss/test_setup_maker_2.0.rb75
-rw-r--r--test/rss/test_syndication.rb2
-rw-r--r--test/rss/test_taxonomy.rb18
-rw-r--r--test/rss/test_trackback.rb2
-rw-r--r--test/ruby/envutil.rb7
-rw-r--r--test/ruby/suicide.rb2
-rw-r--r--test/ruby/test_array.rb28
-rw-r--r--test/ruby/test_assignment.rb412
-rw-r--r--test/ruby/test_beginendblock.rb42
-rw-r--r--test/ruby/test_bignum.rb8
-rw-r--r--test/ruby/test_dir.rb6
-rw-r--r--test/ruby/test_env.rb24
-rw-r--r--test/ruby/test_eval.rb2
-rw-r--r--test/ruby/test_file.rb41
-rw-r--r--test/ruby/test_float.rb35
-rw-r--r--test/ruby/test_fnmatch.rb105
-rw-r--r--test/ruby/test_hash.rb564
-rw-r--r--test/ruby/test_io.rb27
-rw-r--r--test/ruby/test_iterator.rb71
-rw-r--r--test/ruby/test_lambda.rb53
-rw-r--r--test/ruby/test_marshal.rb20
-rw-r--r--test/ruby/test_method.rb11
-rw-r--r--test/ruby/test_pipe.rb1
-rw-r--r--test/ruby/test_proc.rb40
-rw-r--r--test/ruby/test_range.rb37
-rw-r--r--test/ruby/test_readpartial.rb2
-rw-r--r--test/ruby/test_regexp.rb27
-rw-r--r--test/ruby/test_settracefunc.rb1
-rw-r--r--test/ruby/test_signal.rb2
-rw-r--r--test/ruby/test_sprintf.rb141
-rw-r--r--test/ruby/test_stringchar.rb8
-rw-r--r--test/ruby/test_struct.rb28
-rw-r--r--test/ruby/test_super.rb17
-rw-r--r--test/ruby/test_system.rb14
-rw-r--r--test/ruby/test_time.rb21
-rw-r--r--test/ruby/test_variable.rb20
-rw-r--r--test/ruby/test_whileuntil.rb14
-rw-r--r--test/ruby/ut_eof.rb12
-rw-r--r--test/runner.rb2
-rw-r--r--test/scanf/data.txt6
-rw-r--r--test/scanf/test_scanf.rb310
-rw-r--r--test/scanf/test_scanfblocks.rb78
-rw-r--r--test/scanf/test_scanfio.rb19
-rw-r--r--test/sdbm/test_sdbm.rb17
-rw-r--r--test/soap/calc/test_calc_cgi.rb4
-rw-r--r--test/soap/header/test_authheader_cgi.rb4
-rw-r--r--test/soap/ssl/test_ssl.rb4
-rw-r--r--test/soap/wsdlDriver/test_calc.rb14
-rw-r--r--test/socket/test_socket.rb24
-rw-r--r--test/socket/test_tcp.rb28
-rw-r--r--test/socket/test_udp.rb32
-rw-r--r--test/strscan/test_stringscanner.rb13
-rw-r--r--test/test_generator.rb4
-rw-r--r--test/test_ipaddr.rb4
-rw-r--r--test/test_pp.rb4
-rw-r--r--test/test_prettyprint.rb4
-rw-r--r--test/test_set.rb4
-rw-r--r--test/test_shellwords.rb39
-rw-r--r--test/test_time.rb4
-rw-r--r--test/test_tsort.rb4
-rw-r--r--test/testunit/collector/test_dir.rb29
-rw-r--r--test/testunit/test_assertions.rb1
-rwxr-xr-xtest/thread/lbtest.rb51
-rw-r--r--test/thread/test_thread.rb119
-rw-r--r--test/uri/test_ftp.rb22
-rw-r--r--test/uri/test_generic.rb2
-rw-r--r--test/webrick/.htaccess1
-rw-r--r--test/webrick/test_cgi.rb18
-rw-r--r--test/webrick/test_cookie.rb2
-rw-r--r--test/webrick/test_filehandler.rb141
-rw-r--r--test/webrick/test_utils.rb64
-rw-r--r--test/webrick/utils.rb14
-rwxr-xr-xtest/webrick/webrick_long_filename.cgi36
-rw-r--r--test/win32ole/test_folderitem2_invokeverb.rb79
-rw-r--r--test/win32ole/test_nil2vtempty.rb32
-rw-r--r--test/win32ole/test_propertyputref.rb24
-rw-r--r--test/win32ole/test_win32ole.rb44
-rw-r--r--test/win32ole/test_win32ole_method.rb135
-rw-r--r--test/win32ole/test_win32ole_param.rb84
-rw-r--r--test/win32ole/test_win32ole_type.rb142
-rw-r--r--test/win32ole/test_win32ole_typelib.rb95
-rw-r--r--test/win32ole/test_win32ole_variable.rb61
-rw-r--r--test/win32ole/test_win32ole_variant.rb109
-rw-r--r--test/win32ole/test_win32ole_variant_m.rb33
-rw-r--r--test/wsdl/any/test_any.rb14
-rw-r--r--test/wsdl/document/echo.rb92
-rw-r--r--test/wsdl/document/test_rpc.rb2
-rw-r--r--test/wsdl/qualified/lp.rb0
-rw-r--r--test/wsdl/ref/test_ref.rb14
-rw-r--r--test/wsdl/rpc/echoDriver.rb55
-rw-r--r--test/wsdl/rpc/echo_serviceClient.rb23
-rw-r--r--test/wsdl/simpletype/rpc/test_rpc.rb14
-rw-r--r--test/xmlrpc/webrick_testing.rb4
-rw-r--r--test/yaml/test_yaml.rb8
-rw-r--r--time.c920
-rw-r--r--utf8.c3764
-rw-r--r--util.c3473
-rw-r--r--util.h19
-rw-r--r--variable.c650
-rw-r--r--version.c15
-rw-r--r--version.h25
-rw-r--r--vms/config.h193
-rw-r--r--vms/vms.h9
-rw-r--r--win32/Makefile.sub80
-rw-r--r--win32/README.win3227
-rwxr-xr-xwin32/configure.bat52
-rw-r--r--win32/dir.h9
-rwxr-xr-x[-rw-r--r--]win32/mkexports.rb151
-rwxr-xr-x[-rw-r--r--]win32/resource.rb6
-rw-r--r--win32/setup.mak10
-rw-r--r--win32/win32.c1310
-rw-r--r--win32/win32.h228
-rw-r--r--wince/Makefile.sub17
-rw-r--r--wince/README.wince19
-rwxr-xr-x[-rw-r--r--]wince/configure.bat2
-rw-r--r--wince/mkconfig_wce.rb7
-rw-r--r--wince/mkexports.rb35
-rw-r--r--wince/resource.rb96
-rw-r--r--wince/setup.mak2
697 files changed, 55516 insertions, 76429 deletions
diff --git a/.cvsignore b/.cvsignore
index 76c9bc0b78..a72211d03f 100644
--- a/.cvsignore
+++ b/.cvsignore
@@ -14,7 +14,6 @@
COPYING.LIB
ChangeLog.pre-alpha
ChangeLog.pre1_1
-ChangeLog-1.8.0
Makefile
README.fat-patch
README.v6
@@ -35,12 +34,9 @@ newdate.rb
newver.rb
parse.c
patches
-patches-master
-pitest.rb
ppack
preview
rbconfig.rb
-rename2.h
repack
riscos
rubicon
diff --git a/COPYING.ja b/COPYING.ja
index aa2a163848..933cc7cb9a 100644
--- a/COPYING.ja
+++ b/COPYING.ja
@@ -1,6 +1,6 @@
-$BK\%W%m%0%i%`$O%U%j!<%=%U%H%&%'%"$G$9!%(BGPL (the GNU General
-Public License)$B%P!<%8%g%s(B2$B$^$?$O0J2<$K<($9>r7o$GK\%W%m%0%i%`(B
-$B$r:FG[I[$G$-$^$9!%(BGPL$B$K$D$$$F$O(BGPL$B%U%!%$%k$r;2>H$7$F2<$5$$!%(B
+$BK\%W%m%0%i%`$O%U%j!<%=%U%H%&%'%"$G$9!%(BGPL(the GNU General
+Public License)$B$^$?$O0J2<$K<($9>r7o$GK\%W%m%0%i%`$r:FG[I[$G(B
+$B$-$^$9!%(BGPL$B$K$D$$$F$O(BGPL$B%U%!%$%k$r;2>H$7$F2<$5$$!%(B
1. $BJ#@=$O@)8B$J$/<+M3$G$9!%(B
diff --git a/ChangeLog b/ChangeLog
index 09651f36c5..7ec3d689f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,1990 +1,3441 @@
-Tue Nov 7 18:35:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jan 11 11:31:52 2009 Shugo Maeda <shugo@ruby-lang.org>
- * eval.c (formal_assign): need to pack rest arg information in
- argc.
+ * lib/net/ftp.rb (chdir): handle 5xx errors correctly.
+ backported from trunk. fixed [ruby-core:18057].
-Tue Nov 7 18:05:01 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+Fri Jan 9 19:22:24 2009 Shugo Maeda <shugo@ruby-lang.org>
- * ext/tk/lib/tk/itemconfig.rb: minor bug fix.
+ * lib/net/imap.rb (disconnect): do not refer SSL::SSLSocket for
+ environments without OpenSSL. backported from trunk.
+ fixed [ruby-dev:35755].
-Tue Nov 7 17:52:08 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Thu Jan 8 13:20:15 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * class.c (rb_include_module): revert duplicate inclusion of
- modules. [ruby-dev:29793]
+ * 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]
-Tue Nov 7 17:18:11 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Jan 7 10:06:12 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (method_missing): update old argument adjustment.
+ * eval.c (timeofday): use monotonic clock. based on a patch
+ from zimbatm <zimbatm@oree.ch> in [ruby-core:16627].
-Tue Nov 7 16:41:21 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Jan 6 09:02:14 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (when_check): need to splat for NODE_ARGSCAT as well.
- [ruby-dev:29860]
+ * parse.y (yylex): 8 and 9 in octal integer should cause compile
+ error. [ruby-dev:35729]
-Mon Nov 6 22:23:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Jan 5 11:12:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * string.c (Init_String): remove duplicated definition of
- Symbol#to_s.
+ * eval.c (rb_thread_schedule): runs deferred finalizers.
-Mon Nov 6 18:54:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * gc.c (gc_sweep): sets rb_thread_pending to run deferred finalizers.
- * eval.c (svalue_to_avalue): need to splat but no error.
+ * rubysig.h (CHECK_INTS): now checks rb_thread_pending even on
+ platforms where setitimer is not available. [ruby-core:18045]
- * eval.c: new macros - YIELD_CALL, YIELD_VALUES.
+Mon Jan 5 11:12:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (rb_yield_values): specify YIELD_VALUES.
+ * rubysig.h (CHECK_INTS): gives the chance to perform to deferred
+ finalizers before explicit GC.start or the process termination.
+ [ruby-core:18045]
- * eval.c (rb_yield_0): use new macros.
+Sun Jan 4 04:47:57 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (proc_invoke): slightly modified to separate YIELD_CALL
- and YIELD_VALUES from YIELD_ARY_ARGS.
+ * win32/win32.c (rb_w32_telldir): just returns loc.
- * object.c (Init_Object): add nil.to_splat => [].
+ * win32/win32.c (rb_w32_rewinddir): needs to intialize loc.
+ [ruby-core:18041]
-Mon Nov 6 15:41:55 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+Thu Jan 1 08:39:36 2009 Tadayoshi Funaba <tadf@dotrb.org>
- * ext/tk/lib/tk/itemconfig.rb: ext/tk/lib/tk/itemconfig.rb: bug
- fix on 'itemconfiginfo' method, and modify to make it easy to
- override 'itemconfiginfo' method.
+ * 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.
- * ext/tk/lib/tkextlib/tile/treeview.rb : support Tile 0.7.8.
+ * lib/date.rb, lib/date/format.rb: some trivial changes.
- * ext/tk/lib/tkextlib/version.rb : [new] add Tk::Tkextlib_RELEASE_DATE
- to get the information from scripts.
+Mon Aug 11 09:34:52 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/tk/lib/tk.rb: load 'tkextlib/version.rb', and update RELEASE_DATE
+ * ext/dl/dl.c (rb_str_to_ptr): should propagate taint to dlptr.
- * ext/tk/lib/tkextlib/SUPPORT_STATUS: update.
+ * ext/dl/dl.c (rb_ary_to_ptr): ditto.
- * ext/tk/sample/editable_listbox.rb: [new] the listbox with editable
- items. It's one of the example about usage of Place geometry manager.
+ * ext/dl/sym.c (rb_dlsym_call): should check taint of DLPtrData as
+ well.
- * ext/tk/sample/tktextio.rb: improve the functions of TkTextIO class.
- Those are required by 'irbtkw.rbw'.
+Fri Aug 8 10:53:52 2008 Tanaka Akira <akr@fsij.org>
- * ext/tk/sample/irbtkw.rbw: [new] IRB on Ruby/Tk. It doesn't need any
- real console. IRB works on a text widget without I/O blocking. That
- is, thread switching on IRB will work properly, even if on Windows.
+ * lib/resolv.rb: randomize source port and transaction id.
+ CVE-2008-1447.
-Mon Nov 6 00:42:05 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/resolv-replace.rb (UDPSocket#bind): don't resolv host if host is
+ "".
- * parse.y (arg_dup_check): vid may be nameless internal id.
+Mon Aug 4 14:15:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sun Nov 5 19:52:19 2006 Tadayoshi Funaba <tadf@dotrb.org>
+ * lib/webrick/httputils.rb (WEBrick::HTTPUtils#split_header_value):
+ reduce backtrack. based on a fix by Christian Neukirchen
+ <chneukirchen AT gmail.com>.
- * lib/date.rb: updated based on date2 3.9.7.
+Mon Aug 4 14:10:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Nov 4 13:09:31 2006 Shugo Maeda <shugo@ruby-lang.org>
+ * regex.c (xmalloc, xrealloc, xfree): not to use ruby managed memory.
- * lib/net/imap.rb: accept NOMODSEQ. [ruby-core:9002]
+ * regex.c (DOUBLE_STACK, re_compile_fastmap0, re_adjust_startpos),
+ (re_search, re_match_exec): check if failed to allocate memory.
-Fri Nov 3 00:16:37 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Aug 4 13:49:36 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/socket/socket.c (ruby_getnameinfo__aix): AF_INET6 workaround
- for AIX. a patch from Yutaka Kanemoto <kinpoco AT gmail.com>.
- [ruby-dev:29744]
+ * bignum.c (rb_big2str0, bigsqr): made interruptible. [ruby-Bugs-20622]
-Thu Nov 2 14:19:44 2006 Akinori MUSHA <knu@iDaemons.org>
+Mon Aug 4 13:39:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/set.rb (Set#^): Fix XOR operation against a container that
- holds duplicate values. [ruby-core:9372]
+ * ext/openssl/openssl_missing.h (d2i_of_void): define for older
+ versions. [ruby-dev:35637]
-Thu Nov 2 10:00:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Aug 4 12:25:08 2008 NAKAMURA Usaku <usa@ruby-lang.org>
- * string.c: class Symbol is no longer subclass of String. also
- covers [ruby-core:09366]
+ * 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>
-Thu Nov 2 08:21:07 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * numeric.c (check_uint, rb_num2uint, rb_fix2uint): strict check.
+ fixed [ruby-dev:33683]
- * lib/xmlrpc/create.rb (XMLRPC::Create::conv2value): Symbol should
- come earlier than String.
+Mon Aug 4 12:11:29 2008 Tanaka Akira <akr@fsij.org>
- * lib/soap/mapping/rubytypeFactory.rb (RubytypeFactory::obj2soap):
- ditto.
+ * gc.c (Init_GC): fix syntax error.
- * lib/set.rb (TC_Set::test_s_new): strings are no longer
- Enumerable
+Mon Aug 4 12:11:29 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/soap/property.rb (Property::load): ditto.
+ * error.c (rb_exc_new3): keeps the given string itself.
- * lib/webrick/httputils.rb (WEBrick::HTTPUtils::parse_header): ditto.
+ * eval.c (Init_Proc), gc.c (Init_GC): freeze messages of preallocated
+ special exceptions also.
- * lib/soap/mimemessage.rb (MIMEMessage::Headers::parse): ditto.
+Thu Jul 17 21:37:39 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-Thu Nov 2 09:08:04 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/net/smtp.rb (Net::SMTP::start): revert to avoid RFC2821
+ violation. [ruby-dev:35487]
- * array.c: revert lfree shift/unshift boost patch to avoid unknown
- memory error.
+Thu Jul 17 21:31:46 2008 Tanaka Akira <akr@fsij.org>
-Wed Nov 1 23:24:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * string.c (rb_str_format_m): make tmp volatile to avoid possible GC
+ problem.
- * ruby.h (struct RArray): revert embedding ptr in RVALUE.
+Thu Jul 17 21:29:34 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * array.c: ditto.
+ * lib/optparse.rb (OptionParser#environment): requires shellwords.
+ [ruby-dev:35466]
-Wed Nov 1 23:01:55 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Thu Jul 17 01:36:02 2008 Yusuke Endoh <mame@tsg.ne.jp>
- * string.c (hash): use Bob Jenkins' hash algorithm.
+ * ext/zlib/zlib.c (rb_gzfile_set_mtime): fix typo. [ruby-core:17713]
-Wed Nov 1 02:22:31 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jul 13 00:07:07 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/lib/digest/hmac.rb (Digest::HMAC::update): Minor
- optimization.
+ * 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].
- * ext/digest/digest.c (rb_digest_instance_equal): Allow comparing
- a digest instance with another of a different class.
+Sun Jul 13 00:02:26 2008 Tanaka Akira <akr@fsij.org>
-Wed Nov 1 01:05:13 2006 NAKAMURA Usaku <usa@ruby-lang.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
- * eval.c (rb_call0): fixed bug of zsuper with both of opt and rest.
- fixed: [ruby-list:42928]
+Thu Jul 10 18:44:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Tue Oct 31 17:03:21 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * file.c (rb_file_s_extname): fix for file name with spaces.
+ [ruby-talk:307404]
- * time.c (time_dup): duplicate the class of original time.
- [ruby-core:09357]
+Thu Jul 10 18:39:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/time.rb (Time::make_time, Time::rfc2822, Time::httpdate):
- should respect subclasses. [ruby-core:09357]
+ * lib/net/ftp.rb (Net::FTP#sendport): use divmod. [ruby-core:17557]
-Tue Oct 31 16:25:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Thu Jul 10 18:35:07 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
- * array.c (ary_shared_first): should address offset after
- ary_shared_array(). [ruby-core:09358]
+ * ruby.c: Mac OS X needs origargc times of '\0' in
+ origargv. [ruby-dev:35308]
-Mon Oct 30 23:40:52 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Jul 10 13:51:03 2008 Tanaka Akira <akr@fsij.org>
- * Makefile.in (miniruby): add XLDFLAGS.
+ * 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.
- * configure.in (aix): use -bE option for miniruby. [ruby-dev:29698]
+Mon Jul 7 16:14:05 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * dir.c (glob_helper): get rid of possible memory leak.
+ * lib/net/smtp.rb (Net::SMTP::start): use 'localhost' instead of
+ 'localhost.localdomain'. [ruby-dev:35333]
- * win32/win32.c (cmdglob, rb_w32_cmdvector, rb_w32_opendir,
- rb_w32_get_environ): not to use GC before initialization.
+ * lib/net/smtp.rb (Net::SMTP::SMTP.start): ditto.
-Mon Oct 30 19:28:02 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Mon Jul 7 12:07:28 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * bignum.c (rb_big2str0): use better approximation.
+ * ext/win32ole/win32ole.c: avoid creating Ruby object during
+ GC. thanks to arton <artonx AT yahoo.co.jp>. [ruby-dev:35313]
-Mon Oct 30 18:35:33 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/win32ole/tests: add test_win32ole_event.rb, remove
+ testOLEEVENT.rb
- * bignum.c (rb_big2str0): wrong allocation length. a patch from
- U.Nakamura <usa at garbagecollect.jp> [ruby-dev:29710]
+ * ext/win32ole/tests/testWIN32OLE.rb(test_convert_bignum):
+ fix test.
-Mon Oct 30 12:34:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Jul 7 12:07:28 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * eval.c (rb_eval): fix commit miss. [ruby-dev:29707]
+ * gc.c: add rb_during_gc(). based on a patch from arton <artonx AT
+ yahoo.co.jp> at [ruby-dev:35313].
-Mon Oct 30 11:15:40 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * intern.h: ditto.
- * sprintf.c (rb_str_format): should preserve leading zero
- information for negative %b and %x. [ruby-talk:221347]
+Thu Jul 3 17:15:04 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-Sun Oct 29 19:51:31 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
+ * win32/win32.c: revert r17290, requested by NAKAMURA Usaku
+ <usa at ruby-lang.org>
- * regexec.c: invalid offset value was used in STATE_CHECK_BUFF_INIT().
+Wed Jul 2 19:05:35 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Oct 28 20:13:18 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
+ * lib/cgi.rb (CGI::QueryExtension.read_multipart): blanks inside
+ double quotes are allowed. [ruby-list:45140]
- * oniguruma.h: Version 4.4.5
+Wed Jul 2 19:01:13 2008 Tanaka Akira <akr@fsij.org>
- * regint.h: ditto.
+ * numeric.c (num_coerce): call rb_Float(x) first. don't depend on
+ evaluation order of function arguments.
- * regerror.c: ditto.
+Wed Jul 2 18:55:50 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * regexec.c: ditto.
+ * 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>.
- * regcomp.c ditto.
+ * ext/syslog/syslog.c (mSyslog_close): ditto.
- * regparse.c ditto.
+ * ext/syslog/syslog.c (mSyslog_set_mask): ditto.
-Sat Oct 28 07:56:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Jul 2 18:25:17 2008 Tanaka Akira <akr@fsij.org>
- * marshal.c (r_object0): missing break. [ruby-core:09345]
+ * math.c (domain_check): fix preprocess condition.
-Fri Oct 27 17:30:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Jul 2 18:19:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * enumerator.c (enum_each_cons): move RETURN_ENUMERATOR() after
- argument check.
+ * 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]
-Thu Oct 26 21:05:48 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Wed Jul 2 18:13:30 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * ext/openssl/ossl_pkcs7.c (ossl_pkcs7_verify): should clear error.
- (fix http://bugs.debian.org/394336)
+ * ext/win32ole/win32ole.c (date2time_str): fix the overflow in
+ some situation. [ruby-bugs-20793]
- * ext/openssl/ossl_ns_spki.c (ossl_spki_initialize): ditto.
+Wed Jul 2 17:38:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Thu Oct 26 15:23:47 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/iconv/iconv.c (iconv_iconv): fixed backport miss.
+ [ruby-core:17115]
- * enumerator.c: remove by_slice and by_cons.
+Tue Jul 1 15:09:37 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Thu Oct 26 15:12:12 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * array.c (rb_ary_fill): check if beg is too big.
- * ext/digest/digest.c (Init_digest): typo.
+Mon Jun 30 20:34:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Wed Oct 25 17:16:05 2006 Akinori MUSHA <knu@iDaemons.org>
+ * string.c (str_buf_cat): check for self concatenation.
- * test/digest/test_digest_hmac.rb: added.
+Sun Jun 29 21:38:52 2008 Tanaka Akira <akr@fsij.org>
-Wed Oct 25 16:34:31 2006 Akinori MUSHA <knu@iDaemons.org>
+ * eval.c (rb_obj_respond_to): use RTEST to test the result of
+ respond_to? method.
- * ext/digest/test.sh: make this script work again.
+Sun Jun 29 20:40:57 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-Wed Oct 25 07:59:42 2006 Tadayoshi Funaba <tadf@dotrb.org>
+ * array.c (rb_ary_fill): (compatibility) do not raise
+ ArgumentError on negative length. This behaviour shall change
+ in a future release.
- * lib/date/format.rb: updated based on date2 3.9.6.
- [ruby-core:09323]
+Sun Jun 29 20:06:45 2008 Tanaka Akira <akr@fsij.org>
-Wed Oct 25 00:58:19 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * time.c (time_timeval): fix rounding negative float.
- * win32/mkexports.rb, win32/resource.rb: use unique variable names.
+Sun Jun 29 18:35:23 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Tue Oct 24 19:18:53 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * test/inlinetest.rb (InlineTest.in_progname): workaround for frozen
+ $0. [ruby-dev:35261]
- * enumerator.c (enumerator_by_slice): new method added.
+ * lib/test/unit/ui/console/testrunner.rb (TestRunner#finished): ditto.
- * enumerator.c (enumerator_by_cons): ditto.
+Sun Jun 29 18:35:23 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Tue Oct 24 18:56:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ruby.c (set_arg0, ruby_prog_init): freeze $0. a patch from Keita
+ Yamaguchi <keita.yamaguchi at gmail.com>.
- * enumerator.c (enum_each_slice, enum_each_cons): returns
- Enumerable::Enumerator if no block is given. [ruby-dev:29246]
+Sun Jun 29 18:32:19 2008 Tanaka Akira <akr@fsij.org>
- * enumerator.c: remove methods: enum_with_index, enum_slice,
- enum_cons. [ruby-dev:29246]
+ * process.c: include sys/resource.h if HAVE_SYS_RESOURCE_H is defined.
+ pointed by TOYOFUKU Chikanobu. [ruby-dev:35258]
-Tue Oct 24 18:51:27 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 29 18:25:03 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * enum.c (enum_zip): add RETURN_ENUMERATOR() to zip method.
+ * variable.c (rb_f_trace_var): should not be allowed at safe level 4.
+ a patch from Keita Yamaguchi <keita.yamaguchi at gmail.com>.
-Mon Oct 23 04:30:04 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * eval.c (rb_call0): wrong condition to check insecure method.
+ a patch from Keita Yamaguchi <keita.yamaguchi at gmail.com>.
- * marshal.c (r_object0): use return value from proc given as the
- second argument to Marshal#load() to allow value replacement in
- the restoring data.
+Sun Jun 29 18:24:13 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sun Oct 22 14:48:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * array.c (rb_ary_fill): not depend on unspecified behavior at integer
+ overflow. reported by Vincenzo Iozzo <snagg AT openssl.it>.
- * signal.c (Init_signal): avoid duplicated installation of SIGCHLD
- handler.
+Sun Jun 29 18:21:23 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-Sun Oct 22 16:47:56 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/win32ole/win32ole.c(ole_invoke): fix memory leak.
+ [ruby-bugs-20792]
- * string.c (rb_str_substr): should be infected with only original
- string, but not the shared string. fixed: [ruby-core:09152]
+Sun Jun 29 17:34:11 2008 Akinori MUSHA <knu@iDaemons.org>
- * strnig.c (rb_str_new4): keep shared string untainted when orignal
- string is tainted. fixed: [ruby-dev:29672]
+ * 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 Oct 22 07:55:11 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 29 17:23:51 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * string.c (rb_str_upcase, rb_str_downcase, rb_str_downcase,
- rb_str_upcase_bang, rb_str_downcase_bang, rb_str_swapcase_bang):
- add RDoc description that case conversion to be effective only
- in ASCII region.
+ * lib/rdoc/parsers/parse_rb.rb (RDoc#collect_first_comment): skip
+ magic comment.
-Sun Oct 22 05:20:34 2006 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
+Sun Jun 29 17:21:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * configure.in: alloca is broken; use C_ALLOCA instead.
- [ruby-dev:29416]
+ * ext/stringio/stringio.c (strio_each, strio_readlines): IO#each and
+ IO#readlines do not affect $_. [ruby-core:17277]
-Sat Oct 21 17:50:40 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 29 17:18:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/lib/digest.rb: Follow the framework updates.
+ * ext/stringio/stringio.c (strio_readline, strio_each)
+ (strio_readlines): set lastline. [ruby-core:17257]
-Fri Oct 20 22:00:43 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 29 17:10:30 2008 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/digest/lib/digest/hmac.rb: Complete half-boiled updates.
+ * 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]
- * ext/digest/sha2/lib/digest/sha2.rb: Fix #initialize_clone().
+Sun Jun 29 17:07:30 2008 wanabe <s.wanabe@gmail.com>
-Fri Oct 20 20:28:37 2006 Akinori MUSHA <knu@iDaemons.org>
+ * util.c (ruby_strtod): ruby_strtod don't allow a trailing
+ decimal point like "7.". [ruby-dev:34835] [ruby-dev:35009]
- * ext/digest: Prefix C constants with RUBY_ and C type names with
- rb_ to avoid name clash in writing extensions.
+Sun Jun 29 16:56:57 2008 Akinori MUSHA <knu@iDaemons.org>
- * ext/digest: Introduce Digest::Class and Digest::Instance for
- ease of implementing subclasses and add-ons, inspried by
- gotoyuzo.
+ * 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.
- * ext/digest: The Digest::Instance module now requires and assumes
- that any instance be resettable and clonable, and add some
- convenient instance methods such as "new()", for creating a new
- copy, parameter taking "digest()" and "hexdigest()", for instant
- calculation. These methods make digest instances work just like
- digest classes.
+Sun Jun 29 16:49:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/sha2/lib/digest/sha2.rb:
- Add the Digest::SHA2 class to wrap up SHA2 variants: SHA256,
- SHA384 and SHA512, hoping this module would make a decent
- example of a digest subclass written in Ruby.
+ * 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.
- * ext/digest/lib/digest.rb: Adjust autoload entries for SHA2
- classes.
+Sat Jun 28 19:26:43 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
- * ext/digest/lib/digest/hmac.rb: Follow the framework updates.
+ * class.c (clone_method): use rb_copy_node_scope.
+ fixed [ruby-list:45102]
+ fixed [ruby-core:17393]
-Fri Oct 20 10:47:43 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Sat Jun 28 19:25:56 2008 Akinori MUSHA <knu@iDaemons.org>
- * lib/mkmf.rb: fixed the bug of handling COMMON_MACROS.
+ * eval.c (rb_copy_node_scope), node.h: Rename from copy_node_scope
+ and export.
-Fri Oct 20 08:42:38 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Jun 27 17:38:21 2008 Akinori MUSHA <knu@iDaemons.org>
- * common.mk (NULLCMD): dummy command.
+ * ext/zlib/zlib.c (rb_deflate_initialize, Init_zlib): Fix up
+ initialize_copy; [ruby-list:45016], [ruby-list:45018].
- * bcc32/Makefile.sub (post-install-*): Borland make cannot ignore
- command-less double-colon rules. [ruby-dev:29676]
+Fri Jun 27 17:28:39 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-Fri Oct 20 00:37:07 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * io.c (rb_open_file, rb_io_s_sysopen): fmode should be unsigned int.
+ fixed [ruby-dev:34979]
- * bcc32/Makefile.sub ($(LIBRUBY_SO)): execute pre-link hook.
+Fri Jun 27 17:20:40 2008 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/extmk.rb: workaround for Borland make.
+ * win32/win32.h: include ws2tcpip.h. fixed [ruby-Bugs-20528]
-Wed Oct 18 23:02:40 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Jun 27 15:57:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * array.c (rb_ary_shift): shorten copy size. fixed: [ruby-list:42907]
+ * ext/iconv/iconv.c (iconv_iconv): fixed backport miss.
+ [ruby-core:17115]
- * signal.c (Init_signal): handle SIGTERM. fixed: [ruby-list:42895]
+Fri Jun 27 15:57:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * win32/win32.c (rb_w32_utime): allow NULL to set the current time.
- [ruby-talk:219248]
+ * ext/iconv/iconv.c (iconv_iconv): fix for length argument and now
+ allows range. [ruby-core:17092]
-Wed Oct 18 13:25:50 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Tue Jun 24 15:38:52 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * string.c (rb_str_each_line): String#lines now works when a block
- is given. in other words, lines become an alias to each_line.
- [ruby-core:09218]
+ * lib/erb.rb (ERB::Compiler::TrimScanner#explicit_trim_line): Fix
+ without strscan problems. [ruby_core:17028].
- * string.c (rb_str_each_byte): ditto for bytes in place of lines.
+ * test/erb/test_erb.rb (TestERBCoreWOStrScan): Add test class for
+ without strscan.
-Wed Oct 18 00:55:33 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Jun 22 00:09:20 2008 Akinori MUSHA <knu@iDaemons.org>
- * parse.y (parser_yylex): use particular enums. [ruby-core:09221]
+ * 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].
-Tue Oct 17 22:03:08 2006 Minero Aoki <aamine@loveruby.net>
+Fri Jun 20 18:24:18 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/erb.rb: String#each was removed, use #each_line instead.
+ * string.c (rb_str_buf_append): should infect.
-Tue Oct 17 12:27:32 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Jun 20 15:52:30 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * array.c (ary_shared_array): should set NOEMBED flag for a copied
- array.
+ * array.c (rb_ary_store, rb_ary_splice): not depend on unspecified
+ behavior at integer overflow.
-Tue Oct 17 08:04:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * string.c (str_buf_cat): ditto.
- * string.c (rb_str_lines): now takes optional argument for the
- line separator.
+Wed Jun 18 22:25:10 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
- * io.c (rb_io_lines, rb_io_bytes): new methods.
+ * 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
-Mon Oct 16 23:33:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * 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
- * array.c (rb_ary_unshift_m): a bug in lfree shift length
- calculation.
+ * sprintf.c (rb_str_format): backported from trunk.
-Mon Oct 16 08:30:43 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * intern.h: ditto.
- * mkconfig.rb: *OBJS are not needed for extension libraries.
+Fri Jun 20 01:40:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * {bcc32,wince,win32}/Makefile.sub (config.status): fixed typo,
- missing comma.
+ * 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]
-Mon Oct 16 00:44:26 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Jun 18 15:20:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * pack.c (pack_unpack): execute block if given with unpacked value
- instead of creating an array. an idea from Tim Bray.
+ * marshal.c (w_object, marshal_dump, r_object0, marshal_load): search
+ public methods only. [ruby-core:17283]
-Sun Oct 15 01:03:08 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * object.c (convert_type): ditto.
- * lib/test/unit/collector/dir.rb (Collector::Dir#collect): append base
- directory but not prepend.
+ * lib/singleton.rb (Singleton#_dump): conversion method should be
+ public.
- * lib/test/unit/collector/dir.rb (Collector::Dir#collect_file): do not
- join with dot. fixed: [ruby-core:09179]
+Wed Jun 18 13:19:55 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
-Sat Oct 14 23:39:50 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * file.c: fixes to compile on mswin32. Patch from U. Nakamura
+ <usa at garbagecollect.jp>. [ruby-dev:35127]
- * parse.y (singleton): no need to re-create NODE_SELF() again.
- [ruby-core:09177]
+Tue Jun 17 22:16:44 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Oct 14 23:25:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * configure.in (LIBPATHFLAG, RPATHFLAG): no needs to be quoted,
+ it is done by libpathflag in mkmf.rb.
- * parse.y (parser_warning, parser_warn): some error message may
- contain format specifiers. a patch from Akinori MUSHA <knu at
- iDaemons.org>. [ruby-dev:29657]
+Mon Jun 16 15:43:07 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * regparse.c (onig_rb_warning, onig_rb_warn): ditto.
+ * proc.c (proc_dup): should copy safe_level from src proc
+ properly. a patch from Keita Yamaguchi
+ <keita.yamaguchi at gmail.com>
- * ext/bigdecimal/bigdecimal.c (VpException): ditto.
+Sun Jun 15 23:31:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/dl/handle.c (rb_dlhandle_initialize): ditto.
+ * ext/zlib/extconf.rb: search zlib1, and regard mswin32 later than VC6
+ as WIN32. [ruby-core:16984]
- * ext/gdbm/gdbm.c (rb_gdbm_fatal): ditto.
+Sun Jun 15 23:28:15 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Oct 14 08:15:42 2006 Akinori MUSHA <knu@iDaemons.org>
+ * marshal.c (w_object, marshal_dump, r_object0, marshal_load): search
+ private methods too. [ruby-dev:34671]
- * ext/digest/digest.c, ext/digest/digest.h,
- ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
- ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
- Introduce API versioning.
+ * object.c (convert_type): ditto.
- * ext/digest/digest.c, ext/digest/digest.h,
- ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
- ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
- the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
- instance methods digest_length() and block_length(). Class
- methods with the same names are also provided, which take extra
- parameters for a digest method.
+Sun Jun 15 23:26:50 2008 Akinori MUSHA <knu@iDaemons.org>
- * ext/digest/lib/digest/hmac.rb: Completely redesign the somewhat
- bizarre API, now that Digest classes can take hashing
- parameters.
+ * numeric.c (flo_divmod): Revert the behavior change; do not
+ suppress an exception when div is NaN or Inf. [ruby-dev:34857]
-Sat Oct 14 05:54:05 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 15 23:24:32 2008 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/digest/digest.c: Improve RDoc documentation further more.
+ * file.c (BUFCHECK): wrong condition. [ruby-core:16921]
-Sat Oct 14 04:33:33 2006 Akinori MUSHA <knu@iDaemons.org>
+ * file.c (file_expand_buf): shouldn't use buflen for length of string.
- * ext/digest/digest.c: Improve RDoc documentation.
+Sun Jun 15 23:21:22 2008 Akinori MUSHA <knu@iDaemons.org>
- * ext/digest/digest.c (Init_digest, rb_digest_base_s_digest,
- rb_digest_base_s_hexdigest): Make Digest::Base::digest() and
- Digest::Base::hexdigest() take extra arguments, which are passed
- through to the constructor in an internal call.
+ * marshal.c (r_object0, Init_marshal): Fix the garbled s_call
+ definition; fixes [ruby-dev:34843].
- * ext/digest/bubblebabble/bubblebabble.c
- (rb_digest_base_s_bubblebabble): Ditto for
- Digest::Base::bubblebabble().
+Sun Jun 15 23:19:53 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-Sat Oct 14 00:55:08 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * object.c (rb_cstr_to_dbl): should clear errno before calling
+ strtod(3). [ruby-dev:34834]
- * bcc32/Makefile.sub (post-install-ext): no longer needed.
+Sun Jun 15 23:18:15 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * bcc32/configure.bat: get rid of a quirk of Borland make, which
- sets empty macro in command line to "1".
+ * marshal.c (marshal_load): should initialize arg.data used for
+ reentrant check. [ruby-dev:34837]
-Fri Oct 13 22:49:02 2006 Tadayoshi Funaba <tadf@dotrb.org>
+Sun Jun 15 23:13:23 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/date.rb: updated based on date2 3.9.5.
+ * 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>
-Fri Oct 13 21:00:01 2006 Akinori MUSHA <knu@iDaemons.org>
+ * marshal.c (reentrant_check): check reentrance via callcc.
+ [ruby-dev:34802]
- * ext/digest/lib/digest.rb (Digest): Try to auto-load non-standard
- digest modules when a specified digest class is missing.
- * ext/digest/lib/digest.rb: Define Digest(name) for ease of
- dynamically selecting a hashing algorithm.
+Sun Jun 15 23:09:00 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-Fri Oct 13 20:53:37 2006 Akinori MUSHA <knu@iDaemons.org>
+ * sprintf.c (rb_f_sprintf): fixed SEGV on win32 with "% 0e" % 1.0/0.0.
- * ext/digest/digest.c (Init_digest): Digest::Base.new() does no
- longer take an initial string to feed. This change allows
- subclasses to take hashing parameters. A statement such as
- ``md = Digest::MD5.new(s)'' can be easily rewritten as
- ``md = Digest::MD5.new << s'' or
- ``md = Digest::MD5.new.update(s)''.
+Sun Jun 15 23:07:46 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-Fri Oct 13 20:51:55 2006 Akinori MUSHA <knu@iDaemons.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>
- * ext/digest/digest.c, ext/digest/md5/md5init.c,
- ext/digest/rmd160/rmd160init.c, ext/digest/sha1/sha1init.c,
- ext/digest/sha2/sha2init.c: Add RDoc documentation.
+Sun Jun 15 23:02:12 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * ext/digest/digest.txt, ext/digest/digest.txt.ja: Removed in
- favor of embedded RDoc documentation.
+ * 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.
-Fri Oct 13 20:38:12 2006 Akinori MUSHA <knu@iDaemons.org>
+ * lib/webrick/httpservlet/abstract.rb
+ (WEBrick::HTTPServlet::AbstracServlet#redirect_to_directory_uri):
+ should escape the value of Location: header.
- * ext/digest/bubblebabble, ext/digest/digest.c: Rip BubbleBabble
- support out of the base class and have a separate module named
- digest/bubblebabble.
+ * lib/webrick/httpservlet/cgi_runner.rb: accept interpreter
+ command line arguments.
-Fri Oct 13 19:53:59 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 15 23:02:12 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/digest.c (rb_digest_base_equal): Again, should call
- digest() of a subclass instead of the one defined in the base
- class.
+ * file.c (file_expand_path): support for alternative data stream
+ and ignored trailing garbages of NTFS.
-Fri Oct 13 18:19:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * file.c (rb_file_s_basename): ditto.
- * object.c: Class#inherited RDoc added. a patch from Daniel
- Berger <djberg96 at gmail.com> [ruby-core:08942]
+ * file.c (rb_file_s_extname): ditto.
-Fri Oct 13 02:42:00 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 15 22:53:20 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/digest/digest.c (rb_digest_base_equal): Should call digest()
- of a subclass instead of the one defined in the base class.
+ * string.c (rb_str_cat): fixed buffer overrun reported by
+ Christopher Thompson <cthompson at nexopia.com> in [ruby-core:16746]
-Fri Oct 13 02:30:12 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Jun 15 22:51:24 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/test/unit/collector/dir.rb (Collector::Dir#collect): prepend
- base directory to load path.
+ * eval.c (is_defined): add NODE_OP_ASGN_{OR,AND}. "defined?(a||=1)"
+ should not operate assignment. [ruby-dev:34645]
- * lib/test/unit/collector/dir.rb (Collector::Dir#collect_file): should
- use the given File-like interface, but not File directly.
+Sun Jun 15 22:49:45 2008 NAKAMURA Usaku <usa@ruby-lang.org>
- * test/testunit/collector/test_dir.rb (TestDir::FileSystem): implement
- File-like methods correctly.
+ * win32/win32.c (rb_w32_select): backport from trunk.
+ [ruby-talk:300743]
-Fri Oct 13 01:48:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 15 22:48:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/date.rb (Date::self.complete_hash): need to check if g is
- nil before dereference. [ruby-core:09116]
+ * lib/delegate.rb (SimpleDelegator::dup): removed needless argument.
+ [ruby-list:44910]
-Fri Oct 13 01:05:58 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/delegate.rb (clone, dup): keep relationship with the target
+ object.
- * string.c (rb_str_partition): RDoc update. a patch from
- Mauricio Fernandez <mfp at acm.org>. [ruby-core:09160]
+Sun Jun 15 22:46:34 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * hash.c (rb_hash_compare_by_id): ditto.
+ * 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]
-Fri Oct 13 00:34:26 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 15 22:44:25 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * object.c (rb_mod_cvar_defined): wrong id check. a patch from
- Mauricio Fernandez <mfp at acm.org>. [ruby-core:09158]
+ * struct.c (rb_struct_s_def): to_str should be called only once.
+ [ruby-core:16647]
- * object.c (rb_mod_cvar_get): typo fixed. [ruby-core:09168]
+Sun Jun 15 22:42:54 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * object.c (rb_mod_cvar_set): ditto.
+ * ext/zlib/zlib.c (gzreader_gets): may cause infinite loop.
+ a patch from Kouya <kouyataifu4 at gmail.com> in
+ [ruby-reference-manual:762].
-Thu Oct 12 22:58:11 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 15 22:34:09 2008 James Edward Gray II <jeg2@ruby-lang.org>
- * hash.c (rb_hash_compare_by_id): somehow we lost renaming from
- Hash#identical. [ruby-core:09163]
+ Merged 16241 from trunk.
-Thu Oct 12 18:25:40 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * 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.
- * ext/tk/tkutil/tkutil.c (cbsubst_table_setup): need to handle new
- character literal (1 char string).
+Sun Jun 15 22:31:47 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/mkmf.rb: shut up some warnings from tk's extconf.rb.
+ * re.c (rb_reg_search): use local variable. a patch from wanabe
+ <s.wanabe AT gmail.com> in [ruby-dev:34537]. [ruby-dev:34492]
-Thu Oct 12 02:15:24 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 15 22:20:45 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/digest/lib/digest/hmac.rb: Make use of String#bytes.
+ * sprintf.c (rb_f_sprintf): should protect temporary string from
+ GC. [ruby-dev:34480]
-Thu Oct 12 02:12:31 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 15 22:18:30 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/digest/digest.c (get_digest_base_metadata): Use an instance
- variable of a class object instead of a class variable for
- metadata. This change is only crucial for ruby 1.8 because
- class variables are inherited to subclasses prior to 1.9, but
- applying it also to 1.9 will assure compatibilities.
+ * regex.c (re_search): string might be NULL. [ruby-core:16478]
- * ext/digest/md5/md5init.c (Init_md5): Ditto.
+Sun Jun 15 22:16:21 2008 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/digest/rmd160/rmd160init.c (Init_rmd160): Ditto.
+ * time.c (rb_strftime): check errno to detect strftime(3)'s error.
+ this is workaround for recent version of MSVCRT.
+ [ruby-dev:34456]
- * ext/digest/sha1/sha1init.c (Init_sha1): Ditto.
+Sun Jun 15 22:12:07 2008 Akinori MUSHA <knu@iDaemons.org>
- * ext/digest/sha2/sha2init.c (Init_sha2): Ditto.
+ * lib/yaml/types.rb: Likewise, pass self to YAML::quick_emit;
+ merged from 1.9.
-Wed Oct 11 21:36:47 2006 Akinori MUSHA <knu@iDaemons.org>
+ * 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.
- * ext/digest/digest.c (rb_digest_base_alloc,
- rb_digest_base_equal): Simplify the equality check and just
- compare resulted digests since state-level equality should
- not be so significant.
+Sun Jun 15 22:09:02 2008 Akinori MUSHA <knu@iDaemons.org>
- * ext/digest/digest.h: Ditto.
+ * ext/syck/rubyext.c: Node#value defined twice.
- * ext/digest/*/*.[ch]: Ditto.
+ * lib/yaml/: several method redefinitions causing warnings.
-Wed Oct 11 17:11:03 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 15 22:04:44 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * eval.c (rb_obj_define_method): add half boiled RDoc document.
+ * 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].
-Wed Oct 11 16:57:46 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 15 21:59:22 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * array.c (rb_ary_replace): should shift lfree pointer before
- calling xfree.
+ * re.c (rb_reg_quote): should always copy the quoting string.
+ [ruby-core:16235]
-Wed Oct 11 15:07:42 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 15 21:27:46 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/digest/lib/digest/hmac.rb: Add digest/hmac, which implements
- HMAC keyed-hashing algorithm.
+ * lib/net/pop.rb (Net::POP3::do_finish): clear @n_mails and
+ @n_bytes as well. [ruby-core:16144]
-Wed Oct 11 15:03:55 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 15 21:08:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/digest.c (rb_digest_base_reset): Do not make
- recursive calls, but call initialize() when reset() is not
- defined in a subclass.
+ * lib/resolv.rb (Resolv::Config.default_config_hash): requires
+ win32/resolv to use Win32::Resolv. [ruby-dev:34138]
-Wed Oct 11 14:56:10 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 15 20:54:07 2008 Akinori MUSHA <knu@iDaemons.org>
- * ext/digest/sha1/sha1ossl.h: libssl 0.9.8c-3 defines no
- SHA_BLOCK_LENGTH.
+ * 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.
-Wed Oct 11 14:03:31 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 15 20:30:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/digest.c (rb_digest_base_reset, Init_digest): Add
- Digest::Base#reset.
+ * lib/resolv.rb (Resolv::Hosts): should not use win32/resolv on cygwin.
+ [ruby-dev:29945], [ruby-dev:34095]
- * ext/digest/digest.h: Update the header comment.
+ * lib/win32/registry.rb (Win32::Registry.expand_environ): try upcased
+ name too for cygwin. [ruby-dev:29945]
- * ext/digest/md5/md5ossl.h, ext/digest/md5/md5init.c (Init_md5):
- Define DIGEST_LENGTH and BLOCK_LENGTH.
+ * lib/win32/resolv.rb (Win32::Resolv.get_hosts_path): use expand_path.
- * ext/digest/rmd160/rmd160init.c (Init_rmd160): Ditto.
+Sun Jun 15 20:27:59 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/sha1/sha1init.c (Init_sha1): Ditto.
+ * 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]
- * ext/digest/sha2/sha2init.c (Init_sha2): Ditto.
+Sun Jun 15 20:20:59 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/depend, ext/digest/extconf.rb: Use $INSTALLFILES
- rather than adding make targets. [Pointed out by: nobu]
+ * numeric.c (fix_coerce): try conversion before type check.
+ [ruby-core:15838]
-Tue Oct 10 16:39:08 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 15 19:56:53 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/digest.c (hexdigest_str_new, bubblebabble_str_new):
- Perform StringValue() checks properly.
+ * bignum.c (BIGZEROP): fix for longer Bignum zeros. [ruby-Bugs-17454]
-Tue Oct 10 13:21:21 2006 Akinori MUSHA <knu@iDaemons.org>
+Sun Jun 15 19:54:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/sha1/depend, ext/digest/sha2/depend: Remove obsolete
- dependencies.
+ * bignum.c (big2str_find_n1): check integer overflow.
-Mon Oct 9 23:46:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 15 19:52:20 2008 Tanaka Akira <akr@fsij.org>
- * lib/parsedate.rb: documentation patch from Konrad Meyer
- <konrad.meyer@gmail.com>. [ruby-doc:1238]
+ * gc.c (STACK_LENGTH) [SPARC] : 0x80 offset removed. [ruby-dev:33857]
- * lib/open3.rb, lib/ping.rb: ditto.
+Sun Jun 15 19:50:20 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Mon Oct 9 23:40:58 2006 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].
- * ext/extmk.rb, lib/fileutils.rb, lib/mkmf.rb, lib/optparse.rb,
- lib/shellwords.rb: get rid of shadowing outer local variable.
+Sun Jun 15 19:44:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Mon Oct 9 22:56:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * parse.y (yycompile): clear ruby_eval_tree_begin if parse failed.
- * lib/rexml/encoding.rb (REXML::Encoding::check_encoding): spaces
- are allowed around equal sign. [ruby-core:09032]
+Sun Jun 15 19:44:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/rexml/parsers/baseparser.rb (REXML::Parsers::BaseParser): ditto.
+ * parse.y (yycompile): clear ruby_eval_tree_begin too before parse.
-Mon Oct 9 01:56:34 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 15 19:22:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (rb_obj_define_method): add new method
- Kernel#define_singleton_method. [ruby-list:42851]
+ * ext/pty/lib/expect.rb (IO#expect): check if peer is closed.
+ [ruby-Bugs-17940]
-Sat Oct 7 23:53:08 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 15 19:20:13 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * string.c (rb_str_scan): small documentation fix.
- [ruby-core:09007]
+ * ext/iconv/iconv.c (iconv_convert): check upper bound. a patch from
+ Daniel Luz at [ruby-Bugs-17910].
-Sat Oct 7 23:44:33 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 15 19:13:46 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * bignum.c (rb_big_rshift): a bug in right shift of negative
- bignums. [ruby-core:09020]
+ * configure.in (ftruncate): check if available.
-Sat Oct 7 23:33:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * file.c (rb_file_truncate): check if ftruncate instead of truncate.
- * eval.c (formal_assign): packed post splat arguments may conflict
- with normal arguments. [ruby-core:09021]
+Sun Jun 15 19:02:46 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (rb_call0): ditto.
+ * configure.in (sigsetmask): check when signal semantics is not POSIX.
-Sat Oct 7 11:53:04 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * signal.c (USE_TRAP_MASK): set true if sigprocmask or sigsetmask is
+ available.
- * object.c (rb_mod_initialize): since module_eval no longer passes
- self, use module_exec instead. fixed: [ruby-dev:29637]
+Sat Jun 14 16:49:41 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Oct 7 00:27:58 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/timeout.rb (Timeout::timeout): made sensitive to location on the
+ stack. [ruby-core:15458]
- * class.c (rb_include_module): remove unnecessary check.
- [ruby-talk:218402]
+Fri Jun 13 13:14:31 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Oct 6 15:19:59 2006 Akinori MUSHA <knu@iDaemons.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>
- * ext/digest/depend: Fix header installation when the build
- directory is different from srcdir. [Pointed out by: eban]
+ * class.c (clone_method): should copy cref as well.
+ [ruby-core:15833]
-Fri Oct 6 09:56:31 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ Yoshiki <ikoma@mb.i-chubu.ne.jp> in [ruby-dev:33776].
- * {bcc32,win32,wince}/Makefile.sub (config.status): shouldn't use
- copy command instead of install. use -run install.
+Fri Jun 13 13:13:23 2008 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
-Fri Oct 6 06:53:46 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * gc.c (rb_newobj): prohibit call of rb_newobj() during gc.
+ Submitted by Sylvain Joyeux [ruby-core:12099].
- * eval.c (rb_yield_0): small refactoring.
+ * 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 ].
- * parse.y (bparam_item): fixed bugs in handling parenthesized LHS.
+Fri Jun 13 12:10:13 2008 NARUSE, Yui <naruse@ruby-lang.org>
-Fri Oct 6 04:47:07 2006 Akinori MUSHA <knu@iDaemons.org>
+ * lib/benchmark.rb (Job::Benchmark#item): fix typo.
- * ext/digest/depend: Install digest.h.
+Fri Jun 13 12:06:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Fri Oct 6 04:27:40 2006 Akinori MUSHA <knu@iDaemons.org>
+ * ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): use strtod() for more
+ precision. [ruby-talk:290296]
- * ext/digest/lib/md5.rb, ext/digest/lib/sha1.rb: Remove those
- compatibility stub libraries.
+ * ext/bigdecimal/bigdecimal.c (BASE_FIG): made constant.
- * sample/openssl/c_rehash.rb: Use digest/md5 instead of obsolete md5.
+ * ext/bigdecimal/extconf.rb: ditto. [ruby-dev:33658]
-Fri Oct 6 04:09:51 2006 Akinori MUSHA <knu@iDaemons.org>
+Fri Jun 13 12:01:57 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/digest.c: Make hexdigest() always call digest() internally.
+ * lib/irb.rb (IRB::Irb::eval_input): rescues Interrupt and other than
+ SystemExit and SignalException. [ruby-core:15359]
- * ext/digest/digest.c: Add bubblebabble().
+Fri Jun 13 11:57:46 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Oct 6 02:38:42 2006 Akinori MUSHA <knu@iDaemons.org>
+ * lib/benchmark.rb (Benchmark::realtime): make Benchmark#realtime
+ a bit faster. a patch from Alexander Dymo <dymo@ukrpost.ua> in
+ [ruby-core:15337].
- * ext/digest/digest.c: Allow subclassing in Ruby.
+Fri Jun 13 11:50:59 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Oct 6 02:06:10 2006 Akinori MUSHA <knu@iDaemons.org>
+ * io.c (rb_open_file): should check NUL in path.
+ <http://www.rubyist.net/~matz/20080125.html#c01>.
- * ext/digest/digest.c (hexdigest_str_new): Add a string size check.
+ * io.c (rb_io_s_popen): ditto.
-Thu Oct 5 19:28:35 2006 Akinori MUSHA <knu@iDaemons.org>
+ * io.c (rb_io_reopen): ditto.
- * ext/digest/digest.[ch]: Since the argument order of
- hash_final_func_t was inconsistent with others, change it and
- rename to hash_finish_func_t to avoid confusion.
+ * io.c (next_argv): ditto.
- * ext/digest/digest.[ch]: Remove and eliminate the use of
- hash_end_func_t. Implement hexdigest conversion in the base
- class.
+ * io.c (rb_io_s_foreach): ditto.
- * ext/digest/md5/md5.c, ext/digest/md5/md5.h,
- ext/digest/md5/md5init.c, ext/digest/md5/md5ossl.c,
- ext/digest/md5/md5ossl.h: Remove MD5_End() and change
- MD5_Final() to MD5_Finish().
+ * io.c (rb_io_s_readlines): ditto.
- * ext/digest/rmd160/depend, ext/digest/rmd160/extconf.rb,
- ext/digest/rmd160/rmd160.c, ext/digest/rmd160/rmd160.h,
- ext/digest/rmd160/rmd160hl.c, ext/digest/rmd160/rmd160init.c,
- ext/digest/rmd160/rmd160ossl.c, ext/digest/rmd160/rmd160ossl.h:
- Remove unused functions RMD160_End(), RMD160_File(),
- RMD160_Data() and change RMD160_Final() to RMD160_Finish().
+ * io.c (rb_io_s_read): ditto.
- * ext/digest/sha1/extconf.rb, ext/digest/sha1/sha1.c,
- ext/digest/sha1/sha1.h, ext/digest/sha1/sha1hl.c,
- ext/digest/sha1/sha1init.c, ext/digest/sha1/sha1ossl.c,
- ext/digest/sha1/sha1ossl.h: Likewise.
+Wed Jun 11 15:23:13 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/digest/sha2/extconf.rb, ext/digest/sha2/sha2.c,
- ext/digest/sha2/sha2.h, ext/digest/sha2/sha2hl.c,
- ext/digest/sha2/sha2init.c: Likewise.
+ * lib/uri/generic.rb (URI::Generic::inspect): use Kernel#to_s instead
+ object_id with printf. [ruby-dev:33347]
-Wed Oct 4 18:47:25 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+Wed Jun 11 15:00:55 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/tk/lib/tkextlib/*: bugfix and update
- (see ext/tk/ChangeLog.tkextlib).
+ * configure.in: Remove wrong assumptions about Cygwin. a patch from
+ Corinna Vinschen in [ruby-Bugs-17018].
-Wed Oct 4 17:25:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Jun 9 18:09:20 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (rb_call): check protected visibility based on real self,
- not ruby_frame->self. [ruby-talk:217822]
+ * eval.c (eval): check if backtrace is empty. [ruby-core:15040]
-Wed Oct 4 15:46:32 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 8 06:08:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * parse.y (block_param): should interpret single parenthesized
- left hand side expression.
+ * eval.c (rb_define_alloc_func, rb_undef_alloc_func): should
+ define/undef on a signleton class. [ruby-core:09959]
-Wed Oct 4 08:52:30 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Jun 8 06:04:41 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * test/optparse/test_getopts.rb: changed the class name of test case
- to get rid of conflict with test_optparse.rb.
+ * time.c (time_arg): use converted object. [ruby-core:14759]
-Tue Oct 3 21:04:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 8 06:02:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * parse.y (dyna_in_block): inline using macro.
+ * io.c (fptr_finalize): clear errno first. [ruby-talk:284492]
- * parse.y (mlhs): simplifies the rule a bit.
+Sun Jun 8 05:59:36 2008 Tadayoshi Funaba <tadf@dotrb.org>
- * parse.y (block_param): restrict block parameters to be local
- variables only.
+ * lib/date.rb: don't freeze nil even if 1.8 will not be aware of
+ the issue. [ruby-dev:32677]
- * test/ruby/test_iterator.rb (TestIterator::test_nested_iterator):
- update test suite to conform the last change.
+Sun Jun 8 05:54:44 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Tue Oct 3 02:31:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * configure.in (TIMEZONE_VOID): check whether timezone requires zero
+ arguments. [ruby-dev:32631]
- * eval.c (splat_value): use "to_splat" instead of "to_ary" to
- prepare splat values as an array.
+Sun Jun 8 05:37:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * array.c (Init_Array): define to_splat.
+ * parse.y (f_rest_arg): check if duplicated. [ruby-core:14140]
- * range.c (range_to_splat): new method.
+Sun Jun 8 05:32:45 2008 Tanaka Akira <akr@fsij.org>
- * enumerator.c (enumerator_to_splat): ditto.
+ * 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).
-Tue Oct 3 01:36:47 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 8 05:24:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * string.c (rb_str_lines): returns an Enumerator instead of an
- array of lines.
+ * configure.in (RUBY_CHECK_VARTYPE): check if a variable is defined
+ and its type.
- * string.c (rb_str_bytes): a new method.
+ * configure.in (timezone, altzone): check for recent cygwin.
-Mon Oct 2 23:47:55 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * missing/strftime.c (strftime): fix for timezone. [ruby-dev:32536]
- * lib/test/unit/autorunner.rb (Test::Unit::AutoRunner::COLLECTORS):
- base directory should be lower precedence. fixed: [ruby-dev:29622]
+ * lib/mkmf.rb (try_var): should fail for functions.
- * lib/test/unit/autorunner.rb (Test::Unit::AutoRunner#options): typo.
+ * ext/readline/extconf.rb: should use have_func for functions instead
+ of have_var.
- * lib/test/unit/collector/dir.rb (Test::Unit::Collector::Dir#collect_file):
- load expanded path. fixed: [ruby-dev:29621]
+Sun Jun 8 05:08:35 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Mon Oct 2 15:47:55 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * lib/cgi.rb (read_multipart): exclude blanks from header values.
+ [ruby-list:44327]
- * instruby.rb: batfile should be CRLF'ed.
+Sun Jun 8 05:02:25 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Mon Oct 2 01:24:26 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * bignum.c (rb_cstr_to_inum): trailing spaces may exist at sqeezing
+ preceeding 0s. [ruby-core:13873]
- * common.mk (test-all): separate directory where running test cases
- from source tree.
+Sun Jun 8 04:58:05 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/test/unit/autorunner.rb (options): added --basedir, --workdir
- and --load-path options.
+ * eval.c (error_print): put newline unless multiple line message ends
+ with a newline. [ruby-dev:32429]
- * lib/test/unit/collector/dir.rb (recursive_collect, collect_file):
- base directory support.
+Sun Jun 8 04:55:26 2008 James Edward Gray II <jeg2@ruby-lang.org>
-Sun Oct 1 23:56:52 2006 Nobuyoshi Nakada <nobu@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.
- * Makefile.in, common.mk, ext/extmk.rb, win{32,ce}/Makefile.in: keep
- LIBRUBY_SO unless need to be removed.
+Sun Jun 8 04:49:43 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sun Oct 1 23:12:19 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * parse.y (newline_node): set line from outermost node before removing
+ NODE_BEGIN. [ruby-dev:32406]
- * lib/optparse.rb (OptionParser#make_switch): pass arguments directly.
+Sun Jun 8 04:37:34 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Sep 30 15:11:26 2006 Tadayoshi Funaba <tadf@dotrb.org>
+ * parse.y (stmt): remove unnecessary NODE_BEGIN. [ruby-core:13814]
- * lib/date.rb, lib/date/format.rb: updated based on date2 3.9.4.
+Sun Jun 8 04:16:35 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Fri Sep 29 13:18:24 2006 Akinori MUSHA <knu@iDaemons.org>
+ * eval.c (rb_alias): do not call hook functions until initialization
+ finishes. [ruby-talk:279538]
- * ext/digest/lib/digest.rb (Digest): Require digest.so and fix the
- breakage. Point out by NAKAMURA Usaku in [ruby-dev:29619].
+Sun Jun 8 04:14:16 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-Fri Sep 29 12:11:04 2006 WATANABE Hirofumi <eban@ruby-lang.org>
+ * ext/win32ole/win32ole.c (ole_invoke): bug fix. [ruby-talk:279100]
- * jcode.rb (succ!): call original succ! if $KCODE == 'n'.
- fixed: [ruby-talk:216845]
+Sun Jun 8 03:59:31 2008 NAKAMURA Usaku <usa@ruby-lang.org>
-Fri Sep 29 11:43:40 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/curses/extconf.rb: check macro if cannot find func.
+ [ruby-list:44224]
- * lib/mkmf.rb (try_func): revert fallback checking undeclared function.
- fixed: [ruby-core:08949]
+Sun Jun 8 03:52:53 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Sep 29 09:56:56 2006 Nobuyoshi Nakada <nobu@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]
- * ext/extmk.rb: extout is needed for also clean.
- fixed: [ruby-core:08944]
+Sun Jun 8 03:49:15 2008 Tanaka Akira <akr@fsij.org>
- * lib/optparse.rb (OptionParser::Switch#conv_arg): unsplat by
- Proc#call if no conversion is given.
+ * missing/isinf.c (isinf): don't define if the macro is defined.
-Thu Sep 28 23:59:31 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Jun 8 03:42:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * node.h (struct thread): declare win32_exception_list on cygwin and
- win32 regardless if it is implemented. Provisional fix for
- [ruby-core:08917].
+ * numeric.c (round): fallback definition.
-Thu Sep 28 20:49:20 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * numeric.c (flo_divmod, flo_round): use round() always.
+ [ruby-dev:32269]
- * lib/tmpdir.rb: use return value of getdir.call for length.
+Sun Jun 8 03:42:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Wed Sep 27 22:08:16 2006 Akinori MUSHA <knu@iDaemons.org>
+ * numeric.c (flodivmod): work around for infinity.
- * ext/digest/md5/md5init.c (Init_md5): Now that we have digest.rb,
- require "digest" rather than "digest.so".
+ * numeric.c (flo_divmod): work around for platforms have no round().
+ [ruby-dev:32247]
- * ext/digest/rmd160/rmd160init.c (Init_rmd160): Ditto.
+Sun Jun 8 03:42:10 2008 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
- * ext/digest/sha1/sha1init.c (Init_sha1): Ditto.
+ * numeric.c (flo_divmod): round to the nearest integer.
+ [ ruby-Bugs-14540 ]
- * ext/digest/sha2/sha2init.c (Init_sha2): Ditto.
+Sun Jun 8 03:28:53 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
-Wed Sep 27 21:21:08 2006 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]
- * string.c (rb_str_startwith): rename startwith? to start_with?,
- endwith? to endwith?, respectively. [ruby-talk:216685]
+Sun Jun 8 03:07:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Wed Sep 27 13:29:01 2006 Yukihiro Matsumoto <matz@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].
- * lib/cgi.rb (CGI::TagMaker::nOE_element_def): replace to_s by
- join. some other methods as well. [ruby-dev:29613]
+Sun Jun 8 03:04:38 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Wed Sep 27 01:04:49 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * numeric.c (fix_pow): returns infinity for 0**-1. [ruby-dev:32084]
- * lib/mkmf.rb (try_func): check function pointer first and macro next.
+Sun Jun 8 02:58:19 2008 James Edward Gray II <jeg2@ruby-lang.org>
- * lib/mkmf.rb (have_type): simplified with typedef and sizeof.
+ Merged 13781 from trunk.
-Wed Sep 27 00:08:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/net/telnet.rb (Net::Telnet#login): Allowing "passphrase" in
+ addition to "password" for Telnet login prompts. [ruby-Bugs-10746]
- * array.c (rb_ary_shift): shift/unshift performance boost patch,
- based on the patch from Eric Mahurin <eric_mahurin at yahoo.com>.
- [ruby-core:05861]
+Wed Oct 25 06:46:21 2007 James Edward Gray II <jeg2@ruby-lang.org>
- * array.c (rb_ary_unshift_m): ditto.
+ Merged 13779 from trunk.
- * array.c (ary_make_shared): ditto.
+ * lib/net/telnet.rb (Net::Telnet#login): Making the password prompt
+ pattern case insensitive. [ruby-Bugs-10746]
- * array.c (RESIZE_CAPA): ditto.
+Sun Jun 8 02:55:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * array.c (rb_ary_free): new function to free memory. code moved
- from gc.c.
+ * io.c (rb_io_tell, rb_io_seek): check errno too. [ruby-dev:32093]
- * string.c (rb_str_free): ditto.
+Sun Jun 8 01:53:50 2008 James Edward Gray II <jeg2@ruby-lang.org>
-Tue Sep 26 23:57:03 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ Merged 13767, 13768, 13769, and 13770 from trunk.
- * lib/optparse.rb (OptionParser#getopts): use strings as key.
- fixed: [ruby-dev:29614]
+ * 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]
-Tue Sep 26 15:29:55 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * lib/xmlrpc/client.rb (XMLRPC::Client#do_rpc): Explicitly start
+ the HTTP connection to support keepalive requests. [ruby-Bugs-9353]
- * {win32,wince}/Makefile.sub (CPP): check predefined value.
+ * lib/xmlrpc/client.rb (XMLRPC::Client#do_rpc): Improving the error
+ message for Content-Type check failures. [ruby-core:12163]
-Tue Sep 26 07:55:16 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/xmlrpc/utils.rb (XMLRPC::ParseContentType#parse_content_type):
+ Making Content-Type checks case insensitive. [ruby-Bugs-3367]
- * array.c (rb_ary_shift): should not move memory region if array
- body is shared. a patch from Kent Sibilev <ksruby at gmail.com>.
- [ruby-core:08922]
+Sun Jun 8 01:50:07 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Mon Sep 25 23:10:46 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * marshal.c (r_bytes0): refined length check. [ruby-dev:32059]
- * dir.c (rb_push_glob): need not to check by FilePathValue().
- [ruby-dev:29599]
+Sun Jun 8 01:50:07 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * dir.c (dir_globs): ditto.
+ * marshal.c (r_bytes0): check if source has enough data.
+ [ruby-dev:32054]
-Mon Sep 25 22:26:26 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Jun 8 01:41:19 2008 Tanaka Akira <akr@fsij.org>
- * file.c (rb_path_end): skip root directory. fixed: [ruby-core:08913]
+ * ext/socket/socket.c (s_accept_nonblock): make accepted fd
+ nonblocking. [ruby-talk:274079]
- * lib/mkmf.rb (rm_f): get rid of NUL.
+Sun Jun 8 01:36:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/mkmf.rb (init_mkmf): set default $LDFLAGS. Patch by Michal
- Suchanek <hramrach at centrum.cz>. [ruby-talk:216256]
+ * configure.in (AC_SYS_LARGEFILE): keep results also in command
+ options, to vail out of mismatch. [ruby-list:44114]
-Mon Sep 25 15:06:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * mkconfig.rb, lib/mkmf.rb (configuration): add DEFS.
- * sample/test.rb: "print nil" now prints empty string.
+Sun Jun 8 01:31:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * test/ruby/test_system.rb (TestSystem::test_system): ditto.
+ * win32/mkexports.rb: deal with __fastcall name decorations.
+ [ruby-list:44111]
-Mon Sep 25 11:26:25 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 8 01:27:06 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * hash.c (recursive_hash): remove unused local variable.
+ * {bcc,win}32/mkexports.rb: explicit data. [ruby-list:44108]
- * parse.y (parser_yylex): ditto.
+Sun Jun 8 01:15:50 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * parse.y (rb_gc_mark_symbols): fix unmatched prototype .
+ * lib/net/http.rb, lib/open-uri.rb: remove
+ Net::HTTP#enable_post_connection_check. [ruby-dev:31960]
- * file.c (rb_get_path): check NUL byte in the path string.
+ * lib/net/imap.rb: hostname should be verified against server's
+ indentity as persented in the server's certificate. [ruby-dev:31960]
-Mon Sep 25 08:14:43 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/openssl/lib/net/telnets.rb, ext/openssl/lib/net/ftptls.rb: ditto.
- * array.c (rb_ary_shift): should clear shifting top element.
- [ruby-talk:216055]
+Thu Jun 5 16:21:16 2008 NAKAMURA Usaku <usa@ruby-lang.org>
- * array.c (rb_ary_shift): avoid creating shared object if array
- size is small.
+ * win32/win32.c (make_cmdvector): adjust escaped successive
+ double-quote handling. (merge from trunk)
-Mon Sep 25 08:11:35 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Thu Jun 5 12:26:45 2008 NAKAMURA Usaku <usa@ruby-lang.org>
- * random.c (rb_f_rand): RDoc typo fix. a patch from Frederick
- Cheung <fred at 82ask.com>. [ruby-talk:216047]
+ * win32/win32.c (init_env): initialize HOME and USER environment
+ variables unless set. [ruby-core:12328] (merge from trunk)
-Sun Sep 24 21:19:24 2006 Guy Decoux <ts@moulon.inra.fr>
+ * win32/win32.c (NtInitialize, getlogin): ditto.
- * gc.c (gc_mark_children): NODE_POSTEXE holds Ruby VALUE.
- [ruby-core:08912]
+ * configure.in, win32/Makefile.sub (LIBS): need to link shell32
+ library for SH* functions on mswin32 and mingw32.
-Sun Sep 24 22:28:20 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Jun 5 12:22:28 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * runruby.rb: extension library scripts moved into common directory.
+ * gc.c (id2ref): valid id should not refer T_VALUE nor T_ICLASS.
+ [ruby-dev:31911]
-Sun Sep 24 12:10:04 2006 Tadayoshi Funaba <tadf@dotrb.org>
+Wed Jun 4 16:41:19 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/date.rb, lib/date/format.rb: updated based on date2 3.9.3.
+ * Makefile.in (ext/extinit.o): use $(OUTFLAG) as well as other
+ objects. [ruby-Bugs-14228]
-Sun Sep 24 06:55:36 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Jun 3 16:15:27 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * io.c (rb_io_print): no special handling for nil as well as puts.
- fixed: [ruby-dev:29586]
+ * parse.y (yyerror): limit error message length. [ruby-dev:31848]
-Sun Sep 24 06:25:53 2006 why the lucky stiff <why@ruby-lang.org>
+ * regex.c (re_mbc_startpos): separated from re_adjust_startpos.
- * eval.c (rb_thread_save_context, rb_thread_restore_context):
- sandbox hook to save and restore sandbox state.
+Tue Jun 3 15:45:00 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (thread_no_ensure): added THREAD_NO_ENSURE thread flag.
+ * gc.c (os_obj_of, os_each_obj): hide objects to be finalized.
+ [ruby-dev:31810]
- * eval.c (rb_thread_kill_bang): Thread#kill! uses the above flag
- to circumvent ensure, in order to prevent endless loops.
- contributed by MenTaLguY. [ruby-core:08768]
+Wed Jun 4 19:16:40 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * eval.c (rb_thread_kill): fix Thread#kill docs, which returns
- the thread object in all cases.
+ * eval.c (remove_method): should not remove undef place holder.
+ [ruby-dev:31817]
- * node.h: expose the rb_jmpbuf_t and rb_thread_t structs, along
- with the thread flags. used by the sandbox extension.
+Tue Jun 3 15:22:47 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ruby.h: extern rb_eThreadError, so sandbox can swap it.
+ * process.c (struct rb_exec_arg): proc should be a VALUE.
-Sat Sep 23 21:34:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * process.c (rb_f_exec): suppress a warning.
- * lib/cgi.rb (CGI::QueryExtension::read_multipart): CGI content
- may be empty. a patch from Jamis Buck <jamis at 37signals.com>.
+ * process.c (rb_detach_process): cast for the platforms where size of
+ pointer differs from size of int.
-Sat Sep 23 20:54:28 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
+ * process.c (rb_f_exec, rb_f_system): should not exceptions after
+ fork. [ruby-core:08262]
- * oniguruma.h: Version 4.4.4
+Wed May 21 01:32:56 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * regexec.c: ditto.
+ * 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.
- * regcomp.c ditto.
+ * lib/webrick/httpservlet/abstract.rb
+ (WEBrick::HTTPServlet::AbstracServlet#redirect_to_directory_uri):
+ should escape the value of Location: header.
-Sat Sep 23 08:35:53 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/webrick/httpservlet/cgi_runner.rb: accept interpreter
+ command line arguments.
- * lib/rdoc/ri/ri_options.rb: prevent NameError. [ruby-dev:29597]
+Sun May 18 01:57:44 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Sep 23 01:02:57 2006 Tadayoshi Funaba <tadf@dotrb.org>
+ * file.c (isdirsep): backslash is valid path separator on cygwin too.
+ backported from 1.8 HEAD.
- * lib/date.rb, lib/date/format.rb: updated based on date2 3.9.2.
+Sat May 17 23:53:57 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Fri Sep 22 18:07:17 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * file.c (file_expand_path): fix for short file name on Cygwin.
- * string.c (rb_str_partition): no need to call rb_call_super(),
- since String is no longer includes Enumerable.
+Sat May 17 23:50:29 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Fri Sep 22 17:33:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * file.c (OpenFile): prevent conflict on Windows.
- * hash.c (rb_hash_eql): new method to be used by Hash.
+ * file.c (USE_NTFS): fixed merge miss.
- * hash.c (rb_hash_hash): ditto.
+Sat May 17 12:36:46 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Fri Sep 22 06:53:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * file.c (file_expand_path): rb_str_set_len is not backported.
- * bignum.c (rb_big_hash): use rb_memhash().
+Sat May 17 12:15:48 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * numeric.c (flo_hash): simplified. klass need not to affect
- resulting hash value.
+ * file.c (file_expand_path): support for alternative data stream
+ and ignored trailing garbages of NTFS.
-Fri Sep 22 02:06:26 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * file.c (rb_file_s_basename): ditto.
- * .cvsignore: ignore timestamp files and installed list file.
+ * file.c (rb_file_s_extname): ditto.
-Fri Sep 22 01:36:34 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat May 17 10:18:44 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
- * instruby.rb: include FileUtils unconditionally.
+ * re.c (rb_reg_search): need to free allocated buffer in re_register.
-Fri Sep 22 00:36:05 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Mar 3 23:34:13 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * numeric.c (Init_Numeric): fix_odd_p and fix_even_p are for Fixnum.
- patch from Ondrej Bilka <neleai at seznam.cz>. [ruby-core:08904]
+ * 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].
-Thu Sep 21 22:56:20 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/webrick/httpservlet/filehandler.rb: pathnames which have
+ not to be published should be checked case-insensitively.
- * common.mk (no-install): not install rdoc actually.
+Mon Dec 3 08:13:52 2007 Kouhei Sutou <kou@cozmixng.org>
- * common.mk (install-doc, no-install-doc): use instruby.rb.
+ * 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.
- * instruby.rb: rdoc installation.
+Sun Sep 23 21:57:25 2007 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * ext/extmk.rb: expand ruby executable names.
+ * 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>
-Thu Sep 21 20:19:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/net/open-uri.rb: use Net::HTTP#enable_post_connection_check to
+ perform SSL post connection check.
- * string.c (str_new3): embed shorter strings more eagerly.
+ * ext/openssl/lib/openssl/ssl.c
+ (OpenSSL::SSL::SSLSocket#post_connection_check): refine error message.
-Thu Sep 21 17:44:49 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Sep 23 07:49:49 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * string.c (rb_str_startwith): a new method to check if a string
- starts with given prefix.
+ * eval.c, intern.h, ext/thread/thread.c: should not free queue while
+ any live threads are waiting. [ruby-dev:30653]
- * string.c (rb_str_endwith): the opposite of String#startwith?.
+Sun Sep 23 06:05:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Thu Sep 21 16:29:02 2006 WATANABE Hirofumi <eban@ruby-lang.org>
+ * ext/stringio/stringio.c (strio_init): separate from strio_initialize
+ to share with strio_reopen properly. [ruby-Bugs-13919]
- * rubytest.rb: use each_line instead of each.
+Sun Sep 23 05:42:35 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
-Thu Sep 21 15:06:24 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rdoc/options.rb (Options::check_diagram): dot -V output
+ changed. [ ruby-Bugs-11978 ], Thanks Florian Frank.
- * numeric.c (int_odd_p): a new method to check even or odd.
- [RCR#337]
+Wed Sep 19 11:13:07 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
- * numeric.c (int_even_p): ditto.
+ * bignum.c (bigtrunc): RBIGNUM(x)->len may be zero. out of bound
+ access. [ruby-dev:31404]
-Thu Sep 21 13:55:07 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Sep 17 05:24:13 2007 Sylvain Joyeux <sylvain.joyeux@m4x.org>
- * ext/etc/etc.c (etc_getpwuid): uid integer should be wraped in
- uid_t value. [ruby-core:08897]
+ * 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 ]
- * ext/etc/etc.c (etc_getpwuid): uid_t may be bigger than plain
- 'int' type.
+ * test/thread/test_thread.rb (test_mutex_exception_handling):
+ test for above.
-Thu Sep 21 10:07:09 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Sep 17 05:01:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * string.c (rb_str_partition): RDoc typo fixed. [ruby-core:08898]
+ * runruby.rb: fix incomplete backport r12339.
- * string.c (rb_str_rpartition): fixed separation seek bug.
+Mon Sep 17 04:56:28 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Thu Sep 21 09:38:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * test/thread/test_thread.rb (test_local_barrier),
+ test/thread/lbtest.rb: test for [ruby-dev:30653].
- * string.c (rb_str_lines): new method to split a string into lines.
+Mon Sep 17 04:52:21 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
- * string.c (Init_String): Strings are no longer Enumerable. use
- each_line or lines method explicitly.
+ * ruby.c (proc_options): -W should be allowed in RUBYOPT
+ environment variable. [ruby-core:12118]
- * string.c (Init_String): remove each method. use each_lines.
+Mon Sep 17 04:37:10 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-Wed Sep 20 23:17:41 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * range.c (range_step): fixed integer overflow. [ruby-dev:31763]
- * common.mk (pre-install-doc): create data directory before install.
+Fri Sep 7 17:06:16 2007 Vincent Isambart <vincent.isambart@gmail.com>
- * lib/mkmf.rb (dir_re): fixed typo.
+ * eval.c (rb_thread_start_0): should unset time_thread_alive_p.
+ [ruby-talk:257219], [ruby-core:11542], [ruby-dev:31253]
- * lib/mkmf.rb (install_dirs): remove extra slash.
+Fri Sep 7 16:39:23 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-Wed Sep 20 22:41:45 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * array.c (rb_ary_subseq): need integer overflow check.
+ [ruby-dev:31736]
- * numeric.c (fix_mul): typo again. patch from Tadashi Saito
- <shiba at mail2.accsnet.ne.jp>. fixed: [ruby-core:08893]
+ * array.c (rb_ary_splice): ditto. [ruby-dev:31737]
-Wed Sep 20 19:32:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * array.c (rb_ary_fill): ditto. [ruby-dev:31738]
- * string.c (rb_str_partition): a new method to separate the string
- by a separator. taken from Python 2.5.
+ * string.c (rb_str_splice): integer overflow for length.
+ [ruby-dev:31739]
- * string.c (rb_str_rpartition): ditto.
+Fri Sep 7 16:33:23 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-Wed Sep 20 09:49:40 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * include/ruby/defines.h (flush_register_windows): call "ta 0x03"
+ even on Linux/Sparc. [ruby-dev:31674]
- * {bcc32,win32,wince}/Makefile.sub (INSTALLED_LIST): need to define
- this macro to install.
+Fri Sep 7 16:09:39 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-Wed Sep 20 09:43:10 2006 Shugo Maeda <shugo@ruby-lang.org>
+ * ext/win32ole/win32ole.c (ole_type_progid, reg_enum_key,
+ reg_get_val, ole_wc2mb): fix the bug. Thanks, arton.
+ [ruby-dev:31576]
- * lib/net/imap.rb: allow extra spaces in responses.
- Thanks, Tom Soderlund.
+Fri Sep 7 15:50:50 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-Wed Sep 20 09:25:39 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * eval.c (mnew): should preserve noex as safe_level.
- * ext/gdbm/gdbm.c: add RDoc documentation. a patch from Peter
- Adolphs <futzilogik at users dot sourceforge dot net>.
- [ruby-doc:1223]
+ * eval.c (rb_call0): tighten security check condition..
-Tue Sep 19 00:42:15 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Sep 7 15:43:43 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * object.c (rb_obj_ivar_defined, rb_mod_cvar_defined): new methods,
- Kernel#instance_variable_defined? and Module#class_variable_defined?.
- [ruby-dev:29587]
+ * ext/tk/tcltklib.c (Init_tcltklib): use rb_set_end_proc().
- * lib/date/format.rb (Date::Bag#method_missing): use new method,
- instance_variable_defined? to check if an instance variable is
- defined. fixed: [ruby-dev:29554]
- -- This didn't fix anything.
+Fri Sep 7 15:42:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Tue Sep 19 00:07:17 2006 Yukihiro Matsumoto <matz@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]
- * string.c (sym_eql): fail early to gain performance.
+Fri Sep 7 15:40:47 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * string.c (sym_hash): cache hash value in aux.shared if possible.
+ * sample/test.rb, test/ruby/test_system.rb(valid_syntax?): keep
+ comment lines first.
- * gc.c (rb_obj_id): no need to treat symbols specially.
+Wed Aug 22 12:40:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/fileutils.rb (FileUtils::FileUtils): singleton_methods() no
- longer return an array of strings, but of symbols.
+ * hash.c (rb_hash_delete_key): delete the entry without calling block.
- * lib/delegate.rb (DelegateClass): ditto.
+ * hash.c (rb_hash_shift): should consider iter_lev too.
-Mon Sep 18 15:29:21 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * hash.c (delete_if_i): use rb_hash_delete_key() so that the block
+ isn't called twice. [ruby-core:11556]
- * dir.c (dir_s_glob): restore GC protection volatile variable.
- [ruby-dev:29588]
+Sun Arg 12 03:56:30 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * re.c (rb_reg_regcomp): ditto.
+ * lib/rinda/tuplespace.rb: fix Rinda::TupleSpace keeper thread bug.
+ the thread is started too early. [ruby-talk:264062]
-Mon Sep 18 12:16:48 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * test/rinda/test_rinda.rb: ditto.
- * numeric.c (fix_mul): get rid of shift overflow.
+Wed Aug 22 12:31:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Mon Sep 18 10:47:49 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * configure.in (ac_cv_func_isinf): set yes also on OpenSolaris.
+ [ruby-Bugs-12859]
- * dir.c (dir_s_glob): remove unused variable.
+Wed Aug 22 12:30:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * math.c (math_log): ditto.
+ * lib/rexml/encodings/{ISO-8859-15,CP-1252}.rb: fixed invalid syntax.
- * re.c (rb_reg_regcomp): ditto.
+Wed Aug 22 12:29:36 2007 Tadayoshi Funaba <tadf@dotrb.org>
- * eval.c (break_jump): ditto.
+ * lib/README: fixed a typo.
- * eval.c (rb_thread_yield_0): remove unused function.
+Wed Aug 22 12:13:54 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sun Sep 17 23:44:58 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/extmk.rb (extmake): save all CONFIG values.
- * lib/rdoc/rdoc.rb (RDoc::RDoc#document): scan only files modified
- after the previous generation.
+ * ext/extmk.rb (extmake): remove mkmf.log at clean, and extconf.h at
+ distclean, respectively.
-Sun Sep 17 17:42:13 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/extmk.rb: remove rdoc at clean, and installed list file at
+ distclean, respectively.
- * common.mk (install-doc): reverted.
+Wed Aug 22 11:49:00 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * instruby.rb: stores file name list without destdir prefix.
+ * sprintf.c (rb_f_sprintf): should not check positional number as
+ width. [ruby-core:11838]
- * lib/rdoc/generators/ri_generator.rb: do not chdir twice.
+Wed Aug 22 11:47:11 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sun Sep 17 10:42:10 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * bignum.c (rb_big_aref): check for Bignum index range.
+ [ruby-dev:31271]
- * numeric.c (fix_mul): fixed typo. fixed: [ruby-core:08885]
+Wed Aug 22 11:41:44 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Sep 16 19:47:16 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * dln.c (conv_to_posix_path): removed.
- * README.EXT: should mention new macros: RSTRING_PTR, RSTRING_LEN,
- RARRAY_PTR, RARRAY_LEN.
+ * ruby.c (rubylib_mangled_path, rubylib_mangled_path2): return
+ VALUE instead of a pointer to static buffer.
- * README.EXT.ja: ditto.
+ * ruby.c (push_include_cygwin): fixed buffer overflow.
+ [ruby-dev:31297]
-Sat Sep 16 16:39:23 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ruby.c (ruby_init_loadpath): not convert built-in paths.
- * Makefile.in, common.in, instruby.rb, ext/extmk.rb, lib/mkmf.rb:
- use instruby.rb to install extensions instead of ext/extmk.rb.
+Wed Aug 22 11:39:31 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * instruby.rb: store installed list into the file.
+ * intern.h (is_ruby_native_thread): removed since declared as an int
+ function in ruby.h already.
- * ext/dbm/extconf.rb: allow multiple candidates for dbm-type.
+Wed Aug 22 11:00:20 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/io/wait/extconf.rb: suspicious checking_for.
+ * lib/mkmf.rb (init_mkmf): should remove mkmf.log too.
- * ext/pty/pty.c (establishShell): parent pid is not used.
+Wed Aug 22 10:57:50 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/pty/pty.c (freeDevice): not used.
+ * ext/openssl/ossl_config.c (ossl_config_set_section): do not
+ initialize aggregations with dynamic values. [ruby-talk:259306]
- * lib/mkmf.rb (checking_for): improved the messages.
+Wed Aug 22 10:55:00 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Sep 16 11:03:49 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * eval.c (get_backtrace): check the result more.
+ [ruby-dev:31261] [ruby-bugs-12398]
- * array.c (ary_shared_first): should create embedded copies
- instead of sharing memory region for smaller arrays.
+Wed Aug 22 10:36:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Sep 16 09:37:39 2006 Yukihiro Matsumoto <matz@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]
- * struct.c (inspect_struct): do not display a class name for
- anonymous struct. The member fields are sufficient.
+ * numeric.c (rb_fix_lshift, rb_fix_rshift): ditto.
-Fri Sep 15 20:22:15 2006 NARUSE, Yui <naruse@ruby-lang.org>
+Wed Aug 22 10:29:45 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/nkf/nkf-8/nkf.c: imported nkf 2.0.8 rev.110.
- * Fix: check_bom cuts \xfe\xff\xXX\xXX of UTF-32LE.
- * Add support --ic=UTF-32.
- * Fix: can't guess UTF-16 and UTF-32.
- * Fix: can't decode beyond BMP of UTF-16LE.
+ * bignum.c (rb_big_pow): refine overflow check. [ruby-dev:31242]
- * ext/nkf/nkf.c (guess): Support UTF-32.
+Wed Aug 22 10:26:59 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/nkf/lib/kconv.rb (kconv): Support UTF-32.
+ * time.c (time_succ): Time#succ should return a time object in the
+ same timezone mode to the original. [ruby-talk:260256]
- * ext/nkf/lib/kconv.rb (to_utf32): new method.
+Wed Aug 22 10:24:00 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Sep 15 05:23:24 2006 NARUSE, Yui <naruse@ruby-lang.org>
+ * numeric.c (fix_pow): integer power calculation: 0**n => 0,
+ 1**n => 1, -1**n => 1 (n: even) / -1 (n: odd).
- * ext/nkf/nkf-8/nkf.c: imported nkf 2.0.8 2006-09-15.
- Add support for U+10000 - U+10FFFF
- Add support UTF-32
+ * test/ruby/test_fixnum.rb (TestFixnum::test_pow): update test
+ suite. pow(-3, 2^64) gives NaN when pow(3, 2^64) gives Inf.
-Fri Sep 15 00:03:07 2006 Tanaka Akira <akr@fsij.org>
+Wed Aug 22 10:23:01 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/digest/lib/digest.rb (Digest::Base.file): open a file in binary
- mode. suggested by Kazuhiro NISHIYAMA. [ruby-dev:29579]
+ * lib/base64.rb (Base64::b64encode): should not specify /o option
+ for regular expression. [ruby-dev:31221]
-Thu Sep 14 17:21:07 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Aug 22 10:20:32 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * numeric.c (fix_mul): avoid bignum multiplication as far as
- possible. a patch from Ondrej Bilka <neleai at seznam.cz>.
- [ruby-core:08825]
+ * sprintf.c (rb_f_sprintf): more checks for format argument.
+ [ruby-core:11569], [ruby-core:11570], [ruby-core:11571],
+ [ruby-core:11573]
-Thu Sep 14 16:34:55 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Aug 22 10:13:45 2007 pegacorn <subscriber.jp AT gmail.com>
- * string.c (rb_str_intern): allow zero length symbols.
- [ruby-core:08861]
+ * 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]
-Thu Sep 14 16:11:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/openssl/ossl.h: include ossl_pkcs5.h. [ruby-dev:31231]
- * string.c (rb_str_intern): raise SecurityError only when $SAFE
- level is greater than zero. [ruby-core:08862]
+ * ext/openssl/ossl_pkcs5.h: new file for PKCS5. [ruby-dev:31231]
- * parse.y (rb_interned_p): new function to check if a string is
- already interned.
+ * 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.
- * string.c (str_to_id): use rb_str_intern().
+ * lib/mkmf.rb (init_mkmf): add current directory to default
+ library path with highest priority. [ruby-core:10960]
-Thu Sep 14 14:37:45 2006 Tanaka Akira <akr@fsij.org>
+ * lib/mkmf.rb (LINK_SO): LIBPATH to be placed before DLDFLAGS.
- * ext/digest/lib/digest.rb (Digest::Base.file): new method.
- [ruby-dev:29572]
+Wed May 23 03:33:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Thu Sep 14 08:30:02 2006 Tanaka Akira <akr@fsij.org>
+ * lib/monitor.rb (ConditionVariable#wait, mon_enter, mon_exit_for_cond):
+ ensures Thread.critical to be false. [ruby-talk:248300]
- * ext/digest/digest.c (rb_digest_base_inspect): new method.
- [ruby-dev:29573]
+Wed May 23 03:25:13 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Thu Sep 14 01:13:56 2006 NAKAMURA Usaku <usa@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;
+ submitted by sheepman <sheepman AT sheepman.sakura.ne.jp>
+ in [ruby-dev:30554].
+
+Fri Mar 16 18:28:06 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/etc/etc.c (etc_getgrgid): Fix a bug in Etc::getgrgid()
+ always returning the (real) group entry of the running process;
+ reported by: UEDA Hiroyuki <ueda AT netforest.ad.jp>
+ in [ruby-dev:30586].
+
+Fri Mar 16 16:33:58 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/thread/thread.c (unlock_mutex_inner): Make sure that the
+ given mutex is actually owned by the caller; submitted by:
+ Sylvain Joyeux <sylvain.joyeux AT m4x.org> in [ruby-core:10598].
+
+Fri Mar 16 16:21:35 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/thread/thread.c (wait_condvar, lock_mutex): Fix a problem in
+ ConditionVariable#wait that occurs when two threads that are
+ trying to access the condition variable are also in concurrence
+ for the given mutex; submitted by: Sylvain Joyeux
+ <sylvain.joyeux AT m4x.org> and MenTaLguY <mental AT rydia.net>
+ in [ruby-core:10598].
+
+Fri Mar 16 16:17:27 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * test/thread/test_thread.rb: Add a test script for the `thread'
+ library. This should result in failure as of now with
+ ext/thread; submitted by: Sylvain Joyeux <sylvain.joyeux AT
+ m4x.org> in [ruby-core:10598].
+
+Wed Mar 14 12:30:00 2007 Shigeo Kobayashi <shigeo@tinyforest.jp>
+
+ * ext/bigdecimal/bigdecimal.c: BigDecimal("-.31") is now
+ treated as ("-0.31") not as ("0.31").
+
+Tue Mar 13 04:04:04 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * stable version 1.8.6 released.
+
+Tue Mar 13 02:54:17 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * lib/cgi.rb (CGI::header): IIS >= 5.0 does not need the nph
+ assumption any more; submitted by MIYASAKA Masaru <alkaid AT
+ coral.ocn.ne.jp> in [ruby-dev:30537].
+
+Mon Mar 12 11:07:44 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/openssl/ossl_asn1.c (Init_ossl_asn1): Let rdoc know about
+ externally defined modules; submitted by Technorama
+ Ltd. <oss-ruby AT technorama.net> in [ruby-bugs:PR#4704].
+
+ * ext/openssl/ossl_bn.c (Init_ossl_bn): Ditto.
+
+ * ext/openssl/ossl_cipher.c (Init_ossl_cipher): Ditto.
+
+ * ext/openssl/ossl_digest.c (Init_ossl_digest): Ditto.
+
+ * ext/openssl/ossl_hmac.c (Init_ossl_hmac): Ditto.
+
+ * ext/openssl/ossl_pkey.c (Init_ossl_pkey): Ditto.
+
+ * ext/openssl/ossl_pkey_dh.c (Init_ossl_dh): Ditto.
+
+ * ext/openssl/ossl_pkey_dsa.c (Init_ossl_dsa): Ditto.
+
+ * ext/openssl/ossl_pkey_rsa.c (Init_ossl_rsa): Ditto.
+
+ * ext/openssl/ossl_rand.c (Init_ossl_rand): Ditto.
+
+ * ext/openssl/ossl_ssl.c (Init_ossl_ssl): Ditto.
+
+Mon Mar 12 01:23:50 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/dl/sym.c (rb_dlsym_inspect): Use "0x%x" rather for pointers.
+ This might not be very right but it is commonly used in other
+ parts of the code; submitted by sheepman <sheepman AT
+ sheepman.sakura.ne.jp> in [ruby-dev:30532].
+
+ * ext/dl/ptr.c (rb_dlptr_inspect): Ditto.
+
+ * ext/dl/lib/dl/import.rb (DL::Importable::Internal::import,
+ DL::Importable::Internal::callback): Avoid race condition for an
+ instance variable; submitted by sheepman <sheepman AT
+ sheepman.sakura.ne.jp> in [ruby-dev:30530].
+
+Sun Mar 11 19:04:29 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * misc/README: Add a note about ruby-electric.el.
+
+ * misc/ruby-mode.el (ruby-non-block-do-re): Fix
+ ruby-non-block-do-re. [ruby-core:03719]
+
+ * misc/inf-ruby.el: Synchronize the comment section with trunk.
+
+ * misc/README, misc/rdebug.el: Add rdebug.el, Emacs ruby-debug
+ interface based on rubydb3x.el; submitted by Martin Nordholts
+ <enselic AT gmail.com> in [ruby-bugs:PR#9023].
+
+Sun Mar 11 17:51:46 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/dl/mkcallback.rb (mkfunc): Make sure that a callback
+ function is found in the function table before trying to call
+ it; submitted by sheepman <sheepman AT sheepman.sakura.ne.jp>
+ in [ruby-dev:30524].
+
+Sun Mar 11 17:30:53 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (error_handle): no message when exiting by signal.
+
+ * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
+
+ * eval.c (rb_thread_interrupt): instantiate SignalException.
+
+ * eval.c (rb_thread_signal_raise): now takes signal number instead
+ of signal name.
+
+ * intern.h (rb_thread_signal_raise, ruby_default_signal): prototypes.
+
+ * signal.c (esignal_init): takes a signal number and an optional
+ signal name.
+
+ * signal.c (interrupt_init): pass SIGINT always.
+
+ * signal.c (ruby_default_signal): invoke system default signal
+ handler.
+
+ * signal.c (rb_signal_exec, trap): handle SIGTERM. [ruby-dev:30505]
+
+Tue Mar 6 19:03:42 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/digest/lib/md5.rb (MD5::new, MD5::md5): Do not modify
+ Digest::MD5.
+
+ * ext/digest/lib/sha1.rb (SHA1::new, SHA1::sha1): Ditto.
+
+ * lib/shell/process-controller.rb: fix thread synchronization
+ problem for [ruby-dev:30477].
+
+ * ext/digest/lib/md5.rb (MD5::new, MD5::md5): Catch up with
+ Digest's API changes; noted by: Kazuhiro Yoshida <moriq AT
+ 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].
+
+ * ext/tk/sample/irbtkw.rbw: fails to exit process.
+
+Mon Mar 5 20:26:10 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * time.c (time_to_s): Correct the wrong format which did not
+ really conform to RFC 2822; pointed out by: OHARA Shigeki <os at
+ iij.ad.jp> in [ruby-dev:30487].
+
+Sun Mar 4 23:53:27 2007 Minero Aoki <aamine@loveruby.net>
+
+ * lib/fileutils.rb (mv): could not move a directory between
+ different filesystems. [ruby-dev:30411]
+
+Sun Mar 4 23:46:40 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * file.c (rb_file_s_utime): allow nil to set the current time.
+
+ * lib/fileutils.rb (touch): ditto, and added :mtime and :nocreate
+ options. fixed: [ruby-talk:219037]
+
+Sun Mar 4 23:19:00 2007 WATANABE Hirofumi <eban@ruby-lang.org>
+
+ * util.c (push_element): should return a int value.
+
+Sun Mar 4 01:06:55 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * lib/set.rb (Set#^, Set#&): Correct documentation. Those methods
+ return sets, not arrays; noted by Oliver Frank Wittich <nietz AT
+ mangabrain.de>.
+
+Sat Mar 3 21:41:31 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * eval.c (stack_check): Unset inline to fix build with GCC 3.4.6;
+ submitted by: NISHIMATSU Takeshi <t_nissie AT yahoo.co.jp> in
+ [ruby-list:43218].
+ cf. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24556
+
+Sat Mar 3 19:07:05 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/thread/thread.c (push_list): Use ALLOC().
+
+ * ext/thread/thread.c (rb_mutex_alloc): Ditto.
+
+ * ext/thread/thread.c (rb_condvar_alloc): Ditto.
+
+Sat Mar 3 18:56:40 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * NEWS: Add a note for String#intern.
+
+Sat Mar 3 18:36:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (rb_provided): return true only for features loaded from
+ .rb files, and not search actual library type. [ruby-dev:30414]
+
+ * eval.c (rb_feature_p): check loading_tbl if the given ext is
+ empty. [ruby-dev:30452]
+
+ * eval.c (rb_feature_p): fix possible buffer overrun.
+
+Sat Mar 3 16:30:39 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * env.h (SCOPE_CLONE): Introduce a new scope flag to prevent a
+ local_tbl region from getting freed many times; submitted by
+ Chikanaga Tomoyuki <chikanag AT nippon-control-system.co.jp> in
+ [ruby-dev:30460].
+
+ * eval.c (proc_invoke): Ditto.
+
+ * gc.c (obj_free): Ditto.
+
+ * parse.y (top_local_setup_gen): Ditto.
+
+Sat Mar 3 16:09:27 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * object.c (rb_obj_ivar_set): RDoc updated according to a
+ suggestion from Brian Candler <B.Candler AT pobox.com>.
+ [ruby-core:10469]
+
+Sat Mar 3 15:41:33 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (stmt, arg): should not omit lhs of OP_ASGN1 even if
+ empty. [ruby-dev:30452]
+
+Thu Mar 1 04:08:30 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * mkconfig.rb (patchlevel): read from version.h.
+
+Thu Mar 1 03:42:09 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/digest/digest.c (get_digest_base_metadata): Allow inheriting
+ Digest::Base subclasses, which was unintentionally made
+ impossible while restructuring Digest classes.
+
+Wed Feb 28 22:10:55 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * doc/NEWS-1.8.0: Rename NEWS to NEWS-1.8.0. This is way too old
+ NEWS.
+
+ * NEWS: Add NEWS, a document file to keep user visible feature
+ changes between releases.
+
+ * configure.in (ac_cv_func_fcntl): fcntl support for MinGW.
+
+ * missing/flock.c: workaround for MinGW.
+
+ * ext/openssl/extconf.rb: no need to check unistd.h and sys/time.h.
+ they are already checked at configure.
+ reported by KOBAYASHI Yasuhiro [ruby-list:43225]
+
+ * lib/mkmf.rb ($DEFLIBPATH): default library paths ($(topdir), etc)
+ should be the first elements of library paths list.
+ reported by KOBAYASHI Yasuhiro [ruby-list:43225]
+
+ * test/{dbm,gdbm}/test_{dbm,gdbm}.rb: shouldn't use host_os. use
+ target_os instead. reported by KOBAYASHI Yasuhiro [ruby-list:43225]
+
+ * mkconfig.rb (RbConfig): add CONFIG['PATCHLEVEL']
+
+ * common.mk: new target dist
+
+ * distruby.rb: new file
+
+ * configure.in (--enable-auto-image-base): avoid the neccessity to
+ rebase the shared libs as much as possible;
+ submitted by Corinna Vinschen <spam at vinschen.de> in
+ [ruby-talk:240964].
+
+Wed Feb 28 20:51:32 2007 URABE Shyouhei <shyouhei@ruby-lang.org>
+
+ * pack.c (pack_unpack): properly ignore non-base64 octets such as
+ UTF-8 encoded BOMs; submitted by SOUMA Yutaka <holon@radastery.jp>
+ to fix [ruby-core:10437]
+
+Tue Feb 27 21:50:10 2007 WATANABE Hirofumi <eban@ruby-lang.org>
+
+ * util.c (__crt0_glob_function): use ruby_glob() instead of rb_globi().
+
+ * configure.in (ac_cv_func_setrlimit): workaround for djgpp.
+
+Tue Feb 27 20:49:19 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * lib/base64.rb (Base64::b64encode): Fix documentation; submitted
+ by David Symonds <dsymonds@gmail.com> in [ruby-core:10432].
+
+ * regex.c (calculate_must_string, slow_search, re_search): Silence
+ warnings regarding char * vs. unsigned char * mismatch;
+ submitted by Lyle Johnson <lyle.johnson@gmail.com>
+ in [ruby-core:10416].
+
+ * ext/bigdecimal/bigdecimal.c (BigDecimal_load): Ditto.
+
+ * ext/digest/sha1/sha1ossl.c (SHA1_Finish): Ditto.
+
+ * ext/digest/rmd160/rmd160ossl.c (RMD160_Finish): Ditto.
+
+ * ext/digest/digest.c (rb_digest_base_finish,
+ rb_digest_base_update): Ditto.
+
+ * ext/nkf/nkf.c (rb_str_resize, rb_nkf_kconv, rb_nkf_guess1,
+ rb_nkf_guess2): Ditto.
+
+ * ext/thread/thread.c (wait_list_cleanup, rb_mutex_try_lock):
+ Eliminate rb_thread_critical switching where unnecessary;
+ implied by shugo in [ruby-dev:30412].
+
+ * ext/thread/thread.c (set_critical): Merge in
+ thread_exclusive_ensure().
+
+ * ext/thread/thread.c: Consistently use 0 and 1 for
+ rb_thread_critical values.
+
+ * ext/thread/thread.c: Use xmalloc()/xfree() instead of
+ malloc()/free(); pointed out by shugo in [ruby-dev:30412].
+
+ * lib/test/unit/autorunner.rb (Test::Unit::AutoRunner::initialize):
+ Initialize @workdir properly to silence a warning under -w.
+ Submitted by <tommy at tmtm.org> in [ruby-dev:30400].
+
+Sun Feb 25 02:50:51 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * defines.h: Pull the RUBY_MBCHAR_MAXSIZE definition from trunk,
+ which is necessary for dir.c to compile on djgpp and emx.
+
+Sat Feb 24 17:04:01 2007 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * lib/date/format.rb: updated based on date2 4.0.3.
+
+Sat Feb 24 17:01:02 2007 Minero Aoki <aamine@loveruby.net>
+
+ * ext/racc/cparse/cparse.c (cparse_params_mark): remove useless
+ rb_gc_mark. Thanks Tomoyuki Chikanaga. [ruby-dev:30405]
+
+Sat Feb 24 16:53:09 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * signal.c (sighandler): need to tell to be interrupted to main
+ context when handler is installed.
+
+ * win32/win32.[ch] (rb_win32_interrupted): new function to listen
+ interrupt.
+
+ * win32/win32.c (set_pioinfo_extra): new function for VC++8 SP1
+ workaround. [ruby-core:10259]
+
+ * win32/win32.c (NtInitialize): call above function.
+
+Fri Feb 23 13:04:43 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * numeric.c (fix_cmp, fix_equal): Remove FIX2LONG() to optimize.
+ suggested in
+ http://t-a-w.blogspot.com/2007/02/making-ruby-faster.html.
+ [ruby-talk:240223]
+
+Fri Feb 23 12:47:13 2007 James Edward Gray II <james@grayproductions.net>
+
+ * lib/xmlrpc/client.rb (XMLRPC::Client::do_rpc): Make the
+ Content-Length parameter optional for responses in
+ xmlrpc/client.rb; suggested by Daniel Berger
+ <Daniel.Berger@qwest.com> and approved by the maintainer.
+
+ * lib/xmlrpc/create.rb (XMLRPC::Create::conv2value): Add DateTime
+ support to xmlrpc; approved by the maintainer.
+
+Mon Feb 19 18:33:30 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/socket/socket.c (unix_peeraddr): wrong syscall name in error
+ message for #peeraddr. a patch from Sam Roberts
+ <sroberts at uniserve.com>. [ruby-core:10366]
+
+Mon Feb 19 18:27:42 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * configure.in, defines.h, eval.c (rb_feature_p, rb_provided,
+ load_wait, search_required, rb_require_safe), ext/extmk.rb: Fix
+ a bug where a statically linked extension cannot be autoloaded.
+ [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]
+
+ * lib/prettyprint.rb: Suppress RDoc for PrettyPrint test suite.
+
+Thu Feb 15 18:10:09 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * dir.c (glob_helper): Fix the function declaration.
+
+Thu Feb 15 16:55:33 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * version.h: Branch off ruby_1_8_6 from ruby_1_8 in preparation
+ for the forthcoming 1.8.6 release.
+
+Thu Feb 15 16:44:14 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * lib/uri/generic.rb (URI::Generic::userinfo): Considering how
+ `scheme://user:@...', `scheme://:password@...' and
+ `scheme://:@...' are parsed, an empty user name or password
+ should be allowed and represented as it is.
+
+Thu Feb 15 11:46:05 2007 KIMURA Koichi <hogemuta@gmail.com>
+
+ * dir.c, win32/win32.c, win32/dir.h, ruby.h, intern.h: Bring
+ encoding aware globbing support in from trunk. Dir.[] and
+ Dir.glob() can now take many patterns in an array. Minor fixes
+ will follow.
+
+Thu Feb 15 11:00:26 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * lib/uri/generic.rb (URI::Generic::userinfo): should support
+ empty password. [ruby-core:10290]
+
+ * lib/uri/generic.rb (URI::Generic::set_password): password can be
+ cleared by nil. [ruby-core:10290]
+
+ * lib/uri/common.rb (escape): regard second string argument as a
+ character set properly. [ruby-dev:27692]
+
+ * lib/uri/ftp.rb: Attempt to conform to RFC 1738 with regard to
+ relative/absolute paths.
+
+ * lib/uri: Lovely RDOC patches from mathew (metaATpoboxDOTcom).
+
+Thu Feb 15 10:57:38 2007 Tietew <tietew@tietew.net>>
+
+ * lib/cgi.rb (CGI::unescapeHTML): invalid decoding for single
+ unescaped ampersand. a patch from Tietew
+ <tietew+ruby-dev at tietew.net> in [ruby-dev:30292].
+ fixed: [ruby-dev:30289]
+
+Thu Feb 15 10:48:40 2007 MenTaLguY <mental@rydia.net>
+
+ * ext/thread/thread.c: Handle interrupted waits correctly.
+ [ruby-bugs:PR#8663]
+
+Wed Feb 14 19:22:15 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/digest/lib/digest.rb (Digest::self.const_missing): Drop
+ autoloads for sha2 classes in favor of handling in
+ const_missing(), to work around a problem exposed on OS X.
+
+Tue Feb 13 02:21:12 2007 Sam Roberts <sroberts@uniserve.com>
+
+ * io.c (rb_f_syscall): Fix buffer overflow with syscall
+ arguments. [ruby-bugs:PR#8541]
+
+Sun Feb 11 07:46:45 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * lib/cgi.rb (CGI::QueryExtension::read_multipart): Properly parse
+ a quoted-string in a Content-Disposition value.
+
+Sun Feb 11 06:27:54 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * configure.in, ext/thread/extconf.rb, lib/thread.rb: Add a
+ configure option `--disable-fastthread', to choose the original,
+ pure ruby version of the "thread" library instead of the new,
+ much faster implementation in ext/thread.
+
+Sun Feb 11 06:22:20 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/Setup: Add thread except for platforms without threads
+ support.
+
+Sun Feb 11 06:15:16 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/thread/lib/thread.rb: Add a replacement of thread.rb that
+ loads this extension.
+
+Sun Feb 11 05:39:47 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * lib/thread.rb: Remove an ineffective part of the code.
+
+Sun Feb 11 05:32:54 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/thread/thread.c (rb_thread_exclusive): Implement
+ Thread.exclusive.
+
+Sun Feb 11 05:26:51 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/thread/thread.c: Get rid of use of a dummy function.
+
+Sun Feb 11 01:45:31 2007 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * ext/thread/thread.c (Init_thread): Define missing aliases:
+ Queue#enq and SizedQueue#enq.
+
+Sat Feb 10 09:27:35 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+
+ * ext/win32ole/win32ole.c (ole_variant2val): fix compile error
+ on VC++.
+
+Sat Feb 10 07:41:52 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+
+ * ext/win32ole/win32ole.c (ole_variant2val): fix the bug when
+ SAFEARRAY pointer is NULL.
+
+Sat Feb 10 00:13:11 2007 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * 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>
+
+ * ext/thread: Make style fixes (mostly de-K&R'ism) to match the
+ rest of the source code.
+
+ * ext/thread: Make USE_MEM_POOLS an extconf option.
+
+Fri Feb 9 20:43:01 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/thread: Import the "fastthread" implementation by MenTaLguY
+ in the original form. This module is not hooked into the build
+ yet since it needs some style fixes and adjustments.
+
+Fri Feb 9 15:46:09 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/bigdecimal: Synchronize with trunk. Better function
+ prototypes, removal of a useless method `!=', and document
+ updates.
+
+Tue Feb 06 22:06:45 2007 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * ext/nkf/nkf-utf8/{nkf.c,utf8tbl.c}:
+ imported nkf 2007-01-28.
+ * Fixed: can't decode MIME encode JIS string.
+ * Fixed: Fullwitdh-halfwidth conversion.
+ * Support DoCoMo's and Softbank's EMOJI
+ * Support CP932, CP5022x, eucJP-ms UDC
+ * Support UTF-32 encoding
+ * Support beyond BMP
+ [ruby-dev:29700] [ruby-dev:29922] [ruby-dev:30144]
+
+Wed Jan 31 14:52:09 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (rb_iterate): need to PUSH_ITER in proper order.
+ [ruby-core:10125]
+
+ * test/ruby/test_iterator.rb (TestIterator::test_block_given_within_iterator):
+ add new test. [ruby-core:10125]
+
+Tue Jan 30 14:58:51 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * string.c (rb_str_sub_bang): calling rb_str_modify() should be just
+ before actually modifying the string.
+ fixed: [ruby-dev:30211] (originally reported by zunda)
+
+Tue Jan 30 12:05:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * mkconfig.rb: autoconf 2.61 support. [ruby-core:10016]
+
+Sat Jan 27 15:20:11 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * parse.y (dyna_var_lookup): should not alter dvar->val not to
+ destroy living value. [ruby-core:10076]
+
+ * parse.y (dyna_init): ditto.
+
+Fri Jan 26 12:03:39 2007 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * ext/tk/lib/tk.rb (TkConfigMethod#__confinfo_cmd,
+ __conv_keyonly_optkeys): make them private [ruby-dev:30074].
+
+ * ext/tk/lib/tk/txtwin_abst.rb: fix typo [ruby-dev:30073].
+
+ * ext/tk/lib/tk/canvas.rb (TkCanvas#scan_dragto): lack of an argument.
+
+ * ext/tk/lib/tk/canvas.rb: clarify the including module name
+ [ruby-dev:30080].
+
+ * ext/tk/lib/tk/scrollable.rb: change primary name of modules
+ [ruby-dev:30080].
+
+Wed Jan 24 18:05:39 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * misc/ruby-mode.el (ruby-font-lock-syntactic-keywords): fix
+ 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>
+
+ * lib/cgi.rb (CGI::QueryExtension::read_multipart): use == instead
+ of ===. [ruby-dev:30176]
+
+Tue Jan 23 10:48:17 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * hash.c: added documentation for Hash about how it uses eql? and
+ hash methods for the keys. [ruby-core:09995]
+
+Mon Jan 22 14:57:25 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ext/socket/socket.c: fix errors in socket sample code.
+ [ruby-core:09992]
+
+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,
+ ole_event_free): fix memory leak. [ruby-core:09846]
+
+Fri Jan 12 11:13:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/etc/etc.c (etc_getpwuid, etc_getgrgid): fix to correctly
+ convert uid/gid from VALUE. (backport of r11521)
+
+Wed Jan 10 18:57:57 2007 Minero Aoki <aamine@loveruby.net>
+
+ * ext/strscan/strscan.c (strscan_do_scan): should set kcode option
+ before match. [ruby-dev:29914]
+
+ * test/strscan/test_stringscanner.rb: test it.
+
+ * re.c: export kcode_set_option and kcode_reset_option (with "rb_"
+ prefix).
+
+ * intern.h: ditto.
+
+Tue Jan 9 17:45:17 2007 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * file.c (rb_find_file): should not call fpath_check() with NULL.
+ fixed: [ruby-core:09867]
+
+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>
+
+ * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#find_class_comment):
+ Look for class and module comments above rb_define_class and
+ rb_define_module. Patch by Daniel Berger <djberg96 at gmail.com>
+
+Sun Jan 7 10:32:12 2007 Eric Hodel <drbrain@segment7.net>
+
+ * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#handle_constants):
+ Properly handle escaping of : in comments.
+ * test/rdoc/parsers/test_parse_c.rb:
+ Test RDoc::C_Parser#do_classes and Rdoc::C_Parser#find_class_comment.
+
+Sun Jan 7 09:33:02 2007 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * lib/date/format.rb: updated based on date2 4.0.1.
+
+Wed Jan 3 11:36:51 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * io.c (ruby_dup): start GC on ENOMEM as well.
+
+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.
+
+Mon Jan 1 06:13:11 2007 Eric Hodel <drbrain@segment7.net>
+
+ * ext/bigdecimal/bigdecimal.c: Update constant comments to provide
+ 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].
+ * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#handle_constansts): Fix
+ whitespace handling in constant comments.
+
+Sun Dec 31 00:31:16 2006 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * lib/date.rb, lib/date/format.rb: updated based on date2 4.0.
+
+Thu Dec 14 18:29:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ext/readline/readline.c: NetBSD editline does not have
+ rl_username_completion_function() and rl_completion_matches().
+ a patch from Takahiro Kambe <taca at back-street.net>.
+ [ruby-dev:30008]
+
+Thu Dec 14 18:20:43 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/irb/locale.rb (IRB::Locale::puts): typo fixed. a patch from
+ NAKAMURA Usaku <usa@ruby-lang.org>. [ruby-dev:30012]
+
+Mon Dec 11 11:58:36 2006 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/digest/sha2/lib/sha2.rb: Moved one level up from under
+ the superfluous subdirectory digest/.
+
+Mon Dec 11 11:46:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * variable.c (rb_define_const): typo fixed.
+
+Mon Dec 11 09:36:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_aset): index double decode problem.
+ [ruby-core:09695]
+
+Sat Dec 9 21:39:24 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (ruby_cleanup): keep the exception till after END blocks.
+ [ruby-core:09675]
+
+Sat Dec 9 11:22:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/irb/locale.rb (IRB::Locale::search_file): ues File.exist?
+ instead of File.exists?. a patch from Yutaka Kanemoto
+ <kinpoco at gmail.com> in [ruby-dev:30000].
+
+Thu Dec 7 09:29:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/weakref.rb (WeakRef::__setobj__): should support
+ marshaling. [ruby-talk:228508]
+
+ * lib/delegate.rb (Delegator::marshal_load): need to call
+ __setobj__.
+
+Wed Dec 6 23:56:14 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * Makefile.in, common.mk (NULLCMD): moved for platforms that empty
+ command does not run. fixed: [ruby-dev:29994]
+
+Wed Dec 6 17:17:26 2006 WATANABE Hirofumi <eban@ruby-lang.org>
+
+ * configure.in (SITE_DIR): fixed to emtpy RUBY_SITE_LIB in config.h on
+ NetBSD. fixed: [ruby-dev:29358]
+
+Tue Dec 5 00:59:05 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * misc/ruby-mode.el (ruby-parse-partial): need to parse "/=" as
+ self assignment operator, not regex. [ruby-talk:227324]
+
+Mon Dec 4 10:48:03 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ruby.h (OFFT2NUM): use LONG2NUM() if sizeof(long) equals to
+ sizeof(off_t).
+
+Mon Dec 4 10:43:46 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * parse.y (dyna_init_gen): dvar initialization only if dvar is
+ assigned inner block. [ruby-talk:227402]
+
+Mon Dec 4 08:32:49 2006 Shugo Maeda <shugo@ruby-lang.org>
+
+ * lib/cgi.rb (CGI::QueryExtension::read_multipart): should quote
+ boundary. JVN#84798830
+
+Sat Dec 2 07:09:04 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * ext/openssl/ossl_ocsp.c: OpenSSL::OCSP::OSCPError should be
+ subclass of OpenSSL::OpenSSLError. [ruby-dev:29980]
+
+Fri Dec 1 17:01:49 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* gc.c (ruby_init_stack): decrease "stack level too deep" in Windows.
- [ruby-dev:29569]
+ merge from trunk.
-Thu Sep 14 01:02:25 2006 Tanaka Akira <akr@fsij.org>
+Fri Dec 1 16:31:53 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/digest/lib/digest.rb: new file.
- [ruby-dev:28689]
+ * ext/tk/tcltklib.c: shouldn't run the killed thread at callback.
+ [ruby-talk: 227408]
-Wed Sep 13 18:43:05 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Nov 27 17:18:27 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * README.EXT: English adjustment. [ruby-core:08851] and
- [ruby-core:08852]
+ * sprintf.c (rb_f_sprintf): need not to truncate string if no
+ width specifier given for %s. [ruby-dev:29952]
-Wed Sep 13 18:25:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Nov 26 16:36:46 2006 URABE Shyouhei <shyouhei@ruby-lang.org>
- * misc/ruby-mode.el (ruby-parse-partial): better here-doc support.
- a patch from Marshall T. Vandegrift <llasram at gmail.com>.
- [ruby-core:08804]
+ * version.h: addition of RUBY_PATCHLEVEL.
+ * version.c: ditto.
-Wed Sep 13 16:43:36 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Nov 24 10:17:51 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * string.c (rb_str_intern): prohibit interning tainted string.
+ * bignum.c (bignorm): avoid segmentation. a patch from Hiroyuki
+ Ito <ZXB01226@nifty.com>. [ruby-list:43012]
-Wed Sep 13 01:14:02 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Nov 23 10:38:40 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/optparse.rb (OptionParser#getopts): works with pre-registered
- options. [ruby-core:08826]
+ * eval.c (rb_mod_define_method): set implicit visibility only when
+ it's called for the target class (ruby_cbase).
-Tue Sep 12 03:58:39 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Nov 22 16:00:49 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * hash.c (rb_hash_compare_by_identity): rename Hash#identical to
- Hash#compare_by_identity.
+ * ext/tk/extconf.rb: support --with-X11/--without-X11 option.
-Mon Sep 11 16:52:37 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/tk/README.tcltklib: add description about --with-X11-* option
+ [ruby-talk:225166] and --with-X11/--without-X11 option.
- * hash.c (rb_hash_identical): a new method to make a hash to
- compare keys by their identity.
+ * ext/tk/tkutil/extconf.rb: able to be called manually
+ [ruby-talk:225950].
- * hash.c (rb_hash_identical_p): new method to tell if a hash is
- identical or not.
+Wed Nov 15 23:22:54 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * st.c (st_numcmp, st_numhash): export hash type functions.
+ * file.c (test_grpowned, rb_stat_grpowned): should honor
+ supplementary group IDs. [ruby-core:09546]
-Mon Sep 11 11:42:21 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Thu Nov 9 03:15:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/rexml/source.rb (REXML::Source::encoding): should not
- convert the body twice. [ruby-core:08828]
+ * eval.c (BEGIN_CALLARGS): ruby_block may be NULL even when
+ ITER_PRE.
- * lib/rexml/encoding.rb (REXML::Encoding::encoding):
- Encoding#encoding= to return boolean value to tell if the body
- is really converted or not.
+Tue Nov 7 18:34:34 2006 Akinori MUSHA <knu@iDaemons.org>
- * lib/rexml/encoding.rb (REXML::Encoding::encoding): Specific
- conversion library (e.g. rexml/encodings/UTF-16.rb) to have
- higher preceding.
+ * ext/digest/lib/digest/hmac.rb: Keep this out of the 1.8 tree
+ until we reach a consensus that HMAC should be put under Digest.
- * lib/rexml/encodings/UTF-16.rb (REXML::Encoding::decode_utf16):
- UTF-16#decode_utf16 should work strings without BOM.
+Tue Nov 7 18:05:01 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-Mon Sep 11 07:39:44 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/tk/lib/tk/itemconfig.rb: minor bug fix.
- * string.c (sym_equal): "sym == str" should compare them as
- strings. [ruby-dev:29554]
+Mon Nov 6 20:11:20 2006 Kouhei Sutou <kou@cozmixng.org>
-Sun Sep 10 22:59:43 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/rss/0.9.rb (RSS::Rss): removed needless include.
- * instruby.rb (parse_args): remove splat.
+Mon Nov 6 15:41:55 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-Sun Sep 10 20:25:30 2006 Tadayoshi Funaba <tadf@dotrb.org>
+ * ext/tk/lib/tk/itemconfig.rb: ext/tk/lib/tk/itemconfig.rb: bug
+ fix on 'itemconfiginfo' method, and modify to make it easy to
+ override 'itemconfiginfo' method.
- * lib/date.rb, lib/date/format.rb: updated based on date2 3.9.1.
+ * ext/tk/lib/tkextlib/tile/treeview.rb : support Tile 0.7.8.
-Sun Sep 10 09:41:29 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/tk/lib/tkextlib/version.rb : [new] add Tk::Tkextlib_RELEASE_DATE
+ to get the information from scripts.
- * file.c: ISPRINT() needs ctype.h
+ * ext/tk/lib/tk.rb: load 'tkextlib/version.rb', and update RELEASE_DATE
-Sun Sep 10 09:19:47 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/tk/lib/tkextlib/SUPPORT_STATUS: update.
- * lib/optparse.rb: splat parsed arguments.
+ * ext/tk/sample/editable_listbox.rb: [new] the listbox with editable
+ items. It's one of the example about usage of Place geometry manager.
-Tue Jan 10 09:18:03 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/tk/sample/tktextio.rb: improve the functions of TkTextIO class.
+ Those are required by 'irbtkw.rbw'.
- * eval.c (rb_require_safe): prevent extension from loading twice.
- fixed: [ruby-dev:29523]
+ * ext/tk/sample/irbtkw.rbw: [new] IRB on Ruby/Tk. It doesn't need any
+ real console. IRB works on a text widget without I/O blocking. That
+ is, thread switching on IRB will work properly, even if on Windows.
-Sat Sep 9 23:55:28 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Nov 5 19:53:49 2006 Tadayoshi Funaba <tadf@dotrb.org>
- * file.c (rb_f_test): test(0) should not have any special
- meaning. [ruby-dev:29425]
+ * lib/date.rb: updated based on date2 3.9.7.
- * file.c (rb_f_test): properer error message.
+Sat Nov 4 13:13:57 2006 Shugo Maeda <shugo@ruby-lang.org>
-Sat Sep 9 14:08:38 2006 Eric Hodel <drbrain@segment7.net>
+ * lib/net/imap.rb: accept NOMODSEQ. [ruby-core:9002]
+ (backported from HEAD)
- * lib/test/unit/testcase.rb (Test::Unit::TestCase#run): Rescue
- Exception in Test::Unit::TestCase#run. [ruby-core:08783]
+Fri Nov 3 00:16:37 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Sat Sep 9 04:55:59 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/socket/socket.c (ruby_getnameinfo__aix): AF_INET6 workaround
+ for AIX. a patch from Yutaka Kanemoto <kinpoco AT gmail.com>.
+ [ruby-dev:29744]
- * lib/pstore.rb: open all in binary mode, and get rid of the quirk of
- msvcrt. fixed: [ruby-dev:29518]
+Thu Nov 2 15:43:39 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-Sat Sep 9 04:47:45 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * parse.y (primary): should set NODE even when compstmt is NULL.
+ merge from trunk. fixed: [ruby-dev:29732]
- * Makefile.in, win32/Makefile.sub (MINIRUBY): append MINIRUBYOPT.
+Thu Nov 2 14:48:30 2006 Akinori MUSHA <knu@iDaemons.org>
- * mkconfig.rb, ext/extmk.rb, lib/mkmf.rb, win32/mkexports.rb: suppress
- warnings with $VERBOSE.
+ * lib/set.rb (Set#^): Fix XOR operation against a container that
+ holds duplicate values. [issue: #6444]
- * win32/resource.rb: only file which has more than one icon is DLL.
+Wed Nov 1 02:41:38 2006 Akinori MUSHA <knu@iDaemons.org>
-Fri Sep 8 16:53:30 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/digest/lib/digest/hmac.rb (Digest::HMAC::update): Minor
+ optimization.
- * string.c (str_alloc): should allocate a String object, even when
- asked to allocate a Symbol object. [ruby-dev:29529]
+ * ext/digest/digest.c (rb_digest_instance_equal): Allow comparing
+ a digest instance with another of a different class.
-Fri Sep 8 16:36:27 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Nov 1 01:05:13 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/extmk.rb (extmake): follow Array#to_s.
+ * eval.c (rb_call0): fixed bug of zsuper with both of opt and rest.
+ fixed: [ruby-list:42928]
- * lib/mkmf.rb (create_makefile): ditto.
+ * test/ruby/test_super.rb: add tests to check above bug.
- * win32/resource.rb: ditto.
+Tue Oct 31 17:03:21 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Sep 8 10:00:12 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
+ * time.c (time_dup): duplicate the class of original time.
+ [ruby-core:09357]
- * lib/webrick/cookie.rb (WEBrick::Cookie.parse_set_cookies): new
- method to parse multiple cookies per Set-Cookie header.
- Thanks to Aaron Patterson <aaron_patterson at speakeasy.net>.
- [ruby-core:08802]
+ * lib/time.rb (Time::make_time, Time::rfc2822, Time::httpdate):
+ should respect subclasses. [ruby-core:09357]
-Fri Sep 8 08:59:30 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Oct 30 23:40:52 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * win32/Makefile.sub, win32/configure.bat win32/setup.mak: program
- name transform.
+ * Makefile.in (miniruby): add XLDFLAGS.
-Fri Sep 8 08:25:39 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * configure.in (aix): use -bE option for miniruby. [ruby-dev:29698]
- * lib/optparse.rb: suppress `assigning void value' warning.
+ * dir.c (glob_helper): get rid of possible memory leak.
-Fri Sep 8 01:16:34 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * win32/win32.c (cmdglob, rb_w32_cmdvector, rb_w32_opendir,
+ rb_w32_get_environ): not to use GC before initialization.
- * array.c (Init_Array): #to_s to be an alias to #inspect.
- [ruby-dev:29520]
+Mon Oct 30 19:29:20 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * hash.c (Init_Hash): ditto.
+ * bignum.c (rb_big2str0): use better approximation.
- * lib/mkmf.rb (create_makefile): replace "print array" by
- "print *array".
+Mon Oct 30 18:35:33 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * mkconfig.rb: ditto.
+ * bignum.c (rb_big2str0): wrong allocation length. a patch from
+ U.Nakamura <usa at garbagecollect.jp> [ruby-dev:29710]
-Thu Sep 7 21:02:56 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Oct 30 12:34:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * object.c (nil_to_s): returns the empty string again.
- [ruby-dev:29520]
+ * eval.c (rb_eval): fix commit miss. [ruby-dev:29707]
-Thu Sep 7 23:27:05 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Oct 30 12:20:58 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * file.c (path_check_0, fpath_check): disable path check on cygwin.
- [ruby-talk:213074]
+ * bignum.c (rb_big2str0): a bug in length adjustment.
-Thu Sep 7 02:03:45 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Oct 30 11:15:40 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * time.c (time_to_s): adopt new date format using digits
- e.g. "2006-09-07 02:03:45 +9000".
+ * sprintf.c (rb_str_format): should preserve leading zero
+ information for negative %b and %x. [ruby-talk:221347]
-Thu Sep 7 01:54:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Thu Oct 26 21:05:58 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * string.c (sym_equal): override. check equivalence.
+ * ext/openssl/ossl_pkcs7.c (ossl_pkcs7_verify): should clear error.
+ (fix http://bugs.debian.org/394336)
-Wed Sep 6 13:25:04 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/openssl/ossl_ns_spki.c (ossl_spki_initialize): ditto.
- * parse.y (symbols_i): need to initialize early-created symbols.
- [ruby-dev:29496]
+Thu Oct 26 15:21:10 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-Wed Sep 06 12:05:19 2006 NARUSE, Yui <naruse@ruby-lang.org>
+ * ext/digest/digest.c (Init_digest): typo.
- * ext/nkf/lib/kconv.rb (Kconv::toeuc): remove -m0 [ruby-dev:29505]
+Wed Oct 25 17:23:28 2006 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/digest, test/digest/test_digest.rb: Merge from trunk:
+ - Introduce versioning in Digest::Base API, and prefix C
+ constants with RUBY_ and C type names with rb_ to avoid name
+ clash in writing extensions.
+ - Introduce Digest::Class and Digest::Instance for ease of
+ implementing subclasses and add-ons.
+ - Digest::Instance module requires and assumes that any instance
+ be resettable and clonable. An instance method #new() is
+ added so digest instances work just like digest classes.
+ - The constructor does no longer take an initial string to feed;
+ digest() and hexdigest() now do, instead. This allows digest
+ classes to take their own hashing parameters.
+ - Make some changes to digest() and hexdigest() class methods,
+ which now take extra arguments, which are passed through to
+ the constructor in an internal call.
+ - Add #digest_length/size/length() and #block_length(),
+ - Add the Digest::SHA2 class to wrap up SHA2 variants: SHA256,
+ SHA384 and SHA512, hoping this module would make a decent
+ example of a digest subclass written in Ruby.
+ - Rip BubbleBabble support out of the base class and have a
+ separate module named digest/bubblebabble.
+ - Remove RD documents in favor of newly written and embedded
+ RDoc documentation.
+
+Wed Oct 25 08:03:23 2006 Tadayoshi Funaba <tadf@dotrb.org>
-Tue Sep 5 22:06:43 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/date/format.rb: updated based on date2 3.9.6.
+ [ruby-core:09323]
- * ext/tk/tcltklib.c: use rb_ary_new3() since RARRAY_LEN() is not l-value.
+Sun Oct 22 14:48:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/tk/tkutil/tkutil.c: use RARRAY_PTR() and RARRAY_LEN() and etc.
- fixed: [ruby-dev:29473]
+ * signal.c (ruby_signal): don't set SA_RESTART. a backport from
+ the HEAD. [ruby-talk:220937] [ruby-talk:147220]
-Tue Sep 5 06:47:22 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * signal.c (Init_signal): avoid duplicated installation of SIGCHLD
+ handler.
- * time.c (time_to_s): variable declaration after an execution
- statement.
+Sun Oct 22 16:47:56 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Tue Sep 5 05:49:41 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * string.c (rb_str_substr): should be infected with only original
+ string, but not the shared string. fixed: [ruby-core:09152]
- * file.c (path_check_0): check if sticky bit is set on parent
- directories for executable path. fixed: [ruby-dev:29415]
+ * string.c (rb_str_new4): keep shared string untainted when orignal
+ string is tainted. fixed: [ruby-dev:29672]
-Tue Sep 5 05:03:46 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Oct 22 05:20:34 2006 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
- * numeric.c (fix_plus): addition in Fixnum will never overflow
- long. a patch from Ondrej Bilka <neleai at seznam.cz>.
- [ruby-core:08794]
+ * configure.in: alloca is broken; use C_ALLOCA instead.
+ [ruby-dev:29416]
- * numeric.c (fix_minus): ditto.
+Fri Oct 20 10:47:43 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * bignum.c (rb_big_pow): eagerly truncate resulting bignum.
- [ruby-core:08794]
+ * lib/mkmf.rb: fixed the bug of handling COMMON_MACROS.
-Mon Sep 4 23:15:34 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Oct 20 08:42:38 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * time.c (time_to_s): make it conform to RFC2822 date format.
- [ruby-dev:29467]
+ * common.mk (NULLCMD): dummy command.
-Mon Sep 4 21:43:57 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * bcc32/Makefile.sub (post-install-*): Borland make cannot ignore
+ command-less double-colon rules. [ruby-dev:29676]
- * ext/dbm/extconf.rb: create makefile according to the result of check
- for dbm header. fixed: [ruby-dev:29445]
+Fri Oct 20 00:37:07 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Mon Sep 4 21:39:42 2006 Tadayoshi Funaba <tadf@dotrb.org>
+ * bcc32/Makefile.sub ($(LIBRUBY_SO)): execute pre-link hook.
- * lib/date.rb, lib/date/format.rb: updated based on date2 3.9.
+ * ext/extmk.rb: workaround for Borland make.
-Mon Sep 4 21:14:20 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Oct 18 23:02:40 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * time.c (time_strftime): include nul character. fixed: [ruby-dev:29422]
+ * array.c (rb_ary_shift): shorten copy size. fixed: [ruby-list:42907]
-Mon Sep 4 16:39:11 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * signal.c (Init_signal): handle SIGTERM. fixed: [ruby-list:42895]
- * lib/cgi.rb (CGI::out): specify -x option for nkf.
+ * win32/win32.c (rb_w32_utime): allow NULL to set the current time.
+ [ruby-talk:219248]
- * lib/cgi.rb (CGI::out): should not convert utf-8 implicitly using
- NKF. it is too Japanese centric.
+Wed Oct 18 00:55:33 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Mon Sep 4 14:23:10 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * parse.y (parser_yylex): use particular enums. [ruby-core:09221]
- * ext/dbm/extconf.rb (db_check): remove debug print.
+Mon Oct 16 08:30:43 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Mon Sep 4 06:46:08 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * mkconfig.rb: *OBJS are not needed for extension libraries.
- * parse.y (rb_id2sym): intern if id is attrset_id.
- [ruby-dev:29420] [ruby-dev:29447]
+ * {bcc32,wince,win32}/Makefile.sub (config.status): fixed typo,
+ missing comma.
-Mon Sep 4 01:25:16 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Oct 15 01:03:08 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (rb_f_local_variables): list symbols.
+ * lib/test/unit/collector/dir.rb (Collector::Dir#collect): append base
+ directory but not prepend.
- * struct.c (rb_struct_s_members_m): ditto.
+ * lib/test/unit/collector/dir.rb (Collector::Dir#collect_file): do not
+ join with dot. fixed: [ruby-core:09179]
- * variable.c (ivar_i): ditto.
+Sat Oct 14 23:39:50 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * variable.c (gvar_i): ditto.
+ * parse.y (singleton): no need to re-create NODE_SELF() again.
+ [ruby-core:09177]
- * variable.c (cv_i): ditto.
+Sat Oct 14 23:25:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Sun Sep 3 20:47:02 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * parse.y (parser_warning, parser_warn): some error message may
+ contain format specifiers. a patch from Akinori MUSHA <knu at
+ iDaemons.org>. [ruby-dev:29657]
- * ruby.h (SYMBOL_P): Qnil and Qfalse are not Symbol.
+ * ext/bigdecimal/bigdecimal.c (VpException): ditto.
-Sun Sep 3 15:32:44 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/dl/handle.c (rb_dlhandle_initialize): ditto.
- * lib/mkmf.rb: get rid of nil.to_s.
+ * ext/gdbm/gdbm.c (rb_gdbm_fatal): ditto.
-Sun Sep 3 06:24:38 2006 Tanaka Akira <akr@fsij.org>
+Sat Oct 14 08:24:45 2006 Akinori MUSHA <knu@iDaemons.org>
- * ext/socket/socket.c (ruby_connect): sockerrlen should be socklen_t.
+ * ext/digest/lib/digest/hmac: Back out the addition of digest/hmac
+ for now because the API is too premature for a stable branch.
-Sun Sep 3 04:40:42 2006 Tanaka Akira <akr@fsij.org>
+Sat Oct 14 00:55:08 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/socket/extconf.rb: check arpa/inet.h for ntohs.
+ * bcc32/Makefile.sub (post-install-ext): no longer needed.
- * ext/socket/socket.c: include arpa/inet.h if available.
+ * bcc32/configure.bat: get rid of a quirk of Borland make, which
+ sets empty macro in command line to "1".
-Sat Sep 2 23:59:58 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Oct 13 22:50:43 2006 Tadayoshi Funaba <tadf@dotrb.org>
- * string.c (Init_String): undef Symbol#new.
+ * lib/date.rb: updated based on date2 3.9.5.
- * struct.c (rb_struct_s_def): wrong symbol detection.
+Fri Oct 13 22:33:28 2006 Minero Aoki <aamine@loveruby.net>
-Sat Sep 2 23:59:37 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/fileutils.rb (FileUtils.cp_r): dereference_root=true is
+ default in Ruby 1.8. This line is wrongly removed in last commit.
- * string.c (str_to_id): a bug caused by premature optimization.
+Fri Oct 13 18:19:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Sat Sep 2 23:53:28 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * object.c: Class#inherited RDoc added. a patch from Daniel
+ Berger <djberg96 at gmail.com> [ruby-core:08942]
- * object.c (Init_Object): move symbol related code to string.c
+Fri Oct 13 02:30:12 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * string.c (Init_String): Symbol as subclass of String.
+ * lib/test/unit/collector/dir.rb (Collector::Dir#collect): prepend
+ base directory to load path.
- * parse.y (rb_intern2): handle symbol as strings.
+ * lib/test/unit/collector/dir.rb (Collector::Dir#collect_file): should
+ use the given File-like interface, but not File directly.
- * string.c (str_new): substring of symbols are mere strings, not
- symbols.
+ * test/testunit/collector/test_dir.rb (TestDir::FileSystem): implement
+ File-like methods correctly.
-Sat Sep 2 23:37:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Oct 13 01:48:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ruby.h (struct RArray): embed small arrays.
- (RARRAY_LEN): defined for accessing array members.
- (RARRAY_PTR): ditto.
+ * lib/date.rb (Date::self.complete_hash): need to check if g is
+ nil before dereference. [ruby-core:09116]
- * array.c: use RARRAY_LEN and RARRAY_PTR.
+Fri Oct 13 00:34:26 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Sat Sep 2 13:23:01 2006 Tanaka Akira <akr@fsij.org>
+ * object.c (rb_mod_cvar_defined): wrong id check. a patch from
+ Mauricio Fernandez <mfp at acm.org>. [ruby-core:09158]
- * common.mk (ia64.o): use the compiler driver to assemble ia64.s
- to use appropriate ABI.
+ * object.c (rb_mod_cvar_get): typo fixed. [ruby-core:09168]
-Sat Sep 2 12:06:35 2006 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+ * object.c (rb_mod_cvar_set): ditto.
- * lib/soap/generator.rb (SOAP::SOAPGenerator#encode_tag): do not dump
- XML attribute which value is nil. value "" and nil both were dumped
- as 'attr="value"'. [ruby-dev:29395]
+Wed Oct 11 22:21:41 2006 Akinori MUSHA <knu@iDaemons.org>
-Sat Sep 2 11:47:58 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/digest: Merge from trunk; metadata location changed,
+ Digest::Base#reset() added, Digest::Base#equal() changed, and
+ digest/hmac added with some modifications made for ruby 1.8.
- * eval.c (rb_eval): should handle when in else clause. a patch
- from Eric Hodel <drbrain at segment7.net>. [ruby-core:08662]
+Tue Oct 10 17:24:12 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * parse.y (primary): wrap with NODE_CASE. [ruby-core:08663]
+ * {bcc32,win32,wince}/Makefile.sub (config.status): shouldn't use
+ copy command instead of install. use -run install.
-Sat Sep 2 12:00:32 2006 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Tue Oct 10 16:49:16 2006 Akinori MUSHA <knu@iDaemons.org>
- * lib/csv.rb (CSV::IOReader#initialize): use String#[](pos, len)
- instead of String#[](idx) to check utf BOM. follows String#[](idx)
- behavior change of 1.9.
+ * ext/digest/digest.c (hexdigest_str_new, bubblebabble_str_new):
+ Perform StringValue() checks properly.
-Sat Sep 2 11:47:58 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/digest/digest.c: Use RSTRING_{PTR,LEN} macros.
- * eval.c (rb_eval): should handle when in else clause. a patch
- from Eric Hodel <drbrain at segment7.net>. [ruby-core:08662]
+Tue Oct 10 13:49:53 2006 Akinori MUSHA <knu@iDaemons.org>
- * parse.y (primary): wrap with NODE_CASE. [ruby-core:08663]
+ * ext/digest: Merge from trunk; apply all changes since the
+ initial import, except for the removal of compatibility stub
+ libraries (md5.rb and sha1.rb).
-Fri Sep 1 22:07:04 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Oct 9 23:46:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ruby.h (RSTRING_EMBED_LEN_MASK): uses 5 bits to support 64bit
- environment. [ruby-dev:29369]
+ * lib/parsedate.rb: documentation patch from Konrad Meyer
+ <konrad.meyer@gmail.com>. [ruby-doc:1238]
-Fri Sep 1 22:02:08 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/open3.rb, lib/ping.rb: ditto.
- * string.c (rb_str_resize): should copy embedded string to
- malloc'ed buffer. a patch from <nobu at ruby-lang.org> in
- [ruby-dev:29369]. fixed: [ruby-dev:29368]
+Mon Oct 9 22:56:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * string.c (rb_str_ord): use %ld specifier since STRING_LEN() is a
- long. [ruby-dev:29369]
+ * lib/rexml/encoding.rb (REXML::Encoding::check_encoding): spaces
+ are allowed around equal sign. [ruby-core:09032]
-Fri Sep 1 21:41:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rexml/parsers/baseparser.rb (REXML::Parsers::BaseParser): ditto.
- * ext/socket/socket.c (socks_init): typo fixed. a patch from Sven
- Klemm <sven at c3d2.de>. [ruby-core:08770]
+Sat Oct 7 23:53:08 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Sep 1 14:22:42 2006 WATANABE Hirofumi <eban@ruby-lang.org>
+ * string.c (rb_str_scan): small documentation fix.
+ [ruby-core:09007]
- * array.c (rb_ary_shuffle): RDoc fixed.
+Sat Oct 7 23:44:33 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Sep 1 13:52:57 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+ * bignum.c (rb_big_rshift): a bug in right shift of negative
+ bignums. [ruby-core:09020]
- * ext/tk/lib/tk/font.rb: TkFont#current_configinfo() doesn't work
- on Tcl/Tk8.x.
+Sat Oct 7 00:27:58 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Sep 1 09:32:55 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * class.c (rb_include_module): remove unnecessary check.
+ [ruby-talk:218402]
- * lib/irb/ruby-lex.rb (RubyLex::getc): should not push nil into
- reading buffer (@readed). reported in
- <http://jarp.does.notwork.org/diary/200608c.html#200608311>.
+Fri Oct 6 04:30:30 2006 Akinori MUSHA <knu@iDaemons.org>
-Thu Aug 31 23:59:03 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * sample/openssl/c_rehash.rb: Use digest/md5 instead of obsolete md5.
- * lib/mkmf.rb (configuration): follow nil.to_s.
+Wed Oct 4 18:47:25 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-Thu Aug 31 20:50:46 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * ext/tk/lib/tkextlib/*: bugfix and update
+ (see ext/tk/ChangeLog.tkextlib).
- * lib/mkmf.rb (create_makefile): follow nil.to_s.
+Wed Oct 4 17:25:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * win32/resource.rb: ditto.
+ * eval.c (rb_call): check protected visibility based on real self,
+ not ruby_frame->self. [ruby-talk:217822]
-Thu Aug 31 20:21:47 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Oct 4 08:52:30 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (search_required): use RSTRING_PTR and RSTRING_STR.
+ * test/optparse/test_getopts.rb: changed the class name of test case
+ to get rid of conflict with test_optparse.rb.
- * file.c (test_identical, rb_file_s_truncate): ditto.
+Tue Oct 3 23:32:27 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * io.c (pipe_open, rb_io_reopen): ditto.
+ * lib/test/unit/testcase.rb (Test::Unit::TestCase.suite): test name
+ must be string. fixed: [ruby-core:08978]
- * object.c (nil_plus): ditto.
+Mon Oct 2 23:47:55 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * process.c (proc_spawn_n, rb_spawn): ditto.
+ * lib/test/unit/autorunner.rb (Test::Unit::AutoRunner::COLLECTORS):
+ base directory should be lower precedence. fixed: [ruby-dev:29622]
- * util.c (ruby_add_suffix): ditto.
+ * lib/test/unit/autorunner.rb (Test::Unit::AutoRunner#options): typo.
- * ext/Win32API/Win32API.c (Win32API_initialize): ditto.
+ * lib/test/unit/collector/dir.rb (Test::Unit::Collector::Dir#collect_file):
+ load expanded path. fixed: [ruby-dev:29621]
- * ext/dl/cptr.c (rb_dlptr_s_to_ptr): ditto.
+Mon Oct 2 15:49:19 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/openssl/ossl_x509ext.c (ossl_x509extfactory_create_ext): ditto.
+ * instruby.rb: batfile should be CRLF'ed.
- * ext/tk/stubs.c, ext/tk/tcltklib.c, ext/tk/tkutil/tkutil.c: ditto.
+Mon Oct 2 01:24:26 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/win32ole/win32ole.c (ole_val2olevariantdata): ditto.
+ * common.mk (test-all): separate directory where running test cases
+ from source tree.
-Thu Aug 31 18:23:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/test/unit/autorunner.rb (options): added --basedir, --workdir
+ and --load-path options.
- * ruby.h (struct RString): embed small strings.
- (RSTRING_LEN): defined for accessing string members.
- (RSTRING_PTR): ditto.
+ * lib/test/unit/collector/dir.rb (recursive_collect, collect_file):
+ base directory support.
- * string.c: use RSTRING_LEN and RSTRING_PTR.
+Sun Oct 1 23:56:52 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Thu Aug 31 17:16:19 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * Makefile.in, common.mk, ext/extmk.rb, win{32,ce}/Makefile.in: keep
+ LIBRUBY_SO unless need to be removed.
- * array.c (rb_ary_shuffle_bang): new method.
+Sun Oct 1 23:12:19 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * array.c (rb_ary_shuffle): ditto.
+ * lib/optparse.rb (OptionParser#make_switch): pass arguments directly.
- * random.c (genrand_real): ditto.
+Sat Sep 30 15:12:25 2006 Tadayoshi Funaba <tadf@dotrb.org>
- * random.c (genrand_int32): export the function.
+ * lib/date.rb, lib/date/format.rb: updated based on date2 3.9.4.
- * random.c (Init_Random): initialize random seed at the
- beginning.
+Fri Sep 29 12:11:04 2006 WATANABE Hirofumi <eban@ruby-lang.org>
-Thu Aug 31 13:12:06 2006 why the lucky stiff <why@ruby-lang.org>
+ * jcode.rb (succ!): call original succ! if $KCODE == 'n'.
+ fixed: [ruby-talk:216845]
- * eval.c (ruby_init): rename top_cref to ruby_top_cref and export,
- along with ruby_cref, for use by the sandbox. [ruby-core:08762]
+Fri Sep 29 11:43:40 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * node.h: ditto.
+ * lib/mkmf.rb (try_func): revert fallback checking undeclared function.
+ fixed: [ruby-core:08949]
-Wed Aug 30 12:01:57 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Sep 29 09:56:56 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * numeric.c (flo_hash): improve collision.
+ * ext/extmk.rb: extout is needed for also clean.
+ fixed: [ruby-core:08944]
- * string.c (rb_memhash): new generic function to calculate hash value
- for memory chunk.
+ * lib/optparse.rb (OptionParser::Switch#conv_arg): unsplat by
+ Proc#call if no conversion is given.
-Tue Aug 29 19:10:10 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Sep 28 23:59:31 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * hash.c (rb_hash_s_create): fixed memory leak, based on the patch
- by Kent Sibilev <ksruby at gmail.com>. fixed: [ruby-talk:211233]
+ * node.h (struct thread): declare win32_exception_list on cygwin and
+ win32 regardless if it is implemented. Provisional fix for
+ [ruby-core:08917].
-Mon Aug 28 11:29:46 2006 Eric Hodel <drbrain@segment7.net>
+Thu Sep 28 20:53:16 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * eval.c, parse.y: Revert.
- * ext/.document: Add digest.c.
- * ext/digest/digest.c: Make RDoc show up.
- * ext/io/wait.c: Fix call-seq in RDoc.
+ * lib/tmpdir.rb: use return value of getdir.call for length.
-Mon Aug 28 08:03:20 2006 Eric Hodel <drbrain@segment7.net>
+Wed Sep 27 01:04:49 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/.document: Add C files with RDoc.
- * ext/digest/digest.c: Convert to RDoc.
- * ext/io/wait.c: ditto.
- * lib/rdoc/parsers/parse_rb.rb: Fix typo. Submitted by
- <calamitas at gmail.com>. [ruby-core:08724]
+ * lib/mkmf.rb (try_func): check function pointer first and macro next.
-Mon Aug 28 07:21:47 2006 Eric Hodel <drbrain@segment7.net>
+ * lib/mkmf.rb (have_type): simplified with typedef and sizeof.
- * file.c (File#size?): Fix documentation submitted by Rick Ohnemus.
- ruby-Bugs-5529. [ruby-core:08725]
+Tue Sep 26 23:57:03 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sun Aug 27 21:41:23 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
+ * lib/optparse.rb (OptionParser#getopts): use strings as key.
+ fixed: [ruby-dev:29614]
- * oniguruma.h: Version 4.4.0
+Tue Sep 26 15:31:26 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * regint.h: ditto.
+ * {win32,wince}/Makefile.sub (CPP): check predefined value.
- * regparse.h: ditto.
+Tue Sep 26 07:55:16 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * regexec.c: ditto.
+ * array.c (rb_ary_shift): should not move memory region if array
+ body is shared. a patch from Kent Sibilev <ksruby at gmail.com>.
+ [ruby-core:08922]
- * regcomp.c ditto.
+Mon Sep 25 22:26:26 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * regparse.c: ditto.
+ * file.c (rb_path_end): skip root directory. fixed: [ruby-core:08913]
-Sat Aug 26 08:03:03 2006 Tadayoshi Funaba <tadf@dotrb.org>
+ * lib/mkmf.rb (init_mkmf): set default $LDFLAGS. Patch by Michal
+ Suchanek <hramrach at centrum.cz>. [ruby-talk:216256]
- * lib/date.rb, lib/date/format.rb: updated based on date2 3.8.2.
+Mon Sep 25 08:14:43 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Aug 25 21:15:22 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
+ * array.c (rb_ary_shift): should clear shifting top element.
+ [ruby-talk:216055]
- * common.mk: add regint.h and oniguruma.h to dependence.
+ * array.c (rb_ary_shift): avoid creating shared object if array
+ size is small.
- * ext/strscan/depend: ditto.
+Mon Sep 25 08:11:35 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Aug 25 20:35:57 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * random.c (rb_f_rand): RDoc typo fix. a patch from Frederick
+ Cheung <fred at 82ask.com>. [ruby-talk:216047]
- * test/wsdl/document/echo.rb: removed.
+Sun Sep 24 22:28:20 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * test/wsdl/document/test_rpc.rb: remove echo.rb after test.
- [ruby-dev:29337]
+ * runruby.rb: extension library scripts moved into common directory.
-Fri Aug 25 17:02:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Sep 24 14:59:50 2006 Tanaka Akira <akr@fsij.org>
- * gc.c (gc_sweep): typo fixed.
+ * node.h (struct thread): ia64 support is broken by sandbox patch.
-Fri Aug 25 16:05:50 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Sep 24 12:11:16 2006 Tadayoshi Funaba <tadf@dotrb.org>
- * object.c (sym_call): check if the receiver is given.
+ * lib/date.rb, lib/date/format.rb: updated based on date2 3.9.3.
-Fri Aug 25 01:10:11 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sat Sep 23 23:24:57 2006 why the lucky stiff <why@ruby-lang.org>
- * object.c (rb_Integer): Integer(nil) should raise TypeError.
- [ruby-talk:210205]
+ * eval.c (rb_thread_save_context, rb_thread_restore_context):
+ sandbox hook to save and restore sandbox state.
- * object.c (nil_to_s): no longer returns empty string but "nil".
- [ruby-talk:210205]
+ * eval.c (thread_no_ensure): added THREAD_NO_ENSURE thread flag.
- * lib/mkmf.rb: avoid COMMON_HEADERS being nil.
+ * eval.c (rb_thread_kill_bang): Thread#kill! uses the above flag
+ to circumvent ensure, in order to prevent endless loops.
+ [ruby-core:08768]
-Wed Aug 23 00:25:14 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * eval.c (rb_thread_kill): fix Thread#kill docs, which returns
+ the thread object in all cases.
- * lib/rexml/source.rb (REXML::IOSource#initialize): encoding have to
- be set with the accessor. fixed: [ruby-list:42737]
+ * node.h: expose the rb_jmpbuf_t and rb_thread_t structs, along
+ with the thread flags. used by the sandbox extension.
-Tue Aug 22 19:21:00 2006 Minero Aoki <aamine@loveruby.net>
+ * ruby.h: extern rb_eThreadError, so sandbox can swap it.
- * lib/net/smtp.rb: parameter `to_addrs' might be an Array,
- .flatten is required. [ruby-dev:29316]
+Sat Sep 23 21:34:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Tue Aug 22 18:47:51 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/cgi.rb (CGI::QueryExtension::read_multipart): CGI content
+ may be empty. a patch from Jamis Buck <jamis at 37signals.com>.
- * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::handle_method):
- rdoc documents C module methods as instance methods. a patch in
- [ruby-core:08536].
+Sat Sep 23 08:35:53 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Tue Aug 22 12:35:57 2006 NARUSE, Yui <naruse@ruby-lang.org>
+ * lib/rdoc/ri/ri_options.rb: prevent NameError. [ruby-dev:29597]
- * ext/nkf/lib/kconv.rb (Kconv::RegexpEucjp): fix regexp for
- euc-jp [ruby-dev:29344]
+Sat Sep 23 01:04:20 2006 Tadayoshi Funaba <tadf@dotrb.org>
-Sun Aug 20 11:46:52 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/date.rb, lib/date/format.rb: updated based on date2 3.9.2.
- * numeric.c (num_step): also return an enumerator object if no block
- is given.
+Fri Sep 22 02:06:26 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Sat Aug 19 16:47:51 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+ * .cvsignore: ignore timestamp files and installed list file.
- * ext/win32ole/win32ole.c (hash2named_arg): accept hash argument
- of symbol key.
+Fri Sep 22 01:36:34 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * test/win32ole/test_win32ole.rb
- ditto.
+ * instruby.rb: include FileUtils unconditionally.
-Sat Aug 19 11:28:08 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Sep 21 22:56:20 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * file.c (rb_file_s_rename): use errno if set properly.
- fixed: [ruby-dev:29293]
+ * common.mk (no-install): not install rdoc actually.
-Fri Aug 18 01:05:57 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * common.mk (install-doc, no-install-doc): use instruby.rb.
- * lib/cgi.rb (CGI::out): specify -m0 to disable MIME decode. a
- patch from Fujioka <fuj at rabbix.jp>. [ruby-dev:29284]
+ * instruby.rb: rdoc installation.
-Thu Aug 17 19:15:16 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/extmk.rb: expand ruby executable names.
- * file.c (rb_stat_[rRwWxX]): check for super user.
- fixed: [ruby-core:08616]
+Thu Sep 21 13:55:07 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Thu Aug 17 14:47:06 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/etc/etc.c (etc_getpwuid): uid integer should be wraped in
+ uid_t value. [ruby-core:08897]
- * lib/mkmf.rb: added rdoc by Daniel Berger. [ruby-core:08177]
+ * ext/etc/etc.c (etc_getpwuid): uid_t may be bigger than plain
+ 'int' type.
-Wed Aug 16 17:46:59 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Sep 20 23:17:41 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * marshal.c (r_byte): IO#getc returns one byte string now.
- fixed: [ruby-dev:29255]
+ * common.mk (pre-install-doc): create data directory before install.
-Wed Aug 16 17:22:44 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * lib/mkmf.rb (dir_re): fixed typo.
- * common.mk (pre-install-local): remove unnecessary code.
- [ruby-dev:29249]
+ * lib/mkmf.rb (install_dirs): remove extra slash.
-Wed Aug 16 11:45:36 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Sep 20 09:53:38 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * process.c (proc_setuid, proc_setgid, proc_seteuid, proc_setegid):
- get rid of bogus implementations on Mac OS X.
+ * {bcc32,win32,wince}/Makefile.sub (INSTALLED_LIST): need to define
+ this macro to install.
-Wed Aug 16 11:09:26 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Sep 20 09:43:10 2006 Shugo Maeda <shugo@ruby-lang.org>
- * ruby.c (set_arg0): fill argv other than the first with an empty
- string instead of NULL.
+ * lib/net/imap.rb: allow extra spaces in responses.
+ Thanks, Tom Soderlund. (backported from HEAD)
-Tue Aug 15 11:21:08 2006 Minero Aoki <aamine@loveruby.net>
+Wed Sep 20 09:25:39 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/net/smtp.rb: support SMTP/SSL. Thanks Kazuhiro NISHIYAMA.
+ * ext/gdbm/gdbm.c: add RDoc documentation. a patch from Peter
+ Adolphs <futzilogik at users dot sourceforge dot net>.
+ [ruby-doc:1223]
- * lib/net/smtp.rb: new method SMTP.use_ssl?
+Tue Sep 19 01:28:00 2006 Minero Aoki <aamine@loveruby.net>
- * lib/net/smtp.rb: new method SMTP.enable_ssl.
+ * lib/fileutils.rb: backport from HEAD (rev 1.71).
- * lib/net/smtp.rb: new method SMTP.disable_ssl.
+ * lib/fileutils.rb (FileUtils.cp_r): new option
+ :remove_destination.
- * lib/net/smtp.rb: new method SMTP.default_ssl_port.
+Tue Sep 19 00:42:15 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/net/smtp.rb: new method SMTP.default_tls_port.
+ * object.c (rb_obj_ivar_defined, rb_mod_cvar_defined): new methods,
+ Kernel#instance_variable_defined? and Module#class_variable_defined?.
+ [ruby-dev:29587]
- * lib/net/smtp.rb: now SMTP#enable_tls accepts a SSLContext
- object, instead of a verity and cert. [FEATURE CHANGE]
+ * lib/date/format.rb (Date::Bag#method_missing): use new method,
+ instance_variable_defined? to check if an instance variable is
+ defined. fixed: [ruby-dev:29554]
+ -- This didn't fix anything.
- * lib/net/smtp.rb: new method SMTP.ssl_context.
+Sun Sep 17 23:44:58 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/net/smtp.rb: new method SMTP.default_ssl_context.
+ * lib/rdoc/rdoc.rb (RDoc::RDoc#document): scan only files modified
+ after the previous generation.
- * lib/net/smtp.rb: export SMTP.authenticate.
+Sun Sep 17 17:42:13 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/net/smtp.rb: export SMTP.auth_plain.
+ * common.mk (install-doc): reverted.
- * lib/net/smtp.rb: export SMTP.auth_login.
+ * instruby.rb: stores file name list without destdir prefix.
- * lib/net/smtp.rb: export SMTP.auth_cram_md5.
+ * lib/rdoc/generators/ri_generator.rb: do not chdir twice.
- * lib/net/smtp.rb: export SMTP.starttls.
+Sat Sep 16 23:14:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/net/smtp.rb: export SMTP.helo.
+ * ext/pty/pty.c (establishShell): remove remaining unused line.
- * lib/net/smtp.rb: export SMTP.ehlo.
+Sat Sep 16 16:40:44 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/net/smtp.rb: export SMTP.mailfrom.
+ * Makefile.in, common.in, instruby.rb, ext/extmk.rb, lib/mkmf.rb:
+ use instruby.rb to install extensions instead of ext/extmk.rb.
- * lib/net/smtp.rb: export SMTP.rcptto.
+ * instruby.rb: store installed list into the file.
- * lib/net/smtp.rb: export SMTP.rcptto_list.
+ * ext/dbm/extconf.rb: allow multiple candidates for dbm-type.
- * lib/net/smtp.rb: export SMTP.data.
+ * ext/io/wait/extconf.rb: suspicious checking_for.
- * lib/net/smtp.rb: export SMTP.quit.
+ * ext/pty/pty.c (establishShell): parent pid is not used.
-Sat Aug 12 22:33:06 2006 Eric Hodel <drbrain@segment7.net>
+ * ext/pty/pty.c (freeDevice): not used.
- * string.c (String#split): Describe grouping behavior. Patch by Jan
- Svitok <jan.svitok at gmail.com>. [ruby-core:08603]
+ * ext/pty/pty.c (get_device_once): removed garbage right brace.
-Sun Aug 13 12:08:02 2006 Tanaka Akira <akr@fsij.org>
+ * lib/mkmf.rb (checking_for): improved the messages.
- * ext/socket/socket.c: ANSIfied. [ruby-core:08601]
+Thu Sep 14 16:11:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Sat Aug 12 15:55:32 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * string.c (rb_str_intern): raise SecurityError only when $SAFE
+ level is greater than zero. [ruby-core:08862]
- * configure.in, bcc32/Makefile.sub, win32/Makefile.sub, win32/dir.h,
- win32/win32.c, win32/win32.h: large file support for win32.
+ * parse.y (rb_interned_p): new function to check if a string is
+ already interned.
-Fri Aug 11 15:39:25 2006 Eric Hodel <drbrain@segment7.net>
+ * object.c (str_to_id): use rb_str_intern().
- * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#find_body): Make RDoc
- ignore C function prototypes. Patch by Tilman Sauerbeck
- <tilman at code-monkey.de>. [ruby-core:8574]
- * lib/yaml/tag.rb: Replace nodoc with stopdoc so Module methods get
- documented.
+Wed Sep 13 18:43:05 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * README.EXT: English adjustment. [ruby-core:08851] and
+ [ruby-core:08852]
+
+Wed Sep 13 18:25:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * misc/ruby-mode.el (ruby-parse-partial): better here-doc support.
+ a patch from Marshall T. Vandegrift <llasram at gmail.com>.
+ [ruby-core:08804]
+
+Wed Sep 13 16:43:36 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_intern): prohibit interning tainted string.
+
+Wed Sep 13 01:14:21 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/optparse.rb (OptionParser#getopts): works with pre-registered
+ options. [ruby-core:08826]
+
+Sun Sep 10 20:27:13 2006 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * lib/date.rb, lib/date/format.rb: updated based on date2 3.9.1.
+
+Tue Jan 10 09:18:03 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (stack_extend): fixed prototype.
+
+ * eval.c (rb_require_safe): prevent extension from loading twice.
+ fixed: [ruby-dev:29523]
+
+Sat Sep 9 23:50:38 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * bignum.c (rb_big_mul0): bignum multiplication without
+ normalization.
+
+ * bignum.c (rb_big_pow): use rb_big_mul0(). [ruby-dev:29547]
+
+Sat Sep 9 14:08:38 2006 Eric Hodel <drbrain@segment7.net>
+
+ * lib/test/unit/testcase.rb (Test::Unit::TestCase#run): Rescue
+ Exception in Test::Unit::TestCase#run. [ruby-core:08783]
+
+Sat Sep 9 04:55:59 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/pstore.rb: open all in binary mode, and get rid of the quirk of
+ msvcrt. fixed: [ruby-dev:29518]
+
+Sat Sep 9 04:54:42 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * Makefile.in, win32/Makefile.sub (MINIRUBY): append MINIRUBYOPT.
+
+ * mkconfig.rb, ext/extmk.rb, lib/mkmf.rb, win32/mkexports.rb: suppress
+ warnings with $VERBOSE.
+
+ * ext/extmk.rb: Proc#call does not pass the block in 1.8.
-Wed Aug 9 16:53:28 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * win32/resource.rb: add more info.
- * lib/net/smtp.rb (Net::SMTP::auth_cram_md5): use ord to retrieve
- bytes from strings. a patch from WATANABE Tetsuya
- <Tetsuya.WATANABE at nifty.com>. [ruby-dev:29240]
+Fri Sep 8 10:03:59 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * lib/webrick/cookie.rb (WEBrick::Cookie.parse_set_cookies): new
+ method to parse multiple cookies per Set-Cookie header.
+ Thanks to Aaron Patterson <aaron_patterson at speakeasy.net>.
+ [ruby-core:08802]
+
+Fri Sep 8 08:59:30 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * win32/Makefile.sub, win32/configure.bat win32/setup.mak: program
+ name transform.
+
+Fri Sep 8 01:33:08 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ruby.h (RSTRING_PTR): add migration macro.
+
+ * ruby.h (RARRAY_PTR): ditto.
+
+Thu Sep 7 23:27:05 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * file.c (path_check_0, fpath_check): disable path check on cygwin.
+ [ruby-talk:213074]
+
+Wed Sep 06 12:05:19 2006 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * ext/nkf/lib/kconv.rb (Kconv::RegexpEucjp): fix regexp for euc-jp
+ [ruby-dev:29344]
+
+ * ext/nkf/lib/kconv.rb (Kconv::toeuc): remove -m0 [ruby-dev:29505]
+
+Tue Sep 5 06:47:22 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * time.c (time_to_s): variable declaration after an execution
+ statement.
+
+Tue Sep 5 05:56:51 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * numeric.c (flo_hash): improve collision. fixed: [ruby-dev:29352]
+
+Tue Sep 5 05:49:41 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * file.c (path_check_0): check if sticky bit is set on parent
+ directories for executable path. fixed: [ruby-dev:29415]
+
+Tue Sep 5 05:03:46 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * numeric.c (fix_plus): addition in Fixnum will never overflow
+ long. a patch from Ondrej Bilka <neleai at seznam.cz>.
+ [ruby-core:08794]
+
+ * numeric.c (fix_minus): ditto.
+
+ * bignum.c (rb_big_pow): eagerly truncate resulting bignum.
+ [ruby-core:08794]
+
+Mon Sep 4 23:15:34 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * time.c (time_to_s): make it conform to RFC2822 date format.
+ [ruby-dev:29467]
+
+Mon Sep 4 21:43:57 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/dbm/extconf.rb: create makefile according to the result of check
+ for dbm header. fixed: [ruby-dev:29445]
+
+Mon Sep 4 21:42:35 2006 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * lib/date.rb, lib/date/format.rb: updated based on date2 3.9.
+
+Mon Sep 4 21:14:20 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * time.c (time_strftime): include nul character. fixed: [ruby-dev:29422]
+
+Mon Sep 4 16:29:33 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/cgi.rb (CGI::out): specify -m0 -x option for nkf.
+ [ruby-dev:29284]
+
+Mon Sep 4 16:13:23 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * io.c (pipe_open): command name should not contain null bytes.
+ [ruby-dev:29421]
+
+ * process.c (proc_spawn): ditto.
+
+ * process.c (proc_spawn_n): ditto.
+
+ * process.c (rb_f_system): ditto.
+
+Sun Sep 3 15:32:44 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/mkmf.rb: get rid of nil.to_s.
+
+Sun Sep 3 06:24:38 2006 Tanaka Akira <akr@fsij.org>
+
+ * ext/socket/socket.c (ruby_connect): sockerrlen should be socklen_t.
+
+Sun Sep 3 04:40:42 2006 Tanaka Akira <akr@fsij.org>
+
+ * ext/socket/extconf.rb: check arpa/inet.h for ntohs.
+
+ * ext/socket/socket.c: include arpa/inet.h if available.
+
+Sun Sep 3 02:34:55 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+
+ * lib/drb/unix.rb (DRbUNIXSocket#close): don't get path if client mode.
+ [ruby-dev:29417]
+
+Sun Sep 3 01:45:17 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+
+ * lib/drb/acl.rb (ACLEntry#initialize): examine whether '*' is
+ included before IPAddr.new. [ruby-dev:29406]
+
+Sat Sep 2 13:23:01 2006 Tanaka Akira <akr@fsij.org>
+
+ * common.mk (ia64.o): use the compiler driver to assemble ia64.s
+ to use appropriate ABI.
+
+Sat Sep 2 03:36:22 2006 Tanaka Akira <akr@fsij.org>
+
+ * common.mk, configure.in, defines.h, eval.c, gc.c, main.c,
+ numeric.c, ruby.h, ia64.s: backport IA64 HP-UX support.
+
+Fri Sep 1 13:52:57 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * ext/tk/lib/tk/font.rb: TkFont#current_configinfo() doesn't work
+ on Tcl/Tk8.x.
+
+Thu Aug 31 12:46:55 2006 why the lucky stiff <why@ruby-lang.org>
+
+ * eval.c (ruby_init): rename top_cref to ruby_top_cref and export,
+ along with ruby_cref, for use by the sandbox. [ruby-core:08762]
+
+ * node.h: ditto.
+
+Tue Aug 29 19:10:10 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * hash.c (rb_hash_s_create): fixed memory leak, based on the patch
+ by Kent Sibilev <ksruby at gmail.com>. fixed: [ruby-talk:211233]
+
+Mon Aug 28 11:36:02 2006 Eric Hodel <drbrain@segment7.net>
+
+ * lib/rdoc/parsers/parse_rb.rb: Fix typo. Submitted by
+ <calamitas at gmail.com>. [ruby-core:08724]
+
+Mon Aug 28 07:53:44 2006 Eric Hodel <drbrain@segment7.net>
+
+ * lib/rdoc/ri/ri_formatter.rb: Don't unescape HTML in HtmlFormatter.
+ Submitted by Kent Sibilev <ksruby at gmail.com>. [ruby-core:08392].
+
+Mon Aug 28 07:25:45 2006 Eric Hodel <drbrain@segment7.net>
+
+ * file.c (File#size?): Fix documentation submitted by Rick Ohnemus.
+ ruby-Bugs-5529. [ruby-core:08725]
+
+Sat Aug 26 08:07:13 2006 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * lib/date.rb, lib/date/format.rb: updated based on date2 3.8.2.
+
+Fri Aug 25 22:32:04 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/rexml/source.rb (REXML::IOSource#initialize): encoding have to
+ be set with the accessor. fixed: [ruby-list:42737]
+
+Fri Aug 25 17:15:17 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * stable version 1.8.5 released.
+
+Fri Aug 25 17:02:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * gc.c (gc_sweep): typo fixed.
+
+Tue Aug 22 18:47:51 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::handle_method):
+ rdoc documents C module methods as instance methods. a patch in
+ [ruby-core:08536].
+
+Sat Aug 19 14:15:02 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/Makefile.sub (config.status): include winsock2.h instead of
+ winsock.h when --with-winsock2 is specified.
+ fixed: [ruby-dev:29296]
+
+Sat Aug 19 11:28:08 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * file.c (rb_file_s_rename): use errno if set properly.
+ fixed: [ruby-dev:29293]
+
+Sat Aug 19 11:09:23 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * parse.y (then): remove semicolon warning. [ruby-dev:29299]
+
+Thu Aug 17 19:15:16 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * file.c (rb_stat_[rRwWxX]): check for super user.
+ fixed: [ruby-core:08616]
+
+Thu Aug 17 14:47:06 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/mkmf.rb: added rdoc by Daniel Berger. [ruby-core:08177]
+
+Thu Aug 17 00:39:05 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+
+ * lib/rinda/ring.rb (do_reply): Fix for RingServer fails to find a
+ TupleSpace when TupleSpace resides in the same ruby process with
+ RingServer. a patch from Kent Sibilev. [ruby-core:08453]
+
+Wed Aug 16 11:45:36 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * process.c (proc_setuid, proc_setgid, proc_seteuid, proc_setegid):
+ get rid of bogus implementations on Mac OS X.
+
+Tue Aug 15 19:10:18 2006 Eric Hodel <drbrain@segment7.net>
+
+ * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#find_class_comment): Fix
+ broken class-level documentation.
+
+Wed Aug 16 11:09:26 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ruby.c (set_arg0): fill argv other than the first with an empty
+ string instead of NULL.
+
+Wed Aug 16 11:08:00 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * win32/win32.h: removed an excess macro. fixed: [ruby-dev:29258]
Tue Aug 8 23:49:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -1992,23 +3443,17 @@ Tue Aug 8 23:49:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
RDoc. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:08522]
-Tue Aug 8 19:26:10 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/resolv.rb (Resolv::DNS::Message::MessageDecoder::get_string):
- affected by str[0] returns 1 char string. [ruby-dev:29223]
-
- * lib/resolv.rb (Resolv::DNS::Message::MessageDecoder::get_labels):
- ditto.
-
-Tue Aug 8 12:28:43 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Aug 8 11:32:54 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * parse.y (arg): allow newlines before ternary colon. [ruby-dev:29189]
+ * Makefile.in, common.mk, configure.in: fix for platforms without
+ rm. patches from Yutaka kanemoto <kinpoco at gmail.com>.
+ [ruby-dev:29215]
Mon Aug 7 17:56:59 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/bigdecimal/bigdecimal.c, ext/digest/rmd160/rmd160ossl.c,
ext/digest/sha1/sha1ossl.c, ext/readline/readline.c: move
- inclusion of config.h to pacify AIX. a patch from Yutaka
+ incluion of config.h to pacify AIX. a patch from Yutaka
Kanemoto <kinpoco at gmail.com>. [ruby-dev:29197]
Mon Aug 7 15:55:08 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -2025,58 +3470,33 @@ Mon Aug 7 14:37:48 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
Mon Aug 7 12:05:28 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * dln.c, eval.c, gc.c, ruby.h: shut up AIX alloca warning.
- a patch from Yutaka Kanemoto <kinpoco at gmail.com>.
+ * dln.c, eval.c, gc.c, regex.c, ruby.h: shut up AIX alloca
+ warning. a patch from Yutaka Kanemoto <kinpoco at gmail.com>.
[ruby-dev:29191]
-Sun Aug 6 20:34:24 2006 Tadayoshi Funaba <tadf@dotrb.org>
+Sun Aug 6 20:40:41 2006 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date/format.rb (str[fp]time): %[EO]U didn't denote %U.
-Sun Aug 6 17:12:12 2006 Tanaka Akira <akr@fsij.org>
-
- * io.c (io_reopen): STDERR.reopen(open("/dev/tty", "w")) should not
- clear FMODE_PREP in STDERR.
-
-Sat Aug 5 22:53:41 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * oniguruma.h: Version 4.2.2
-
- * regint.h: ditto.
-
- * regparse.h: ditto.
-
- * regexec.c: ditto.
-
- * regcomp.c ditto.
-
- * regerror.c: ditto.
-
- * regparse.c: ditto.
-
Sat Aug 5 17:07:43 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (top_local_setup): local_vars[-1] should point
ruby_scope itself to protect local_tbl from garbage collection.
[ruby-dev:29049]
-Sat Aug 5 13:49:43 2006 Tadayoshi Funaba <tadf@dotrb.org>
+Sat Aug 5 13:54:03 2006 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date/format.rb (str[fp]time): "%\n" means "\n".
-Fri Aug 4 12:13:22 2006 Eric Hodel <drbrain@segment7.net>
+Fri Aug 4 15:21:00 2006 Eric Hodel <drbrain@segment7.net>
- * lib: Clean up files for RDoc.
- * lib/.document: Include most of the standard library in RDoc
- generation.
- * lib/rdoc/ri/ri_formatter.rb: Don't unescape HTML in HtmlFormatter.
- Submitted by <ksruby at gmail.com>. [ruby-core:08392].
+ * lib: Merge RDoc and .document from HEAD.
* lib/drb/ssl.rb: Close socket on SSLError [ruby-core:7197]
-Fri Aug 4 18:59:49 2006 Keiju Ishitsuka <keiju@ruby-lang.org>
+Fri Aug 4 19:13:41 2006 Keiju Ishitsuka <keiju@ruby-lang.org>
* lib/irb/{init.rb,ruby-lex.rb,slex.rb}: can't input '\c' for
- [ruby-core: 7122]. and support for ruby1.8.X
+ [ruby-core: 7122].
Fri Aug 4 14:02:14 2006 James Edward Gray II <james@grayproductions.net>
@@ -2089,22 +3509,15 @@ Fri Aug 4 13:56:51 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* pack.c (pack_pack): check argument overrun for 'P'. based on a
patch by rucila <rucila at yahoo.cojp>. fixed: [ruby-dev:29182]
-Fri Aug 4 02:42:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * sprintf.c (rb_str_format): a bug in %c type check.
+Tue Aug 1 17:44:03 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Fri Aug 4 01:28:19 2006 Tanaka Akira <akr@fsij.org>
-
- * io.c (io_reopen): STDERR.reopen(File.open("/dev/null", "w")) should
- not fclose stderr.
+ * win32/win32.c (init_stdhandle): assign standard file handles.
-Thu Aug 3 15:16:44 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Tue Aug 1 12:24:58 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * range.c (range_include): should always call Enumerable#include?
- (not #===) for non numeric end points. [ruby-core:08477]
- [ruby-core:08496]
+ * eval.c (Init_Binding): fix old commit miss.
-Mon Jul 31 16:51:40 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Mon Jul 31 17:08:20 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (exit_handler): new function; release winsock and
environment work area.
@@ -2115,7 +3528,7 @@ Mon Jul 31 16:51:40 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_getenv): use GetEnvironmentStrings() instead
of GetEnvironmentVariable(), because the latter cannot distinguish
- whether a null environment variable exists or not.
+ wheather a null environment variable exists or not.
fixed: [ruby-talk:205123]
Mon Jul 31 16:15:13 2006 Tanaka Akira <akr@fsij.org>
@@ -2124,18 +3537,18 @@ Mon Jul 31 16:15:13 2006 Tanaka Akira <akr@fsij.org>
setrlimit may fail with EINVAL.
reported by MIYAMUKO Katsuyuki. [ruby-dev:29174]
+Mon Jul 31 13:38:22 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * lib/webrick/httprequest.rb (WEBrick::HTTPReuqest#parse_uri): improve
+ for the value of IPv6 address in the Host: header field.
+
Mon Jul 31 09:22:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ruby.h: use ifdef (or defined) for macro constants that may or
may not be defined to shut up gcc's -Wundef warnings.
[ruby-core:08447]
-Mon Jul 31 13:38:13 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httprequest.rb (WEBrick::HTTPReuqest#parse_uri): improve
- for the value of IPv6 address in the Host: header field.
-
-Sun Jul 30 23:26:12 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Jul 30 23:26:22 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_call0): trace call/return of method defined from block.
fixed: [ruby-core:08329]
@@ -2157,33 +3570,9 @@ Sat Jul 29 01:23:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
statement back before the comment block. a patch from Hugh
Sasse <hgs at dmu.ac.uk>. [ruby-core:08422]
-Fri Jul 28 17:18:03 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/curses/curses.c (NUM2CH, CH2FIX): use single char strings.
-
-Fri Jul 28 14:09:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_call): fixed typo in cache look-up. [ruby-dev:29167]
-
-Fri Jul 28 10:41:35 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_call): a bug in method cache look-up.
- http://www.rubyist.net/~matz/20060720.html#c04
-
-Fri Jul 28 10:19:28 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): documentation update patch from Jacob
- Fugal <lukfugl at gmail.com>. [ruby-core:08418]
-
-Fri Jul 28 09:41:45 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * time.c (time_to_s): fixed typo. [ruby-dev:29162]
-
-Fri Jul 28 00:26:47 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * math.c (domain_check): ANSI style function arguments
+Thu Jul 27 22:21:52 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * math.c (math_log): too few argument to domain_check().
+ * time.c (time_to_s): fixed format mismatch.
Thu Jul 27 21:19:54 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -2196,10 +3585,6 @@ Thu Jul 27 21:19:54 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* math.c (math_sqrt): fix documentation flaw.
-Thu Jul 27 22:21:52 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * time.c (time_to_s): fixed format mismatch.
-
Thu Jul 27 18:12:12 2006 WATANABE Hirofumi <eban@ruby-lang.org>
* time.c: need to declare time_utc_offset.
@@ -2209,19 +3594,23 @@ Thu Jul 27 17:01:01 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_close): always calls "close" method of the receiver.
[ruby-core:6911] [ruby-core:8112]
+Thu Jul 27 16:49:01 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * time.c (time_to_s): use +0900 style timezone string for local time.
+ [ruby-dev:29143]
+
Thu Jul 27 16:41:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/openssl/ossl.h: move <ruby.h> inclusion point to shut up
Solaris compiler. [ruby-core:08114]
- * time.c (time_to_s): use +0900 style timezone string for local time.
- [ruby-dev:29143]
-
Wed Jul 26 22:20:59 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* configure.in: add support for as and ASFLAGS. [ruby-dev:29138]
-Wed Jul 26 21:59:33 2006 Minero Aoki <aamine@loveruby.net>
+Wed Jul 26 22:13:45 2006 Minero Aoki <aamine@loveruby.net>
+
+ * lib/net/http.rb: sync with HEAD (rev 1.132).
* lib/net/http.rb (Net::HTTP#post, request_post, request): should
set Content-Type: x-www-form-urlencoded by default.
@@ -2235,37 +3624,21 @@ Wed Jul 26 21:59:33 2006 Minero Aoki <aamine@loveruby.net>
* lib/net/http.rb (Net::HTTPHeader#type_params): wrongly failed
when there's no Content-Type.
-Wed Jul 26 18:38:13 2006 Minero Aoki <aamine@loveruby.net>
-
- * ext/strscan/strscan.c (strscan_do_scan): always return nil if
- p->curr exceeds string size.
-
-Wed Jul 26 18:33:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Jul 26 18:35:38 2006 Minero Aoki <aamine@loveruby.net>
- * eval.c (Init_eval): rename #invoke_method and
- #invoke_functional_method to __send and __send! respectively.
+ * ext/strscan/strscan.c: sync with HEAD (rev 1.25).
- * eval.c (remove_method): prohibit removing __send and __send!.
-
- * eval.c (rb_undef): prohibit undef'ing __send and __send!.
-
- * eval.c (rb_eval): prohibit redefining __send and __send!.
-
- * lib/delegate.rb (Delegator): preserve __send.
+ * ext/strscan/strscan.c (strscan_do_scan):
+ StringScanner.new("").scan(//) should return "". [ruby-Bugs:4361]
Wed Jul 26 18:14:19 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/pty/pty.c (getDevice): retry once after GC on failure.
[ruby-core:08282]
-Wed Jul 26 17:43:20 2006 Minero Aoki <aamine@loveruby.net>
-
- * ext/strscan/strscan.c (strscan_do_scan):
- StringScanner.new("").scan(//) should return "". [ruby-Bugs:4361]
-
Wed Jul 26 17:28:16 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * sprintf.c (rb_str_format): prepend ".." to %u for negative bignum,
+ * sprintf.c (rb_f_sprintf): prepend ".." to %u for negative bignum,
but not "-". fixed: [ruby-core:08167]
Wed Jul 26 16:39:07 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -2283,7 +3656,11 @@ Wed Jul 26 01:02:59 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in: suppress warnings by automake 1.8 or later.
-Tue Jul 25 14:46:14 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Jul 25 00:30:06 2006 Eric Hodel <drbrain@segment7.net>
+
+ * lib/prettyprint.rb: RD to RDoc conversion by Hugh Sasse.
+
+Tue Jul 25 14:49:51 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/mkmf.rb (configuration): typo.
@@ -2296,6 +3673,13 @@ Mon Jul 24 22:03:40 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (backtrace): skip frames successive on node and method name.
+Mon Jul 24 17:55:55 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * process.c (rb_f_system): add security check. [ruby-talk:202947]
+
+ * process.c (rb_f_system): move signal right before fork to avoid
+ signal handler intervention.
+
Mon Jul 24 15:51:52 2006 Tanaka Akira <akr@fsij.org>
* ext/readline/readline.c (readline_readline): rl_deprep_term_function
@@ -2311,61 +3695,36 @@ Sun Jul 23 22:59:49 2006 Tanaka Akira <akr@fsij.org>
* test/socket/test_unix.rb: disabled on cygwin.
reported by Kouhei Yanagita. [ruby-dev:29080]
-Fri Jul 21 23:57:26 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ruby.c (proc_options): script is never used while recursing.
-
Fri Jul 21 21:21:08 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_call0): include funcalled methods in caller list.
fixed: [ruby-core:08290]
-Fri Jul 21 17:52:24 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (rb_cstr_to_dbl): "9_e8" should consider "_e8" as
- trailing garbage so that it should return 9.0. [ruby-dev:29088]
-
Fri Jul 21 12:11:00 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb, lib/mkmf.rb (with_destdir): remove drive letter before
prepending destdir on DOSISH.
-Fri Jul 21 04:17:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_call): try local method look-up first for fcall, then
- normal method look-up. [ruby-talk:202564]
-
- * eval.c (rb_get_method_body): save local method cache separately.
-
- * eval.c (search_method): export info whether method is local or
- not.
-
-Thu Jul 20 20:27:07 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (rb_mod_attr): make Module#attr to be an alias to
- attr_reader. [RCR#331]
-
Thu Jul 20 15:07:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ruby.h: export classes/modules to implement sandbox.
[ruby-core:08283]
-Wed Jul 19 19:40:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Thu Jul 20 00:06:29 2006 Keiju Ishitsuka <keiju@ishitsuka.com>
- * eval.c (rb_yield_0): should check args_args before lambda
- argument check. [ruby-dev:29029]
+ * lib/irb/completion.rb: support for completion of numeric
+ number. [ruby-dev: 29038]
-Tue Jul 18 23:53:59 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Jul 19 23:53:05 2006 Kouhei Sutou <kou@cozmixng.org>
- * process.c (rb_f_system): shouldn't block SIGCHLD if it's not
- exist.
+ * lib/rss/parser.rb, lib/rss/utils.rb: added documents.
Tue Jul 18 22:10:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* process.c (rb_f_system): block SIGCHLD during the process
execution, like glibc system(3) does. [ruby-talk:202361]
-Tue Jul 18 23:10:43 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Jul 18 23:12:14 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (open_ifs_socket): should not use plain malloc.
@@ -2376,11 +3735,6 @@ Tue Jul 18 18:05:49 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* test/ruby/test_float.rb (TestFloat::test_strtod): update test to
conform strtod change.
-Tue Jul 18 16:52:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (yield_under_i): argument should be passed in avalue
- form. [ruby-dev:29044]
-
Tue Jul 18 15:49:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (pack_unpack): propagate association array to copied
@@ -2392,15 +3746,6 @@ Tue Jul 18 15:49:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (pack_pack): taint 'p' packed strings.
-Tue Jul 18 15:19:07 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * intern.h (st_foreach_safe): fix prototype.
-
- * node.h (NODE_LMASK): bigger than long on LLP64.
-
- * missing/vsnprintf.c (BSD__uqtoa): new function to support LLP64.
- all changes are derived from [ruby-dev:29045]
-
Tue Jul 18 14:03:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/webrick/httpserver.rb (WEBrick::HTTPServer::unmount): remove
@@ -2427,23 +3772,23 @@ Mon Jul 17 23:30:46 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (rb_cv_msvcrt): defaulted to msvcrt. Workaround for a
bug of cygwin 1.5.20.
-Mon Jul 17 22:55:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/io/wait/wait.c (io_ready_p): protoize.
-
Mon Jul 17 13:43:05 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (define_swapx): should not use plain malloc.
- * ext/curses/curses.c (curses_getmouse): ditto.
-
Mon Jul 17 12:58:41 2006 WATANABE Hirofumi <eban@ruby-lang.org>
* configure.in: should use ac_cv_lib_dl_dlopen=no on MinGW.
-Mon Jul 17 11:47:35 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Sat Jul 15 23:50:12 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (rb_require_safe): wait for another thread requiring the same
+ feature. fixed: [ruby-core:08229]
- * st.c: still need to include config.h on some platforms.
+Sat Jul 15 01:27:13 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * dir.c (has_magic): glob names contain alphabets to enable case fold
+ search also for directories. fixed: [ruby-talk:201917]
Sat Jul 15 01:09:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -2451,6 +3796,8 @@ Sat Jul 15 01:09:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
malloc/calloc, to detect memory allocation failure. see
<http://www.nongnu.org/failmalloc/>.
+ * gc.c (rb_memerror): should not raise empty nomem_error.
+
Fri Jul 14 13:08:13 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: add methods for new features of latest Tcl/Tk8.5.
@@ -2462,6 +3809,10 @@ Fri Jul 14 02:30:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/monitor.rb: document patch from Hugh Sasse <hgs at dmu.ac.uk>.
[ruby-core:08205]
+Fri Jul 14 01:09:46 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * parse.y (then): error in warning action.
+
Fri Jul 14 00:10:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_pop): may cause realloc oscillation. a patch
@@ -2473,23 +3824,15 @@ Thu Jul 13 22:23:56 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/composite.rb: improve handling of the classname on the
option database for the widget class which includes TkComposite.
-Thu Jul 13 00:40:57 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ruby.h (FIX2LONG): returns integer of size of VALUE.
- [ruby-dev:29024]
-
- * ruby.h (FIX2ULONG): ditto.
-
-Wed Jul 12 20:05:23 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (f_args): allow post mandatory arguments after optional
- arguments. [ruby-dev:29014]
+Thu Jul 13 20:32:19 2006 Kouhei Sutou <kou@cozmixng.org>
- * parse.y (new_args_gen): allow post_args without rest_args.
+ * lib/rss/parser.rb: updated documents by a patch from
+ Hugh Sasse <hgs at dmu.ac.uk>. [ruby-core:8194]
- * eval.c (formal_assign): ditto.
+Wed Jul 12 13:54:09 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * parse.y (new_args_gen): check post argument duplication.
+ * parse.y (then): we'd like to reserve colon here for the future.
+ warning added.
Tue Jul 11 20:58:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -2504,42 +3847,10 @@ Tue Jul 11 18:00:57 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: security fix.
-Tue Jul 11 17:28:08 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Jul 11 17:33:39 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* string.c (rb_str_dump): need to extend len for \b.
-Tue Jul 11 15:29:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * bignum.c (rb_int2big): use SIGNED_VALUE. [ruby-dev:29019]
-
- * bignum.c (rb_int2inum, rb_uint2inum): use VALUE sized integer.
-
- * bignum.c (rb_big2long, rb_big2ulong): ditto.
-
- * numeric.c (rb_num2long, rb_num2ulong): ditto.
-
- * numeric.c (check_int, check_uint): ditto.
-
- * bignum.c (rb_quad_pack): typo fixed.
-
-Tue Jul 11 13:40:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * bignum.c (bignorm): sizeof(long) may be smaller than
- sizeof(VALUE). [ruby-dev:29013]
-
- * ruby.h (FIXNUM_MAX): fixnum may be bigger than long.
-
- * ruby.h (SIGNED_VALUE): signed integer of size of VALUE.
-
-Mon Jul 10 23:37:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/soap/rpc/proxy.rb (Proxy::Operation::response_doc): remove
- splat star from return statements.
-
- * lib/soap/rpc/proxy.rb (Proxy::Operation::response_obj): retrieve
- the first value from the result array if response has only one
- value.
-
Mon Jul 10 22:00:00 2006 Shigeo Kobayashi <shigek@ruby-lang.org>
* ext/bigdecimal/bigdecimal.c: Allows '_' to appear within
@@ -2583,52 +3894,17 @@ Mon Jul 10 18:46:52 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/demos-jp/widget: ditto.
-Mon Jul 10 17:32:38 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * sample/test.rb: update test suites.
-
- * test/ruby/test_assignment.rb (TestAssignment::test_yield): ditto.
-
- * test/ruby/test_iterator.rb (TestIterator::test_itertest): ditto.
-
-Mon Jul 10 14:43:47 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Jul 10 13:58:40 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * eval.c (rb_call): remove erroneously restored prot_tag->blkid
- initialization. [ruby-dev:28997] [ruby-dev:29000]
-
-Mon Jul 10 13:58:08 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * signal.c (install_nativethread_sighandler): commented out.
-
-Mon Jul 10 09:29:12 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_clear_cache_for_remove): clear entries for included
- module. fixed: [ruby-core:08180]
+ * signal.c (ruby_nativethread_signal, posix_nativethread_signal,
+ sigsend_to_ruby_thread, install_nativethread_sighandler):
+ nativethread-support on signal handler. RE-backport from 1.9.
-Mon Jul 10 02:22:58 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ruby.h (HAVE_NATIVETHREAD_KILL): ditto.
- * eval.c (proc_invoke): should not overwrite block information in
- current frame. [ruby-dev:28957]
+ * eval.c (ruby_native_thread_kill): ditto.
- * eval.c (rb_yield_0): retrieve proper block object from the frame
- record.
-
- * eval.c (proc_alloc): return preserved block object if it's
- available.
-
-Mon Jul 10 01:48:38 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * st.h (st_data_t): use pointer sized integer for st_data_t.
- [ruby-dev:28988]
-
-Sun Jul 9 18:06:47 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (try_constant): fix for value 1 at cross compiling.
-
- * lib/mkmf.rb (create_makefile): prevent substitution of macro
- definition. fixed: http://www.yotabanana.com/lab/20060624.html#p02
-
-Sun Jul 9 07:58:48 2006 Ryan Davis <ryand@zenspider.com>
+Mon Jul 10 10:54:14 2006 Ryan Davis <ryand@zenspider.com>
* lib/rdoc/parsers/parse_f95.rb: massive overhaul from Yasuhiro
Morikawa including new file suffixes, function support, public
@@ -2648,33 +3924,44 @@ Sun Jul 9 07:58:48 2006 Ryan Davis <ryand@zenspider.com>
* lib/pp.rb: minor clarification on exception.
-Sun Jul 9 00:54:11 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Jul 10 09:29:12 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (next_jump): deal with destination of next.
- fixed: [ruby-core:08169]
+ * eval.c (rb_clear_cache_for_undef): clear entries for included
+ module. fixed: [ruby-core:08180]
-Fri Jul 7 17:49:16 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Jul 10 01:48:38 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * string.c (rb_str_ord): extract lower byte. fixed: [ruby-dev:28980]
+ * st.h (st_data_t): use pointer sized integer for st_data_t.
+ [ruby-dev:28988]
- * lib/jcode.rb (String#succ!): fix for 1.9. fixed: [ruby-dev:28979]
+Sun Jul 9 18:06:47 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Fri Jul 7 14:05:03 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * lib/mkmf.rb (try_constant): fix for value 1 at cross compiling.
- * win32/Makefile.sub (config.h): define FUNC_STDCALL/FUNC_CDECL.
- from [ruby-dev:28970].
+ * lib/mkmf.rb (create_makefile): prevent substitution of macro
+ definition. fixed: http://www.yotabanana.com/lab/20060624.html#p02
+
+Sun Jul 9 00:54:34 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (next_jump): deal with destination of next.
+ fixed: [ruby-core:08169]
Fri Jul 7 00:38:49 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* hash.c (rb_hash_default): should not call default procedure if
no key is given. [ruby-list:42541]
-Thu Jul 6 23:30:04 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Jul 7 00:29:10 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * time.c (time_mload): a patch from Daniel Berger
+ <Daniel.Berger at qwest.com>. [ruby-core:08128]
+
+Thu Jul 6 22:21:57 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c (rb_proc_times): use sysconf(_SC_CLK_TCK) value prior to
HZ and CLK_TCK. fixed: [ruby-talk:200293]
-Thu Jul 6 21:50:06 2006 Minero Aoki <aamine@loveruby.net>
+Thu Jul 6 22:17:21 2006 Minero Aoki <aamine@loveruby.net>
* ext/racc/cparse/cparse.c: sync with original code, rev 1.8.
@@ -2684,30 +3971,6 @@ Thu Jul 6 21:50:06 2006 Minero Aoki <aamine@loveruby.net>
* lib/racc/parser.rb: update coding style.
-Wed Jul 5 05:28:45 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (block_param): should allow block argument after splat
- and post splat args.
-
-Wed Jul 5 01:12:19 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * test/ruby/test_lambda.rb (TestLambdaParameters::test_lambda_as_iterator):
- -> style block no longer available. [ruby-dev:28958]
-
-Tue Jul 4 21:48:56 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ruby.c (proc_options): supress warning on DOSISH.
-
-Tue Jul 4 15:12:49 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_call): should not set prot_tag->blkid since it would
- never catch breaks at this level. [ruby-dev:28922]
-
-Tue Jul 4 04:48:36 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * bignum.c: ruby 1.9 HEAD 64 bit warnings clean up from
- <ville.mattila at stonesoft.com>. [ruby-core:08120]
-
Mon Jul 3 19:04:38 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c (ip_make_menu_embeddable): help to make a menu
@@ -2730,15 +3993,6 @@ Mon Jul 3 14:42:06 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
from int, and sys/types.h needs to be included before grp.h.
fixed: [ruby-dev:28938]
-Mon Jul 3 10:44:01 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (popen_exec): close file descriptors other than standard I/Os.
- fixed: [ruby-dev:28924]
-
-Mon Jul 3 05:15:29 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * test/openssl/test_asn1.c: String#[]= doesn't accept Integer.
-
Mon Jul 3 01:14:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_inspect): encode \b (\010) for escape.
@@ -2746,34 +4000,15 @@ Mon Jul 3 01:14:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_dump): ditto.
-Sun Jul 2 19:03:30 2006 Minero Aoki <aamine@loveruby.net>
-
- * ext/racc/cparse/cparse.c: sync with original code, rev 1.7.
-
- * ext/racc/cparse/cparse.c: must require version.h to get
- RUBY_VERSION_CODE.
-
-Sun Jul 2 18:42:27 2006 Minero Aoki <aamine@loveruby.net>
+Sun Jul 2 19:17:56 2006 Minero Aoki <aamine@loveruby.net>
- * ext/racc/cparse/cparse.c: sync with original source code, rev
- 1.6.
+ * ext/racc/cparse/cparse.c: sync with original code (rev 1.7).
- * ext/racc/cparse/cparse.c: do not use rb_iterate to give a block
- to the method, use rb_block_call instead. [ruby-dev:28445]
-
-Sun Jul 2 11:22:03 2006 Tanaka Akira <akr@m17n.org>
-
- * io.c (io_reopen): STDOUT.reopen(filename, "w+") didn't work.
- (rb_io_reopen): STDOUT.reopen(File.open(filename, "w+")) didn't work.
-
-Sat Jul 1 23:55:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (PUSH_FRAME): initialize frame->self. [ruby-dev:28911]
-
-Sat Jul 1 17:00:42 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * test/webrick/utils.rb: use Proc#yield instead of Proc#call.
- [ruby-dev:28914]
+ * ext/racc/cparse/cparse.c: use rb_catch instead of rb_iterate.
+ Giving a block to a Ruby-level method by rb_iterate is obsolete on
+ Ruby 1.9. Note that current cparse.c still includes one
+ rb_iterate call on Ruby 1.8, but it is not a problem (at least
+ just now).
Sat Jul 1 15:15:49 2006 Tanaka Akira <akr@m17n.org>
@@ -2789,34 +4024,6 @@ Fri Jun 30 23:46:23 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* configure.in: -shared patch from Andrew Morrow
<andrew.c.morrow at gmail.com>. [ruby-core:08100]
-Fri Jun 30 19:35:41 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httputils.rb (WEBrick::HTTPUtils._escape): should
- use String#ord to get ascii code from the one-character string.
- [ruby-dev:28901]
-
-Thu Jun 29 23:56:01 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * gc.c (gc_mark_children): a bug in NODE_BLOCK_PASS marking.
- [ruby-dev:28908]
-
-Thu Jun 29 23:04:36 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y: use ARGSPUSH instead of ARGSCAT to prevent too much
- splat expansion.
-
- * eval.c (when_check): need to handle ARGSPUSH as well.
-
- * eval.c (block_orphan): lambda and proc from method are always
- orphan.
-
- * gc.c (gc_mark_children): proper marking for NODE_LAMBDA.
-
-Thu Jun 29 22:47:30 2006 Tanaka Akira <akr@m17n.org>
-
- * eval.c (SETUP_ARGS0): avoid GC problem.
- [ruby-dev:28902]
-
Thu Jun 29 18:58:51 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/bigdecimal/bigdecimal.c (BigDecimal_version): fix patch
@@ -2827,51 +4034,16 @@ Thu Jun 29 18:00:51 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/bigdecimal/bigdecimal.c: add RDoc document. a patch from
mathew <meta at pobox.com>. [ruby-core:07050]
-Wed Jun 28 14:53:09 2006 Eric Hodel <drbrain@segment7.net>
+Wed Jun 28 15:47:14 2006 Eric Hodel <drbrain@segment7.net>
* lib/optparse.rb: RDoc patch from Robin Stocker <robin@nibor.org>
[ruby-core:08087]
-Wed Jun 28 23:23:48 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (rb_cstr_to_dbl): underscores should appear only
- between digits. [ruby-dev:28891]
-
Wed Jun 28 19:04:34 2006 Tanaka Akira <akr@m17n.org>
* test/socket/test_unix.rb: test_seqpacket_pair removed.
[ruby-dev:28846]
-Wed Jun 28 13:51:21 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (when_check): arbitrary values are allowed after splats.
- fixed: [ruby-dev:28879]
-
-Wed Jun 28 09:16:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (primary): remove meaningless else-only case statement
- syntax.
-
-Wed Jun 28 08:08:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_eval): problem to handle else part. [ruby-dev:28873]
-
-Wed Jun 28 01:48:23 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_eval): support splat in when expression list.
- [ruby-dev:28822]
-
- * eval.c (when_check): a new auxiliary function for case match.
-
- * eval.c (when_cond): ditto.
-
-Wed Jun 28 01:05:37 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (rb_cstr_to_dbl): should not skip '_' at the beginning
- of a string. [ruby-dev:28830]
-
- * bignum.c (rb_cstr_to_inum): ditto.
-
Tue Jun 27 23:03:49 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c: RDoc update for =~ method. a patch from Alex Young
@@ -2884,17 +4056,6 @@ Tue Jun 27 22:47:18 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb (tk_tcl2ruby): [bug fix] sometimes fail to convert
a tcl string to a ruby object if the tcl string includes "\n".
-Tue Jun 27 20:05:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * io.c (pipe_open): backout unnecessary fix on 2006-06-26.
- [ruby-dev:28865]
-
- * eval.c (rb_yield_0): exact argument number check now done only
- for lambda Proc.
-
- * eval.c (rb_yield_0): add check for number of arguments, if
- there's one lambda block parameter.
-
Tue Jun 27 16:04:05 2006 WATANABE Hirofumi <eban@ruby-lang.org>
* win32/win32.h: define isascii on MinGW for msvcrt compatibility.
@@ -2907,246 +4068,297 @@ Tue Jun 27 11:36:02 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/etc/etc.c (setup_passwd, setup_group): allow bignum uid, gid and
so on. [ruby-talk:199102]
-Tue Jun 27 10:46:53 2006 Tanaka Akira <akr@m17n.org>
-
- * eval.c (rb_yield_0): avoid core dump. [ruby-dev:28840]
+Mon Jun 26 13:37:27 2006 Eric Hodel <drbrain@segment7.net>
-Mon Jun 26 11:03:00 2006 Eric Hodel <drbrain@segment7.net>
+ * lib/rdoc: Merge from HEAD.
+ Add options to limit the ri search path.
- * lib/rdoc/ri: Add options to limit the ri search path.
+Tue Jun 27 00:54:08 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Tue Jun 27 01:31:59 2006 Tanaka Akira <akr@m17n.org>
-
- * ext/socket/socket.c (bsock_recv_nonblock): new method
- BasicSocket#recv_nonblock.
- (udp_recvfrom_nonblock): renamed from ip_recvfrom_nonblock.
- IPSocket#recvfrom_nonblock is moved to UDPSocket#recvfrom_nonblock.
- (unix_recvfrom_nonblock): removed.
- UNIXSocket#recvfrom_nonblock is removed.
-
-Tue Jun 27 00:52:40 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/ripper/eventids2.c (token_assoc): added tCHAR, which is not
- under 256 now. fixed: [ruby-dev:28832]
-
-Mon Jun 26 23:42:57 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (call_trace_func): no check for argument number of the
- callback. fixed: [ruby-dev:28812]
+ * util.c (powersOf10): constified.
Mon Jun 26 18:37:44 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c (ip_delete): fix SEGV when a slave-ip is
deleted on callback.
-Mon Jun 26 15:40:26 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/socket/socket.c (sock_accept): revert to avoid ambiguity of
- argument evaluation order. [ruby-dev:28861]
-
- * ext/socket/socket.c (sock_accept_nonblock): ditto.
-
Mon Jun 26 10:47:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (pipe_open): avoid closing uninitialized file descriptors.
a patch from <tommy at tmtm.org> [ruby-dev:28600]
+Mon Jun 26 09:56:22 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/win32.[ch] (rb_w32_send, rb_w32_sendto): constified.
+
Sun Jun 25 23:02:12 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* Makefile.in, mkconfig.rb: catch-up for latest autoconf.
-Sun Jun 25 17:44:16 2006 Tanaka Akira <akr@m17n.org>
+Sat Jun 24 06:35:00 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * parse.y (paren_args): wrap $2 by escape_Qundef because it may be
- Qundef. [ruby-dev:28843]
+ * signal.c: revert last change.
-Sun Jun 25 17:18:33 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+ * ruby.h: ditto.
- * ext/win32ole/win32ole.c(ole_invoke): support some kind of
- method of word. [ruby-Bugs#3237]
+ * eval.c: ditto.
- * test/win32ole/test_word.rb: ditto.
+Thu Jun 22 11:52:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Sat Jun 24 23:48:08 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/net/http.rb (Net::HTTPResponse): duplicated error 501;
+ HTTPInternalServerError should be error 500. [ruby-core:08037]
- * parse.y: replace terminal token names with more descriptive
- name, i.e. kEND to keyword_end. [ruby-list:42477]
+Thu Jun 22 05:15:58 2006 Tanaka Akira <akr@m17n.org>
-Sat Jun 24 23:37:41 2006 Tanaka Akira <akr@m17n.org>
+ * ext/socket/socket.c (sock_s_socketpair): try GC only once.
+ [ruby-dev:28778]
- * eval.c (rb_eval): use rb_ary_new2 instead of rb_ary_new4 to avoid
- GC problem.
- (rb_yield_values): use rb_ary_new2 instead of rb_ary_new4.
+Wed Jun 21 21:28:32 2006 Tadayoshi Funaba <tadf@dotrb.org>
- * array.c (rb_ary_new4): don't set len as n if contents is not
- initialized. make it safe with GC.
+ * lib/date.rb (jd_to_commercial): now works fine even if in
+ mathn-ized context.
- [ruby-dev:28826]
+Wed Jun 21 17:32:31 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-Fri Jun 23 23:35:32 2006 Tanaka Akira <akr@m17n.org>
+ * signal.c (ruby_nativethread_signal, posix_nativethread_signal,
+ sigsend_to_ruby_thread, install_nativethread_sighandler):
+ nativethread-support on signal handler (backport from 1.9).
- * ruby.h, lib/drb/drb.rb, lib/drb/invokemethod.rb: remove Values class.
- [ruby-dev:28805]
+ * ruby.h (HAVE_NATIVETHREAD_KILL): ditto.
-Fri Jun 23 17:27:52 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * eval.c (ruby_native_thread_kill): ditto.
- * eval.c (rb_block_pass): removed.
+Wed Jun 21 08:39:54 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * eval.c (rb_thread_start_1): use rb_proc_yield() instead of
- rb_block_pass(). fixed: [ruby-dev:28794]
+ * lib/xmlrpc/create.rb (XMLRPC::Create::conv2value): merge Date
+ and Time processing. [ruby-core:08033]
-Thu Jun 22 11:52:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Jun 21 01:40:25 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/net/http.rb (Net::HTTPResponse): duplicated error 501;
- HTTPInternalServerError should be error 500. [ruby-core:08037]
+ * parse.y (yylex, reswords): modifier token is no longer returned in
+ fname state. [ruby-dev:28775]
-Thu Jun 22 11:47:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Jun 21 01:12:46 2006 Kouhei Sutou <kou@cozmixng.org>
- * variable.c (rb_mod_name): returns nil for anonymous modules.
- [ruby-talk:198440]
+ * lib/rss/rss.rb: RSS::Element.def_corresponded_attr_writer
+ supported date type.
-Thu Jun 22 10:31:39 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Tue Jun 20 22:08:36 2006 Kouhei Sutou <kou@cozmixng.org>
- * string.c (rb_str_aref): "abc"[3] should not return an empty
- string but nil. [ruby-dev:28786]
+ * test/rss/test_parser.rb: split parser tests into ...
+ * test/rss/test_parser_1.0.rb: ... RSS 1.0 parsing tests and ...
+ * test/rss/test_parser_2.0.rb: ... RSS 2.0 parsing tests.
-Thu Jun 22 05:15:58 2006 Tanaka Akira <akr@m17n.org>
+Tue Jun 20 21:19:06 2006 Kouhei Sutou <kou@cozmixng.org>
- * ext/socket/socket.c (sock_s_socketpair): try GC only once.
- [ruby-dev:28778]
+ * lib/rss/rss.rb: provided default RSS::Element#children.
-Wed Jun 21 21:20:31 2006 Tadayoshi Funaba <tadf@dotrb.org>
+ * lib/rss/0.9.rb: used default RSS::Element#children.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/2.0.rb: ditto.
+ * lib/rss/taxonomy.rb: ditto.
- * lib/date.rb (jd_to_commercial): now works fine even if in
- mathn-ized context.
+Tue Jun 20 21:04:33 2006 Kouhei Sutou <kou@cozmixng.org>
-Wed Jun 21 17:29:57 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * lib/rss/rss.rb: provided default RSS::Element#_tags.
- * ext/socket/getaddrinfo.c (freeaddrinfo, get_name): fixed typo.
+ * lib/rss/0.9.rb: used default RSS::Element#_tags.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/2.0.rb: ditto.
+ * lib/rss/image.rb: ditto.
+ * lib/rss/taxonomy.rb: ditto.
- * ext/tk/tcltklib.c (tcl_eval, tcl_global_eval): ditto.
+Tue Jun 20 20:47:07 2006 Kouhei Sutou <kou@cozmixng.org>
- * ext/zlib/zlib.c (rscheck): constified.
+ * lib/rss/rss.rb: hide RSS::Element.install_model.
+ (RSS::Element.install_have_child_element,
+ RSS::Element.install_have_children_element,
+ RSS::Element.install_text_element,
+ RSS::Element.install_date_element): call
+ RSS::Element.install_model internally.
-Wed Jun 21 17:18:55 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rss/0.9.rb: followed new API.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/2.0.rb: ditto.
+ * lib/rss/content.rb: ditto.
+ * lib/rss/dublincore.rb: ditto.
+ * lib/rss/image.rb: ditto.
+ * lib/rss/syndication.rb: ditto.
+ * lib/rss/taxonomy.rb: ditto.
+ * lib/rss/trackback.rb: ditto.
- * lib/pp.rb (PP::PPMethods::seplist): should have preserved
- original reference to the array. [ruby-dev:28747]
+Tue Jun 20 20:18:05 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
-Wed Jun 21 14:35:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/openssl/extconf.rb: add check for OBJ_NAME_do_all_sorted.
- * parse.y (block_param): do not use multiple assignment for a sole
- block parameter. [ruby-dev:28710]
+ * ext/openssl/ossl_cipher.c (ossl_s_ciphers): new method
+ OpenSSL::Cipher.ciphers. it returns all the cipher names.
- * eval.c (rb_yield_0): pass a raw yielded value to a sole block
- parameter if a value is passed by yield.
+ * ext/openssl/lib/openssl/cipher.rb:
+ - add constants AES128, AES192, AES256. [ruby-dev:28610]
+ - reimplement without eval()
- * eval.c (proc_invoke): args may not be an array.
+ * ext/openssl/lib/openssl/digest.rb: reimplement without eval().
- * eval.c (rb_proc_yield): pass original value without wrapping
- it in an array.
+ * test/openssl/test_cipher.rb, test_digest: fix about reimplemented
+ features.
-Wed Jun 21 14:06:47 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * sample/openssl/cipher.rb: rewrite all.
- * parse.y (method_call): remove (fn)(args) style lambda
- invocation, add fn.(args) instead.
+Sat Jun 19 11:21:46 2006 Eric Hodel <drbrain@segment7.net>
-Wed Jun 21 08:39:54 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/test/unit/assertions.rb: Merge RDoc from HEAD.
- * lib/xmlrpc/create.rb (XMLRPC::Create::conv2value): merge Date
- and Time processing. [ruby-core:08033]
+Tue Jun 20 01:06:57 2006 Kouhei Sutou <kou@cozmixng.org>
-Wed Jun 21 03:01:10 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rss/rss.rb:
+ - cleanup validation mechanism. Now, #XXX_validation is
+ needless.
+ - changed internal variable name RSS::Element::MODEL to
+ RSS::Element::MODELS.
+ - RSS::Element.install_model requires uri.
- * eval.c, file.c, etc.: code-cleanup patch from Stefan Huehner
- <stefan at huehner.org>. [ruby-core:08029]
+ * lib/rss/0.9.rb: followed new validation API.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/2.0.rb: ditto.
+ * lib/rss/content.rb: ditto.
+ * lib/rss/dublincore.rb: ditto.
+ * lib/rss/image.rb: ditto.
+ * lib/rss/syndication.rb: ditto.
+ * lib/rss/taxonomy.rb: ditto.
+ * lib/rss/trackback.rb: ditto.
-Wed Jun 21 01:40:25 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Jun 19 23:40:59 2006 NARUSE, Yui <naruse@ruby-lang.org>
- * parse.y (reswords): modifier token is no longer returned in fname
- state. fixed: [ruby-dev:28775]
+ * ext/nkf/lib/kconv.rb: remove default -m0 and fix document.
-Tue Jun 20 23:28:34 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/nkf/nkf-8/{nkf.c, config.h, utf8tbl.c, utf8tbl.h}:
+ imported nkf 2.0.7.
- * ext/extmk.rb (parse_args): provisional catch-up for the recent changes.
+Mon Jun 19 22:31:59 2006 Kouhei Sutou <kou@cozmixng.org>
- * lib/optparse.rb (OptionParser::List#summarize, OptionParser#order!): ditto.
+ * lib/rss/rss.rb:
+ - provided default #to_s as RSS::Element#to_s.
+ - removed RSS::Element#other_element.
+ - RSS::Element#tag requires attributes as Hash instead of Array.
-Tue Jun 20 11:07:55 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rss/0.9.rb: removed #to_s to use RSS::Element#to_s.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/image.rb: ditto.
+ * lib/rss/taxonomy.rb: ditto.
+ * lib/rss/trackback.rb: ditto.
- * eval.c (proc_invoke): intercept break and return from lambda
- Proc objects. [ruby-dev:28742]
+ * lib/rss/2.0.rb: removed #other_element.
- * eval.c (proc_invoke): remove unnecessary YIELD_PROC_CALL flag.
+Mon Jun 19 22:09:16 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * eval.c (YIELD_EXACT_ARGS): renamed from YIELD_LAMBDA_CALL, which
- is no longer related to the behavior turned on by this flag.
+ * ext/win32ole/win32ole.c(ole_invoke): support some kind of
+ method of word. [ruby-Bugs#3237]
- * eval.c (return_jump): no need to care about PROT_YIELD.
+ * ext/win32ole/tests/test_word.rb: ditto.
- * eval.c (break_jump): no jump to toplevel PROT_THREAD tag.
+ * ext/win32ole/tests/testall.rb: ditto.
- * eval.c (rb_yield_0): fix confusion between lambda (which is a
- property of a proc) and pcall (which depends on whether it's
- called via yield or call).
+Mon Jun 19 00:02:17 2006 Kouhei Sutou <kou@cozmixng.org>
- * eval.c (rb_thread_yield): no need to specify YIELD_LAMBDA_CALL.
+ * lib/rss/rss.rb: automatically detected attributes.
- * eval.c (rb_block_pass): update blkid in prot_tag.
+ * lib/rss/0.9.rb: removed #_attrs.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/2.0.rb: ditto.
+ * lib/rss/image.rb: ditto.
+ * lib/rss/taxonomy.rb: ditto.
+ * lib/rss/trackback.rb: ditto.
-Mon Jun 19 23:40:59 2006 NARUSE, Yui <naruse@ruby-lang.org>
+ * lib/rss/parser.rb: followed new internal API.
- * ext/nkf/lib/kconv.rb: remove default -m0 and fix document.
+Mon Jun 19 00:00:17 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/nkf/nkf-8/{nkf.c, config.h, utf8tbl.c, utf8tbl.h}:
- imported nkf 2.0.7.
+ * ext/tk/lib/multi-tk.rb: fix bug: initialize improper tables.
-Mon Jun 19 17:02:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Jun 18 22:36:13 2006 Kouhei Sutou <kou@cozmixng.org>
- * sample/test.rb (proc_return3): return within non lambda block
- should terminate surrounding method. [ruby-dev:28741]
+ * lib/rss/rss.rb: RSS::Element#initialize accepts initial
+ attributes.
+ * lib/rss/0.9.rb: ditto.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/2.0.rb: ditto.
+ * lib/rss/dublincore.rb: ditto.
+ * lib/rss/image.rb: ditto.
+ * lib/rss/taxonomy.rb: ditto.
+ * lib/rss/trackback.rb: ditto.
-Mon Jun 19 13:22:48 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rss/utils.rb: added Utils.element_initialize_arguments? to
+ detect backward compatibility initial arguments.
- * ext/socket/socket.c (unix_sysaccept): typo fixed.
+ * lib/rss/parser.rb: user initial attributes to initialize
+ RSS::Element.
- * ext/socket/socket.c (sock_connect): remove an unused local
- variable tmpaddr.
+Sun Jun 18 18:24:42 2006 Kouhei Sutou <kou@cozmixng.org>
-Mon Jun 19 02:10:32 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rss/converter.rb: use NKF for Uconv fallback.
- * ext/socket/socket.c (tcp_accept_nonblock): forgot to remove
- abandoned hacks. [ruby-dev:28740]
+Sun Jun 18 18:22:04 2006 Kouhei Sutou <kou@cozmixng.org>
-Mon Jun 19 00:00:17 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+ * test/rss/test_image.rb: shared name space configuration.
- * ext/tk/lib/multi-tk.rb: fix bug: initialize improper tables.
+Sun Jun 18 18:13:25 2006 Kouhei Sutou <kou@cozmixng.org>
-Sun Jun 18 20:28:43 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+ * lib/rss/rss.rb: improved ignore_unknown_element
+ handling. RSS::NotExpectedTagError provides tag URI.
+ * lib/rss/parser.rb: ditto.
+ * lib/rss/0.9.rb: ditto.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/content.rb: ditto.
+ * lib/rss/dublincore.rb: ditto.
+ * lib/rss/image.rb: ditto.
+ * lib/rss/syndication.rb: ditto.
+ * lib/rss/taxonomy.rb: ditto.
+ * lib/rss/trackback.rb: ditto.
- * ext/win32ole/win32ole.c (fole_methods): The return value
- of WIN32OLE#ole_methods should include PROPERTYPUTREF methods.
+ * test/rss/rss-assertions.rb: checked URI of not expected tag too.
+ * test/rss/test_parser.rb: ditto.
- * ext/win32ole/win32ole.c (fole_put_methods): The return value
- of WIN32OLE#ole_put_methods should include PROPERTYPUTREF methods.
+Sun Jun 18 18:08:36 2006 Kouhei Sutou <kou@cozmixng.org>
- * test/win32ole/test_ole_methods.rb: ditto.
+ * lib/rss/rss.rb: changed empty namespace URI representation to ""
+ from nil.
+ * lib/rss/parser.rb: ditto.
+ * lib/rss/0.9.rb: ditto.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/2.0.rb: ditto.
- * ext/win32ole/win32ole.c (ole_propertyput): support
- PROPERTYPUTREF. [ruby-talk:183042]
+Sun Jun 18 18:03:50 2006 Kouhei Sutou <kou@cozmixng.org>
+
+ * lib/rss/parser.rb: removed a guard for requiring open-uri.
+
+Sun Jun 18 18:01:26 2006 Kouhei Sutou <kou@cozmixng.org>
+
+ * lib/rss/rss.rb: fixed typo: except -> expect
+ * lib/rss/parser.rb: ditto.
+ * test/rss/rss-assertions.rb: ditto.
+ * test/rss/test_parser.rb: ditto.
- * test/win32ole/test_propertyputref.rb : ditto.
+Sun Jun 18 17:52:39 2006 Kouhei Sutou <kou@cozmixng.org>
-Sat Jun 17 23:42:26 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rss/rss.rb: RSS::Element#calc_indent became to be deprecated.
+ * lib/rss/0.9.rb: ditto.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/image.rb: ditto.
+ * lib/rss/taxonomy.rb: ditto.
+ * lib/rss/trackback.rb: ditto.
- * eval.c (Init_eval): add aliases invoke_method and
- invoke_functional_method corresponding send and funcall
- respectively. [ruby-talk:197512]
+ * test/rss/test_1.0.rb: removed RSS::Element.indent_size tests.
+ * test/rss/test_2.0.rb: ditto.
- * parse.y (parser_yylex): returns the most typical keyword token
- on EXPR_FNAME. [ruby-core:7995]
+Sun Jun 18 00:49:11 2006 Tanaka Akira <akr@m17n.org>
- * ext/socket/socket.c: protoize.
+ * ext/socket/socket.c (bsock_recv_nonblock): new method
+ BasicSocket#recv_nonblock.
+ (udp_recvfrom_nonblock): renamed from ip_recvfrom_nonblock.
+ IPSocket#recvfrom_nonblock is moved to UDPSocket#recvfrom_nonblock.
+ (unix_recvfrom_nonblock): removed.
+ UNIXSocket#recvfrom_nonblock is removed.
Sat Jun 17 22:17:17 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -3155,147 +4367,227 @@ Sat Jun 17 22:17:17 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
Sat Jun 17 14:53:32 2006 Tanaka Akira <akr@m17n.org>
- * lib/pathname.rb (Kernel#Pathname): new method.
+ * lib/pathname.rb: backport from 1.9.
+ (Kernel#Pathname): new method.
-Sat Jun 17 02:01:00 2006 Tanaka Akira <akr@m17n.org>
+Sat Jun 17 10:30:41 2006 Kouhei Sutou <kou@cozmixng.org>
- * lib/pp.rb (Kernel#pretty_inspect): defined for pretty printed
- string.
+ * lib/rss/rss.rb (Hash#merge, Enumerable#sort_by): removed.
-Fri Jun 16 01:41:00 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/rss/rss.rb (RSS::RootElementMixin#to_xml): added.
+ [ruby-talk:197284]
- * eval.c (rb_proc_arity): get rid of segfault for mere splat.
+ We can convert RSS version easily like the following:
+ rss10 = RSS::Parser.parse(File.read("1.0.rdf"))
+ File.open("2.0.rss", "w") {|f| f.print(rss10.to_xml("2.0"))}
- * gc.c (gc_mark_children): NODE_BLOCK_PASS needs u3 to be marked.
+ * test/rss/test_1.0.rb: added #to_xml test.
+ * test/rss/test_2.0.rb: ditto.
-Thu Jun 15 22:06:56 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * test/rss/rss-testcase.rb: added some helper methods that
+ generates sample RSS 2.0.
- * parse.y (then): remove ':' from 'then' and 'do' rules.
+ * sample/rss/convert.rb: added a sample script to convert RSS format.
-Wed Jun 14 18:00:20 2006 Eric Hodel <drbrain@segment7.net>
+Sat Jun 17 10:23:22 2006 Kouhei Sutou <kou@cozmixng.org>
- * enum.c (enum_any): Documentation typo.
+ * lib/rss/rss.rb (Kernel#funcall): removed.
+ * lib/rss/parser.rb (Kernel.URI): removed.
-Wed Jun 14 15:01:09 2006 Eric Hodel <drbrain@segment7.net>
+ * lib/rss/maker/: supported
+ xxx.new_yyy do |yyy|
+ yyy.zzz = zzz
+ ...
+ end
+ style and this style became the style of the recommendation.
- * lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser#warn): Don't print
- warnings when -q is set.
+ Old style
+ yyy = xxx.new_yyy
+ yyy.zzz = zzz
+ ...
+ is supported too but this style isn't recommended.
+ [ruby-talk:197284]
-Wed Jun 14 16:11:37 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * test/rss/test_*maker*.rb: used new recommended style.
- * eval.c (rb_f_method_name, rb_f_callee_name): document typo.
+Sat Jun 17 09:03:47 2006 Kouhei Sutou <kou@cozmixng.org>
-Wed Jun 14 15:19:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rss, test/rss: backported from trunk. (2005-11-16 - now)
- * hash.c (env_aset): raise TypeError on nil with more descriptive
- message. [ruby-core:07990]
+ * lib/rss/rss.rb (RSS::VERSION): 0.1.5 -> 0.1.6.
+ * test/rss/test_version.rb (RSS::TestVersion#test_version): ditto.
-Tue Jun 13 17:22:19 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rss/trackback.rb: added TrackBack prefix.
+ * lib/rss/maker/trackback.rb: ditto.
- * ext/socket/socket.c (Init_socket): remove obsolete constants:
- IPsocket, TCPsocket, SOCKSsocket, TCPserver, UDPsocket,
- UNIXsocket, UNIXserver.
+ * lib/rss/rss.rb : removed needless argument 'prefix'.
+ * lib/rss/parser.rb: ditto.
-Tue Jun 13 09:07:27 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rss/1.0.rb: added rdf:Bag.
- * eval.c (formal_assign): post splat arguments should have had
- higher priority than optional arguments, since they are
- mandatory. [ruby-dev:28715]
+ * lib/rss/taxonomy.rb: implemented taxonomy module.
+ * test/rss/test_taxonomy.rb: added tests for taxonomy support.
- * eval.c (VIS_MASK): broken. should be 15. [ruby-dev:28715]
+ * lib/rss/1.0.rb: added convenience method 'resources'.
+ * lib/rss/taxonomy.rb: ditto.
+ * test/rss/rss-assertions.rb: added test for 'resources'.
+ * test/rss/test_taxonomy.rb: ditto.
- * io.c (argf_getc): should return one-character string.
- [ruby-dev:28715]
+ * lib/rss/rss.rb: fixed a indentation bug.
+ * lib/rss/taxonomy.rb: fixed <taxo:topic> #to_s bug.
+ * test/rss/test_taxonomy.rb: added a #to_s test.
- * io.c (rb_io_readchar): ditto.
+ * lib/rss/maker/taxonomy.rb: implemented taxonomy module for RSS
+ Maker.
+ * lib/rss/taxonomy.rb: supported RSS Maker.
+ * lib/rss/maker.rb: added taxonomy module support.
-Sun Jun 11 23:20:07 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/rss/rss.rb: adjusted to other element API.
+ * lib/rss/1.0.rb: adjusted to other element API but backward
+ compatibility is reserved.
+ * lib/rss/0.9.rb: ditto.
- * object.c (sym_call): disallow to call private methods.
+ * test/rss/test_maker_taxo.rb: added test case for taxonomy module
+ for RSS Maker.
+ * test/rss/test_setup_maker_1.0.rb: added tests for taxo:topic.
- * lib/optparse.rb (OptionParser::Arguable#getopts): pass self to the
- parser.
+ * test/rss/test_setup_maker_1.0.rb: added backward compatibility
+ test.
+ * test/rss/test_setup_maker_0.9.rb: ditto.
+ * test/rss/test_setup_maker_2.0.rb: ditto.
-Sun Jun 11 09:56:41 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * test/rss/rss-testcase.rb: added convenience method for setting
+ up taxo:topic.
+ * test/rss/rss-assertions.rb: added assertion for taxo:topic.
- * win32/win32.h (write): not need to define on bcc.
+ * sample/rss/blend.rb: followed new API.
-Sun Jun 11 08:30:33 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/rss/taxonomy.rb: changed class or module prefix to
+ Taxonomy from Taxo.
+ * lib/rss/maker/taxonomy.rb: ditto.
- * lib/optparse.rb (OptionParser#getopts): new methods.
+ * test/rss/test_taxonomy.rb: use #reject directory.
-Sun Jun 11 07:27:11 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * lib/rss/: use #__send__ instead of #send.
+ * test/rss/: ditto.
- * lib/rdoc/ri/ri_writer.rb: use String#ord.
+ * lib/rss/parser.rb: added entity handling type predicate.
+ * lib/rss/rexmlparser.rb: ditto.
+ * lib/rss/xmlparser.rb: ditto.
+ * lib/rss/xmlscanner.rb: ditto.
-Sun Jun 11 04:38:20 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/rss/xmlscanner.rb: more robust entity handling.
- * object.c (sym_to_proc): imported Symbol#to_proc from ActiveSupport.
+ * test/rss/test_parser.rb: added an entity handling test.
-Sat Jun 10 18:02:40 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * test/rss/test_2.0.rb: added RSS 2.0 tests.
+ * test/rss/rss-assertions.rb: extended XML stylesheet assertion.
+ * lib/rss/0.9.rb: added initialize method.
+ * test/rss/test_1.0.rb: cleanup.
- * ext/bigdecimal/lib/bigdecimal/newton.rb (Newton::nlsolve): typo
- fixed: raize -> raise. [ruby-talk:196608]
+ * lib/rss/image.rb: added Image prefix.
+ * lib/rss/maker/image.rb: ditto.
-Sat Jun 10 17:49:53 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rss/rss.rb: improved type conversion.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/0.9.rb: ditto.
+ * lib/rss/2.0.rb: ditto.
+ * lib/rss/image.rb: ditto.
+ * lib/rss/syndication.rb: ditto.
- * string.c (rb_str_ord): new method.
+ * test/rss/test_2.0.rb: added type conversion tests.
+ * test/rss/test_accessor.rb: ditto.
+ * test/rss/test_to_s.rb: ditto.
+ * test/rss/test_syndication.rb: ditto.
+ * test/rss/test_setup_maker_2.0.rb: ditto.
+ * test/rss/test_setup_maker_1.0.rb: ditto.
+ * test/rss/test_setup_maker_0.9.rb: ditto.
+ * test/rss/test_maker_sy.rb: ditto.
+ * test/rss/test_maker_image.rb: ditto.
+ * test/rss/test_maker_2.0.rb: ditto.
+ * test/rss/test_maker_0.9.rb: ditto.
+ * test/rss/test_image.rb: ditto.
- * parse.y (rbracket): allow optional newline before closing
- brackets.
+ * test/rss/test_maker_1.0.rb: use assert instead of assert_equal.
-Sat Jun 10 15:12:29 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * test/rss/rss-assertions.rb: improved type conversion assertions.
- * eval.c (rb_f_method_name, rb_f_callee_name): new functions.
- new global method `__method__' and `__callee__'.
+ * lib/rss/rss.rb: added backward compatibility codes.
+ * lib/rss/parser.rb: ditto.
+ * test/rss/test_parser.rb: ditto.
+ * test/rss/test_2.0.rb: ditto.
-Sat Jun 10 10:13:13 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Sat Jun 17 02:01:00 2006 Tanaka Akira <akr@m17n.org>
- * lib/getoptlong.rb (GetoptLong#set_options): receive arguments
- as Array.
+ * lib/pp.rb (Kernel#pretty_inspect): defined for pretty printed
+ string.
- * lib/irb/slex.rb: use Proc#yield.
+Sat Jun 17 00:23:58 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/rdoc/markup/simple_markup/inline.rb: follow the new behavior
- of String#[].
+ * parse.y (reswords): kDO_BLOCK was missing. fixed: [ruby-core:7995]
- * lib/rdoc/ri/ri_writer.rb: ditto.
+Sat Jun 17 00:02:15 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-Sat Jun 10 08:17:23 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/win32ole/win32ole.c (ole_propertyput): support
+ PROPERTYPUTREF. [ruby-talk:183042]
- * math.c (log2): may be a macro.
+ * ext/win32ole/tests/test_propertyputref.rb: ditto.
- * parse.y (args, block_param, f_args): pass f_post_arg to #params.
+Thu Jun 15 23:02:47 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * util.c (powersOf10): constified.
+ * ext/win32ole/win32ole.c (fole_methods): The return value
+ of WIN32OLE#ole_methods should include PROPERTYPUTREF methods.
- * ext/readline/readline.c: include extconf.h first.
+ * ext/win32ole/win32ole.c (fole_put_methods): The return value
+ of WIN32OLE#ole_put_methods should include PROPERTYPUTREF methods.
- * ext/ripper/eventids2.c: removed tLAMBDA_ARG.
+ * ext/win32ole/tests/test_ole_methods.rb: ditto.
- * ext/tk/tcltklib.c (lib_fromUTF8_core): removed conflict.
+ * ext/win32ole/tests/testall.rb : ditto.
- * ext/tk/tkutil/tkutil.c (cbsubst_get_subst_arg): rb_id2name() is
- defined as const now.
+Wed Jun 14 18:23:28 2006 Eric Hodel <drbrain@segment7.net>
- * ext/win32ole/win32ole.c (fole_missing): ditto.
+ * enum.c (enum_any): Documentation typo.
+
+Wed Jun 14 15:01:09 2006 Eric Hodel <drbrain@segment7.net>
+
+ * lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser#warn): Don't print
+ warnings when -q is set.
+
+Wed Jun 14 23:03:53 2006 Tanaka Akira <akr@m17n.org>
+
+ * configure.in: check sizeof(rlim_t).
+ check setrlimit.
+
+ * process.c (proc_getrlimit): new method Process.getrlimit.
+ (proc_setrlimit): new method Process.setrlimit.
+
+ * ruby.h (NUM2ULL): new macro.
+
+Mon Jun 12 22:25:09 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * sprintf.c (rb_f_sprintf): adjust precision length to prevent
+ splitting multi-byte characters. [ruby-list:42389]
+
+Sun Jun 11 23:20:07 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/optparse.rb (OptionParser::Arguable#getopts): pass self to the
+ parser.
- * lib/mkmf.rb (create_makefile): force to create extconf header.
+Sun Jun 11 10:00:57 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * lib/optparse.rb (order!): use Proc#yield.
+ * win32/win32.h (write): not need to define on bcc.
-Sat Jun 10 06:53:22 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Sun Jun 11 08:30:33 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (CALLARGS): remove last semicolon. C90 compiler doesn't
- allow any lines (even if they're empty) within variable
- declarations.
+ * lib/optparse.rb (OptionParser#getopts): new methods.
-Fri Jun 9 09:56:32 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sat Jun 10 18:02:40 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * sprintf.c (rb_str_format): allow %c to print one character
- string (e.g. ?x).
+ * ext/bigdecimal/lib/bigdecimal/newton.rb (Newton::nlsolve): typo
+ fixed: raize -> raise. [ruby-talk:196608]
-Thu Jun 8 14:00:02 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Jun 8 14:19:17 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.[ch] (rb_w32_read, rb_w32_write): new functions.
use recv() and send() when fd is socket. fixed: [ruby-dev:28694]
@@ -3305,25 +4597,43 @@ Wed Jun 7 16:22:51 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
-Wed Jun 7 16:16:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Jun 7 14:53:04 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * parse.y (do_block): remove -> style block.
+ * win32/win32.c (errmap): add some winsock errors.
- * parse.y (parser_yylex): remove tLAMBDA_ARG.
+Wed Jun 7 11:34:38 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-Wed Jun 7 14:51:22 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+ * configure.in: add new configure option `--with-winsock2' for mingw.
- * win32/win32.c (errmap): add some winsock errors.
+ * win32/Makefile.sub (config.h): define USE_WINSOCK2 in config.h
+ instead of in CPPFLAGS.
+
+ * ext/socket/extconf.rb: determine whether to use winsock2 or not
+ by using with_config.
+
+Wed Jun 7 10:45:10 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/{configure.bat, setup.mak, Makefile.sub, win32.h}: add
+ new configure option `--with-winsock2'.
+
+ * win32/win32.c (StartSockets): ditto.
+
+ * ext/socket/extconf.rb: ditto.
+
+ * win32/win32.c (open_ifs_socket): new function.
+
+ * win32/win32.c (StartSockets, rb_w32_socket): use open_ifs_socket()
+ instead of socket().
+ ifs socket support is backported from trunk.
Wed Jun 7 09:14:44 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
-Tue Jun 6 23:25:49 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (proc_invoke): return behavior should depend whether it
- is surrounded by a lambda or a mere block.
+ * eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
+ event_hooks. no guarantee for arbitrary hook deletion.
+ [ruby-dev:28632]
Mon Jun 5 18:12:12 2006 Tanaka Akira <akr@m17n.org>
@@ -3337,21 +4647,12 @@ Sun Jun 4 20:40:19 2006 Tanaka Akira <akr@m17n.org>
* ext/socket/socket.c: fix sockaddr_un handling.
[ruby-dev:28677]
-Sat Jun 3 23:53:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (formal_assign): handles post splat arguments.
+Fri Jun 2 22:08:17 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * eval.c (rb_call0): ditto.
+ * lib/forwardable.rb: RDoc typo fix from Jan Svitok
+ <jan.svitok at gmail.com>. [ruby-core:07943]
-Sat Jun 3 13:10:41 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * st.c (strhash): use FNV-1a hash.
-
-Fri Jun 2 20:01:24 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (parser_yylex): removed experimental ';;' terminator.
-
-Fri Jun 2 19:00:40 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Fri Jun 2 19:02:09 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/extconf.rb: use create_header.
@@ -3380,83 +4681,23 @@ Thu Jun 1 19:12:37 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (rb_w32_cmdvector): backslashes inside single-quotes
no longer has special meanings. fixed: [ruby-list:42311]
-Thu Jun 1 17:55:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_node_arity): should be aware of post splat arguments.
-
- * eval.c (rb_proc_arity): ditto.
-
-Thu Jun 1 16:17:26 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Jun 1 16:14:41 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_getcwd): runtime's getcwd() will not success
if the length of the cwd is longer than MAX_PATH.
fixed [ruby-list:42335]
-Thu Jun 1 16:07:48 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (f_args): syntax rule enhanced to support arguments
- after the splat.
-
- * parse.y (mlhs_basic): ditto for multiple assignments
-
- * parse.y (block_param): ditto for block parameters.
-
- * parse.y (f_post_arg): mandatory formal arguments after the splat
- argument.
-
- * parse.y (new_args_gen): generate nodes for mandatory formal
- arguments after the splat argument.
-
- * eval.c (rb_eval): dispatch mandatory formal arguments after the
- splat argument.
-
-Thu Jun 1 11:33:32 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Jun 1 11:29:14 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_getcwd): set errno if not set.
fixed [ruby-list:42346]
-Thu Jun 1 00:45:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (args): allow more than one splat in the argument list.
-
-Wed May 31 18:38:11 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (method_call): allow aref [] to accept all kind of
- method argument, including assocs, splat, and block argument.
-
- * eval.c (SETUP_ARGS0): prepare block argument as well.
-
-Tue May 30 18:13:53 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
-
-Mon May 29 22:40:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (error_line): print receivers true/false/nil specially.
-
- * eval.c (rb_proc_yield): handles parameters in yield semantics.
-
- * eval.c (nil_yield): gives LocalJumpError to denote no block
- error.
-
- * io.c (rb_io_getc): now takes one-character string.
-
-Sat May 27 22:46:38 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (proc_invoke): save and restore block in the current frame.
- fixed: [ruby-core:07833], [ruby-talk:191639]
-
-Sat May 27 11:29:46 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat May 27 11:29:46 2006 nobuyoshi nakada <nobu@ruby-lang.org>
* ext/extmk.rb (extmake): remove extinit files if no statically linked
extensions.
-Fri May 26 19:56:46 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
- hashing algorithm.
-
-Fri May 26 09:05:11 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri May 26 09:05:11 2006 nobuyoshi nakada <nobu@ruby-lang.org>
* ruby.h, lib/mkmf.rb (create_header): clear command line options for
macros moved to extconf.h.
@@ -3471,7 +4712,7 @@ Fri May 26 09:05:11 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (configuration): add $defs unless extconf.h was created.
-Thu May 25 01:52:07 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu May 25 01:52:07 2006 nobuyoshi nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (pkg_config): particular config commands support.
@@ -3485,27 +4726,23 @@ Thu May 25 01:52:07 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/setup.mak: suffix OS name by runtime version.
-Wed May 24 23:52:11 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed May 24 23:52:11 2006 nobuyoshi nakada <nobu@ruby-lang.org>
* configure.in (ac_install_sh): ignore dummy install-sh.
[ruby-talk:193876]
-Wed May 24 17:55:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * string.c (rb_str_aref): str[0] now returns 1 character string,
- instead of a fixnum. [Ruby2]
-
- * parse.y (parser_yylex): ?c now returns 1 character string,
- instead of a fixnum. [Ruby2]
-
- * string.c (rb_str_aset): no longer support fixnum insertion.
-
-Wed May 24 03:10:44 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Wed May 24 03:10:48 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/lib/openssl/ssl.rb
(OpenSSL::SSL::SocketForwarder#setsockopt,getsockopt): typo fixed.
-Mon May 22 16:32:03 2006 Tanaka Akira <akr@m17n.org>
+Mon May 22 17:54:12 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * ext/socket/socket.c (sock_recvfrom_nonblock): use rb_read_pending
+ instead of rb_io_read_pending.
+ [ruby-dev:28663]
+
+Mon May 22 17:30:04 2006 Tanaka Akira <akr@m17n.org>
* rubyio.h (rb_io_set_nonblock): declared.
@@ -3514,8 +4751,7 @@ Mon May 22 16:32:03 2006 Tanaka Akira <akr@m17n.org>
(io_read_nonblock): new method: IO#read_nonblock.
(io_write_nonblock): new method: IO#write_nonblock.
- * ext/socket/socket.c (s_accept): retry for EWOULDBLOCK.
- revert [ruby-talk:113807].
+ * ext/socket/socket.c
(sock_connect_nonblock): new method: Socket#connect_nonblock.
(sock_accept_nonblock): new method: Socket#accept_nonblock.
(sock_recvfrom_nonblock): new method: Socket#recvfrom_nonblock.
@@ -3532,33 +4768,6 @@ Mon May 22 13:38:57 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
-Sun May 21 09:50:31 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * regexec.c: add STK_NULL_CHECK_END to IS_TO_VOID_TARGET().
- [ruby-list:42234]
-
-Thu May 18 22:37:20 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/config.rb (WEBrick::Config::HTTP): add new parameters,
- :InputBufferSize and :OutputBufferSize.
-
- * lib/webrick/utils.rb (WEBrick::Utils.timeout): add new timeout
- method. this implementation is expected to be compatible with
- timeout.rb and faster than timeout.rb.
-
- * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#_read_data):
- Timeout.timeout is replaced by WEBrick::Utils.timeout.
-
- * lib/webrick/httprequest.rb: WEBrick::HTTPRequest::BUFSIZE is
- replaced by config[:InputBufferSize].
-
- * lib/webrick/httpresposne.rb: WEBrick::HTTPResponse::BUFSIZE is
- replaced by config[:OutputBufferSize].
-
- * lib/webrick/server.rb: get rid of unnecessary require.
-
- * test/webrick/test_utils.rb: test for WEBrick::Utils.timeout.
-
Thu May 18 17:51:32 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* time.c (time_timeval): should round for usec floating
@@ -3566,21 +4775,24 @@ Thu May 18 17:51:32 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* time.c (time_add): ditto.
-Thu May 18 00:42:12 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu May 18 17:11:45 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/cgi.rb (CGI::out): support utf-8. a patch from Fujioka
+ <fuj at rabbix.jp>. [ruby-dev:28649]
+
+Thu May 18 00:42:12 2006 nobuyoshi nakada <nobu@ruby-lang.org>
* ext/extmk.rb, lib/mkmf.rb: use BUILD_FILE_SEPARATOR in Makefiles.
Wed May 17 17:55:26 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (sys_warning): should not call a vararg function
- rb_sys_warning() indirectly. [ruby-core:07886]
+ rb_sys_warning() indirectly. [ruby-core:07886]
-Tue May 16 17:23:19 2006 <sinara@blade.nagaokaut.ac.jp>
+Wed May 17 08:17:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * numeric.c (flo_divmod): the first element of Float#divmod should
- be an integer. [ruby-dev:28589]
-
- * test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
+ * util.c (ruby_strtod): try to reduce errors using powersOf10
+ table. [ruby-dev:28644]
Tue May 16 15:34:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -3598,10 +4810,6 @@ Tue May 16 09:20:16 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
-Mon May 15 21:37:12 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * re.c (rb_reg_prepare_re): don't use onig_recompile().
-
Mon May 15 17:42:39 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
@@ -3615,85 +4823,40 @@ Sat May 13 16:14:05 2006 Tanaka Akira <akr@m17n.org>
(Struct#pretty_print_cycle): ditto.
[ruby-core:7865]
-Fri May 12 15:54:48 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
- event_hooks. no guarantee for arbitrary hook deletion.
- [ruby-dev:28632]
-
Thu May 11 19:57:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
-Thu May 11 18:30:11 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Fri Aug 11 15:39:25 2006 Eric Hodel <drbrain@segment7.net>
- * ext/openssl/ossl_cipher.c (add_cipher_name_to_ary): should return
- value. [ruby-dev:28627]
+ * lib/yaml/tag.rb: Replace nodoc with stopdoc so Module methods get
+ documented.
Thu May 11 18:10:43 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
-Wed May 10 23:40:21 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * oniguruma.h: Version 4.0.3
-
- * regexec.c: ditto.
-
-Mon May 8 09:10:31 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/extconf.rb: add check for OBJ_NAME_do_all_sorted.
-
- * ext/openssl/ossl_cipher.c (ossl_s_ciphers): new method
- OpenSSL::Cipher.ciphers. it returns all the cipher names.
-
- * ext/openssl/ossl_cipher.c (ossl_cipher_init): refine warning message.
-
- * ext/openssl/lib/openssl/cipher.rb: reimplement without eval() and
- add constants AES128, AES192, AES256. [ruby-dev:28610]
-
- * ext/openssl/lib/openssl/digest.rb: reimplement without eval().
-
- * test/openssl/test_cipher.rb, test_digest: fix about reimplemented
- features.
-
- * sample/openssl/cipher.rb: rewrite all.
-
Sun May 7 03:09:51 2006 Stephan Maka <stephan@spaceboyz.net>
* lib/resolv.rb (Resolv::DNS::Requester::ConnectedUDP#initialize):
Use AF_INET6 for nameservers containing colons.
-Sat May 6 23:40:03 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (proc_invoke): should restore old ruby_frame->block.
- thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
- also fix [ruby-dev:28614] as well.
-
Sat May 6 00:38:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
-Thu May 4 22:13:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * math.c (math_log2): add new method inspired by
- [ruby-talk:191237].
-
- * math.c (math_log): add optional base argument to Math::log().
- [ruby-talk:191308]
-
Thu May 4 02:24:16 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
- uninitialized array element. a patch from Pat Eyler
+ uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
- patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
+ patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
@@ -3705,17 +4868,17 @@ Wed May 3 02:12:07 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
-Mon May 1 17:58:16 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+Mon May 1 12:23:19 2006 <sinara@blade.nagaokaut.ac.jp>
- * ext/win32ole/win32ole.c (add_event_call_back): should not
- delete event handler when the event name is not entried.
+ * numeric.c (num_div): use floor rather than rb_Integer().
+ [ruby-dev:28589]
-Mon May 1 08:32:10 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+ * numeric.c (flo_divmod): the first element of Float#divmod should
+ be an integer. [ruby-dev:28589]
- * ext/win32ole/win32ole.c (ole_param_ole_type): should return
- "unknown type" string when ITypeInfo::GetFuncDesc failed.
+ * test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
-Sat Apr 29 22:43:37 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Sat Apr 29 22:42:08 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_asn1.c (ossl_asn1_decode0): should initialize
flag. [ruby-core:07785]
@@ -3725,6 +4888,8 @@ Fri Apr 28 10:53:16 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
+ * util.c (ruby_strtod): fixed wrong conversion.
+
Thu Apr 27 01:38:10 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_fill): internalize local variable "beg" to
@@ -3733,12 +4898,7 @@ Thu Apr 27 01:38:10 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
Wed Apr 26 16:59:24 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
- <tommy at tmtm.org>. [ruby-dev:28601]
-
-Wed Apr 26 16:55:19 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * applied code clean-up patch from Stefan Huehner
- <stefan at huehner.org>. [ruby-core:07764]
+ <tommy at tmtm.org>. [ruby-dev:28601]
Tue Apr 25 18:00:05 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -3751,6 +4911,12 @@ Tue Apr 25 07:55:31 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
+Tue Apr 25 00:08:24 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * regex.c (re_compile_pattern): should check if c is not a
+ multibyte character. a patch from KIMURA Koichi
+ <kimura.koichi at canon.co.jp>. [ruby-dev:28598]
+
Fri Apr 21 15:19:13 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c (lib_eventloop_ensure): refer freed pointer
@@ -3761,11 +4927,6 @@ Fri Apr 21 12:14:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
-Thu Apr 20 08:43:54 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/mathn.rb (Integer): need not to remove gcd2. a patch from
- NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
-
Wed Apr 19 13:55:27 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (arg): too much NEW_LIST()
@@ -3777,6 +4938,8 @@ Wed Apr 19 11:57:04 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
+ * parse.y (list_concat): revert last change.
+
* parse.y (arg): use NODE_ARGSCAT for placeholder.
Wed Apr 19 11:13:17 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -3789,6 +4952,11 @@ Wed Apr 19 10:13:27 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
+Wed Apr 19 09:49:36 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * parse.y (list_concat): should not modify nodes other than
+ NODE_ARRAY. [ruby-dev:28583]
+
Tue Apr 18 17:40:37 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: add a binding to a container for a slave IP.
@@ -3799,6 +4967,19 @@ Tue Apr 18 17:40:37 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/stubs.c: fix potential bugs about handling rb_argv0.
+Tue Apr 18 00:11:21 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c: block_unique should be 1, not frame_unique.
+ [ruby-dev:28577]
+
+Fri Aug 11 15:39:25 2006 Eric Hodel <drbrain@segment7.net>
+
+ * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#find_body): Make RDoc
+ ignore C function prototypes. Patch by Tilman Sauerbeck
+ <tilman at code-monkey.de>. [ruby-core:8574]
+ * lib/yaml/tag.rb: Replace nodoc with stopdoc so Module methods get
+ documented.
+
Mon Apr 10 01:03:10 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* prec.c (prec_prec_f): documentation patch from
@@ -3813,30 +4994,10 @@ Sat Apr 8 02:12:38 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* README.EXT: update symbol description. [ruby-talk:188104]
-Sat Apr 8 18:06:28 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c: add WIN32OLE_METHOD#inspect,
- WIN32OLE_PARAM#inspect.
-
- * test/win32ole/test_win32ole_method.rb: ditto.
-
- * add test/win32ole/test_win32ole_param.rb.
-
-Fri Apr 7 22:11:30 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c(foletypelib_initialize): WIN32OLE_TYPELIB.new
- accepts OLE file.
-
- * test/win32ole/test_win32ole_typelib.rb(test_initialize): ditto.
-
Thu Apr 6 23:28:47 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
-Thu Apr 6 16:43:06 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * intern.h (rb_obj_instance_exec, rb_mod_module_exec): add declaration.
-
Thu Apr 6 11:18:37 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/panedwindow.rb: lack of arguments. [ruby-core:7681]
@@ -3860,51 +5021,27 @@ Thu Apr 6 01:04:47 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/variable.rb: remove warning about unseting Tcl
variables.
-Wed Apr 5 00:22:54 2006 Tanaka Akira <akr@m17n.org>
-
- * lib/pathname.rb: use a subclass for instantiation except
- methods take pathname argument. suggested by Evan Phoenix.
- [ruby-core:7618]
-
-Tue Apr 4 22:15:41 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y: remove some obsolete syntax rules (unparenthesized
- method calls in argument list).
-
-Sat Apr 1 15:11:27 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+Wed Mar 29 20:54:44 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * ext/win32ole/win32ole.c :add WIN32OLE_TYPE#inspect,
- WIN32OLE_VARIABLE#inspect
+ * ext/win32ole/win32ole.c (fole_getproperty): WIN32OLE#[] should accept
+ multi arguments.
- * remove ext/win32ole/tests/testOLEVARIABLE.rb, testOLETYPE.rb
- testOLETYPELIB.rb.
+ * ext/win32ole/tests/testWIN32OLE.rb (test_setproperty_bracket): ditto.
- * testall.rb :ditto.
-
- * add test/win32ole
-
-Fri Mar 31 14:24:55 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * enumerator.c (enumerator_with_index): removed suspicious return
- statement.
-
-Wed Mar 29 23:06:48 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c (ole_invoke): change the behavior of
- WIN32OLE#[], WIN32OLE#[]=. These methods invoke DISPID_VALUE.
-
- * ext/win32ole/sample/excel2.rb: ditto.
-
- * ext/win32ole/tests/testWIN32OLE.rb: ditto.
-
-Wed Mar 29 10:11:31 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Mar 29 10:07:44 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/nkf/nkf-utf8/nkf.c (nkf_each_char_to_hex, encode_fallback_subchar,
e2w_conv): support C90 compiler.
-Mon Mar 27 22:45:37 2006 NARUSE, Yui <naruse@ruby-lang.org>
+Wed Mar 29 06:48:40 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/nkf/nkf-utf8/{nkf.c, utf8tbl.c}: imported nkf 2.0.6.
+ * eval.c (backtrace): reports aliased method names in a generated
+ backtrace. a patch from "U.Nakamura" <usa at garbagecollect.jp>.
+ [ruby-dev:28471]
+
+Mon Mar 27 22:19:09 2006 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * ext/nkf/nkf-utf8/{nkf.c, utf8tbl.c, config.h}: imported nkf 2.0.6.
* Add --ic / --oc option and mapping tables.
* Add fallback option.
* Add --no-best-fit-chars option.
@@ -3915,12 +5052,6 @@ Mon Mar 27 22:45:37 2006 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/lib/kconv.rb (Kconv.to*): add -m0.
Note that Kconv.to* still imply -X.
- * ext/nkf/test.rb: Removed. Obsolete by test/nkf.
-
- * ext/.document: enabled documents in nkf and kconv
-
- * ext/nkf/nkf.c, ext/nkf/lib/kconv.rb: Add rdoc.
-
Mon Mar 27 03:17:21 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_call0): insecure calling should be checked for non
@@ -3929,125 +5060,53 @@ Mon Mar 27 03:17:21 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
-Sun Mar 26 22:02:51 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * re.c: refactoring for options.
-
- * parse.y: ditto.
-
-Fri Mar 24 21:11:02 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
+Fri Mar 24 23:14:30 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * re.c (match_aref): RDoc description updated.
-
- * string.c (rb_str_sub): ditto.
-
- * string.c (rb_str_gsub): ditto.
+ * eval.c (yield_under_i): pass self again for instance_eval().
+ [ruby-dev:28466]
Fri Mar 24 17:20:03 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * process.c (rb_f_sleep): remove RDoc description about SIGALRM
- which is not valid on the current implementation. [ruby-dev:28464]
-
-Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * re.c (rb_reg_regsub): prohibit \1, \2 ...\9 in replaced string
- for named regex pattern.
-
-Thu Mar 23 21:06:23 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * oniguruma.h: Version 4.0.2
-
- * regparse.c: ditto.
-
- * regcomp.c ditto.
-
- * regerror.c: ditto.
+ * process.c (rb_f_sleep): remove description about SIGALRM which
+ is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 10:47:03 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (method_missing): should support argument splat in
- super. a bug in combination of super, splat and
- method_missing. [ruby-talk:185438]
-
-Thu Mar 23 00:01:32 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * re.c (rb_reg_regsub): add back reference by name \k<name> in
- replace string.
-
- * re.h : add regexp argument to rb_reg_regsub().
-
- * string.c (rb_str_sub_bang): ditto.
-
- * string.c (str_gsub): ditto.
-
-Tue Mar 21 22:14:01 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * re.c (match_alloc): initialize member regexp.
-
- * re.c (match_aref): add String and Symbol argument. [ruby-dev:28448]
-
- * re.h : add member regexp to RMatch.
-
- * gc.c (gc_mark_children): add gc_mark() to regexp member.
+ super. [ruby-talk:185438]
Mon Mar 20 12:05:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
-Mon Mar 20 11:12:38 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/win32ole/win32ole.c (folevariant_value): could not compile
- with C90 compiler.
-
Mon Mar 20 09:40:23 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
-Sun Mar 19 09:46:30 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
- of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
- String object.
+Fri Mar 17 19:08:49 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * ext/win32ole/win32ole.c (folevariant_value): ditto.
+ * ext/openssl/ossl_ssl.c, ext/openssl/ossl_nsspki.c: fix typo.
+ [ruby-core:07571]
- * ext/win32ole/tests/testOLEVARIANT.rb: ditto.
-
-Wed Mar 15 16:51:11 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Mar 15 16:54:21 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/mkmf.rb (create_makefile): support libraries without *.so.
-Wed Mar 15 16:39:29 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Wed Mar 15 16:35:43 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_nsspki.c: should use
"rb_str_new(0, 0)" to make empty string.
-Sun Mar 12 17:02:10 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c(ole_val2olevariantdata): support VT_ARRAY in
- WIN32OLE_VARIANT.new().
-
- * ext/win32ole/tests/testOLEVARIANT.rb: ditto.
-
- * ext/win32ole/tests/testOLEPARAM.rb: test method name should not be
- duplicated.
-
Sat Mar 11 14:24:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rdoc/ri/ri_formatter.rb (RI::TextFormatter::wrap): removed
+ space before argument parenthesis. [ruby-talk:183630]
+
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
-Sun Mar 5 18:40:58 2006 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb: do not repeat command options.
-
-Sun Mar 5 18:35:03 2006 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb (send_request_with_body): #content_type never
- return false, use #main_type instead. [ruby-core:07476]
-
Sat Mar 4 15:26:40 2006 Tanaka Akira <akr@m17n.org>
* gc.c (id2ref): fix symbol test.
@@ -4055,112 +5114,84 @@ Sat Mar 4 15:26:40 2006 Tanaka Akira <akr@m17n.org>
Sat Mar 4 01:08:07 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
- directories. a patch from Eric Hodel <drbrain at segment7.net>.
+ directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
-Fri Mar 3 17:59:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_clear_cache_by_class): clearing wrong cache.
-
-Fri Mar 3 21:22:42 2006 Tanaka Akira <akr@m17n.org>
-
- * lib/fileutils.rb (FileUtils.cp_r): implement :remove_destination
- option.
-
- * ext/extmk.rb: use :remove_destination to install extension libraries
- to avoid SEGV. [ruby-dev:28417]
-
-Fri Mar 3 14:41:04 2006 Minero Aoki <aamine@loveruby.net>
-
- * ext/dl/.cvsignore: ignore callback.h.
+Thu Mar 2 19:44:18 2006 Tanaka Akira <akr@m17n.org>
- * ext/ripper/.cvsignore: ignore eventids2table.c.
-
- * ext/socket/.cvsignore: ignore constants.h.
+ * gc.c: align VALUE with sizeof(RVALUE) globally.
+ (is_pointer_to_heap): check alignment out of loop.
+ (id2ref): avoid collision between symbols and objects.
+ (rb_obj_id): ditto. moved from object.c.
+ [ruby-talk:178364] [ruby-core:7305]
Thu Mar 2 18:58:18 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
-Thu Mar 2 09:12:05 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c (rb_ary_flatten_bang): allow specifying recursion
- level. [ruby-talk:182170]
-
- * array.c (rb_ary_flatten): ditto.
-
-Thu Mar 2 08:02:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
- Weil <weil at mail.berlios.de>.
-
-Wed Mar 1 17:13:37 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_call): use separate cache for fcall/vcall
- invocation.
-
- * eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
- functions.
-
- * eval.c (rb_mod_local): a new method to specify newly added
- visibility "local".
-
- * eval.c (search_method): search for local methods which are
- visible only from the current class.
-
- * class.c (rb_class_local_methods): a method to list local methods.
-
-Thu Mar 2 17:54:45 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Mar 2 17:57:49 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* gc.c: commited magic for reducing RVALUE size on windows. (24->20byte)
[ruby-core:7474]
-Thu Mar 2 14:12:26 2006 Tanaka Akira <akr@m17n.org>
-
- * gc.c: align VALUE with sizeof(RVALUE) globally.
- (is_pointer_to_heap): check alignment out of loop.
- (id2ref): avoid collision between symbols and objects.
- (rb_obj_id): ditto. moved from object.c.
- [ruby-talk:178364] [ruby-core:7305]
-
-Thu Mar 2 12:55:16 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Mar 2 12:59:14 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (filetime_to_unixtime): should set tm_isdst to -1.
stat() didn't treat daylight saving time property on WinNT.
[ruby-talk:182100]
-Wed Mar 1 00:15:51 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Mar 2 08:02:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * gc.c (add_heap): heap_slots may overflow. a patch from Stefan
+ Weil <weil at mail.berlios.de>.
+
+Wed Mar 1 00:24:31 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/rdoc/parsers/parse_rb.rb (read_escape): could not handle /\^/.
merged Mr. Ishizuka's lib/irb/ruby-lex.rb 's patch rev 1.29.
[ruby-talk:181631] [ruby-dev:28404]
-Tue Feb 28 19:32:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Tue Feb 28 09:32:17 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * object.c (Init_Object): add BasicObject class as a top level
- BlankSlate class.
+ * lib/drb/extservm.rb (invoke_service_command): cannot invoke command
+ if command name is quoted on mswin32. [ruby-dev:28400]
Mon Feb 27 00:19:16 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
-Fri Feb 24 20:21:38 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Fri Feb 24 20:07:23 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/drb/drbtest.rb (add_service_command): quote pathnames in the
server's command line for space contained directory names.
Thanks, arton. [ruby-dev:28386]
-Fri Feb 24 12:10:07 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Fri Feb 24 12:11:08 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* instruby.rb: install *.exe.manifest and *.dll.manifest if exist.
It's for VC++8.
-Fri Feb 24 11:17:45 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Fri Feb 24 11:33:52 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * bcc32/Makefile.sub (HAVE_HYPOT): bcc32 has hypot().
+
+Fri Feb 24 11:19:58 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * time.c (time_new_internal): add prototype to tell the compiler
+ arugments types.
* win32/win32.c (NtInitialize): need to set a handler for VC++8.
+Fri Feb 24 08:19:16 2006 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * test.rb: Removed. Obsolete by test/nkf.
+
+ * ext/.document: enabled documents in nkf and kconv
+
+ * ext/nkf/nkf.c ext/nkf/lib/kconv.rb: Add rdoc.
+
Thu Feb 23 22:39:59 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* bcc32/Makefile.sub: use borlndmm.dll if possible. bcc32's RTL internal
@@ -4168,84 +5199,30 @@ Thu Feb 23 22:39:59 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
ex: 10000.times { "" << "." * 529671; GC.start } # crash
[ruby-dev:28230]
-Thu Feb 23 13:23:03 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Feb 23 13:20:28 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* eval.c (SETUP_ARGS0): fixed memory corruption. [ruby-dev:28360]
-Wed Feb 22 21:16:55 2006 Tanaka Akira <akr@m17n.org>
-
- * lib/pathname.rb (Pathname#each_filename): use split_names properly.
-
-Wed Feb 22 16:24:05 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * test/webrick/test_cgi.rb: should support platforms which search
- library path from the interpreter's path.
- And, support test without install incidentally.
-
-Wed Feb 22 14:21:03 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Tue Feb 21 02:18:46 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * bignum.c (bignorm): x may not be a bignum. [ruby-dev:28367]
+ * configure.in (mingw): have link. [ruby-list:41838]
-Wed Feb 22 09:22:40 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (proc_alloc): add proper check for creation of a lambda
- without a block.
+ * win32/Makefile.sub (config.h): ditto.
Tue Feb 21 02:07:39 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (f_arglist): should set command_start = Qtrue for
command body. [ruby-talk:180648]
-Mon Feb 20 22:30:17 2006 Tanaka Akira <akr@m17n.org>
-
- * mkconfig.rb: alias Config to RbConfig for compatibility.
-
-Mon Feb 20 18:21:41 2006 Tanaka Akira <akr@m17n.org>
-
- * io.c (rb_io_reopen): flush before reopening a file.
- reported by Mathieu Bouchard. [ruby-core:7396]
-
-Mon Feb 20 17:29:50 2006 Tanaka Akira <akr@m17n.org>
-
- * mkconfig.rb: generate RbConfig instead of Config.
+Mon Feb 20 17:37:26 2006 Tanaka Akira <akr@m17n.org>
- * instruby.rb, rubytest.rb, runruby.rb, bcc32/Makefile.sub,
- ext/extmk.rb, ext/dl/extconf.rb, ext/iconv/charset_alias.rb,
- lib/mkmf.rb, lib/rdoc/ri/ri_paths.rb,
- lib/webrick/httpservlet/cgihandler.rb,
- test/dbm/test_dbm.rb, test/gdbm/test_gdbm.rb,
- test/ruby/envutil.rb, test/soap/calc/test_calc_cgi.rb,
- test/soap/header/test_authheader_cgi.rb, test/soap/ssl/test_ssl.rb,
- win32/mkexports.rb, win32/resource.rb: Use RbConfig instead of
- Config.
-
-Mon Feb 20 13:46:19 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * lib/find.rb: should raise ENOENT if root entry does not exist,
- without opening it. [ruby-dev:28345]
+ * mkconfig.rb: alias RbConfig for Config.
Mon Feb 20 12:27:53 2006 Kent Sibilev <ksruby@gmail.com>
* lib/rational.rb (Integer::gcd): small typo fix.
[ruby-core:07395]
-Mon Feb 20 10:03:59 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * variable.c (rb_const_get_0): Object should have been the lowest
- in const lookup precedence. [ruby-dev:28343]
-
-Mon Feb 20 09:17:11 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/delegate.rb (Delegator): should not delegate "funcall".
-
-Mon Feb 20 09:13:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/webrick/httpservlet/cgihandler.rb (WEBrick::HTTPServlet::CGIHandler):
- qualify the access for Config constant. [ruby-dev:28338]
-
- * lib/resolv.rb (Resolv::DNS::Resource::IN::A): qualify
- ClassValue. [ruby-dev:28338]
-
Mon Feb 20 01:05:27 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/rational.rb (Integer::gcd): replaced by gcd4 in
@@ -4256,13 +5233,6 @@ Mon Feb 20 00:57:02 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl.h (OSSL_Debug): should not use __func__.
[ruby-dev:28339]
-Mon Feb 20 00:13:49 2006 Tanaka Akira <akr@m17n.org>
-
- * lib/open-uri.rb: add :ssl_verify_mode option.
- suggested by Will Glynn.
-
- * lib/open-uri.rb: add :ssl_ca_cert option.
-
Sun Feb 19 04:46:29 2006 Guy Decoux <ts@moulon.inra.fr>
* eval.c: initial value for block_unique must be 1.
@@ -4278,44 +5248,17 @@ Sat Feb 18 23:58:26 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* sample/rtags.rb: ditto.
-Sat Feb 18 21:16:27 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sat Feb 18 12:18:26 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * eval.c (rb_obj_instance_eval): RDoc description updated. a
- patch from Ozgur Murat Homurlu <ozgurmurath at gmail.com>.
- [ruby-core:07381]
-
-Sat Feb 18 01:01:17 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * variable.c (rb_const_get_0): skip ruby_wrapper in const search
- to give it lower priority (just above Object). need not to
- change rb_const_defined_0() since it's only a precedence matter;
- they are defined anyway.
+ * lib/fileutils.rb (FileUtils::fu_world_writable): make it
+ private. [ruby-core:07383]
Sat Feb 18 00:22:39 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/tracer.rb: merged a minor clarification patch from Daniel
Berger <Daniel.Berger at qwest.com>. [ruby-core:07376]
-Fri Feb 17 17:30:20 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (ev_const_get): simplified using rb_const_get_fallback().
-
- * eval.c (ev_const_defined): adopt to ev_const_get() using
- rb_const_defined_fallback().
-
- * variable.c (rb_const_get_fallback): new function to implement
- constant search.
-
- * variable.c (rb_const_defined_fallback): new function to
- implement constant definition check.
-
- * variable.c (rb_const_get_0): adopt to new behavior. constants
- are looked up in the order of: current class, super classes (but
- Object), lexically external classes/modules, and Object.
-
- * variable.c (rb_const_defined_0): ditto.
-
-Fri Feb 17 11:20:53 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Feb 17 11:18:42 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* util.c (ruby_strtod): Float("1e") should fail. [ruby-core:7330]
@@ -4330,6 +5273,11 @@ Fri Feb 17 09:39:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_thread_wait_for): sleep should always sleep for
specified amount of time. [ruby-talk:180067]
+Thu Feb 16 01:10:48 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (backtrace): frame->orig_func may not be initialized.
+ [ruby-core:07367]
+
Wed Feb 15 16:52:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_eval): NODE_OP_ASGN1 should allow splat in its
@@ -4341,10 +5289,6 @@ Wed Feb 15 16:52:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_eval): honor visibility on OP_ASGN1 and
OP_ASGN2. [ruby-core:07366]
-Wed Feb 15 15:20:23 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (error_line): remove void control path. [ruby-dev:28335]
-
Wed Feb 15 10:09:51 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (yield_under_i): should not pass self as an argument to
@@ -4355,32 +5299,17 @@ Wed Feb 15 09:20:35 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_obj_instance_eval): should be no singleton classes for
true, false, and nil. [ruby-dev:28186]
-Tue Feb 14 20:26:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * enumerator.c (enumerator_each): return self if no block is
- given. [yarv-dev:882]
-
Tue Feb 14 18:48:33 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (DMETHOD_P): accessing wrong frame. [ruby-dev:28181]
* eval.c (proc_invoke): preserve FRAME_DMETH flag.
-Tue Feb 14 15:15:22 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Feb 14 15:13:51 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/zlib/zlib.c: supress warning on test/zlib. [ruby-dev:28323]
-Tue Feb 14 13:47:22 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (rb_w32_utime): drop read-only attribute before
- changing file time.
-
-Tue Feb 14 13:38:01 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/Makefile.sub (config.h): should define HAVE_LONG_LONG with
- VC++8.
-
-Tue Feb 14 11:42:38 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Feb 14 14:01:17 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* time.c (search_time_t): support non 32bit time_t environments.
@@ -4388,40 +5317,35 @@ Tue Feb 14 11:42:38 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/Makefile.sub (config.h): VC++8's time_t is 64bit value.
-Mon Feb 13 18:01:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (copy_node_scope): remove duplicated semicolons at end.
- a patch from KIMURA Koichi <kimura.koichi at canon.co.jp>.
- [ruby-dev:28332]
-
- * eval.c (VIS_MODE): remove unnecessary argument.
- [ruby-dev:28332]
+ * win32/win32.c (rb_w32_utime): drop read-only attribute before
+ changing file time.
-Mon Feb 13 13:49:48 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+ all changes are backported from CVS HEAD.
- * parse.y (parser_parse_string): mention "regexp" in a error
- message. a patch from Mauricio Fernandez <mfp at acm.org>
- [ruby-core:07340]
+Tue Feb 14 11:21:38 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-Mon Feb 13 00:01:32 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
+ * io.c (argf_forward): should not use frame->argv.
+ [ruby-core:07358]
- * oniguruma.h: Version 4.0.1
+Mon Feb 13 18:08:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * regparse.c (onig_free_shared_cclass_table): fix memory leaks.
+ * eval.c (rb_call0): argument update propagation. [ruby-dev:28044]
- * regcomp.c (optimize_node_left): change from IS_POSIXLINE() to IS_MULTILINE().
+ * env.h: remove argv member from struct FRAME.
- * regint.h: rename ANCHOR_ANYCHAR_STAR_PL to ANCHOR_ANYCHAR_STAR_ML.
+Mon Feb 13 13:27:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * regparse.h: ditto.
+ * eval.c (eval): should push class from binding if supplied.
+ [ruby-core:07347]
- * regexec.c: ditto.
+Mon Feb 13 00:04:00 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-Sat Feb 11 21:57:29 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+ * lib/erb.rb (ERB::Compiler): add instance variable @insert_cmd to
+ change <%='s behavior. (backported 1.15 - 1.16)
- * ext/win32ole/win32ole.c: add WIN32OLE.create_guid.
+Sat Feb 11 02:04:11 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/win32ole/tests/testWIN32OLE.rb: ditto.
+ * eval.c (eval): no need to push ruby_class. [ruby-dev:28176]
Sat Feb 11 01:57:44 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -4429,76 +5353,39 @@ Sat Feb 11 01:57:44 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
instance_eval for objects cannot have singleton classes,
e.g. fixnums and symbols). [ruby-dev:28178]
-Fri Feb 10 12:31:05 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_eval): should support NODE_ZSUPER in NODE_ITER.
- [ruby-dev:28326]
-
- * eval.c (ZSUPER_ARGS): support macro.
-
-Wed Feb 8 10:26:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * gc.c (rb_gc_call_finalizer_at_exit): turn on during_gc while
- invoking finalizers.
-
- * gc.c (rb_gc_finalize_deferred): ditto.
-
-Tue Feb 7 23:03:13 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Feb 7 23:03:24 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/zlib/zlib.c: should not access ruby objects in finalizer.
[ruby-dev:28286]
-Tue Feb 7 18:42:00 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * io.c (rb_write_error2): use fwrite(3) if rb_stderr is not
- updated or is already freed. [ruby-dev:28313]
-
Mon Feb 6 16:02:51 2006 WATANABE Hirofumi <eban@ruby-lang.org>
* file.c (rb_thread_flock): ERROR_NOT_LOCKED is not an error on Cygwin.
In such situation, flock() should return 0.
-Mon Feb 6 14:36:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (error_line): include the class name of a surrounding
- method in error position description.
-
-Mon Feb 6 00:14:57 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * enum.c (enum_find_index): a new method Enumerable#find_index.
- [ruby-talk:178495]
-
-Sun Feb 5 23:29:31 2006 Tanaka Akira <akr@m17n.org>
+Mon Feb 6 00:41:08 2006 Tanaka Akira <akr@m17n.org>
- * ruby.h (struct RStruct): embed 3 or less elements structs.
- (RSTRUCT_LEN): defined for accessing struct members.
- (RSTRUCT_PTR): ditto.
+ * ruby.h (RSTRUCT_LEN, RSTRUCT_PTR): defined for source level
+ compatibility with ruby 1.9.
- * struct.c: use RSTRUCT_LEN and RSTRUCT_PTR.
- (struct_alloc): allocate small structs in embedded format.
- (rb_struct_init_copy): ditto.
-
- * gc.c (gc_mark_children): use RSTRUCT_LEN and RSTRUCT_PTR.
- (obj_free): ditto.
-
- * marshal.c (w_object): use RSTRUCT_LEN and RSTRUCT_PTR.
-
-Sun Feb 5 21:01:49 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sun Feb 5 21:05:34 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* numeric.c (fix_to_s): removed workaround for radix 2. Historically,
rb_fix2str could only handle radix 8, 10, 16. (Rev1.37) But for now,
it can handle radix 2..36. [ruby-Bugs#3438] [ruby-core:7300]
-Sun Feb 5 18:49:00 2006 Minero Aoki <aamine@loveruby.net>
+Sun Feb 5 18:55:08 2006 Minero Aoki <aamine@loveruby.net>
- * lib/net/http.rb (add_field, get_fields): keep 1.8.2
- compatibility. This patch is contributed by Rob Pitt.
+ * lib/net/http.rb: imported from trunk, rev 1.129
-Sun Feb 5 16:33:50 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * lib/net/http.rb (add_field, get_fields): keep 1.8.2 backward
+ compatibility.
- * lib/mkmf.rb (create_makefile): Kernel#sub! was removed on HEAD.
+ * lib/net/https.rb: imported from trunk, rev 1.3.
-Sun Feb 5 14:26:54 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * lib/net/https.rb: #use_ssl? definition moved from net/http.rb.
+
+Sun Feb 5 14:22:15 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/pstore.rb: should return default value if name is not found.
[ruby-core:7304]
@@ -4510,59 +5397,33 @@ Sat Feb 4 22:51:43 2006 Tanaka Akira <akr@m17n.org>
* eval.c: apply the FreeBSD getcontext/setcontext workaround
only before FreeBSD 7-CURRENT.
-Sat Feb 4 21:10:06 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Sat Feb 4 21:19:23 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (LK_ERR): ERROR_NOT_LOCKED is not an error.
In such situation, flock() should return 0.
-Sat Feb 4 15:52:56 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sat Feb 4 15:56:37 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* numeric.c (fix_to_s): (2**32).to_s(2) fails with exception where
sizeof(int) == 4 < sizeof(long). [ruby-core:7300]
-Sat Feb 4 15:02:05 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * oniguruma.h: merge Oniguruma 4.0.0 [ruby-dev:28290]
-
-Fri Feb 3 19:25:53 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ruby.h: fixed prototype.
-
- * ext/syck/rubyext.c: defined symbol ID as global variable as others.
-
-Fri Feb 3 17:57:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c: unify ruby_class (for method definition) and ruby_cbase
- (for constant reference).
-
-Fri Feb 3 15:02:10 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Feb 3 15:06:50 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/syck/syck.c (syck_move_tokens): should reset p->cursor or etc
even if skip == 0. This causes buffer overrun.
(ex: YAML.load('--- "..' + '\x82\xA0' * 511 + '"'))
-Fri Feb 3 00:01:31 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Feb 2 23:51:18 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/syck/emitter.c (syck_emitter_write): should not set '\0' on
- emitter's marker. if marker points to the end of buffer, this is
+ emitter's marker. if marker points to the end of buffer, this causes
buffer overrun. (ex: YAML.dump("." * 12288))
-Thu Feb 2 17:13:01 2006 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser#get_tk): added
- support of :'string' style Symbol.
-
Thu Feb 2 16:01:24 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
- * eval.c (rb_call0): use TMP_ALLOC() instead of allocating
- a temporary array object.
-
* eval.c (eval): need not to protect $SAFE value.
[ruby-core:07177]
- * error.c (Init_Exception): change NameError to direct subclass of
- Exception so that default rescue do not handle it silently.
-
Thu Feb 2 14:45:53 2006 Ville Mattila <ville.mattila@stonesoft.com>
* configure.in: The isinf is not regognized by autoconf
@@ -4589,36 +5450,17 @@ Tue Jan 31 11:58:51 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/namespace.rb: TkNamespace#eval was enbugged at the
last commit. Now it will return a proper object.
-Tue Jan 31 08:07:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * numeric.c (int_upto): return an enumerator if no block is
- attached to the method.
-
- * numeric.c (int_downto): ditto.
-
- * numeric.c (int_dotimes): ditto.
-
- * enum.c (enum_first): new method Enumerable#first to take first n
- elements from an enumerable.
-
- * enum.c (enum_group_by): new method Enumerable#group_by that
- groups enumerable values according to their block values.
-
-Tue Jan 31 00:08:22 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Jan 31 00:10:26 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/syck/rubyext.c (syck_resolver_transfer): workaround for SEGV.
ex: ruby -ryaml -e 'YAML.load("!map:B {}")' [ruby-core:7217]
-Sat Jan 28 07:49:30 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sat Jan 28 07:56:57 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/rdoc/usage.rb: support "a:0:33" style caller[-1]. In this case
file name is "a:0". I don't know this really happens though...
[ruby-Bugs:3344]
-Thu Jan 26 15:55:52 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/socket/socket.c: turn on do_not_reverse_lookup by default.
-
Wed Jan 25 22:29:04 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in, dln.c, file.c, intern.h, missing.h (eaccess): use
@@ -4642,7 +5484,13 @@ Sun Jan 22 20:03:35 2006 Tanaka Akira <akr@m17n.org>
FreeBSD/i386 getcontext/setcontext bug.
[ruby-dev:28263]
-Thu Jan 19 22:19:18 2006 Minero Aoki <aamine@loveruby.net>
+Sat Jan 21 00:36:47 2006 Tanaka Akira <akr@m17n.org>
+
+ * eval.c (FUNCTION_CALL_MAY_RETURN_TWICE): use only on SPARC and IA64
+ before gcc 4.0.3.
+ [ruby-dev:28247]
+
+Thu Jan 19 22:21:23 2006 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (mv): should remove file after copying.
[ruby-dev:28223]
@@ -4656,34 +5504,32 @@ Wed Jan 18 23:37:06 2006 Tanaka Akira <akr@m17n.org>
reported by Pav Lucistnik and Marius Strobl.
http://lists.freebsd.org/pipermail/freebsd-sparc64/2006-January/003739.html
-Tue Jan 17 23:59:56 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * object.c (rb_mod_const_get, rb_mod_const_defined): added optional
- flag to search ancestors, which is defaulted to true.
- fixed: [ruby-talk:175899]
-
- * eval.c (rb_mod_method_defined): ditto.
-
-Tue Jan 17 11:31:47 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Jan 17 11:32:46 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/setup.mak (MAKE): workaround for nmake 8.
-Tue Jan 17 11:06:19 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Jan 17 11:10:21 2006 NAKAMURA Usaku <usa@ruby-lang.org>
- * win32/Makefile.sub: invoke .bat via shell. workaround for nmake 8.
+ * win32/{Makefile.sub,setup.mak}: invoke .bat via shell. workaround
+ for nmake 8.
-Mon Jan 16 10:13:38 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Jan 16 10:26:23 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/syck/emitter.c (syck_emit_seq, syck_emit_map, syck_emit_item):
should output complex key mark even if map's key is empty seq/map.
[ruby-core:7129]
-Sat Jan 14 03:38:54 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sat Jan 14 05:37:06 2006 Tanaka Akira <akr@m17n.org>
+
+ * io.c (READ_DATA_PENDING, READ_DATA_PENDING_COUNT): defined
+ for DragonFly BSD 1.4.0.
+
+Sat Jan 14 03:43:24 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* file.c (rb_file_s_chmod): avoid warning where sizeof(int) !=
sizeof(void*).
-Fri Jan 13 19:26:15 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Jan 13 19:14:56 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/rdoc/diagram.rb:
- properly quote bare element attributes
@@ -4705,15 +5551,23 @@ Thu Jan 12 11:53:08 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
[new feature] support 'command' option which is called just before
popping up the balloon help.
-Wed Jan 11 00:12:29 2006 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Wed Jan 11 15:00:00 2006 Ville Mattila <mulperi@iki.fi>
- * lib/erb.rb (ERB::Compiler): add instance variable @insert_cmd to
- change <%='s behavior.
+ * io.c (READ_PENDING*): Support solaris 64-bit environments.
+ Solaris defines a opaque FILE struct when compiling 64 bit
+ binaries. This means that we dont have access to _ptr etc.
+ members anymore. The solution by Steven Lumos is to define
+ FILE64 that has needed members available. I've modified
+ the origanal patch a bit so that it compiles both with gcc
+ and now free sun studio 11 compiler and both amd64 and sparc.
+ NOTE! We have to 64 bit solaris FILE structure time to time
+ otherwise we'll get breakage.
+ [ruby-core:7106]
Tue Jan 10 19:42:33 2006 Tanaka Akira <akr@m17n.org>
* gc.c (garbage_collect): mark ruby_current_node.
- if an exception is raised in a finalizer written in C called by
+ if an exception is raised in a finalizer called written in C by
rb_gc_call_finalizer_at_exit, ruby_set_current_source may use
collected ruby_current_node and mark_source_filename may corrupt
memory.
@@ -4736,68 +5590,37 @@ Tue Jan 10 12:00:48 2006 Aaron Schrab <aaron @nospam@ schrab.com>
* lib/yaml/rubytypes.rb (Symbol#yaml_new): YAML loading of quoted
Symbols broken. [ruby-Bugs:2535]
-Tue Jan 10 07:26:52 2006 Tanaka Akira <akr@m17n.org>
-
- * gc.c (gc_stress): renamed from always_gc and enabled by default.
- (gc_stress_get): new function for GC.stress.
- (gc_stress_set): new function for GC.stress=.
-
-Mon Jan 9 19:58:56 2006 arton <artonx@yahoo.co.jp>
+Mon Jan 9 19:54:35 2006 arton <artonx@yahoo.co.jp>
* ext/zlib/extconf.rb: zlib compiled DLL version 1.2.3 distributed by
http://www.zlib.net/ has zdll.lib. [ruby-dev:28209]
-Mon Jan 9 14:25:00 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Jan 9 14:17:12 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/Makefile.sub (OPTFLAGS): I have experienced trouble on y- flag,
(VisualC++6) so use -O2b2xg- if $(MSC_VER) < 1400. [ruby-core:7040]
-Mon Jan 9 14:25:00 2006 Kero van Gelder <rubyforge @nospam@ kero.tmfweb.nl>
+Mon Jan 9 14:17:12 2006 Kero van Gelder <rubyforge @nospam@ kero.tmfweb.nl>
* lib/webrick/httpservlet/filehandler.rb: fixed typo. [ruby-core:7075]
-Sun Jan 8 14:15:27 2006 Tanaka Akira <akr@m17n.org>
-
- * eval.c (GCC_VERSION_BEFORE): check __INTEL_COMPILER.
- Intel C++ Compiler defines __GNUC__.
- http://www.intel.com/software/products/compilers/clin/docs/ug_cpp/lin1077.htm
-
Sat Jan 7 15:40:07 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (singleton): get rid of segfault on syntax error.
fixed: [ruby-core:07070]
-Sat Jan 7 06:24:18 2006 Tanaka Akira <akr@m17n.org>
-
- * eval.c (rb_fd_isset): compare the result of FD_ISSET with 0 to
- avoid FreeBSD bug. FreeBSD defines FD_ISSET as just a bitmap of
- unsigned long. So returning the value from rb_fd_isset discards
- upper 32bits on LP64 environment.
- http://www.freebsd.org/cgi/query-pr.cgi?pr=ia64/91421
-
-Fri Jan 6 02:20:18 2006 Tanaka Akira <akr@m17n.org>
+Fri Jan 6 10:16:20 2006 Steven Lumos <steven@lumos.us>
- * configure.in: don't force getcontext on IA64.
+ * io.c (READ_DATA_PENDING): defined for 64bit Solaris on SPARC.
+ [ruby-core:7057]
+ (READ_DATA_PENDING_COUNT): ditto.
+ (READ_DATA_PENDING_PTR): ditto.
- * eval.c (ruby_setjmp): add an argument for just before getcontext.
- (THREAD_SAVE_CONTEXT): call rb_thread_save_context just
- before getcontext.
- [ruby-dev:28205]
-
-Sun Jan 1 15:28:46 2006 Tanaka Akira <akr@m17n.org>
-
- * missing.h (isinf): avoid macro expansion
- "extern int isinf(double);" to
- "extern int ((sizeof(double)==sizeof(float))?_Isinff(double):_Isinf(double));" on
- HP-UX.
-
-Sun Jan 1 14:42:54 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sun Jan 1 17:07:59 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_seekdir): should not segfault even if passed
- the location which rb_w32_telldir didn't return. (and should change
- `bits' position) [ruby-core:7035]
-
- * win32/dir.h: ditto. (stores `loc' instead of `bitpos')
+ the location which rb_w32_telldir didn't return. [ruby-core:7035]
+ (I think HEAD implementation is better. but binary compatibility)
* test/ruby/test_dir.rb: added.
@@ -4806,41 +5629,26 @@ Sat Dec 31 22:57:00 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_thread_save_context): should not recycle scope object used
in a thread. fixed: [ruby-dev:28177]
-Sat Dec 31 19:50:38 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ext/syck/rubyext.c: attribute name was truncated with Rev1.64.
-
-Sat Dec 31 11:53:16 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * lib/generator.rb: (Generator#initialize): should kill @loop_thread
- before starting new thread. (occurs when called via Generator#rewind)
- [ruby-dev:28184]
-
Fri Dec 30 18:22:42 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * gc.c (garbage_collect): mark objects referred from aborting threads.
+ * gc.c (garbage_collect): mark objects refered from aborting threads.
[ruby-dev:28190]
* win32/Makefile.sub: VC++8 support.
-Fri Dec 30 15:17:35 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * lib/generator.rb (Generator#initialize): ensured to stop @loop_thread.
- Mr. Tanaka pointed out one Thread.pass is not enough. [ruby-dev:28185]
+Fri Dec 30 14:24:53 2005 WATANABE Hirofumi <eban@ruby-lang.org>
-Fri Dec 30 12:20:57 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * dir.c (glob_helper): do not use TRUE for djgpp.
- * lib/generator.rb (Generator#initialize): fixed dead lock. this occurred
- when end? was called before @loop_thread was stopped. [ruby-core:7029]
+Fri Dec 30 04:54:40 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-Fri Dec 30 01:04:52 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * file.c (eaccess): workaround for VC++8 runtime.
- * lib/generator.rb: should work with another thread. (more robust code)
- [ruby-dev:28177]
+ * win32/win32.c (ioinfo): VC++8 support.
Thu Dec 29 23:59:37 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (rb_gc_mark_threads): keep unmarked threads which won't wake
+ * eval.c (rb_gc_mark_threads): leave unmarked threads which won't wake
up alone, and mark threads in the loading table. [ruby-dev:28154]
* eval.c (rb_gc_abort_threads), gc.c (gc_sweep): kill unmarked
@@ -4851,87 +5659,23 @@ Thu Dec 29 17:02:07 2005 Tanaka Akira <akr@m17n.org>
* test/ruby/envutil.rb (EnvUtil.rubybin): search "ruby" instead of
"miniruby". [ruby-dev:28140]
-Thu Dec 29 14:35:10 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_mod_define_method): should save safe_level in the
- proc object. [ruby-dev:28146]
-
-Thu Dec 29 11:22:34 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * lib/generator.rb: reimplemented Generator class with Thread instead of
- callcc, in order to fix memory leak. [ruby-dev:28142]
-
-Wed Dec 28 14:10:05 2005 Tanaka Akira <akr@m17n.org>
-
- * ia64.s: remove .pred.safe_across_calls directive.
- reported by WATANABE Tetsuya. [ruby-dev:28141]
-
-Wed Dec 28 01:32:39 2005 Tanaka Akira <akr@m17n.org>
-
- * eval.c (struct thread): add bstr_max.
- (rb_thread_save_context): use realloc instead of REALLOC_N
- to avoid GC.
-
-Tue Dec 27 23:59:53 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb (CompletingHash#match): fix for 1.9.
-
Tue Dec 27 16:59:52 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* test/drb/drbtest.rb (DRbService::self.ext_service): increase
timeout limit. a patch from Kazuhiro NISHIYAMA
<zn at mbf.nifty.com>. [ruby-dev:28132]
-Tue Dec 27 14:17:55 2005 Tanaka Akira <akr@m17n.org>
-
- * configure.in: define IA64 for portability. (HP aC++/ANSI C doesn't
- define __ia64__.)
- don't check libunwind stuff.
- check __libc_ia64_register_backing_store_base.
-
- * defines.h: declare rb_ia64_bsp and rb_ia64_flushrs.
- (flush_register_windows): call rb_ia64_flushrs on IA64.
-
- * ia64.s: new file for IA64.
- it is separated from C program files because
- Intel C++ Compiler for IA64 doesn't support inline assembly.
-
- * common.mk (ia64.$(OBJEXT)): new target.
-
- * ruby.h (RUBY_INIT_STACK): defined.
- (ruby_init_stack): declared for RUBY_INIT_STACK.
-
- * main.c (main): precedes RUBY_INIT_STACK before ruby_init.
-
- * gc.c (rb_gc_register_stack_start): new global variable on IA64.
- (garbage_collect): simplify register stack marking code.
- don't use libunwind.
- (Init_stack): initialize rb_gc_register_stack_start.
- (ruby_init_stack): new function for RUBY_INIT_STACK.
-
- * eval.c (struct thread): add bstr_pos member for original position of
- register stack.
- (rb_thread_save_context): simplify register stack saving code.
- don't use libunwind.
- (rb_thread_restore_context_0): new function. moved from
- rb_thread_restore_context except the stack position checking code.
- don't use libunwind for IA64 register stack.
- (register_stack_extend): new function.
- (stack_extend): make it self-recursive with
- the stack position checking code in old rb_thread_restore_context.
- (rb_thread_restore_context): just call stack_extend.
- (flush_register_windows): removed.
-
- [ruby-dev:28127]
+Tue Dec 27 08:29:18 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-Tue Dec 27 14:09:39 2005 Minero Aoki <aamine@loveruby.net>
-
- * process.c: new method Process.exec. [ruby-dev:28107]
+ * ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SSLSocket#post_connection_chech):
+ treat wildcard character in commonName. [ruby-dev:28121]
-Tue Dec 27 08:22:15 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Dec 26 22:32:47 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SSLSocket#post_connection_check):
- treat wildcard character in commonName. [ruby-dev:28121]
+ * eval.c (rb_eval), gc.c (gc_mark_children), node.h (NEW_ALIAS,
+ NEW_VALIAS), parse.y (fitem): allow dynamic symbols to
+ NODE_UNDEF and NODE_ALIAS.
+ backported from trunk. fixed: [ruby-dev:28105]
Mon Dec 26 08:50:36 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -4944,20 +5688,23 @@ Mon Dec 26 08:50:36 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
Joel VanderWerf <vjoel at path.berkeley.edu>.
[ruby-talk:165285] [ruby-core:6995]
+Sat Dec 24 18:58:14 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * stable version 1.8.4 released.
+
Fri Dec 23 10:30:23 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/digest/sha2/sha2.c (ULL): support AIX C. a patch from
Kailden <kailden at gmail.com>. [ruby-core:06984]
-Wed Dec 21 16:47:35 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Dec 21 16:53:06 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* file.c (w32_io_info): should return handle because FileIndex is
valid only while file is open. [ruby-dev:28088]
-Wed Dec 21 12:12:21 2005 Tanaka Akira <akr@m17n.org>
+Wed Dec 21 14:53:26 2005 Tanaka Akira <akr@m17n.org>
- * test/pathname/test_pathname.rb (test_kernel_open): use
- File.identical?.
+ * lib/pathname.rb (test_kernel_open): use File.identical?.
[ruby-talk:171804]
Tue Dec 20 22:41:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -4965,102 +5712,36 @@ Tue Dec 20 22:41:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (eval_under_i): evaluate source in caller's frame.
[ruby-dev:28076]
-Tue Dec 20 12:53:23 2005 why the lucky stiff <why@ruby-lang.org>
-
- * ext/syck/rubyext.c (syck_emitter_reset): to ensure compatibility
- with previous Ruby versions, documents are no longer headless.
-
-Tue Dec 20 12:33:01 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * eval.c (rb_call_super): use original method name on exception.
+ [ruby-dev:28078]
- * ext/syck/rubyext.c (syck_node_transform): ruby object holding
- explicitly freed SyckNode caused SEGV. [ruby-dev:28067]
+Tue Dec 20 13:11:59 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- ... I think syck GC problem was solved now!
+ * ext/syck/rubyext.c: fixed GC problem (backported HEAD 1.55 - 1.62)
+ [ruby-dev:27839]
-Tue Dec 20 01:46:48 2005 Tanaka Akira <akr@m17n.org>
-
- * io.c (rb_f_backquote): fix a GC problem on
- IA64 with gcc 4.0.3 20051216 (prerelease) -O3.
-
-Mon Dec 19 23:32:39 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * Makefile.in (XCFLAGS): separated as well as win32/Makefile.sub.
-
- * main.c (always_gc): dllimport is required for VC to import a DLL
- symbol. fixed: [ruby-dev:28051]
-
- * parse.y (rb_symname_p): fixed wrong validation. [ruby-dev:28047]
-
-Mon Dec 19 23:09:24 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * ext/syck/syck.h (S_FREE): small hack. no need to check if pointer is
+ NULL or not before S_FREE.
* st.c: uses malloc instead of xmalloc to avoid GC. syck uses st_insert
in gram.c to insert node from rb_syck_bad_anchor_handler into
SyckParser's hash table. if GC occurs in st_insert, it's not under
SyckParser's mark system yet. so RString can be released wrongly.
+ [ruby-dev:28057]
- * ext/syck/syck.h (S_FREE): small hack. no need to check if pointer is
- NULL or not before S_FREE.
-
- * ext/syck/rubyext.c (syck_parser_assign_io): rb_check_string_type can
- return new RString. if so, it becomes unreachable from GC after
- returns syck_parser_assign_io, and can be freed by GC. (dangling
- in syck io system) so extends its life time till syck_parse is called.
-
- * ext/syck/rubyext.c (syck_parser_s_alloc): always allocates bonus,
- so no need to check if NULL, and "volatile VALUE hash"
- is not needed. (bonus->port was not protected in syck_emitter_reset)
-
- * ext/syck/rubyext.c (syck_mark_parser): ditto.
-
- * ext/syck/rubyext.c (syck_parser_load): ditto.
-
- * ext/syck/rubyext.c (syck_parser_load_documents): ditto.
-
- * ext/syck/rubyext.c (syck_emitter_s_alloc): ditto.
-
- * ext/syck/rubyext.c (syck_mark_emitter): ditto.
-
- * ext/syck/rubyext.c (syck_emitter_reset): ditto.
-
- * ext/syck/rubyext.c (syck_scalar_value_set): "should set newly
- allocated memory instead of RString's internal storage" stuff again.
- by this, should call syck_free_node instead of rb_syck_free_node.
-
- * ext/syck/rubyext.c (syck_node_type_id_set): ditto.
-
- ... I believe syck GC problem was solved by this.
-
-Mon Dec 19 12:20:59 2005 Tanaka Akira <akr@m17n.org>
-
- * eval.c (FUNCTION_CALL_MAY_RETURN_TWICE): activate only
- before gcc 4.0.3 on SPARC and IA64.
-
-Mon Dec 19 11:37:47 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ext/syck/rubyext.c: sorry, I reverted my "should set newly
- allocated memory instead of RString's internal storage" stuff.
- node allocated in rubyext.c seems to be freed by rb_syck_free_node
- not syck_free_node, and it won't free data.str->ptr and type_id.
-
- (I still think this is unsafe because RString(foo)->ptr becomes
- dangling pointer when RString is modified or freed, but anyway
- I misunderstood, so go back to original code for now)
-
-Sat Dec 17 21:50:41 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Dec 20 12:53:23 2005 why the lucky stiff <why@ruby-lang.org>
- * ext/syck/rubyext.c (syck_emitter_reset): should initialize
- emitter->bonus->oid. otherwise rb_gc_mark crashes.
+ * ext/syck/rubyext.c (syck_emitter_reset): to ensure compatibility
+ with previous Ruby versions, documents are no longer headless.
- * ext/syck/rubyext.c (syck_mark_parser): should mark anchor nodes
- because they hold ruby objects. (ie: rb_syck_bad_anchor_handler)
+Tue Dec 20 01:46:48 2005 Tanaka Akira <akr@m17n.org>
-Sat Dec 17 11:00:17 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * io.c (rb_f_backquote): fix a GC problem on
+ IA64 with gcc 4.0.3 20051216 (prerelease) -O3.
- * ext/syck/rubyext.c (rb_syck_compile): avoid potential memory
- leak.
+Mon Dec 19 23:32:39 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/syck/rubyext.c (syck_set_ivars): avoid potential memory
- leak by explicit symbol allocation.
+ * parse.y (rb_symname_p): fixed wrong validation. [ruby-dev:28047]
Sat Dec 17 03:57:01 2005 Tanaka Akira <akr@m17n.org>
@@ -5072,35 +5753,10 @@ Sat Dec 17 03:30:23 2005 Tanaka Akira <akr@m17n.org>
* eval.c (bmcall): fix a GC problem by tail call on
IA64 with gcc 4.0.3 20051216 (prerelease).
-Fri Dec 16 17:53:45 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ext/syck/rubyext.c (rb_syck_compile): fixed memory leak.
-
- * ext/syck/rubyext.c: should protect global variable from GC.
-
-Fri Dec 16 11:44:43 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ext/syck/rubyext.c (syck_resolver_tagurize): fixed memory leak.
-
- * ext/syck/rubyext.c (syck_node_type_id_set): should set newly
- allocated memory instead of RString's internal storage.
-
- * ext/syck/rubyext.c (syck_scalar_value_set): ditto.
-
- ... these fixes won't fix [ruby-dev:27839]. more work is needed.
-
-Fri Dec 16 04:38:55 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/delegate.rb (Delegator::method_missing): should delegate
- block as well.
-
-Thu Dec 15 19:57:12 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Dec 16 00:54:06 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/cgi.rb (CGI::QueryExtension::MorphingBody): fix criteria to
- use Tempfile. A fix from Zev Blut <rubyzbibd at ubit.com>.
- [ruby-core:06076]
-
- * string.c: remove global functions work on $_.
+ * signal.c (Init_signal): revert C++ style comment.
+ [ruby-dev:28041]
Thu Dec 15 12:35:14 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -5112,18 +5768,10 @@ Thu Dec 15 01:33:31 2005 Tanaka Akira <akr@m17n.org>
* ext/zlib/zlib.c (zstream_run): fix a GC problem by tail call on
x86_64 with gcc 4.0.3 20051111 (prerelease) (Debian 4.0.2-4)
-Wed Dec 14 23:50:20 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/rdoc/parsers/parse_c.rb (find_class_comment): fix for class
- document with prototypes. [ruby-core:06863]
-
-Wed Dec 14 23:39:53 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Dec 14 12:11:46 2005 WATANABE Hirofumi <eban@ruby-lang.org>
- * dir.c (has_magic): glob names contain alphabets to enable case fold
- search. [ruby-dev:27735]
-
- * dir.c (Init_Dir): FNM_SYSCASE which is default case fold flag.
- [ruby-dev:23296]
+ * test/gdbm/test_gdbm.rb: specify pid for the argument of
+ Process.wait. workaround for Cygwin.
Wed Dec 14 12:01:26 2005 Tanaka Akira <akr@m17n.org>
@@ -5147,18 +5795,11 @@ Tue Dec 13 00:08:09 2005 Tanaka Akira <akr@m17n.org>
* sprintf.c (rb_str_format): fix a GC problem.
[ruby-dev:28001]
-Mon Dec 12 15:51:22 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Dec 12 15:54:56 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* test/openssl/test_ssl.rb (test_parallel): call GC.start to close
unused files. [ruby-dev:27981]
-Mon Dec 12 09:58:09 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * range.c (range_cover): new method Range#cover? added. the
- method name might be changed. thanks to takano32 at
- http://www.rubyist.net/~matz/20051210.html#c08 for name
- suggestion. [ruby-talk:167182]
-
Mon Dec 12 00:33:56 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/digest/digest.c (rb_digest_base_s_digest): add volatile to
@@ -5168,38 +5809,11 @@ Mon Dec 12 00:33:56 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
be called before actual variable initialization.
[ruby-dev:27986]
-Sun Dec 11 23:54:07 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/*: update to support libraries in ActiveTcl8.4.12.0
- (see ext/tk/ChangeLog.tkextlib).
-
- * ext/tk/sample/scrollframe.rb: add a new sample.
-
-Sun Dec 11 22:07:58 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * test/rinda/test_rinda.rb (test_remote_array_and_hash): pseudo remote
- objects are protected against GC. [ruby-dev:27911]
-
-Sat Dec 10 01:06:06 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
-
- * lib/matrix.rb: add Matrix#determinant_e, Matrix#rank_e.
- [ruby-dev:27820] and related thread.
-
-Sat Dec 10 00:31:42 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (calling_scope_t): gave names to magic numbers for rb_call().
- [ruby-dev:27978]
-
Fri Dec 9 23:31:02 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rexml/encoding.rb (encoding=): give priority to particular
conversion to iconv. [ruby-core:06520]
-Fri Dec 9 23:16:51 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * range.c (range_include): return false unless included in numeric
- range. fixed: [ruby-dev:27975]
-
Thu Dec 8 02:07:19 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (umethod_bind): adjust invoking class for module method.
@@ -5214,15 +5828,6 @@ Wed Dec 7 17:10:27 2005 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* sprintf.c (rb_f_sprintf): [ruby-dev:27967]
-Wed Dec 7 16:39:18 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * range.c (range_include): use discrete membership for non Numeric
- values, for example, String.
-
- * numeric.c (num_scalar_p): new method. [ruby-dev:27936]
-
- * lib/complex.rb (Complex#scalar?): ditto.
-
Wed Dec 7 15:31:35 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* sprintf.c (rb_str_format): integer overflow check added.
@@ -5250,22 +5855,11 @@ Wed Dec 7 01:02:04 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/demos-en/menu.rb: ditto.
-Tue Dec 6 16:48:40 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * gc.c (ruby_xmalloc2): change check condition for integer
- overflow. [ruby-dev:27399]
-
- * gc.c (ruby_xrealloc2): ditto.
-
Tue Dec 6 16:37:57 2005 Yuya Nishida <yuya@j96.org>
* eval.c (exec_under): avoid accessing ruby_frame->prev.
[ruby-dev:27948]
-Fri Dec 2 19:06:06 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (Compare): should not fold double byte alphabet on win9x.
-
Thu Dec 1 00:50:33 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_funcall2): allow to call protected methods.
@@ -5273,9 +5867,6 @@ Thu Dec 1 00:50:33 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
Wed Nov 30 23:52:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * parse.y (struct parser_params): fields common to ripper must be
- placed at each same offset.
-
* parse.y (NEWHEAP, ADD2HEAP): set count after pointer was set.
fixed: [ruby-dev:27896]
@@ -5284,53 +5875,23 @@ Wed Nov 30 13:43:07 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* misc/ruby-mode.el (ruby-expr-beg): support $! at the end of
expression. [ruby-dev:27868]
-Mon Nov 28 20:24:22 2005 Tanaka Akira <akr@m17n.org>
-
- * lib/pp.rb (PP::PPMethods#object_address_group): mask an address with
- word size.
-
-Tue Nov 29 23:57:05 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (struct parser_params): heap must be placed at same offset
- also in ripper.y. fixed: [ruby-dev:27846]
-
- * parse.y (yycompile): prevent vparser from tail call optimization.
- fixed: [ruby-dev:27851]
-
- * parse.y (parser_mark): value needs to be marked.
- fixed: [ruby-dev:27845]
-
-Tue Nov 29 22:45:30 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/drb/observer.rb (notify_observers): follow change of observer.rb.
- fixed: [ruby-core:6796]
-
-Mon Nov 28 20:24:22 2005 Tanaka Akira <akr@m17n.org>
-
- * lib/pp.rb (PP::PPMethods#object_address_group): adjust address format.
-
-Mon Nov 28 18:55:22 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Mon Nov 28 18:55:43 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/socket/socket.c (init_inetsock_internal): remove setting
SO_REUSEADDR option on server socket on Cygwin.
fixed: [ruby-core:6765] ([ ruby-Bugs-2872 ])
-Mon Nov 28 13:11:45 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Nov 28 13:08:54 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_strerror): remove all CR and LF. (avoid broken
error message on bccwin32 + winsock)
-Mon Nov 28 09:15:50 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Nov 28 09:21:49 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/mkmf.rb (create_makefile): should not change sodir with
- dir.gsub!. (bccwin32 failed to install third party extensions)
+ dir.gsub!. (bccwin32 failed to install third party exntesions)
[ruby-dev:27834]
-Sun Nov 27 05:37:20 2005 Tanaka Akira <akr@m17n.org>
-
- * lib/pathname.rb: use File.basename to decompose pathnames.
- experimental Windows support.
-
Sun Nov 27 00:56:13 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/wsdl/xmlSchema/complexContent.rb: missing
@@ -5340,103 +5901,23 @@ Sat Nov 26 19:57:45 2005 WATANABE Hirofumi <eban@ruby-lang.org>
* dln.c (conv_to_posix_path): should initialize posix.
-Fri Nov 25 20:34:56 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/xmlrpc/datetime.rb (DateTime::to_a): comparison with non
- array-convertible object must return false.
-
-Fri Nov 25 14:34:09 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * range.c (range_max): treat end exclusion without iteration if
- the end value is an integer. [ruby-talk:167433]
-
-Fri Nov 25 12:52:57 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb: added backward compatibility codes.
- * lib/rss/parser.rb: ditto.
- * test/rss/test_parser.rb: ditto.
- * test/rss/test_2.0.rb: ditto.
-
- * test/rss/test_content.rb: use #__send__ instead of #funcall for
- no private method.
-
-Fri Nov 25 12:39:56 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb: improved type conversion.
- * lib/rss/1.0.rb: ditto.
- * lib/rss/0.9.rb: ditto.
- * lib/rss/2.0.rb: ditto.
- * lib/rss/image.rb: ditto.
- * lib/rss/syndication.rb: ditto.
-
- * test/rss/test_2.0.rb: added type conversion tests.
- * test/rss/test_accessor.rb: ditto.
- * test/rss/test_to_s.rb: ditto.
- * test/rss/test_syndication.rb: ditto.
- * test/rss/test_setup_maker_2.0.rb: ditto.
- * test/rss/test_setup_maker_1.0.rb: ditto.
- * test/rss/test_setup_maker_0.9.rb: ditto.
- * test/rss/test_maker_sy.rb: ditto.
- * test/rss/test_maker_image.rb: ditto.
- * test/rss/test_maker_2.0.rb: ditto.
- * test/rss/test_maker_0.9.rb: ditto.
- * test/rss/test_image.rb: ditto.
-
- * test/rss/test_maker_1.0.rb: use assert instead of assert_equal.
-
- * test/rss/rss-assertions.rb: improved type conversion assertions.
-
-Fri Nov 25 10:38:20 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/image.rb: added Image prefix.
-
- * lib/rss/maker/image.rb: ditto.
-
-Fri Nov 25 10:33:02 2005 Kouhei Sutou <kou@cozmixng.org>
+Thu Nov 24 21:05:58 2005 NAKAMURA Usaku <usa@ruby-lang.org>
- * test/rss/test_2.0.rb: added RSS 2.0 tests.
-
- * test/rss/rss-assertions.rb: extended XML stylesheet assertion.
-
- * lib/rss/0.9.rb: added initialize method.
-
- * test/rss/test_1.0.rb: cleanup.
+ * configure.in (AC_CHECK_FUNCS): need to check link().
+ fixed: [ruby-dev:27814]
-Fri Nov 25 10:29:48 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * range.c (range_min): use <=> comparison rather than iteration.
- [ruby-talk:167420]
-
- * range.c (range_max): ditto.
-
-Thu Nov 24 01:31:44 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Nov 24 01:22:25 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* file.c (w32_io_info): CreateFile failed on Win9x if file was already
opened. (FILE_SHARE_READ was needed, but actually I don't understand
the flags of CreateFile well...)
-Wed Nov 23 23:52:35 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * numeric.c (num_div): use floor rather than rb_Integer().
- [ruby-dev:27674]
-
-Wed Nov 23 22:34:15 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/parser.rb: added entity handling type predicate.
- * lib/rss/rexmlparser.rb: ditto.
- * lib/rss/xmlparser.rb: ditto.
- * lib/rss/xmlscanner.rb: ditto.
-
- * lib/rss/xmlscanner.rb: more robust entity handling.
-
- * test/rss/test_parser.rb: added an entity handling test.
-
Wed Nov 23 20:59:01 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: add Tk.pkgconfig_list and Tk.pkgconfig_get
[Tk8.5 feature].
- * ext/tk/lib/tk/text.rb: supports new indices modifiers on a Text
+ * ext/tk/lib/tk/text.rb: supports new indices modifires on a Text
widget [Tk8.5 feature].
* ext/tk/lib/tk/virtevent.rb: add TkNamedVirtualEvent.
@@ -5446,7 +5927,7 @@ Wed Nov 23 20:59:01 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/event.rb: add :data key for virtual events [Tk8.5
feature].
-Wed Nov 23 18:52:45 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Nov 23 18:55:31 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* file.c (w32_io_info): should not call GetFileInformationByHandle
for pipe.
@@ -5455,61 +5936,15 @@ Wed Nov 23 18:52:45 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* file.c (w32_io_info): now can identify directory on WinNT.
-Wed Nov 23 18:46:53 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/: use #__send__ instead of #send.
- * test/rss/: ditto.
-
-Wed Nov 23 18:32:56 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * test/rss/test_taxonomy.rb: use #reject directory.
-
-Wed Nov 23 18:26:00 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/taxonomy.rb: changed class or module prefix to
- Taxonomy from Taxo.
- * lib/rss/maker/taxonomy.rb: ditto.
-
-Wed Nov 23 18:21:11 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/maker/taxonomy.rb: implemented taxonomy module for RSS
- Maker.
- * lib/rss/taxonomy.rb: supported RSS Maker.
- * lib/rss/maker.rb: added taxonomy module support.
-
- * lib/rss/rss.rb: adjusted to other element API.
- * lib/rss/1.0.rb: adjusted to other element API but backward
- compatibility is reserved.
- * lib/rss/0.9.rb: ditto.
-
- * test/rss/test_maker_taxo.rb: added test case for taxonomy module
- for RSS Maker.
- * test/rss/test_setup_maker_1.0.rb: added tests for taxo:topic.
-
- * test/rss/test_setup_maker_1.0.rb: added backward compatibility
- test.
- * test/rss/test_setup_maker_0.9.rb: ditto.
- * test/rss/test_setup_maker_2.0.rb: ditto.
-
- * test/rss/rss-testcase.rb: added convenience method for setting
- up taxo:topic.
- * test/rss/rss-assertions.rb: added assertion for taxo:topic.
-
- * sample/rss/blend.rb: followed new API.
-
-Wed Nov 23 17:42:24 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb: fixed a indentation bug.
-
- * lib/rss/taxonomy.rb: fixed <taxo:topic> #to_s bug.
-
- * test/rss/test_taxonomy.rb: added a #to_s test.
-
Wed Nov 23 03:40:49 2005 Guy Decoux <ts@moulon.inra.fr>
* re.c (KR_REHASH): should cast to unsigned for 64bit CPU.
[ruby-core:06721]
+Wed Nov 23 11:01:33 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * intern.h, file.c: failed to compile on windows.
+
Wed Nov 23 07:26:44 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/extconf.rb: check for X509V3_EXT_nconf_nid.
@@ -5541,14 +5976,14 @@ Tue Nov 22 18:36:11 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (winnt_stat): set mapped errno instead of ENOENT.
-Tue Nov 22 14:36:54 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Nov 22 14:46:57 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* file.c (rb_file_s_basename): skip slashes just after UNC top slashes.
* test/ruby/test_path.rb (test_dirname, test_basename): follow new
spec. and add new tests.
-Tue Nov 22 13:30:15 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Nov 22 13:18:32 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_stat): Dir.chdir('//server/shared');
p Dir.glob('*') should work on WinNT. (implemented our own
@@ -5577,11 +6012,6 @@ Mon Nov 21 16:03:48 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/setup.mk: findstr doesn't exist on win9x.
fixed: [ruby-dev:27756]
-Sun Nov 20 21:39:27 2005 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * regparse.c (fetch_token_in_cc): tok->escaped should be
- initialized. [ruby-dev:27763]
-
Sun Nov 20 22:34:06 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (rb_symname_p): [ not followed by ] is not valid symbol.
@@ -5592,10 +6022,6 @@ Sat Nov 19 19:57:54 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/fileutils.rb (FileUtils::ln): ln documentation fix.
[ruby-core:06661]
-Sat Nov 19 08:19:38 2005 Zach Dennis <zdennis@mktec.com>
-
- * ext/socket/socket.c: Socket Documentation. [ruby-core:6552]
-
Sat Nov 19 07:34:32 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/font.rb: remove dependency on Ruby's version (1.8
@@ -5605,7 +6031,7 @@ Sat Nov 19 07:34:32 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/tkextlib/treectrl/demo.rb: ditto.
-Fri Nov 18 18:07:05 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Fri Nov 18 17:57:08 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* file.c (rb_file_s_dirname): should use skipprefix for UNC path.
pointed out by nobu ([ruby-dev:27744]). fixed: [ruby-core:5076]
@@ -5626,7 +6052,7 @@ Fri Nov 18 17:35:09 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/namespace.rb: ditto.
-Fri Nov 18 16:47:33 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Fri Nov 18 17:26:06 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* file.c (rb_file_s_dirname): added checks for some patterns with drive
letter. fixed: [ruby-dev:27738]
@@ -5634,37 +6060,11 @@ Fri Nov 18 16:47:33 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* test/ruby/test_path.rb (test_dirname): added tests for above
patterns.
-Fri Nov 18 12:19:16 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Nov 18 12:18:02 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.h (S_IFIFO): r,w = IO.pipe; r.stat.pipe? now
returns true on VisualC++6.
-Thu Nov 17 17:58:00 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/1.0.rb: added convenience method 'resources'.
-
- * lib/rss/taxonomy.rb: ditto.
-
- * test/rss/rss-assertions.rb: added test for 'resources'.
-
- * test/rss/test_taxonomy.rb: ditto.
-
-Thu Nov 17 17:53:30 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/taxonomy.rb: implemented taxonomy module.
-
- * test/rss/test_taxonomy.rb: added tests for taxonomy support.
-
-Thu Nov 17 17:40:19 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/1.0.rb: added rdf:Bag.
-
-Thu Nov 17 13:52:00 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb : removed needless argument 'prefix'.
-
- * lib/rss/parser.rb: ditto.
-
Wed Nov 16 23:24:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* common.mk (static-ruby): overridable.
@@ -5674,24 +6074,12 @@ Wed Nov 16 23:24:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb (RUBY, RUBYW): overridable.
-Wed Nov 16 01:29:31 2005 Kouhei Sutou <kou@cozmixng.org>
+Tue Nov 15 23:46:35 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/rss/trackback.rb: added TrackBack prefix.
+ * lib/find.rb (Find::find): should not ignore symbolic links to
+ non-existing files. [ruby-talk:165866]
- * lib/rss/maker/trackback.rb: ditto.
-
-Wed Nov 16 01:26:13 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb (RSS::VERSION): 0.1.5 -> 0.1.6.
-
- * test/rss/test_version.rb (RSS::TestVersion#test_version): ditto.
-
-Tue Nov 15 23:54:24 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (file_load_ok): eaccess() returns 0 on success.
- fixed: [ruby-dev:27713]
-
-Tue Nov 15 16:36:03 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Nov 15 16:23:26 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* array.c (rb_ary_fill): previous commit disabled this usage:
@@ -5699,17 +6087,9 @@ Tue Nov 15 16:36:03 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
a.fill {|i| a[i] * 10} #=> [nil, nil, ...., nil]
previous commit has the advantage of early garbage collection, but
- potentially this would break some script. so I reverted behavior.
-
-Tue Nov 15 16:15:23 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * file.c (file_load_ok): use eaccess() instead of actually opening
- the file. [ruby-talk:156378]
+ potensially this would break some script. so I reverted behavior.
- * lib/jcode.rb (String::reverse): add new methods.
- [ruby-list:41245]
-
-Tue Nov 15 15:49:34 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Nov 15 16:04:10 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* array.c (rb_ary_fill): tail elements were vanished when the middle
part of array was filled. (ie: [0,1,2,3,4].fill(-1,2,1) => [0,1,-1])
@@ -5731,71 +6111,33 @@ Mon Nov 14 17:36:22 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_first): RDoc update from Daniel Berger
<djberg96@yahoo.com>. [ruby-core:06577].
-Sun Nov 13 10:55:24 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/uri/common.rb (escape): regard second argument as a
- character set. [ruby-dev:27692]
-
-Sat Nov 12 08:36:40 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Nov 11 10:31:44 2005 Zach Dennis <zdennis@mktec.com>
- * configure.in, eval.c, intern.h: check fd_mask type.
-
- * configure.in (socketpair): need to be checked.
-
-Fri Nov 11 19:53:47 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * eval.c, intern.h: failed to compile where NFDBITS is defined but
- howmany() is not defined. [ruby-dev:27680]
-
- * io.c (is_socket): failed to compile where S_ISSOCK is not defined.
-
- * io.c (pipe_open): failed to compile where socketpair is not supported.
+ * ext/socket/socket.c: Socket Documentation. [ruby-core:6552]
Fri Nov 11 08:20:56 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* Makefile.in (OUTFLAG): keep trailing spaces. [ruby-dev:27666]
- * mkconfig.rb: substitution references added.
+ * mkconfig.rb: substitution refereces added.
-Fri Nov 11 07:39:49 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Nov 11 07:44:18 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* configure.in: undef HAVE_LINK on BeOS. (link(2) always returns
EINVAL, and this causes error in test/fileutils.)
- * file.c: override chown(2) and fchown(2) on BeOS. (these functions
+ * file.c: overwride chown(2) and fchown(2) on BeOS. (these functions
should not change user/group id if -1 is passed as corresponding
argument, and this causes error in test/fileutils too)
[ruby-dev:27672]
-Thu Nov 10 21:05:03 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/shellwords.rb: fix for blank but not empty string.
- fixed: [ruby-dev:27663]
-
-Wed Nov 9 08:39:38 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/shellwords.rb: refactored. [ruby-core:06581]
-
-Tue Nov 8 17:35:53 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * intern.h, eval.c (rb_thread_signal_raise): constified.
-
- * signal.c: cosmetic change.
+ * file.c (rb_file_s_link): checks HAVE_LINK.
Tue Nov 8 15:32:27 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/drb/ssl.rb (DRb::SSLConfig#accept): fixed typo.
[ruby-dev:27560] [ruby-core:4627]
-Mon Nov 7 20:54:57 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/iconv.c: iconvctl() support. [EXPERIMENTAL]
-
-Mon Nov 7 16:23:23 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/openssl/ossl.h: need to include winsock2.h before including
- windows.h by some openssl headers.
-
Mon Nov 7 13:43:51 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/stubs.c (_nativethread_consistency_check): use simpler
@@ -5806,7 +6148,7 @@ Mon Nov 7 13:43:51 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tkutil/tkutil.c: ditto.
-Mon Nov 7 00:06:12 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Nov 7 00:06:58 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/yaml.rb: removed :nodoc: to generate Kernel doc. [ruby-core:6324]
@@ -5815,7 +6157,7 @@ Sun Nov 6 23:39:13 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/iconv/iconv.c (Iconv::BrokenLibrary): exception when detected a
bug of underlying library.
-Sun Nov 6 21:43:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sun Nov 6 21:46:59 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/tk/stubs.c (ruby_tcl_create_ip_and_stubs_init): should touch
interpreter after initialization is done. [ruby-dev:27638]
@@ -5825,33 +6167,21 @@ Sun Nov 6 20:13:27 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_s_readlink): readlink(2) on AIX fails with ERANGE if
buffer size is less than required. fixed: [ruby-dev:27634]
-Sat Nov 5 13:42:50 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in, cygwin/GNUmakefile.in (mingw): use def file to alias
- symbols. [ruby-dev:27532]
-
- * bcc32/mkexports.rb, win32/mkexports.rb: make aliases in DLL.
-
- * win32/win32.c, win32/win32.h: replace symbols only when RUBY_EXPORT
- is defined.
-
-Thu Nov 3 07:57:39 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/open-uri.rb (open_loop): find_proxy should return nil when
- proxy does not exist. [ruby-dev:27630]
-
Wed Nov 2 20:25:28 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/extconf.rb: ext/tk/extconf.rb: change the check parameter
for Win32.
+Wed Nov 2 20:14:53 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * ext/tcltklib: merge into ext/tk and remove.
+
Wed Nov 2 19:03:06 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c (ip_rbUpdateObjCmd, ip_rb_threadUpdateObjCmd):
- passed improper flags to DoOneEvent().
+ * ext/tcltklib/tcltklib.c (ip_rbUpdateObjCmd,
+ ip_rb_threadUpdateObjCmd): passed improper flags to DoOneEvent().
- * ext/tk/tkutil/tkutil.c: use rb_obj_respond_to() instead of
- rb_respond_to().
+ * ext/tk/tkutil.c: use rb_obj_respond_to() instead of rb_respond_to().
Tue Nov 1 14:20:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -5861,7 +6191,7 @@ Tue Nov 1 14:20:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (exec_under): frame during eval should preserve external
information.
-Tue Nov 1 10:48:49 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Tue Nov 1 10:50:17 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/extconf.rb: should check ERR_peek_last_error().
[ruby-dev:27597]
@@ -5873,14 +6203,19 @@ Mon Oct 31 17:34:46 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* configure.in: use proper option for Sun linker. A patch from
Shinya Kuwamura <kuwa at labs.fujitsu.com>. [ruby-dev:27603]
-Mon Oct 31 05:46:08 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Oct 31 11:27:22 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * test/gdbm/test_gdbm.rb, test/sdbm/test_sdbm.rb (test_s_open_error):
+ skip on Win32/DOS platforms.
+
+Mon Oct 31 05:49:23 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_cipher.c (ossl_cipher_update): input data must
not be empty. [ruby-talk:161220]
* test/openssl/test_cipher.rb: add test for Cipher#update("").
-Mon Oct 31 05:38:26 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Oct 31 05:37:20 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httpservlet/cgihandler.rb
(WEBrick::HTTPServlet::CGIHandler#do_GET): the value of Set-Cookie:
@@ -5892,14 +6227,17 @@ Mon Oct 31 05:38:26 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* test/webrick/test_cookie.rb, test/webrick/test_cgi.rb,
test/webrick/webrick.cgi: add some test for cookie.
-Mon Oct 31 02:33:25 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Oct 31 03:19:36 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ext/readline/readline.c (readline_readline): type check.
+ [ruby-core:6089]
* numeric.c (fix_rshift): RDoc fix. [ruby-core:6351]
* util.h (strtod): add #undef for platforms defines strtod()
macro. [ruby-dev:27563]
-Mon Oct 31 02:31:41 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Oct 31 02:35:59 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* test/ruby/test_float.rb (test_precision): test by assert_in_delta.
[ruby-dev:27575]
@@ -5911,33 +6249,25 @@ Sat Oct 29 01:58:25 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/fcntl/fcntl.c: ditto.
-Sat Oct 29 16:56:03 2005 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb: added seven predicates sunday? to saturday?.
-
- * lib/date.rb: added two methods {prev,next}_month,
- that are almost same as << and >>.
-
-Thu Oct 27 20:34:43 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * enumerator.c (enumerator_allocate): allow subclassing.
-
Thu Oct 27 16:45:31 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (scan_once): wrong condition to use mbclen2().
[ruby-dev:27535]
-Thu Oct 27 11:53:17 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * missing.h, missing/memcmp.c, missing/memmove.c:
- ANSI compatible interface.
-
-Wed Oct 26 09:15:48 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Oct 26 09:27:27 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/syck/implicit.c (syck_type_id_to_uri): should return
newly allocated memory. otherwise, type_id will be freed
twice. [ruby-dev:27384] [ruby-core:6385]
+Wed Oct 26 09:04:51 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * ruby.h (Qfalse, Qtrue, Qnil, Qundef): make sure these immediate
+ values have VALUE type. there is an environment where sizeof(VALUE)
+ != sizeof(int) like IA64. if 32bit integer (Qtrue) is passed to ANYARGS
+ and received by 64bit integer (VALUE), upper bits may have garbage value.
+ [ruby-dev:27513]
+
Wed Oct 26 01:58:19 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (RUBY_EXTERN): macro to export symbols in shared
@@ -5948,14 +6278,6 @@ Wed Oct 26 01:58:19 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb (extmake): RUBY_EXTERN for static linked extensions.
-Tue Oct 25 20:06:59 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ruby.h (Qfalse, Qtrue, Qnil, Qundef): make sure these immediate
- values have VALUE type. there is an environment where sizeof(VALUE)
- != sizeof(int) like IA64. if 32bit integer (Qtrue) is passed to ANYARGS
- and received by 64bit integer (VALUE), upper bits may have garbage value.
- [ruby-dev:27513]
-
Tue Oct 25 15:32:00 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/rational.rb: applied documentation patch from Gavin Sinclair
@@ -5964,22 +6286,12 @@ Tue Oct 25 15:32:00 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/irb.rb (IRB::Irb::eval_input): handle prompts with newlines
in irb auto-indentation mode. [ruby-core:06358]
-Tue Oct 25 14:21:46 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * gc.c (garbage_collect): sorry, previous commit was incorrect.
- [ruby-core:6386]
-
-Tue Oct 25 13:40:16 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * gc.c (garbage_collect): return now whether there're rooms for new
- objects, rather than whether GC run. fixed: [ruby-core:6376]
-
Tue Oct 25 02:12:08 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rdoc/markup/simple_markup.rb (SM::SimpleMarkup::LABEL_LIST_RE):
reduce redundant backtrack. [ruby-talk:161771]
-Tue Oct 25 00:35:33 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Tue Oct 25 00:27:35 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/rinda/*: RDoc documentation from Eric Hodel
<drbrain@segment7.net> added.
@@ -5989,19 +6301,11 @@ Mon Oct 24 21:14:29 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in, io.c: use sys/syscall.h if syscall.h is not available.
[ruby-core:06247]
-Mon Oct 24 20:38:25 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Mon Oct 24 20:49:45 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/Win32API/lib/win32/resolv.rb (get_info): support multiple DNS.
fixed: [ruby-list:40058], [ruby-dev:27479]
-Mon Oct 24 11:01:11 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk/canvas.rb (TkCanvasItemConfig::__item_val2ruby_optkeys):
- typo fixed. [ruby-talk:162187]
-
- * ext/tk/lib/tk/menu.rb (TkMenuEntryConfig::__item_val2ruby_optkeys):
- ditto. [ruby-core:06359]
-
Mon Oct 24 07:57:56 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/tk/lib/tk/canvas.rb (TkCanvasItemConfig::__item_val2ruby_optkeys):
@@ -6010,18 +6314,15 @@ Mon Oct 24 07:57:56 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/tk/lib/tk/menu.rb (TkMenuEntryConfig::__item_val2ruby_optkeys):
ditto. [ruby-core:06359]
- * lib/matrix.rb (Matrix::initialize): use funcall instead of send
- to allow private methods to be called. A report from
- Jean-Claude Arbaut <jcarbaut@laposte.net>. [ruby-core:06359]
-
-Mon Oct 24 00:41:18 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sun Oct 23 21:50:15 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * time.c (time_sunday): added predicate methods for the days of the
- week. [ruby-list:41340]
+ * ext/enumerator/enumerator.c: applied documentation patch from
+ James Edward Gray II <james@grayproductions.net>.
+ [ruby-core:06348]
Sun Oct 23 07:11:11 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/extconf.rb: improve messages [ruby-core:06325].
+ * ext/tcltklib/extconf.rb: improve messages [ruby-core:06325].
* ext/tk/lib/tk.rb, ext/tk/lib/tk/canvas.rb, ext/tk/lib/tk/entry.rb,
ext/tk/lib/tk/frame.rb, ext/tk/lib/tk/image.rb,
@@ -6048,16 +6349,6 @@ Sat Oct 22 23:54:07 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb, lib/mkmf.rb (with_config): support --with-extension
options. [ruby-dev:27449]
-Sat Oct 22 14:25:43 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * util.[hc] (ruby_add_suffix): constified.
-
- * util.[hc] (ruby_scan_{oct,hex}): fixed typo. (renamed from
- scan_{oct,hex})
-
- * util.c: almostly ANSI styled. (except for functions depending on
- macro and K&R technique)
-
Sat Oct 22 13:26:57 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* object.c (sym_inspect), parse.y (parser_yylex, rb_symname_p): check
@@ -6068,20 +6359,7 @@ Sat Oct 22 13:26:57 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* time.c (rb_strftime): removed meaningless volatile modifiers, and
concatenate successive nul characters at once. [ruby-dev:27472]
- * ext/tk/lib/tk/font.rb, ext/tk/lib/tkextlib/ICONS/icons.rb,
- ext/tk/sample/tkextlib/treectrl/demo.rb, lib/net/imap.rb,
- lib/rss/parser.rb, test/rss/test_content.rb,
- test/rss/test_dublincore.rb, test/rss/test_syndication.rb,
- test/rss/test_trackback.rb, test/ruby/test_eval.rb,
- test/socket/test_socket.rb, test/socket/test_udp.rb:
- Object#fcall was renamed as Object#funcall.
-
-Sat Oct 22 10:08:28 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * missing.h, missing/*.c: SUSv3 compatible strcasecmp and strncasecmp,
- ANSI compatible strtol and strtoul, and ANSI styled other functions.
-
-Fri Oct 21 19:16:08 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Oct 21 19:21:56 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* rubysig.h (CHECK_INTS): fixed typo. (I believe bit-or is improper)
@@ -6089,27 +6367,7 @@ Fri Oct 21 17:49:32 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* bin/erb (ERB::Main::run): typo fixed. [ruby-core:06337]
-Fri Oct 21 15:42:28 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * intern.h, struct.c (rb_struct_iv_get): constified.
-
- * marshal.c: avoid one VC++6 warning for implicit conversion
- from int to char.
-
- * ruby.h: ANSI styled.
-
- * bcc32/Makefile.sub (HAVE_HYPOT): added.
-
- * ext/socket/extconf.rb: BeOS is only one platform should call
- closesocket, so check __BEOS__ macro directly. (I was worried
- accidently HAVE_CLOSESOCKET is defined on windows again because
- it has it)
-
- * ext/socket/{getaddrinfo.c,socket.c}: ditto.
-
- ... these are all cosmetic changes.
-
-Fri Oct 21 15:23:23 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Oct 21 15:27:17 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* bignum.c (bignew_1): convertion from `int' to `char' discards
upper bits, (ie. (char)0xff00 -> 0) so it's better to test if
@@ -6119,26 +6377,7 @@ Fri Oct 21 15:23:23 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* time.c: should use LONG_LONG instead of `long long'.
-Thu Oct 20 22:22:49 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parser.y (struct parser_params): parser never modify input string.
-
- * ext/ripper/tools/preproc.rb (prelude): do not append surplus
- newlines to fix line numbers.
-
-Thu Oct 20 11:41:57 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * class.c, eval.c, hash.c, st.c, variable.c: changed /* ??? */ stuff
- protoize generated to ANYARGS.
-
-Thu Oct 20 11:18:11 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * eval.c, file.c, ruby.c: removed strchr, strrchr, strstr definition
- because they are defined in missing.h.
-
- * missing.h, missing/strchr.c, missing/strstr.c: ANSI styled.
-
-Thu Oct 20 09:36:06 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Oct 20 09:37:15 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/mkmf.rb (create_makefile): Borland make seems not to allow
empty dependency list. If this change is not good, please correct
@@ -6149,13 +6388,20 @@ Thu Oct 20 07:55:09 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (create_makefile): get rid of a restriction
of Borland make. fixed: [ruby-dev:27460]
- * ext/ripper/depend: ditto.
+Thu Oct 20 00:13:18 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * rubysig.h (CHECK_INTS): fix typo.
Wed Oct 19 23:58:03 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (create_makefile): do not create unnecessary empty
directories. fixed: [ruby-dev:27451]
+Wed Oct 19 19:26:15 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (rb_gc_mark_parser): get rid of segfault with old yacc.
+ fixed: [ruby-dev:27439]
+
Wed Oct 19 08:28:32 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_join): elements may contain null pointer strings.
@@ -6163,33 +6409,27 @@ Wed Oct 19 08:28:32 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
Wed Oct 19 02:34:33 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * enumerator.c, eval.c, gc.c, parse.y, regparse.c, sjis.c, time.c:
- made internal symbols static. [ruby-dev:27435]
+ * eval.c, gc.c, time.c: made internal symbols static. [ruby-dev:27435]
-Tue Oct 18 10:58:27 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Oct 19 01:27:07 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/dl/depend, ext/dl/extconf.rb, ext/socket/depend,
- ext/socket/extconf.rb: shouldn't define DESTCLEANFILES in depend,
- use $distcleanfiles in extconf.rb.
+ * regex.c (re_compile_pattern): numeric literal inside character class
+ disabled succeeding backtrack. fixed: [ruby-list:41328]
- * win32/Makefile.sub (distclean-local): should remove .config.h.time.
+Mon Oct 17 21:18:50 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Mon Oct 17 09:42:50 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+ * parse.y (parser_heap): byacc never free parser stack.
+ fixed: [ruby-dev:27428]
- * mkconfig.rb: fixup configure_args for mswin32 configure.
+Mon Oct 17 16:04:47 2005 NAKAMURA Usaku <usa@ruby-lang.org>
- * win32/configure.bat (srcdir, target): ditto.
-
-Mon Oct 17 05:01:50 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * env.h: move struct METHOD and struct BLOCK from eval.c to
- support NodeWrap and ParseTree.
+ * file.c (chmod_internal, lchmod_internal): fixed type of 2nd argument.
Sun Oct 16 22:16:51 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb: omit non-existing directories.
-Sun Oct 16 14:40:54 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sun Oct 16 14:30:05 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/rinda/rinda.rb (Rinda::Tuple#initialize): check remote hash
tuple. fixed: [ruby-list:41227]
@@ -6207,48 +6447,20 @@ Sun Oct 16 03:38:07 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_thread_schedule): clear rb_thread_critical.
[ruby-core:04039]
-Sun Oct 16 00:13:14 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/configure.bat: remove unnecessary line which prevents
- creating Makefile.
-
-Sat Oct 15 23:52:07 2005 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/ftp.rb: (getbinaryfile): allow nil for localfile, and
- returns retrieved data if localfile is nil.
-
- * lib/net/ftp.rb: (gettextfile): ditto.
-
-Sat Oct 15 19:51:29 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sat Oct 15 19:56:38 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* bin/erb: typo fixed, again. thanks, Doug Kearns.
-Fri Oct 14 23:09:31 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/Makefile.sub (MKFILES): update MKFILES if configure files get
- changed.
-
- * win32/configure.bat, win32/setup.mak (configure_args): store
- arguments to configure files.
-
-Fri Oct 14 22:05:45 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Fri Oct 14 22:08:26 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (ioctl): should set errno.
-Fri Oct 14 16:39:37 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Fri Oct 14 16:57:32 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/config.rb (Config::FileHandler): :UserDir should be nil.
It is harmful to permit the access to ~/public_html by default.
suggested by Hiroyuki Iwatsuki.
-Fri Oct 14 04:58:38 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_obj_instance_exec): create instance_exec and
- module_exec which pass arguments to the block.
-
- * eval.c (rb_f_funcall): rename fcall to funcall to follow
- tradition.
-
Thu Oct 13 23:29:51 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (HEAPCNT): bison allocates indivisible size.
@@ -6257,7 +6469,7 @@ Thu Oct 13 23:29:51 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c, pack.c, ext/syck/rubyext.c, ext/syck/syck.h, missing/isinf.c:
get rid of warnings. fixed: [ruby-core:06247]
-Wed Oct 12 12:51:56 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Wed Oct 12 12:52:57 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl.c (Init_openssl): should call
OpenSSL_add_ssl_algorithms().
@@ -6268,15 +6480,6 @@ Wed Oct 12 11:08:54 2005 WATANABE Hirofumi <eban@ruby-lang.org>
Tue Oct 11 21:41:58 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * configure.in (RUBY_FUNC_ATTRIBUTE): check prefixed attribute form
- first. [ruby-dev:27398]
-
- * array.c, enum.c, eval.c, util.c: safer function pointer usage.
- fixed: [ruby-core:06143]
-
- * util.h (qsort): removed the definition incompatible to ANSI.
- fixed: [ruby-core:06147]
-
* eval.c (rb_obj_respond_to): check if obj responds to the given
method with the given visibility. [ruby-dev:27408]
@@ -6287,66 +6490,33 @@ Tue Oct 11 00:01:21 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* st.c (st_free_table): do not call free() but xfree().
[ruby-core:06205]
-Sat Oct 8 19:49:42 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat Oct 8 20:04:40 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (Init_Binding): add Binding#dup method. [yarv-dev:666]
- * io.c (rb_io_init_copy): clear PREP flag for copied IO.
- fixed: [ruby-dev:27371]
-
* parse.y (rb_parser_malloc, rb_parser_free): manage parser stack on
heap. [ruby-list:41199]
- * parse.y (ripper_initialize): use rb_respond_to().
-
- * ext/ripper/depend (check): get rid of re-generating ripper.y always.
-
* ext/iconv/charset_alias.rb: parse config.charset_alias file directly.
- * ext/nkf/lib/kconv.rb (Kconv.conv): get rid of nil.to_a.
-
- * lib/scanf.rb (Scanf::FormatSpecifier#letter, #width): use matched
- substring directly.
-
- * test/ruby/test_assignment.rb, test/ruby/test_iterator.rb: followed
- change of sample/test.rb.
-
- * test/net/http/test_http.rb: removed superfluous splatting stars.
-
-Fri Oct 7 16:41:43 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (splat_value): call rb_Array() to convert svalue to
- values. [ruby-dev:27397]
-
Fri Oct 7 09:54:00 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/cgi.rb (CGI::Cookie::parse): Cookies from Nokia devices may
not be parsed correctly. A patch from August Z. Flatby
(augustzf) in [ruby-Patches-2595]. [ruby-core:06183]
-Thu Oct 6 22:51:30 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (rb_Array): Array() to raise error for objects without
- to_ary, nor to_a.
-
- * object.c (nil_to_a): revert NilClass#to_a.
-
-Thu Oct 6 20:10:38 2005 Minero Aoki <aamine@loveruby.net>
+Thu Oct 6 20:12:16 2005 Minero Aoki <aamine@loveruby.net>
* ext/strscan/strscan.c (strscan_free): remove useless code.
[ruby-dev:26368] [ruby-dev:27389]
-
-Thu Oct 6 01:02:19 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * range.c (rb_range_beg_len): should return Qfalse for non-range
- object.
+ (backported from trunk, rev 1.22)
Wed Oct 5 04:42:38 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/xmlrpc/server.rb (XMLRPC::Server#initialize): should mount the
servlet on "/".
-Wed Oct 5 04:06:49 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Wed Oct 5 03:59:09 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/xmlrpc/server.rb (XMLRPC::Server#serve): delete wrong call
of "join".
@@ -6355,31 +6525,14 @@ Mon Oct 3 00:04:00 2005 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* pack.c (EXTEND16): [ruby-dev:27383]
-Sat Oct 1 23:55:24 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (do_select, rb_w32_select): brush up.
-
-Sat Oct 1 12:57:02 2005 Tanaka Akira <akr@m17n.org>
-
- * bignum.c (rb_big_rand): removed. [ruby-dev:25405]
-
-Sat Oct 1 01:46:51 2005 Tanaka Akira <akr@m17n.org>
-
- * lib/open-uri.rb (OpenURI.open_loop): prohibit multiple proxy
- options.
-
Thu Sep 29 10:26:18 2005 Tanaka Akira <akr@m17n.org>
- * ext/dl/cptr.c (rb_dlptr_s_to_ptr): abolish sizeof(FILE).
+ * ext/dl/dl.c (rb_io_to_ptr): abolish sizeof(FILE).
[ruby-dev:27317]
-Thu Sep 29 10:15:14 2005 Tanaka Akira <akr@m17n.org>
-
- * lib/open-uri.rb (:proxy_http_basic_authentication): new option.
-
Thu Sep 29 07:22:05 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (rb_f_send): underscores need to be escaped.
+ * evalc. (rb_f_send): underscores need to be escaped.
fixed by Doug Kearns. [ruby-core:06053]
Thu Sep 29 00:57:35 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -6390,11 +6543,23 @@ Thu Sep 29 00:57:35 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* variable.c (rb_autoload_load): now return true if autoload
succeeded. fixed: [ruby-dev:27331]
-Wed Sep 28 23:40:04 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Sep 28 23:42:15 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * file.c (apply2files): add prototype.
* file.c (rb_stat_inspect): constified.
-Wed Sep 28 15:12:28 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+ * class.c (rb_mod_init_copy, rb_class_init_copy), file.c (rb_stat_init_copy),
+ numeric.c (num_init_copy), object.c (rb_obj_init_copy, Init_Object),
+ re.c (match_init_copy, rb_reg_init_copy), time.c (time_init_copy):
+ undocumented.
+
+Wed Sep 28 23:09:23 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/delegate.rb: document update from James Edward Gray II
+ <james@grayproductions.net>. [ruby-core:06027]
+
+Wed Sep 28 15:14:19 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/cgi.rb (WEBrick::CGI#start): req.query_string should
refer the value of QUERY_STRING. [ruby-list:41186]
@@ -6404,7 +6569,12 @@ Wed Sep 28 15:12:28 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
Wed Sep 28 10:45:44 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c: cannot compile with Tcl/Tk8.0.x [ruby-dev:27335].
+ * ext/tcltklib/tcltklib.c: cannot compile with Tcl/Tk8.0.x
+ [ruby-dev:27335].
+
+Wed Sep 28 08:12:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (read_buffered_data): check if reached EOF. fixed: [ruby-dev:27334]
Wed Sep 28 07:56:52 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -6415,7 +6585,7 @@ Wed Sep 28 07:56:52 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/yaml/types.rb (YAML::PrivateType, YAML::DomainType): ditto.
-Wed Sep 28 03:16:41 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Sep 28 03:23:35 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* rubysig.h: fixed build problem with --enable-pthread on platforms
which don't have setitimer().
@@ -6425,38 +6595,15 @@ Mon Sep 26 22:32:13 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (set_trace_func): add rb_secure(4) to prevent adding
tracing function.
-Mon Sep 26 20:59:28 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * parse.y: changed to ANSI function style.
-
-Sun Sep 25 12:02:04 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sun Sep 25 12:05:10 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* bin/erb: typo fixed.
-Sun Sep 25 11:54:11 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/rinda/tuplespace.rb (Rinda::TemplateEntry::initialize): pull
- up method. Tabs converted to spaces.
-
-Sun Sep 25 09:34:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * parse.y: replaced `foo _((boo))' with `foo(boo)'.
-
-Sun Sep 25 08:19:53 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/rss/test_content.rb, test/rss/test_syndication.rb: use fcall
- instead of send in order to override visibility.
-
Sun Sep 25 01:46:43 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* misc/ruby-mode.el (ruby-calculate-indent): arrange deep-indent
closing parenthesis at same column as the opening.
-Sun Sep 25 01:33:41 2005 Tanaka Akira <akr@m17n.org>
-
- * process.c (proc_setrlimit): make the third argument (rlim_max)
- optional.
-
Sun Sep 25 00:42:11 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* misc/ruby-mode.el (ruby-expr-beg): deal with heredoc separately.
@@ -6466,37 +6613,20 @@ Sun Sep 25 00:42:11 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
level for continuous line inside parentheses.
http://nabeken.tdiary.net/20050915.html#p02
-Sat Sep 24 21:19:39 2005 Minero Aoki <aamine@loveruby.net>
-
- * ext/strscan/strscan.c: document enhancement.
-
- * ext/strscan/strscan.c: update copyright year.
-
- * ext/strscan/strscan.c: update coding style.
+Sun Sep 25 00:18:11 2005 Tanaka Akira <akr@m17n.org>
-Sat Sep 24 20:20:05 2005 Minero Aoki <aamine@loveruby.net>
-
- * test/net/http/test_http.rb (teardown): Net::HTTP.version_1_1 breaks
- many other tests; ensure that Net::HTTP is version 1.2 after test.
- [ruby-dev:27312]
-
-Sat Sep 24 11:44:28 2005 Minero Aoki <aamine@loveruby.net>
-
- * test/net/http/test_http.rb: new file.
+ * eval.c (unknown_node): show more information. [ruby-dev:26196]
-Sat Sep 24 08:54:05 2005 Minero Aoki <aamine@loveruby.net>
+Sat Sep 24 08:56:01 2005 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (cd): no longer accept :noop option, related
- code is useless. [ruby-core:05858] [ruby-Bugs:2494]
-
-Sat Sep 24 08:30:00 2005 Tanaka Akira <akr@m17n.org>
-
- * lib/pathname.rb (Pathname#sub): new method.
+ code is useless (backported from trunk, rev 1.67).
+ [ruby-core:05858] [ruby-Bugs:2494]
-Sat Sep 24 08:29:36 2005 Minero Aoki <aamine@loveruby.net>
+Sat Sep 24 08:38:07 2005 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb: fix visibility of FileUtils::NoWrite, Verbose,
- DryRun. [ruby-core:05954]
+ DryRun (backported from trunk, rev 1.66). [ruby-core:05954]
* test/fileutils/test_nowrite.rb: test it.
@@ -6504,163 +6634,32 @@ Sat Sep 24 08:29:36 2005 Minero Aoki <aamine@loveruby.net>
* test/fileutils/test_verbose.rb: new file.
-Sat Sep 24 07:59:01 2005 Minero Aoki <aamine@loveruby.net>
-
- * sample/ripper/colorize.rb: removed (replaced by ruby2html.rb).
-
- * sample/ripper/ruby2html.rb: added.
-
-Sat Sep 24 06:35:15 2005 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper: no longer generates .rb files.
-
- * parse.y (Init_ripper): ripper_init_eventids*() takes 1 argument,
- self (class Ripper).
-
- * ext/ripper/depend: target removed: `lib/ripper/core.rb'.
-
- * ext/ripper/depend: new target `eventids2table.c'.
-
- * ext/ripper/depend: new target `check'.
-
- * ext/ripper/eventids2.c: include eventids2table.c.
-
- * ext/ripper/eventids2.c: initialize SCANNER_EVENT_TABLE.
-
- * ext/ripper/extconf.rb: update $cleanfiles list.
-
- * ext/ripper/tools/generate.rb: no longer generate ripper/core.rb.
-
- * ext/ripper/tools/generate.rb: new mode `check'.
-
- * ext/ripper/tools/generate.rb: new mode `eventids2table'.
-
- * ext/ripper/lib/ripper/core.rb.in: removed.
-
- * ext/ripper/lib/ripper/core.rb: added.
-
- * ext/ripper/lib/ripper/filter.rb: update copyright year.
-
- * ext/ripper/lib/ripper/lexer.rb: ditto.
-
- * ext/ripper/lib/ripper/sexp.rb: ditto.
-
Sat Sep 24 02:40:20 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/delegate.rb: document update from James Edward Gray II
<james@grayproductions.net>. [ruby-core:05942]
-Sat Sep 24 02:05:51 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * process.c (proc_daemon): should restrict execution on levels
- higher than $SAFE=2. suggested by URABE Shyouhei
- <shyouhei@ice.uec.ac.jp>.
-
-Fri Sep 23 20:10:35 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/ripper/tools/generate.rb, ext/ripper/tools/preproc.rb: StringIO
- is not available for miniruby. fixed: [ruby-dev:27307]
-
-Fri Sep 23 17:36:48 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c: avoid core dump with WIN32OLE_EVENT.
- [ruby-dev:27133]
-
-Fri Sep 23 16:27:39 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/forwardable.rb: replaced by new implementation from
- <Daniel.Berger@qwest.com>. [ruby-core:05899]
-
-Fri Sep 23 07:07:47 2005 Minero Aoki <aamine@loveruby.net>
-
- * test/ripper/depend: use --output option instead of redirect;
- nmake does not remove a target when the target file is created by
- redirect. [ruby-dev:26466]
-
- * test/ripper/tools/preproc.rb: new option --output.
-
-Fri Sep 23 06:57:52 2005 Minero Aoki <aamine@loveruby.net>
-
- * test/ripper/tools/generate.rb: check parser event arity.
-
- * test/ripper/tools/generate.rb: detect crash of parser-event-IDs
- and scanner-event-IDs.
-
-Fri Sep 23 06:01:30 2005 Minero Aoki <aamine@loveruby.net>
-
- * test/ruby/test_file.rb: check File#chown(nil,nil).
- [ruby-dev:27140]
-
-Fri Sep 23 05:57:23 2005 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper: refactoring code generation tools. [ruby-dev:27247]
- [ruby-dev:27273]
-
- * ext/ripper/depend: use generate.rb.
-
- * ext/ripper/lib/ripper/core.rb: removed.
-
- * ext/ripper/tools/generate-eventids1.rb: removed (code moved to
- generate.rb).
-
- * ext/ripper/tools/generate-ripper_rb.rb: removed (code moved to
- generate.rb).
-
- * ext/ripper/tools/list-parse-event-ids.rb: removed (code moved to
- generate.rb).
-
- * ext/ripper/tools/list-scan-event-ids.rb: removed (code moved to
- generate.rb).
-
- * ext/ripper/lib/ripper/core.rb: removed.
-
- * ext/ripper: refactoring tests. [ruby-dev:27273]
-
- * ext/ripper/test/check-event-arity.rb: removed (code moved to
- tools/generate.rb).
-
- * ext/ripper/test/check-event-coverage.rb: removed (code moved to
- test/ripper/test_parser_events.rb).
-
- * ext/ripper/test/check-scanner-event-coverage.rb: removed (code
- moved to test/ripper/test_scanner_events.rb).
-
- * ext/ripper/test/list-called-events.rb: removed.
-
- * ext/ripper/test/src_rb: removed.
-
- * ext/ripper/test/validate.rb: removed.
-
- * test/ripper/test_scanner_events.rb: check event coverage.
-
- * ext/ripper/lib/ripper/core.rb.in: update copyright year.
-
-Thu Sep 22 23:40:19 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Sep 22 23:36:24 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (find_executable0): default path if environment is not
set. [ruby-dev:27281]
- * ext/ripper/extconf.rb (have_command): replaced with find_executable.
-
-Thu Sep 22 17:31:48 2005 Shugo Maeda <shugo@ruby-lang.org>
+Thu Sep 22 16:33:12 2005 Shugo Maeda <shugo@ruby-lang.org>
* test/readline/test_readline.rb (TestReadline::replace_stdio):
merged the patch of [ruby-dev:25232] instead of [ruby-dev:25223].
- (merged from ruby_1_8 branch)
Wed Sep 21 23:30:44 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (configuration): generalized nmake dependent code.
-Wed Sep 21 14:16:30 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/ripper/depend (SUFFIXES): no longer needed.
+Wed Sep 21 09:07:55 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/ripper/depend (c): avoid nmake problem. fixed [ruby-dev:27191]
+ * stable version 1.8.3 released.
Wed Sep 21 08:52:25 2005 why the lucky stiff <why@ruby-lang.org>
- * ext/syck/token.c: correctly compute indentation of a block
+ * ext/syck/token.c: correctly compute identation of a block
scalar's parent node. [ruby-talk:150620]
Wed Sep 21 08:20:24 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -6677,18 +6676,19 @@ Wed Sep 21 02:44:09 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* file.c (path_check_0): disallow sticky world writable directory
in PATH (and $LOAD_PATH). [ruby-dev:27226]
-Wed Sep 21 00:32:22 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * file.c (fpath_check): typo fixed.
+
+Tue Sep 20 22:29:49 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
- * numeric.c (fix_idiv): 1.div(1.0) should return integer value.
- [ruby-dev:27235]
+ * test/wsdl/simpletype/rpc/test_rpc.rb, test/wsdl/ref/test_ref.rb,
+ test/wsdl/any/test_any.rb test/soap/wsdlDriver/test_calc.rb:
+ suppress deliberate warnings with $VERBOSE = nil.
-Tue Sep 20 22:25:43 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Sep 20 21:26:23 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/io/wait/lib/nonblock.rb: disable on platforms non-blocking flag
is not available. fixed: [ruby-dev:27187]
- * file.c (rb_stat_inspect): protoized function pointer.
-
Tue Sep 20 18:23:04 2005 Tanaka Akira <akr@m17n.org>
* eval.c (thread_mark): mark th->last_status. [ruby-dev:27179]
@@ -6708,23 +6708,28 @@ Tue Sep 20 17:48:34 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/xmlrpc/server.rb (WEBrickServlet::service): ditto.
-Tue Sep 20 17:26:42 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Sep 20 17:34:46 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* test/webrick/test_cgi.rb: set ENV["PATH"] to CGIEnvPath on
windows. bcc32's runtime is not installed into system directory,
so it cannot be found without this setting. [ruby-dev:27166]
-Tue Sep 20 17:14:10 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * io.c: PIPE_BUF is not defined on BeOS. use _POSIX_PIPE_BUF instead.
- [ruby-dev:27185]
-
Tue Sep 20 17:10:38 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* test/dbm/test_dbm.rb (TestDBM::test_s_open_error): remove
test_s_open_error test to detect duplicate open.
[ruby-dev:27202]
+Tue Sep 20 17:08:31 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * io.c: PIPE_BUF is not defined on BeOS. use _POSIX_PIPE_BUF instead.
+ [ruby-dev:27185]
+
+Tue Sep 20 16:53:53 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * test/readline/test_readline.rb (TestReadline::replace_stdio):
+ BSD seek support from [ruby-dev:25223]. fixed: [ruby-dev:27150]
+
Tue Sep 20 15:39:40 2005 why the lucky stiff <why@ruby-lang.org>
* ext/syck/emitter.c (syck_scan_scalar): prevent indicators from
@@ -6741,57 +6746,49 @@ Tue Sep 20 15:39:40 2005 why the lucky stiff <why@ruby-lang.org>
* ext/syck/rubyext.c: loading of binary-typed nodes. prevent
emission of plain strings that look like symbols, but which aren't.
-Tue Sep 20 05:48:26 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Sep 20 05:50:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* test/xmlrpc/test_webrick_server.rb (setup_http_server):
should not include 'webrick/https' unless 'use_ssl' because
it fails where openssl is not installed.
-Tue Sep 20 01:24:45 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (splat_value): use to_a to splat non Array object.
-
- * object.c (nil_to_a): remove nil.to_a. [experimental]
-
-Tue Sep 20 01:01:41 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/mathn.rb (Fixnum): remove debug print.
-
- * lib/rational.rb (Rational): ditto.
-
Tue Sep 20 00:34:07 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_close): call rb_io_close() directly if io is a T_FILE
object. [ruby-dev:27156]
-Mon Sep 19 18:58:10 2005 Minero Aoki <aamine@loveruby.net>
+Mon Sep 19 19:09:08 2005 Minero Aoki <aamine@loveruby.net>
* file.c (rb_file_chown): should accept nil. [ruby-dev:27171]
+ (backport from trunk, rev 1.208)
-Mon Sep 19 18:29:54 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Sep 19 18:35:13 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * file.c (file_expand_path): allow pathnames to expand.
- [ruby-dev:27152]
+ * ext/dl/dl.c (rb_io_to_ptr): fix DragonFlyBSD support.
+ [ruby-dev:27151]
-Mon Sep 19 15:12:15 2005 Minero Aoki <aamine@loveruby.net>
+Mon Sep 19 14:17:04 2005 Minero Aoki <aamine@loveruby.net>
- * ext/ripper/depend: do not make ripper/core.rb. [ruby-dev:26462]
+ * ext/syck/emitter.c (syck_emit): passing an int* value to the
+ long* parameter causes unaligned access on LP64 systems.
+ [ruby-dev:27161]
-Mon Sep 19 14:49:19 2005 Minero Aoki <aamine@loveruby.net>
+Mon Sep 19 13:44:03 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * ext/ripper/eventids2.c: add prefix `t' to tLAMBDA-related lexer
- events.
+ * ext/win32ole/win32ole.c: avoid core dump with WIN32OLE_EVENT.
+ [ruby-dev:27133]
- * ext/ripper/lib/ripper/core.rb: updated.
+Mon Sep 19 10:36:06 2005 Minero Aoki <aamine@loveruby.net>
-Mon Sep 19 14:39:46 2005 Minero Aoki <aamine@loveruby.net>
+ * lib/fileutils.rb (cp_r): default is :dereference_root=>true for
+ backward compatibility. [ruby-dev:27145]
- * parse.y (do_block): do_block event dispatches 2 args.
- [ruby-dev:26964]
+ * test/fileutils/test_fileutils.rb (test_cp_r): test it.
- * ext/ripper/lib/ripper/core.rb: updated.
+Mon Sep 19 09:57:39 2005 Minero Aoki <aamine@loveruby.net>
- * ext/ripper/tools/list-parser-event-ids.rb: check arity mismatch.
+ * test/fileutils/test_fileutils.rb: backported from trunk (1.36).
+ (again) [ruby-dev:27145]
Mon Sep 19 07:45:37 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
@@ -6803,23 +6800,43 @@ Mon Sep 19 07:45:37 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_engine.c: (ossl_engine_load_privkey): set private
key flag.
- * test/openssl/test_pkey_rsa.rb: add test about private detection.
+Mon Sep 19 06:41:32 2005 Minero Aoki <aamine@loveruby.net>
-Mon Sep 19 06:38:03 2005 Minero Aoki <aamine@loveruby.net>
+ * lib/fileutils.rb: backported from trunk (rev 1.65):
- * lib/fileutils.rb: method renaming: collect_methods ->
- collect_method.
+ * lib/fileutils.rb (rm_r): new option :secure.
-Mon Sep 19 05:58:59 2005 Minero Aoki <aamine@loveruby.net>
+ * lib/fileutils.rb (rm_rf): new option :secure.
- * lib/fileutils.rb: use module_function instead of single extend.
+ * lib/fileutils.rb: new method #remove_entry_secure.
- * test/fileutils/test_fileutils.rb: test existence of singleton
- methods.
+ * lib/fileutils.rb (cd): remove option :noop.
-Mon Sep 19 05:32:41 2005 Minero Aoki <aamine@loveruby.net>
+ * lib/fileutils.rb (cp_r): new option :dereference_root.
+
+ * lib/fileutils.rb (cp_r): new option :dereference_root.
+
+ * lib/fileutils.rb: new method #remove_entry.
+
+ * lib/fileutils.rb: new method #chmod_R.
+
+ * lib/fileutils.rb: new method #chown.
+
+ * lib/fileutils.rb: new method #chown_R.
- * lib/fileutils.rb (remove_entry_secure): does not use chdir(2).
+ * lib/fileutils.rb: new method .commands.
+
+ * lib/fileutils.rb: new method .options.
+
+ * lib/fileutils.rb: new method .have_option?.
+
+ * lib/fileutils.rb: new method .options_of.
+
+ * lib/fileutils.rb: new method .collect_method.
+
+ * lib/fileutils.rb: use module_function instead of single extend.
+
+ * test/fileutils/test_fileutils.rb: backported from trunk (1.36).
Mon Sep 19 03:17:48 2005 Tanaka Akira <akr@m17n.org>
@@ -6831,24 +6848,13 @@ Mon Sep 19 03:17:48 2005 Tanaka Akira <akr@m17n.org>
which is full. [ruby-dev:27132]
* io.c (rb_io_syswrite): wrap the write system call by
- TRAP_BEG/TRAP_END to run signal hander in syswrite method.
- [ruby-dev:27134]
-
-Mon Sep 19 01:07:38 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * numeric.c (Init_Numeric): should define Fixnum#div.
- [ruby-dev:27129]
+ TRAP_BEG/TRAP_END to enable signals when writing to a pipe which is
+ full. [ruby-dev:27134]
- * file.c (rb_thread_flock): wrap flock(2) by TRAP_BEG and
- TRAP_END. [ruby-dev:27122]
+Mon Sep 19 03:02:08 2005 Tanaka Akira <akr@m17n.org>
- * file.c (rb_file_join): call FilePathValue() to all Pathnames to
- join. [ruby-dev:27127]
-
- * file.c (rb_get_path): call StringValueCStr() to ensure no nul
- bytes in path strings.
-
- * gc.c (garbage_collect): need value for return. [ruby-dev:27127]
+ * io.c (io_fwrite): wrap the write system call by TRAP_BEG/TRAP_END to
+ enable signals when writing to a pipe which is full.
Sun Sep 18 02:10:47 2005 why the lucky stiff <why@ruby-lang.org>
@@ -6866,10 +6872,6 @@ Sun Sep 18 02:10:47 2005 why the lucky stiff <why@ruby-lang.org>
* test/yaml/test_yaml.rb: remove outdated tests.
-Sun Sep 18 01:10:37 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (garbage_collect): return false if no GC run.
-
Sat Sep 17 23:25:04 2005 sheepman <sheepman@sheepman.sakura.ne.jp>
* lib/mathn.rb (Rational::inspect): should preserve original
@@ -6880,79 +6882,6 @@ Sat Sep 17 23:20:27 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/cgi.rb (CGI::Cookie): should handle multiple values for a
cookie name. [ruby-talk:156140]
- * test/socket/test_tcp.rb (TestTCPSocket::test_recvfrom): typo
- fixed. [ruby-dev:27123]
-
-Sat Sep 17 20:58:56 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * win32/win32.c (rb_w32_select): fixed deadlock bug.
- because select(2) modifies its fd_set arguments, it must be
- restored sometimes.
-
- * win32/win32.c (rb_w32_select): performance improvement when
- 'always readable/writable handles' and sockets are passed.
- sockets should be polled every time.
-
- require "net/http"
-
- Thread.new {
- loop do
- STDOUT.write(".") # busy on console (this is worst case though)
- end
- }
-
- # socket operation took long time. (sometimes timed out)
- Net::HTTP.start("www.ruby-lang.org") do |http|
- http.get("/cgi-bin/cvsweb.cgi/ruby/array.c?rev=1.179")
- end
-
-Sat Sep 17 14:54:40 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * test/ruby/test_readpartial.rb (test_open_pipe, test_with_stdio):
- these tests are working now, so turned on. (windows)
-
-Sat Sep 17 14:18:15 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * win32/win32.c (rb_w32_select): I hope performance problem was
- solved.
-
-Sat Sep 17 13:45:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * win32/win32.c (rb_w32_select): console support is back.
- but still has performance problem because I loosely took 1 second
- for wait time. I'll fix it later. (The reason I drastically changed
- the code is that I wanted to implement the fileset management as
- single function, and I was worried that if pipe or console
- was always available, socket may not be processed any time)
-
-Sat Sep 17 11:24:16 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * win32/win32.c (rb_w32_select): select for socket didn't work.
- this caused deadlock in drb test. this happened because GetFileType
- for socket handle returns FILE_TYPE_PIPE. Of course, it's not a
- pipe. So socket handle didn't reach winsock's select function.
-
- * win32/win32.c (rb_w32_select): read for pipe was still blocked
- even if writer handle was closed.
-
- r,w = IO.pipe
-
- Thread.new {
- sleep 3; puts "------- 1"
- w.puts("foo")
- sleep 3; puts "------- 2"
- w.puts("boo")
- sleep 3; puts "------- 3"
- w.close
- }
-
- until r.eof? # should break by w.close but didn't.
- puts r.gets
- end
-
- * win32/win32.c (rb_w32_select): temporary reverted console support
- but it'll be back soon.
-
Sat Sep 17 10:42:13 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: MultiTkIp#eval_string and bg_eval_string
@@ -6971,19 +6900,19 @@ 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.
-Sat Sep 17 08:02:53 2005 Shugo Maeda <shugo@ruby-lang.org>
+Fri Sep 16 23:09:20 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * lib/net/imap.rb: supported DIGEST-MD5. Thanks, Mathieu Arnold.
+ * ext/win32ole/win32ole.c (ole_search_event_at): bug fix
+ in ext/win32ole/sample/ienavi.rb.
- * lib/net/imap.rb: use fcall instead of send. Thanks, Satoru
- Takabayashi.
+ * ext/win32ole/win32ole/tests/testOLEEVENT.rb: ditto.
-Fri Sep 16 22:45:49 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Sep 16 22:41:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_s_extname): empty string for path name ending with a
period. fixed: [ruby-core:05651]
@@ -6991,19 +6920,6 @@ Fri Sep 16 22:45:49 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_join): smarter behavior at edge cases.
fixed: [ruby-core:05706]
- * gc.c (rb_memerror, ruby_xmalloc, ruby_xrealloc, rb_newobj): just
- abondon if no memory available, when interpreter is not running.
- [ruby-dev:27104]
-
- * gc.c (garbage_collect): return whether GC could run.
-
- * dir.c (rb_push_glob): fix delimiter bug. fixed: [ruby-dev:27105]
-
- * dir.c (dir_s_aref, dir_s_glob): allow multiple patterns.
- [ruby-dev:27110]
-
- * win32/win32.c (cmdglob): enable brace expansion.
-
Fri Sep 16 18:34:01 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/syck/node.c (syck_replace_str): was using return from the
@@ -7019,12 +6935,12 @@ Fri Sep 16 12:02:12 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/syck/rubyext.c (syck_resolver_transfer): remove C++ style
comment (//). [ruby-core:05793]
-Fri Sep 16 00:17:03 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Fri Sep 16 00:14:14 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/logger/test_logger.rb: unintentionally overwritten changes by
Usa. reverted.
-Fri Sep 16 00:03:11 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Fri Sep 16 00:06:18 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/cgi.rb (WEBrick::CGI::Socket#initialize): should set
$stdout.binmode.
@@ -7038,10 +6954,10 @@ Thu Sep 15 23:25:21 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* SOAP
* allow to configure an envelope namespace of SOAP request. (#124)
- TemporaryNamespace = 'http://www.w3.org/2003/05/soap-envelope'
- @client.options["soap.envelope.requestnamespace"] =
+ TemporaryNamespace = 'http://www.w3.org/2003/05/soap-envelope'
+ @client.options["soap.envelope.requestnamespace"] =
TemporaryNamespace
- @client.options["soap.envelope.responsenamespace"] =
+ @client.options["soap.envelope.responsenamespace"] =
TemporaryNamespace
@client.do_proc(...)
@@ -7113,62 +7029,45 @@ Thu Sep 15 23:25:21 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* updated deprecated method usage. (#138)
-Thu Sep 15 22:40:27 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Sep 15 23:02:57 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * test/ruby/test_signal.rb (test_exit_action): skip the test using
- fork on fork-less platforms.
+ * win32/win32.h (rb_w32_stat): added prototype.
-Thu Sep 15 13:54:33 2005 Tanaka Akira <akr@m17n.org>
+Thu Sep 15 22:35:55 2005 NAKAMURA Usaku <usa@ruby-lang.org>
- * lib/open-uri.rb: add :read_timeout option.
- [ruby-core:4848]
+ * test/ruby/test_signal.rb (test_exit_action): skip the test using
+ fork on fork-less platforms.
Thu Sep 15 11:39:18 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/dialog.rb: If a dialog does not show up yet,
TkDialogObj#name raises an exception. [ruby-talk:156109]
-Thu Sep 15 11:01:58 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Sep 15 01:39:19 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * win32/win32.c (rb_w32_pipe_exec): remove unnecessary CloseHandle().
-
- * win32/win32.c (extract_console_fd, peek_console): new functions.
-
- * win32/win32.c (rb_w32_select): check consoles by polling them.
+ * lib/rinda/tuplespace.rb (Rinda::TemplateEntry::initialize): pull
+ up method. Tabs converted to spaces.
Thu Sep 15 00:18:24 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/net/telnet.rb (Net::Telnet::waitfor): replace sysread with
readpartial. [ruby-talk:127641]
-Wed Sep 14 23:28:28 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (collect_file_fd): rename from extract_file_fd.
-
- * win32/win32.c (extract_pipe_fd, peek_pipe): new functions.
-
- * win32/win32.c (rb_w32_select): check pipes by polling them.
-
Wed Sep 14 22:40:26 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dir.c (ruby_glob): glob function not using ruby exception system.
-Wed Sep 14 17:24:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c: changed `foo (*bar)_((boo))' to `foo (*bar)(boo)`.
+Wed Sep 14 01:26:03 2005 Minero Aoki <aamine@loveruby.net>
- * enumerator.c, eval.c, gc.c, intern.h, io.c, process.c, ruby.c,
- ruby.h, signal.c: ditto.
+ * lib/net/https.rb: backported from trunk, rev 1.3.
+ [ruby-dev:25673] (again), [ruby-dev:26617] (again),
+ [ruby-dev:27062]
-Wed Sep 14 15:06:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * ext/openssl/lib/net/https.rb: removed.
- * bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
+ * ext/openssl/lib/net/protocols.rb: removed.
- * defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
- gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
- node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
- rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
- util.c, util.h, variable.c: ditto.
+ * lib/net/http.rb: #use_ssl?, #use_ssl are moved from net/https.
Tue Sep 13 22:09:40 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
@@ -7189,20 +7088,19 @@ Tue Sep 13 21:47:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (BEGIN_CALLARGS): pop halfly pushed status.
fixed: [ruby-dev:26881]
-Tue Sep 13 20:24:37 2005 Tanaka Akira <akr@m17n.org>
+Tue Sep 13 16:26:45 2005 Minero Aoki <aamine@loveruby.net>
- * ruby.h (PRINTF_ARGS): new macro for printf style argument checking.
+ * lib/net/http.rb: backported from trunk, rev 1.128.
+ [ruby-dev:25673] [ruby-dev:26617]
-Tue Sep 13 15:41:29 2005 Minero Aoki <aamine@loveruby.net>
+ * lib/net/protocol.rb: backported from trunk, rev 1.78.
- * lib/net/http.rb: wrote docuemntation of HTTPRequest/HTTPResponse
- classes.
+ * lib/net/protocol.rb: new method #old_open to support net/smtp
+ and net/pop.
-Tue Sep 13 14:27:47 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * lib/net/smtp.rb: use #old_open.
- * string.c, missing.h: failed to build on powerpc-apple-darwin7.9.0
- because of crypt argument's constness mismatch. (I hope this works)
- (http://mput.dip.jp/autobuild/ruby-trunk/log/20050913T110001.gz)
+ * lib/net/pop.rb: ditto.
Tue Sep 13 12:33:05 2005 why the lucky stiff <why@ruby-lang.org>
@@ -7218,12 +7116,12 @@ Tue Sep 13 12:33:05 2005 why the lucky stiff <why@ruby-lang.org>
continue support of Object#to_yaml_type.
* ext/syck/rubyext.c: new emitter code. yaml_new and yaml_initialize
- get called, should they be present. consolidated all the diaspora of internal node types into the family below YAML::Syck::Node -- Map,
+ get called, should they be present. consolidated all the diaspora of internal
+ node types into the family below YAML::Syck::Node -- Map,
Seq, Scalar -- all of whom are SyckNode structs pointing to
- Ruby data. moved Object#yaml_new into the node_import and made it
- the default behavior. the target_class is always called wih
- yaml_new, prepended a parameter, which is the klass. loaded nodes
- through GenericResolver show their style.
+ Ruby data. moved Object#yaml_new into the node_import and made it the
+ default behavior. the target_class is always called wih yaml_new, prepended
+ a parameter, which is the klass. loaded nodes through GenericResolver show their style.
new Resolver#tagurize converts type ids to taguris.
* ext/syck/implicit.re: were 'y' and 'n' seriously omitted??
@@ -7242,28 +7140,6 @@ Tue Sep 13 12:33:05 2005 why the lucky stiff <why@ruby-lang.org>
* ext/syck/syck.h: reflect block_styles and new node functions.
-Tue Sep 13 08:09:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/ostruct.rb (new_ostruct_member): Object#send no longer call
- private methods. [ruby-dev:27044]
-
- * test/rss/test_dublincore.rb, test/rss/test_trackback.rb,
- test/ruby/test_eval.rb, test/socket/test_socket.rb: ditto.
-
- * test/ruby/test_lambda (test_call_with_block): lambda makes new scope
- for formal block parameter.
-
-Tue Sep 13 01:17:45 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (proc_save_safe_level): no need to restrict safe level
- memoize in $SAFE>=3. [ruby-dev:27050]
-
-Tue Sep 13 00:02:33 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (apply2files): stricter callback definition.
-
- * file.c (rb_path_check): constified.
-
Mon Sep 12 20:53:06 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* test/openssl/test_pkcs7.rb (test_enveloped): skip this test
@@ -7271,83 +7147,29 @@ Mon Sep 12 20:53:06 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
compiled with OpenSSL-0.9.7d or earlier versions).
http://www.mail-archive.com/openssl-dev@openssl.org/msg17376.html
-Mon Sep 12 20:32:00 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * win32/win32.[hc] (rb_w32_argv_size, ...): reverted my latest change
- to avoid incompatible pointer warning. (mingw32)
-
-Mon Sep 12 19:58:53 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dln.c: avoid warning of const to non-const convertion.
- [ruby-dev:27041]
-
- * eval.c, io.c, ruby.c: ditto.
-
-Mon Sep 12 19:26:29 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * array.c: moved to ANSI function style from K&R function style.
- (used protoize on windows, so still K&R remains on #ifdef part of
- other platforms. And `foo _((boo))' stuff is still there)
- [ruby-dev:26975]
-
- * bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
- enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
- io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
- prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
- regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
- sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
- version.c: ditto.
-
Mon Sep 12 14:03:33 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* test/dbm/test_dbm.rb: remove locking test, which may not be
supported on some platforms. [ruby-dev:27030]
-Sun Sep 11 23:23:02 2005 Shugo Maeda <shugo@ruby-lang.org>
+Mon Sep 12 10:45:58 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/net/imap.rb (starttls): supported the STARTTLS command.
+ * ext/dl/dl.c (rb_io_to_ptr): merged a patch for DragonFly BSD
+ from Takahiro Kambe <taca at back-street.net>. [ruby-dev:27023]
-Sun Sep 11 22:18:07 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sun Sep 11 22:05:51 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* bin/erb (ERB::Main#run): set ERB#filename so that it is used
when reporting syntax/runtime errors. Tabs converted to spaces.
-Sat Sep 10 22:34:19 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c, bignum.c: protoize.
-
-Sat Sep 10 00:23:01 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (splat_value): simpler and consistent array conversion
- for argument splat. [yarv-dev:599]
-
-Fri Sep 9 16:45:25 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * string.c (rb_str_times): make empty strings to keep taintness,
- and a little improvement. [ruby-dev:26900]
-
- * ext/iconv/iconv.c (iconv_try), ext/iconv/extconf.rb: get rid of meta
- characters in command line option. fixed: [ruby-talk:155369]
-
- * ext/iconv/iconv.c: protoized.
-
-Thu Sep 8 14:58:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * merged a patch from Takahiro Kambe <taca at back-street.net> to
- support DragonFly BSD. [ruby-dev:26984]
-
-Thu Sep 8 13:14:57 2005 Tadashi Saito <shiba@mail2.accsnet.ne.jp>
-
- * missing/strchr.c (strrchr): fixed a bug in detecting NUL in a
- string. [ruby-dev:26985]
-
-Wed Sep 7 17:29:27 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Sat Sep 10 10:17:03 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_engine.c (ossl_engine_s_by_id):
OpenSSL::Engine.by_id calls given block before calling
ENGINE_init (block parameter is the return value of this method
itself). this functionality is useful to load dynamic shared
- engines.
+ engines. the following code is a sample of loading a key using
+ OpenSC PKCS #11 module.
require "openssl"
pkcs11 = OpenSSL::Engine.by_id("dynamic"){|e|
@@ -7364,7 +7186,7 @@ Wed Sep 7 17:29:27 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_engine.c (ossl_engine_get_cmds): new method
OpenSSL::Engine#cmds. it returms engine command definitions.
-Wed Sep 7 15:48:37 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Sat Sep 10 10:09:47 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_asn1.c (asn1str_to_str): new function.
@@ -7377,6 +7199,64 @@ Wed Sep 7 15:48:37 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* test/openssl/test_pkcs7.rb: new file.
+Sat Sep 10 10:05:51 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * ext/openssl/ossl_ns_spki.c (ossl_spki_initialize): assume that
+ the argument is a DER string if Base64 decoding failed.
+
+ * ext/openssl/ossl_ns_pki.c (ossl_spki_to_der): new method.
+
+ * test/openssl/test_ns_spki.rb: add new file.
+
+Sat Sep 10 09:56:24 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * ext/openssl/lib/digest.rb: added SHA224, SHA256, SHA384 and SHA512.
+ these features are enabled if this library is compiled with
+ OpenSSL 0.9.8 or later.
+
+ * test/openssl/test_digest.rb: add test for new digests.
+
+Sat Sep 10 09:51:30 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * ext/openssl/ossl.c (ossl_raise): should use ERR_peek_last_error
+ to get last error on the current thread. And should report
+ errors on the stack while OpenSSL.debug is true.
+
+ * ext/openssl/ossl.c (ossl_get_errors): new method for debugging
+ this library.
+
+ * ext/openssl/ossl_ssl.c (ossl_sslctx_set_ciphers): fix error message.
+
+ * ext/openssl/ossl_x509req.c (ossl_x509req_set_attributes): get rid
+ of unused variable.
+
+ * ext/openssl/ossl_x509store.c (ossl_x509store_initialize): should
+ set @time to avoid warning.
+
+ * ext/openssl/ossl_x509store.c (ossl_x509store_set_default_paths,
+ X509_STORE_add_cert, X509_STORE_add_crl): should raise error if
+ wrapped functions failed.
+
+ * test/openssl/test_x509store.rb: add test for errors.
+
+Fri Sep 9 22:13:19 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (rb_call0): prohibit calling tainted method (>2) when
+ $SAFE == 0.
+
+Fri Sep 9 16:45:25 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (rb_str_times): make empty strings to keep taintness,
+ and a little improvement. [ruby-dev:26900]
+
+ * ext/iconv/iconv.c (iconv_try), ext/iconv/extconf.rb: get rid of meta
+ characters in command line option. fixed: [ruby-talk:155369]
+
+Thu Sep 8 14:58:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * merged a patch from Takahiro Kambe <taca at back-street.net> to
+ support DragonFly BSD. [ruby-dev:26984]
+
Wed Sep 7 12:55:08 2005 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb: abolish mod === tempfile to avoid a problem
@@ -7390,15 +7270,6 @@ Wed Sep 7 10:45:15 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_thread_terminated): show backtrace before propagate
exceptions to main thread.
-Wed Sep 7 09:21:41 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * win32/win32.[hc] (rb_w32_utime): constified.
-
- * win32/win32.h (rb_w32_stat): added prototype.
-
- * win32/win32.[hc] (rb_w32_argv_size,rb_w32_join_argv,rb_w32_aspawn):
- changed `char *const *' to `const char *const *'. (constify string)
-
Wed Sep 7 08:35:04 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* Makefile.in, configure.in (MINIOBJS): miniruby on HP-UX can not load
@@ -7417,62 +7288,37 @@ Wed Sep 7 08:35:04 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/etc/etc.c (setup_passwd), ext/etc/extconf.rb: pw_age might be
char*. fixed: [ruby-core:05470]
-Wed Sep 7 08:32:07 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * string.c (rb_str_times): should taint empty strings as well.
-
- * object.c (Init_Object): make class_variable_{get,set} public.
- [ruby-dev:26965]
-
-Mon Sep 5 22:28:46 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Sep 7 08:32:47 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * parse.y (stmt, mlhs_node, lhs, arg, method_call): aref_args might be
- nothing. fixed: [ruby-dev:26952]
+ * object.c (rb_mod_cvar_get, rb_mod_cvar_set): document fix from
+ sheepman <sheepman@sheepman.sakura.ne.jp>; a bug in visibility
+ description. [ruby-dev:26965]
- * ext/ripper/eventids2.c: added new tokens. fixed: [ruby-dev:26952]
+ * sprintf.c (rb_f_sprintf): warn "too many argument" on verbose
+ mode (-v/-w); backported from 1.9. [ruby-dev:26963]
Mon Sep 5 17:03:07 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/find.rb: should raise ENOENT if root entry does not exist.
- [ruby-list:41054]
-
* lib/ostruct.rb: a patch from Florian Gross <florgro at gmail.com>
merged to allow recursive inspect (and to_s) for OpenStruct.
[ruby-core:05532]
-Mon Sep 5 08:20:19 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/observer.rb: a patch from nornagon <nornagon at gmail.com>
- merged to allow arbitrary names for update methods.
- [ruby-core:05416]
-
Mon Sep 5 07:01:12 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/openssl/lib/openssl/buffering.rb (Buffering#do_write):
should clear data from the buffer which already been output.
-Sun Sep 4 15:01:35 2005 Minero Aoki <aamine@loveruby.net>
-
- * parse.y (f_arg): Ripper should not do semantic check.
- [ruby-dev:26948]
-
-Sat Sep 3 23:52:35 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_f_fcall): new method to avoid inefficiency of
- obj.instance_eval{send(...)} tricks.
-
-Sat Sep 3 13:59:31 2005 Tanaka Akira <akr@m17n.org>
+Fri Sep 2 23:51:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/pathname.rb (Pathname#descend): Pathname.new("./a/b/c").descend
- didn't yield "."
- (Pathname#ascend): ditto.
+ * lib: do not use __send__ to access private methods. [ruby-dev:26935]
-Fri Sep 2 23:51:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Sep 2 03:29:00 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
- * parse.y (f_arg): f_norm_arg is a VALUE in ripper, not an ID.
- fixed: [ruby-dev:26942]
+ * lib/irb/init.rb: make IRB -I option that is same befavior for ruby.
+ [ruby-dev:26872], [ruby-dev: 26920]
- * lib: do not use __send__ to access private methods. [ruby-dev:26935]
+ * lib/irb/locale.rb: support to print help message when OS locale is
+ ja_JP.utf-8. [ruby-dev:26872]
Thu Sep 1 17:11:25 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -7487,31 +7333,20 @@ Thu Sep 1 14:12:45 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
to support '-namespace' option of 'interp invokehidden' command
on Tcl8.5.
-Wed Aug 31 14:41:30 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Aug 31 14:43:15 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/Makefile.sub (OPTFLAGS): default global optimization to
disabled for all VC++ versions. fixed: [ruby-dev:26897]
-Wed Aug 31 10:36:09 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * process.c (proc_detach, proc_setmaxgroups): missing argument type
- declaration. (I recommend ANSI-style function)
-
-Wed Aug 31 06:59:01 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Aug 31 11:35:43 2005 NAKAMURA Usaku <usa@ruby-lang.org>
- * string.c (rb_str_scan): already String#scan behaves differently
- regarding if block is given.
-
-Tue Aug 30 23:49:34 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c, dir.c, enum.c, hash.c, io.c, range.c, string.c, struct.c:
- let enumerable methods return Enumerator. [ruby-dev:26924]
-
- * intern.h (RETURN_ENUMERATOR): utility macro for enumerable methods.
+ * test/gdbm/test_gdbm.rb (teardown): should remove GDBM temporary
+ file.
-Tue Aug 30 23:25:45 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Wed Aug 31 10:30:56 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * lib/debug.rb: no need to restart at exit.
+ * process.c (proc_detach, proc_setmaxgroups): missing argument type
+ declaration. (I recommend ANSI-style function)
Tue Aug 30 23:20:19 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -7530,46 +7365,24 @@ Tue Aug 30 19:34:27 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
ext/digest/sha1/sha1ossl.h: include <stddef.h> to avoid
error in compilation with OpenSSL-0.9.8. [ruby-list:41068]
-Tue Aug 30 16:19:40 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
-
- * lib/irb/init.rb: bug fix. [ruby-dev: 26920]
-
-Tue Aug 30 16:13:00 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * enum.c (enum_count): new method. [ruby-dev:26895]
-
-Tue Aug 30 12:45:15 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_f_send): do not call private methods if the receiver
- is specified. [ruby-talk:153672]
-
-Mon Aug 29 19:47:18 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Aug 29 19:54:21 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/rdoc/usage.rb: improper exceptions. [ruby-dev:26870]
* lib/rdoc/usage.rb: support the case when non-ruby code exists before
shebang. (this is needed when ri.bat is executed on windows)
-Mon Aug 29 18:58:05 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
- * lib/irb/init.rb: make IRB -I option that is same befavior for ruby.
- [ruby-dev:26872]
-
- * lib/irb/locale.rb: support to print help message when OS locale is
- ja_JP.utf-8. [ruby-dev:26872]
-
-Mon Aug 29 01:43:05 2005 Tanaka Akira <akr@m17n.org>
+Mon Aug 29 17:48:17 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/pathname.rb (Pathname#descend): new method.
- (Pathname#ascend): ditto.
+ * eval.c (method_arity): should return proper arity value.
+ [ruby-dev:26390]
-Mon Aug 29 00:35:09 2005 Tanaka Akira <akr@m17n.org>
+Mon Aug 29 01:19:57 2005 Tanaka Akira <akr@m17n.org>
- * lib/time.rb: require 'date/format' instead of 'parsedate'.
- (Time.parse): extract fractional seconds using Date._parse.
- (Time.strptime): extract fractional seconds using Date._strptime.
- [ruby-talk:153859]
+ * lib/time.rb (Time.parse): extract fractional seconds using
+ Date._parse. [ruby-talk:153859]
-Sat Aug 27 20:13:31 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sat Aug 27 20:20:01 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/curses/curses.c ({curses,window}_clrtoeol): added. suggested
by Reyn Vlietstra.
@@ -7579,77 +7392,18 @@ Sat Aug 27 20:13:31 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/curses/view.rb: String =~ String is deprecated.
-Thu Aug 25 15:48:58 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ext/win32ole/win32ole.c: supress warnings. (win32)
-
-Wed Aug 24 11:01:26 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Aug 24 10:53:28 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* test/logger/test_logger.rb (test_shifting_size): should close log
device before unlink, since some platform cannot unlink opened
file.
-Tue Aug 23 06:07:02 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/lib/digest.rb: added SHA224, SHA256, SHA384 and SHA512.
- these features are enabled if this library is compiled with
- OpenSSL 0.9.8 or later.
-
- * test/openssl/test_digest.rb: add test for new digests.
-
-Tue Aug 23 05:47:04 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_ns_spki.c (ossl_spki_initialize): try to decode
- the argument as a string.
-
- * ext/openssl/ossl_ns_pki.c (ossl_spki_to_der): new method.
-
- * ext/openssl/ossl_x509store.c (ossl_x509store_initialize): should
- set @time to avoid warning.
-
- * ext/openssl/ossl_x509store.c (ossl_x509store_set_default_paths,
- X509_STORE_add_cert, X509_STORE_add_crl): should raise error if
- wrapped functions fails.
-
- * ext/openssl/ossl_ssl.c (ossl_sslctx_set_ciphers): fix error message.
-
- * ext/openssl/ossl_x509req.c (ossl_x509req_set_attributes): get rid
- of unused variable.
-
- * test/openssl/test_ns_spki.rb: add new file.
-
- * test/openssl/test_x509store.rb: add test for error.
-
-Tue Aug 23 01:11:40 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * sprintf.c (ruby__sfvwrite): should move `buf' to the end of
- `result'. [ruby-dev:26859]
-
-Mon Aug 22 23:51:19 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y: ONIG_OPTION_CAPTURE_GROUP conflicts with
- RE_OPTION_ONCE. [ruby-dev:26852]
-
-Mon Aug 22 20:11:35 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * missing/vsnprintf.c (BSD__sprint): needs to call vwrite function
- pointer. fixed: [ruby-dev:26854]
-
-Sat Aug 20 23:55:25 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (parser_yylex): update paren_nest for brackets [].
-
-Sun Aug 21 00:10:23 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Sun Aug 21 00:13:27 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/wsdl/xmlSchema/importer.rb (WSDL::XMLSchema::Importer#fetch): add
a workaround for importing an WSDL whose path begins with drive
letter. [ruby-dev:26242]
-Sat Aug 20 22:05:25 2005 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * regexec.c (code_is_in_cclass_node): check code size.
- [ruby-dev:26840]
-
Sat Aug 20 22:37:13 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/logger.rb (write, shift_log?, shift_log): file shifting race
@@ -7662,25 +7416,23 @@ Fri Aug 19 18:13:39 2005 Tanaka Akira <akr@m17n.org>
* lib/time.rb (Time.apply_offset): fix a problem with last day of
month. reported by Lucas Nussbaum. [ruby-talk:152866]
-Thu Aug 18 11:05:36 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Aug 18 12:46:28 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * bcc32/Makefile.sub (COMMON_HEADERS): reverted 1.42.2.24.
+ I misunderstood, bccwin32 on ruby_1_8 uses winsock2 originally.
+ [ruby-dev:26806]
- * win32/win32.c (socketpair_internal): need to call open_ifs_socket()
- to create sockets instead of winsock's socket().
- fixed: [yarv-dev:581]
+ * win32/win32.h: include winsock2.h instead of winsock.h. (bcc32)
Wed Aug 17 23:58:05 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * object.c (rb_to_integer): argument constified.
+
* eval.c (terminate_process): take String message.
* eval.c (rb_thread_switch): propagate the exception caused thread
termination directly. fixed: [ruby-core:05552]
-Wed Aug 17 21:20:05 2005 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf/lib/kconv.rb: ensure that symbol_to_option is private_class_method
- and all other methods are module_function
- fixed: [ruby-dev:26808]
-
Wed Aug 17 00:05:46 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_add_method): preserve safe level in the environment
@@ -7689,46 +7441,12 @@ Wed Aug 17 00:05:46 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_call0): restore preserved safe level in the method
execution.
- * parse.y (lambda): need separate block variable stack
- manipulation and lpar_beg maintenance. based on a patch found
- in [ruby-core:05551] from Mauricio Fernandez <mfp at acm.org>.
-
- * parse.y (parser_yylex): adjust lpar_beg after tLAMBEG and
- kDO_LAMBDA. [ruby-core:05551]
-
-Mon Aug 15 07:24:38 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * intern.h (rb_check_to_integer): add declaration.
-
- * object.c (rb_to_integer, rb_check_to_integer): argument constified.
-
Mon Aug 15 00:38:51 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_rescue2): reduce PUSH_TAG() as well as NODE_RESCUE.
[ruby-dev:26800]
- * range.c (range_check, range_init): reduce uselse exceptions.
-
-Mon Aug 15 00:34:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (yycompile): remove unreachable code. [yarv-dev:570]
-
-Sat Aug 13 22:16:12 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (remove_entry_secure): forgot final chdir.
-
-Sat Aug 13 22:07:49 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (remove_entry_secure): uses chdir(2) and check
- if current directory is correct. [ruby-dev:26100] [ruby-dev:26226]
-
-Sat Aug 13 21:11:05 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c: add WIN32OLE_VARIANT class.
-
- * ext/win32ole/tests/testall.rb: ditto.
-
- * ext/win32ole/tests/testOLEVARIANT.rb: ditto.
+ * range.c (range_check, range_init): reduce useless exceptions.
Sat Aug 13 18:51:26 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -7738,30 +7456,10 @@ Sat Aug 13 18:51:26 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_set_string): disallow nil.
http://www.rubyist.net/~nobu/t/20050811.html#c05
-Sat Aug 13 08:01:59 2005 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf/lib/kconv.rb: Kconv.kconv is now alias of Kconv.conv
- * ext/nkf/lib/kconv.rb: remove nkf dependend symbols fomr SYMBOL_TO_OPTION
-
-Fri Aug 12 17:06:53 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (f_larglist): allow optional arguments even when
- parentheses are omitted. based on Nobu's patch from
- http://www.rubyist.net/~nobu/t/20050805.html
-
- * parse.y (parser_yylex): update & maintain lpar_beg for detect
- lambda parameters.
-
Thu Aug 11 23:29:03 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c: keep holding string after closed.
-Thu Aug 11 20:48:40 2005 Tadashi Saito <shiba@mail2.accsnet.ne.jp>
-
- * numeric.c (fix_equal, fix_cmp, fix_gt, fix_ge, fix_lt, fix_le):
- reduce coercing when a method knows about a operand type.
- [ruby-dev:26789]
-
Thu Aug 11 13:01:48 2005 Kouhei Sutou <kou@cozmixng.org>
* lib/rss: fixed sort bug. [ruby-list:41018]
@@ -7786,33 +7484,6 @@ Thu Aug 11 13:01:48 2005 Kouhei Sutou <kou@cozmixng.org>
(RSS::TestSetupMaker10::test_setup_maker_items_sort): added some
tests for RSS::Maker::ItemsBase#do_sort.
-Wed Aug 10 12:01:20 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/delegate.rb: simplifies Delegator classes; SimpleDelegator
- now uses method_missing for all methods.
-
-Wed Aug 10 10:38:50 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * bignum.c (rb_big_mul0): multiply two numbers (x, y) without
- normalizing the result. x should be a big number.
- [ruby-dev:26778]
-
- * bignum.c (rb_big_pow): use rb_big_mul0() instead of
- rb_big_mul().
-
- * array.c (rb_ary_or, rb_ary_and, rb_ary_plus, rb_ary_diff):
- revert the change on 2005-08-03. Set operation on other item
- should have in separate methods.
-
- * parse.y (shadowing_lvar_gen): warn when arguments shadows
- external local variables.
-
- * parse.y (f_opt): optional arguments should not clobber external
- local variables.
-
- * parse.y (f_rest_arg): rest arguments should not clobber external
- local variables.
-
Wed Aug 10 10:29:40 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: fix bug on handling __ruby2val_optkeys().
@@ -7824,19 +7495,9 @@ Wed Aug 10 10:29:40 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/blt/component.rb: ditto.
-Tue Aug 9 21:53:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (formal_assign): let default values override
- arguments to zsuper. fixed: [ruby-dev:26743]
-
-Tue Aug 9 20:30:19 2005 Tadashi Saito <shiba@mail2.accsnet.ne.jp>
-
- * bignum.c (rb_big_coerce): allow bignum x bignum coercing.
- [ruby-dev:26778]
-
Tue Aug 9 15:12:04 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c: remove dangerous 'rb_jump_tag's.
+ * ext/tcltklib/tcltklib.c: remove dangerous 'rb_jump_tag's.
* ext/tk/lib/tk.rb: add __val2ruby_optkeys and __ruby2val_optkeys to
help to convert option values between ruby and tcl.
@@ -7859,56 +7520,28 @@ Tue Aug 9 15:12:04 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/*: support to treat tkvariable-type
configure options.
-Tue Aug 9 08:24:05 2005 Mauricio Fernandez <mfp@acm.org>
-
- * parse.y (f_block_arg), eval.c (rb_yield_0): deal with dynamic
- variable lambda arguments. [ruby-core:05540]
-
-Mon Aug 8 22:13:48 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (assign): deal with new block argument.
- fixed: [ruby-core:05536]
-
- * eval.c (rb_node_arity): follow change of NODE_ARGS.
- fixed: [ruby-dev:26761]
-
-Mon Aug 8 21:28:13 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Aug 9 20:30:19 2005 Tadashi Saito <shiba@mail2.accsnet.ne.jp>
- * test/ruby/test_fnmatch.rb: separated from test_file.rb.
+ * bignum.c (rb_big_coerce): allow bignum x bignum coercing.
+ [ruby-dev:26778]
-Mon Aug 8 20:40:35 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Mon Aug 8 20:43:02 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/ruby/test_method.rb: added. [ruby-dev:26761]
-Mon Aug 8 01:26:37 2005 Mauricio Fernandez <mfp@acm.org>
-
- * parse.y (f_larglist): mistake in syntax rule. [ruby-core:05535]
-
-Mon Aug 8 05:16:55 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl.c (ossl_raise): should use ERR_peek_last_error
- to get last error on the current thread. And should report
- if errors are on the stack while OpenSSL.debug is true.
-
- * ext/openssl/ossl.c (ossl_get_errors): new method for debugging
- this library.
+Sun Aug 7 23:50:14 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-Mon Aug 8 05:15:19 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+ * test/ruby/test_super.rb: added from HEAD. [ruby-dev:26743]
- * lib/webrick/httpproxy.rb (HTTPProxyServer#intialize),
- lib/webrick/httpserver.rb (HTTPServer#intialize),
- lib/webrick/httpservlet/cgihandler.rb (CGIHandler#initialize),
- lib/webrick/httpservlet/erbhandler.rb (ERBHandler#initialize),
- lib/webrick/httpservlet/filehandler.rb(DefaultFileHandler#initialize):
- super (called with no arguments) takes default value of optional
- arguments. [ruby-dev:26743]
+Sun Aug 7 01:31:15 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
- * lib/webrick/httputils.rb: add a media-type "text/html" for .xhtml.
+ * ext/win32ole/win32ole.c (WIN32OLE_EVENT#on_event): should set
+ only one event handler.
-Sun Aug 7 23:52:39 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+ * ext/win32ole/tests/testOLEEVENT.rb: ditto.
- * test/ruby/test_super.rb: added optional arg tests. [ruby-dev:26743]
- the tests expects 1.8 behavior at this time.
+ * ext/win32ole/tests/testOLEPARAM.rb: remove re-defined
+ test_ole_type_detail method.
Sat Aug 6 12:35:24 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -7921,58 +7554,33 @@ Sat Aug 6 12:35:24 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/variable.rb: retains backward conpatibility.
-Fri Aug 5 12:48:31 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Aug 5 12:50:32 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ext/tk/tcltklib.c: fixed memory leak when tk_funcall raised
+ * ext/tcltklib/tcltklib.c: fixed memory leak when tk_funcall raised
exception. (copies argv into heap in tk_funcall instead of
caller)
-Fri Aug 5 12:36:40 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Fri Aug 5 12:42:57 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/mkmf.rb (create_makefile): need to convert path separetor
before invoking install command.
-Fri Aug 5 08:08:05 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (return_jump): fix "can't across thread" error message
- when no thread associated.
- http://www.namikilab.tuat.ac.jp/~sasada/diary/200507.html#d31
-
-Fri Aug 5 00:25:12 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Aug 5 00:27:04 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ext/tk/tcltklib.c: refactoring - extract ruby string <->
+ * ext/tcltklib/tcltklib.c: refactoring - extract ruby string <->
tcl object conversion as get_str_from_obj and get_obj_from_str.
Fri Aug 5 00:19:33 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * enumerator.c (Init_Enumerator): provided features should have
- extensions.
-
- * eval.c (rb_feature_p): returns type of the feature instead of
- extension.
-
- * eval.c (search_required): ruby library should be prior to statically
- linked extentions. fixed: [ruby-dev:26711]
-
- * eval.c (formal_assign): returns position of rest arguments variable.
-
- * parse.y (f_rest_arg): use anonymous variable for rest arguments.
- fixed: [ruby-dev:26647]
-
* extmk.rb (extmake): needs to be wrapped in an Array.
-Thu Aug 4 20:03:18 2005 Tadashi Saito <shiba@mail2.accsnet.ne.jp>
-
- * numeric.c (Init_Numeric): do not share implementation among
- Fixnum#/ and Fixnum#div. [ruby-core:05531]
-
Thu Aug 4 18:38:36 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c: cannot compile for Tcl7.6/Tk4.2.
+ * ext/tcltklib/tcltklib.c: cannot compile for Tcl7.6/Tk4.2.
- * ext/tk/tcltklib.c: add nativethread consistency check.
+ * ext/tcltklib/tcltklib.c: add nativethread consistency check.
- * ext/tk/stubs.c: ditto.
+ * ext/tcltklib/stubs.c: ditto.
* ext/tk/lib/tk.rb: forgot to define TclTkIp.encoding and encoding=
when Tcl is 7.6 or 8.0.
@@ -7986,11 +7594,6 @@ Thu Aug 4 18:38:36 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/SUPPRT_STATUS: update RELEASE_DATE
-Thu Aug 4 13:30:15 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * numeric.c (fix_div): should not convert the result into
- integer. [ruby-core:05524]
-
Thu Aug 4 08:03:39 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb (extmake): should not modify $mflags for each
@@ -8005,84 +7608,47 @@ Thu Aug 4 00:25:48 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* {win32,wince}/Makefile.sub: separate config.h for compiler versions.
-Thu Aug 4 00:24:59 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * sprintf.c: replacing is no longer needed.
-
Wed Aug 3 21:59:16 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/variable.rb: TkVariable#trace didn't work on
TkVariable retrived from TkVariable.new_hash.ref. [ruby-dev:26721]
-Wed Aug 3 12:40:28 2005 Tadashi Saito <shiba@mail2.accsnet.ne.jp>
-
- * numeric.c (fix_plus): reduce coercing when a method knows about
- a operand type. [ruby-dev:26723]
-
- * numeric.c (fix_minus, fix_mul, fix_quo, fix_div, fix_mod,
- fix_divmod, fix_pow): ditto.
-
- * bignum.c (rb_big_div, rb_big_modulo): export to reduce
- coercing.
-
-Wed Aug 3 10:13:52 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * configure.in, {bcc32,win32,wince}/Makefile.sub (HAVE_SNPRINTF,
- HAVE_VSNPRINTF): use win32/win32.c's implementation instead of
- missing/vsnprintf.c's.
-
- * win32/win32.[ch] (rb_w32_snprintf, rb_w32_vsnprintf): reverted.
-
-Wed Aug 3 10:05:08 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in: check vsnprintf() and snprintf().
-
- * sprintf.c, missing/vsnprintf.c: made vsnprintf() and snprintf()
- private. fixed: [ruby-dev:26651]
-
Wed Aug 3 08:22:13 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c (ruby_connect): revert [ruby-talk:111654]
changes at 2004-09-07. [ruby-dev:26656]
-Wed Aug 3 06:53:35 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c (rb_ary_or): wraps the operand in an array if it is not
- an array. [ruby-talk:150495] [EXPERIMENTAL]
-
- * array.c (rb_ary_and, rb_ary_plus, rb_ary_diff): ditto.
-
-Tue Aug 2 10:23:12 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Aug 2 10:20:54 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ext/tk/tcltklib.c: use Tcl_[GS]etVar2Ex instead of
+ * ext/tcltklib/tcltklib.c: use Tcl_[GS]etVar2Ex instead of
Tcl_Obj[GS]etVar2. (avoid Tcl_NewStringObj on supported platforms)
- * ext/tk/tcltklib.c: use ip_{get,set,unset}_variable2_core from
+ * ext/tcltklib/tcltklib.c: use ip_{get,set,unset}_variable2_core from
ip_{get,set,unset}_variable.
- * ext/tk/tcltklib.c: replaced Tcl_Panic with rb_bug.
+ * ext/tcltklib/tcltklib.c: replaced Tcl_Panic with rb_bug.
-Tue Aug 2 01:40:38 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Tue Aug 2 01:41:28 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/ping.rb (Ping.pingecho): should rescue StandardError.
[ruby-dev:26677]
-Mon Aug 1 19:02:23 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Aug 1 19:09:41 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ext/tk/tcltklib.c: refactoring - replaced rb_ivar_defined &
+ * ext/tcltklib/tcltklib.c: refactoring - replaced rb_ivar_defined &
rb_ivar_get with single rb_attr_get call.
-Mon Aug 1 18:44:08 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Aug 1 18:45:07 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ext/tk/tcltklib.c (Tcl_GetStringResult): refactoring - define
+ * ext/tcltklib/tcltklib.c (Tcl_GetStringResult): refactoring - define
alternative macro on Tcl7.x or earlier.
-Mon Aug 1 13:53:55 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Aug 1 13:57:35 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ext/tk/tcltklib.c (deleted_ip): refactoring - interpreter
+ * ext/tcltklib/tcltklib.c (deleted_ip): refactoring - interpreter
deletion check. [ruby-dev:26664]
-Mon Aug 1 01:08:21 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Mon Aug 1 01:17:40 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb (check_insecure_method): use private_methods and
protected_methods instead of respond_to? to check method visibility.
@@ -8092,205 +7658,85 @@ Mon Aug 1 01:08:21 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/drb/ut_drb.rb: ditto.
-Sat Jul 30 18:49:44 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c: add WIN32OLE_TYPE#ole_typelib,
- WIN32OLE_TYPE#implemented_ole_types.
-
- * ext/win32ole/tests/testOLETYPE.rb: ditto.
-
-Fri Jul 29 16:12:02 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
-
- * lib/irb/context.rb: fix `irb --readline` option. [ruby-dev:40955]
+Mon Aug 1 00:07:32 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
+ * lib/irb/context.rb: fix `irb --readline` option. [ruby-list:40955]
Fri Jul 29 09:59:38 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (rb_call0): fix calling zsuper from a method with anonymous
- rest argument. [ruby-dev:26639]
-
* eval.c (rb_yield_0): push yielded node instead of yielding.
fixed: [yarv-dev:549]
-Thu Jul 28 21:49:17 2005 IWATSUKI Hiroyuki <don@na.rim.or.jp>
-
- * parse.y (rb_parser_end_seen_p): exclude from ripper.
- <http://moonrock.jp/~don/d/200507.html#d28_t2>
-
- * sprintf.c (clearerr): remove standard macro before re-definition.
- <http://moonrock.jp/~don/d/200507.html#d28_t3>
-
Thu Jul 28 18:09:55 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/stubs.c: When --enable-tcltk-stubs, the initialize
+ * ext/tcltklib/stubs.c: When --enable-tcltk-stubs, the initialize
routine creates a Tcl/Tk interpreter and deletes it. However,
init cost of Tk's MainWindow is not so small. And that makes it
impossible to use libraries written with Tcl functions only on
an environment without a graphical display. This changes support
delaying initalization of Tk_Stubs until the script needs Tk.
- * ext/tk/stubs.h: New file. Define prototypes and return codes of
- functions on stubs.c.
+ * ext/tcltklib/stubs.h: New file. Define prototypes and return
+ codes of functions on stubs.c.
- * ext/tk/tcltklib.c: Support delaying initalization of Tk_Stubs
- until the script needs Tk.
+ * ext/tcltklib/tcltklib.c: Support delaying initalization of
+ Tk_Stubs until the script needs Tk.
- * ext/tk/tcltklib.c: Show friendly error messages for errors on
- initialization.
+ * ext/tcltklib/tcltklib.c: Show friendly error messages for errors
+ on initialization.
- * ext/tk/tcltklib.c: Avoid SEGV on ip_finalize() when ruby is
+ * ext/tcltklib/tcltklib.c: Avoid SEGV on ip_finalize() when ruby is
exiting and $DEBUG is true. (Not fix. If you know the reason of
why, please fix it.)
- * ext/tk/tkutil/tkutil.c (ary2list, ary2list2): bug fix on handling
- of encoding.
+ * ext/tk/tkutil.c (ary2list, ary2list2): bug fix on handling of
+ encoding.
* ext/tk/lib/multi-tk.rb: MultiTkIp#eval_string and bg_eval_string
don't work propery.
* ext/tk/lib/tk.rb: Forget extending Tk::Encoding module to Tk.
-
* ext/tk/lib/tk/variable.rb: TkVarAccess fails to initialize the
object for an element of a Tcl's array variable.
-Thu Jul 28 17:23:37 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (f_larglist): allow block argument in lambda parameter
- list without parenthesis.
-
-Thu Jul 28 17:14:01 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * hash.c (each_i): typo fixed. [ruby-dev:26622]
-
-Thu Jul 28 15:04:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (f_arg): better argument name duplication check
-
- * parse.y (new_args_gen): factored out name duplication check for
- optional and rest arguments.
-
- * parse.y (new_bv_gen): allow shadowing outer local variables;
- warning remains.
-
-Thu Jul 28 13:46:06 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (ripper_warningS): the argument was omitted.
- [ruby-dev:26621]
-
-Thu Jul 28 11:30:57 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (f_larglist): allow bv_decl at the end of lambda
- argument list. [EXPERIMENTAL]
-
- * parse.y (new_bv_gen): allow local variable shadowing, with
- warning in verbose mode.
-
Wed Jul 27 23:23:54 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* gc.c (obj_free): make message format consistent with one from
gc_mark(). [ruby-talk:149668]
- * sprintf.c (quad_t): prepare quad_t as well. [ruby-talk:149668]
-
Wed Jul 27 22:11:37 2005 Kouhei Sutou <kou@cozmixng.org>
* sample/rss/tdiary_plugin: removed. because the plugin
is imported in the tDiary plugin packages.
-Wed Jul 27 19:11:53 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (cd): follow :noop option change. (This patch
- is contributed by Doug Kearns)
-
-Wed Jul 27 16:25:59 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (lambda): Perl6 style -> lambda expression. [NEW]
- [VERY EXPERIMENTAL]
-
-Wed Jul 27 10:43:14 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (id2ref): must not assign pointers to long int. use
- LONG_LONG instead if SIZEOF_LONG < SIZEOF_VOIDP.
- [ruby-talk:149645]
-
- * ruby.h: use LONG_LONG to simplify the change.
- [ruby-talk:149645]
-
Wed Jul 27 10:59:02 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (dir_each): rewinddir(3) before iteration.
[ruby-talk:149628]
-Wed Jul 27 02:34:58 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_f_throw): replace all '0x%lx' by '%p'.
- [ruby-talk:149553]
-
- * missing/vsnprintf.c (BSD_vfprintf): '%p' need to handle 64bit
- size pointer. [ruby-talk:149553]
-
-Tue Jul 26 22:41:28 2005 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/lib/ripper/sexp.rb: new method Ripper.sexp_raw.
-
- * ext/ripper/lib/ripper/sexp.rb (Ripper.sexp): returns more
- readable tree. This is suggested by Kirill A. Shutemov.
-
-Tue Jul 26 22:05:12 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: merge a patch contributed by Daniel Berger,
- with some modification. (RubyForge #2128)
-
-Tue Jul 26 18:11:33 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ruby.h: support LLP64 model. [ruby-talk:149524]
-
-Tue Jul 26 12:57:40 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Tue Jul 26 12:57:49 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/openssl_missin.c: include <openssl/engine.h> before
<openssl/x509_vfy.h> to avoid compilation error of mswin32.
suggested by NAKAMURA Usaku.
-Mon Jul 25 23:48:55 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.[ch]: (rb_w32_vsnprintf, rb_w32_snprintf): removed.
-
Mon Jul 25 21:30:46 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * common.mk: Borland MAKE doesn't look for file names which have paths
- from VPATH. fixed: [ruby-dev:26604]
-
- * ruby.h (NORETURN, DEPRECATED): moved just after config.h.
-
- * {win32,wince}/Makefile.sub: vsnprintf() is in missing now.
-
* {bcc32,win32,wince}/Makefile.sub: moved CPPFLAGS only for ruby
source to XCFLAGS.
-Mon Jul 25 14:10:02 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/multi-tk.rb: fix en-bugged part in the last commit.
-
Mon Jul 25 13:45:18 2005 NAJIMA Hiroki <najima@mickey.ai.kyutech.ac.jp>
* io.c: check HAVE_SYS_IOCTL_H before including the header.
[ruby-dev:26610]
-Sat Jul 23 16:48:12 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_engine.c (ossl_engine_s_load): should check
- OPENSSL_NO_STATIC_ENGINE.
-
-Sat Jul 23 11:46:30 2005 Tanaka Akira <akr@m17n.org>
-
- * eval.c (rb_fd_select): the all three fd_sets must be long enough for
- select. fixed: [ruby-talk:149059]
+Mon Jul 25 14:10:02 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-Sat Jul 23 10:01:41 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/tk/lib/multi-tk.rb: fix en-bugged part in the last commit.
- * sprintf.c (rb_vsprintf, rb_sprintf): new functions return new String,
- using missing/vsnprintf.c. [ruby-dev:26580]
+Sat Jul 23 16:49:04 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * missing/vsnprintf.c: made the output changeable.
+ * ext/openssl/ossl_engine.c (ossl_engine_s_load): should check
+ OPENSSL_NO_STATIC_ENGINE.
Fri Jul 22 21:06:08 2005 Tadashi Saito <shiba@mail2.accsnet.ne.jp>
@@ -8324,12 +7770,12 @@ Fri Jul 22 14:37:43 2005 Kouhei Sutou <kou@cozmixng.org>
Fri Jul 22 07:01:42 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tkutil/tkutil.c (tk_conv_args): forget to revert
- thread_critical and gc_disable when raise ArgumentError.
+ * ext/tk/tkutil.c (tk_conv_args): forget to revert thread_critical
+ and gc_disable when raise ArgumentError.
* ext/tk/lib/remote-tk.rb: RemoteTkIp doesn't need to include TkUtil.
- * ext/tk/tcltklib.c: add TclTkIp#has_mainwindow? method.
+ * ext/tcltklib/tcltklib.c: add TclTkIp#has_mainwindow? method.
* ext/tk/lib/tk.rb: add Tk.has_mainwindow? method.
@@ -8361,17 +7807,11 @@ Fri Jul 22 07:01:42 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: fail to control a slave IP when Tk.mainloop
runs on the IP.
-Thu Jul 21 01:00:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf/nkf-utf8/{nkf.c,utf8tbl.c,config.h}:
- import 1.76
- [ruby-dev:26592] nkf constification
-
-Wed Jul 20 19:18:52 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Jul 20 19:20:37 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* io.c (S_ISREG): need to define S_ISREG before it is used first.
-Wed Jul 20 18:33:15 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Jul 20 18:40:50 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* io.c (wsplit_p): patch for the environment where
fcntl(F_GETFL, O_NONBLOCK) is not supported. in that case,
@@ -8387,7 +7827,7 @@ Wed Jul 20 10:04:51 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* variable.c (rb_class_path): need to adjust snprintf() len for
teminating NUL. [ruby-dev:26581]
-Wed Jul 20 03:58:52 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Jul 20 04:01:55 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/socket/socket.c: sorry, BeOS also uses HAVE_CLOSESOCKET,
so reverted.
@@ -8395,7 +7835,7 @@ Wed Jul 20 03:58:52 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/socket/extconf.rb: should not define HAVE_CLOSESOCKET
on windows.
-Wed Jul 20 03:12:21 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Jul 20 03:16:43 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/socket/socket.c: should not undef close() on win32.
it's defined to rb_w32_close(), otherwise handle leaks.
@@ -8411,22 +7851,19 @@ Tue Jul 19 22:47:29 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* error.c (syserr_initialize): add 1 byte for snprintf() size for
NUL at the end. [ruby-dev:26574]
-Tue Jul 19 17:16:34 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * signal.c (trap): remove sigexit(); handle "EXIT" via sig_exec().
- [ruby-dev:26440]
+Tue Jul 19 16:39:46 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_inspect): replace sprintf() with "%s" format all
over the place by snprintf() to avoid integer overflow.
-Tue Jul 19 14:10:50 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Jul 19 14:08:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ext/tk/tcltklib.c: rbtk_eventloop_depth is used as int.
+ * ext/tcltklib/tcltklib.c: rbtk_eventloop_depth is used as int.
- * ext/tk/tcltklib.c: rbtk_pending_exception is tested with
+ * ext/tcltklib/tcltklib.c: rbtk_pending_exception is tested with
NIL_P, so should assign Qnil instead of 0 (Qfalse).
- * ext/tk/tcltklib.c (ip_invoke_real): fixed memory leak when
+ * ext/tcltklib/tcltklib.c (ip_invoke_real): fixed memory leak when
ip is deleted.
Tue Jul 19 13:19:46 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -8435,50 +7872,33 @@ Tue Jul 19 13:19:46 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
returns a string even if the default value type of the TkVariable
object is not "string".
-Mon Jul 18 21:39:18 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Jul 18 21:40:20 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* eval.c (rb_call0): make the pointer to NODE volatile
instead of NODE itself.
Mon Jul 18 14:32:21 2005 Tanaka Akira <akr@m17n.org>
- * eval.c (rb_call0): make body volatile to avoid possible optimization
- problem.
+ * eval.c (rb_call0): make body volatile to avoid optimization problem.
[ruby-dev:26195]
Mon Jul 18 12:23:27 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ext/io/wait/wait.c: wrong backport from trunk, and compile error on
- platforms fd_set is not a bit set. fixed: [ruby-dev:26562]
+ * ext/io/wait/wait.c: wrong backport from trunk. fixed: [ruby-dev:26562]
Mon Jul 18 09:36:25 2005 Tanaka Akira <akr@m17n.org>
* rubyio.h (FMODE_WSPLIT, FMODE_WSPLIT_INITIALIZED): new constant.
* io.c (wsplit_p): new function.
- (io_fflush): split writing data by PIPE_BUF if wsplit_p is true in
+ (io_fwrite): split writing data by PIPE_BUF if wsplit_p is true in
multi-threaded mode.
- (io_fwrite): ditto.
[ruby-dev:26540]
-Mon Jul 18 05:00:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf/nkf-utf8/nkf.c: import nkf.c 1.73
- fix: TestKconv 1F
-
Sun Jul 17 13:46:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/io/wait/extconf.rb, ext/io/wait/wait.c: Win32 platforms support.
-Sat Jul 16 23:43:16 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * enumerator.c (Init_Enumerator): wrong argument specs.
- [ruby-core:05481]
-
-Sat Jul 16 15:52:50 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * win32/win32.[hc]: constified socket functions. [ruby-dev:26553]
-
Fri Jul 15 23:59:03 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rdoc/parsers/parse_c.rb (handle_class_module): handle a
@@ -8489,25 +7909,23 @@ Fri Jul 15 23:59:03 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rdoc/parsers/parse_c.rb (find_call_seq): allow :nodoc: modifier
in C. [ruby-core:04572]
-Fri Jul 15 23:20:03 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Jul 15 18:00:01 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * enumerator.c (Init_Enumerator): use an internal directly.
+ * bcc32/Makefile.sub (COMMON_HEADERS): ruby_1_8 is using winsock.h.
+ failed to compile ext/socket on bcc5.6.4. [ruby-dev:26193]
-Fri Jul 15 07:58:10 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Fri Jul 15 07:58:56 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/server.rb (WEBrick::GenericServer#accept_client):
sockets should be non-blocking mode. [ruby-dev:26405]
* lib/webrick/utils.rb (WEBrick::Utils.set_non_blocking): new method.
-Fri Jul 15 00:11:36 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * enum.c (enumeratorize): create new enumerator for current method if
- no block is given.
-
- * enumerator.c: moved from ext/enumerator.
+ * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#read_chunked):
+ should call sock.read repeatedly until the preferred size data
+ is obtained.
-Thu Jul 14 18:27:35 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Jul 14 18:27:16 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_strerror): should return correct message
for ENAMETOOLONG and ENOTEMPTY. (bcc32) [ruby-dev:26533]
@@ -8519,11 +7937,7 @@ Thu Jul 14 00:45:42 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* LEGAL (ext/nkf/nkf-utf8): updated from nkf1.7 to nkf-utf8.
-Wed Jul 13 22:44:00 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y: remove static variables. [ruby-dev:26530]
-
-Wed Jul 13 19:36:29 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Jul 13 19:37:47 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_mkdir): should set EEXIST (not EACCES)
if file or directory already exists. (bcc32) [ruby-dev:26508]
@@ -8536,7 +7950,7 @@ Wed Jul 13 19:36:29 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
Wed Jul 13 12:40:00 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c: TclTkLib.do_one_event doesn't work.
+ * ext/tcltklib/tcltklib.c: TclTkLib.do_one_event doesn't work.
* ext/tk/lib/tk.rb: Tk.thread_update is available.
@@ -8544,30 +7958,16 @@ Tue Jul 12 23:32:11 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb: keep curdir unexpanded.
-Mon Jul 11 23:50:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c, intern.h (rb_proc_call, rb_obj_method, rb_method_call):
- export.
-
- * ext/enumerator/enumerator.c (enumerator_with_index): [EXPERIMENTAL]
- added a new method Enumerator#with_index. [ruby-talk:147728]
-
Mon Jul 11 08:31:29 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * regparse.c (fetch_escaped_value): mask values following \c in
+ * regex.c (read_special): fix parsing backslashes following \c in
regexp. fixed: [ruby-dev:26500]
-Sun Jul 11 05:18:17 2005 Michael Neumann <mneumann@ruby-lang.org>
-
- * lib/xmlrpc/server.rb (XMLRPC::Server): Switch from GServer over to
- WEBrick. This makes file lib/xmlrpc/httpserver.rb obsolete (at least it is
- no further used by the XML-RPC library).
-
-Mon Jul 11 02:50:23 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Jul 11 02:53:00 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/cgi.rb (WEBrick::CGI::Socket#request_line):
- mistook to merge the patch of [ruby-dev:26235] at
- revision 1.11.
+ mistook in merging the patch of [ruby-dev:26235] at
+ revision 1.4.2.6.
Sun Jul 10 23:58:04 2005 Tanaka Akira <akr@m17n.org>
@@ -8575,12 +7975,18 @@ Sun Jul 10 23:58:04 2005 Tanaka Akira <akr@m17n.org>
avoid unlink a directory by root.
cf. [ruby-dev:26237]
+Sun Jul 11 05:18:17 2005 Michael Neumann <mneumann@ruby-lang.org>
+
+ * lib/xmlrpc/server.rb (XMLRPC::Server): Switch from GServer over to
+ WEBrick. This makes file lib/xmlrpc/httpserver.rb obsolete (at least it is
+ no further used by the XML-RPC library).
+
Sun Jul 10 12:47:01 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/debug.rb (debug_command): added a deficient format specifier.
fixed: [ruby-core:05419]
-Sat Jul 9 22:02:37 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+Sat Jul 9 21:28:46 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (ole_method_dispid): convert dispid
in Ruby and C by INT2NUM and NUM2INT.
@@ -8605,36 +8011,6 @@ Fri Jul 8 15:45:04 2005 Kouhei Sutou <kou@cozmixng.org>
* test/rss/test_parser.rb (RSS::TestParser#test_category20):
adjusted test case.
-Wed Jul 6 18:45:53 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (rb_obj_pattern_match): now returns nil.
- [ruby-core:05391]
-
-Mon Jul 4 14:35:52 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * sample/svr.rb: service can be stopped by ill-behaved client; use
- tsvr.rb instead.
-
-Mon Jul 4 13:25:21 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * missing/erf.c: original erf.c by prof. Okumura is confirmed to
- be public domain. reverted BSD implementation.
-
-Wed Jul 6 11:15:21 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (open_ifs_socket): new function.
-
- * win32/win32.c (StartSockets, rb_w32_socket): use open_ifs_socket()
- instead of socket().
- all changes are derived from [ruby-core:5388].
-
-Wed Jul 6 00:15:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf/nkf-utf8/{nkf.c,utf8tbl.c,config.h}:
- imported nkf.c 1.70 (support UTF-8-MAC)
-
- * ext/nkf/lib/kconv.rb: add :utf8mac and :internalunicode
-
Tue Jul 5 23:44:06 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* instruby.rb: expand source library path.
@@ -8651,19 +8027,19 @@ Tue Jul 5 15:15:10 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tkutil.c: fix typo.
-Tue Jul 5 14:52:56 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+Tue Jul 5 14:51:35 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c: bug fix on treating Unicode strings.
+ * ext/tcltklib/tcltklib.c: bug fix on treating Unicode strings.
- * ext/tk/tcltklib.c: add methods to treat encoding mode.
+ * ext/tcltklib/tcltklib.c: add methods to treat encoding mode.
- * ext/tk/MANUAL_tcltklib.eng: add description of TclTkLib#encoding,
+ * ext/tcltklib/MANUAL.eng: add description of TclTkLib#encoding,
encoding_system, and so on.
- * ext/tk/MANUAL_tcltklib.eucj: ditto.
+ * ext/tcltklib/MANUAL.euc: ditto.
- * ext/tk/tkutil/tkutil.c: fail to create a Tcl's list string from
- an array including multiple kind of encoded strings.
+ * ext/tk/tkutil.c: fail to create a Tcl's list string from an
+ array including multiple kind of encoded strings.
* ext/tk/lib/tk.rb: ditto.
@@ -8689,11 +8065,17 @@ Tue Jul 5 14:52:56 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/namespace.rb: arguemnts for TclTkIp#_merge_tklist
should be UTF-8 strings.
-Mon Jul 4 19:29:32 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Jul 4 14:35:52 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * sample/svr.rb: service can be stopped by ill-behaved client; use
+ tsvr.rb instead.
+
+Mon Jul 4 13:25:21 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/set.rb: test change to follow revision 1.28. (duck typing?)
+ * missing/erf.c: original erf.c by prof. Okumura is confirmed to
+ be public domain. reverted BSD implementation.
-Mon Jul 4 11:23:50 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Mon Jul 4 11:15:37 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* test/{dbm,gdbm,sdbm}/test_{dbm,gdbm,sdbm}.rb: skip some tests
which using fork on fork-less platforms.
@@ -8716,18 +8098,11 @@ Sat Jul 2 17:06:23 2005 Tanaka Akira <akr@m17n.org>
* eval.c (flush_register_windows): new function.
- * ruby.h (NOINLINE): move up to be effective in defines.h.
-
-Sat Jul 2 15:19:41 2005 Tanaka Akira <akr@m17n.org>
-
- * configure.in: check select_large_fdset.
+Fri Jul 1 17:48:52 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * eval.c: use select_large_fdset to support large file descriptors
- on Solaris. [ruby-dev:26404]
-
-Fri Jul 1 17:55:08 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * bignum.c (rb_big_neg): may be accessing bogus pointer value.
+ * bignum.c (get2comp): revert all prior changes, and calculate
+ proper 2's complement for negative numbers. backported from
+ HEAD.
Fri Jul 1 15:50:12 2005 NAKAMURA Usaku <usa@ruby-lang.org>
@@ -8767,11 +8142,6 @@ Fri Jul 1 00:18:40 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/delegate.rb (Delegator::respond_to): respond_to? must check
destination object. [ruby-talk:146894]
-Thu Jun 30 23:52:12 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * signal.c (trap): non-string trap hander was ignored.
- fixed: [ruby-dev:26417]
-
Thu Jun 30 19:00:21 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
* lib/irb/ruby-lex.rb (RubyLex::identify_number): alternative implements
for [ruby-dev:26410]. And support a numeric form of 0d99999.
@@ -8786,76 +8156,46 @@ Thu Jun 30 15:13:16 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_eval): pre-evaluate argument for unambiguous
evaluation order. [ruby-dev:26383]
-Thu Jun 30 14:48:23 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/net/http.rb (Net::HTTP#connect, Net::HTTP#request): should
- not send proxy username and password to origin servers.
- [ruby-dev:25673]
-
- * lib/net/http.rb (Net::HTTP::ProxyDelta#edit_path): should not
- send HTTPS scheme URL to origine servers. [ruby-dev:25689]
-
Thu Jun 30 09:53:56 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/delegate.rb (Delegator::method_missing): forward unknown
method to the destination. suggested by
<christophe.poucet@gmail.com>. [ruby-talk:146776]
-Wed Jun 29 00:03:20 2005 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * regparse.c (fetch_token): avoid warning of unused goto tag.
- [ruby-dev:26389]
-
Tue Jun 28 21:59:29 2005 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
- * dir.c, eval.c, parse.y, process.c, ruby.c: avoid warning "unused
+ * dir.c, eval.c, hash.c, process.c, ruby.c: avoid warning "unused
variable" [ruby-dev:26387]
- * dir.c (glob_helper): avoid warning "enumeration value `RECURSIVE'
- not handled in switch" [ruby-dev:26392]
-
-Tue Jun 28 01:52:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
+Sat Jun 25 17:15:23 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * ext/nkf/lib/kconv.rb: add Kconv::VERSION
- * ext/nkf/lib/kconv.rb (conv): can process arrayed options
- * ext/nkf/nkf-utf8/nkf.c: imported Revision 1.69
- * ext/nkf/nkf-utf8/utf8tbl.c: imported Revision 1.9
+ * lib/webrick/httputils.rb (WEBrick::HTTPUtils.parse_query): should
+ discard if key=val pair is empty. patch from Gary Wright.
Sat Jun 25 23:30:51 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* process.c (detach_process_watcher): terminate process watcher
thread right after rb_waitpid() succeed. [ruby-talk:146430]
-Sat Jun 25 17:12:20 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httputils.rb (WEBrick::HTTPUtils.parse_query): should
- discard if key=val pair is empty. patch from Gary Wright.
-
Sat Jun 25 15:49:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * enum.c (enum_min, enum_max, enum_min_by, enum_max_by): do not ignore
- nil as the first element.
+ * enum.c (enum_min, enum_max): do not ignore nil as the first element.
-Sat Jun 25 15:13:54 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sat Jun 25 14:40:17 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * lib/set.rb (Set#==): [ruby-dev:25206] (ported from ruby_1_8 branch)
+ * ext/sdbm/init.c (fsdbm_select): SDBM#select had returned the array
+ which contained each elements twice. [ruby-dev:26358]
-Sat Jun 25 11:37:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
+Fri Jun 25 05:06:47 2005 Michael Neumann <mneumann@ruby-lang.org>
- * ext/nkf/lib/kconv.rb: remove constants
- Iconv_Shift_JIS, Uconv_EUC_JP, Iconv_UTF8
- * ext/nkf/lib/kconv.rb: add module functions to Kconv
- conv, {eucjp, shiftjis, utf8}?, guess_as_symbol
- * ext/nkf/lib/kconv.rb: add instance methods to String
- conv, {eucjp, shiftjis, utf8}?
- * ext/nkf/lib/kconv.rb: add aliases Kconv.to_* and String#to_*
+ * lib/xmlrpc/*, test/xmlrpc/*: backported changes from HEAD into 1.8
Fri Jun 24 17:00:00 2005 Shigeo Kobayashi <shigeo@tinyforest.jp>
* ext/bigdecimal/bigdecimal.c: patch from "NATORI Shin"
(u-tokyo.ac.jp) applied to fix rounding bug.
-Fri Jun 24 13:17:45 2005 akira yamada <akira@ruby-lang.org>
+Fri Jun 24 13:06:45 2005 akira yamada <akira@ruby-lang.org>
* lib/uri/common.rb, lib/uri/generic.rb: fixed typo in documents and
replaced some existent domain name with "example.com".
@@ -8892,7 +8232,7 @@ Mon Jun 20 18:44:04 2005 Tanaka Akira <akr@m17n.org>
because setjmp is not enough to fix getcontext and SPARC register
window problem.
-Mon Jun 20 17:15:51 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Mon Jun 20 16:48:36 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/dbm/dbm.c (fdbm_closed): new method DBM#closed?
@@ -8905,7 +8245,7 @@ Mon Jun 20 17:15:51 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.{ch} (unlink): hook runtime function to change
file attribute before unlinking.
- merge from 1.8, see [ruby-dev:26360]
+ fixed: [ruby-dev:26360]
Mon Jun 20 02:15:35 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -8919,17 +8259,6 @@ Mon Jun 20 01:26:49 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
ext/openssl/ossl_pkcs12.h, ext/openssl/ossl_x509req.c: avoid
compiler warnings. suggested by Michal Rokos.
-Sun Jun 20 00:22:02 2005 Michael Neumann <mneumann@ruby-lang.org>
-
- * lib/xmlrpc/utils.rb: Patch by Nobuhiro IMAI fixes the following
- problem: Default value modification on
- Module#public_instance_methods (false -> true) breaks
- s.add_handler(XMLRPC::iPIMethods("sample"), MyHandler.new) style
- security protection.
-
- * lib/xmlrpc/client.rb: Aliased XMLRPC::Client#new2 as
- XMLRPC::Client#new_from_uri, and #new3 as #new_from_hash.
-
Sun Jun 19 14:09:07 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (run_final): reduce unnecessary object allocation during
@@ -8938,30 +8267,15 @@ Sun Jun 19 14:09:07 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (rb_gc_call_finalizer_at_exit): deferred finalizers list should
be cleared before calling them. fixed: [ruby-talk:145790]
-Sat Jun 18 01:15:36 2005 Shugo Maeda <shugo@ruby-lang.org>
-
- * ext/readline/readline.c (readline_readline): do not set
- rl_{in,out}stream.
-
- * ext/readline/readline.c (readline_s_set_input): new method.
-
- * ext/readline/readline.c (readline_s_set_output): new method.
-
- * lib/irb/input-method.rb: set Readline.input and Readline.output.
-
Fri Jun 17 13:01:40 2005 Tanaka Akira <akr@m17n.org>
* lib/time.rb (Time.parse): fix previous leap seconds support.
(Time.rfc2822): ditto.
(Time.xmlschema): ditto.
-Thu Jun 16 15:41:32 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Jun 16 15:06:55 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ruby.c (load_file): '!' is already read. reported by gotoyuzo.
-
-Thu Jun 16 15:09:38 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ext/tk/tcltklib.c (ip_rb_threadVwaitCommand): Tcl_Release
+ * ext/tcltklib/tcltklib.c (ip_rb_threadVwaitCommand): Tcl_Release
was missing.
Thu Jun 16 13:34:48 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -8977,14 +8291,10 @@ Thu Jun 16 12:53:24 2005 Tanaka Akira <akr@m17n.org>
(Time.rfc2822): ditto.
(Time.xmlschema): ditto.
-Thu Jun 16 00:13:41 2005 Tanaka Akira <akr@m17n.org>
+Thu Jun 16 08:29:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * lib/resolv.rb (Resolv::DNS::Resource#ttl): new attribute.
- (Resolv::DNS::Resource#==): ignore @ttl.
- (Resolv::DNS::Resource#hash): ditto.
- (Resolv::DNS::Message::MessageDecoder#get_rr): save TTL in a
- Resource object.
- based on [ruby-core:5190] by Eric Hodel.
+ * ext/dl/sym.c (rb_dlsym_call): needs FREE_ARGS before return.
+ fixed memory leak. [ruby-Bugs-2034]
Wed Jun 15 18:26:39 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -8995,13 +8305,13 @@ Wed Jun 15 18:26:39 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Tue Jun 14 02:02:43 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tkutil/tkutil.c: add TkUtil::CallbackSubst.subst_arg(m, ...)
- & _define_attribute_aliases(hash) to get substitution-argument from
+ * ext/tk/tkutil.c: add TkUtil::CallbackSubst.subst_arg(m, ...) &
+ _define_attribute_aliases(hash) to get substitution-argument from
attributes (e.g. subst_arg(:x,:y,:num,:button) --> "%x %y %b %b ").
* ext/tk/lib/tk/event.rb: use _define_attribute_aliases().
-Mon Jun 13 13:03:08 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Jun 13 13:01:05 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* hash.c (ruby_setenv): fixed SEGV. [ruby-dev:26186]
@@ -9024,20 +8334,11 @@ Mon Jun 13 01:20:02 2005 Tanaka Akira <akr@m17n.org>
* eval.c (rb_gc_mark_threads): curr_thread may not be part of the
thread list. [ruby-dev:26312]
-Sat Jun 11 22:34:44 2005 Minero Aoki <aamine@loveruby.net>
-
- * parse.y: missing arg_paren event. This patch is contributed by
- Mitchell N Charity.
-
-Fri Jun 10 23:55:17 2005 Tanaka Akira <akr@m17n.org>
-
- * eval.c (unknown_node): show more information. [ruby-dev:26196]
-
Fri Jun 10 23:35:34 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* missing/mkdir.c: remove. [ruby-core:05177]
-Fri Jun 10 22:54:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Jun 10 22:54:26 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* missing.h: fd_set stuffs need sys/types.h. fixed: [ruby-core:05179]
@@ -9061,47 +8362,20 @@ Thu Jun 9 19:55:41 2005 Tanaka Akira <akr@m17n.org>
* gc.c (Init_stack): remove IA64_MAGIC_STACK_LIMIT.
-Thu Jun 9 18:24:16 2005 Tanaka Akira <akr@m17n.org>
-
- * configure.in, eval.c, gc.c: use libunwind only on HP-UX.
- [ruby-dev:26297]
-
-Thu Jun 9 14:46:32 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * hash.c (env_aset): do not treat nil as key-removing value.
- [ruby-list:40865]
-
- * parse.y (method_call): allow aref expression ([]) to take a
- block.
-
- * parse.y (block_dup_check): a function to check duplication of
- a block argument and an actual block.
-
Thu Jun 9 11:55:34 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/delegate.rb (SimpleDelegator::__setobj__): need check for
recursive delegation. [ruby-core:04940]
-Thu Jun 9 11:50:43 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/cgi.rb: add underscore aliases CGI::escape_html,
- CGI::unescape_html, CGI::escape_element, CGI::unescape_element.
- [ruby-core:05058]
-
Wed Jun 8 18:47:10 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* misc/ruby-mode.el (ruby-expr-beg): fix looking point drift.
-Wed Jun 8 12:25:59 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c (rb_ary_nitems): add the block feature to Array#nitems.
- suggested by Bertram Scharpf <lists@bertram-scharpf.de> in
- [ruby-talk:134083].
-
Wed Jun 8 11:11:34 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * bignum.c (get2comp): revert all prior changes, and calculate
- proper 2's complement for negative numbers.
+ * bignum.c (get2comp): calculate proper 2's complement for
+ negative numbers. a bug in normalizing negative numbers
+ reported from Honda Hiroki <hhonda@ipflex.com>.
Wed Jun 8 08:33:10 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -9112,15 +8386,6 @@ Wed Jun 8 08:33:10 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (backtrace): skip successive frames sharing same node.
-Wed Jun 8 01:27:06 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * bignum.c (bignorm): fixed a bug in normalizing negative numbers
- reported from Honda Hiroki <hhonda@ipflex.com>. normalizing
- should not trim leading zeros from negative numbers.
-
- * bignum.c (rb_cstr_to_inum): must remove leading zeros for this
- case.
-
Wed Jun 8 00:15:08 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c (ruby_getaddrinfo__aix): merged a patch from
@@ -9146,55 +8411,37 @@ Tue Jun 7 19:34:15 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
Tue Jun 7 18:39:31 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/thread.rb: RDoc documentation from Eric Hodel
- <drbrain@segment7.net> added. [ruby-core:05148]
+ <drbrain at segment7.net> added. [ruby-core:05148]
Tue Jun 7 18:30:04 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (create_makefile): add .SUFFIXES from depend file.
fixed: [ruby-dev:26294]
-Tue Jun 7 17:20:39 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+Tue Jun 7 17:39:54 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * parse.y (parser_yylex): allow ';;' to be block terminator in
- place of 'end'. [highly experimental]
+ * object.c (rb_mod_cvar_get): Module#class_variable_get(): back
+ ported from CVS HEAD. [ruby-talk:144741]
- * misc/ruby-mode.el (ruby-block-end-re): allow ';;' to be a
- negative indent trigger. [highly experimental]
-
- * parse.y (parser_yylex): small error fixed.
-
-Tue Jun 7 16:45:49 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (parser_yylex): "respond_to?:foo" should be interpreted
- as "respond_to? :foo" at the command level. [ruby-talk:144303]
+ * object.c (rb_mod_cvar_set): Module#class_variable_set().
+ [ruby-talk:144741]
Tue Jun 7 16:32:53 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* sprintf.c (rb_f_sprintf): raise exception on debug mode (-d),
not verbose mode (-v/-w). [ruby-core:05123]
- * sprintf.c (rb_f_sprintf): warn always on verbose mode.
-
Tue Jun 7 10:30:49 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: slave-ip fails to call procedures
delegated by master-ip.
-Mon Jun 6 16:35:18 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/ripper/depend: add .y to .SUFFIXES for nmake.
-
Sun Jun 5 23:00:35 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/console.rb: create console when required
* ext/tk/sample/tkextlib/tile/demo.rb: fix TypeError & create Console
-Sun Jun 5 10:23:52 2005 Tanaka Akira <akr@m17n.org>
-
- * signal.c (ruby_signal): don't set SA_RESTART.
- [ruby-dev:26276]
-
Sat Jun 4 14:55:18 2005 Tanaka Akira <akr@m17n.org>
* test/dbm/test_dbm.rb: merged from ext/dbm/testdbm.rb.
@@ -9204,61 +8451,15 @@ Sat Jun 4 14:55:18 2005 Tanaka Akira <akr@m17n.org>
* test/sdbm/test_sdbm.rb: renamed from ext/sdbm/testsdbm.rb with
modification to use test/unit.
-Fri Jun 3 23:23:02 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * intern.h (rb_fdset_t): deal with fd bit sets over FD_SETSIZE.
- fixed: [ruby-dev:26187]
-
- * eval.c (rb_fd_init, rb_fd_term, rb_fd_zero, rb_fd_set, rb_fd_clr,
- rb_fd_isset, rb_fd_copy): ditto.
-
- * io.c (rb_io_wait_readable, rb_io_wait_writable, rb_f_select): ditto.
-
- * ext/io/wait/wait.c (io_wait): ditto.
-
- * ext/socket/socket.c (wait_connectable, unix_recv_io): ditto.
-
Fri Jun 3 14:06:12 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: fix typo.
-Thu Jun 2 23:42:57 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y: pragma support on ripper. [ruby-dev:26266]
-
-Thu Jun 2 00:02:16 2005 Minero Aoki <aamine@loveruby.net>
-
- * struct.c: accessing >10 member caused segmentation fault.
- [ruby-dev:26247]
-
- * test/ruby/test_struct.rb: test it.
-
-Wed Jun 1 11:30:09 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Jun 1 11:32:42 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* bcc32/Makefile.sub: can use single quote character in DESTDIR.
[ruby-dev:26205]
- * bcc32/Makefile.sub: Dir.glob in 1.9 doesn't treat \ as path separator.
- [ruby-dev:26254]
-
-Wed Jun 1 00:11:06 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (method_call): new experiment: "(expr)(args...)" to
- invoke "expr.call(args...)". [EXPERIMENTAL]
-
-Tue May 31 23:43:41 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (command): revert implicit "call" for local variables.
-
-Tue May 31 15:52:45 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): should
- break the loop if the socket reached to EOF. [ruby-talk:142285]
-
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): send response
- without reading the whole request body if keep-alive is diabled.
- [experimental]
-
Mon May 30 23:48:29 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/macpkg.rb: add PACKAGE_NAME information of Tcl/Tk
@@ -9270,12 +8471,12 @@ Mon May 30 23:48:29 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/*: ditto.
-Sat May 28 16:39:21 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Sat May 28 16:40:15 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* test/openssl/test_x509store.rb: add test for expired CRL
and refine some assertions.
-Sat May 28 05:15:44 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Sat May 28 05:15:51 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_x509store.c (ossl_x509stctx_set_time): should
not set internal flag directry.
@@ -9291,41 +8492,22 @@ Fri May 27 16:32:04 2005 WATANABE Hirofumi <eban@ruby-lang.org>
* lib/mkmf.rb: use the semicolon as the path separator
in the environment of MSYS. fixed: [ruby-dev:26232]
-Thu May 26 20:31:21 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (remove_entry_secure): add documentation.
-
- * lib/fileutils.rb (remove_entry_secure): should not invoke
- unlink(2) against a directory.
-
-Thu May 26 08:29:19 2005 Akiyoshi, Masamichi <akiyoshi@hp.com>
-
- * vms/vmsruby_private.c, vms/vmsruby_private.h: private routines
- for VMS port are added.
-
- * eval.c (ruby_init): change to call VMS private intialization routine.
-
-Thu May 26 07:39:07 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (rm_r): use lchown(2), not chown(2).
- [ruby-dev:26226]
+Thu May 26 06:08:11 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * lib/fileutils.rb (cd): remove :noop option. (feature change)
+ * ext/tk/lib/tk.rb: add shortcut-methods of tk_call + tk_split_list
- * lib/fileutils.rb (cp_r): should copy symlink as symlink, for
- also tree root. (feature change)
+Wed May 25 22:52:42 2005 Shugo Maeda <shugo@ruby-lang.org>
- * lib/fileutils.rb (cp_r): new option :dereference_root.
+ * lib/irb/input-method.rb: do not use Readline::HISTORY.pop.
+ (backported from HEAD)
- * lib/fileutils.rb: new method remove_entry.
+Wed May 25 21:55:40 2005 Shugo Maeda <shugo@ruby-lang.org>
- * lib/fileutils.rb: new method remove_entry_secure.
+ * ext/readline/readline.c: supported libedit. (backported from HEAD)
- * lib/fileutils.rb: add documentation.
+ * ext/readline/extconf.rb: ditto.
-Thu May 26 06:08:11 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk.rb: add shortcut-methods of tk_call + tk_split_list
+ * test/readline/test_readline.rb: ditto.
Wed May 25 20:06:27 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -9367,10 +8549,6 @@ Wed May 25 20:06:27 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb: ditto.
-Wed May 25 19:48:12 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (rm_r): does chown(2). [ruby-dev:26199]
-
Wed May 25 12:59:48 2005 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb (OpenURI::Meta::RE_QUOTED_STRING): a content of
@@ -9386,17 +8564,17 @@ Tue May 24 16:57:24 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* ruby.c (require_libraries): caused SEGV when continuation jumped
in to the required library code.
-Tue May 24 17:45:59 2005 Shugo Maeda <shugo@ruby-lang.org>
+Tue May 24 11:56:25 2005 WATANABE Hirofumi <eban@ruby-lang.org>
- * test/readline/test_readline.rb: do not test libedit.
- fixed: [ruby-dev:26217]
+ * lib/getopts.rb: should warn only if verbose mode.
+ fixed: [ruby-dev:26201]
Tue May 24 06:45:31 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* misc/ruby-mode.el (ruby-font-lock-syntactic-keywords): string
literals to be matched non-greedy.
-Tue May 24 00:39:14 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Tue May 24 00:34:32 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/soap/calc: method name 'set' was able to crash with a class Set.
[ruby-dev:26210]
@@ -9404,16 +8582,11 @@ Tue May 24 00:39:14 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/wsdl/document/test_rpc.rb: dateTime comparison failed under
TZ=right/Asia/Tokyo (with leap second.) [ruby-dev:26208]
-Mon May 23 16:23:06 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/extconf.rb: Framework support on MacOS X Tiger.
-
- * ext/tk/README.tcltklib: add description of Framework support options.
+Mon May 23 16:24:05 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-Mon May 23 15:07:34 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+ * ext/tcltklib/extconf.rb: Framework support on MacOS X Tiger.
- * win32/Makefile.sub ($(PROGRAM)): add dependency on $(LIBRUBY_SO).
- [experimental]
+ * ext/tcltklib/README.1st: add description of Framework support options.
Mon May 23 12:21:37 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -9506,79 +8679,41 @@ Sun May 22 19:11:35 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_ssl.c (ossl_sslctx_setup): add session id support.
-Sun May 22 12:30:58 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * intern.h, parse.y (ruby_pragma): removed. fixed: [ruby-dev:26198]
-
- * parse.y (parser_pragma): pragma name was ignored.
-
-Sun May 22 02:39:57 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (rm_r): new option :secure to avoid
- time-to-check-to-time-to-use security problem. [ruby-dev:26100]
-
- * lib/fileutils.rb (remove_file, remove_dir): try chmod(700) only
- on Windows.
-
- * lib/fileutils.rb: does not depend on find.rb.
-
- * lib/fileutils.rb: new method chmod_R.
-
- * lib/fileutils.rb (chown_R): did not work.
-
-Sat May 21 10:23:21 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sat May 21 10:24:21 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* bcc32/Makefile.sub: tds files were not deleted when DESTDIR
included '\' path delimiter. [ruby-dev:26193]
-Fri May 20 15:52:18 2005 Shugo Maeda <shugo@ruby-lang.org>
-
- * ext/readline/readline.c (readline_attempted_completion_function):
- return 2 items if completion_proc returns only 1 item (for libedit).
-
-Fri May 20 01:24:33 2005 Shugo Maeda <shugo@ruby-lang.org>
-
- * ext/readline/extconf.rb: check rl_vi_editing_mode() and
- rl_emacs_editing_mode().
+Thu May 19 19:04:29 2005 speakillof <speakillof@yahoo.co.jp>
-Thu May 19 23:33:09 2005 Shugo Maeda <shugo@ruby-lang.org>
-
- * ext/readline/readline.c: supported libedit. fixed: [ruby-core:4858]
-
- * ext/readline/extconf.rb: added new option --enable-libedit.
-
- * test/readline/test_readline.rb: added assertions for
- Readline::HISTORY.
-
- * lib/irb/input-method.rb: do not use Readline::HISTORY.pop.
+ * lib/rexml/encodings/SHIFT-JIS.rb: encoding and decoding were
+ swapped. [ruby-core:4772]
Wed May 18 23:42:25 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (exc_exception): reverted to call Exception#initialize
directly. fixed: [ruby-dev:26177]
-Wed May 18 17:38:51 2005 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * dir.c (glob_helper): check whether path is "" before calling
- do_opendir. [ruby-dev:26183]
-
-Wed May 18 13:40:48 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (NtInitialize): fix typo.
-
-Wed May 18 11:07:47 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed May 18 23:39:09 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dir.c (glob_helper): get rid of using String. [ruby-dev:26180]
+ * dir.c (push_braces): should skip balanced braces.
+
* eval.c (ruby_options), win32/win32.c (NtInitialize): move argument
intialization back. [ruby-dev:26180]
-Tue May 17 11:49:18 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue May 17 15:31:31 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): should
+ break the loop if the socket reached to EOF. [ruby-talk:142285]
+
+Tue May 17 11:52:18 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (unixtime_to_filetime): use localtime() instead of
gmtime() when using FileLocalTimeToFileTime().
-Mon May 16 22:42:52 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon May 16 22:28:43 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.h, {bcc32,win32,wince}/Makefile.sub: moved rb_[ugp]id_t
to get rid of redefinition warnings on mingw.
@@ -9586,12 +8721,7 @@ Mon May 16 22:42:52 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* class.c (rb_class_init_copy): singleton class is disallowed to copy,
from its definition. fixed: [ruby-talk:142749]
- * parse.y (pragma_encoding): add prototype to suppress false warning
- by VC.
-
- * process.c (proc_spawn_v): use rb_w32_aspawn on Win32.
-
-Mon May 16 03:29:01 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon May 16 08:52:29 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.{h,c}: define rb_[pgu]id_t.
@@ -9601,7 +8731,7 @@ Mon May 16 00:21:02 2005 Tanaka Akira <akr@m17n.org>
Errno::EISDIR because EISDIR is not portable.
[ruby-core:5001]
-Sun May 15 22:28:10 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sun May 15 22:11:33 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb (DRbObject#method_missing): use raise(exception).
[ruby-dev:26164]
@@ -9626,7 +8756,7 @@ Sat May 14 23:59:11 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (exc_exception, {exit,name_err,syserr}_initialize): call
Execption#initialize. fixed: [ruby-talk:142593]
-Sat May 14 23:56:41 2005 Erik Huelsmann <ehuels@gmail.com>
+Sat May 14 23:57:26 2005 Erik Huelsmann <ehuels@gmail.com>
* configure.in: Check for the availability of pid_t, gid_t and uid_t and
remove AC_TYPE_UID_T. fixed: [ruby-core:04745]
@@ -9651,16 +8781,6 @@ Sat May 14 23:56:41 2005 Erik Huelsmann <ehuels@gmail.com>
* wince/sys/types.h: Remove definitions of {p,g,u}id_t.
-Sat May 14 11:47:57 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * intern.h (ruby_pragma): prototype. [ruby-core:04881]
-
- * parse.y (parser_pragma): parse Emacsen hack.
-
- * parse.y (parser_prepare): deal with specific syntax at the top.
-
- * ruby.c (load_file): read the first line iff it started with shebang.
-
Fri May 13 23:44:22 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb: keep srcdir unexpanded.
@@ -9672,45 +8792,87 @@ Fri May 13 23:44:22 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
also INSTALL_PROG and INSTALL_DATA system dependent.
fixed: [ruby-core:04931]
-Fri May 13 23:32:55 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (unknown_node): add volatile directive to prototype.
-
-Fri May 13 17:50:49 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri May 13 17:54:39 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* variable.c (generic_ivar_get): rb_attr_get should not warn.
[ruby-dev:26010]
-Thu May 12 17:41:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
+Fri May 13 12:28:43 2005 Daniel Berger <djberge@qwest.com>
- * ext/nkf/nkf-utf8/nkf.c: follow nkf 2.0.5
+ * array.c (rb_ary_select): can remove argc check. [ruby-core:4911]
+
+ * test/ruby/test_array.rb: add test for find_all.
+
+Fri May 13 11:29:00 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * eval.c (unknown_node): add volatile directive to prototype.
-Thu May 12 16:50:40 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu May 12 17:08:48 2005 Tanaka Akira <akr@m17n.org>
+
+ * io.c (rb_io_eof, remain_size, read_all, io_read, appendline)
+ (swallow, rb_io_each_byte, rb_io_getc): revert previous change.
+
+ * io.c (rb_io_eof, io_fread, appendline, swallow, rb_io_each_byte)
+ (rb_io_getc, rb_getc): call clearerr before getc to avoid
+ stdio incompatibility.
+
+Thu May 12 16:52:20 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/rdoc/parsers/parse_c.rb: more readability for mixing
progress "c..." and warning message.
-Thu May 12 15:50:56 2005 Tilman Sauerbeck <tilman@code-monkey.de>
+Thu May 12 16:31:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * ext/nkf/nkf-utf8/nkf.c: follow nkf 2.0.5
+
+Thu May 12 16:15:01 2005 Tanaka Akira <akr@m17n.org>
+
+ * io.c (rb_io_eof, remain_size, read_all, io_read, appendline)
+ (swallow, rb_io_each_byte, rb_io_getc): don't rely EOF flag.
+ [ruby-talk:141527]
+
+Thu May 12 15:56:20 2005 Tilman Sauerbeck <tilman@code-monkey.de>
* lib/rdoc/parsers/parse_c.rb: show parsing progress for C files.
[ruby-core:4341]
+Thu May 12 13:47:56 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * test/drb/test_drb{ssl,unix}.rb: can test drb
+ before install. (backported from HEAD) [ruby-dev:26146]
+
Thu May 12 09:53:57 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* version.c (ruby_show_version): flush for non-tty stdout.
+Thu May 12 09:07:07 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * test/ruby/envutil.rb, test/drb/drbtest.rb: can test drb
+ before install. (backported from HEAD) [ruby-Bugs-1672]
+
Thu May 12 01:23:55 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * eval.c (rb_eval), parse.y (arg): reduce fixnum range literal at
+ parser. fixed: [ruby-dev:26113]
+
* eval.c (unknown_node): ignore broken NODE to get rid of accessing
possibly inaccessible address. fixed: [ruby-dev:26122]
should emit more useful information like [ruby-dev:26126], though.
+Wed May 11 16:20:01 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * lib/webrick/cgi.rb: new methods WEBrick::CGI#[], WEBrick::CGI#logger
+ and WEBrick::CGI#config. (backported from HEAD)
+
+ * lib/webrick/httputils.rb (WEBrick::HTTPUtils.escape_path): should
+ not use String#split("/"). (backported from HEAD)
+
Wed May 11 15:58:39 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (break_jump): break should not cross functions.
[ruby-list:40818]
-Wed May 11 10:41:54 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed May 11 10:39:37 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/tempfile.rb (Tempfile#unlink): fixed typo.
@@ -9723,12 +8885,7 @@ Sun May 8 23:17:47 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/timer.rb: fix typo.
-Sun May 8 21:00:50 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * hash.c (Init_Hash): remove custom "hash" and "eql?".
- (ported from 1.8) [ruby-dev:26132]
-
-Sun May 8 16:50:25 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sun May 8 16:52:56 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/profiler.rb: fixed "undefined method `[]' for nil:NilClass"
[ruby-core:4775] [ruby-talk:140401] [ruby-dev:26118]
@@ -9737,54 +8894,11 @@ Sat May 7 22:58:00 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (have_var): no libs argument is given.
-Fri May 6 08:08:37 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * hash.c:rb_hash_hash_i() should be static. [ruby-core:04815]
-
- * re.c should include regint.h for declarations of oniguruma
- functions. [ruby-core:04815]
-
-Sun May 1 09:15:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun May 1 09:58:11 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (process_sflag): replace '-' in variable names with '_'.
[ruby-dev:26107]
- * eval.c (rb_eval), parse.y (arg): reduce fixnum range literal at
- parser. fixed: [ruby-dev:26113]
-
-Sat Apr 30 11:59:25 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (RUBY_FUNC_ATTRIBUTE): check for function attribute.
- [ruby-dev:26109]
-
- * eval.c, gc.c: moved noinline to configure.in.
-
- * rubyio.h (DEPRECATED): moved to configure.in.
-
- * ruby.h (DEPRECATED, NOINLINE): default definition.
-
- * win{32,ce}/Makefile.sub (config.h): deprecated and noinline for
- __declspec() are available for VC++7 or later.
-
-Sat Apr 30 06:57:39 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/cgi.rb: new methods WEBrick::CGI#[], WEBrick::CGI#logger
- and WEBrick::CGI#config. these are necessary to use an instance of
- WEBrick::CGI as the first argument of HTTPServlet#get_instance.
- (suggested by Tatsuki Sugiura)
-
- * lib/webrick/cgi.rb
- (WEBrick::CGI#initalize): set a dummy to @config[:ServerSoftware]
- if SERVER_SOFTWARE environment variable is not given.
- (WEBrick::CGI#start): req.path_info must be a String.
- (WEBrick::CGI::Socket#request_line): treat REQUEST_METHOD, PATH_INFO
- and SCRIPT_NAME to run in console.
-
- * lib/webrick/httputils.rb (WEBrick::HTTPUtils.escape_path): should
- not use String#split("/"). it removes trailing empty path component.
-
-Thu Apr 28 08:21:51 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
* ruby.c (set_arg0): use also environment variable space for setting
$0. [ruby-core:04774]
@@ -9795,46 +8909,23 @@ Wed Apr 27 23:42:22 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
Tue Apr 26 22:58:00 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c (ip_invoke_core): call Tcl's "::unknown"
+ * ext/tcltklib/tcltklib.c (ip_invoke_core): call Tcl's "::unknown"
command when can't get information of target command.
-Mon Apr 25 13:54:55 2005 speakillof <speakillof@yahoo.co.jp>
-
- * lib/rexml/encodings/SHIFT-JIS.rb: encoding and decoding were
- swapped. [ruby-core:4772]
-
Mon Apr 25 01:18:43 2005 Tanaka Akira <akr@m17n.org>
- * oniguruma.h (OnigWarnFunc): add a variadic argument.
- [ruby-core:4751]
+ * regex.c: declare rb_warn to have variadic argument. [ruby-core:4751]
-Sat Apr 23 19:49:21 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sat Apr 23 19:45:59 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ext/tk/tcltklib.c (ip_RubyExitCommand): exit with status code
+ * ext/tcltklib/tcltklib.c (ip_RubyExitCommand): exit with status code
via TclTkIp#_eval didn't work. [ruby-talk:139390]
-Sat Apr 23 11:45:29 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_provided): should check also path name to be loaded.
- fixed: [ruby-dev:26093]
-
-Fri Apr 22 16:55:35 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ext/tk/tcltklib.c (ip_set_exc_message): fixed memory leak.
-
- * ext/tk/tcltklib.c: eTkCallbackReturn was not initialized.
+Fri Apr 22 16:41:50 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-Thu Apr 21 06:45:28 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/tcltklib/tcltklib.c (ip_set_exc_message): fixed memory leak.
- * ruby.c (ruby_incpush_expand, proc_options): expand relative path
- given with -I option. [ruby-dev:26090]
-
- * configure.in, lib/mkmf.rb, {bcc32,win32,wince}/Makefile.sub: improve
- C++ support. [ruby-dev:26089]
-
-Thu Apr 21 01:53:09 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: add rdoc.
+ * ext/tcltklib/tcltklib.c: eTkCallbackReturn was not initialized.
Thu Apr 21 00:07:50 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -9848,7 +8939,7 @@ Thu Apr 21 00:07:50 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
Wed Apr 20 23:22:39 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * Makefile.in, common.mk: miniruby depends on MINIOBJS.
+ * Makefile.in, common.mk: miniruby depens on MINIOBJS.
* dmydln.c (dln_load): dummy function to raise LoadError.
@@ -9859,21 +8950,6 @@ Wed Apr 20 23:01:35 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/ifchange.bat: delete testing files.
-Wed Apr 20 22:54:54 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: new method Net::HTTP.post_form.
-
- * lib/net/http.rb: new method Net::HTTPHeader#set_form_data and
- its alias #form_data=.
-
- * lib/net/http.rb: Net::HTTPHeader#add_header -> add_field
- (adjustted to Ruby 1.8).
-
-Wed Apr 20 10:53:30 2005 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * lib/rdoc/parsers/parse_rb.rb (lex_init): use IRB module.
- [ruby-core:04737]
-
Wed Apr 20 07:27:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* {bcc32,win32,wince}/configure.bat, {bcc32,win32,wince}/setup.mak:
@@ -9881,33 +8957,18 @@ Wed Apr 20 07:27:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bcc32/setup.mak: make configuration variables overridable.
-Tue Apr 19 23:37:09 2005 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * lib/ftools.rb (File.safe_unlink): do not modify a symlinked file.
-
-Tue Apr 19 23:02:40 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (search_required): deal with features with path too.
+Wed Apr 20 04:15:27 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
- * intern.h (rb_file_expand_path): prototype. fixed: [ruby-dev:26082]
+ * lib/irb.rb lib/irb/* doc/irb: IRB 0.9.5
-Tue Apr 19 08:38:07 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Apr 19 23:37:09 2005 WATANABE Hirofumi <eban@ruby-lang.org>
- * eval.c (search_required, rb_require_safe): expand path in
- rb_features. [ruby-dev:26079]
+ * lib/ftools.rb (File.safe_unlink): do not modify a symlinked file.
- * file.c (rb_find_file_ext): return absolute path.
+Tue Apr 19 00:06:20 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb: expand path for ext/**/extconf.rb.
- * eval.c (search_required): handle static linked extensions.
-
-Mon Apr 18 15:37:35 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_attr): attribute name check added.
-
- * numeric.c (flo_plus): small typo fix.
-
Mon Apr 18 11:25:14 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/zlib/zlib.c (zstream_run): fixed SEGV. [ruby-core:4712]
@@ -9934,7 +8995,7 @@ Sat Apr 16 15:27:03 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* mkconfig.rb: purge autoconf value variables.
-Sat Apr 16 10:33:48 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sat Apr 16 10:36:01 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* bcc32/Makefile.sub: quick hack... prepend DESTDIR.
still have restriction on DESTDIR ("", "/", "e:")
@@ -9945,54 +9006,18 @@ Sat Apr 16 03:59:42 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/openssl_missing.h: ditto.
-Fri Apr 15 22:40:19 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/tests/testWIN32OLE.rb: add test for WIN32OLE.codepage=
-
- * ext/win32ole/tests/testOLETYPELIB.rb: correct expected message.
-
-Fri Apr 15 22:04:07 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c(ole_invoke): retry after converting Qnil
- to VT_EMPTY.
-
-Thu Apr 14 19:05:06 2005 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper] (regexp): dispatch regexp option.
- [ruby-Bugs:1688]
-
- * ext/ripper/lib/core.rb: regenerated (interface changed).
-
-Thu Apr 14 18:59:43 2005 Minero Aoki <aamine@loveruby.net>
+Thu Apr 14 19:18:30 2005 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (remove_file): ignore exceptions caused by
chmod.
* lib/fileutils.rb (remove_dir): try to get rights to rmdir.
- [ruby-Bugs:1502]
-
-Thu Apr 14 18:51:02 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
+ [ruby-Bugs:1502] (2 items backportted from HEAD, rev 1.53-54)
- * lib/irb/ruby-lex.rb, lib/irb/slex.rb: bug fix of [ruby-Bugs-1745]
+Thu Apr 14 16:57:40 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/irb/ext/loader.rb, lib/irb/ext/save-history.rb:
- fix location of @RCS_ID
-
- * lib/irb/cmd/help.rb: a lost of release IRB 0.9.5.
-
-Thu Apr 14 15:10:30 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
-
- * lib/irb/notifier.rb, lib/irb/output-method.rb, lib/irb/ext/history.rb
- fixed warning of 'ruby -w'
-
-Thu Apr 14 05:35:45 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
-
- * doc/irb/irb.rd.ja: a lost of release IRB 0.9.5.
-
- * lib/irb/slex.rb: bug fix by [ruby-core:04707].
-
-Thu Apr 14 00:20:31 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
- * bin/irb lib/irb.rb lib/irb/...: IRB 0.9.5.
+ * bcc32/Makefile.sub: failed to remove debug information files.
+ fixed: [ruby-dev:26034]
Wed Apr 13 23:40:21 2005 Kouhei Sutou <kou@cozmixng.org>
@@ -10001,44 +9026,33 @@ Wed Apr 13 23:40:21 2005 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/rss.rb (RSS::Element#converter): fixed converter
transmission bug.
-Wed Apr 13 22:12:16 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb (OptionParser#order!): call handlers iff matches
- non-switch.
-
Wed Apr 13 21:20:35 2005 WATANABE Hirofumi <eban@ruby-lang.org>
* configure.in (mingw32): extract msvcr*.dll from objdump result.
-Wed Apr 13 19:25:31 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Apr 13 20:24:30 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (mingw32): use actual runtime DLL name as ruby DLL
name and default load path.
* win32/Makefile.sub, win32/setup.mak: ditto.
-Tue Apr 12 19:30:36 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/optparse.rb (OptionParser#make_switch, OptionParser#order!):
- added non-option and end-of-args handler. [ruby-talk:136878]
- [EXPERIMENTAL]
-
Tue Apr 12 15:33:09 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c (ip_finalize): better modification than the
+ * ext/tcltklib/tcltklib.c (ip_finalize): better modification than the
previous commit [ruby-dev:26029].
Tue Apr 12 12:38:06 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c (ip_finalize): fix SEGV when Tcl_GlobalEval()
+ * ext/tcltklib/tcltklib.c (ip_finalize): fix SEGV when Tcl_GlobalEval()
modifies the argument string to eval.
Tue Apr 12 02:21:55 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c (ip_finalize): add existence check of
+ * ext/tcltklib/tcltklib.c (ip_finalize): add existence check of
Tcl commands before calling Tcl_GlobalEval().
-Mon Apr 11 23:36:04 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Mon Apr 11 23:47:21 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb: [druby-ja:123] fix: When reference of my object is
loaded, the object is tainted.
@@ -10051,13 +9065,28 @@ Mon Apr 11 22:18:23 2005 WATANABE Hirofumi <eban@ruby-lang.org>
Mon Apr 11 20:11:06 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c (ip_finalize): adhoc patch to avoid SEGV when exit
- on Tcl/Tk8.3.x.
+ * ext/tcltklib/tcltklib.c (ip_finalize): adhoc patch to avoid SEGV
+ when exit on Tcl/Tk8.3.x.
-Mon Apr 11 15:24:20 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Mon Apr 11 15:26:25 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/mkmf.rb (configuration): shouldn't output hdrdir twice.
+Mon Apr 11 12:09:05 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * {bcc32,win32,wince}/Makefile.sub: ri data was not installed
+ into correct path. [ruby-dev:26011]
+
+ * bcc32/Makefile.sub: defaulted install-nodoc. [ruby-dev:26011]
+
+Sun Apr 10 10:12:42 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+
+ * ext/win32ole/win32ole.c(ole_invoke): retry after converting Qnil
+ to VT_EMPTY.
+
+ * ext/win32ole/win32ole/tests/testWIN32OLE.rb: correct error
+ message string "Unknown" => "unknown".
+
Sat Apr 9 18:20:31 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/image.rb: support to create TkImage object without
@@ -10077,41 +9106,75 @@ Sat Apr 9 14:42:29 2005 Kouhei Sutou <kou@cozmixng.org>
* sample/rss/tdiary_plugin/rss-recent.rb: supported configuration
via Web browser.
-Fri Apr 8 20:17:48 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat Apr 9 11:59:57 2005 Kouhei Sutou <kou@cozmixng.org>
- * ext/extmk.rb (extmake): hdrdir needs to be defined also in
- Config::CONFIG.
+ * lib/rss: backoported from HEAD.
- * lib/mkmf.rb (configuration, create_makefile): get rid of recursive
- macro reference.
+ * lib/rss: refactored.
+ - gave a name to 'x'.
+ - undef_method -> remove_method for avoiding a warning in ruby 1.6.
-Fri Apr 8 01:55:20 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/sample/demos-{en,jp}/goldberg.rb: reduced window size.
- [ruby-dev:25992]
+ * lib/rss/parser.rb: @@setter -> @@setters.
-Thu Apr 7 23:58:40 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/rss/parser.rb
+ (RSS::BaseListener.register_uri)
+ (RSS::BaseListener.uri_registered?)
+ (RSS::BaseListener.install_get_text_element):
+ swapped the first argument and the second argument.
- * ext/extmk.rb (extmake): keep directory names in Makefile as macros.
+ * lib/rss/taxonomy.rb: swapped the first argument and the second
+ argument for RSS::BaseListener.install_get_text_element.
+ * lib/rss/image.rb: ditto.
+ * lib/rss/syndication.rb: ditto.
+ * lib/rss/dublincore.rb: ditto.
+ * lib/rss/parser.rb: ditto.
+ * lib/rss/1.0.rb: ditto.
+ * lib/rss/2.0.rb: ditto.
+ * lib/rss/0.9.rb: ditto.
+ * lib/rss/content.rb: ditto.
- * lib/mkmf.rb (configuration, create_makefile): ditto.
+ * lib/rss/parser.rb
+ (RSS::BaseListener.install_setter)
+ (RSS::BaseListener.register_uri): changed fallback way.
- * lib/mkmf.rb (CXX_EXT): separate C++ extensions.
+ * lib/rss/parser.rb: added class name registry for complex model
+ elements. (ex. have childlen elements, have some attributes and
+ a child element and so on.)
-Thu Apr 7 17:24:17 2005 Shugo Maeda <shugo@ruby-lang.org>
- * eval.c (rb_call0): "return" event hook should be always executed
- if event_hooks is set.
+ * lib/rss/dublincore.rb: supported multiple Dublin Core items.
+ * lib/rss/maker/dublincore.rb: ditto.
+
+ * lib/rss/maker/image.rb: supproted new Dublin Core API.
-Thu Apr 7 14:33:09 2005 Kouhei Sutou <kou@cozmixng.org>
- * test/rss/test_maker_dc.rb (test_date): added a test for #date=
- and #dc_date=.
+ * lib/rss/maker/base.rb: added default current_element implementation.
+
-Thu Apr 7 11:49:53 2005 Kouhei Sutou <kou@cozmixng.org>
+ * lib/rss/trackback.rb (RSS::TrackBackUtils.new_with_value_if_need):
+ moved to RSS::Utils.
+
+ * lib/rss/utils.rb (RSS::Utils.new_with_value_if_need):
+ moved from RSS::TrackBackUtils.
- * lib/rss/maker/dublincore.rb: _really_ supported multiple Dublin
- Core items.
+
+ * lib/rss/maker/image.rb: fixed invalid argument of
+ add_need_initialize_variable bug.
+ * lib/rss/maker/trackback.rb: ditto.
+
+
+ * lib/rss/rss.rb (Hash#merge): added for ruby 1.6.
+
+ * lib/rss/rss.rb (RSS::BaseModel.date_writer): changed to accept nil
+ for date value.
+
+
+ * test/test_dublincore.rb: added tests for plural accessor and
+ multiple Dublin Core items.
+
+ * test/test_setup_maker_1.0.rb: fixed swapped actual and expected
+ values.
* test/rss/rss-assertions.rb (assert_multiple_dublin_core): added
an assertion for testing multiple Dublin Core items.
@@ -10119,18 +9182,9 @@ Thu Apr 7 11:49:53 2005 Kouhei Sutou <kou@cozmixng.org>
* test/rss/test_maker_dc.rb (test_rss10_multiple): added a test
for making multiple Dublin Core items.
-Wed Apr 6 16:06:30 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * test/ruby/test_env.rb (test_key): should test ENV.key instead of
- ENV.index. [ruby-dev:25994]
-
-Tue Apr 5 16:01:12 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/*: refactored.
- - gave a name to 'x'.
- - undef_method -> remove_method for avoiding a warning in ruby 1.6.
+ * test/rss/test_maker_dc.rb (test_date): added a test for #date=
+ and #dc_date=.
-Tue Apr 5 15:45:33 2005 Kouhei Sutou <kou@cozmixng.org>
* sample/rss/tdiary_plugin/rss-recent.rb:
new option: @options['rss-recent.use-image-link']:
@@ -10139,46 +9193,54 @@ Tue Apr 5 15:45:33 2005 Kouhei Sutou <kou@cozmixng.org>
* sample/rss/tdiary_plugin/rss-recent.rb (RSS_RECENT_VERSION):
0.0.5 -> 0.0.6.
-Tue Apr 5 15:15:26 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/dublincore.rb: supported multiple Dublin Core items.
+Fri Apr 8 20:17:48 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/rss/parser.rb: added class name registry for complex model
- elements. (ex. have childlen elements, have some attributes and
- a child element and so on.)
+ * ext/extmk.rb (extmake): hdrdir needs to be defined also in
+ Config::CONFIG.
- * lib/rss/maker/base.rb: added default current_element implementation.
+ * lib/mkmf.rb (configuration, create_makefile): get rid of recursive
+ macro reference.
- * lib/rss/maker/dublincore.rb: supported multiple Dublin Core
- items.
+Fri Apr 8 18:26:56 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * lib/rss/maker/image.rb: supproted new Dublin Core API.
+ * ext/openssl/ossl_ssl.c: add callbacks to OpenSSL::SSL::SSLContexts.
+ - SSLContext#client_cert_cb=(aProc). it is called when a client
+ certificate is requested by a server and no certificate was not
+ set for the SSLContext. it must return an Array which includes
+ OpenSSL::X509::Certificate and OpenSSL::PKey::RSA/DSA objects.
+ - SSLContext#tmp_dh_callback=(aProc). it is called in key
+ exchange with DH algorithm. it must return an OpenSSL::PKey::DH
+ object.
+ * ext/openssl/ossl_ssl.c (ossl_sslctx_set_ciphers): ignore the
+ argument if it's nil.
- * lib/rss/trackback.rb (RSS::TrackBackUtils.new_with_value_if_need):
- moved to RSS::Utils.
+ * ext/openssl/ossl_pkey.c
+ (GetPrivPKeyPtr, ossl_pkey_sign): should call rb_funcall first.
+ (DupPrivPKeyPtr): new function.
- * lib/rss/utils.rb (RSS::Utils.new_with_value_if_need):
- moved from RSS::TrackBackUtils.
+ * ext/openssl/ossl_pkey_dh.c: add default DH parameters.
+ * ext/openssl/ossl_pkey.h: ditto.
- * lib/rss/maker/image.rb: fixed invalid argument of
- add_need_initialize_variable bug.
+Fri Apr 8 01:55:20 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * lib/rss/maker/trackback.rb: ditto.
+ * ext/tk/sample/demos-{en,jp}/goldberg.rb: reduced window size.
+ [ruby-dev:25992]
+Thu Apr 7 23:58:40 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/rss/rss.rb (Hash#merge): added for ruby 1.6.
+ * ext/extmk.rb (extmake): keep directory names in Makefile as macros.
- * lib/rss/rss.rb (RSS::BaseModel.date_writer): changed to accept nil
- for date value.
+ * lib/mkmf.rb (configuration, create_makefile): ditto.
+ * lib/mkmf.rb (CXX_EXT): separate C++ extensions.
- * test/test_dublincore.rb: added tests for plural accessor and
- multiple Dublin Core items.
+Thu Apr 7 17:43:25 2005 Shugo Maeda <shugo@ruby-lang.org>
- * test/test_setup_maker_1.0.rb: fixed swapped actual and expected
- values.
+ * eval.c (rb_call0): "return" event hook should be always executed
+ if event_hooks is set. fixed: [ruby-core:04662]
+ (backported from HEAD)
Mon Apr 4 23:17:52 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -10193,6 +9255,11 @@ Mon Apr 4 10:26:48 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/tk/lib/tk/dialog.rb: fixed typo.
+Sun Apr 3 17:16:33 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * win32/win32.{h,c} (rb_w32_fdopen): avoid warning on bcc32.
+ (backported from HEAD)
+
Sat Apr 2 23:38:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (CP, INSTALL): get rid of less portable options.
@@ -10200,8 +9267,8 @@ Sat Apr 2 23:38:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (configuration, create_makefile): correct configuration
variable.
- * wince/configure.bat, wince/setup.mak: add prefix, extstatic and
- rdoc options.
+ * {bcc32,win32,wince}/{Makefile.sub,setup.mak}: leave prefix empty in
+ config.status for backward compatibility. fixed: [ruby-core:04649]
* lib/mkmf.rb (create_makefile): ensure library directories get made
before copying libraries there.
@@ -10220,11 +9287,6 @@ Sat Apr 2 16:59:46 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/autoload.rb: add autoload entry 'TkDialogObj' and
'TkWarningObj'
-Sat Apr 2 13:23:17 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * hash.c (env_key): ENV.index is deprecated as well as Hash#index.
- use ENV.key instead. [ruby-dev:25974]
-
Sat Apr 2 02:19:11 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb (TkWindow.initialize): accept 'without_creating'
@@ -10241,39 +9303,12 @@ Thu Mar 31 22:23:51 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* README.EXT, README.EXT.ja (Appendix C): utility functions.
-Thu Mar 31 14:08:43 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Mar 31 14:15:44 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_engine.c (ossl_engine_s_load): should return
value. [ruby-dev:25971]
-Thu Mar 31 11:07:50 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/parser.rb: @@setter -> @@setters.
-
- * lib/rss/parser.rb
- (RSS::BaseListener.register_uri)
- (RSS::BaseListener.uri_registered?)
- (RSS::BaseListener.install_get_text_element):
- swapped the first argument and the second argument.
-
- * lib/rss/taxonomy.rb: swapped the first argument and the second
- argument for RSS::BaseListener.install_get_text_element.
- * lib/rss/image.rb: ditto.
- * lib/rss/syndication.rb: ditto.
- * lib/rss/dublincore.rb: ditto.
- * lib/rss/parser.rb: ditto.
- * lib/rss/1.0.rb: ditto.
- * lib/rss/2.0.rb: ditto.
- * lib/rss/0.9.rb: ditto.
- * lib/rss/content.rb: ditto.
-
-Thu Mar 31 11:00:36 2005 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/parser.rb
- (RSS::BaseListener.install_setter)
- (RSS::BaseListener.register_uri): changed fallback way.
-
-Thu Mar 31 08:25:40 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Mar 31 08:25:50 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* common.mk (RUBYOPT): clear for the environment RubyGems installed.
@@ -10287,10 +9322,21 @@ Thu Mar 31 06:00:20 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
error even if the specified engine could not be loaded. (Dynamic
engines don't have fixed name to load.)
+Thu Mar 31 00:18:27 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * win32/ifchange.bat, win32/rm.bat: backported from HEAD.
+
+Wed Mar 30 23:44:50 2005 Nobuyoshi Nakada <nobu.nokada@softhome.net>
+
+ * Makefile.in, */Makefile.sub, */configure.bat,
+ cygwin/GNUmakefile.in, common.mk, configure.in, ext/extmk.rb,
+ lib/mkmf.rb, instruby.rb, runruby.rb: backport extout.
+ [ruby-dev:25963]
+
Wed Mar 30 17:41:48 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tcltklib.c: add TclTkIp#_create_console() method to create
- a Tcl/Tk's console window.
+ * ext/tcltklib/tcltklib.c: add TclTkIp#_create_console() method to
+ create a Tcl/Tk's console window.
* ext/tk/lib/multi-tk.rb: support TclTkIp#_create_console() method.
@@ -10304,12 +9350,12 @@ Wed Mar 30 17:41:48 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/tkextlib/**: ditto.
-Tue Mar 29 22:20:49 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Tue Mar 29 22:11:56 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/rinda/test_rinda.rb: use DRbObject.new_with instead of reinit.
[ruby-dev:25961]
-Tue Mar 29 00:04:57 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Mon Mar 28 23:40:40 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb: move method DRbObject#reinit to DRbObject.new_with.
extract method DRbObject.prepare_backtrace. add DRb.regist_server,
@@ -10318,23 +9364,15 @@ Tue Mar 29 00:04:57 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/gw.rb: ditto.
-Mon Mar 28 20:53:44 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Mar 28 20:43:34 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/extmk.rb (extract_makefile): nothing to be removed when no file
- was deleted.
-
- * ext/extmk.rb (extmake): restore srcdir.
+ * ext/syck/rubyext.c: get rid of warnings caused by a bug of VC.
Mon Mar 28 08:39:49 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/iconv/iconv.c (iconv_create): Iconv::Failure requires 3
arguments. (pointed out by NaHi)
-Sun Mar 27 00:56:58 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (remove_file): ignore Errno::E* if force option
- is set. [ruby-dev:25944]
-
Sat Mar 26 22:51:33 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb (_callback_entry_class?): add for checking whether
@@ -10390,26 +9428,31 @@ Thu Mar 24 23:10:44 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (check_sizeof): refine logging messages.
-Wed Mar 23 19:08:10 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Mar 24 03:57:48 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/utils.rb (WEBrick::Utils.create_listeners):
- should raise ArgumentError if no port is specified.
- even if the specified port is 0, all TCPServers should be
- initialized with the port given to the first one.
+ initialized with the port given to the first one.
* lib/webrick/server.rb (WEBrick::GenericServer#initialize): if :Port
parameter is 0, it should be updated with the port number which
- ectually listened.
-
-Wed Mar 23 16:12:40 2005 Shugo Maeda <shugo@ruby-lang.org>
-
- * parse.y (primary): fix lineno of rescue and ensure.
+ actually listened.
-Wed Mar 23 00:39:05 2005 Shugo Maeda <shugo@ruby-lang.org>
+Wed Mar 23 00:35:10 2005 Shugo Maeda <shugo@ruby-lang.org>
* test/ruby/test_settracefunc.rb (test_event): added tests for
"class" and "end" and "raise".
+Tue Mar 22 22:40:18 2005 Shugo Maeda <shugo@ruby-lang.org>
+
+ * eval.c (rb_call0): check event_hooks instead of trace_func.
+
+Tue Mar 22 17:30:44 2005 Shugo Maeda <shugo@ruby-lang.org>
+
+ * eval.c (rb_add_event_hook): new function to add a hook function for
+ interpreter events. (backported form HEAD)
+
Sun Mar 20 22:51:19 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (mkmf_failed): check if Makefile is created without
@@ -10435,42 +9478,28 @@ Thu Mar 17 17:42:13 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* struct.c (inspect_struct): ditto.
-Wed Mar 16 23:39:13 2005 Shugo Maeda <shugo@ruby-lang.org>
-
- * test/ruby/test_settracefunc.rb: added test for c-return.
-
-Wed Mar 16 22:57:43 2005 Shugo Maeda <shugo@ruby-lang.org>
+Wed Mar 16 23:36:02 2005 Shugo Maeda <shugo@ruby-lang.org>
* eval.c (rb_call0): call_cfunc() should be protected.
- * eval.c (rb_add_event_hook): use K&R style.
-
- * eval.c (rb_remove_event_hook): ditto.
+ * test/ruby/test_settracefunc.rb: added test for c-return.
-Wed Mar 16 22:03:15 2005 Shugo Maeda <shugo@ruby-lang.org>
+Wed Mar 16 22:20:25 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * eval.c (rb_add_event_hook): new function to add a hook function for
- interpreter events.
+ * object.c (str_to_id): fixed typo.
Wed Mar 16 18:08:32 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_call0): reorganize "return" event post.
- * eval.c (return_jump): no need to post "return" event here.
-
Tue Mar 15 23:49:19 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/iconv/iconv.c (Init_iconv): InvalidEncoding also should include
Iconv::Failure.
-Tue Mar 15 23:12:36 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Mar 15 16:38:11 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * eval.c (recursive_check, recursive_push): more restrictive check.
- fixed: [ruby-dev:25916]
-
-Tue Mar 15 16:38:31 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tkutil/tkutil.c (ary2list): give wrong arguments to hash2kv()
+ * ext/tk/tkutil.c (ary2list): give wrong arguments to hash2kv()
Mon Mar 14 19:39:33 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -10486,8 +9515,7 @@ Mon Mar 14 12:21:03 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Mon Mar 14 08:14:56 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * object.c (str_to_id): raise ArgumentError for NUL containing
- strings.
+ * object.c (str_to_id): warn for NUL containing strings.
Mon Mar 14 00:13:49 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -10507,37 +9535,14 @@ Mon Mar 14 00:13:49 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/demos-jp/tcolor: ditto.
-Sun Mar 13 22:19:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (recursive_pop): raise TypeError instead of fatal error.
- fixed: [ruby-dev:25843]
-
-Sun Mar 13 10:09:17 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sun Mar 13 10:04:17 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/rinda/test_rinda.rb: remove test_gc. [ruby-dev:25871]
-Sun Mar 13 02:32:54 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_ssl.c (ossl_tmp_dh_callback): should get DH
- parameter from the current SSL object.
-
-Sun Mar 13 02:09:03 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Mar 10 19:12:06 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/openssl/ossl_pkey_dh.c (ossl_create_dh): fix typo.
- patch from IWATSUKI Hiroyuki. [ruby-dev:25867]
-
- * ext/openssl/ossl_ssl.c (ossl_tmp_dh_callback): ditto.
- (ossl_call_tmp_dh_callback): ditto
-
-Fri Mar 11 03:24:59 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (primary): wrong var node was set for NODE_LAMBDA.
- [ruby-core:04555]
-
-Thu Mar 10 19:10:29 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tcltklib.c (lib_eventloop_ensure): mis-delete a timer handler
- when exit from a recursive called eventloop
+ * ext/tcltklib/tcltklib.c (lib_eventloop_ensure): mis-delete a timer
+ handler when exit from a recursive called eventloop
* ext/tk/lib/tk/timer.rb: new TkRTTimer class, which can works for a
realtime operation
@@ -10558,48 +9563,18 @@ Thu Mar 10 08:10:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* re.c (make_regexp): need to free internal regexp structure when
compilation fails. [ruby-talk:133228]
-Thu Mar 10 01:08:20 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (bv_decl): remove initialize rule from block local
- variable declaration.
+Wed Mar 9 20:25:58 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-Wed Mar 9 23:55:34 2005 Tanaka Akira <akr@m17n.org>
-
- * lib/pp.rb (PP::PPMethods#guard_inspect_key): support
- __recursive_key__. [ruby-dev:25821]
-
-Wed Mar 9 19:42:21 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_ssl.c: OpenSSL::SSL::SSLContexts suports callbacks:
- - SSLContext#client_cert_cb is a Proc. it is called when a client
- certificate is requested by a server and no certificate was yet
- set for the SSLContext. it must return an Array which includes
- OpenSSL::X509::Certificate and OpenSSL::PKey::RSA/DSA objects.
- - SSLContext#tmp_dh_callback is called in key exchange with DH
- algorithm. it must return an OpenSSL::PKey::DH object.
-
- * ext/openssl/ossl_ssl.c:
- (ossl_sslctx_set_ciphers): ignore the argument if it's nil.
- (ossl_start_ssl, ossl_ssl_write): call rb_sys_fail if errno isn't 0.
- [ruby-dev:25831]
-
- * ext/openssl/ossl_pkey.c
- (GetPrivPKeyPtr, ossl_pkey_sign): should call rb_funcall first.
- (DupPrivPKeyPtr): new function.
-
- * ext/openssl/ossl_pkey_dh.c: add default DH parameters.
-
- * ext/openssl/ossl_pkey.h: ditto.
+ * ext/openssl/ossl_ssl.c (ossl_start_ssl, ossl_ssl_write): call
+ rb_sys_fail if errno isn't 0. [ruby-dev:25831]
* ext/openssl/lib/openssl/cipher.rb: fix typo. [ruby-dev:24285]
-Wed Mar 9 18:09:51 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (gettable_gen): warns if VCALL name is used as
- out-of-scope block local variable. [EXPERIMENTAL]
+Wed Mar 9 15:46:35 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * parse.y (opt_bv_decl): add explicit block local variable
- declaration. raises error for name conflicts. [EXPERIMENTAL]
+ * lib/webrick/server.rb (WEBrick::GenericServer#start): should
+ restore @token if accept failure. suggested by Dominique Brezinski.
+ [ruby-core:04518]
Wed Mar 9 13:37:57 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -10612,10 +9587,9 @@ Tue Mar 8 18:16:55 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
sample supports to use a text widget as if it is a I/O stream (such
like as StringIO class).
-Tue Mar 8 13:39:25 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Mar 8 13:54:40 2005 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/socket/mkconstants.rb: workaround for some of 4.4BSD-Lite
- derived OSs.
+ * ext/socket/socket.c: workaround for some of 4.4BSD-Lite derived OSs.
Tue Mar 8 12:36:17 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -10623,275 +9597,159 @@ Tue Mar 8 12:36:17 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
<sroberts@uniserve.com> for getsockopt and setsockopt is merged.
[ruby-doc:824]
-Tue Mar 8 10:48:53 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * eval.c (rb_exec_recursive): declaration should precede statements
- before C99.
-
-Tue Mar 8 10:05:40 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * error.c (errno_missing): Errno.const_missing to allow references
- to SyscallError exceptions not defined on the platform.
- [ruby-core:04522]
-
- * error.c (Init_syserr): Errno::NOERROR(0) for fallback exception.
-
-Tue Mar 8 01:19:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
+Tue Mar 8 01:27:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/nkf-utf8/nkf.c: follow nkf 1.66
fixed: [ruby-dev:25828]
-Mon Mar 7 21:29:40 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/server.rb (WEBrick::GenericServer#start): should
- restore @token if accept failure. suggested by Dominique Brezinski.
- [ruby-core:04518]
+Mon Mar 7 21:35:02 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* sample/webrick/httpsd.rb: fix typo in comment. suggested by
Kazuhiko Shiozaki.
-Mon Mar 7 21:01:37 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_require_safe): get actual path string under safe level
- when requested. fixed: [ruby-dev:25815]
-
-Mon Mar 7 16:46:02 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/openssl/ossl_ssl.c (ossl_start_ssl, ossl_ssl_read,
- ossl_ssl_write): need to set errno on Win32 platform.
-
Mon Mar 7 14:55:43 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (block_pass): should not push unique number if a block is
not an orphan. [ruby-dev:25808]
-Mon Mar 7 14:13:23 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/lib/openssl/buffering.rb (Buffering#initialize):
- should set @eof and @rbuffer.
-
-Mon Mar 7 10:28:00 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (inspect_obj): unintended space removal.
- [ruby-dev:25810]
+Wed Feb 16 02:55:21 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * eval.c (rb_exec_recursive): should not use NODE in disclosed
- context. [ruby-dev:25812]
-
- * io.c (rb_f_open): need not to check if to_open value is a
- T_FILE. [ruby-dev:25812]
-
-Mon Mar 7 01:21:01 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tkutil/tkutil.c: follow the change of st.c (committed
- at Fri, 4 Mar 2005 15:47:47 +0900 by matz)
-
-Mon Mar 7 00:01:55 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tcltklib.c: fail to call TclTkLib.mainloop when $SAFE==4
-
-Sun Mar 6 13:04:10 2005 Dee Zsombor <zsombor@ruby-lang.org>
-
- * misc/ruby-electric.el: added.
- * misc/Readme: updated.
-
-Sun Mar 6 11:47:10 2005 Sam Roberts <sroberts@uniserve.com>
-
- * lib/pp.rb: rdoced. [ruby-core:4490]
-
-Sun Mar 6 11:36:37 2005 Tanaka Akira <akr@m17n.org>
-
- * lib/pp.rb (File::Stat#pretty_print): Etc.getpwuid and Etc.getgrgid
- may return nil. [ruby-talk:129826]
- reported by Daniel Berger.
-
-Sun Mar 6 06:34:31 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_ssl.c (ossl_start_ssl): should wait for that
- the underlying IO become readable or writable if the error was
- SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. [ruby-dev:25795]
-
- * ext/openssl/ossl_ssl.c (ossl_ssl_read, ossl_ssl_write): ditto.
+ * ext/openssl/ossl_ssl.c (ossl_start_ssl, ossl_ssl_read,
+ ossl_ssl_write):
+ - need to set errno on Win32 platform.
+ - should call rb_sys_fail instead of rasing SSLError if
+ SSL_ERROR_SYSCALL occured.
+ - should wait for that the underlying IO become readable or
+ writable if the error was SSL_ERROR_WANT_READ or
+ SSL_ERROR_WANT_WRITE. [ruby-dev:25795]
* ext/openssl/lib/openssl/buffering.rb
+ (Buffering#initialize): should set @eof and @rbuffer.
+ (Buffering#fill_rbuff): should rescue Errno::EAGAIN.
(Buffering#consume_rbuf): pointless eof flag resetting is deleted.
(Buffering#read): should return an empty string if the specified
size is zero.
(Buffering#readpartial): new method.
(Buffering#readline): fix typo.
(Buffering#getc): return the first character of string correctly.
+ (Buffering#each): fix typo. suggested by Brian Ollenberger.
(Buffering#readchar): fix typo.
(Buffering#eof?): should read again it the input buffer is empty.
(Buffering#do_write): should rescue Errno::EAGAIN.
(Buffering#puts): use "\n" as the output field separator.
+ * ext/openssl/lib/openssl/ssl.rb: set non-blocking flag to the
+ underlying IO.
+
* ext/openssl/extconf.rb: get rid of GNUmakefile generation.
* text/openssl/test_pair.rb: test for IO like methods.
* test/ruby/ut_eof.rb: test about empty file.
-Sat Mar 5 17:48:31 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (rb_glob): fixed mismatch of argument.
+Mon Mar 7 10:22:06 2005 WATANABE Hirofumi <eban@ruby-lang.org>
- * dir.c (fnmatch): removed unnecessary code. (by string.c 1.219)
+ * lib/un.rb: should use OptionParser. (backported form HEAD)
- * win32/win32.c (NtInitialize): ditto. (by numeric.c 1.117)
+Mon Mar 7 09:18:42 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-Sat Mar 5 16:50:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
+ * string.c (rb_str_cmp_m): should not return false but nil.
+ fixed: [ruby-dev:25811]
- * ext/nkf/nkf-utf8/nkf.c: follow nkf 1.65
+Mon Mar 7 01:22:14 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-Sat Mar 5 16:29:26 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/multi-tk.rb: freeze callback-entry objects
+ * ext/tk/tkutil.c: remove the some codes which depend on the
+ difference between Ruby1.8 and 1.9, because st.c on Ruby1.9
+ was changed.
- * ext/tk/lib/tkextlib/tile.rb: support tile-0.6
+Mon Mar 7 00:01:04 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-Sat Mar 5 12:52:08 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/tcltklib/tcltklib.c: fail to call TclTkLib.mainloop when $SAFE==4
- * lib/mkmf.rb (create_makefile): allow putting spaces between target
- and colon in depend file.
+Sun Mar 6 16:41:33 2005 Minero Aoki <aamine@loveruby.net>
-Sat Mar 5 02:41:00 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+ * lib/net/http.rb: HTTPHeader holds its header fields as an array
+ (backport from CVS HEAD rev 1.112-1.123). [ruby-list:40629]
- * file.c (eaccess): workaround for VC++8 runtime.
-
- * win32/win32.c (ioinfo): VC++8 support.
+ * test/net/http/test_httpheader.rb: new file.
-Fri Mar 4 19:39:55 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#do_includes): replace
- also locally defined modules.
-
- * ext/iconv/iconv.c: rdocified.
-
- * ext/strscan/strscan.c: moved misplaced rdoc.
-
-Fri Mar 4 16:11:20 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * eval.c (rb_exec_recursive): matched the declaration to prototype.
-
- * ext/curses/curses.c: don't need to check HAVE_WCOLOR_SET excluding
- window_color_set().
+Sun Mar 6 11:47:10 2005 Sam Roberts <sroberts@uniserve.com>
- * ext/tk/tcltklib.c: fixed commit mistakes.
+ * lib/pp.rb: rdoced. [ruby-core:4490]
-Fri Mar 4 12:45:17 2005 Tilman Sauerbeck <tilman@code-monkey.de>
+Sun Mar 6 11:36:37 2005 Tanaka Akira <akr@m17n.org>
- * lib/rdoc/parsers/parse_c.rb: allow whitespace after function names.
- [ruby-core:4296]
+ * lib/pp.rb (File::Stat#pretty_print): Etc.getpwuid and Etc.getgrgid
+ may return nil. [ruby-talk:129826]
+ reported by Daniel Berger.
- * lib/rdoc/parsers/parse_simple.rb: adds support for private comments
- in the "simple" parser. [ruby-core:4301]
+Sat Mar 5 18:06:21 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-Fri Mar 4 12:45:17 2005 Charles Mills <cmills@freeshell.org>
+ * dir.c (fnmatch): removed unnecessary code. (ruby_1_8 didn't have
+ String#clear, so [ruby-dev:24749] didn't affect it)
- * lib/rdoc/parsers/parse_c.rb: adds support for constants
- (rb_define_const), accessors (rb_define_attr), and makes a
- couple fixes. [ruby-core:4307]
+ * win32/win32.c (NtInitialize): ditto. (by numeric.c 1.101.2.14)
-Fri Mar 4 12:45:17 2005 Florian Gross <florgro@gmail.com>
+Sat Mar 5 16:29:26 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * lib/rdoc/parsers/parse_rb.rb: Logic for def Builtin.method() end
- [ruby-core:4302]
+ * ext/tk/lib/multi-tk.rb: freeze callback-entry objects
-Fri Mar 4 12:45:17 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/tk/lib/tkextlib/tile.rb: support tile-0.6
- * array.c: replace rb_protect_inspect() and rb_inspecting_p() by
- rb_exec_recursive() in eval.c.
+Fri Mar 4 19:39:28 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (rb_exec_recursive): new function.
+ * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#do_includes): replace
+ also locally defined modules.
- * array.c (rb_ary_join): use rb_exec_recursive().
+ * ext/iconv/iconv.c: backport Iconv::InvalidEncoding from CVS HEAD.
- * array.c (rb_ary_inspect, rb_ary_hash): ditto.
+ * ext/strscan/strscan.c: moved misplaced rdoc.
- * file.c (rb_file_join): ditto.
+Fri Mar 4 15:58:12 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
+ * lib/cgi-lib.rb: add deprecation warning. [ruby-dev:25499]
+ getopts.rb, parsearg.rb, importenv.rb as well.
- * io.c (rb_io_puts): ditto.
+Fri Mar 4 11:17:06 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * object.c (rb_obj_inspect): ditto
+ * ext/tcltklib/tcltklib.c (ip_rbUpdateCommand): get rid of
+ warnings with Tcl/Tk 8.3 or former (backport from CVS_HEAD).
- * struct.c (rb_struct_inspect): ditto.
+ * ext/tcltklib/tcltklib.c (ip_rb_threadUpdateCommand): ditto.
Fri Mar 4 10:15:30 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
-Fri Mar 4 09:37:12 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * common.mk (install-nodoc, pre-install-doc, post-install-doc):
- fix some omissions.
-
-Fri Mar 4 08:09:12 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/time.rb (Time::strptime): add new function. inspired by
- [ruby-talk:132815].
-
- * lib/parsedate.rb (ParseDate::strptime): ditto.
-
Fri Mar 4 07:07:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/nkf-utf8/nkf.c: follow nkf 1.63
-Thu Mar 3 23:24:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
+Thu Mar 3 23:49:00 2005 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/nkf-utf8/nkf.c: follow nkf 1.62
-Thu Mar 3 18:47:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * {bcc32,win32,wince}/Makefile.sub (config.h): check if affected
- when makefiles are modified.
-
- * {bcc32,win32,wince}/Makefile.sub (config.status): add variables
- for tests.
-
- * win32/ifchange.bat: try to update a file only if modified.
-
- * win32/resource.rb: more descriptions.
-
- * common.mk: add {pre,post}-install targets.
-
- * instruby.rb (install?): install particular part.
-
- * bcc32/Makefile.sub (post-install-ext): remove debug information
- files after installation.
-
- * ext/tk/tcltklib.c (ip_rbUpdateCommand, ip_rb_threadUpdateCommand):
- get rid of warnings with Tcl/Tk 8.3 or former.
-
Thu Mar 3 11:49:51 2005 Kouhei Sutou <kou@cozmixng.org>
* sample/rss/tdiary_plugin/rss-recent.rb: added site information.
-Wed Mar 2 19:53:44 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb (parse_args): return false if nothing matched.
-
-Wed Mar 2 17:15:08 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tcltklib.c (lib_eventloop_core): fix typo
+Wed Mar 2 19:53:07 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Wed Mar 2 16:59:50 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+ * ext/extmk.rb (parse_args): add DESTDIR only when not directed
+ already. fixed: [ruby-dev:25781]
- * eval.c (ruby_native_thread_kill): call pthread_kill() to send a
- signal to ruby's native thread
+Wed Mar 2 17:14:18 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ruby.h: add definition of ruby_native_thread_kill()
+ * ext/tcltklib/tcltklib.c (lib_eventloop_core): fix typo
- * signal.c (sigsend_to_ruby_thread): send the signal to ruby's
- native thread ([ruby-dev:25744], [ruby-dev:25754]), and set
- signal mask to the current native thread
+Wed Mar 2 16:00:02 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-Wed Mar 2 16:03:08 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tcltklib.c: enforce thread-check and exception-handling to
- avoid SEGV trouble.
+ * ext/tcltklib/tcltklib.c: enforce thread-check and exception-handling
+ to avoid SEGV trouble.
+ [KNOWN BUG] When supports pthread and running multiple Tk
+ interpreters, an interrupt signal causes SEGV frequently. That
+ may be a trouble of Ruby's signal handler.
* ext/tk/tkutil/tkutil.c; fix a bug on converting a SJIS string array
to a Tcl's list string.
@@ -10935,58 +9793,17 @@ Wed Mar 2 16:03:08 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/demos-*/widget: add entries of animation demos.
-Wed Mar 2 12:21:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_eval): [EXPERIMENTAL] NODE_LAMBDA implemented.
- [ruby-dev:25780]
-
- * node.h (NODE_LAMBDA): for literal Proc object.
-
- * parse.y (expr): interpret mere do...end block as proc object.
-
- * parse.y (primary): ditto, for brace block.
-
-Tue Mar 1 21:16:54 2005 K.Kosako <sndgk393 AT ybb.ne.jp>
+Tue Mar 1 00:47:43 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * regcomp.c (optimize_node_left): uninitialized member
- (OptEnv.backrefed_status) was used. [ruby-dev:25778]
+ * test/rinda/test_rinda.rb: backport from CVS_HEAD. use
+ MockClock.sleep instead of Kernel.sleep [ruby-dev:25387]
-Tue Mar 1 16:50:37 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * regparse.c: move st_*_strend() functions from st.c. fixed some
- potential memory leaks.
-
-Tue Mar 1 00:40:35 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Tue Mar 1 00:34:24 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/rinda/tuplespace.rb (Rinda::TupleSpace): improved keeper thread.
* test/rinda/test_rinda.rb: ditto.
-Mon Feb 28 23:10:13 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ext/socket/socket.c (Init_socket): IPv6 is not supported although
- AF_INET6 is defined on bcc32. (rev1.108 again)
-
- * ext/socket/mkconstants.rb: ditto.
-
-Mon Feb 28 21:55:49 2005 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * ext/strscan/strscan.c (strscan_s_allocate):
- use onig_region_init().
-
- * ext/strscan/strscan.c (adjust_registers_to_matched):
- use onig_region_set().
-
-Mon Feb 28 15:12:06 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ext/socket/socket.c (Init_socket): ported more Socket::Constants
- from ruby_1_8, and made it easy to add new constants.
- [ruby-dev:25771]
-
- * ext/socket/depend: ditto.
-
- * ext/socket/mkconstants.rb: ditto. (added)
-
Mon Feb 28 11:42:23 2005 Ian Macdonald <ian@caliban.org>
* exception error messages updated. [ruby-core:04497]
@@ -10997,27 +9814,6 @@ Mon Feb 28 09:03:09 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
-Sun Feb 27 05:55:38 2005 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: fix typo. [ruby-core:04494]
-
-Sat Feb 26 16:58:20 2005 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * parse.y, re.c, regex.h, LEGAL, ext/strscan/strscan.c:
- remove oniggnu.h (GNU regex API).
-
-Wed Feb 23 22:08:16 2005 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * st.c, st.h: imported additional file changes on
- Oniguruma 3.7.0.
-
-Wed Feb 23 21:45:29 2005 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c,
- regenc.c, regenc.h, regerror.c, regexec.c, regint.h,
- regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma
- 3.7.0.
-
Wed Feb 23 15:04:32 2005 akira yamada <akira@ruby-lang.org>
* lib/uri/generic.rb (split_userinfo): should split ":pass" into ""
@@ -11030,53 +9826,27 @@ Wed Feb 23 08:00:18 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_unshift_m): ditto.
-Wed Feb 23 01:53:29 2005 Shugo Maeda <shugo@ruby-lang.org>
+Wed Feb 23 01:57:46 2005 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (initialize): handle certs correctly. Thanks,
- NABEYA Kenichi.
-
-Wed Feb 23 00:37:34 2005 Kouhei Sutou <kou@cozmixng.org>
+ NABEYA Kenichi. (backported from CVS HEAD)
- * lib/mkmf.rb (mkmf_failed): fixed typo.
+Tue Feb 22 07:25:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Tue Feb 22 23:52:45 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * parse.y (parser_yylex): identfier after dot must not be a variable.
- * configure.in, lib/mkmf.rb: use simple commands if available.
-
- * mkconfig.rb: remove autoconf internal variables from rbconfig.rb.
-
- * lib/mkmf.rb (create_makefile): substitute implicit rules in depend
- file.
+Mon Feb 21 10:04:49 2005 NAKAMURA Usaku <usa@ruby-lang.org>
- * {bcc32,win32,wince}/Makefile.sub (COMPILE_RULES, RULE_SUBST):
- include $(topdir) and $(hdrdir) to search path.
-
-Tue Feb 22 23:51:45 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/syck/rubyext.c: get rid of warnings caused by a bug of VC.
-
-Tue Feb 22 23:50:26 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * signal.c (ruby_signal, ruby_nativethread_signal): must be valid as
- expressions, not only statements.
-
-Tue Feb 22 12:54:13 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_thread_start_0): update curr_thread before raising
- TAG_THREAD. [ruby-dev:25712]
-
-Tue Feb 22 07:24:57 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * {bcc32,win32,wince}/Makefile.sub (config.h): add fcntl.
- * parse.y (parser_yylex): identifier after dot must not be a variable.
+ * win32/win32.[ch] (fcntl): ditto.
-Mon Feb 21 18:31:12 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+ * win32/win32.c (rb_w32_connect): support nonblocking mode.
- * signal.c: Standard signal handlers ignore signals on non-Ruby native
- threads. When a handler is entried with ruby_signal() (like as the
- standard signal handlers), the handler for the signal is marked as
- it cannot accept non-Ruby native threads. If a handler can treat all
- signals on all native threads, please use ruby_nativethread_signal()
- to entry it.
+ * ext/socket/socket.c (wait_connectable, ruby_connect): support
+ nonblocking connect on various platforms.
+ all changes are backported from CVS HEAD. [ruby-core:3154],
+ [ruby-core:4364].
Sun Feb 20 00:48:48 2005 Tanaka Akira <akr@m17n.org>
@@ -11084,7 +9854,7 @@ Sun Feb 20 00:48:48 2005 Tanaka Akira <akr@m17n.org>
re-implemented according to RFC 1738.
reported by Guillaume Marcais. [ruby-talk:131650]
-Sat Feb 19 18:46:56 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sat Feb 19 18:11:47 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb (DRbObject#respond_to?): take two arguments.
[ruby-dev:25722]
@@ -11096,16 +9866,7 @@ Sat Feb 19 13:52:02 2005 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb: call OpenSSL::SSL::SSLSocket#post_connection_check
after connection is made.
-Sat Feb 19 13:31:28 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb (extract_makefile): remove no longer existing installed
- files.
-
- * lib/mkmf.rb (install_dirs): return installation directory list.
-
- * lib/mkmf.rb (create_makefile): reverted wrongly removed lines.
-
-Sat Feb 19 01:28:56 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sat Feb 19 01:32:03 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/bigdecimal/lib/bigdecimal/newton.rb: resolved LoadError.
[ruby-dev:25685]
@@ -11122,42 +9883,16 @@ Fri Feb 18 17:14:00 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
-Fri Feb 18 04:06:41 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (fcall_gen): lvar(arg) will be evaluated as
- lvar.call(arg) when lvar is a defined local variable. [new]
-
-Thu Feb 17 22:15:34 2005 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * ext/strscan/strscan.c: calls Oniguruma API directly.
-
-Thu Feb 17 21:53:12 2005 K.Kosako <sndgk393 AT ybb.ne.jp>
-
- * common.mk, LEGAL: remove reggnu.c.
-
-Thu Feb 17 21:53:12 2005 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * gc.c, re.c: now ruby calls Oniguruma API directly, bypassing
- GNU compatible APIs.
-
-Thu Feb 17 20:09:23 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Feb 17 20:11:18 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/drb/drb.rb (DRbServer.default_safe_level): fix typo.
-Thu Feb 17 20:09:23 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Feb 17 20:11:18 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/digest/test_digest.rb: separate test case for each algorithms.
[ruby-dev:25412]
-Thu Feb 17 14:31:52 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (rb_class_initialize): call inherited method before
- calling initializing block.
-
- * eval.c (rb_thread_start_1): initialize newly pushed frame.
- fixed: [ruby-dev:25707]
-
-Thu Feb 17 13:46:00 2005 Nathaniel Talbott <ntalbott@ruby-lang.org>
+Thu Feb 17 11:54:00 2005 Nathaniel Talbott <ntalbott@ruby-lang.org>
* lib/test/unit/collector.rb (collect_file): now deletes paths added
to $LOAD_PATH instead of restoring it verbatim.
@@ -11175,43 +9910,38 @@ Thu Feb 17 04:21:47 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
-Thu Feb 17 00:31:21 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * test/drb/test_drb.rb, ut_safe1.rb: port from 1.8
+Thu Feb 17 00:09:45 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-Thu Feb 17 00:02:27 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * test/drb/ignore_test_drb.rb: move TestDRbReusePort to new file
+ [ruby-dev:25238]
- * eval.c (is_defined): NODE_IASGN is an assignment.
+ * test/drb/test_drb.rb: add method DRbService.ext_service, move
+ TestDRbReusePort to new file [ruby-dev:25238]
-Wed Feb 16 23:54:14 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * test/drb/test_drb.rb: ditto.
- * eval.c (rb_thread_start_1): outer block variables wasn't linked to
- threads. fixed: [ruby-dev:25700]
+ * test/drb/test_drbssl.rb: ditto.
-Wed Feb 16 15:11:43 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+ * test/drb/test_drbunix.rb: ditto.
- * ext/openssl/lib/openssl/ssl.rb (OpenSSL::Nonblock#initialize):
- native win32 platform doesn't have F_GETFL.
+ * test/drb/ut_drb.rb: reduce sleep.
-Wed Feb 16 02:47:45 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Feb 17 00:02:27 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/openssl/ossl_ssl.c (ossl_ssl_read, ossl_ssl_write): should
- call rb_sys_fail instead of raising SSLError if SSL_ERROR_SYSCALL
- occurred.
+ * eval.c (is_defined): NODE_IASGN is an assignment.
- * ext/openssl/lib/openssl/buffering.rb (Buffering#fill_rbuff):
- should rescue Errno::EAGAIN.
+Wed Feb 16 23:34:30 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * ext/openssl/lib/openssl/buffering.rb (Buffering#each): fix typo.
- suggested by Brian Ollenberger.
+ * lib/drb/drb.rb: add lazy stop_service. ([druby-ja:109])
- * ext/openssl/lib/openssl/ssl.rb: set non-blocking flag to the
- underlying IO.
+ * lib/drb/extserv.rb: ditto.
-Tue Feb 15 22:14:34 2005 sheepman <sheepman@tcn.zaq.ne.jp>
+Wed Feb 16 17:07:57 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/readline/readline.c (Readline.readline): use rl_outstream
- and rl_instream. [ruby-dev:25699]
+ * ext/tk/tkutil.c: Follow the change of st.c (st_foreach)
+ [ruby-list:40623].
+ Sometimes mis-convert from a Ruby's Array of SJIS Strings, which
+ includes some kind of SJIS characters, to a Tcl's UTF8 list string.
Mon Feb 14 23:58:17 2005 Kouhei Sutou <kou@cozmixng.org>
@@ -11221,14 +9951,13 @@ Mon Feb 14 23:58:17 2005 Kouhei Sutou <kou@cozmixng.org>
Mon Feb 14 13:12:38 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/lib/openssl/ssl.rb
- (OpenSSL::SSL::SSLSocket#post_connection_check): new method.
+ (OpenSSL::SSL::SSLSocket#post_connection_check): new method.
-Mon Feb 14 00:10:17 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Mon Feb 14 00:40:49 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * lib/drb/drb.rb (DRbServer): add default_safe_level, safe_level,
- config[:safe_level] ([druby-ja:120])
+ * lib/drb/drb.rb (InvokeMethod.perform): pass DRb info to sub thread.
- * test/drb/test_drb.rb, ut_eval.rb, ut_safe1.rb: ditto.
+ * test/drb/test_drb.rb (test_01_safe1_safe4_eval): fix test case.
Sun Feb 13 23:13:46 2005 Kouhei Sutou <kou@cozmixng.org>
@@ -11241,43 +9970,22 @@ Sun Feb 13 23:13:46 2005 Kouhei Sutou <kou@cozmixng.org>
* test/rss/: added tests for the convenient methods.
-Sun Feb 13 23:12:47 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Feb 13 22:43:03 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * eval.c (rb_thread_start_0): restore prot_tag before rewinding.
+ * lib/drb/drb.rb (DRbServer): add default_safe_level, safe_level,
+ config[:safe_level] ([druby-ja:120])
+
+ * test/drb/test_drb.rb, ut_eval.rb, ut_safe1.rb: ditto.
Sun Feb 13 16:56:52 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/cgi.rb (WEBrick::CGI.start): should set reason-phrase
to the value of status header field. ([ruby-dev:40617])
-Sun Feb 13 11:38:40 2005 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * regparse.c (type_cclass_hash): (Thanks Nobu) fixed
- overrun. ([ruby-dev:25676]).
-
-Sun Feb 13 10:53:08 2005 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * oniggnu.h, oniguruma.h, regcomp.c, st.c: imported
- Oni Guruma 3.6.0.
-
-Sun Feb 13 01:33:19 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sun Feb 13 00:52:33 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/erb.rb (ERB::Util.h, u): make it module_function.
-Sat Feb 12 22:17:11 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (TAG_THREAD): to start a new thread.
-
- * eval.c (ruby_init, ruby_options, ruby_cleanup, rb_protect,
- rb_load_protect, rb_thread_start_0): make thread anchor.
-
- * eval.c (proc_alloc): clone proc object if klass is not Proc or
- created in different thread.
-
- * eval.c (rb_block_pass): call a function with a block. [new]
-
- * eval.c (rb_f_throw): raise NameError in main thread.
-
Sat Feb 12 17:29:19 2005 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb (OpenURI.open_loop): send authentication only for
@@ -11287,10 +9995,6 @@ Sat Feb 12 15:07:23 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* random.c (rand_init): suppress warning.
-Sat Feb 12 14:10:24 2005 Tanaka Akira <akr@m17n.org>
-
- * lib/open-uri.rb (OpenURI.open_http): reject userinfo explicitly.
-
Sat Feb 12 13:54:03 2005 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb: support https if the platform provides CA
@@ -11298,10 +10002,10 @@ Sat Feb 12 13:54:03 2005 Tanaka Akira <akr@m17n.org>
Sat Feb 12 06:18:28 2005 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
- * ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
+ * ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check.
[ruby-dev:25675]
-Fri Feb 11 17:37:50 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Fri Feb 11 17:40:42 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_x509store.c (ossl_x509store_set_default_paths):
new method OpenSSL::X509::Store#set_default_paths.
@@ -11323,108 +10027,68 @@ Fri Feb 11 04:54:13 2005 Tilman Sauerbeck <tilman@code-monkey.de>
* lib/rdoc/generators/ri_generator.rb: ditto.
-Thu Feb 10 13:52:42 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Feb 10 11:14:17 2005 NAKAMURA Usaku <usa@ruby-lang.org>
- * configure.in, win32/Makefile.sub (LIBS, COMMON_HEADERS): use
- winsock2 on mswin32/mingw.
+ * win32/Makefile.sub (COMMON_HEADERS): shouldn't include winsock2.h.
- * ext/socket/extconf.rb: ditto.
-
- * win32/win32.c (StartSockets): ditto.
+ * ext/socket/extconf.rb (sockaddr_storage): remove workaround for
+ mswin32.
- * win32/win32.h: ditto.
+Thu Feb 10 10:29:16 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-Thu Feb 10 12:09:16 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb (extract_makefile): default to true if not compiled
- previously.
-
- * ext/extmk.rb (extmake): create dummy makefile if extconf failed.
-
-Thu Feb 10 12:07:10 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (init_stdhandle): assign standard file handles.
-
- * bcc32/Makefile.sub (COMMON_LIBS): add libraries included in
- import32.lib.
-
- * lib/mkmf.rb (create_makefile): restrict prefixing with srcdir to
- rule lines, add search path to implicit rules, and set Borland make
- special macros for search path.
-
- * win32/win32.c, win32/win32.h (read): avoid a BCC runtime bug.
+ * ext/curses/curses.c: don't need to check HAVE_WCOLOR_SET excluding
+ window_color_set().
Thu Feb 10 00:47:25 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* struct.c (make_struct): fixed: [ruby-core:04402]
-Wed Feb 9 16:33:05 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/socket/socket.c (wait_connectable): fixed wrong condition.
-
-Wed Feb 9 14:42:28 2005 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
-
- * eval.c (scope_dup): add volatile not to optimize tbl.
-
-Wed Feb 9 10:02:02 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/tk/make-tkutil, ext/tk/tkutil/subconf.rb: no longer used.
-
- * ext/tk/tkutil/extconf.rb: need to compile tkutil. [ruby-dev:25607]
-
Wed Feb 9 08:07:08 2005 Paul Duncan <pabs@pablotron.org>
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
-Tue Feb 8 23:48:36 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Tue Feb 8 23:51:47 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb: reject :instance_eval, :class_eval, :module_eval
[druby-ja:117]
-Tue Feb 8 22:38:28 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * keywords, parse.y: separate EXPR_VALUE from EXPR_BEG.
- fixed: [ruby-core:04310], [ruby-core:04368]
-
Tue Feb 8 13:06:12 2005 Sam Roberts <sroberts@uniserve.com>
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
+Tue Feb 8 09:30:01 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/cgi.rb (CGI::Cookie): [ruby-talk:130040]
+
Tue Feb 8 00:19:02 2005 Tanaka Akira <akr@m17n.org>
* lib/resolv.rb (Resolv::DNS::Name#subdomain_of?): new method.
(Resolv::DNS::Name#inspect): ditto.
Suggested by Sam Roberts. [ruby-talk:129086]
-Mon Feb 7 23:14:11 2005 Tanaka Akira <akr@m17n.org>
-
- * io.c (io_getc): flush rb_stdout before read from stdin, which is
- connected to a tty. [ruby-core:4378]
-
- * rubyio.h (FMODE_TTY): renamed from FMODE_LINEBUF.
-
Mon Feb 7 10:06:30 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c: [ruby-doc:818]
-Mon Feb 7 02:13:05 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Mon Feb 7 01:56:20 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * instruby.rb, rubytest.rb (srcdir): no longer embed srcdir into
+ rbconfig.rb. (backported from CVS HEAD)
* ext/socket/extconf.rb (sockaddr_storage): winsock2.h have the
definition of struct sockaddr_storage, but socket.c doesn't
include it because this version of ruby still has binary level
compatibility with winsock1.
-Mon Feb 7 01:22:50 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/mkmf.rb (create_makefile): should support header files in
+ depend file.
- * ext/extmk.rb (extract_makefile): extract previously collected
- informations from existing Makefile.
+Mon Feb 7 01:21:50 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/socket/extconf.rb: check if getaddrinfo() works fine only when
wide-getaddrinfo option is not given. fixed: [ruby-dev:25422]
- * ext/tk/extconf.rb: separate tkutil configuration.
-
* lib/mkmf.rb ($extmk): check if under ext directory.
* lib/mkmf.rb (Logging.postpone): allow recursive operation.
@@ -11441,25 +10105,31 @@ Mon Feb 7 01:22:50 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (dir_config): accept arrays of directory names as
default values.
- * lib/mkmf.rb (with_cppflags, with_cflags, with_ldflags): keep flags
- modified if the block returned true.
+ * mkconfig.rb: no longer embed srcdir and compile_dir into
+ rbconfig.rb.
-Sun Feb 6 19:20:05 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+ * lib/mkmf.rb (create_makefile): fix unbalanced parens.
+
+Sun Feb 6 19:23:01 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* eval.c (stack_extend): add prototype because VC++8 doesn't
accept __declspec(noinline) with K&R style function definitions.
+ (backported from CVS HEAD)
-Sun Feb 6 13:56:19 2005 Tadayoshi Funaba <tadf@dotrb.org>
+Sun Feb 6 14:14:26 2005 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date.rb (new_with_hash): changed messages of exception.
* lib/date/format.rb (str[fp]time): undocumented conversion
specifications %[1-3] are now deprecated.
-Sun Feb 6 11:27:37 2005 Tanaka Akira <akr@m17n.org>
+Sun Feb 6 12:20:11 2005 Akinori MUSHA <knu@iDaemons.org>
+
+ * bignum.c (rb_big2ulong_pack): One too many arguments are passed
+ to big2ulong().
- * ext/dl/dl.c (Init_dl): function declaration should precede
- statements before C99.
+ * re.c (rb_reg_init_copy, rb_reg_initialize_m): One too many
+ arguments are passed to rb_reg_initialize().
Sun Feb 6 03:24:20 2005 Tanaka Akira <akr@m17n.org>
@@ -11471,28 +10141,7 @@ Sun Feb 6 03:24:20 2005 Tanaka Akira <akr@m17n.org>
(Resolv::DNS::Message::MessageDecoder#get_string_list): ditto.
based on [ruby-talk:129732] by Sam Roberts.
-Sat Feb 5 02:24:06 2005 Minero Aoki <aamine@loveruby.net>
-
- * test/ripper/test_scanner_events.rb: fix test.
-
-Fri Feb 4 18:44:35 2005 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/lib/ripper/lexer.rb: last Lexer fix was incomplete;
- test all green.
-
-Fri Feb 4 15:57:06 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (open_args): fix too verbose warnings for the space
- before argument parentheses. [ruby-dev:25492]
-
- * parse.y (parser_yylex): ditto.
-
-Fri Feb 4 14:33:25 2005 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/lib/ripper/filter.rb: ripper/tokenizer ->
- ripper/lexer. [ruby-dev:25632]
-
-Fri Feb 4 00:24:15 2005 Kouhei Sutou <kou@cozmixng.org>
+Fri Feb 4 00:30:45 2005 Kouhei Sutou <kou@cozmixng.org>
* lib/rss: supported Image module.
http://web.resource.org/rss/1.0/modules/image/
@@ -11505,19 +10154,6 @@ Thu Feb 3 23:42:36 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_extend, strio_putc): fill with zero
extended portion. [ruby-dev:25626]
-Thu Feb 3 16:12:57 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (parser_yylex): the first expression in the parentheses
- should not be a command. [ruby-dev:25492]
-
-Thu Feb 3 03:31:20 2005 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf/nkf-utf8/nkf.c: follow original v 1.57
-
- * ext/nkf/nkf-utf8/utf8tbl.c: follow original v 1.8
-
- * ext/nkf/nkf-utf8/config.h: follow original v 1.7
-
Wed Feb 2 23:52:53 2005 sheepman <sheepman@tcn.zaq.ne.jp>
* ext/stringio/stringio.c (strio_truncate): should MEMZERO an extended
@@ -11537,49 +10173,18 @@ Wed Feb 2 21:56:01 2005 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/trackback.rb: ditto.
-Wed Feb 2 03:30:58 2005 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/lib/ripper/tokenizer.rb -> lexer.rb.
-
- * ext/ripper/lib/ripper/lexer.rb: new method Ripper.slice.
- [experimental]
-
- * ext/ripper/lib/ripper/sexp.rb: new file. [experimental]
-
- * ext/ripper/lib/ripper.rb: require ripper/lexer and ripper/sexp.
-
-Tue Feb 1 21:49:24 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+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>
- * Makefile.in, configure.in: made EXTOUT configurable.
-
- * ext/extmk.rb (extmake), lib/mkmf.rb: keep topdir as relative style.
-
- * lib/mkmf.rb: make extensions in depth order. [ruby-dev:25522]
-
* configure.in (aix): fix linker flags on AIX. [ruby-talk:125460]
-Mon Jan 31 13:16:39 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/extconf.rb: add tkutil configuration step (remove old schema)
-
- * ext/tk/depend: remove the information of tkutil
-
- * ext/tk/make-tkutil: sub-part of Makefile to compile tkutil
+Mon Jan 31 13:33:21 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/tk/tkutil/tkutil.c: move tkutil.c to subdirectory
-
- * ext/tk/tkutil/subconf.rb: configuration file for tkutil.c
-
- * ext/tk/tkutil/depend: ditto
-
-Mon Jan 31 13:13:35 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/tcltklib.c: add invalid namespace check
+ * ext/tcltklib/tcltklib.c: add invalid namespace check
* ext/tk/lib/multi-tk.rb: add invalid_namespace? method
@@ -11589,22 +10194,11 @@ Mon Jan 31 10:29:18 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
-Mon Jan 31 09:44:03 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (Init_Object): remove Object#type. [ruby-core:04335]
-
Sat Jan 29 09:42:12 2005 Sam Roberts <sroberts@uniserve.com>
* lib/resolv.rb (Resolv::DNS::Resource::IN::SRV): Added RFC2782 SRV
resource record for specifying location of services.
-Sat Jan 29 00:10:33 2005 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c,
- regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h,
- regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported
- Oni Guruma 3.5.4.
-
Fri Jan 28 17:16:55 2005 Tanaka Akira <akr@m17n.org>
* lib/resolv.rb (Resolv::DNS::Config.parse_resolv_conf):
@@ -11614,60 +10208,33 @@ Fri Jan 28 17:16:55 2005 Tanaka Akira <akr@m17n.org>
(Resolv::DNS::Config#lazy_initialize): ditto.
Suggested by Sam Roberts.
-Thu Jan 27 17:15:03 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/tk/extconf.rb: support new tk scheme on bccwin32.
- fixed: [ruby-dev:25546]
-
Thu Jan 27 13:18:03 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
-Thu Jan 27 00:12:19 2005 Minero Aoki <aamine@loveruby.net>
-
- * test/fileutils/test_fileutils.rb (setup): support BSD style
- directory group inheritance (again).
-
-Thu Jan 27 00:02:40 2005 Minero Aoki <aamine@loveruby.net>
+Thu Jan 27 00:15:29 2005 Minero Aoki <aamine@loveruby.net>
- * test/fileutils/test_fileutils.rb (setup): support BSD style
- directory group inheritance. [ruby-dev:25440]
+ * test/fileutils/test_fileutils.rb (setup): support BSD-style
+ directory group inheritance. (backport from HEAD, rev 1.32)
* test/fileutils/fileasserts.rb (assert_same_entry): show entry
- difference.
+ difference. (backport from HEAD, rev 1.4)
-Wed Jan 26 17:12:50 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+Wed Jan 26 23:09:11 2005 Minero Aoki <aamine@loveruby.net>
- * parse.y: forgot to initialize parser struct. [ruby-dev:25492]
+ * lib/net/protocol.rb (WriteAdapter#puts): should append \n, not
+ prepend. [ruby-talk:128302] (backport from HEAD, rev 1.75)
- * parse.y (parser_yylex): no tLABEL on EXPR_BEG.
- [ruby-talk:127711]
-
-Wed Jan 26 14:12:58 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/Setup*: remove tcltklib.
-
-Wed Jan 26 12:45:16 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/tk/extconf.rb: support new tk scheme on mswin32.
- fixed: [ruby-dev:25535]
-
-Wed Jan 26 10:45:19 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Jan 26 10:51:50 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (flock_winnt, flock_win95): unlock file even if
- LOCK_NB is specified.
-
-Tue Jan 25 23:10:48 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+ LOCK_NB is specified. (backported from CVS HEAD)
- * ext/tk: merge tcltklib for Ruby/Tk installation control
+Tue Jan 25 17:11:51 2005 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/tcltklib: remove
-
-Tue Jan 25 17:05:15 2005 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ruby.c (proc_options): correct -T option in RUBYOPT.
- fixed: [ruby-dev:25512]
+ * ruby.c (proc_options): correct -T option in RUBYOPT. (backported
+ from CVS HEAD)
Tue Jan 25 14:05:52 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -11706,17 +10273,31 @@ Tue Jan 25 14:05:52 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/tkHTML/ss.rb: local variable scope bug fix
[ruby-dev:25479]
-Mon Jan 24 16:00:53 2005 NARUSE, Yui <naruse@ruby-lang.org>
+Mon Jan 24 15:44:25 2005 Tilman Sauerbeck <tilman@code-monkey.de>
+
+ * lib/rdoc/parsers/parse_c.rb: allow whitespace after function names.
+ [ruby-core:4296]
+
+ * lib/rdoc/parsers/parse_simple.rb: adds support for private comments
+ in the "simple" parser. [ruby-core:4301]
+
+Mon Jan 24 15:44:25 2005 Charles Mills <cmills@freeshell.org>
+
+ * lib/rdoc/parsers/parse_c.rb: adds support for constants
+ (rb_define_const), accessors (rb_define_attr), and makes a
+ couple fixes. [ruby-core:4307]
- * ext/nkf/lib/kconv.rb (guess_old): not use NKF.guess_old
- but NKF.guess1. fixed: [ruby-dev:25491]
+Mon Jan 24 15:44:25 2005 Florian Gro <florgro@gmail.com>
+
+ * lib/rdoc/parsers/parse_rb.rb: Logic for def Builtin.method() end
+ [ruby-core:4302]
Mon Jan 24 15:44:25 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
-Sun Jan 23 12:38:01 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Sun Jan 23 12:41:16 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/soap/wsdlDriver.rb: from 1.5.3-ruby1.8.2, operation which has
capitalized name (such as KeywordSearchRequest in AWS) is defined as
@@ -11732,62 +10313,65 @@ Sun Jan 23 05:24:42 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_ocsp.c (ossl_ocspreq_to_der): should call
GetOCSPReq at first.
-Sat Jan 22 22:59:08 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sat Jan 22 23:09:47 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/ssl.rb (accept): rescue SSLError. [druby-ja:110]
-Sat Jan 22 22:27:28 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sat Jan 22 22:35:03 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/unix.rb: fail if UNIXFileOwner is set. [druby-ja:111]
+Fri Jan 21 23:58:42 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ext/stringio/stringio.c (strio_set_pos): clear EOF flag.
+ [ruby-talk:127511]
+
Fri Jan 21 20:07:02 2005 Tanaka Akira <akr@m17n.org>
* lib/resolv.rb (Resolv::DNS::Config.resolv): don't raise ResolvError.
reported by Sam Roberts. [ruby-talk:127133]
-Fri Jan 21 17:09:44 2005 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/imap.rb (decode_utf7): use pack("U*") to encode UTF-8.
-
- * lib/net/imap.rb (encode_utf7): use unpack("U*") to decode UTF-8.
-
- * test/net/imap/test_imap.rb: added tests for Net::IMAP.
-
Fri Jan 21 16:58:10 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (rb_push_glob): should work for NUL delimited patterns.
- * dir.c (rb_glob2): should aware of offset in the pattern.
-
Fri Jan 21 13:58:37 2005 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (u8tou16): fixed typo. fixed: [ruby-list:40546]
+ (backported from CVS HEAD)
+
+Fri Jan 21 09:30:16 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * rubyio.h (rb_eof_error): should mark as NORETURN. (backported
+ from CVS HEAD)
-Fri Jan 21 00:37:09 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Jan 21 00:31:36 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/syck/rubyext.c (syck_parser_bufsize_set): avoid VC++ warning
"local variable 'size' used without having been initialized".
+Thu Jan 20 19:03:24 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * ext/extmk.rb (extmake): shouldn't set $extflags on mswin32.
+
+ * win32/Makefile.sub (LIBRUBY_SO): should use $DLDOBJS instead of
+ $EXTOBJS.
+ fixed: [ruby-core:04290] (backported from CVS HEAD)
+
Thu Jan 20 11:42:02 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_new4): should propagate taintedness.
- * env.h: rename member names in struct FRAME; last_func -> callee,
- orig_func -> this_func, last_class -> this_class.
-
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
-Thu Jan 20 02:01:10 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (Init_Object): remove rb_obj_id_obsolete()
-
-Wed Jan 19 18:02:19 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Jan 19 18:06:40 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/ipaddr.rb (to_s, test_to_s): too many colons with some cases.
+ (backported from CVS HEAD)
Wed Jan 19 01:16:30 2005 Tanaka Akira <akr@m17n.org>
@@ -11795,6 +10379,32 @@ Wed Jan 19 01:16:30 2005 Tanaka Akira <akr@m17n.org>
domain and search directive without an argument.
reported by Sam Roberts. [ruby-talk:126781]
+Tue Jan 18 15:03:05 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * lib/webrick/ssl.rb (WEBrick::Config::SSL): the default value
+ of :SSLEnable is false.
+
+ * lib/webrick/server.rb (WEBrick::Daemon.start): prepared stdio
+ don't allow changing its mode.
+
+ * lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_service):
+ should delete trailing LF from the result of pack("m*").
+
+ * lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_connect):
+ - should delete trailing LF from the result of pack("m*").
+ - clear Request-Line not to send the response by HTTPServer#run.
+
+ * lib/webrick/httputils (WEBrick::HTTPUtils.parse_qvalues):
+ refine regexp (and change the name of a local variable).
+
+ * lib/webrick/httputils.rb (WEBrick::HTTPUtils#escape_path): add
+ new method to escape URI path component.
+
+ * lib/webrick/cgi.rb (WEBrick::CGI::Socket#request_line): should
+ escape SCRIPT_NAME and PATH_INFO before being parsed as a URI.
+
+ * test/webrick/*, sample/webrick/httpproxy.rb: add new file.
+
Mon Jan 17 23:33:46 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (aix): fix typo. [ruby-talk:126401]
@@ -11823,63 +10433,48 @@ Sat Jan 15 14:57:22 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (proc_options): ignore trailing CRs at the end of short
options as well as long options. fixed: [ruby-core:04232]
-Sat Jan 15 13:44:22 2005 Kouhei Sutou <kou@cozmixng.org>
+Sat Jan 15 13:35:16 2005 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/rss.rb (RSS::VERSION): 0.1.2 -> 0.1.3.
* lib/rss/rss.rb: accept inheritance. [ruby-talk:126104]
-Wed Jan 12 12:29:28 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_mod_define_method): incomplete subclass check.
- [ruby-dev:25464]
+Thu Jan 13 04:48:53 2005 Tanaka Akira <akr@m17n.org>
- * class.c (rb_make_metaclass): class of metaclasses should be
- plain Class. [ruby-list:40524]
+ * io.c (io_fread): don't warn nonblocking behavior by default.
-Tue Jan 11 20:58:52 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Jan 12 00:36:29 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * io.c (remain_size): use buffered data instead of unreading to avoid
- inconsistency of text mode. fixed: [ruby-dev:25446]
+ * object.c (rb_class_superclass): superclass of singleton class also
+ should be a singleton class. fixed: [ruby-list:40519]
-Tue Jan 11 09:37:53 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Jan 11 09:44:40 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* numeric.c (Init_Numeric): turn off floating point exceptions
on bcc32. "1e300".to_f had crashed by overflow.
-Mon Jan 10 15:28:51 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Tue Jan 11 03:10:10 2005 Minero Aoki <aamine@loveruby.net>
- * lib/webrick/cgi.rb (WEBrick::CGI::Socket#request_line): should
- escape SCRIPT_NAME and PATH_INFO before being parsed as a URI.
-
- * lib/webrick/httputils.rb (WEBrick::HTTPUtils#escape_path): add
- new method to escape URI path component.
+ * lib/fileutils.rb (copy_entry): could not copy symbolic link.
+ [ruby-talk:125733]
- * lib/webrick/ssl.rb (WEBrick::Config::SSL): the default value
- of :SSLEnable is false.
+ * lib/fileutils.rb (copy_stream): use read/write instead of
+ sysread/syswrite.
- * test/webrick/{test_cgi.rb,webrick.cgi}: new file.
+Mon Jan 10 23:08:15 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * test/webrick/utils.rb: require "webrick/https.h".
+ * variable.c (rb_autoload): hide internal data from ruby level.
+ fixed: [ruby-dev:25435], [ruby-list:40498]
Mon Jan 10 01:22:55 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
-Sun Jan 9 14:12:17 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (rb_f_select): IO list could be altered. [ruby-dev:25312]
-
-Sun Jan 9 04:08:40 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * test/webrick/test_server.rb (test_daemon): delete an assertion
- which has possibility to fail by race condition.
+Sun Jan 9 03:12:58 2005 Tanaka Akira <akr@m17n.org>
-Sun Jan 9 03:22:46 2005 Minero Aoki <aamine@loveruby.net>
-
- * test/fileutils/test_fileutils.rb (test_copy_entry): copy_entry
- copies only file type, not mtime. [ruby-dev:25383]
+ * io.c (io_fread): warn nonblocking behavior.
+ (io_readpartial): new method IO#readpartial.
Sat Jan 8 04:38:47 2005 why the lucky stiff <why@ruby-lang.org>
@@ -11890,33 +10485,17 @@ Fri Jan 7 21:12:29 2005 TAMURA Takashi <sheepman@tcn.zaq.ne.jp>
* random.c (rand_init): use ALLOC_N instead of ALLOCA_N
[ruby-dev:25426]
-Fri Jan 7 20:01:31 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_service):
- should delete trailing LF from the result of pack("m*").
-
- * lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_connect):
- - should delete trailing LF from the result of pack("m*").
- - clear Request-Line not to send the response by HTTPServer#run.
-
- * lib/webrick/httputils (WEBrick::HTTPUtils.parse_qvalues):
- refine regexp (and change the name of a local variable).
-
- * lib/webrick/server.rb (WEBrick::Daemon.start): prepared stdio
- don't allow changing its mode.
-
- * test/webrick/*, sample/webrick/httpproxy.rb: add new files.
-
Fri Jan 7 18:03:35 2005 Tanaka Akira <akr@m17n.org>
* gc.c (mark_locations_array): avoid core dump with -O3.
[ruby-dev:25424]
-Thu Jan 6 20:29:18 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Jan 6 20:31:07 2005 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/zlib/zlib.c (zstream_end): should return value.
+ * ext/zlib/zlib.c (zstream_end): should return value. (backported
+ from CVS HEAD)
-Thu Jan 6 19:59:03 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Jan 6 19:55:13 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_close): didn't close socket handle.
[ruby-dev:25414]
@@ -11924,7 +10503,7 @@ Thu Jan 6 19:59:03 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_open_osfhandle): bcc32's _open_osfhandle
never set EMFILE.
-Thu Jan 6 17:22:41 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Jan 6 17:14:31 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* random.c (random_seed): O_NONBLOCK isn't defined on some
platforms. [ruby-dev:25417]
@@ -11938,11 +10517,6 @@ Thu Jan 6 07:58:28 2005 Dave Thomas <dave@pragprog.com>
* lib/rdoc/usage.rb (RDoc::RDoc.usage_no_exit): Allow for colons
in path names on DOS machines. (thanks to Johan Nilsson)
-Thu Jan 6 00:02:35 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * test/rinda/test_rinda.rb: use MockClock.sleep instead of Kernel.sleep
- [ruby-dev:25387]
-
Wed Jan 5 20:16:32 2005 Tanaka Akira <akr@m17n.org>
* random.c (limited_big_rand): didn't work if SIZEOF_BDIGITS == 2.
@@ -11950,20 +10524,22 @@ Wed Jan 5 20:16:32 2005 Tanaka Akira <akr@m17n.org>
* random.c (random_seed): refined.
-Wed Jan 5 16:39:54 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * parse.y (BITSTACK_POP): workaround for bcc32 compiler's bug.
- shift assignment operator '>>=' for __int64 in struct may
- generate collapsed code. [ruby-dev:25342]
-
- * win32/win32.[ch]: failed to compile on bcc32 (and probably wince)
- [ruby-dev:25306]
-
Wed Jan 5 12:49:39 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_thread_initialize): Thread objects cannot be initialized
again. fixed: [ruby-core:04067]
+Wed Jan 5 10:48:16 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * dir.c (dir_s_mkdir): win32 special processing doesn't need any
+ longer. (backported from CVS HEAD)
+
+ * win32/win32.[ch] (rb_w32_mkdir): new function. POSIX.1 compatible
+ interface. (backported from CVS HEAD)
+
+ * win32/win32.[ch] (rb_w32_rmdir): new function. (backported from CVS
+ HEAD)
+
Wed Jan 5 02:30:11 2005 Tanaka Akira <akr@m17n.org>
* random.c (init_by_array): imported from mt19937ar-cok.tgz.
@@ -11982,10 +10558,10 @@ Tue Jan 4 23:25:29 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
-Tue Jan 4 21:25:43 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Tue Jan 4 11:15:29 2005 TAMURA Takashi <sheepman@tcn.zaq.ne.jp>
- * test/drb/{test_drbssl.rb,test_drbunix.rb,ut_drb.rb}: use
- DRbService.ext_service. reduce sleep.
+ * bignum.c (rb_big_rand): do not use rb_big_modulo to generate
+ random bignums. [ruby-dev:25396]
Mon Jan 3 14:01:54 2005 Tanaka Akira <akr@m17n.org>
@@ -11997,21 +10573,7 @@ Mon Jan 3 11:37:42 2005 Tanaka Akira <akr@m17n.org>
* random.c (random_seed): use /dev/urandom if available.
[ruby-dev:25392]
-Tue Jan 4 11:15:29 2005 TAMURA Takashi <sheepman@tcn.zaq.ne.jp>
-
- * bignum.c (rb_big_rand): do not use rb_big_modulo to generate
- random bignums. [ruby-dev:25396]
-
-Mon Jan 3 11:03:37 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * test/drb/test_drb.rb: move TestDRbReusePort to new file.
- [ruby-dev:25238]
-
- * test/drb/drbtest.rb: change timeout.
-
- * test/drb/ignore_test_drb.rb: new file.
-
-Mon Jan 3 07:27:46 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Jan 3 07:46:42 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httpauth/htpasswd.rb (WEBrick::Htpasswd#reload):
raise NotImplementedError if password is encrypted by digest
@@ -12027,46 +10589,6 @@ Mon Jan 3 07:27:46 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* test/webrick/test_httpauth.rb: new file.
-Sun Jan 2 15:42:10 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/drb/drb.rb: add lazy stop_service.
-
- * lib/drb/extserv.rb: ditto.
-
-Sun Jan 2 01:17:17 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * test/drb/drbtest.rb: add method DRbService.ext_service.
-
- * test/drb/test_drb.rb: ditto.
-
- * test/drb/test_drbssl.rb: ditto.
-
-Sat Jan 1 20:23:02 2005 Tanaka Akira <akr@m17n.org>
-
- * io.c (argf_readpartial): new method ARGF.readpartial.
- (io_getpartial): extracted from io_readpartial.
- (io_readpartial): call io_getpartial.
-
-Sat Jan 1 17:44:54 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb (each_capitalized): should join header field
- value. This patch is contributed sheepman [ruby-list:40478]
-
- * test/net/http/test_httpheader.rb: test it.
-
-Sat Jan 1 16:21:29 2005 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (copy_stream): use read/write instead of
- sysread/syswrite, which allows duck typing. [ruby-dev:25369]
-
- * lib/fileutils.rb (copy_stream): does NOT support nonblocking IO.
- [ruby-dev:25370]
-
- * lib/fileutils.rb (copy_entry): could not copy symlink.
-
- * test/fileutils/test_fileutils.rb: test copy_entry, copy_file,
- copy_stream.
-
Sat Jan 1 04:20:23 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_ns_spki.c (ossl_spki_set_challenge): should call
@@ -12078,29 +10600,8 @@ Sat Jan 1 01:13:28 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
Fri Dec 31 14:10:43 2004 Dave Thomas <dave@pragprog.com>
- * lib/rdoc/ri/ri_formatter.rb (RI::TextFormatter::display_flow_item):
- Fix problem if heading contains formatting.
-
-Fri Dec 31 00:08:02 2004 Tanaka Akira <akr@m17n.org>
-
- * configure.in (HAVE_RLIM_T): removed because not used.
-
-Thu Dec 30 22:45:39 2004 Tanaka Akira <akr@m17n.org>
-
- * rubyio.h: don't deprecate rb_read_check.
-
- * io.c (STDIO_READ_DATA_PENDING): reverted from old READ_DATA_PENDING
- to check stdio read buffer.
- (rb_read_check): use STDIO_READ_DATA_PENDING.
- (rb_read_pending): ditto.
- (rb_getc): ditto.
-
-Thu Dec 30 05:39:35 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y: eliminate unused members in struct parser_params.
- [ruby-dev:25258] (again)
-
- * parse.y: make parser_new() static.
+ * lib/rdoc/ri/ri_formatter.rb (RI::TextFormatter::display_flow_item): Fix problem
+ if heading contains formatting.
Thu Dec 30 00:41:42 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -12118,11 +10619,6 @@ Tue Dec 28 22:31:46 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_justify): create buffer string after argument type
conversion. fixed: [ruby-dev:25341]
-Tue Dec 28 17:18:17 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * lib/net/telnet.rb (preprocess): remove NULL unless binmode.
- fixed: [ruby-list:40320]
-
Tue Dec 28 15:41:48 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/nkf/nkf-utf8/nkf.c (reinit): should initialize all static
@@ -12143,58 +10639,91 @@ Tue Dec 28 13:35:20 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/zlib/zlib.c (rb_deflate_init_copy): replace rb_deflate_clone.
+Tue Dec 28 12:26:45 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/Makefile.sub, win32/setup.mak (RDOCTARGET, install,
+ install-nodoc, install-doc): rdoc support for mswin32.
+
+ * win32/configure.bat (--enable-install-doc, --disable-install-doc):
+ ditto.
+
Mon Dec 27 20:02:14 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c: fix SEGV bug when deleting Tk interp
* ext/tk/lib/multi-tk.rb: ditto
-Mon Dec 27 16:54:05 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Dec 27 16:55:17 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_x509name.c (Init_ossl_x509name): should use
rb_hash_new to get exactly a Hash. fix [ruby-dev:25325].
-Mon Dec 27 15:29:12 2004 Minero Aoki <aamine@loveruby.net>
+Mon Dec 27 16:29:56 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * test/fileutils/test_fileutils.rb (cp_r): tested wrong file name.
- [ruby-dev:25339]
+ * string.c (rb_str_justify): [ruby-dev:25341]
-Mon Dec 27 15:15:18 2004 Minero Aoki <aamine@loveruby.net>
+Mon Dec 27 15:47:48 2004 Minero Aoki <aamine@loveruby.net>
+
+ * test/fileutils/fileasserts.rb: sync with HEAD.
+
+ * test/fileutils/test_fileutils.rb: ditto.
+
+ * test/fileutils/test_nowrite.rb: ditto.
+
+Mon Dec 27 15:21:07 2004 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (mv): should raise error when moving a
directory to the (empty) directory. [ruby-talk:124368]
+ (backport from HEAD 1.48)
* lib/fileutils.rb (mv): wrongly did not overwrite file on Win32
- platforms.
+ platforms. (backport from HEAD 1.48)
+
+Sat Dec 25 11:11:48 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-Mon Dec 27 14:36:20 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+ * stable version 1.8.2 released.
- * process.c (NUM2RLIM, RLIM2NUM): Without SIZEOF_RLIM_T is not error.
- fixed: [ruby-dev:25346]
+Sat Dec 25 04:23:49 2004 Minero Aoki <aamine@loveruby.net>
-Sun Dec 26 16:21:39 2004 Shugo Maeda <shugo@ruby-lang.org>
+ * lib/fileutils.rb (mkdir, mkdir_p): should ensure directory
+ permission. (backportted from HEAD, 1.47)
- * lib/net/imap.rb (Net::IMAP::PlainAuthenticator): added a new class
- to support the PLAIN authentication mechanism. Thanks, Benjamin
- Stiglitz.
+ * lib/fileutils.rb (traverse, remove_dir): untaint trasted
+ objects. (backportted from HEAD, 1.46)
Sat Dec 25 01:28:23 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * io.c (rb_f_select): [ruby-dev:25312]
+ * io.c: cancel io_reopen() change on Dec. 24th.
+
+ * dln.c: use <dlfcn.h> for NetBSD. [ruby-dev:25313]
+
+ * io.c (rb_f_select): IO list could be altered. [ruby-dev:25312]
+
+Fri Dec 24 23:51:48 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * bcc32/Makefile.sub: bcc32 should use RTL dll (backport from HEAD)
+ [ruby-dev:25306]
+
+ * win32/win32.[ch]: ditto.
Fri Dec 24 23:27:18 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/image.rb: TkPhotoImage#cget bug fix
-Fri Dec 24 03:06:13 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Dec 24 18:39:25 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * win32/win32.[ch]: failed to compile on bcc32 (and probably wince)
+ [ruby-dev:25306]
+
+Fri Dec 24 02:52:52 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (io_reopen, rb_io_reopen): prohibit to change access mode for
special IO ports. [ruby-dev:25225]
- * io.c (next_argv): reduce use of stdio.
-
Fri Dec 24 02:22:53 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/syck/rubyext.c (rb_syck_io_str_read): [ruby-core:03973]
+
* ext/syck/rubyext.c (syck_loader_transfer): check type conversion.
* ext/syck/rubyext.c (syck_parser_assign_io, rb_new_syck_node): duck
@@ -12214,20 +10743,11 @@ Fri Dec 24 01:21:00 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/blt/tile/*.rb: ditto
-Thu Dec 23 23:43:24 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Dec 23 23:36:28 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * process.c (proc_setgroups): check if the argument length is
+ * process.c (proc_setgroups): check if the argument lenght is
modified. fixed: [ruby-dev:25285]
- * process.c (SIZEOF_RLIM_T): err if size of rlim_t is not set.
-
-Thu Dec 23 19:08:41 2004 Tanaka Akira <akr@m17n.org>
-
- * rubyio.h: rename FMODE_UNSEEKABLE to FMODE_DUPLEX.
-
- * io.c (io_check_tty): extracted function to set FMODE_LINEBUF and
- FMODE_DUPLEX.
-
Thu Dec 23 13:13:33 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c: define TclTkLib::COMPILE_INFO and
@@ -12239,6 +10759,10 @@ Thu Dec 23 13:13:33 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: define Tk::RELEASE_DATE
+Thu Dec 23 09:38:31 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (io_reopen): restore exact mode. fixed: [ruby-core:04003]
+
Thu Dec 23 00:16:32 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (bsdi): use $(CC) for LDSHARED. fixed [ruby-dev:25270]
@@ -12253,49 +10777,41 @@ Wed Dec 22 08:34:32 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/dl/sym.c (rb_dlsym_initialize): extract internal pointers after
all argument conversion. fixed: [ruby-dev:25271]
-Tue Dec 21 16:15:21 2004 Michael Neumann <mneumann@ruby-lang.org>
-
- * lib/xmlrpc/client.rb: use "" instead of "." if prefix argument is
- nil in proxy methods. nil is default value.
-
- * test/xmlrpc/test_webrick_server.rb, test/xmlrpc/webrick_testing.rb:
- use threads instead of forking. this should fix issue #1208
- (http://rubyforge.org/tracker/?func=detail&atid=1698&aid=1208&group_id=426).
- removed testing of SSL enabled servlet as this hangs.
-
-Wed Dec 22 00:05:10 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Wed Dec 22 00:08:01 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/soap/*, test/soap/*, sample/soap/authheader/*: eval cleanup.
-Tue Dec 21 22:07:41 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_asn1.c (ossl_asn1_decode_all): use rb_str_new4
- to avoid SEGV.
+Tue Dec 21 22:07:33 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_asn1.c (ossl_asn1_traverse, ossl_asn1_decode,
ossl_asn1_decode_all): temporary value should be marked volatile.
-Tue Dec 21 12:42:34 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Tue Dec 21 14:40:02 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * ext/openssl/ossl_asn1.c (ossl_asn1_traverse, ossl_asn1_decode):
- use rb_str_new4 to avoid SEGV. fix [ruby-dev:25261]
+ * ext/openssl/ossl_asn1.c (ossl_asn1_traverse, ossl_asn1_decode,
+ ossl_asn1_decode_all): use rb_str_new4 to avoid SEGV.
+ fix [ruby-dev:25261]
* test/openssl/test_asn1.rb: add tests for OpenSSL::ASN1.
+Tue Dec 21 12:22:40 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (io_reopen): keep duplex pipe in correct mode for exception
+ safeness. fixed: [ruby-dev:25152]
+
Tue Dec 21 12:10:04 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/grid.rb: rescue bug of 'grid configure' on Tcl/Tk8.3-
-Mon Dec 20 22:52:29 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Tue Dec 21 00:53:01 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * added samples for the previous soap4r's commit.
+ * ext/openssl/ossl_asn1.c (ossl_asn1_traverse): [ruby-dev:25261]
-Mon Dec 20 22:56:39 2004 Tanaka Akira <akr@m17n.org>
+ * ext/openssl/ossl_asn1.c (ossl_asn1_decode): ditto.
- * gc.c (set_stack_end): gcc noinline attribute is available since
- gcc-3.1.
+ * ext/openssl/ossl_asn1.c (ossl_asn1_decode_all): ditto.
-Mon Dec 20 22:40:31 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Mon Dec 20 23:22:26 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* added files:
* lib/soap/mapping/wsdl*.rb
@@ -12309,6 +10825,8 @@ Mon Dec 20 22:40:31 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/soap/*
* test/wsdl/*
* test/xsd/*
+ * sample/soap/*
+ * sample/sdl/*
* summary
* imported from the soap4r repository. Version: 1.5.3-ruby1.8.2
@@ -12322,14 +10840,12 @@ Mon Dec 20 22:40:31 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* HTTP client/server gzipped content encoding support.
* improved WSDL schema definition support; still is far from
- complete, but is making step by step improvement.
+ complete, but is making step by step improovement.
-Mon Dec 20 14:45:19 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/net/https.rb: delete descriptions about key_file and cert_file.
- fixed: [ruby-dev:25243]
+Mon Dec 20 22:56:39 2004 Tanaka Akira <akr@m17n.org>
- * ext/openssl/lib/net/telnets.rb: ditto.
+ * gc.c (stack_end_address): gcc noinline attribute is available since
+ gcc-3.1.
Mon Dec 20 14:07:02 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -12341,14 +10857,21 @@ Mon Dec 20 14:07:02 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/panedwindow.rb: ditto
-Mon Dec 20 13:51:40 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Dec 20 12:47:13 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * ext/openssl/lib/net/https.rb,protocols.rb,telnets.rb: delete
+ doc and code about SSLContext#{key_file,cert_file}.
+ fixed: [ruby-dev:25243]
+
+Mon Dec 20 12:42:17 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
+ * io.c (io_fwrite): workaround for MSVCRT's bug.
+ fixed: [ruby-core:03982]
-Mon Dec 20 10:51:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Dec 20 11:21:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * parse.y (special_local_set): prevent the parser object from GC.
- fixed: [ruby-dev:25252]
+ * io.c (rb_io_eof): check if closed before clearerr().
+ fixed: [ruby-dev:25251]
Mon Dec 20 03:30:40 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -12359,10 +10882,40 @@ Mon Dec 20 01:51:01 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* struct.c (make_struct): [ruby-dev:25249]
-Mon Dec 20 00:16:54 2004 Kouhei Sutou <kou@cozmixng.org>
+Mon Dec 20 00:28:20 2004 Kouhei Sutou <kou@cozmixng.org>
+
+ * lib/rexml/encodings/SHIFT-JIS.rb: backported from CVS HEAD.
+
+ * lib/rexml/encodings/SHIFT_JIS.rb: ditto.
- * lib/rexml/encodings/SHIFT_JIS.rb: fixed LoadError bug.
- [ruby-core:3958]
+Sun Dec 19 17:19:48 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * ext/openssl/ossl_x509store.c
+ (ossl_x509store_set_time): add OpenSSL::X509::Store#time=.
+ (ossl_x509stctx_set_time): add OpenSSL::X509::StoreContext#time=.
+
+ * test/openssl/ossl_x509store.rb: test certificate validity times.
+
+ * ext/openssl/ossl_x509name.c (ossl_x509name_to_s): add optional
+ second argument to specify the output format (see also
+ X509_NAME_print_ex).
+
+ * ext/openssl/ossl_x509name.c (ossl_x509name_init): new constants:
+ OpenSSL::X509::Name::COMPAT, OpenSSL::X509::Name::RFC2253,
+ OpenSSL::X509::ONELINE, OpenSSL::X509::MULTILINE.
+
+ * ext/openssl/lib/openssl/x509.rb (OpenSSL::X509::Name::RFC2253DN):
+ new module to provide the parse for RFC2253 DN format.
+
+ * ext/openssl/lib/openssl/x509.rb (OpenSSL::X509::Name.parse_rfc2253):
+ new method to parse RFC2253 DN format.
+
+ * test/openssl/ossl_x509name.rb: add tests about RFC2253 DN.
+
+ * text/openssl/ssl_server.rb: try to listen ports from 20443 to 20542
+ while EADDRINUSE is raised.
+
+ * all changes in this entry are backport from 1.9.
Sun Dec 19 17:24:59 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -12384,7 +10937,7 @@ Sat Dec 18 16:36:23 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/zlib/zlib.c (rb_deflate_s_deflate, rb_inflate_s_inflate):
disallow interrupt by type conversion. fixed: [ruby-dev:25226]
-Sat Dec 18 15:09:02 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Sat Dec 18 15:16:41 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/webrick/httpauth.rb,
lib/webrick/httpauth/{basicauth.rb,digestauth.rb}: use
@@ -12395,12 +10948,10 @@ Sat Dec 18 10:51:01 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
- * io.c (rb_f_open): add type check for return value from to_open.
+Fri Dec 17 18:07:01 2004 Shugo Maeda <shugo@ruby-lang.org>
-Fri Dec 17 16:44:26 2004 Tanaka Akira <akr@m17n.org>
-
- * configure.in (ac_cv_sizeof_rlim_t): set 8 for BSD/OS.
- Reported by OHARA Shigeki. [ruby-dev:25236]
+ * test/readline/test_readline.rb: fix for BSD. Thanks, GOTOU Yuuzou.
+ fixed: [ruby-dev:25218]
Fri Dec 17 16:28:12 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -12438,27 +10989,45 @@ Fri Dec 17 16:28:12 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/textwindow.rb: wrong gravity of text mark for
embedded window
+Fri Dec 17 13:50:00 2004 Akiyoshi, Masamichi <akiyoshi@hp.com>
+
+ * vms/vmsruby_private.c, vms/vmsruby_private.h: private routines
+ for VMS port are added.
+
+ * eval.c (ruby_init): change to call VMS private intialization routine.
+
Fri Dec 17 13:33:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/cgi/session.rb (CGI::Session#initialize): control adding
session_id hidden fields. fixed: [ruby-talk:123850]
-Fri Dec 17 00:01:48 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Dec 16 23:25:25 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * eval.c (rb_proc_arity, rb_node_arity, rb_mod_method_arity,
- rb_obj_method_arity): new functions to obtain method arity.
- [ruby-dev:25143]
+ * lib/drb/drb.rb, lib/drb/ssl.rb: backported from CVS HEAD.
+ [druby-ja:101]
-Thu Dec 16 23:31:13 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * test/drb/test_drb.rb: adjust and reduce sleep (backported from
+ CVS HEAD.)
- * lib/mkmf.rb (create_makefile): create RUBYARCHDIR also when no extension
- is installed. fixed: [ruby-dev:25215]
+Thu Dec 16 18:44:58 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-Thu Dec 16 22:36:57 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+ * lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): should wait
+ for reading request till data arrive. [ruby-talk:121068]
- * test/drb/test_drb.rb: adjust and reduce sleep.
+ * lib/webrick/server.rb (WEBrick::GenericServer#start_thread):
+ should log about all accepted socket. [ruby-core:03962]
+
+ * lib/webrick/accesslog.rb (WEBrick::AccessLog#setup_params):
+ "%%" and "%u" are supported. [webricken:135]
+
+ * lib/webrick/httpservlet/filehandler.rb
+ (WEBrick::HTTPServlet::FileHandler#check_filename):
+ :NondisclosureName is acceptable if it is Enumerable.
+
+ * lib/webrick/config.rb (WEBrick::Config::FileHandler):
+ default value of :NondisclosureName is [".ht*", "*~"].
-Thu Dec 16 18:37:08 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Dec 16 18:36:52 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl.c (ossl_raise): refine message format.
@@ -12497,64 +11066,55 @@ Thu Dec 16 16:03:50 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/*: ditto
-Thu Dec 16 04:02:28 2004 Minero Aoki <aamine@loveruby.net>
+Thu Dec 16 03:14:28 2004 Minero Aoki <aamine@loveruby.net>
- * ext/ripper/extconf.rb: bison is not needed if ripper.c exists.
- [ruby-dev:25191]
+ * lib/net/http.rb (basic_encode): return value of pack('m') may
+ include multiple CR/LFs. Backported from main trunk (rev 1.112).
+ [ruby-dev:25212]
-Thu Dec 16 03:27:10 2004 Minero Aoki <aamine@loveruby.net>
+Thu Dec 16 00:33:37 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/net/http.rb: remove junk.
-
-Thu Dec 16 00:57:30 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/syck/rubyext.c (rb_syck_io_str_read): [ruby-core:03973]
+ * hash.c (Init_Hash): remove custom "hash" and "eql?".
-Thu Dec 16 00:43:29 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Wed Dec 15 18:57:01 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/drb/drb.rb: changed default binded address family to use an
- available address family of host name. [druby-ja:101]
+ * lib/set.rb (Set::eql): wrong definition. [ruby-dev:25207]
- * lib/drb/ssl.rb: ditto
+Wed Dec 15 18:48:42 2004 Shugo Maeda <shugo@ruby-lang.org>
-Wed Dec 15 17:47:17 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+ * ext/curses/curses.c (window_subwin): call NUM2INT() before
+ GetWINDOW(). (backported from CVS HEAD)
- * lib/webrick/server.rb (WEBrick::GenericServer#start_thread):
- should log about all accepted socket. [ruby-core:03962]
+Wed Dec 15 17:03:50 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * lib/webrick/accesslog.rb (WEBrick::AccessLog#setup_params):
- "%%" and "%u" are supported. [webricken:135]
+ * win32/win32.[ch] (rb_w32_isatty): new function to replace MSVCRT's
+ isatty because it never sets errno. (backported from CVS HEAD)
- * lib/webrick/httpservlet/filehandler.rb
- (WEBrick::HTTPServlet::FileHandler#check_filename):
- :NondisclosureName is acceptable if it is Enumerable.
+Wed Dec 15 15:39:32 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * lib/webrick/config.rb (WEBrick::Config::FileHandler):
- default value of :NondisclosureName is [".ht*", "*~"].
+ * ext/openssl/ossl_x509name.c (ossl_x509name_to_a): avoid SEGV
+ (rollback the previous commit).
Wed Dec 15 16:10:23 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (rb_obj_id_obsolete): warn always.
+ * eval.c (rb_enable_super): ditto.
+
Wed Dec 15 15:31:02 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/set.rb (Set#==): [ruby-dev:25206]
-Wed Dec 15 14:32:18 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Dec 15 14:22:10 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_fdisset): check whether the handle is valid.
+ fixed: [ruby-core:03959]
Wed Dec 15 10:30:37 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/openssl/ossl_digest.c (ossl_digest_initialize): [ruby-dev:25198]
-Tue Dec 14 19:17:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * utf8.c (utf8_is_mbc_ambiguous): [ruby-talk:123561]
-
- * utf8.c (utf8_mbc_to_normalize): ditto.
-
-Tue Dec 14 17:08:15 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Dec 14 17:10:09 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_close): need to reset osfhnd().
@@ -12568,36 +11128,27 @@ Tue Dec 14 12:36:04 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/cgi/session.rb (CGI::Session::initialize): generate new
session if given session_id does not exist. [ruby-list:40368]
-Tue Dec 14 08:47:45 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (Init_eval): should mark ruby_eval_tree. [ruby-dev:25189]
-
Mon Dec 13 18:13:52 2004 Tanaka Akira <akr@m17n.org>
- * gc.c (set_stack_end): new function to obtain stack end address.
- set_stack_end obtains a stack end address by an address of local
- variable in the function.
- (SET_STACK_END, STACK_END): use set_stack_end. don't use alloca.
+ * gc.c (stack_end_address): new function to obtain stack end address.
+ stack_end_address calls __builtin_frame_address(0) to obtain the
+ frame pointer of a stack frame of stack_end_address. The address
+ is the stack pointer of the caller's stack frame.
+ (SET_STACK_END): use stack_end_address.
This makes the conservative garbage collector to scan a stack frame
of the garbage_collect function itself. This is required because
callee-save registers may be stored in the frame.
[ruby-dev:25158]
-Mon Dec 13 02:45:51 2004 Shugo Maeda <shugo@ruby-lang.org>
-
- * ext/curses/curses.c (window_subwin): call NUM2INT() before
- GetWINDOW(). fixed: [ruby-dev:25161]
-
Mon Dec 13 00:58:02 2004 Tanaka Akira <akr@m17n.org>
* lib/pathname.rb (cleanpath_aggressive): make it private.
(cleanpath_conservative): ditto.
Suggested by Daniel Berger. [ruby-core:3914]
-Sun Dec 12 21:32:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Dec 12 20:06:38 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * test/ruby/test_super.rb (TestSuper#test_define_method): now methods
- from procs can call super.
+ * lib/drb/drb.rb: backported from CVS HEAD.
Sun Dec 12 10:35:10 2004 Dave Thomas <dave@pragprog.com>
@@ -12609,7 +11160,14 @@ Sun Dec 12 10:14:03 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/rdoc.rb (RDoc::RDoc::parse_files): Never exclude files
explicitly given on the command line.
-Sat Dec 11 21:10:16 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sun Dec 11 23:54:07 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * ext/tk/*: update to support libraries in ActiveTcl8.4.12.0
+ (see ext/tk/ChangeLog.tkextlib).
+
+ * ext/tk/sample/scrollframe.rb: add a new sample.
+
+Sat Dec 11 20:12:21 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb: add DRbRemoteError. [ruby-list:40348],
[ruby-list:40390]
@@ -12618,27 +11176,41 @@ Sat Dec 11 21:10:16 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/drb/ut_drb.rb: ditto.
-Sat Dec 11 13:08:28 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat Dec 11 15:38:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/jcode.rb (String::succ): [ruby-dev:25156]
+
+Sat Dec 11 12:41:55 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * eval.c (run_trap_eval): prototype; avoid VC++ warnings.
+
+ * ext/socket/getaddrinfo.c: fix typo. fixed: [ruby-core:03947]
+
+ * win32/win32.c: need to include dln.h.
+
+Sat Dec 11 00:10:18 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * sample/optparse/subcommand.rb: a sample for sub commands like
- cvs. contributed by Minero Aoki.
+ * io.c (io_reopen): [ruby-dev:25150]
-Fri Dec 10 08:39:48 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Dec 10 08:39:27 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/socket/socket.c (sock_listen): get OpenFile just before calling
- listen(2).
+ listen(2). fixed: [ruby-dev:25149]
-Thu Dec 9 16:28:35 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Dec 9 17:00:00 2004 Akiyoshi, Masamichi <akiyoshi@hp.com>
- * ext/sdbm/init.c (GetDBM): typo.
+ * ext/socket/socket.c, ext/socket/getaddrinfo.c: port to VMS
-Thu Dec 9 16:21:51 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Dec 9 16:31:02 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * lib/webrick/cgi.rb (WEBrick::CGI#setup_header): avoid
- SecurityError. [ruby-dev:24970]
+ * ext/sdbm/init.c (GetDBM): typo.
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): should wait
- for reading request till data arrive. [ruby-talk:121068]
+Thu Dec 9 16:05:00 2004 Akiyoshi, Masamichi <akiyoshi@hp.com>
+
+ * defines.h: change path of vms.h
+ * vms/vms.h: delete reference for snprintf()
+ * vms/config.h: new file
+ * vms/config.h_in: deleted
Thu Dec 9 14:38:35 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -12647,10 +11219,6 @@ Thu Dec 9 14:38:35 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_dump): not escape # which isn't a substitution.
-Thu Dec 9 12:31:53 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * io.c (pipe_open): should set prog if argc != 0.
-
Thu Dec 9 10:54:36 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/dbm/dbm.c (fdbm_select): [ruby-dev:25132]
@@ -12659,11 +11227,6 @@ Thu Dec 9 10:54:36 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/gdbm/gdbm.c: ditto.
-Thu Dec 9 10:19:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/socket/test_socket.rb (test_setsockopt): use SO_LINGER instead
- of SO_BINDTODEVICE. fixed: [ruby-dev:25133]
-
Thu Dec 9 03:08:36 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c (ip_init): set root-win title to "ruby" when
@@ -12718,174 +11281,44 @@ Wed Dec 8 23:54:29 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/template/html/html.rb (RDoc::Page): Typo
meant that h2 tag was invisible.
-Wed Dec 8 22:10:02 2004 Tanaka Akira <akr@m17n.org>
-
- * rubyio.h, io.c, ext/dl/dl.c, ext/pty/pty.c, ext/socket/socket.c:
- create FILE object only when required: popen(3) and DL's IO#to_ptr.
- [ruby-dev:25122]
-
- * io.c (rb_io_binmode): use setmode for Human68k. [ruby-dev:25121]
-
-Wed Dec 8 20:13:06 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * process.c (rb_spawn): support for DJGPP.
+Wed Dec 8 21:56:31 2004 Kouhei Sutou <kou@cozmixng.org>
- * lib/mkmf.rb (VPATH): specify the implicit path separator for DJGPP.
-
-Wed Dec 8 17:48:22 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (proc_invoke): merge Guy Decoux's argument preserve
- patch in [ruby-core:03874].
-
-Wed Dec 8 17:37:33 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (rb_w32_pipe_exec): need to close original socket
- handle.
+ * lib/rss, test/rss, sample/rss: backported from CVS HEAD.
Wed Dec 8 14:31:36 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * sprintf.c (rb_f_sprintf): [ruby-dev:25104]
-
-Wed Dec 8 13:49:46 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (rb_w32_pipe_exec): must close original handle
- before exec. fixed: [ruby-dev:25112]
-
-Wed Dec 8 11:46:26 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (string_content): get rid of segfault at empty evstr.
- fixed: [ruby-dev:25113]
-
-Wed Dec 8 03:26:51 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_bio.c (ossl_obj2bio): should not use fptr->f.
- [ruby-dev:25101]
-
-Wed Dec 8 03:26:41 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * io.c (io_fwrite): change dereference for cosmetic reason.
- * runruby.rb: prepend LIBRUBY_SO to LD_PRELOAD as well as rubytest.rb.
-
-Wed Dec 8 01:35:44 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (is_socket): reorder of function definitions.
-
-Wed Dec 8 00:44:31 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * io.c (pipe_open): win32 bidirectional pipe support.
-
- * win32/win32.[ch] (rb_w32_pipe_exec): ditto.
-
- * win32/win32.[ch] (socketpair): new function. POSIX socketpair
- emulation.
-
- * win32/win32.c (socketpair_internal): ditto.
-
-Wed Dec 8 00:25:07 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * test/rss/test_version.rb: added version check test.
- [ruby-dev:25053]
-
-Tue Dec 7 15:40:38 2004 Tanaka Akira <akr@m17n.org>
-
- * io.c (io_fwrite): avoid context switch before writing to stderr.
- [ruby-dev:25080]
-
- * rubyio.h: refine deprecated declaration.
-
- * configure.in, file.c, io.c: remove useless check: fseeko, etc.
-
-Tue Dec 7 13:42:07 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * dir.c (dir_s_mkdir): win32 special processing doesn't need any
- longer.
+ * sprintf.c (rb_f_sprintf): [ruby-dev:25104]
- * win32/win32.[ch] (rb_w32_mkdir): new function. POSIX.1 compatible
- interface.
+Tue Dec 7 19:08:00 2004 Akiyoshi, Masamichi <akiyoshi@hp.com>
- * win32/win32.[ch] (rb_w32_rmdir): new function.
+ * io.c (io_fwrite): fix offset incrementation (for VMS and Human68k)
Tue Dec 7 00:27:37 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* process.c (proc_setgroups): [ruby-dev:25081]
-Mon Dec 6 23:07:57 2004 Tanaka Akira <akr@m17n.org>
-
- * configure.in: check -lsocket for socketpair and shutdown.
- reported by Ville Mattila. [ruby-core:03903]
-
-Mon Dec 6 23:00:45 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * configure.in (ac_cv_sizeof_rlim_t): setup for DJGPP.
-
- * io.c (is_socket, shutdown): define dummy macros for DJGPP.
-
- * process.c: use SIZEOF_RLIM_T instead of HAVE_RLIM_T for DJGPP.
-
-Mon Dec 6 21:19:40 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * io.c (is_socket): fix typos. [ruby-core:03900]
-
-Mon Dec 6 20:13:28 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * io.c (is_socket): new function.
-
- * io.c (rb_io_close_read, rb_io_close_write): use is_socket().
-
- * io.c (rb_io_fptr_finalize): need to check fptr->f before calling
- rb_io_fptr_cleanup().
-
- * io.c (pipe_open): win32 pipe support (experimental).
-
- * win32/win32.[ch] (rb_w32_pipe_exec): return file descriptors
- instead of FILE structure objects.
-
- * win32/win32.[ch] (rb_w32_is_socket): new function.
-
-Mon Dec 6 19:40:40 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * Makefile.in (.y.c): simplify the rule.
-
Mon Dec 6 18:08:10 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* re.c (rb_reg_eqq): document fix. [ruby-talk:122541]
-Mon Dec 6 17:49:30 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * eval.c (run_trap_eval): add prototype for Microsoft compiler.
-
-Mon Dec 6 17:32:38 2004 Tanaka Akira <akr@m17n.org>
+Mon Dec 6 17:19:13 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
- ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
- Use own buffering mechanism instead of stdio. [ruby-dev:25056]
+ * rubysig.h (TRAP_BEG, TRAP_END): safe errno around CHECK_INTS.
+ (backported from CVS HEAD) [ruby-dev:24993]
- * io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
- EOF flag removed.
+Mon Dec 6 10:18:17 2004 Dave Thomas <dave@pragprog.com>
-Mon Dec 6 17:15:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/socket/test_socket.rb (TestBasicSocket#test_setsockopt):
- BasicSocket#setsockopt dumps core. [ruby-dev:25039]
-
- * test/socket/test_tcp.rb (TestTCPSocket#test_recvfrom):
- TCPSocket#recvfrom dumps core. [ruby-dev:24705]
-
- * test/socket/test_udp.rb (TestUDPSocket#test_connect):
- UDPSocket#connect dumps core. [ruby-dev:25045]
-
- * test/socket/test_udp.rb (TestUDPSocket#test_bind):
- UDPSocket#bind dumps core. [ruby-dev:25057]
+ * lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::look_for_directives_in):
+ Oops - 1.8 doesn't have String#clear
Mon Dec 6 09:59:23 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * io.c (io_fread): take VALUE argument.
-
* ext/socket/socket.c (sock_connect): use rb_str_new4().
[ruby-dev:25052]
- * eval.c (rb_yield_0): [ruby-dev:25051]
-
-Mon Dec 6 01:32:31 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Dec 6 01:42:08 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_pkey_rsa.c (ossl_rsa_public_encrypt,
ossl_rsa_public_decrypt, ossl_rsa_private_encrypt,
@@ -12906,11 +11339,6 @@ Sun Dec 5 19:39:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/optparse.rb (OptionParser#order!): ignore case only for long
option. [ruby-dev:25048]
-Sun Dec 5 00:54:32 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * mkconfig.rb: setup library paths before requiring library.
- [ruby-core:03892]
-
Sat Dec 4 22:54:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_write): remove rb_str_locktmp(). [ruby-dev:25050]
@@ -12934,29 +11362,10 @@ Sat Dec 4 22:54:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* hash.c (rb_hash_hash): should provide "hash" method where "eql?"
is redefined. [ruby-talk:122482]
-Sat Dec 4 21:29:05 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb: (In previous commit) new method chown.
-
- * lib/fileutils.rb: (In previous commit) new method chown_R.
-
- * lib/fileutils.rb: (In previous commit) new method chmod_R
- wrongly added. Removed now.
-
-Sat Dec 4 20:45:52 2004 Minero Aoki <aamine@loveruby.net>
+Sat Dec 4 14:54:52 2004 WATANABE Hirofumi <eban@ruby-lang.org>
- * lib/fileutils.rb (mkdir, mkdir_p): should chmod explicitly.
- [ruby-core:03881]
-
-Sat Dec 4 18:54:09 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb: removed empty lines from output.
-
-Sat Dec 4 18:49:09 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb (RSS::VERSION): 0.1.1 -> 0.1.2
-
- * lib/rss/rss.rb: #item=/#set_item and so on are obsolete.
+ * eval.c (proc_invoke): use volatile `tmp' rather than `args'.
+ [ruby-core:03882]
Sat Dec 4 14:28:56 2004 Dave Thomas <dave@pragprog.com>
@@ -12970,13 +11379,48 @@ Sat Dec 4 14:28:56 2004 Dave Thomas <dave@pragprog.com>
The lines before :section: are removed, and identical lines at the end are
also removed if present.
+Sat Dec 4 03:33:45 2004 Shugo Maeda <shugo@ruby-lang.org>
+
+ * ext/readline/readline.c: check $SAFE. (backported from CVS HEAD)
+
+ * test/readline/test_readline.rb: added tests for readline.
+ (backported from CVS HEAD)
+
+Sat Dec 4 02:24:00 2004 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * ext/nkf/nkf.c: add constant NKF::VERSION
+
+ * ext/nkf/nkf.c(guess): this becomes an alias of guess2
+
+ * ext/nkf/test.rb(mime_out2): add --no-cp932
+
+ * ext/nkf/nkf-utf8/nkf.c: original nkf2 revision 1.47
+
Sat Dec 4 00:35:08 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c (bsock_setsockopt): [ruby-dev:25039]
-Fri Dec 3 12:25:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Dec 3 18:57:03 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/ostruct.rb: 1.9 marshaling support back-ported.
+ [ruby-core:03871]
+
+Fri Dec 3 13:45:20 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (proc_invoke): copy arguments to frame.argv.
+ [ruby-core:03861]
+
+Fri Dec 3 12:25:41 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * st.h: fix prototypes.
+
+Fri Dec 3 00:21:05 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * object.c (convert_type): use rb_respond_to() again.
+ [ruby-dev:25021]
- * st.h: fix prototype for C++.
+ * eval.c (rb_respond_to): funcall respond_to? if it's redefined.
+ [ruby-dev:25021]
Fri Dec 3 01:55:24 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -12996,25 +11440,6 @@ Fri Dec 3 01:55:24 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/demos-jp/widget: ditto.
-Fri Dec 3 00:21:05 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (proc_invoke): prepare to pass a block from "call" method
- to a Proc generated by Method#to_proc. [ruby-dev:25031]
-
- * eval.c (rb_yield_0): actually passes a block given to "call".
-
- * object.c (convert_type): use rb_respond_to() again. this fix is
- based on [ruby-dev:25021]
-
- * eval.c (rb_respond_to): funcall respond_to? if it's redefined.
- [ruby-dev:25021]
-
-Thu Dec 2 15:13:53 2004 Michael Neumann <mneumann@ruby-lang.org>
-
- * test/xmlrpc/test_parser.rb, test/xmlrpc/data/*.expected: Expected
- values are now stored in YAML instead of using #inspect. This fixes
- false hash order.
-
Fri Dec 3 00:11:48 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_file_initialize): [ruby-dev:25032]
@@ -13027,16 +11452,12 @@ Thu Dec 2 16:41:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_callcc, rb_cont_call): prohibit calling from different
signal contexts. [ruby-dev:25022]
-Thu Dec 2 10:45:02 2004 Shugo Maeda <shugo@ruby-lang.org>
-
- * test/readline/test_readline.rb: fix for NetBSD.
-
Thu Dec 2 09:57:24 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/ostruct.rb (OpenStruct::Marshaler): OpenStruct can be
marshaled again. [ruby-core:03862]
-Thu Dec 2 09:30:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Dec 2 09:30:06 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (thread_mark): mark thread group. [ruby-dev:25020]
@@ -13046,56 +11467,35 @@ Thu Dec 2 07:57:16 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_ctl): [ruby-dev:25019]
-Wed Dec 1 06:13:00 2004 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf/nkf.c: add constant NKF::VERSION
-
- * ext/nkf/nkf.c(guess): this becomes an alias of guess2
-
- * ext/nkf/test.rb: add --no-cp932
-
- * ext/nkf/nkf-utf8/nkf.c: original nkf2 revision 1.47
-
Wed Dec 1 02:21:02 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* signal.c (sighandler): call handler immediately only for default
handlers. [ruby-dev:25003]
-Tue Nov 30 23:49:12 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (pipe_open): errno should be preserved for rb_sys_fail() when
- fork failed.
-
-Tue Nov 30 16:18:50 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+Tue Nov 30 23:38:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (io_fread): need not to null terminate. [ruby-dev:24998]
- * eval.c (rb_eval): should check previous frame for ZSUPER.
-
* io.c (read_all): remove unnecessary rb_str_resize().
- [ruby-dev:24996]
+ [ruby-dev:24996] (backported from CVS HEAD)
* io.c (io_readpartial): ditto.
* io.c (io_read): ditto.
-Tue Nov 30 14:58:33 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+Tue Nov 30 16:18:50 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * instruby.rb (install): add arguments explicitly to "super".
+ * io.c (io_fread): need not to null terminate. [ruby-dev:24998]
-Tue Nov 30 00:49:08 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * io.c (read_all): remove unnecessary rb_str_resize().
+ [ruby-dev:24996]
- * eval.c (PUSH_FRAME): flags should have been initialized.
+ * io.c (io_read): ditto.
- * eval.c (rb_eval): [ruby-core:03856]
+Tue Nov 30 00:49:08 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_sysread): use temporary lock. [ruby-dev:24992]
-Tue Nov 30 00:12:57 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * regparse.c: now handles many alternatives (over 500000)
- in regexp. [ruby-dev:24773]
-
Mon Nov 29 16:06:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_write): insufficiently filled string
@@ -13113,19 +11513,10 @@ Mon Nov 29 15:22:28 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/io/nonblock/test_flush.rb: abandon tests when io/nonblock is
not supported.
-Mon Nov 29 13:37:54 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (fptr_finalize): must not use FILE after fclose().
- [ruby-dev:24985]
-
-Mon Nov 29 13:13:13 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (CreateChild): push back the last space before next
- loop because CharNext() eats it.
-
Mon Nov 29 03:08:30 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * object.c (convert_type): [ruby-core:03845]
+ * object.c (convert_type): direct call conversion methods for the
+ performance. [ruby-core:03845]
* eval.c (rb_funcall_rescue): new function.
@@ -13133,57 +11524,30 @@ Mon Nov 29 03:08:30 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (rb_Integer): ditto.
- * eval.c (get_backtrace): no conversion for nil.
-
* parse.y (reduce_nodes): empty body should return nil.
-Mon Nov 29 01:18:18 2004 Tanaka Akira <akr@m17n.org>
+ * string.c (rb_str_aset): the original string should not be
+ affected by modifying duplicated string. [ruby-dev:24981]
- * io.c (rb_io_check_writable): call io_seek regardless of
- NEED_IO_SEEK_BETWEEN_RW. [ruby-dev:24986]
+Mon Nov 29 13:57:38 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-Sun Nov 28 15:57:58 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb (RSS::Element#tag): not use block_given? for
- working with ruby 1.6 again.
-
- * lib/rss/{0.9,2.0,trackback}.rb, lib/rss/maker/base.rb:
- undef -> remove_method for working with ruby 1.6 again.
-
-Sun Nov 28 15:51:40 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb (RSS::NotSetError): added.
-
- * lib/rss/maker/{1.0,0.9,2.0}.rb: changed RSS Maker to raise
- RSS::NotSetError if required values of maker.channel are not
- set. [ruby-talk:120061]
-
- * test/rss/test_maker_{1.0,0.9,2.0}.rb: changed tests to check RSS
- Maker raises or not.
-
-Sun Nov 28 12:14:47 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * regparse.c (fetch_token): fixed test failure on HP-UX ia64
- ([ruby-dev:24859]).
-
-Sun Nov 28 12:08:15 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * regparse.c, test/ruby/test_regexp.rb: fixed problem with UTF-8
- characters that have U+00FE or invalid characters.
+ * win32/win32.c (CreateChild): search executable file if no program
+ name given. (backported from CVS HEAD)
-Sun Nov 28 12:07:04 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
+Mon Nov 29 13:37:54 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * regexec.c, test/ruby/test_regexp.rb: fixed segmentation fault
- ([ruby-dev:24887]).
+ * io.c (fptr_finalize): must not use FILE after fclose().
+ [ruby-dev:24985]
-Sun Nov 28 12:05:48 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
+Mon Nov 29 13:16:31 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * regcomp.c, regint.h: fixed PLATFORM_UNALIGNED_WORD_ACCESS
- problem ([ruby-dev:24802] and [ruby-core:3733])
+ * win32/win32.c (CreateChild): push back the last space before next
+ loop because CharNext() eats it.
-Sat Nov 27 23:43:39 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Nov 29 01:18:18 2004 Tanaka Akira <akr@m17n.org>
- * io.c (rb_io_initialize): [ruby-dev:24972]
+ * io.c (rb_io_check_writable): call io_seek regardless of
+ NEED_IO_SEEK_BETWEEN_RW. [ruby-dev:24986]
Sat Nov 27 21:43:39 2004 Tanaka Akira <akr@m17n.org>
@@ -13195,36 +11559,10 @@ Sat Nov 27 21:43:39 2004 Tanaka Akira <akr@m17n.org>
(rb_io_fwrite): wrapper for io_fwrite now.
(io_write): call io_fwrite instead of rb_io_fwrite.
-Sat Nov 27 17:43:21 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/{0.9,1.0,2.0,trackback,xml-stylesheet}.rb: added
- #setup_maker.
-
- * test/rss/test_setup_maker_*.rb: added tests for #setup_maker.
-
- * lib/rss/maker/base.rb(RSS::Maker::Items#max_size=): supported
- output item size limitation.
-
- * sample/rss/blend.rb: added sample for RSS Maker.
-
-Sat Nov 27 17:41:35 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/maker/0.9.rb: supported RSS::Maker.make("0.91"). Now,
- "0.9" is just alias of "0.91."
-
- * test/rss/test_maker_0.9.rb: make("0.9") -> maker("0.91").
-
- * test/rss/test_to_s.rb: ditto.
-
-Sat Nov 27 17:21:30 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * sample/rss/list_description.rb: untabified.
-
- * sample/rss/rss_recent.rb: ditto.
-
Sat Nov 27 14:44:15 2004 Kent Sibilev <ksibilev@bellsouth.net>
- * lib/cgi/session.rb (CGI::Session::initialize): [ruby-core:03832]
+ * lib/cgi/session.rb (CGI::Session::initialize): create_new_id is
+ now a instance method. [ruby-core:03832]
Sat Nov 27 09:41:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -13242,18 +11580,8 @@ Fri Nov 26 18:02:44 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/*: some methods uses TkWindow#epath
-Fri Nov 26 14:29:39 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * io.c (rb_io_initialize): uninitialized fd was checked to see open
- mode. [ruby-dev:24963]
-
- * io.c (rb_io_initialize): uninitialized fd was used. [ruby-dev:24962]
-
Fri Nov 26 13:49:06 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * io.c (rb_io_initialize): should retrieve flags from copying file
- descriptor. [ruby-dev:24961]
-
* eval.c (method_missing): raise TypeError for classes do not
have allocators. [ruby-core:03752]
@@ -13275,17 +11603,12 @@ Thu Nov 25 20:14:57 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/thwait.rb (ThreadsWait#join_nowait): abnormally terminated
threads should be also processed. [ruby-talk:121320]
-Thu Nov 25 18:06:37 2004 Tanaka Akira <akr@m17n.org>
+Thu Nov 25 10:14:26 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * configure.in: AC_CHECK_SIZEOF(rlim_t) to include stdio.h to fix
- problem with autoconf 2.52 or earlier.
- revert AC_PREREQ to 2.50.
- [ruby-core:3809]
+ * dir.c (push_braces): do not reuse buffer strings. [ruby-core:03806]
Thu Nov 25 07:59:41 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * configure.in: AC_PREREQ(2.53) [ruby-core:03800]
-
* io.c (read_all): stringify non-nil buffer argument, and always
taint the result. [ruby-dev:24955]
@@ -13316,12 +11639,13 @@ Tue Nov 23 00:10:48 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (dir_seek): use NUM2OFFT().
- * misc/ruby-mode.el (ruby-non-block-do-re): [ruby-core:03719]
+ * misc/ruby-mode.el (ruby-non-block-do-re): should not match words
+ start with block keyword and underscore. [ruby-core:03719]
Mon Nov 22 22:33:02 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::parse_require): Don't use names
- of variables or constants when parsing 'require'
+ of variables or constants when oarsing 'require'
Mon Nov 22 00:13:35 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -13331,7 +11655,7 @@ Mon Nov 22 00:13:35 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
Sat Nov 20 23:57:33 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/README (et al): Add a new directive, :section:, and
- change the output format to accommodate. :section: allows to to
+ change the output format to accomodate. :section: allows to to
group together methods, attributes, constants, etc under
headings in the output. If used, a table of contents is
generated.
@@ -13346,25 +11670,9 @@ Sat Nov 20 23:55:19 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_splice): should place index wrapping after
possible modification. [ruby-dev:24940]
-Sat Nov 20 23:25:12 2004 Minero Aoki <aamine@loveruby.net>
-
- * io.c (rb_io_getline): f.gets("") did not work. [ruby-core:03771]
-
- * test/ruby/test_io.rb (test_gets_rs): test it.
-
-Sat Nov 20 22:55:09 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * test/runner.rb (CROSS_COMPILING): need to require rbconfig.rb before
- using CROSS_COMPILNG.
-
-Sat Nov 20 20:42:42 2004 Minero Aoki <aamine@loveruby.net>
+Sat Nov 20 13:26:03 2004 NARUSE, Yui <naruse@ruby-lang.org>
- * ext/ripper/depend: fix ripper.o dependency.
-
-Sat Nov 20 17:48:29 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * io.c (io_reopen): work around problem with Cygwin fseeko
- returning ESPIPE.
+ * ext/nkf/nkf-utf8/utf8tbl.c: original revision 1.7
Sat Nov 20 05:34:24 2004 NARUSE, Yui <naruse@ruby-lang.org>
@@ -13372,11 +11680,6 @@ Sat Nov 20 05:34:24 2004 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/test.rb: add test for mime encode/decode
-Sat Nov 20 01:45:04 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * test/xmlrpc/test_webrick_server.rb : move `requrie "webrick/https"'
- into #setup_http_server method to avoid soap test errors.
-
Sat Nov 20 01:37:34 2004 Johan Holmberg <holmberg@iar.se>
* eval.c (error_print): nicer traceback at interrupt.
@@ -13387,66 +11690,6 @@ Sat Nov 20 00:07:16 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (str_gsub): internal buffer should not be listed by
ObjectSpace.each_object() by String#gsub. [ruby-dev:24931]
-Fri Nov 19 22:44:43 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * lib/test/unit/collector/dir.rb: better support for -p/-x option.
-
-Fri Nov 19 17:46:56 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/maker/0.9.rb (RSS::Maker::RSS09::Image#have_required_values):
- changed /rss/channel/image to be optional. [ruby-Bugs:1047]
-
- * test/rss/test_maker_0.9.rb: added tests for the above.
-
-Fri Nov 19 17:18:17 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb (RSS::VERSION): 0.1.0 -> 0.1.1.
-
- * lib/rss: #to_s used #tag.
-
- * test/rss/test_to_s.rb: added.
-
- * lib/rss/maker.rb (RSS::Maker.make): changed API. It's not
- received modules which is used as the second argument.
-
- * lib/rss/xml-stylesheet.rb (RSS::XMLStyleSheet#alternate):
- changed return value type which is not String but Boolean.
-
- * lib/rss/2.0.rb (RSS::Rss::Channel#ttl): changed return value
- type which is not String but Integer.
-
- * lib/rss/0.9.rb (RSS::Rss::Channel): <skipDays> has <day>s and
- <skipHours> has <hour>s.
-
- * lib/rss/maker/0.9.rb (RSS::Maker::RSS09::Channel): ditto.
-
- * lib/rss/0.9.rb (RSS::Rss::Channel::Item): <item> has <category>s.
-
- * lib/rss/maker/2.0.rb (RSS::Maker::Rss20::Channel::Item): ditto.
-
- * lib/rss/2.0.rb (RSS::Rss::Channel): <channel> has <category>s.
-
- * lib/rss/maker/2.0.rb (RSS::Maker::RSS20::Channel): ditto.
-
- * lib/rss/trackback.rb: parent element has <trackback:about>s.
-
- * lib/rss/maker/trackback.rb: ditto.
-
-Fri Nov 19 11:10:16 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * lib/test/unit/collector/dir.rb: add support for directory name
- with -p/-x options.
-
- * test/testunit/collector/test_dir.rb: ditto.
-
- * lib/xmlrpc/datetime.rb (XMLRPC::DateTime#==): should use Array()
- instead of to_a.
-
-Fri Nov 19 10:32:36 2004 Shugo Maeda <shugo@ruby-lang.org>
-
- * ext/readline/readline.c (readline_s_set_completion_append_character):
- accept nil. [ruby-core:03765]
-
Fri Nov 19 01:20:22 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/cgi/session.rb (CGI::Session::FileStore::initialize): raise
@@ -13458,37 +11701,12 @@ Fri Nov 19 00:59:31 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (str_gsub): internal buffer should not be listed by
ObjectSpace.each_object(). [ruby-dev:24919]
-Thu Nov 18 23:42:36 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/depend: Never regenerate lib/ripper/core.rb
- automatically. [ruby-dev:24911]
-
-Thu Nov 18 20:47:24 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.[ch] (rb_w32_isatty): new function to replace MSVCRT's
- isatty because it never sets errno.
-
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().
-
-Thu Nov 18 17:05:01 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (f_rest_arg): store rest args into invisible local variable
- in order to get rid of SEGV at ZSUPER. [ruby-dev:24913]
-
-Thu Nov 18 15:39:52 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * hash.c (rb_f_getenv): prohibit for $SAFE=4. [ruby-dev:24908]
-
-Thu Nov 18 14:58:42 2004 Shugo Maeda <shugo@ruby-lang.org>
-
- * ext/readline/readline.c: check $SAFE.
-
- * test/readline/test_readline.rb: added tests for readline.
+ (rb_str_swapcase_bang): missing rb_str_modify(). [ruby-dev:24915]
Thu Nov 18 00:21:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -13509,15 +11727,10 @@ Thu Nov 18 10:10:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_initialize): allow Fixnum as mode as
well as IO.new does. [ruby-dev:24896]
-Wed Nov 17 23:47:30 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Wed Nov 17 23:42:40 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/ruby/test_settracefunc.rb: added. [ruby-dev:24884]
-Wed Nov 17 18:59:16 2004 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * process.c (proc_getrlimit, proc_setrlimit): add rb_secure(2) to
- methods of Process.{getrlimit,setrlimit}
-
Wed Nov 17 13:56:57 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (newline_node): should not use FL_SET. [ruby-dev:24874]
@@ -13527,65 +11740,28 @@ Wed Nov 17 13:56:57 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* node.h (NODE_NEWLINE): remove unused bit to utilize flag field
in nodes.
-Wed Nov 17 13:05:10 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Nov 17 13:09:40 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * dir.c (rb_push_glob): fix overrun. [ruby-dev:24886]
+ * {bcc32,win32,wince}/Makefile.sub (test): should build ruby.exe
+ before running test. [ruby-core:03756]
-Wed Nov 17 11:48:17 2004 Michael Neumann <mneumann@ruby-lang.org>
+Wed Nov 17 04:33:01 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * lib/xmlrpc/parser.rb, test/xmlrpc/test_features.rb: fixed "assigning
- to constants" warnings
+ * pack.c: all features are backport from 1.9. [ruby-dev:24826]
-Wed Nov 17 09:38:18 2004 Johan Holmberg <holmberg@iar.se>
-
- * re.c (rb_reg_initialize_m): should raise exception instead of
- compile error. [ruby-core:03755]
+ * bignum.c (rb_big2ulong_pack): new function to pack Bignums.
Wed Nov 17 03:42:45 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_splice): move rb_str_modify() after
StringValue(), which may alter the receiver. [ruby-dev:24878]
- * error.c (rb_error_frozen): now raise RuntimeError instead of
- TypeError.
-
-Tue Nov 16 21:22:47 2004 Michael Neumann <mneumann@ruby-lang.org>
-
- * lib/xmlrpc/server.rb (CGIServer): fixed bug when client sends
- "Content-typ: text/xml; ..."
-
Tue Nov 16 23:45:07 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (flo_divmod): protect float values from GC by
assignment to local variables. [ruby-dev:24873]
-Tue Nov 16 14:31:54 2004 Michael Neumann <mneumann@ruby-lang.org>
-
- * test/xmlrpc/*: imported and refactored original test cases.
-
- * test/xmlrpc/test_webrick_server.rb, test/xmlrpc/webrick_testing.rb:
- added test case that starts up a WEBrick XML-RPC server and performs
- some tests on it (both http and https servers are started).
-
- * lib/xmlrpc/create.rb (XMLWriter::each_installed_writer),
- lib/xmlrpc/parser.rb (XMLParser::each_installed_parser):
- added methods to simply original test cases
-
- * lib/xmlrpc/parser.rb, lib/xmlrpc/datetime.rb: applied patch by
- MoonWolf <moonwolf@moonwolf.com> to allow parsing datetime.iso8601
- (e.g. 20041105T01:15:23Z).
-
- * lib/xmlrpc/server.rb: fixed issue #998
- (http://rubyforge.org/tracker/?func=detail&atid=1700&aid=998&group_id=426)
-
- * lib/xmlrpc/create.rb, lib/xmlrpc/utils.rb: when marshalling/loading
- user-defined data structures, use Class#allocate instead of defining
- an empty #initialize method. module XMLRPC::Marshallable is now only
- used for tagging.
-
- * lib/xmlrpc/.document, lib/xmlrpc/README.rdoc: added howto
-
-Tue Nov 16 16:26:12 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Nov 16 16:30:21 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* {bcc32,win32,wince}/setup.mak (-epilogue-): remove config.h and
config.status to force updating them.
@@ -13595,15 +11771,6 @@ Tue Nov 16 16:20:45 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_read): position was ignored when a
buffer was passed. http://www.yo.rim.or.jp/~nov/d/?date=20041116#p03
-Tue Nov 16 13:35:54 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * lib/test/unit/autorunner.rb (Test::Unit::AutoRunner::options): add
- new option --exclude (-x) to skip some tests. [ruby-core:3363],
- [ruby-dev:24865]
-
- * lib/test/unit/collector/dir.rb (Test::Unit::Collector::Dir.exclude):
- ditto.
-
Tue Nov 16 11:19:07 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/test/unit/autorunner.rb (Test::Unit::AutoRunner::options): use
@@ -13617,72 +11784,32 @@ Tue Nov 16 01:41:31 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_update): pedantic check to detect
rb_ary_to_ary() to modify the receiver. [ruby-dev:24861]
-Mon Nov 15 18:58:05 2004 Tanaka Akira <akr@m17n.org>
+Mon Nov 15 13:50:52 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * configure.in: check rlim_t more portably. [ruby-core:3735]
+ * string.c (rb_str_justify): typo fixed. [ruby-dev:24851]
Mon Nov 15 11:50:32 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* misc/ruby-mode.el (ruby-special-char-p, ruby-parse-partial): handle
operator symbols. [ruby-talk:120177]
-Mon Nov 15 08:58:55 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (Init_Proc): make proc as an alias to Proc.new.
- [ruby-dev:24848]
-
-Mon Nov 15 00:46:03 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_yield_0): lambda{}.call(1) should raise exception.
- [ruby-talk:120253]
-
-Mon Nov 15 00:33:40 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * string.c (rb_str_clear): avoid revealing NULL pointer.
- [ruby-dev:24766]
-
- * string.c (str_gsub): add paranoid check. [ruby-dev:24827]
-
- * string.c (str_mod_check): check frozen status as well.
- [ruby-dev:24801]
-
-Sun Nov 14 18:59:03 2004 Tanaka Akira <akr@m17n.org>
-
- * process.c (proc_getrlimit): new function for Process.getrlimit.
- (proc_setrlimit): new function for Process.setrlimit.
- [ruby-dev:24834]
-
- * configure.in: check rlim_t and its size. check setrlimit.
-
- * ruby.h (NUM2ULL): new macro.
-
Sun Nov 14 13:27:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/pp.rb (PP#object_address_group): remove odd number of 'f'
prefixed to negative address.
-Sun Nov 14 10:48:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/mathn.rb (Integer::gcd2): faster implementation by
- <erlercw@siu.edu>. [ruby-talk:120232]
-
-Sun Nov 14 08:46:33 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Sun Nov 14 08:51:04 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/logger/test_logger.rb: Logger just expects
Logger#datetime_format to be used for Time#strftime independently of
locale. [ruby-dev:24828]
-Fri Nov 12 17:32:07 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * bcc32/README.bcc32, win32/README.win32: need bison instead of
- byacc.
-
-Fri Nov 12 15:15:06 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Fri Nov 12 15:03:26 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* eval.c (ruby_options): now we cannot call rb_glob() before
ruby_init(), so call rb_w32_cmdvector() at ruby_options().
- * win32/win32.{c,h} (rb_w32_cmdvector): rename make_cmdvector() and
+ * win32.{c,h} (rb_w32_cmdvector): rename make_cmdvector() and
export it.
Fri Nov 12 14:08:01 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -13696,15 +11823,21 @@ Fri Nov 12 00:31:05 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/gdbm/gdbm.c (fgdbm_store): StringValue() may alter string
pointer. [ruby-dev:24783]
-Thu Nov 11 17:58:19 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+Thu Nov 11 17:36:12 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * dir.c (rb_glob): should have called rb_glob_caller().
- [ruby-dev:24773]
+ * dir.c (rb_globi): also should call back via rb_glob_caller().
+ [ruby-dev:24775]
-Thu Nov 11 16:56:10 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Nov 11 16:47:21 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* test/ruby/test_file.rb (test_truncate_wbuf): we want to test
- only File#truncate, not behavior of seek(2).
+ only File#truncate, not behaviour of seek(2).
+
+Thu Nov 11 09:41:01 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * dir.c (push_braces): was confusing VALUE and char*.
+
+ * dir.c (rb_push_glob): Dir.glob should have called its block.
Thu Nov 11 01:52:52 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -13718,10 +11851,6 @@ Wed Nov 10 22:49:01 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/delegate.rb (DelegateClass::dup): ditto.
-Wed Nov 10 19:47:55 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dir.c (glob_helper): path is a string object now.
-
Wed Nov 10 12:31:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* README.EXT (Example): extconf.rb is indispensable now.
@@ -13733,22 +11862,10 @@ Wed Nov 10 03:33:36 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/tile/style.rb: bug fix
-Tue Nov 9 22:24:07 2004 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf: original nkf.c rev:1.38
-
- * ext/nkf/nkf.c: fix bug: can't parse long-name options
-
- * ext/nkf/test.rb: fix bug: mime tests fail
-
Tue Nov 9 14:27:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/optparse.rb (OptionParser::Officious): moved from DefaultList.
-Tue Nov 9 00:50:06 2004 Dave Thomas <dave@pragprog.com>
-
- * lib/rdoc/rdoc.rb: Change version numbering of RDoc and ri
-
Tue Nov 9 01:05:04 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (rb_glob2): do not allocate buffer from heap to avoid
@@ -13762,7 +11879,15 @@ Tue Nov 9 01:05:04 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (fnmatch): p or s may be NULL. [ruby-dev:24749]
-Tue Nov 9 00:36:26 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Tue Nov 9 00:53:53 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+
+ * regex.c (slow_match): avoid GCC 3.4.x warnings.
+
+Tue Nov 9 00:50:06 2004 Dave Thomas <dave@pragprog.com>
+
+ * lib/rdoc/rdoc.rb: Change version numbering of RDoc and ri
+
+Mon Nov 8 23:38:35 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/extservm.rb: add DRb::ExtServManager#uri=.
[ruby-dev:24743]
@@ -13793,14 +11918,13 @@ Sun Nov 7 23:49:26 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib: ditto.
-Sat Nov 6 20:40:16 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+Sat Nov 6 14:58:44 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * ext/win32ole/win32ole.c: rename WIN32OLE#ole_obj_help to
- WIN32OLE#ole_type. alias ole_obj_help to ole_type.
+ * lib/webrick/server.rb (WEBrick::HTTPServer#start): remove
+ :DoNotReverseLookup option. (Socket#do_not_reverse_lookup is a
+ ruby 1.9 feature)
- * ext/win32ole/tests/testWIN32OLE.rb: ditto.
-
-Sat Nov 6 11:18:59 2004 Tadayoshi Funaba <tadf@dotrb.org>
+Sat Nov 6 11:31:04 2004 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date.rb (_parse): checks whether zone was given.
@@ -13809,10 +11933,6 @@ Sat Nov 6 00:46:27 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_locktmp): check STR_TMPLOCK flag before
locking. [ruby-dev:24727]
-Fri Nov 5 19:07:16 2004 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf: follow CVS Head of original nkf.
-
Fri Nov 5 18:12:42 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/scrollable.rb: divide Scrollable module into
@@ -13839,43 +11959,23 @@ Fri Nov 5 08:52:48 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* gc.c (gc_mark): stricter GC stack check.
+Fri Nov 5 08:52:48 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * gc.c (gc_mark): stricter GC stack check.
+
Fri Nov 5 08:34:43 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (str_gsub): should have removed rb_str_unlocktmp(str).
[ruby-dev:24708]
- * ext/socket/socket.c (s_recvfrom): buffer modification check.
- [ruby-dev:24708]
-
-Thu Nov 4 23:54:21 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * regexec.c, regparse.c, regint.h: fixed conflicts between
- vendor branch.
-
-Thu Nov 4 23:41:55 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c,
- regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c,
- regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
- imported Oni Guruma 3.4.0.
-
- * parse.y, re.c: Now mbclen() takes unsigned char as
- its argument.
-
Thu Nov 4 21:25:38 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (str_gsub): string modify check no longer based on
tmplock. [ruby-dev:24706]
-Thu Nov 4 21:13:48 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c(typelib_file_from_typelib): search "win16"
- entry to get library path.
-
- * ext/win32ole/win32ole.c(oletypelib_path): ditto.
+Thu Nov 4 19:27:46 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/win32ole/win32ole.c(ole_typedesc2val): add VT_LPWSTR, VT_LPSTR,
- VT_ERROR case.
+ * io.c (rb_f_open): fix typo.
Thu Nov 4 15:02:14 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -13893,6 +11993,10 @@ Thu Nov 4 03:11:33 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c (s_recvfrom): tmplock input buffer.
[ruby-dev:24705]
+Wed Nov 3 22:32:12 2004 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * process.c: On NetBSD don't use setruid() and setrgid().
+
Wed Nov 3 22:24:17 2004 Daigo Moriwaki <techml@sgtpepper.net>
* lib/webrick/httpauth/digestauth.rb: use Base64.encode64 to
@@ -13907,7 +12011,11 @@ Wed Nov 3 17:19:59 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_or): ditto.
-Wed Nov 3 17:02:48 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+Wed Nov 3 17:13:02 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * io.c (pipe_open): fix compile error
+
+Wed Nov 3 16:58:07 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: support to use different Tcl commands between
configure and configinfo
@@ -13923,55 +12031,33 @@ Wed Nov 3 17:02:48 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib: some bug fixes (see ext/tk/ChangeLog.tkextlib)
-Wed Nov 3 15:38:28 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * test/rss/*.rb: removed tab width configuration headers.
-
- * test/rss/test_maker_{0.9,1.0}.rb: sort -> do_sort.
+Wed Nov 3 16:30:41 2004 NARUSE, Yui <naruse@ruby-lang.org>
- * lib/rss/maker/*.rb: changed API to RSS version independence.
+ * ext/nkf: follow nkf 2.0.4
- * lib/rss/maker/base.rb
- (RSS::Maker::XMLStyleSheets::XMLStyleSheet): checked required
- (pseudo) attributes.
+Wed Nov 3 15:53:34 2004 Kouhei Sutou <kou@cozmixng.org>
- * lib/rss/maker/base.rb (RSS::Maker::Items): sort -> do_sort.
+ * test/rss/test_maker_*.rb: added tests for RSS Maker.
- * lib/rss/rss.rb (RSS::BaseModel.install_date_element): avoided
- warning.
+ * lib/rss/maker.rb: added RSS Maker.
- * lib/rss/0.9.rb (RSS::Rss#textinput): added convenience method.
+ * lib/rss/maker/*.rb: ditto.
Tue Nov 2 16:35:57 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/enumerator/enumerator.c (each_cons_i): pass copy of an
internal consequent array. [ruby-talk:118691]
-Tue Nov 2 14:54:02 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Nov 2 16:05:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * io.c (pipe_open): need to set cmd if argc == 0 (win32).
+ * process.c (rb_f_fork): need to flush stdout and stderr before
+ fork(2). [ruby-talk:117715]
Tue Nov 2 01:20:09 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * io.c (pipe_open): IO.popen should take array as 1st argument for
- a command line. [ruby-dev:24678]
-
* eval.c (proc_invoke): nail down dyna_var node when Proc object
or continuation is created. [ruby-dev:24671]
- * io.c (rb_io_s_popen): do not expand argv array. [ruby-dev:24670]
-
-Mon Nov 1 22:25:56 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/maker/base.rb: changed xml-stylesheet's API of RSS Maker
- like to item's one.
-
- * lib/rss/xml-stylesheet.rb (RSS::XMLStyleSheet#guess_type): fixed
- regular expression bug.
-
- * test/rss/test_maker_xml-stylesheet.rb: updated tests for
- xml-stylesheet.
-
Mon Nov 1 13:59:28 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* ext/extmk.rb (MANIFEST): do not use anymore, use extconf.rb instead.
@@ -13983,29 +12069,15 @@ Mon Nov 1 13:59:28 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* README.EXT, README.EXT.ja: remove MANIFEST stuff.
-Mon Nov 1 11:52:18 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * io.c (pipe_open): avoid conflict of variable name. [ruby-dev:24662]
-
-Mon Nov 1 11:46:19 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * process.c (rb_f_exec): should check whether prog is NULL.
-
-Mon Nov 1 09:37:19 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/maker.rb: added entry point of RSS Maker.
+Mon Nov 1 01:14:52 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-Mon Nov 1 03:14:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * io.c (rb_f_open): create copy of popen specifier. [ruby-dev:24656]
- * eval.c (rb_get_method_body): store ICLASS in the cache.
- [ruby-core:03672]
+Mon Nov 1 00:36:48 2004 WATANABE Hirofumi <eban@ruby-lang.org>
- * eval.c (rb_provided): should return true for loading library
- too for autoloading. [ruby-core:03655]
+ * main.c (_stklen): move to gc.c.
-Mon Nov 1 01:14:52 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * io.c (rb_f_open): create copy of popen specifier. [ruby-dev:24656]
+Sun Oct 31 00:22:28 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_locktmp): lock string temporarily.
@@ -14018,54 +12090,15 @@ Mon Nov 1 01:14:52 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (read_all): ditto.
-Sun Oct 31 23:37:00 2004 NARUSE, Yui <naruse@ruby-lang.org>
-
- * process.c: on NetBSD don't use setruid() and setrgid().
-
-Sun Oct 31 23:12:10 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/maker/*.rb: added RSS Maker.
-
- * test/rss/test_maker_*.rb: added tests for RSS Maker.
-
-Sun Oct 31 16:58:12 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c: add WIN32OLE.codepage, WIN32OLE.codepage=.
-
- * ext/win32ole/tests/testWIN32OLE.rb: ditto.
-
-Sun Oct 31 14:35:26 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * ext/nkf/nkf-utf8/nkf.c: add "\075?UTF-8?Q?" for Gmail.
-
-Sun Oct 31 14:18:56 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: emit lexer-event values to the parser
- (still incomplete).
-
-Sat Oct 30 15:24:41 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
-
- * ext/win32ole/win32ole.c: add WIN32OLE_TYPELIB class. add
- WIN32OLE#ole_typelib method.
-
- * ext/win32ole/tests/testOLETYPELIB.rb: add WIN32OLE_TYPELIB class.
-
Sat Oct 30 06:53:24 2004 Peter Vanbroekhoven <peter.vanbroekhoven@cs.kuleuven.ac.be>
* eval.c (rb_eval): NODE_XSTR should pass copy of literal string.
Sat Oct 30 00:19:40 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * array.c (rb_ary_update): a[n,m]=nil no longer works as element
- deletion.
-
* enum.c (enum_sort_by): protect continuation jump in.
[ruby-dev:24642]
- * eval.c (rb_eval), gc.c (gc_mark_children), node.h (NEW_ALIAS,
- NEW_VALIAS), parse.y (fitem): allow dynamic symbols to
- NODE_UNDEF and NODE_ALIAS.
-
Fri Oct 29 21:27:51 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_io_check_initialized): new function to check uninitialized
@@ -14073,26 +12106,6 @@ Fri Oct 29 21:27:51 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_path), io.c (rb_io_closed): check if initialized.
-Fri Oct 29 19:05:33 2004 NARUSE, Yui <naruse@ruby-lang.org>
-
- * ext/nkf: follow nkf2.0.
-
-Fri Oct 29 17:18:22 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * parse.y (ripper_s_allocate): add prototype for Microsoft compiler.
-
- * range.c (range_step, range_each): need cast.
-
-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]
-
-Fri Oct 29 11:35:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (rb_parser_append_print, rb_parser_while_loop): body node
- can be empty. [ruby-dev:24628]
-
Fri Oct 29 10:00:30 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_thread_start_0): forget to free some memory chunks.
@@ -14107,20 +12120,32 @@ Thu Oct 28 08:42:02 2004 Tanaka Akira <akr@m17n.org>
(argf_read): call argf_forward with argv argument.
[ruby-dev:24624]
+Thu Oct 28 23:32:54 2004 akira yamada <akira@ruby-lang.org>
+
+ * ext/zlib/zlib.c (zstream_detach_input): resets klass of z->input if
+ z->input isn't nil.
+
+Thu Oct 28 23:19:31 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/extmk.rb: prefer relative path. [ruby-talk:93037]
+
+Wed Oct 27 18:49:11 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * gc.c: prototype; rb_io_fptr_finalize() doesn't return any value
+ at this version.
+
+Wed Oct 27 17:27:45 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * gc.c (gc_sweep): recover ruby_in_compile variable.
+
Wed Oct 27 09:17:30 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (str_gsub): use a string object for exception safeness.
[ruby-dev:24601]
-Wed Oct 27 07:38:55 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * node.h (NODE_TYPESHIFT): allow 4 more bits for line numbers.
- [ruby-talk:117841]
-
- * ruby.h (FL_ABLE): nodes are not subject for flag operations.
+Tue Oct 26 23:52:32 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * io.c (ARGF_FORWARD): should have specified argv explicitly,
- since we no longer have frame->argv saved. [ruby-dev:24602]
+ * io.c (rb_io_getline): rs modification check should not interfere in the loop.
Tue Oct 26 23:30:39 2004 Dave Thomas <dave@pragprog.com>
@@ -14142,6 +12167,16 @@ Tue Oct 26 10:56:55 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* sprintf.c (rb_f_sprintf): raise ArgumentError for extra
arguments, unless (digit)$ style used.
+Tue Oct 26 11:33:26 2004 David G. Andersen <dga@lcs.mit.edu>
+
+ * ext/zlib/zlib.c (gzreader_gets): use memchr() to to gain
+ performance. [ruby-talk:117701]
+
+Tue Oct 26 10:56:55 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * sprintf.c (rb_f_sprintf): raise ArgumentError for extra
+ arguments, unless (digit)$ style used.
+
Mon Oct 25 18:35:39 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* win32/win32.c (isUNCRoot): should check NUL after '.'.
@@ -14153,16 +12188,11 @@ Mon Oct 25 08:03:26 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (get_backtrace): ignore illegal backtrace. [ruby-dev:24587]
-Sun Oct 24 00:40:50 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Oct 24 00:41:09 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_load, search_required, rb_require_safe, rb_require): use
frozen shared string to avoid outside modification. [ruby-dev:24580]
-Sat Oct 23 23:40:34 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * io.c (rb_io_fptr_finalize): leave stdin/stdout/stderr open in
- interpreter termination. [ruby-dev:24579]
-
Sat Oct 23 22:18:32 2004 Guy Decoux <ts@moulon.inra.fr>
* eval.c (frame_free): Guy Decoux solved the leak problem.
@@ -14206,10 +12236,6 @@ Thu Oct 21 19:06:15 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httpresponse.rb (WEBrick::HTTPResponse#send_body_io):
ensure to close @body. (http://bugs.debian.org/277520)
-Thu Oct 21 13:11:31 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * io.c (pipe_open): variable name "fpw" is conflicted.
-
Thu Oct 21 00:36:41 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_alias): should warn on method discarding.
@@ -14218,21 +12244,11 @@ Thu Oct 21 00:36:41 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/zlib/zlib.c (zstream_expand_buffer_into): hide internal
string buffer by clearing klass. [ruby-dev:24548]
- * parse.y (lex_getline): should not touch ruby_debug_lines if
- RIPPER is defined. [ruby-dev:24547]
-
Wed Oct 20 19:45:13 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (str_gsub): reentrant check. [ruby-dev:24432]
-Wed Oct 20 12:42:53 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (rb_io_getline): rs modification check should not interfere
- in the loop.
-
-Wed Oct 20 10:31:33 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (lex_getline): should update ruby_debug_lines.
+ * backport all SEGV bug fixes from CVS HEAD. [ruby-dev:24536]
Wed Oct 20 04:17:55 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -14254,23 +12270,13 @@ Wed Oct 20 01:37:18 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (ruby_exec): stack marking position may be higher than
expected. thanks to Guy Decoux. [ruby-core:03527]
-Wed Oct 20 00:25:41 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (search_required): required name must not be changed before
- loading. [ruby-dev:24492]
-
-Tue Oct 19 23:59:46 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_require_safe): provide the feature after loaded.
- [ruby-list:40085]
-
Tue Oct 19 22:43:12 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_attr): If
we come across 'attr' in a context where it isn't
followed by a symbol, just issue a warning.
-Tue Oct 19 20:32:50 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+Tue Oct 19 20:41:37 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole.c(ole_invoke): retrieve the result value when
retrying the IDispatch::invoke.
@@ -14290,7 +12296,15 @@ Tue Oct 19 17:24:11 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/zlib/zlib.c (zstream_expand_buffer): hide internal string
buffer by clearing klass. [ruby-dev:24510]
-Tue Oct 19 08:47:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Oct 19 16:12:18 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * ext/tk/tkutil.c: backport from CVS HEAD
+
+Tue Oct 19 08:54:26 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * intern.h, object.c (rb_class_inherited_p): export.
+
+Tue Oct 19 08:46:57 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_upto): method result must be checked. [ruby-dev:24504]
@@ -14301,20 +12315,60 @@ Mon Oct 18 23:37:05 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* marshal.c (r_object0): check inheritance by the internal function.
[ruby-dev:24515]
-Mon Oct 18 11:29:32 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Oct 18 15:58:01 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * range.c (range_step, range_each): need cast.
+
+Fri Oct 29 16:34:19 2004 Daiki Ueno <ueno@unixuser.org>
- * io.c (rb_io_flags_mode, rb_io_mode_flags): distinguish whether file
- not existing is created. [ruby-dev:24505]
+ * misc/ruby-mode.el (ruby-parse-partial): Parse the rest of the
+ line after opening heredoc identifier. [ruby-dev:24635]
Mon Oct 18 07:26:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_truncate): discard read buffer before truncation.
[ruby-dev:24197]
-Mon Oct 18 01:56:03 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Oct 18 02:11:21 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * lib/webrick/config.rb (WEBrick::Config::General): add default values:
+ - WEBrick::Config[:DoNotReverseLookup]
+ - WEBrick::Config[:RequestCallback] (it used as an alias of
+ :RequestHandler in WEBrick::HTTPServer#run)
+ - WEBrick::Config::FileHandler[:AcceptableLanguages]
+
+ * lib/webrick/httpservlet/filehandler.rb
+ (WEBrick::HTTPServlet::FileHandler#set_filename): search files
+ having suffix of language-name which Accept-Language header field
+ includes if :AcceptableLanguages options is present.
+
+ * lib/webrick/httpservlet/filehandler.rb
+ (WEBrick::HTTPServlet::FileHandler#get_servlet): new method to
+ search servlet correspond to the suffix of filename.
+
+ * lib/webrick/httprequest.rb: add attributes access methods: accept,
+ accept_charset, accept_encoding, accept_language, content_length
+ and content_type.
- * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#initialize):
- initial value of accpet-* should be array.
+ * lib/webrick/httpresponse.rb: add attribute access methods:
+ content_length, content_length=, content_type and content_type=.
+
+ * lib/webrick/httputils.rb (WEBrick::HTTPUtils.mime_types):
+ use the second suffix to detect media type. (the first suffix
+ may be a language name.)
+
+ * lib/webrick/httputils.rb (WEBrick::HTTPUtils.parse_qvalues):
+ add method to parse Accept header field. it returns an Array of
+ values sorted by the qvalues.
+
+Mon Oct 18 02:04:11 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * lib/webrick/httpserver.rb (WEBrick::HTTPServer#virtual_host): new
+ method to register virtual hosting servers.
+
+ * lib/webrick/server.rb (WEBrick::GenericServer#accept): call
+ do_not_reverse_lookup for each socket if :DoNotReverseLookup
+ is set. [ruby-core:02357]
Mon Oct 18 00:42:45 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -14328,7 +12382,7 @@ Sun Oct 17 23:03:48 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/timer.rb: TkTimer#start and restart accept a block
-Sun Oct 17 12:53:46 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+Sun Oct 17 13:05:04 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (fole_func_methods): correct argument mismatch.
* ext/win32ole/win32ole.c (fole_get_methods): ditto.
@@ -14351,21 +12405,6 @@ Sat Oct 16 13:34:56 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss: supported prety print.
* test/rss/test_1.0.rb: added test for calculating default indent size.
-Sat Oct 16 10:56:36 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb (create_makefile): install-rb is needed for statically
- linked extensions. [ruby-dev:24491]
-
-Fri Oct 15 18:07:08 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_x509store.c
- (ossl_x509stctx_initialize): setup OpenSSL::X509::StoreContext with
- ossl_x509stctx_* functions instead of X509_STORE_CTX_*.
- (ossl_x509store_set_time): add OpenSSL::X509::Store#time=.
- (ossl_x509stctx_set_time): add OpenSSL::X509::StoreContext#time=.
-
- * test/openssl/ossl_x509store.rb: test certificate validity times.
-
Fri Oct 15 18:04:35 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/timer.rb: TkTimer.new(interval, loop){ ... } is
@@ -14376,60 +12415,13 @@ Fri Oct 15 12:43:09 2004 Tanaka Akira <akr@m17n.org>
* eval.c (Init_stack): make prototype declaration consistent with
the definition in gc.c.
-Thu Oct 14 13:33:59 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/rss.rb: added link to Tutorial.
-
-Tue Oct 12 21:22:50 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/config.rb:
- add WEBrick::Config::FileHandler[:AcceptableLanguages].
-
- * lib/webrick/httpservlet/filehandler.rb
- (WEBrick::HTTPServlet::FileHandler#set_filename): search files
- having suffix of language-name which Accept-Language header field
- includes if :AcceptableLanguages options is present.
-
- * lib/webrick/httpservlet/filehandler.rb
- (WEBrick::HTTPServlet::FileHandler#get_servlet): new method to
- search servlet correspond to the suffix of filename.
-
- * lib/webrick/httprequest.rb: add attributes access methods: accept,
- accept_charset, accept_encoding, accept_language, content_length
- and content_type.
-
- * lib/webrick/httpresponse.rb: add attribute access methods:
- content_length, content_length=, content_type and content_type=.
-
- * lib/webrick/httputils.rb (WEBrick::HTTPUtils.mime_types):
- use the second suffix to detect media type. (the first suffix
- may be a language name.)
-
- * lib/webrick/httputils.rb (WEBrick::HTTPUtils.parse_qvalues):
- add method to parse Accept header field. it returns an Array of
- values sorted by the qvalues.
-
-Tue Oct 12 15:05:32 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+Thu Oct 14 14:34:01 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* io.c (MODE_BINMODE, MODE_BINARY): fixed reversed condition.
-Mon Oct 11 17:51:34 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * io.c (rb_io_popen): get mode string via rb_io_flags_mode() to
- avoid mode string modification. [ruby-dev:24454]
-
- * io.c (rb_io_getline_fast): should take delim as unsigned char to
- distinguish EOF and '\377'. [ruby-dev:24460]
-
- * io.c (rb_io_getline): add check for RS modification.
- [ruby-dev:24461]
-
- * enum.c (enum_sort_by): use qsort() directly instead using
- rb_iterate(). [ruby-dev:24462]
+Thu Oct 14 13:33:59 2004 Kouhei Sutou <kou@cozmixng.org>
- * enum.c (enum_each_with_index): remove rb_gc_force_recycle() to
- prevent access to recycled object (via continuation for
- example). [ruby-dev:24463]
+ * lib/rss/rss.rb: added link to Tutorial.
Mon Oct 11 13:48:20 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -14440,16 +12432,6 @@ Sun Oct 10 12:32:08 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::parse_require): Allow 'require'
to be used as a variable name
-Sun Oct 10 02:49:14 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/lib/ripper/filter.rb: require ripper/tokenizer.
-
- * ext/ripper/lib/ripper/filter.rb (parse): argument is optional.
-
-Sun Oct 10 02:43:13 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: \n between two comments disappeared.
-
Sat Oct 9 21:23:37 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/converter.rb: changed to try to use Iconv for default
@@ -14462,19 +12444,6 @@ Sat Oct 9 19:50:36 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_io_getline): should not treat char as negative value.
[ruby-dev:24460]
-Sat Oct 9 00:25:39 2004 Tanaka Akira <akr@m17n.org>
-
- * io.c (rb_io_fread): rb_thread_wait_fd() was lost.
- [ruby-dev:24457]
-
-Fri Oct 8 21:36:56 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (fu_traverse): return value of Dir.entries is
- reliable. (pass $SAFE=1)
-
- * lib/fileutils.rb (remove_dir): return value of Dir.foreach is
- reliable. (pass $SAFE=1)
-
Fri Oct 8 09:49:32 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (pack_pack): pointer modification check before each
@@ -14534,19 +12503,7 @@ Wed Oct 6 09:21:00 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* range.c (member_i): use RANGE_EACH_BREAK. [ruby-talk:114959]
-Tue Oct 5 09:53:22 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * io.c (rb_fopen): mode string copy at the lowest level.
-
- * io.c (rb_io_flags_mode): requires output buffer no more. no
- allocation needed.
-
- * array.c (rb_ary_index): takes a block to compare items in an
- array. [ruby-talk:113069] [Ruby2]
-
- * array.c (rb_ary_rindex): ditto.
-
-Mon Oct 4 14:03:40 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Oct 4 14:04:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_file_open_internal, rb_io_reopen): fname might be altered
while GC. [ruby-dev:24408]
@@ -14558,21 +12515,16 @@ Mon Oct 4 12:53:45 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/image.rb: bug fix
-Sun Oct 3 21:16:05 2004 Shugo Maeda <shugo@ruby-lang.org>
+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.
+ version of Microsoft Exchange Server. (backported from HEAD)
* lib/net/imap.rb (RTEXT_REGEXP): ditto.
* lib/net/imap.rb (CTEXT_REGEXP): ditto.
-Sat Oct 2 20:34:05 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (local_vars): moved to struct parser_params.
- [ruby-dev:24391]
-
- * parser.y (stmts): remove suspicious NODE_BEGIN. [ruby-dev:24390]
+Sat Oct 2 20:34:22 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* node.h (NEW_DVAR): extra semicolon.
@@ -14594,6 +12546,9 @@ Sat Oct 2 00:42:20 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (specific_eval): defer pointer retrieval to prevent
unsafe sourcefile string modification. [ruby-dev:24382]
+ * eval.c (specific_eval): defer pointer retrieval to prevent
+ unsafe sourcefile string modification. [ruby-dev:24382]
+
* string.c (rb_str_sum): wrong cast caused wrong result.
[ruby-dev:24385]
@@ -14605,6 +12560,24 @@ Sat Oct 2 00:42:20 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_sum): string may be altered. [ruby-dev:24381]
+Mon Oct 11 17:51:34 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * io.c (rb_io_popen): get mode string via rb_io_flags_mode() to
+ avoid mode string modification. [ruby-dev:24454]
+
+ * io.c (rb_io_getline_fast): should take delim as unsigned char to
+ distinguish EOF and '\377'. [ruby-dev:24460]
+
+ * io.c (rb_io_getline): add check for RS modification.
+ [ruby-dev:24461]
+
+ * enum.c (enum_sort_by): use qsort() directly instead using
+ rb_iterate(). [ruby-dev:24462]
+
+ * enum.c (enum_each_with_index): remove rb_gc_force_recycle() to
+ prevent access to recycled object (via continuation for
+ example). [ruby-dev:24463]
+
Fri Oct 1 11:40:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_f_eval): defer pointer retrieval to prevent unsafe
@@ -14649,18 +12622,6 @@ Wed Sep 29 10:58:07 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* enum.c (sort_by_i): internally used object must not be changed
outside. [ruby-dev:24368]
-Mon Sep 27 21:25:12 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_call0): invoke finalizers periodically.
-
- * gc.c (gc_sweep): defer running finalizers. [ruby-dev:24354]
-
- * gc.c (rb_gc_finalize_deferred): run deferred finalizers.
-
-Mon Sep 27 15:01:59 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: missing ';'.
-
Mon Sep 27 13:46:45 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* intern.h, struct.c (rb_struct_s_members, rb_struct_members): public
@@ -14670,34 +12631,9 @@ Mon Sep 27 13:46:45 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
Mon Sep 27 09:14:03 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * array.c (rb_ary_delete): comparison may change the capacity.
- [ruby-dev:24348]
-
- * array.c (rb_ary_fill): fill should honor length argument.
- [ruby-dev:24346]
-
- * array.c (rb_ary_replace): should not use ptr from shared array.
- [ruby-dev:24345]
-
* ext/socket/socket.c (s_accept): don't retry for EWOULDBLOCK.
[ruby-talk:113807]
-Sun Sep 26 08:05:10 2004 Tadayoshi Funaba <tadf@dotrb.org>
-
- * lib/date.rb: provides {Time,Date,DateTime}#to_{time,date,datetime}.
-
- * sample/cal.rb: uses getoptlong instead of getopts.
-
-Sat Sep 25 18:39:22 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * array.c (flatten): element size might change during comparison.
- [ruby-dev:24343]
-
-Sat Sep 25 01:52:49 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * struct.c (rb_struct_s_members): wrong call of struct_members.
- [ruby-dev:24333]
-
Fri Sep 24 16:09:42 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (proc_invoke): propagate DVAR_DONT_RECYCLE on termination
@@ -14705,11 +12641,6 @@ Fri Sep 24 16:09:42 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
Fri Sep 24 08:29:45 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * parse.y (rb_parser_append_print): should handle prelude.
- [llama@u01.gate0]
-
- * parse.y (rb_parser_while_loop): ditto.
-
* array.c (rb_ary_subseq): original object might be modified after
sharing data creation. [ruby-dev:24327]
@@ -14720,22 +12651,6 @@ Fri Sep 24 08:29:45 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* struct.c (struct_members): always check struct size and size of
members list in the class. [ruby-dev:24320]
-Thu Sep 23 19:48:14 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/Makefile.dev: removed.
-
- * ext/ripper/ripper.rb.in: moved to lib/ripper/core.rb.in.
-
- * ext/ripper/lib/ripper/core.rb: new file.
-
- * ext/ripper/lib/ripper/core.rb.in: new file.
-
- * ext/ripper/tools/generate-ripper_rb.rb: change comment.
-
- * test/ripper/*.rb: on__scan event removed.
-
- * test/ripper/*.rb: event name is changed: on__XXX -> on_XXX.
-
Thu Sep 23 09:29:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_sub_bang): check if string is not modified
@@ -14744,50 +12659,23 @@ Thu Sep 23 09:29:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* hash.c (rb_hash_rehash): replace st_foreach() by its deep
checking counterpart. [ruby-dev:24310]
-Wed Sep 22 14:21:54 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: on__scan event removed.
-
- * parse.y [ripper]: event name is changed: on__XXX -> on_XXX.
-
- * ext/ripper/eventids2.c: ditto.
-
- * ext/ripper/ripper.rb.in: ditto.
-
- * ext/ripper/lib/ripper.rb: sync with ripper.rb.in.
-
- * ext/ripper/lib/ripper/tokenizer: ditto.
-
- * ext/ripper/lib/ripper/filter: new file.
-
- * sample/ripper/colorize.rb: new file.
-
- * sample/ripper/strip-comment.rb: new file.
-
-Wed Sep 22 13:50:49 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * hash.c (hash_alloc): was using tbl pointer without
- initialization.
-
Wed Sep 22 13:38:12 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* hash.c (rb_hash_rehash): add iteration check. [ruby-dev:24301]
* st.c (st_foreach): add deep check.
- * hash.c (rb_hash_fetch): returns KeyError instead of IndexError.
+Wed Sep 22 13:06:14 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * hash.c (env_fetch): ditto.
+ * win32/win32.c (rb_w32_call_handler): workaround for Ctrl-C.
+ merge from HEAD.
-Wed Sep 22 13:02:02 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Wed Sep 22 00:11:12 2004 Dave Thomas <dave@pragprog.com>
- * win32/win32.c (rb_w32_call_handler): workaround for Ctrl-C.
+ * process.c: Add documentation for fork()
Wed Sep 22 09:04:41 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * parse.y: remove global variables ruby_eval_tree and
- ruby_eval_tree_begin.
-
* array.c (rb_ary_collect_bang): element size might change during
comparison. [ruby-dev:24300]
@@ -14795,116 +12683,13 @@ Wed Sep 22 09:04:41 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_eql): ditto. [ruby-dev:24300]
-Wed Sep 22 00:11:12 2004 Dave Thomas <dave@pragprog.com>
-
- * process.c: Add documentation for fork()
-
Tue Sep 21 18:29:49 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * array.c (rb_ary_equal): merge miss.
+
* array.c (rb_ary_uniq_bang): element size might change during
comparison. [ruby-dev:24298]
-Mon Sep 20 17:46:51 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/lib/ripper/tokenizer.rb: fix typo.
-
-Mon Sep 20 17:38:43 2004 Minero Aoki <aamine@loveruby.net>
-
- * test/ripper/test_scanner_events.rb: tokens must be reordered.
-
- * ext/ripper/lib/ripper/tokenizer.rb: ditto.
-
-Mon Sep 20 16:58:16 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: do not delay dispatching.
-
- * ext/ripper/lib/ripper/tokenizer.rb: sort tokens by right order.
-
-Mon Sep 20 15:17:47 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/lib/ripper/tokenizer.rb: new file.
-
-Mon Sep 20 15:13:52 2004 Minero Aoki <aamine@loveruby.net>
-
- * test/ripper/test_scanner_events.rb: test #lineno and #column.
-
-Mon Sep 20 14:50:17 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: delayed heredocument events should be
- dispatched after EOF.
-
-Mon Sep 20 14:39:42 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: adjust lineno and columns for multi-line
- strings.
-
- * parse.y [ripper]: delay heredocument events until seeing
- end-of-line.
-
- * parse.y [ripper]: event on__heredoc_contentn ->
- on__tstring_content.
-
- * ext/ripper/eventids2.c: ditto.
-
- * ext/ripper/lib/ripper.rb: sync with eventids2.c.
-
- * test/ripper/test_scanner_events.rb: test it.
-
- * ext/ripper/tools/generate-ripper_rb.rb: show basename of input.
-
- * ext/ripper/Makefile.dev: support objdir build.
-
-Mon Sep 20 13:22:55 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: remove Ripper#pos.
-
- * parse.y [ripper]: Ripper#column should return the column of the
- current token.
-
-Mon Sep 20 12:02:41 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: unify old_lex_p and token_head.
-
- * test/ripper/test_scanner_events.rb: now \r\n is saved correctly.
-
- * parse.y: new macro lex_goto_eol() for next change.
-
-Mon Sep 20 11:01:55 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: adjust line number for heredoc. [ruby-dev:24272]
-
-Mon Sep 20 04:49:22 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/ripper.rb.in: new const Ripper::PARSER_EVENT_TABLE.
-
- * ext/ripper/ripper.rb.in: new const Ripper::SCANNER_EVENT_TABLE.
-
- * ext/ripper/lib/ripper.rb: sync with ripper.rb.in.
-
-Mon Sep 20 04:13:00 2004 Minero Aoki <aamine@loveruby.net>
-
- * test/ripper/test_scanner_events.rb: test spaces before heredoc
- mark.
-
-Mon Sep 20 03:46:54 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: spaces before heredoc marker was lost.
- [ruby-dev:24272]
-
- * keywords: rb_reserved_word() should be defined only in ruby
- core. [ruby-dev:24272]
-
- * lex.c: sync with keywords.
-
- * ext/ripper/ripper.rb.in (parse): fix typo.
-
- * ext/ripper/lib/ripper.rb: sync with ripper.rb.in.
-
-Mon Sep 20 03:37:59 2004 Tanaka Akira <akr@m17n.org>
-
- * ext/zlib/zlib.c (gzfile_read_raw): call readpartial at first.
- (Zlib::GzipReader#readpartial): new method.
-
Mon Sep 20 00:24:19 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* enum.c (enum_sort_by): do not use qsort directly. use
@@ -14946,23 +12731,15 @@ Sat Sep 18 14:10:23 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
direcotry or within block. thanks to Johan Holmberg
<holmberg@iar.se> [ruby-core:03446]
-Fri Sep 17 20:29:33 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Fri Sep 17 20:20:27 2004 Minero Aoki <aamine@loveruby.net>
- * parse.y: add prototypes for Microsoft compiler.
-
- * ext/ripper/depend (parse.obj): lex.c exists at hdrdir.
-
- * {bcc32,win32,wince}/Makefile.sub (YACC, YFLAGS, parse.c):
- use bison.
+ * lib/fileutils.rb (mkdir_p): backport from CVS HEAD 1.45. [ruby-core:03420]
Fri Sep 17 17:11:08 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_delete): element comparison might change array
size. [ruby-dev:24273]
- * parse.y: make ruby parser reentrant. merge ripper parser to the
- real one. this change makes ruby require bison.
-
* file.c (rb_file_truncate): clear stdio buffer before truncating
the file. [ruby-dev:24191]
@@ -14990,7 +12767,7 @@ Fri Sep 17 15:01:57 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/tkoptdb-safeTk.rb: ditto
-Thu Sep 16 18:12:13 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Sep 16 18:12:32 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/cgi.rb (WEBrick::CGI#start): should set REMOTE_USER
to request.user attribute.
@@ -15019,44 +12796,6 @@ Tue Sep 14 23:45:44 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_formatter.rb (RI::TextFormatter::TextFormatter.for):
Add Eric Hodel's simpleformatter.
-Tue Sep 14 22:11:08 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: Add rdoc.
-
-Tue Sep 14 20:24:49 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y [ripper]: space event is on__sp, not on__lwsp.
- [ruby-dev:24257]
-
- * ext/ripper/eventids2.c: ditto.
-
- * ext/ripper/lib/ripper.rb: ditto.
-
- * ext/ripper/depend (ripper.o): No action is needed.
- [ruby-dev:24260]
-
- * ext/ripper/depend: Borland make does not accept pipes in
- Makefile rules. [ruby-dev:24589]
-
- * ext/ripper/depend: separate rules for developpers.
-
- * ext/ripper/Makefile.dev: new file.
-
- * ext/ripper/MANIFEST: add Makefile.dev.
-
- * ext/ripper/tools/generate-eventids1.rb: read from file, not
- stdin.
-
- * ext/ripper/extconf.rb: clean ripper.E.
-
- * ext/ripper/tools/generate-ripper_rb.rb: #include ids1/ids2
- function was lost.
-
- * ext/ripper/tools/generate-ripper_rb.rb: SCANNER_EVENTS wrongly
- contained parser events.
-
- * ext/ripper/lib/ripper.rb: ditto.
-
Tue Sep 14 16:59:37 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c: fix SEGV
@@ -15067,22 +12806,9 @@ Tue Sep 14 16:59:37 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/safe-tk.rb: new sample script
+Tue Sep 14 00:15:15 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-Mon Sep 13 21:33:40 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_x509name.c (ossl_x509name_to_s): add optional
- second argument to specify the output format (see also
- X509_NAME_print_ex).
-
- * ext/openssl/ossl_x509name.c (ossl_x509name_init): new constants:
- OpenSSL::X509::Name::COMPAT, OpenSSL::X509::Name::RFC2253,
- OpenSSL::X509::ONELINE, OpenSSL::X509::MULTILINE.
-
- * ext/openssl/lib/openssl/x509.rb (OpenSSL::X509::Name::RFC2253DN):
- new module to provide the parse for RFC2253 DN format.
-
- * ext/openssl/lib/openssl/x509.rb (OpenSSL::X509::Name.parse_rfc2253):
- new method to parse RFC2253 DN format.
+ * ext/zlib/zlib.c: backported from HEAD.
Mon Sep 13 19:16:33 2004 WATANABE Hirofumi <eban@ruby-lang.org>
@@ -15093,92 +12819,10 @@ Mon Sep 13 16:23:27 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: MultiTkIp.new_master and new_slave accept
safe-level value argument
-Mon Sep 13 10:48:37 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (rb_w32_getpid): don't need to use _getpid() on
- mswin32 and mingw32.
-
-Mon Sep 13 10:22:05 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Mon Sep 13 10:20:45 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* object.c (nil_inspect): fix typo.
-Mon Sep 13 09:29:58 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/depend: (nmake hack) prepend "./" to ripper.c to
- avoid {$(srcdir)}.
-
-Mon Sep 13 06:43:42 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper/tools/list-parse-event-ids.rb: does not use getopts.
-
- * ext/ripper/tools/list-scan-event-ids.rb: ditto.
-
-Mon Sep 13 02:42:28 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/Setup: add ripper.
-
- * ext/Setup.atheos: ditto.
-
- * ext/Setup.dj: ditto.
-
- * ext/Setup.emx: ditto.
-
- * ext/Setup.nt: ditto.
-
- * ext/Setup.x68: ditto.
-
-Mon Sep 13 02:26:31 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/ripper: ripper extention added.
-
- * ext/ripper/MANIFEST: new file.
-
- * ext/ripper/README: new file.
-
- * ext/ripper/depend: new file.
-
- * ext/ripper/extconf.rb: new file.
-
- * ext/ripper/eventids2.c: new file.
-
- * ext/ripper/ripper.rb.in: new file.
-
- * ext/ripper/lib/ripper.rb: new file.
-
- * ext/ripper/test/check-event-arity.rb: new file.
-
- * ext/ripper/test/check-event-coverage.sh: new file.
-
- * ext/ripper/test/check-scanner-event-coverage.rb: new file.
-
- * ext/ripper/test/list-called-events.rb: new file.
-
- * ext/ripper/test/src_rb: new file.
-
- * ext/ripper/test/validate.rb: new file.
-
- * ext/ripper/tools/generate-eventids1.rb: new file.
-
- * ext/ripper/tools/generate-param-macros.rb: new file.
-
- * ext/ripper/tools/generate-ripper_rb.rb: new file.
-
- * ext/ripper/tools/list-parse-event-ids.rb: new file.
-
- * ext/ripper/tools/list-scan-event-ids.rb: new file.
-
- * ext/ripper/tools/preproc.rb: new file.
-
- * ext/ripper/tools/strip.rb: new file.
-
- * test/ripper: ripper tests added.
-
- * test/ripper/dummyparser.rb: new file.
-
- * test/ripper/test_parser_events.rb: new file.
-
- * test/ripper/test_scanner_events.rb: new file.
-
Mon Sep 13 01:03:02 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c: improve control of preserv/release tcltkip
@@ -15187,19 +12831,7 @@ Mon Sep 13 01:03:02 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tkutil.c: fix(?) SEGV
-Mon Sep 13 00:22:53 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y: fix file header.
-
-Mon Sep 13 00:20:39 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y: ripper merged.
-
- * lex.c: ditto.
-
- * keywords: ditto.
-
-Sun Sep 12 23:53:17 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sun Sep 12 23:46:23 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* util.c (ruby_strdup): remove unnecessary code. (xmalloc never
returns NULL.)
@@ -15211,6 +12843,7 @@ Sun Sep 12 02:41:58 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c: add TclTkIp#allow_ruby_exit? and
allow_ruby_exit=
+
* ext/tk/lib/multi-tk.rb: ditto.
* ext/tk/lib/remote-tk.rb: ditto.
@@ -15231,25 +12864,11 @@ Sat Sep 11 16:09:46 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb: Fix up cross-file class merging.
-Fri Sep 10 20:18:05 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Sep 10 20:20:53 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/tcltklib/tcltklib.c (lib_merge_tklist): fix suspicious
pointer conversion.
-Fri Sep 10 19:16:24 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * bcc32/Makefile.sub: bccwin32 port starts to use RTL dll.
- (need to rebuild all) [ruby-dev:24138]
-
- * win32/win32.{h,c}: ditto.
-
-Fri Sep 10 15:55:59 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (mkdir_p): should pass mode argument to
- Dir.mkdir. [ruby-dev:24242]
-
- * test/fileutils/test_fileutils.rb: test it.
-
Fri Sep 10 02:43:54 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/template/kilmer.rb: James Buck's
@@ -15291,16 +12910,9 @@ Tue Sep 7 15:17:49 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/socket/socket.c (ruby_connect): break immediately if a
socket is non-blocking. [ruby-talk:111654]
-Tue Sep 7 12:48:22 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * {bcc32,win32,wince}/Makefile.sub (config.h): add fcntl.
+Mon Sep 6 11:08:50 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * win32/win32.[ch] (fcntl): ditto.
-
- * win32/win32.c (rb_w32_connect): support nonblocking mode.
-
- * ext/socket/socket.c (wait_connectable, ruby_connect): support
- nonblocking connect on various platforms.
+ * ext/tk/lib/tk/menu.rb(TkOptionMenubutton#insert): call correct method
Mon Sep 6 11:00:47 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -15308,10 +12920,6 @@ Mon Sep 6 11:00:47 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
exception occurred within a block. a patch was given from Johan
Holmberg <holmberg at iar.se>. [ruby-core:03292]
-Mon Sep 6 10:57:40 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ext/tk/lib/tk/menu.rb(TkOptionMenubutton#insert): call correct method
-
Mon Sep 6 07:51:42 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (cvar_cbase): singletons should refer outer cvar scope.
@@ -15345,20 +12953,18 @@ Fri Sep 3 02:12:48 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Fri Sep 3 01:54:20 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/extmk.rb (extmake): extact target prefix from Makefiles.
-
* ext/extmk.rb: already built-in libraries satisfy dependencies.
[ruby-dev:24028]
-Wed Sep 1 21:16:50 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Sep 2 11:36:20 2004 WATANABE Hirofumi <eban@ruby-lang.org>
- * ext/tk/lib/tk/spinbox.rb: fix typo
+ * eval.c (rb_obj_instance_eval): backported from HEAD.
-Wed Sep 1 19:28:37 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Sep 1 21:18:25 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * process.c (rb_proc_exec): label cannot precede variable declarations.
+ * ext/tk/lib/tk/spinbox.rb: fix typo
-Tue Aug 31 18:20:49 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Aug 31 18:24:04 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/tk/tkutil.c (cbsubst_init): fix memory leak
@@ -15373,10 +12979,6 @@ Tue Aug 31 12:30:36 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c (del_root): fix SEGV
-Mon Aug 30 21:50:14 2004 Dave Thomas <dave@pragprog.com>
-
- * object.c: Add RDoc for Module.included.
-
Mon Aug 30 23:11:06 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_driver.rb (and others): ri now merges documentation
@@ -15386,10 +12988,19 @@ Mon Aug 30 22:40:30 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: 'restart' method accepts arguments
+Mon Aug 30 21:50:14 2004 Dave Thomas <dave@pragprog.com>
+
+ * object.c: Add RDoc for Module.included.
+
Mon Aug 30 15:10:46 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* configure.in (GNU/k*BSD): fixed FTBFS on GNU/k*BSD. [ruby-dev:24051]
+Mon Aug 30 11:29:35 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/win32.c (CreateChild): strip trailing spaces. [ruby-dev:24143]
+ merge from HEAD.
+
Sun Aug 29 14:08:56 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c: compile error on bcc32 [ruby-dev:24081]
@@ -15401,49 +13012,27 @@ Sat Aug 28 23:04:41 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* bignum.c (rb_big_and): protect parameters from GC.
[ruby-talk:110664]
-Fri Aug 27 12:13:50 2004 Tanaka Akira <akr@m17n.org>
-
- * ext/stringio/stringio.c (Init_stringio): add StringIO#readpartial as
- an alias for StringIO#sysread.
-
-Fri Aug 27 10:14:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (rb_proc_exec): strip trailing spaces. [ruby-dev:24143]
-
- * win32/win32.c (CreateChild): ditto.
-
Thu Aug 26 04:38:29 2004 Dave Thomas <dave@pragprog.com>
* eval.c (return_jump): Minor typo in error message. Now reads
"return can't jump across threads".
-Wed Aug 25 15:18:52 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_longjmp): Exception#to_str is no longer defined.
-
-Wed Aug 25 11:39:10 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * error.c (exc_equal): exceptions are equal if they share same
- class, message and backtrace. [ruby-talk:110354]
-
- * error.c (name_err_mesg_equal): ditto.
-
-Tue Aug 24 16:41:48 2004 Shugo Maeda <shugo@ruby-lang.org>
+Tue Aug 24 17:30:00 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/cgi/session.rb (CGI::Session::FileStore#initialize): do not
- use a session id as a filename.
+ use a session id as a filename. (backported from HEAD)
* lib/cgi/session/pstore.rb (CGI::Session::PStore#initialize): ditto.
* lib/cgi/session/pstore.rb (CGI::Session::PStore#initialize): use
- Dir::tmpdir.
+ Dir::tmpdir. (backported from HEAD)
-Tue Aug 24 14:32:17 2004 Shugo Maeda <shugo@ruby-lang.org>
+Tue Aug 24 14:40:16 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/cgi/session.rb (CGI::Session::FileStore#initialize): untaint
- session id after check.
+ session id after check. (backported from HEAD)
-Tue Aug 24 08:57:51 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Tue Aug 24 09:09:01 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_x509attr.c (ossl_x509attr_initialize): d2i
functions may replace the pointer indicated by the first argument.
@@ -15452,12 +13041,7 @@ Tue Aug 24 08:57:51 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_x509name.c (ossl_x509name_initialize): ditto.
-Mon Aug 23 12:43:32 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * lib/resolv.rb (Config.default_config_hash): when multiple domains
- are set, Win32::Resolv.get_resolv_info returns Array.
-
-Sun Aug 22 16:27:38 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Aug 23 14:04:51 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_ssl.c (ossl_ssl_read):
- should return an empty string if specified length to read is 0.
@@ -15473,7 +13057,12 @@ Sun Aug 22 16:27:38 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/lib/openssl/buffering.rb: should not use select.
-Sun Aug 22 01:10:36 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Aug 23 12:40:56 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * lib/resolv.rb (Config.default_config_hash): when multiple domains
+ are set, Win32::Resolv.get_resolv_info returns Array.
+
+Sun Aug 22 01:15:31 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_connect):
should call :ProxyContentHandler before finishing CONNECT.
@@ -15485,15 +13074,6 @@ Sat Aug 21 06:41:16 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (arg_config, with_config): deal with '-' and '_'
uniformly. [ruby-dev:24118]
-Fri Aug 20 14:49:42 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * io.c (rb_io_check_writable): no need to check read buffer if
- already changed to write mode.
-
-Fri Aug 20 11:46:43 2004 UENO Katsuhiro <katsu@blue.sky.or.jp>
-
- * ext/zlib/zlib.c: GzipReader#ungetc caused crc error.
-
Thu Aug 19 16:29:45 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: Fail to treat a hash value of 'font' option.
@@ -15507,15 +13087,17 @@ Thu Aug 19 15:15:24 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (free_dir): fix memory leak. reported by yamamoto
madoka.
-Thu Aug 19 09:19:27 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Aug 19 11:00:00 2004 Akiyoshi, Masamichi <masamichi.akiyoshi@hp.com>
- * configure.in, win32/Makefile.sub (LIBS): need to link shell32
- library for SH* functions on mswin32 and mingw32.
+ * dln.c (dln_load): Modify to call lib$find_image_symbol for VMS.
+ * io.c (rb_io_fwrite): Use fputc() for VMS non-stream file.
- * wince/Makefile.sub (LIBS): need to link ceshell library for SH*
- functions on mswince.
+Thu Aug 19 06:07:45 2004 why the lucky stiff <why@ruby-lang.org>
-Thu Aug 19 03:07:00 2004 why the lucky stiff <why@ruby-lang.org>
+ * ext/syck/token.c: re2c no longer compiled with bit vectors. caused
+ problems for non-ascii characters. [ruby-core:03280]
+ * ext/syck/implicit.c: ditto.
+ * ext/syck/bytecode.c: ditto.
* lib/yaml/baseemitter.rb: folding now handles double-quoted strings,
fixed problem with extra line feeds at end of folding, whitespace
@@ -15524,9 +13106,9 @@ Thu Aug 19 03:07:00 2004 why the lucky stiff <why@ruby-lang.org>
* lib/yaml/rubytypes.rb: subtelties in handling strings with
non-printable characters and odd whitespace patterns.
-Wed Aug 18 23:44:20 2004 Minero Aoki <aamine@loveruby.net>
+Wed Aug 18 23:41:33 2004 Minero Aoki <aamine@loveruby.net>
- * lib/net/protocol.rb (rbuf_fill): OpenSSL::SSLSocket has its own
+ * lib/net/protocol.rb (rbuf_fill): OpenSSL::SSL::SSLSocket has its own
buffer, select(2) might not work. [ruby-dev:24072]
Wed Aug 18 17:10:12 2004 WATANABE Hirofumi <eban@ruby-lang.org>
@@ -15539,17 +13121,6 @@ Wed Aug 18 12:52:55 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_obj_instance_eval): evaluates under special singleton
classes as for special constants.
-Wed Aug 18 11:22:52 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (init_env): initialize HOME and USER environment
- variables unless set.
-
-Wed Aug 18 10:17:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (bind_eval): new method. [RCR 251]
-
- * string.c (rb_str_clear): new method. [ruby-dev:24104]
-
Tue Aug 17 17:20:59 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_reopen): should clear allocated OpenFile. pointed
@@ -15560,19 +13131,23 @@ Tue Aug 17 01:36:32 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/usage.rb: Remove extra indent. Tidy 'ri' option
parsing so RDoc::usage plays better with OptionParser.
+Sat Aug 14 13:09:10 2004 Minero Aoki <aamine@loveruby.net>
+
+ * lib/fileutils.rb: backport from CVS HEAD (rev1.44).
+
+ * lib/fileutils.rb: cp_r should copy symlink itself, except cp_r
+ root.
+
+ * lib/fileutils.rb: new option mv :force.
+
+ * lib/fileutils.rb: new module FileUtils::DryRun.
+
Sat Aug 14 02:48:16 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/usage.rb: Added. Allows command line programs
to report usage using their initial RDoc comment.
-Sat Aug 14 01:25:48 2004 why the lucky stiff <why@ruby-lang.org>
-
- * ext/syck/token.c: re2c no longer compiled with bit vectors. caused
- problems for non-ascii characters. [ruby-core:03280]
- * ext/syck/implicit.c: ditto.
- * ext/syck/bytecode.c: ditto.
-
-Fri Aug 13 12:55:20 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Fri Aug 13 13:23:17 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httputils.rb (WEBrick::HTTPUtils.parse_range_header):
fix regex for range-spec.
@@ -15581,44 +13156,15 @@ Fri Aug 13 12:55:20 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
(WEBrick::HTTPServlet::DefaultFileHandler#make_partial_content):
multipart/byteranges response was broken.
- * lib/xmlrpc/server.rb: refine example code.
-
-Thu Aug 12 10:54:17 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * rubyio.h (rb_eof_error): should mark as NORETURN.
-
- * win32/win32.c (make_cmdvector): adjust escaped successive
- double-quote handling.
-
-Thu Aug 12 01:53:10 2004 Tanaka Akira <akr@m17n.org>
-
- * io.c (read_buffered_data): extracted from rb_io_fread.
- (io_readpartial): new method IO#readpartial.
- [ruby-dev:24055]
-
-Wed Aug 11 17:17:50 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * configure.in (RPATHFLAG): stop setting RPATHFLAG on Interix.
-
-Mon Aug 9 15:03:20 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
* lib/webrick/httpservlet/erbhandler.rb
(WEBrick::HTTPServlet::ERBHandler#do_GET): should select media type
by suffix of script filename.
-Mon Aug 9 12:51:43 2004 Dave Thomas <dave@pragprog.com>
-
- * dir.c (dir_s_glob): Roll in Austin Ziegler's Dir.glob and
- fnmatch updates.
-
-Mon Aug 9 06:33:06 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (cp_r): copies symlink to symlink, except
- root entries of cp_r.
+ * lib/xmlrpc/server.rb: refine example code.
- * lib/fileutils.rb: new method FileUtils.copy_entry.
+Wed Aug 11 17:17:50 2004 WATANABE Hirofumi <eban@ruby-lang.org>
- * test/fileutils/test_fileutils.rb: more cp_r tests.
+ * configure.in (RPATHFLAG): stop setting RPATHFLAG on Interix.
Sun Aug 8 00:43:31 2004 why the lucky stiff <why@ruby-lang.org>
@@ -15630,38 +13176,21 @@ Sun Aug 8 00:43:31 2004 why the lucky stiff <why@ruby-lang.org>
collections. plain scalars are trimmed if indentation follows in
an ambiguous flow collection.
-Sat Aug 7 03:08:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * process.c (proc_daemon): new method. should be modified for
- platforms without /dev/null.
-
Sat Aug 7 00:50:01 2004 Tanaka Akira <akr@m17n.org>
* ext/zlib/zlib.c: Zlib::GzipReader#read(0) returns "" instead of nil.
-Wed Aug 4 13:26:00 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * marshal.c (r_bytes0): optimize out read(0). [ruby-talk:108276]
-
-Tue Aug 3 13:49:12 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+Tue Aug 3 13:49:20 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/namespace.rb: bug fix
* ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: add Tk::TreeCtrl.loupe
-Mon Aug 2 23:33:48 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * test/ruby/test_file.rb (test_fnmatch): added more tests.
-
Mon Aug 2 18:04:21 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/msgcat.rb (set_translation): bug fix (fail to set
trans_str to the same as src_str when trans_str is not given.)
-Mon Aug 2 17:40:44 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (blk_free): fixed serious memory leak. [ruby-dev:24013]
-
Mon Aug 2 11:53:06 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/code_objects.rb (RDoc::Context::find_symbol): Fix infinite recursion
@@ -15672,21 +13201,15 @@ Mon Aug 2 11:48:29 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::do_methods): Allow '.'s in
variable names to support SWIG generated files (Hans Fugal)
-Sat Jul 31 23:08:00 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (is_defined): stupid mistakes fixed. [ruby-dev:24006]
-
-Sat Jul 31 17:39:47 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat Jul 31 17:40:16 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* misc/ruby-mode.el (ruby-expr-beg, ruby-parse-partial,
ruby-calculate-indent, ruby-move-to-block, ruby-forward-sexp,
ruby-backward-sexp): keywords must match word-wise.
-Sat Jul 31 13:37:51 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sat Jul 31 05:47:37 2004 why the lucky stiff <why@ruby-lang.org>
- * eval.c (is_defined): avoid unnecessary method invocations.
-
-Sat Jul 31 05:35:37 2004 why the lucky stiff <why@ruby-lang.org>
+ * lib/yaml.rb (YAML::load_file, YAML::parse_file): added.
* lib/yaml/rubytypes.rb: exceptions were using an older
YAML.object_maker. [ruby-core:03080]
@@ -15695,10 +13218,9 @@ Sat Jul 31 05:35:37 2004 why the lucky stiff <why@ruby-lang.org>
handline CR-LFs. "\000" was showing up on folded blocks which
stopped at EOF.
-Sat Jul 31 01:25:11 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (is_defined): call is_defined() before invoking
- rb_eval(). [ruby-talk:107867]
+ * ext/syck/token.c: re2c compiled with bit vectors now.
+ * ext/syck/implicit.c: ditto.
+ * ext/syck/bytecode.c: ditto.
Fri Jul 30 16:10:54 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -15716,26 +13238,8 @@ Wed Jul 28 18:59:17 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/cgi.rb (CGI::initialize): remove at_exit code for CGI_PARAMS
and CGI_COOKIES. they will no longer be used.
-Wed Jul 28 15:44:08 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_call0): should call rb_call_super() directly for
- visibility overriding. [ruby-dev:23989]
-
Wed Jul 28 01:04:44 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * env.h: remove argv from ruby_frame.
-
- * eval.c (rb_eval): no more copy on write.
-
- * eval.c (assign): ditto.
-
- * eval.c (rb_call0): can receive *rest by specifying negative
- argc. (-1 means 0 arg and *rest, -2 means 1 arg and *rest...)
-
- * eval.c (rb_call0): properly set frame's argc counter.
-
- * gc.c (rb_gc_mark_frame): need not to mark frame's argv
-
* gc.c (run_final): wrong order of data. [ruby-dev:23984]
Tue Jul 27 07:05:04 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -15756,13 +13260,11 @@ Mon Jul 26 11:22:55 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httputils.rb (WEBrick::HTTPUtils.escape): should
escape space.
-Sun Jul 25 10:56:28 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Sun Jul 25 11:05:21 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.{h,c} (rb_w32_{f,fd,fs}open): workaround for bcc32's
{f,fd,fs}open bug. set errno EMFILE and EBADF. [ruby-dev:23963]
- * test/drb/drbtest.rb: fix method duplication.
-
Sat Jul 24 13:32:47 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* range.c (rb_range_beg_len): returns Qnil only when "beg" points
@@ -15773,24 +13275,37 @@ Fri Jul 23 16:40:25 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* gc.c (define_final): should not disclose NODE* to Ruby world.
[ruby-dev:23957]
-Fri Jul 23 08:52:22 2004 Shugo Maeda <shugo@ruby-lang.org>
+Fri Jul 23 09:03:16 2004 Shugo Maeda <shugo@ruby-lang.org>
- * lib/net/imap.rb (disconnected?): new method.
+ * lib/net/imap.rb (disconnected?): new method. (backported from HEAD)
Thu Jul 22 16:41:54 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/cgi/session.rb (CGI::Session::FileStore#update): sets the
- permission of the session data file to 0600.
+ permission of the session data file to 0600.
* lib/cgi/session/pstore.rb (CGI::Session::Pstore#initialize):
ditto.
-Mon Jul 19 00:53:46 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Jul 22 00:02:21 2004 Masahiro Kitajima <katonbo@katontech.com>
+
+ * process.c (rb_f_system): not need to call last_status_set() any
+ longer on _WIN32.
+
+Tue Jul 20 09:15:17 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * test/fileutils/test_fileutils.rb: File.link raises EINVAL on BeOS.
+
+Mon Jul 19 01:15:07 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httpservlet/cgihandler.rb
(WEBrick::HTTPServlet::CGIhandler#do_GET): set SystemRoot environment
variable to CGI process on Windows native platforms. [ruby-dev:23936]
+ * lib/webrick/httpservlet/cgihandler.rb
+ (WEBrick::HTTPServlet::CGIhandler#do_GET): use $?.exitstatus and
+ refine log message.
+
Sun Jul 18 16:14:29 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/msgcat.rb (TkMsgCatalog.callback): bug fix
@@ -15800,19 +13315,18 @@ Sun Jul 18 08:13:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (rb_f_sprintf): remove extra sign digit.
-Sun Jul 18 03:19:14 2004 Akinori MUSHA <knu@iDaemons.org>
-
- * dir.c (bracket): use NULL instead of 0.
+Sun Jul 18 03:21:42 2004 Akinori MUSHA <knu@iDaemons.org>
-Sun Jul 18 02:35:30 2004 Shugo Maeda <shugo@ruby-lang.org>
+ * dir.c (range): use NULL instead of 0.
- * lib/net/imap.rb (receive_responses): return if a LOGOUT response
- received.
+ * dir.c (range): get rid of a gcc 3.4 warning.
-Sat Jul 17 23:59:01 2004 Shugo Maeda <shugo@ruby-lang.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)
* lib/net/imap.rb (send_string_data): wait command continuation
- requests before sending octet data of literals.
+ requests before sending octet data of literals. (backported from HEAD)
Sat Jul 17 23:54:59 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -15826,14 +13340,6 @@ Sat Jul 17 18:29:07 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (stmt): not to show same error messages twice.
-Sat Jul 17 14:18:11 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * string.c (rb_str_match_m): String#match should also take
- optional argument. [ruby-core:03205]
-
- * re.c (rb_reg_match_m): add optional second argugment "pos" to
- specify match start point. [ruby-core:03203]
-
Sat Jul 17 13:13:32 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/irb/ruby-lex.rb (RubyLex::identify_string): %s string do not
@@ -15841,7 +13347,7 @@ Sat Jul 17 13:13:32 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
Sat Jul 17 05:26:27 2004 Dave Thomas <dave@pragprog.com>
- * lib/rdoc/diagram.rb: Incorporate Micheal Neumann's
+ * lib/rdoc/diagram.rb: Incorporate Micheal Neuman's
client-side imagemao patch
Sat Jul 17 01:57:03 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -15854,6 +13360,24 @@ Fri Jul 16 22:30:28 2004 Michael Neumann <mneumann@ntecs.de>
* file.c (rb_stat_dev_major): new methods File::Stat#dev_major and
#dev_minor. [ruby-core:03195]
+Fri Jul 16 15:23:53 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (return_jump, break_jump): raise unexpceted local jump
+ exception directly. [ruby-dev:23740]
+
+ * lib/base64.rb (Deprecated): super in bound method calls original
+ name method in stable version. [ruby-dev:23916]
+
+Fri Jul 16 11:31:49 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * lib/test/unit/ui/{fox,gtk,gtk2}/testrunner.rb: remove
+ garbage (patch from akira yamada) [ruby-dev:23911]
+
+Fri Jul 16 11:20:00 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * sprintf.c (rb_f_sprintf): fix output of NaN, Inf and -Inf with
+ "%f" or etc on MSVCRT platforms. (backported from HEAD)
+
Fri Jul 16 11:17:38 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (exit_initialize): use EXIT_SUCCESS instead of 0.
@@ -15873,19 +13397,13 @@ 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.
+ termcap. (backported from HEAD)
-Thu Jul 15 20:44:46 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Jul 15 20:29:15 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * class.c: rdoc patch
-
-Thu Jul 15 14:12:34 2004 why the lucky stiff <why@ruby-lang.org>
-
- * lib/yaml.rb (YAML::load_file, YAML::parse_file): added.
-
- * ext/syck/token.c: re2c compiled with bit vectors now.
- * ext/syck/implicit.c: ditto.
- * ext/syck/bytecode.c: ditto.
+ * class.c, error.c, eval.c, intern.h, object.c, variable.c:
+ do not set path if it is a singleton class. [ruby-dev:22588]
+ (backport from 1.9)
Thu Jul 15 10:15:04 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -15912,12 +13430,7 @@ Thu Jul 15 10:15:04 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/tkextlib/: add samples of Iwidget and TkTable
-Wed Jul 14 23:49:30 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * enum.c (enum_min_by): new method Enum#min_by. added Enum#max_by
- as well.
-
-Wed Jul 14 18:05:21 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Wed Jul 14 18:08:37 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_asn1.c (ossl_asn1cons_to_der): fix type of
argument. [ruby-dev:23891]
@@ -15925,14 +13438,14 @@ Wed Jul 14 18:05:21 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* test/openssl/test_x509store.rb: prune tests for CRL checking
unless X509::V_FLAG_CRL_CHECK is defined.
-Wed Jul 14 12:20:05 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Jul 14 12:29:07 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* util.c (ruby_strtod): should not convert string in the form of
"-I.FE-X" which both "I" and "F" are ommitted. [ruby-dev:23883]
* test/ruby/test_float.rb (test_strtod): add test for bug fix.
-Wed Jul 14 00:33:48 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Jul 14 00:31:15 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* array.c: rdoc patch. merged patch from Johan Holmberg
<holmberg@iar.se> [ruby-core:3170]
@@ -15947,7 +13460,7 @@ Tue Jul 13 19:39:12 2004 akira yamada <akira@ruby-lang.org>
* test/uri/test_generic.rb (TestGeneric#test_merge): added tests.
-Tue Jul 13 15:48:56 2004 Akinori MUSHA <knu@iDaemons.org>
+Tue Jul 13 15:51:45 2004 Akinori MUSHA <knu@iDaemons.org>
* lib/mkmf.rb (init_mkmf): Do not add $(libdir) to $LIBPATH in
extmk mode.
@@ -15959,14 +13472,14 @@ Tue Jul 13 00:50:48 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb: Support call-seq: for Ruby files.
-Mon Jul 12 21:20:51 2004 Dave Thomas <dave@pragprog.com>
+Mon Jul 12 21:20:36 2004 Dave Thomas <dave@pragprog.com>
* html_generator.rb: Support hyperlinks of the form {any text}[xxx]
as well as stuff[xxx]
Sat Jul 10 09:30:24 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
- * test/soap/marshal/test_struct.rb: use qualified built-in class name
+ * test/soap/marshal/test_struct.rb: use qualified build-tin class name
(::Struct) to avoid name crash.
Sat Jul 10 04:21:56 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@@ -15981,7 +13494,7 @@ Sat Jul 10 04:21:56 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
function of Tk::ValidateConfigure to define validatecommand
methods easier
-Fri Jul 9 22:18:59 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri Jul 9 22:36:36 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* array.c, enum.c, pack.c: rdoc patch from Johan Holmberg
<holmberg@iar.se> [ruby-core:3132] [ruby-core:3136]
@@ -16008,26 +13521,29 @@ Fri Jul 9 01:47:08 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/tkextlib/iwidgets : very simple examples of
[incr Widgets]
-Thu Jul 8 19:27:16 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (rb_cv_stack_end_address): detect stack end address
- variable supplied by system. [ruby-core:03115]
+Thu Jul 8 22:52:19 2004 Kouhei Sutou <kou@cozmixng.org>
- * gc.c (Init_stack): use system provided address if possible.
+ * lib/rss/{rss,parser,0.9,1.0,2.0}.rb: supported RSS 0.9x/2.0
+ validation and validation which disregard order of elements.
+ * test/rss/test_parser.rb: added tests for RSS 0.9x/2.0
+ validation.
+ * test/rss/{test_trackback,rss-testcase}.rb: fixed no good method
+ name.
Thu Jul 8 00:05:23 2004 akira yamada <akira@ruby-lang.org>
* lib/tempfile.rb (Tempfile::initialize): got out code of
generating tmpname. [ruby-dev:23832][ruby-dev:23837]
-Wed Jul 7 02:31:41 2004 Kouhei Sutou <kou@cozmixng.org>
+Wed Jul 7 15:53:14 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * lib/rss/{rss,parser,0.9,1.0,2.0}.rb: supported RSS 0.9x/2.0
- validation and validation which disregard order of elements.
- * test/rss/test_parser.rb: added tests for RSS 0.9x/2.0
- validation.
- * test/rss/{test_trackback,rss-testcase}.rb: fixed no good method
- name.
+ * string.c (rb_str_match): raise TypeError when both arguments are
+ strings. [ruby-dev:22869] (backported from HEAD)
+
+ * string.c (rb_str_match2): removed.
+
+ * Makefile.in, bcc32/Makefile.sub, win32/Makefile.sub,
+ wince/Makefile.sub (string.c): now not depend on version.h.
Wed Jul 7 00:48:34 2004 WATANABE Hirofumi <eban@ruby-lang.org>
@@ -16055,7 +13571,7 @@ Mon Jul 5 09:02:52 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_thread_yield, rb_f_catch): 4th argument to rb_yield_0()
is a set of bit flags. [ruby-dev:23859]
-Mon Jul 5 01:20:17 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Jul 5 01:27:32 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/drb/drb.rb(DRbConn self.open): If socket pool is full, close
the socket whose last-access-time is oldest. (and add new one)
@@ -16065,10 +13581,12 @@ Sun Jul 4 12:24:50 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/rss.rb: added copyright header.
-Sat Jul 3 22:25:27 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Sun Jul 4 00:24:40 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
- * added files:
- * lib/soap/header/*
+ * added files
+ * lib/soap/attachment.rb
+ * lib/soap/header
+ * lib/soap/mimemessage.rb
* lib/soap/rpc/httpserver.rb
* lib/wsdl/soap/cgiStubCreator.rb
* lib/wsdl/soap/classDefCreator.rb
@@ -16082,29 +13600,36 @@ Sat Jul 3 22:25:27 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/wsdl/xmlSchema/enumeration.rb
* lib/wsdl/xmlSchema/simpleRestriction.rb
* lib/wsdl/xmlSchema/simpleType.rb
- * lib/xsd/codegen/*
+ * lib/xsd/codegen
* lib/xsd/codegen.rb
- * sample/soap/authheader/*
- * sample/soap/raa2.4/*
- * sample/soap/ssl/*
- * sample/soap/swa/*
+ * sample/soap/authheader
+ * sample/soap/raa2.4
+ * sample/soap/ssl
+ * sample/soap/swa
* sample/soap/whois.rb
- * sample/wsdl/raa2.4/*
- * test/soap/header/*
- * test/soap/ssl/*
- * test/soap/struct/*
- * test/soap/swa/*
- * test/soap/wsdlDriver/*
+ * sample/soap/calc/samplehttpd.conf
+ * sample/soap/exchange/samplehttpd.conf
+ * sample/soap/sampleStruct/samplehttpd.conf
+ * sample/wsdl/raa2.4
+ * sample/wsdl/googleSearch/samplehttpd.conf
+ * test/openssl/_test_ssl.rb
+ * test/soap/header
+ * test/soap/ssl
+ * test/soap/struct
+ * test/soap/swa
+ * test/soap/wsdlDriver
* test/wsdl/multiplefault.wsdl
- * test/wsdl/simpletype/*
+ * test/wsdl/simpletype
* test/wsdl/test_multiplefault.rb
- * modified files:
+ * modified files
* lib/soap/baseData.rb
* lib/soap/element.rb
* lib/soap/generator.rb
+ * lib/soap/marshal.rb
* lib/soap/netHttpClient.rb
* lib/soap/parser.rb
+ * lib/soap/processor.rb
* lib/soap/property.rb
* lib/soap/soap.rb
* lib/soap/streamHandler.rb
@@ -16119,6 +13644,7 @@ Sat Jul 3 22:25:27 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/soap/mapping/wsdlRegistry.rb
* lib/soap/rpc/cgistub.rb
* lib/soap/rpc/driver.rb
+ * lib/soap/rpc/element.rb
* lib/soap/rpc/proxy.rb
* lib/soap/rpc/router.rb
* lib/soap/rpc/soaplet.rb
@@ -16135,12 +13661,26 @@ Sat Jul 3 22:25:27 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/wsdl/xmlSchema/schema.rb
* lib/xsd/datatypes.rb
* lib/xsd/qname.rb
+ * sample/soap/calc/httpd.rb
+ * sample/soap/exchange/httpd.rb
+ * sample/soap/sampleStruct/httpd.rb
* sample/soap/sampleStruct/server.rb
* sample/wsdl/amazon/AmazonSearch.rb
* sample/wsdl/amazon/AmazonSearchDriver.rb
+ * sample/wsdl/googleSearch/httpd.rb
+ * test/soap/test_basetype.rb
* test/soap/test_property.rb
+ * test/soap/test_streamhandler.rb
+ * test/soap/calc/test_calc.rb
+ * test/soap/calc/test_calc2.rb
* test/soap/calc/test_calc_cgi.rb
+ * test/soap/helloworld/test_helloworld.rb
* test/wsdl/test_emptycomplextype.rb
+ * test/wsdl/axisArray/test_axisarray.rb
+ * test/wsdl/datetime/test_datetime.rb
+ * test/wsdl/raa/test_raa.rb
+ * test/xsd/test_xmlschemaparser.rb
+ * test/xsd/test_xsd.rb
* summary
* add SOAP Header mustUnderstand support.
@@ -16155,33 +13695,34 @@ Sat Jul 3 22:25:27 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* add WSDL simpleType support to restrict lexical value space.
+ * add SOAP with Attachment support.
+
Sat Jul 3 17:19:44 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* ext/tk/lib/tkextlib/tkDND.rb: fix syntax error.
-Thu Jul 1 18:36:08 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+Thu Jul 1 23:15:29 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/tk/lib/tcltklib : bug fix
+ * lib/pstore.rb (transaction): safer backup scheme. [ruby-list:39102]
- * ext/tk/lib/tk : bug fix and add Tcl/Tk extension support libraries
+ * lib/pstore.rb (commit_new): use FileUtils.copy_stream for Cygwin.
+ [ruby-dev:23157]
-Thu Jul 1 18:31:31 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/pstore.rb (transaction): allow overriding dump and load.
+ [ruby-dev:23567]
* lib/pstore.rb (PStore#transaction): get rid of opening in write mode
when read only transaction. [ruby-dev:23842]
-Thu Jul 1 00:44:42 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+ * lib/yaml/store.rb: follow lib/pstore.rb's change.
- * ext/openssl/ossl_cipher.c (ossl_cipher_encrypt, ossl_cipher_decrypt):
- re-implemnt (the arguments for this method is ).
+Thu Jul 1 18:36:08 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/openssl/ossl_cipher.c (ossl_cipher_pkcs5_keyivgen): new method
- OpenSSL::Cipher::Cipher#pkcs5_keyivgen. it calls EVP_BytesToKey().
+ * ext/tk/lib/tcltklib : bug fix
- * ext/openssl/ossl_cipher.c (ossl_cipher_set_key_length): new method
- OpenSSL::Cipher::Cipher#key_len=.
+ * ext/tk/lib/tk : bug fix and add Tcl/Tk extension support libraries
-Wed Jun 30 19:48:09 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Jul 1 11:59:45 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/extconf.rb: check for EVP_CIPHER_CTX_copy, ENGINE_add,
EVP_CIPHER_CTX_set_padding, EVP_CipherFinal_ex, EVP_CipherInit_ex,
@@ -16193,17 +13734,23 @@ Wed Jun 30 19:48:09 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
EVP_CipherInit_ex, EVP_CipherFinal_ex, HMAC_Init_ex): new macro for
OpenSSL 0.9.6.
+ * ext/openssl/ossl_cipher.c (ossl_cipher_encrypt, ossl_cipher_decrypt):
+ re-implemnt (the arguments for this method is ).
+
+ * ext/openssl/ossl_cipher.c (ossl_cipher_pkcs5_keyivgen): new method
+ OpenSSL::Cipher::Cipher#pkcs5_keyivgen. it calls EVP_BytesToKey().
+
* ext/openssl/ossl_cipher.c (ossl_cipher_alloc, ossl_cipher_initialize,
- ossl_cipher_copy, ossl_cipher_reset, ossl_cipher_encrypt,
- ossl_cipher_decrypt, ossl_cipher_final, ossl_cipher_set_key,
- ossl_cipher_set_iv): replace all EVP_CipherInit and
- EVP_CipherFinal into EVP_CipherInit_ex and EVP_CipherFinal_ex.
+ ossl_cipher_copy, ossl_cipher_reset ossl_cipher_final,
+ ossl_cipher_set_key, ossl_cipher_set_iv): replace all EVP_CipherInit
+ and EVP_CipherFinal into EVP_CipherInit_ex and EVP_CipherFinal_ex.
and EVP_CIPHER_CTX_init should only be called once.
- * ext/openssl/ossl_cipher.c (ossl_cipher_set_padding): check for
- EVP_CIPHER_CTX_set_padding.
+ * ext/openssl/ossl_cipher.c (ossl_cipher_set_key_length): new method
+ OpenSSL::Cipher::Cipher#key_len=.
- * ext/openssl/ossl_cipher.c (Init_ossl_cipher): Cipher#<< is deprecated.
+ * ext/openssl/ossl_cipher.c (ossl_cipher_init_deprecated): new
+ finction; print warning for Cipher#<<.
* ext/openssl/ossl_digest.c: replace all EVP_DigestInit and
EVP_DigestFinal into EVP_DigestInit_ex and EVP_DigestFinal_ex.
@@ -16221,16 +13768,50 @@ Wed Jun 30 19:48:09 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* test/openssl/test_cipher.rb, test/openssl/test_digest.rb,
test/openssl/test_hmac.rb: new file.
-Wed Jun 30 16:59:39 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Thu Jul 1 04:08:30 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * ext/openssl/ossl_asn1.c (ossl_i2d_ASN1_TYPE, ossl_ASN1_TYPE_free):
+ workaround for the versions earlier than OpenSSL-0.9.7.
+
+Thu Jul 1 03:33:55 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * ext/openssl/ossl_pkey_dh.c (ossl_dh_initialize): should create
+ empty pkey object if no argument is passed. [ruby-talk:103328]
+
+ * ext/openssl/ossl_pkey_dsa.c (ossl_dsa_initialize): ditto.
+
+ * ext/openssl/ossl_pkey_rsa.c (ossl_rsa_initialize): ditto.
+
+ * ext/openssl/ossl_pkey_dh.c: add new methods: OpenSSL::PKey::DH#p,
+ OpenSSL::PKey::DH#p=, OpenSSL::PKey::DH#g, OpenSSL::PKey::DH#g=,
+ OpenSSL::PKey::DH#pub_key, OpenSSL::PKey::DH#pub_key=,
+ OpenSSL::PKey::DH#priv_key and OpenSSL::PKey::DH#priv_key=.
+
+ * ext/openssl/ossl_pkey_dsa.c: add new methods: OpenSSL::PKey::DSA#p,
+ OpenSSL::PKey::DSA#p=, OpenSSL::PKey::DSA#q, OpenSSL::PKey::DSA#q=,
+ OpenSSL::PKey::DSA#g, OpenSSL::PKey::DSA#g=,
+ OpenSSL::PKey::DSA#pub_key, OpenSSL::PKey::DSA#pub_key=,
+ OpenSSL::PKey::DSA#priv_key and OpenSSL::PKey::DSA#priv_key=.
+
+Thu Jul 1 03:16:09 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * test/ruby/test_file.rb (test_fnmatch): some tests for File.fnmatch
- are added.
+ * ext/openssl/ossl_ssl.c (ossl_ssl_read): take optional second argument
+ to specify a string to be written.
+
+ * ext/openssl/lib/openssl/buffering.rb (OpenSSL::Buffering#read):
+ take optional second argument to specify a string to be written.
+
+ * ext/openssl/lib/openssl/buffering.rb (OpenSSL::Buffering#gets):
+ refine regexp for end-of-line.
+
+ * ext/opnessl/lib/openssl/ssl.rb
+ (OpenSSL::SSL::SocketForwarder#listen): fix typo.
Wed Jun 30 11:38:51 2004 Mikael Brockman <phubuh@phubuh.org>
* parse.y (primary): should not be NULL. [ruby-core:03098]
-Wed Jun 30 02:41:10 2004 why the lucky stiff <why@ruby-lang.org>
+Wed Jun 30 02:53:24 2004 why the lucky stiff <why@ruby-lang.org>
* ext/syck/rubyext.c (syck_emitter_new): set buffer after
Data_Wrap_Struct to avoid possible GC. [ruby-talk:104835]
@@ -16250,107 +13831,80 @@ Mon Jun 28 14:57:56 2004 Jeff Mitchell <quixoticsycophant@yahoo.com>
* configure.in, lib/mkmf.rb (LIBPATHFLAG): use double quotes due to
DOSISH compilers. [ruby-core:03107]
-Mon Jun 28 00:35:29 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Mon Jun 28 00:30:19 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* sample/drb/*.rb: using 'DRb.thread.join' instead of 'gets'
-Sun Jun 27 22:36:47 2004 Kouhei Sutou <kou@cozmixng.org>
+Sun Jun 27 22:39:51 2004 Kouhei Sutou <kou@cozmixng.org>
* sample/rss/tdiary_plugin/rss-recent.rb: supported Hiki.
-Sat Jun 26 15:17:11 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Jun 27 12:19:46 2004 Kouhei Sutou <kou@cozmixng.org>
- * variable.c (rb_mod_class_variables): class variables are no longer
- inherited. [ruby-dev:23808]
+ * {lib,sample,test}/rss: added RSS Parser. [ruby-dev:23780]
-Sat Jun 26 11:07:20 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat Jun 26 11:07:30 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (aix): -b must come at the start of the command line,
and -e must not appear while testing libraries. [ruby-talk:104501]
- * lib/mkmf.rb (find_header, dir_config): quote directory names if
- necessary. [ruby-talk:104505]
+ * lib/mkmf.rb (dir_config): quote directory names if necessary.
+ [ruby-talk:104505]
-Sat Jun 26 00:13:08 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Jun 25 15:33:19 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * io.c (rb_fopen, rb_fdopen, rb_io_reopen): setvbuf() may return
- positive value on failure. [ruby-dev:23792]
+ * ext/iconv/extconf.rb: check stricter. [ruby-talk:104501]
-Fri Jun 25 18:07:15 2004 Michal Rokos <michal@ruby-lang.org>
+ * ext/iconv/extconf.rb: include iconv.h for libiconv. [ruby-dev:22715]
- * gc.c: bring back _stklen for DJGPP [ruby-core:3084]
+Fri Jun 25 08:31:29 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-Fri Jun 25 15:33:01 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * eval.c (rb_thread_atfork): remove "fork terminates thread"
+ warning. [ruby-dev:23768]
- * ext/iconv/extconf.rb: check stricter. [ruby-talk:104501]
+ * object.c (rb_obj_clone): backport FL_FINALIZE patch from 1.9.
+ [ruby-core:02786][ruby-core:03067]
-Fri Jun 25 01:58:01 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+ * ext/socket/socket.c (sock_sockaddr): Socket#gethostbyname()
+ should give us packed address, not struct sockaddr.
+ [ruby-core:03053]
+
+Fri Jun 25 02:04:23 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* {bcc32,win32,wince}/setup.mak: remove RUBY_EXTERN lines when
- including version.h. [ruby-talk:104456]
+ including version.h. [ruby-talk:104456] (backported from HEAD)
Thu Jun 24 14:23:29 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_io_fread): return already read data when system call is
interrupted. [ruby-talk:97206]
-Thu Jun 24 01:25:21 2004 Shugo Maeda <shugo@ruby-lang.org>
+Thu Jun 24 01:32:43 2004 Shugo Maeda <shugo@ruby-lang.org>
* version.h: added declarations of ruby_version,
- ruby_release_date, ruby_platform.
-
-Thu Jun 24 01:07:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/socket/socket.c (sock_sockaddr): Socket#gethostbyname()
- should give us packed address, not struct sockaddr.
- [ruby-core:03053]
+ ruby_release_date, ruby_platform.
+ (backported from HEAD)
-Wed Jun 23 22:19:10 2004 Dave Thomas <dave@pragprog.com>
+Wed Jun 23 22:23:37 2004 Dave Thomas <dave@pragprog.com>
* ext/socket/socket.c (sock_s_gethostbyaddr): Work around problem
with OS X not returning 'from' parameter to recvfrom for
connection-oriented sockets.
-Wed Jun 23 22:16:16 2004 Michal Rokos <michal@ruby-lang.org>
-
- * io.c: io_seek()'s retval should be checked [ruby-core:03045]
-
-Wed Jun 23 21:48:27 2004 Michal Rokos <michal@ruby-lang.org>
-
- * time.c: Fix indentation.
-
- * main.c: Remove _stklen, and _CRT_glob. Move _stacksize for
- __human68k__ to gc.c where the others are.
-
- * gc.c: put _stacksize in place and clean the #ifdefs macros.
-
-Wed Jun 23 17:37:54 2004 Shugo Maeda <shugo@ruby-lang.org>
-
- * lib/net/imap.rb: added new option --ssl.
-
Wed Jun 23 01:45:27 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RubyLex::identify_quotation):
Fix problem with the 'r' being dropped from %r{xxx}
-Wed Jun 23 00:10:17 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Jun 23 00:20:20 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/win32ole/win32ole.c (ole_hresult2msg): remove trailing
CRs and LFs. (doesn't depend on CR+LF) [ruby-dev:23749]
Wed Jun 23 00:00:25 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * eval.c (return_jump, break_jump): raise unexpected local jump
- exception directly. [ruby-dev:23740]
-
* io.c (rb_io_initialize): should check fcntl result. [ruby-dev:23742]
-Tue Jun 22 23:35:43 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): support FZERO and FSPACE with NaN/Inf.
-
- * test/ruby/test_sprintf.rb (test_nan, test_inf): add tests.
-
Tue Jun 22 21:11:36 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (OLE_FREE): should not call CoFreeUnuse-
@@ -16361,56 +13915,21 @@ Tue Jun 22 21:11:36 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (ole_hresult2msg): truncate error message
before CR.
-Tue Jun 22 19:24:59 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): unify output of NaN, Inf and -Inf with
- "%f" or etc on all platform. [ruby-dev:23704], [ruby-dev:23747]
-
-Tue Jun 22 15:28:12 2004 Michal Rokos <michal@ruby-lang.org>
-
- * compar.c: Remove explicit NIL_P() checks since rb_cmpint() does it
- again in the exactly same manner.
-
-Tue Jun 22 01:32:40 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_pkey_dh.c (ossl_dh_initialize): should create
- empty pkey object if no argument is passed. [ruby-talk:103328]
-
- * ext/openssl/ossl_pkey_dsa.c (ossl_dsa_initialize): ditto.
+Tue Jun 22 16:47:42 2004 Shugo Maeda <shugo@ruby-lang.org>
- * ext/openssl/ossl_pkey_rsa.c (ossl_rsa_initialize): ditto.
-
- * ext/openssl/ossl_pkey_dh.c: add new methods: OpenSSL::PKey::DH#p,
- OpenSSL::PKey::DH#p=, OpenSSL::PKey::DH#g, OpenSSL::PKey::DH#g=,
- OpenSSL::PKey::DH#pub_key, OpenSSL::PKey::DH#pub_key=,
- OpenSSL::PKey::DH#priv_key and OpenSSL::PKey::DH#priv_key=.
-
- * ext/openssl/ossl_pkey_dsa.c: add new methods: OpenSSL::PKey::DSA#p,
- OpenSSL::PKey::DSA#p=, OpenSSL::PKey::DSA#q, OpenSSL::PKey::DSA#q=,
- OpenSSL::PKey::DSA#g, OpenSSL::PKey::DSA#g=,
- OpenSSL::PKey::DSA#pub_key, OpenSSL::PKey::DSA#pub_key=,
- OpenSSL::PKey::DSA#priv_key and OpenSSL::PKey::DSA#priv_key=.
-
-Mon Jun 21 09:24:51 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (rb_w32_opendir): should set errno if error occurs
- when calling OS API.
+ * lib/net/ftp.rb (MDTM_REGEXP): fix for demon's ftp server.
+ Thanks, Rutger Nijlunsing.
-Sun Jun 20 21:12:54 2004 Shugo Maeda <shugo@ruby-lang.org>
+Mon Jun 21 10:19:23 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * lib/net/ftp.rb (binary=): send TYPE commands only once.
+ * win32/win32.c (rb_w32_opendir): use FindFirstFile()/FindNextFile()/
+ FindClose() instead of _findfirst()/_findnext()/_findclose().
+ merge from HEAD.
-Sat Jun 19 13:27:01 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat Jun 19 13:24:15 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (method_call): allow changing $SAFE. [ruby-dev:23713]
- * eval.c (proc_set_safe_level, proc_invoke, rb_mod_define_method): not
- set $SAFE for methods defined from Proc. [ruby-dev:23697]
-
-Sat Jun 19 01:10:12 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * sample/rss/tdiary_plugin/rss-recent.rb: added more information.
-
Fri Jun 18 23:12:22 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (proc_save_safe_level, rb_set_safe_level, safe_setter): limit
@@ -16421,27 +13940,10 @@ Wed Jun 16 23:05:57 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (rb_mod_freeze): prepare string representation before
freezing. [ruby-talk:103646]
-Wed Jun 16 19:57:24 2004 Michal Rokos <michal@ruby-lang.org>
-
- * test/ruby/test_array.rb: extend testcase to check #first, #last,
- #shift, #unshift, #pop, #push
-
-Wed Jun 16 16:05:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * array.c (ary_new): move alloc behind checks. [ruby-core:02982]
-
- * array.c (rb_ary_pop_m, rb_ary_shift_m): take arg to behave as push
- and unshift.
-
- * array.c (rb_ary_first, rb_ary_last): make shared array for result
- array, and correct doc for Array#first(n) and Array#last(n)
-
- * array.c (rb_ary_select): not accept any arg.
+Wed Jun 16 16:04:40 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Wed Jun 16 16:03:59 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * object.c (rb_class_inherited_p): singleton class inherits Class
- rather than its object's class. [ruby-dev:23690]
+ * object.c (rb_mod_le): singleton class inherits Class rather than its
+ object's class. [ruby-dev:23690]
Wed Jun 16 16:01:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -16476,36 +13978,31 @@ Sun Jun 13 00:23:04 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/sample/menubar?.rb: [add] sample of menu_spec usage
-Sat Jun 12 14:15:20 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c: RDOC for File::FNM_CASEFOLD was missed.
-
Sat Jun 12 11:15:53 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* configure.in (target_os): strip -gnu suffix on Linux.
-Fri Jun 11 22:08:50 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Jun 11 17:08:21 2004 Akinori MUSHA <knu@iDaemons.org>
- * array.c: remove #indexes, #indices.
+ * config.guess: Restore a wrongly removed hyphen.
- * hash.c: ditto.
+Fri Jun 11 14:30:08 2004 Akinori MUSHA <knu@iDaemons.org>
- * ext/dbm/dbm.c: remove #indexes, #indices, "values_at" warning
- from #select.
+ * config.guess: Attempt to avoid system name change on
+ Darwin platforms also.
- * ext/gdbm/gdbm.c: ditto.
-
- * ext/sdbm/init.c: ditto.
+Fri Jun 11 14:22:45 2004 Akinori MUSHA <knu@iDaemons.org>
- * ext/dbm/dbm.c (Init_dbm): set VERSION constant as "unknown" when
- DB_VERSION_STRING is not available.
+ * config.guess, config.sub: Attempt to avoid system name change on
+ Linux platforms. We have been using "linux" instead of
+ "linux-gnu" on this branch.
Thu Jun 10 19:19:41 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/sdbm/init.c (fsdbm_store): sdbm should use StringValue().
[ruby-talk:103062]
-Wed Jun 9 16:09:01 2004 akira yamada <akira@ruby-lang.org>
+Wed Jun 9 18:04:14 2004 akira yamada <akira@ruby-lang.org>
* lib/uri/generic.rb (URI::Generic::merge,
URI::Generic::route_from): accepts non-hierarchical URI.
@@ -16514,18 +14011,12 @@ Wed Jun 9 16:09:01 2004 akira yamada <akira@ruby-lang.org>
* test/uri/test_generic.rb (TestGeneric::test_route,
TestGeneric::test_merge): added tests for above changes.
-Wed Jun 9 15:39:55 2004 Akinori MUSHA <knu@iDaemons.org>
-
- * configure.in: Add support for DragonFly BSD.
-
-Wed Jun 9 15:07:06 2004 Akinori MUSHA <knu@iDaemons.org>
+Wed Jun 9 17:39:37 2004 Akinori MUSHA <knu@iDaemons.org>
* config.guess, config.sub: Update to a more recent version as of
2004-01-20.
-Wed Jun 9 11:20:05 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c: remove unused functions and variables.
+ * configure.in: Add support for DragonFly BSD.
Wed Jun 2 20:16:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -16543,43 +14034,82 @@ Fri May 28 11:20:31 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (eval): reverted wrongly removed condition. [ruby-dev:23638]
-Thu May 27 21:37:50 2004 Tanaka Akira <akr@m17n.org>
-
- * lib/pathname.rb (Pathname#initialize): fix pathname initialization
- by pathname.
+Thu May 27 23:15:18 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-Thu May 27 20:02:09 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * lib/logger.rb: leading 0 padding of timestamp usec part.
- * io.c (rb_io_fwrite): check all case errno != 0 [ruby-dev:23648]
+ * lib/csv.rb (CSV.parse): [CAUTION] behavior changed. in the past,
+ CSV.parse accepts a filename to be read-opened (it was just a
+ shortcut of CSV.open(filename, 'r')). now CSV.parse accepts a
+ string or a stream to be parsed e.g.
+ CSV.parse("1,2\n3,r") #=> [['1', '2'], ['3', '4']]
-Thu May 27 15:54:02 2004 Shugo Maeda <shugo@ruby-lang.org>
+ * lib/csv.rb: CSV::Row and CSV::Cell are deprecated. these classes
+ are removed in the future. in the new csv.rb, row is represented
+ as just an Array. since CSV::Row was a subclass of Array, it won't
+ hurt almost all programs except one which depended CSV::Row#match.
+ and a cell is represented as just a String or nil(NULL). this
+ change will cause widespread destruction.
- * lib/net/ftp.rb (MDTM_REGEXP): fix for demon's ftp server.
- Thanks, Rutger Nijlunsing.
+ CSV.open("foo.csv", "r") do |row|
+ row.each do |cell|
+ if cell.is_null # using Cell#is_null
+ p "(NULL)"
+ else
+ p cell.data # using Cell#data
+ end
+ end
+ end
-Thu May 27 14:53:13 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+ must be just;
- * io.c (rb_io_fwrite): workaround for bcc32's fwrite bug.
- add errno checking. [ruby-dev:23627]
+ CSV.open("foo.csv", "r") do |row|
+ row.each do |cell|
+ if cell.nil?
+ p "(NULL)"
+ else
+ p cell
+ end
+ end
+ end
- * io.c (rb_io_fwrite): should check if errno == ENOENT, too.
+ * lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
+ change. CSV.open, CSV.parse, and CSV,generate now do not force
+ opened file binmode. formerly it set binmode explicitly.
-Thu May 27 11:25:03 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+ with CSV.open, binmode of opened file depends the given mode
+ parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
+ file with "r" and "w".
- * test/csv/test_csv.rb: illegal require module name (../lib/csv.rb).
+ setting mode properly is user's responsibility now.
-Wed May 26 23:12:13 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+ * lib/csv.rb: accepts String as a fs (field separator/column separator)
+ and rs (record separator/row separator)
* lib/csv.rb (CSV.read, CSV.readlines): added. works as IO.read and
IO.readlines in CSV format.
- * lib/csv.rb (CSV.parse): [CAUTION] behavior changed. in the past,
- CSV.parse accepts a filename to be read-opened (it was just a
- shortcut of CSV.open(filename, 'r')). now CSV.parse accepts a
- string or a stream to be parsed e.g.
- CSV.parse("1,2\n3,r") #=> [['1', '2'], ['3', '4']]
+ * lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
+ now does not handle "| cmd" as a path different from IO.foreach.
+ needed?
- * test/csv/test_csv.rb: follow above changes.
+ * test/csv/test_csv.rb: updated.
+
+ * test/ruby/test_float.rb: added test_strtod to test Float("0").
+
+Thu May 27 21:37:50 2004 Tanaka Akira <akr@m17n.org>
+
+ * lib/pathname.rb (Pathname#initialize): refine pathname initialization
+ by pathname.
+
+Thu May 27 20:22:05 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * io.c (rb_io_fwrite): check all case errno != 0 [ruby-dev:23648]
+
+Thu May 27 14:53:13 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+
+ * io.c (rb_io_fwrite): workaround for bcc32's fwrite bug.
+ add errno checking. [ruby-dev:23627]
Wed May 26 14:19:42 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -16610,33 +14140,16 @@ Wed May 26 00:00:00 2004 why the lucky stiff <why@ruby-lang.org>
* lib/yaml/baseemitter.rb (indent_text): simpler flow block code.
-Tue May 25 11:54:13 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_yield_0, proc_invoke, proc_arity): allow passing a block
- to a Proc. [ruby-dev:23533]
-
- * parse.y (block_par, block_var): ditto.
-
-Tue May 25 01:50:17 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_asn1.c (ossl_i2d_ASN1_TYPE, ossl_ASN1_TYPE_free):
- workaround for the versions earlier than OpenSSL-0.9.7.
+ * lib/yaml.rb: added rdoc to beginning of lib.
Mon May 24 10:46:26 2004 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* lib/rdoc/generators/template/html/html.rb: SYSTEM identifiers
must be absolute URIs
-Sun May 23 04:53:50 2004 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
-
- * lib/pstore.rb (transaction): allow overriding dump and load.
- [ruby-dev:23567]
-
- * lib/yaml/store.rb: follow lib/pstore.rb's change.
-
-Sat May 22 11:54:10 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat May 22 12:00:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * MANIFEST: add test/openssl/test_x509store.rb.
+ * MANIFEST: add new encodings in rexml.
* ext/tk/MANIFEST: add recent files.
@@ -16650,12 +14163,6 @@ Fri May 21 09:22:05 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_method_parameters):
Add ()'s around parameters that don't have them
-Fri May 21 02:21:11 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * lib/csv.rb: fixed a few bugs around multi char record/field separator.
-
- * test/csv/test_csv.rb: added boundary test for above feature.
-
Thu May 20 17:02:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (check_sizeof): define result size. [ruby-core:02911]
@@ -16663,6 +14170,10 @@ Thu May 20 17:02:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (create_header): macro name should not include equal
sign.
+Thu May 20 15:59:50 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+
+ * ext/socket/socket.c: fix SEGV. [ruby-dev:23550]
+
Thu May 20 14:35:52 2004 Tanaka Akira <akr@m17n.org>
* ext/socket/socket.c: check SCM_RIGHTS macro addition to
@@ -16683,100 +14194,20 @@ Thu May 20 12:34:39 2004 Dave Thomas <dave@pragprog.com>
Thu May 20 12:22:13 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (have_type): do not check pointer to incomplete type,
- which always get compiled.
- [ruby-list:39683]
-
-Wed May 19 23:45:43 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ which always get compiled. [ruby-list:39683]
- * test/inlinetest.rb (InlineTest::loadtest): requiring library with
- replaced $0 can make $0 == __FILE__ block be evaluated twice.
-
- * test/ruby/envutil.rb (EnvUtil::rubybin): give priority to
- environment variable. [ruby-dev:23538]
-
-Wed May 19 11:08:10 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+Wed May 19 11:09:00 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: change permition of TkObject#tk_send from
private to public
-Wed May 19 02:29:36 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: support TRACE.
-
-Wed May 19 02:21:53 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: do not use class variables.
-
-Tue May 18 21:21:43 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * lib/csv.rb: writes lines with "\n" when row separator is not given.
- formerly it was "\r\n".
-
- * lib/csv.rb: [CAUTION] API change
-
- * CSV::Row removed. a row is represented as just an Array. since
- CSV::Row was a subclass of Array, it won't hurt almost all programs
- except one which depended CSV::Row#match.
-
- * CSV::Cell removed. a cell is represented as just a String or
- nil(NULL). this change will cause widespread destruction.
-
- CSV.open("foo.csv", "r") do |row|
- row.each do |cell|
- if cell.is_null # Cell#is_null
- p "(NULL)"
- else
- p cell.data # Cell#data
- end
- end
- end
-
- must be just;
-
- CSV.open("foo.csv", "r") do |row|
- row.each do |cell|
- if cell.nil?
- p "(NULL)"
- else
- p cell
- end
- end
- end
-
- * lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
- change. CSV.open, CSV.parse, and CSV,generate now do not force
- opened file binmode. formerly it set binmode explicitly.
-
- with CSV.open, binmode of opened file depends the given mode
- parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
- file with "r" and "w".
-
- setting mode properly is user's responsibility now.
-
- * lib/csv.rb: accepts String as a fs (field separator/column separator)
- and rs (record separator/row separator)
-
- * lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
- now does not handle "| cmd" as a path different from IO.foreach.
- needed?
-
- * test/csv/test_csv.rb: updated.
-
-Tue May 18 14:24:20 2004 why the lucky stiff <why@ruby-lang.org>
-
- * lib/yaml.rb: added rdoc to beginning of lib.
-
Tue May 18 14:00:46 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* node.h (NEW_DSTR): adjust list length.
* parse.y (literal_concat): ditto.
-Tue May 18 09:30:25 2004 SASADA Koichi <ko1@atdot.net>
-
- * eval.c (rb_method_node): search cache entry first.
-
-Mon May 17 16:04:06 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon May 17 16:14:25 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* numeric.c (flo_to_s): it's preferable that "p 0.0" outputs "0.0"
instead of "0.0e+00". [ruby-dev:23480]
@@ -16793,43 +14224,13 @@ Mon May 17 10:13:33 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/socket/socket.c (sock_s_getnameinfo): ditto.
-Mon May 17 00:36:21 2004 why the lucky stiff <why@ruby-lang.org>
+Mon May 17 01:15:23 2004 why the lucky stiff <why@ruby-lang.org>
+
+ * lib/yaml.rb: removed fallback to pure Ruby parser.
* lib/yaml/baseemitter.rb (indent_text): was forcing a mod value
of zero at times, which kept some blocks from getting indentation.
-Mon May 17 00:07:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
-
- * lib/drb/drb.rb: Cosmetic documentation changes.
-
-Sun May 16 20:55:49 2004 Tanaka Akira <akr@m17n.org>
-
- * ext/dbm/dbm.c (fdbm_initialize): accept optional 3rd argument to
- specify an open flag.
- (Init_dbm): define open flags: DBM::READER, DBM::WRITER, DBM::WRCREAT
- and DBM::NEWDB.
-
-Sat May 15 17:52:24 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * test/ruby/test_float.rb(test_strtod): Add test for signed 0.000...1
-
-Sat May 15 14:20:13 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * ext/syck/depend: add ruby's headers.
-
-Sat May 15 13:38:33 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/syck/MANIFEST, ext/syck/depend: new file.
-
- * lib/yaml/rubytypes.rb: range of exponential floats. [ruby-core:02824]
-
- * test/yaml/test_yaml.rb: tests for strings start with colon and some
- round trip.
-
-Sat May 15 12:04:58 2004 why the lucky stiff <why@ruby-lang.org>
-
- * lib/yaml.rb: removed fallback to pure Ruby parser.
-
* lib/yaml/baseemitter.rb (node_text): rewriting folded scalars.
* ext/syck/syck.h: reports style of scalars now, be they plain, block
@@ -16846,9 +14247,33 @@ Sat May 15 12:04:58 2004 why the lucky stiff <why@ruby-lang.org>
* ext/syck/rubyext.c (yaml_org_handler): symbols loaded only
if scalar style is plain.
+ * ext/syck/rubyext.c (yaml_org_handler): some empty strings were
+ loaded as symbols.
+
* test/yaml/test_yaml.rb (test_perl_regexp): updated test to
match new regexp serialization.
+Mon May 17 00:03:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+
+ * lib/drb/drb.rb: Cosmetic documentation changes.
+
+Sun May 16 22:36:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+
+ * lib/test/unit.rb: Removed :nodoc: directive (it prevented effective
+ RDoc operation), and added file-level comment.
+
+Sun May 16 20:55:49 2004 Tanaka Akira <akr@m17n.org>
+
+ * ext/dbm/dbm.c (fdbm_initialize): accept optional 3rd argument to
+ specify an open flag.
+ (Init_dbm): define open flags: DBM::READER, DBM::WRITER, DBM::WRCREAT
+ and DBM::NEWDB.
+
+Sun May 16 13:10:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+
+ * lib/test/unit/**/*.rb: Removed :nodoc: directives (many were
+ generating warnings, many were on private methods).
+
Sat May 15 01:41:34 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (eval): forgot to restore $SAFE value before evaluating
@@ -16864,27 +14289,18 @@ Fri May 14 22:08:38 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_new4): should not reuse frozen shared string if
the original is not an instance of String. [ruby-talk:100193]
-Fri May 14 21:29:26 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * time.c (time_mdump): preserve GMT bit in the marshal data.
- [ruby-talk:100213]
-
-Fri May 14 18:37:49 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk/canvas.rb: improve coords support for canvas
- items. Now, supports all of the followings.
- TkcLine.new(c, 0, 0, 100, 100, :fill=>'red')
- TkcLine.new(c, [0, 0, 100, 100], :fill=>'red')
- TkcLine.new(c, [0, 0], [100, 100], :fill=>'red')
- TkcLine.new(c, [[0, 0], [100, 100]], :fill=>'red')
- TkcLine.new(c, :coords=>[0, 0, 100, 100], :fill=>'red')
- TkcLine.new(c, :coords=>[[0, 0], [100, 100]], :fill=>'red')
+Fri May 14 18:39:25 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-Fri May 14 13:30:39 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * ext/tk/lib/tk/canvas.rb: improve coords support for canvas items.
+ Now, supports all of the followings.
+ TkcLine.new(c, 0, 0, 100, 100, :fill=>'red')
+ TkcLine.new(c, [0, 0, 100, 100], :fill=>'red')
+ TkcLine.new(c, [0, 0], [100, 100], :fill=>'red')
+ TkcLine.new(c, [[0, 0], [100, 100]], :fill=>'red')
+ TkcLine.new(c, :coords=>[0, 0, 100, 100], :fill=>'red')
+ TkcLine.new(c, :coords=>[[0, 0], [100, 100]], :fill=>'red')
- * test/ruby/test_float.rb: Add test for util.c revision 1.42.
-
-Fri May 14 12:13:46 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri May 14 12:11:43 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* util.c (ruby_strtod): strtod("0", &end); => end should point '\0'.
[ruby-dev:23498]
@@ -16894,10 +14310,15 @@ Thu May 13 15:47:30 2004 akira yamada <akira@ruby-lang.org>
* lib/net/telnet.rb (Net::Telnet::login): "options" can specify
regexps for login prompt and/or password prompt.
-Thu May 13 14:17:57 2004 why the lucky stiff <why@ruby-lang.org>
+Thu May 13 14:23:45 2004 WATANABE Hirofumi <eban@ruby-lang.org>
- * ext/syck/rubyext.c (yaml_org_handler): some empty strings were
- loaded as symbols.
+ * hash.c (delete_if_i): use st_delete_safe() (via
+ rb_hash_delete()) instead of returning ST_DELETE.
+ backport from HEAD. [ruby-dev:23487]
+
+Thu May 13 13:01:30 2004 akira yamada <akira@ruby-lang.org>
+
+ * lib/uri/mailto.rb (URI::MailTo::to_s): should include fragment.
Thu May 13 11:04:08 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
@@ -16929,15 +14350,6 @@ Wed May 12 11:51:08 2004 Dave Thomas <dave@pragprog.com>
* class.c (rb_obj_singleton_methods): fix rdoc
-Tue May 11 07:09:42 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (is_defined): do not protect exception during receiver
- evaluation.
-
-Mon May 10 22:28:14 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/protocol.rb (each_crlf_line): remove junk line.
-
Mon May 10 21:44:42 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/html_generator.rb: Change scheme for
@@ -16956,81 +14368,43 @@ Mon May 10 12:11:37 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/html_generator.rb: Hack to search parents
for unqualified constant names.
-Mon May 10 01:18:15 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/pop.rb (logging): append "\n".
-
-Sun May 9 23:38:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
-
- * lib/net/ftp.rb: ported documentation improvement from 1.8 branch
-
- * lib/net/imap.rb: ditto
+Mon May 10 12:11:37 2004 Dave Thomas <dave@pragprog.com>
- * lib/net/pop.rb: ditto
+ * lib/rdoc/generators/html_generator.rb: Hack to search parents
+ for unqualified constant names.
- * lib/net/smtp.rb: ditto
+Sun May 9 22:37:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+ * lib/net/ftp.rb: improved documentation
+ * lib/net/imap.rb: ditto
+ * lib/net/pop.rb: ditto
+ * lib/net/smtp.rb: ditto
* lib/net/telnet.rb: ditto
-Sun May 9 23:34:51 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * test/ruby/test_float.rb: added test_strtod to test Float("0").
-
-Sun May 9 13:24:24 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * lib/yaml/store.rb: use FileUtils::copy.
-
-Sun May 9 12:34:26 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * regex.c : removed unused file.
-
-Sat May 8 10:53:30 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * io.c (rb_f_open): open should not ignore block when "to_open"
- method is used. [ruby-dev:23478]
-
-Fri May 7 22:07:39 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/fileutils.rb (mv): new option `force'. [ruby-talk:99457]
-
- * lib/fileutils.rb: new method for command option reflection:
- FileUtils.commands, .options, .have_option?, .options_of,
- .collect_methods.
-
- * lib/fileutils.rb: module Verbose, NoWrite, DryRun do not have
- option flags @fileutils_verbose and @fileutils_noop, they make no
- sense.
-
Fri May 7 21:50:21 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::parse_include): Allow
multiple arguments to 'include'
-Fri May 7 21:03:51 2004 Minero Aoki <aamine@loveruby.net>
+Fri May 7 21:31:56 2004 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (fu_list): Array() breaks pathes including "\n".
[ruby-core:02843]
- * test/fileutils/test_fileutils.rb (mkdir): test "\n" in path.
-
-Fri May 7 20:53:25 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/dbm/dbm.c (fdbm_modify): typo fixed. [ruby-dev:23473]
-
-Fri May 7 11:17:27 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Fri May 7 11:25:53 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* util.c (ruby_strtod): "0.0000000000000000001" should be converted
to 1.0e-19 instead of 0.0. (leading zeros aren't significant digits)
[ruby-talk:99318] [ruby-dev:23465]
-Thu May 6 22:27:32 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Fri May 7 10:00:05 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
- * ext/socket/socket.c (ippaddr): use NUMERICHOST if can not resolve
- hostname.
+ * ext/tk/tkutil.c (get_eval_string_core): bug fix. [ruby-dev:23466]
-Thu May 6 22:09:29 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+Thu May 6 22:13:17 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * ext/tk/tkutil.c (get_eval_string_core): bug fix. [ruby-dev:23466]
+ * ext/socket/socket.c (ippaddr): use NUMERICHOST if can not resolve
+ hostname.
Thu May 6 14:22:29 2004 why the lucky stiff <why@ruby-lang.org>
@@ -17045,15 +14419,6 @@ Thu May 6 14:22:29 2004 why the lucky stiff <why@ruby-lang.org>
* ext/syck/gram.c: fixed transfer methods on structs, broke it
last commit.
-Thu May 6 14:38:02 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (rb_push_glob): simplified code (not change behavior)
-
-Thu May 6 13:32:44 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb: get rid of side effect of Config.expand, patched by
- <tttt01@infoseek.jp> (ruby-bugs:PR#597)
-
Thu May 6 11:40:28 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (string): accept NIL.
@@ -17066,13 +14431,16 @@ Thu May 6 01:59:04 2004 Dave Thomas <dave@pragprog.com>
Don't include the &block parameter if we have explicit
yield parameters.
-Wed May 5 03:52:31 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Wed May 5 03:40:29 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/rinda/ring.rb: use recv instead of recvfrom.
-Wed May 5 00:38:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+Tue May 4 23:52:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
* lib/gserver.rb: documented
+
+Tue May 4 23:46:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+
* lib/xmlrpc/README.txt: introduced for documentation purposes
Mon May 3 09:47:24 2004 Dave Thomas <dave@pragprog.com>
@@ -17080,10 +14448,6 @@ Mon May 3 09:47:24 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_method_or_yield_parameters):
Fix parsing bug if yield called within 1 line block
-Sun May 2 21:56:48 2004 Minero Aoki <aamine@loveruby.net>
-
- * test/fileutils/test_fileutils.rb (rm_f, rm_r): test :force flag.
-
Sun May 2 01:04:38 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib, ext/tk: renewal Ruby/Tk
@@ -17092,26 +14456,11 @@ Fri Apr 30 20:08:41 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* time.c (SIZEOF_TIME_T): support SIZEOF_TIME_T == SIZEOF_INT.
-Wed Apr 28 01:26:11 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * oniguruma.h, regparse.c: imported Oni Guruma 2.2.8.
-
-Wed Apr 28 01:16:23 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * oniguruma.h, regparse.c: imported Oni Guruma 2.2.7.
-
-Tue Apr 27 14:43:32 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk: LIBURUBY_A is needed for extconf.rb even when
- cross-compiling.
-
-Tue Apr 27 13:33:50 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+Tue Apr 27 13:12:42 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * parse.y (string_content): turn off NODE_NEWLINE flag to avoid
- unnecessary line trace for inlined expression.
- (ruby-bugs PR#1320)
+ * eval.c (rb_eval): too many line trace call. (ruby-bugs PR#1320)
-Tue Apr 27 08:15:13 2004 why the lucky stiff <why@ruby-lang.org>
+Tue Apr 27 08:41:28 2004 why the lucky stiff <why@ruby-lang.org>
* lib/yaml/rubytypes.rb: passing Range tests.
@@ -17139,33 +14488,32 @@ Mon Apr 26 21:40:09 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/code_objects.rb (RDoc::Context::add_alias): Only alias
to instance methods.
-Sun Apr 25 18:26:23 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * configure.in (ac_cv_func_fork): set to no on DJGPP.
-
-Sat Apr 24 14:32:03 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * re.c: applied stack error handling patch. [ruby-dev:23431]
-
Sat Apr 24 10:38:31 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/markup/simple_markup.rb (SM::SimpleMarkup::group_lines):
Fix bug where consecutive headings are merged.
-Fri Apr 23 23:24:47 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Apr 23 23:26:13 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/mkmf.rb: $hdrdir should not contain macros, for backward
+ * lib/mkmf.rb: $hdrdir should not contain macros for backward
compatibility. [bruby-dev:28]
- * lib/mkmf.rb (create_makefile): in the case of extout, just copy
- script files, without comparison.
+ * version.c (ruby_show_copyright): obtain copyright year from
+ RUBY_RELEASE_YEAR.
+
+ * win32/resource.rb: ditto.
+
+ * win32/resource.rb: default rubyw icon to ruby.ico, and let DLL also
+ include them.
+
+ * win32/resource.rb: include winver.h for older WindowsCE.
Fri Apr 23 16:38:46 2004 Tanaka Akira <akr@m17n.org>
* lib/pathname.rb: sync taint/freeze flag between
a pathname object and its internal string object.
-Fri Apr 23 14:52:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Apr 23 14:52:08 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (stmt, arg, aref_args): should not make sole splat into
array, in aref_args other than aref with op_asgn.
@@ -17175,18 +14523,7 @@ Fri Apr 23 14:14:38 2004 Tanaka Akira <akr@m17n.org>
* lib/resolv.rb: don't use Regexp#source to embed regexps.
[ruby-dev:23432]
-Thu Apr 22 18:25:10 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk, ext/extmk.rb: make ext and .ext get removed by distclean.
-
-Thu Apr 22 10:07:01 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * */Makefile.sub (distclean-local): should remove $(RBCONFIG).
-
-Thu Apr 22 04:17:57 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_mod_define_method): allow binding methods to modules.
- [ruby-dev:23410]
+Thu Apr 22 04:15:36 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (aref_args): should pass expanded list. [ruby-core:02793]
@@ -17198,7 +14535,7 @@ Thu Apr 22 01:12:57 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_index_m): use unsigned comparison for T_FIXNUM
search. [ruby-talk:97342]
-Wed Apr 21 23:04:42 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Wed Apr 21 22:57:27 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/rinda/rinda.rb, test/rinda/test_rinda.rb: check Hash tuple size.
@@ -17207,44 +14544,6 @@ Wed Apr 21 20:05:00 2004 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb (URI::HTTP#proxy_open): set Host: field explicitly.
[ruby-list:39542]
-Wed Apr 21 18:39:46 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/smtp.rb: merge SMTP-TLS patch. This patch is
- contributed by Daniel Hob. [ruby-core:02789]
-
-Wed Apr 21 18:23:45 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/smtp.rb: change coding style: def m( a ) -> def m(a).
-
-Wed Apr 21 18:01:47 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/pop.rb: do not use class variables.
-
- * lib/net/pop.rb (do_start): ensure to clean up connection when
- authentication failed.
-
-Wed Apr 21 17:23:59 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb (HTTP#connect): CONNECT must precede SSL connect.
- [ruby-dev:23379]
-
- * lib/net/http.rb (HTTP.new): class variables are not inherited
- now.
-
-Wed Apr 21 15:56:43 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/test/unit/ui/console/testrunner.rb (test_started): restore $0
- after changing process title. [ruby-talk:97426]
-
-Wed Apr 21 10:18:06 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * process.c(rb_spawn): fix SEGV at "p system('command line here')"
- (may happen only in bccwin32) [ruby-dev:23380]
-
-Mon Apr 19 20:58:44 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c: Updated RDocs.
-
Mon Apr 19 18:11:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* hash.c (rb_hash_equal): returns true if two hashes have same set
@@ -17253,132 +14552,107 @@ Mon Apr 19 18:11:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* hash.c (rb_hash_eql): returns true if two hashes are equal and
have same default values.
-Mon Apr 19 08:19:11 2004 Doug Kearns <djkea2@mugca.its.monash.edu.au>
+Mon Apr 19 08:19:58 2004 Doug Kearns <djkea2@mugca.its.monash.edu.au>
- * dln.c, io.c, pack.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb,
- lib/date.rb, lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb,
- lib/matrix.rb, lib/monitor.rb, lib/set.rb, lib/thwait.rb,
- lib/timeout.rb, lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb,
- lib/net/ftp.rb, lib/net/http.rb, lib/net/imap.rb, lib/net/pop.rb,
- lib/net/telnet.rb, lib/racc/parser.rb, lib/rinda/rinda.rb,
- lib/rinda/tuplespace.rb, lib/shell/command-processor.rb,
- lib/soap/rpc/soaplet.rb, lib/test/unit/testcase.rb,
- lib/test/unit/testsuite.rb: typo fix.
+ * dln.c, io.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb, lib/date.rb,
+ lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb, lib/matrix.rb,
+ lib/monitor.rb, lib/set.rb, lib/thwait.rb, lib/timeout.rb,
+ lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb, lib/net/ftp.rb,
+ lib/net/http.rb, lib/net/imap.rb, lib/net/telnet.rb,
+ lib/racc/parser.rb, lib/rinda/rinda.rb, lib/rinda/tuplespace.rb,
+ lib/shell/command-processor.rb, lib/soap/rpc/soaplet.rb,
+ lib/test/unit/testcase.rb, lib/test/unit/testsuite.rb: typo fix.
Mon Apr 19 08:14:18 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::find_body): Allow for
#ifdef HAVE_PROTOTYPES
+Fri Apr 16 22:33:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+
+ * ext/iconv/iconv.c: nearly finished RDoc comments.
+
Fri Apr 16 17:04:07 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_equal): always returns true or false, never
returns nil. [ruby-dev:23404]
-Fri Apr 16 12:38:48 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/drb/drb.rb (DRb::DRbUnknown::initialize): Exception#to_str is
- deprecated.
-
- * lib/drb/drb.rb (DRb::DRbServer::InvokeMethod::perform): multiple
- value class changed.
-
- * lib/drb/invokemethod.rb (DRb::DRbServer::InvokeMethod18Mixin::block_yield):
- ditto.
-
-Fri Apr 16 08:27:08 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Apr 16 08:27:02 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb: skip linking when libraries to be preloaded not
compiled. [ruby-list:39561]
-Thu Apr 15 19:57:11 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Apr 15 23:21:52 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c (pst_success_p): new method Process::Status#success?.
[ruby-dev:23385]
- * rubytest.rb: do nothing while cross-compiling, return status in
- system independent style.
-
-Thu Apr 15 19:26:54 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (rb_push_glob): Dir.glob() should return nil if block is given.
- (http://www.ruby-lang.org/ja/man/index.cgi?cmd=view;name=Dir)
-
- * dir.c (push_braces): Dir.glob() should handle '{ }' nested more than
- 3 times.
-
- * dir.c (push_braces, rb_push_glob): Dir.glob() should handle escaped
- '{' and '}' and ','.
-
- [ruby-dev:23376]
-
Thu Apr 15 17:12:13 2004 Tanaka Akira <akr@m17n.org>
* ext/gdbm/gdbm.c (Init_gdbm): define GDBM::READER, GDBM::WRITER,
GDBM::WRCREAT and GDBM::NEWDB.
(fgdbm_initialize): use specified read/write flag.
-Wed Apr 14 13:06:09 2004 Doug Kearns <djkea2@mugca.its.monash.edu.au>
-
- * array.c, enum.c, eval.c, file.c, io.c, numeric.c, object.c, prec.c,
- process.c, re.c, string.c: typos in RDoc comments. [ruby-core:02783]
-
Wed Apr 14 11:29:56 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* numeric.c (flo_eq): workaround for bcc32's bug.
(ruby-bugs-ja:PR#594)
+Wed Apr 14 13:06:35 2004 Doug Kearns <djkea2@mugca.its.monash.edu.au>
+
+ * array.c, enum.c, eval.c, file.c, io.c, numeric.c, object.c, prec.c,
+ process.c, re.c, string.c: typos in RDoc comments. [ruby-core:02783]
+
Wed Apr 14 11:06:38 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::scan): Changed
behavior of :enddoc: -- it now unconditionally terminates
processing of the current file.
-Wed Apr 14 10:57:40 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Wed Apr 14 11:03:22 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* defines.h: include <net/socket.h> to get fd_set definition in BeOS.
-Tue Apr 13 23:00:55 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Tue Apr 13 23:06:30 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/rinda/rinda.rb: change pattern matching.
a === b -> a == b || a === b. [druby-ja:98]
* test/rinda/test_rinda.rb: ditto.
-Tue Apr 13 21:50:57 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Apr 13 19:54:29 2004 Minero Aoki <aamine@loveruby.net>
- * bcc32/Makefile.sub (PHONY): Borland make disallows empty command
- rules.
+ * lib/net/http.rb: should not overwrite HTTP request header.
+ [ruby-list:39543]
-Tue Apr 13 17:55:16 2004 Minero Aoki <aamine@loveruby.net>
+Tue Apr 13 01:30:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
- * lib/net/http.rb (begin_transport): should not overwrite HTTP
- request header. [ruby-list:39543]
+ * ext/iconv/iconv.c: RDoc documentation (from RD; nearly finished).
+ * ext/iconv/charset_alias.rb: Prevent from RDoc'ing.
-Tue Apr 13 16:48:00 2004 Minero Aoki <aamine@loveruby.net>
+Mon Apr 12 19:11:29 2004 Eric Hodel <drbrain@segment7.net>
- * lib/net/pop.rb: merge POP3S patch. This patch is contributed by
- Daniel Hobe.
+ * gc.c (rb_gc_copy_finalizer): typo. [ruby-core:02774]
-Tue Apr 13 02:56:29 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
+Mon Apr 12 18:52:32 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
- * common.mk: changed the order of ascii.c alphabetically.
+ * ext/openssl/ossl_x509name.c (ossl_x509name_init_i): should return
+ a value.
-Mon Apr 12 19:11:21 2004 Eric Hodel <drbrain@segment7.net>
+Mon Apr 12 10:43:47 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * gc.c (rb_gc_copy_finalizer): typo. [ruby-core:02774]
+ * dir.c (rb_glob2, rb_glob, rb_globi, push_globs, push_braces,
+ rb_push_glob): fix memory leak. (leaked when block was interrupted)
-Mon Apr 12 18:45:58 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Mon Apr 12 10:27:37 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * ext/openssl/ossl_x509name.c (ossl_x509name_init_i): should return
- a value.
+ * bcc32/Makefile.sub: backport SIZEOF_TIME_T definition from 1.9.
-Mon Apr 12 10:39:50 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * win32/Makefile.sub: ditto.
- * dir.c (rb_glob2, rb_glob, push_globs, push_braces, rb_push_glob):
- fix memory leak. (leaked when block was interrupted)
+ * wince/Makefile.sub: ditto.
-Sun Apr 11 19:10:13 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sun Apr 11 19:12:35 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (require_libraries): restore source file/line after
statically linked extensions initialized. [ruby-dev:23357]
@@ -17399,73 +14673,7 @@ Sat Apr 10 00:00:19 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/markup/simple_markup/inline.rb: Fix problem
with \_cat_<b>dog</b>
-Fri Apr 9 17:05:21 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (has_magic, find_dirsep): incomplete '[' matches no character
- in Dir.glob. (follows File.fnmatch's behavior)
-
- * dir.c (fnmatch_helper): incomplete escape is ignored in File.fnmatch.
- (follows Dir.glob's behavior)
-
- * dir.c (find_dirsep): '/' between '[' and ']' is ignored in Dir.glob.
- (follows File.fnmatch with File::FNM_PATHNAME 's behavior)
-
- * dir.c (find_dirsep): escaped slash '\/' loses its meaning as
- directory separator in Dir.glob.
-
- [ruby-dev:23291]
-
-Thu Apr 8 20:25:19 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb (extmake): skip uncompiled extensions.
-
- * lib/mkmf.rb (create_makefile): emit no rules for static library if
- $static is nil, e.g., outside of ext/.
-
- * lib/test/unit/ui/console/testrunner.rb (test_started): show test
- name via $0.
-
- * runruby.rb: set environments to use the compiled binary.
-
- * test/runner.rb: do nothing while cross-compiling.
-
- * test/drb/drbtest.rb, test/soap/calc/test_calc_cgi.rb: use envutil to
- know ruby binary, and restore $: after require.
-
- * test/ruby/envutil.rb: give priority to RUBY environment variable to
- use just compiled binary and libraries.
-
-Thu Apr 8 19:03:33 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (rb_io_binmode): inverted condition. [ruby-dev:23349]
-
-Thu Apr 8 18:22:00 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/iconv.c (iconv_s_list): return encoding list if no block
- is given. [ruby-dev:23063]
-
-Wed Apr 7 15:29:24 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * pack.c (pack_pack): use NUM2INT() instead of num2i32().
-
-Wed Apr 7 12:32:02 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/parser.rb, lib/rss/1.0.rb: accepted rdf:resource or
- resource attribute in rdf:li.
- * test/rss/test_parser.rb: added test for above change.
-
- * lib/rss/dublincore.rb: reverted style.
-
- * lib/rss/xmlparser.rb: normalized XMLParser class hierarchy.
-
-Wed Apr 7 10:43:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * Makefile.in, common.mk, */Makefile.sub (ext/extinit.o): OUTFLAG
- doesn't work for object files on VC.
-
- * */Makefile.sub (config.h): need SIZEOF_TIME_T now.
-
-Wed Apr 7 00:24:34 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Wed Apr 7 00:19:50 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/rinda/rinda.rb: fix hash tuple bug.
@@ -17475,12 +14683,6 @@ Wed Apr 7 00:24:34 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
Tue Apr 6 18:24:18 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * file.c (rb_get_path): get path string via "to_path" method if
- path object is not a string. [Ruby2]
-
- * gc.c (rb_gc_call_finalizer_at_exit): do not free threads in the
- exit finalizers.
-
* io.c (rb_io_reopen): should use rb_io_check_io().
Tue Apr 6 16:46:09 2004 Tanaka Akira <akr@m17n.org>
@@ -17491,82 +14693,49 @@ Tue Apr 6 16:46:09 2004 Tanaka Akira <akr@m17n.org>
(time_plus): use time_add.
(time_minus): use time_add.
-Tue Apr 6 13:11:48 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ext/socket/socket.c (raise_socket_error): never return.
+Tue Apr 6 13:21:30 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/socket/socket.c (make_hostent): must return value.
-Tue Apr 6 00:14:43 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * error.c (Init_Exception): remove Exception#to_str. [Ruby2]
-
- * eval.c (error_print): should no call "to_str" anymore use
- "message" method instead.
-
- * io.c (rb_f_open): Kernel#open() calls "to_open" if the first
- argument responds to it. [Ruby2]
-
-Tue Apr 6 00:13:43 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Tue Apr 6 00:05:30 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/rinda/rinda.rb: add require 'drb/drb'
-Mon Apr 5 22:25:32 2004 Tanaka Akira <akr@m17n.org>
-
- * test/zlib/test_zlib.rb: new file.
- (TestZlibGzipWriter#test_new_nil): test for [ruby-dev:23228].
-
-Mon Apr 5 22:16:23 2004 Minero Aoki <aamine@loveruby.net>
-
- * parse.y (assoc_list): {a: 1, b: 2} should be allowed.
- [ruby-dev:23328]
-
-Mon Apr 5 19:43:40 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * regexec.c: imported Oni Guruma 2.2.6.
-
-Mon Apr 5 19:39:10 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
+Mon Apr 5 08:18:23 2004 Dave Thomas <dave@pragprog.com>
- * regparse.c, oniguruma.h: imported Oni Guruma 2.2.6.
+ * lib/rdoc/rdoc.rb: Remove leading ./ from file names so that cross
+ references work properly.
-Mon Apr 5 12:12:09 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Sun Apr 4 20:33:42 2004 Minero Aoki <aamine@loveruby.net>
- * ext/socket/socket.c (raise_socket_error): some platforms don't have
- EAI_SYSTEM.
+ * eval.c (Init_load): make $LOADED_FEATURES built-in.
+ [ruby-dev:23299]
-Mon Apr 5 08:18:23 2004 Dave Thomas <dave@pragprog.com>
+ * ruby.c (ruby_prog_init): make $PROGRAM_NAME built-in.
- * lib/rdoc/rdoc.rb: Remove leading ./ from file names so that cross
- references work properly.
+ * lib/English.rb: remove $LOADED_FEATURES and $PROGRAM_NAME.
Sun Apr 4 14:01:20 2004 Dave Thomas <dave@pragprog.com>
- * lib/rdoc/options.rb (Options::parse): Allow multiple -x options to
- RDoc. Fix bug where files weren't being excluded properly
+ * lib/rdoc/options.rb (Options::parse): Allow multiple -x options to RDoc.
+ Fix bug where files weren't being excluded properly
-Sat Apr 3 09:36:38 2004 why the lucky stiff <why@ruby-lang.org>
+Sat Apr 3 17:11:05 2004 why the lucky stiff <why@ruby-lang.org>
* ext/syck/syck.h: version 0.43.
-Sat Apr 3 08:28:47 2004 why the lucky stiff <why@ruby-lang.org>
-
* ext/syck/lib/gram.c: allow root-level inline collections.
- [ruby-talk:94922]
+ [ruby-talk:94922]
* lib/yaml/rubytypes.rb (Symbol#to_yaml): emit symbols as implicits.
- [ruby-talk:94930]
-
-Fri Apr 2 19:28:48 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ [ruby-talk:94930]
- * bcc32/Makefile.sub (OUTFLAG): needed for static-linked-ext.
-
-Fri Apr 2 18:00:05 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/syck/bytecode.c: turn off default implicit typing.
- * ext/extmk.rb (extmake): extract necessary variables for static link
- from Makefile.
+ * ext/syck/implicit.c: detect base60 integers.
- * lib/mkmf.rb (create_makefile): save preload and libpath for next
- compile.
+ * ext/syck/rubyext.c: handle base60, as well as hex and octal
+ with commas. implicit typing of ruby symbols.
Fri Apr 2 17:27:17 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -17585,20 +14754,8 @@ Fri Apr 2 14:35:26 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (block_pass): should generate unique identifier of the
pushing block. [ruby-talk:96363]
-Fri Apr 2 11:36:20 2004 Minero Aoki <aamine@loveruby.net>
-
- * eval.c (Init_load): make $LOADED_FEATURES built-in.
- [ruby-dev:23299]
-
- * ruby.c (ruby_prog_init): make $PROGRAM_NAME built-in.
-
- * lib/English.rb: remove $LOADED_FEATURES and $PROGRAM_NAME.
-
Fri Apr 2 07:31:38 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/socket/socket.c: mistakingly removed do_not_reverse_lookup.
- [ruby-list:39475]
-
* ext/socket/socket.c (make_hostent): fix memory leak, based on
the patch from HORIKAWA Hisashi <vzw00011@nifty.ne.jp>.
@@ -17623,6 +14780,14 @@ Thu Apr 1 19:58:37 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
be empty). Instance of URI have instance_variables but it must be
llowed whenever original mapping is allowed or not.
+ * lib/xsd/datatypes.rb: check the smallest positive non-zero
+ single-precision float exactly instead of packing with "f".
+ [ruby-talk:88822]
+
+ * lib/soap/mapping/rubytypeFactory.rb: should not dump singleton class.
+ [ruby-dev:22588]
+ c = class << Object.new; class C; self; end; end; SOAPMarshal.dump(c)
+
Wed Mar 31 19:06:23 2004 Tanaka Akira <akr@m17n.org>
* time.c (year_leap_p): new function.
@@ -17630,7 +14795,7 @@ Wed Mar 31 19:06:23 2004 Tanaka Akira <akr@m17n.org>
(search_time_t): use timegm_noleapsecond instead of
mktime for first guess.
-Wed Mar 31 12:05:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Mar 31 12:04:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/delegate.rb (DelegateClass): define internal methods of the
result class, but not metaclass of the caller. [ruby-talk:96156]
@@ -17639,44 +14804,12 @@ Wed Mar 31 12:05:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.h: missing.h is now prerequisite to intern.h.
-Wed Mar 31 11:17:16 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * pack.c (pack_pack): raises RangeError if uv is out of UTF8 value
- range. [ruby-dev:23281]
-
- * io.c (rb_io_binmode): stdio buffer should be empty when calling
- IO#binmode. [ruby-talk:96155]
-
Tue Mar 30 20:25:34 2004 Tanaka Akira <akr@m17n.org>
* time.c (search_time_t): limit guess range by mktime if it is
available. [ruby-dev:23274]
-Tue Mar 30 18:19:00 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_eval): fix SEGV at retry in iterator's receiver.
- [ruby-dev:23227]
-
-Mon Mar 29 20:17:16 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (rb_exec): follow older behavior if close-on-exec is not
- available.
-
- * process.c (rb_fork): protect from exceptions while waiting failed
- process, if status is given.
-
-Sun Mar 28 16:25:37 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * cygwin/GNUmakefile.in (clean-local, distclean-local): remove
- work files.
-
- * win32/Makefile.sub (clean-local): ditto.
-
-Sun Mar 28 14:23:02 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/pop.rb: def m( arg ) -> def m(arg).
-
-Sun Mar 28 14:09:13 2004 Minero Aoki <aamine@loveruby.net>
+Sun Mar 28 14:16:59 2004 Minero Aoki <aamine@loveruby.net>
* lib/net/pop.rb (auth): failed when account/password include "%".
[ruby-talk:95933]
@@ -17690,46 +14823,16 @@ Sat Mar 27 10:40:48 2004 Tanaka Akira <akr@m17n.org>
* (lib/pp.rb, lib/prettyprint.rb): define seplist in PP::PPMethods
instead of PrettyPrint.
-Sat Mar 27 01:47:09 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Thu Mar 25 23:28:52 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * lib/logger.rb: trim tail space of each line. no user visible change.
-
- * lib/rss/dublincore.rb: fixed class definition mismatch.
-
- * sample/openssl/gen_csr.rb: fixed wrong usage text.
+ * time.c (time_overflow_p): backport 1.9 usec overflow function.
+ (ruby-bugs PR#1307)
Thu Mar 25 23:15:24 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_options.rb (RI::Options::show_version):
Add --version option
-Thu Mar 25 21:45:00 2004 Shigeo Kobayashi <shigek@ruby-lang.org>
-
- * ext/bigdecimal/bigdecimal.c: Bug in + and - reported by Bret Jolly
- fixed.
-
-Thu Mar 25 21:01:32 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * version.c (ruby_show_copyright): obtain copyright year from
- RUBY_RELEASE_YEAR.
-
- * win32/resource.rb: ditto.
-
-Thu Mar 25 19:37:35 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/resource.rb: default rubyw icon to ruby.ico, and let DLL also
- include them.
-
- * win32/resource.rb: include winver.h for older WindowsCE.
-
-Thu Mar 25 14:01:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * common.mk, */Makefile.sub (lib, dll): phony targets.
-
- * configure.in (ruby, miniruby): ditto.
-
- * cygwin/GNUmakefile.in (rubyw): ditto.
-
Thu Mar 25 04:16:18 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_options.rb (RI::Options): Add the --list-names option,
@@ -17746,7 +14849,7 @@ Thu Mar 25 02:00:18 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/template/html/one_page_html.rb (Page):
Fix to work with C modules.
-Wed Mar 24 20:49:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+Wed Mar 24 21:17:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
* lib/uri.rb: Documented (thanks Dmitry V. Sabanin).
* lib/uri/common.rb: Ditto.
@@ -17756,13 +14859,17 @@ Wed Mar 24 20:49:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
* lib/uri/https.rb: Ditto.
* lib/uri/ldap.rb: Ditto.
* lib/uri/mailto.rb: Ditto.
+ (All backported from 1.9)
-Wed Mar 24 18:48:05 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Mar 24 18:48:26 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb ($ruby, $topdir, $hdrdir): should not be affected by
DESTDIR after installed.
- * lib/mkmf.rb (dummy_makefile): default file lists to be cleaned.
+ * lib/mkmf.rb (RUBY): / is not recognized as path separator on
+ nmake/bmake. [ruby-list:39388]
+
+ * lib/mkmf.rb (init_mkmf): $INCFLAGS also should be lazy-evaluated.
Wed Mar 24 12:32:56 2004 Dave Thomas <dave@pragprog.com>
@@ -17779,86 +14886,18 @@ Wed Mar 24 11:11:26 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/html_generator.rb (Generators::HTMLGenerator::load_html_template):
Allow non-RDoc templates by putting a slash in the template name
-Wed Mar 24 10:05:22 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * lib/tempfile.rb (Tempfile::_close): should not clear @tmpname
- until the file is really removed. [ruby-core:02684]
-
-Wed Mar 24 04:12:44 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * object.c (rb_mod_cvar_get): new method Module#class_variable_get.
-
- * object.c (rb_mod_cvar_set): ditto (Module#class_variable_set).
-
-Tue Mar 23 17:45:22 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (rb_thread_atfork): 1.9 warns no more for thread
- termination. [ruby-dev:23212]
-
-Tue Mar 23 14:46:10 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * Makefile.in, */Makefile.sub, common.mk (clean-local, distclean-local):
- separate files under directories due to directory separator.
-
- * */Makefile.sub (MKFILES): common.mk and */Makefile.sub should not be
- removed.
-
- * win32/Makefile.sub, wince/Makefile.sub: $* cannot appear in explicit
- rules.
-
- * cygwin/GNUmakefile.in: some mingw stuffs were missed.
+Mon Mar 22 16:19:57 2004 WATANABE Hirofumi <eban@ruby-lang.org>
- * lib/mkmf.rb (create_makefile): Borland make wrongly removes braces
- from command lines.
-
- * bcc32/Makefile.sub: needs bcc32/mkexports.rb.
-
-Mon Mar 22 08:21:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * Makefile.in, */Makefile.sub, common.mk: extract common portions.
-
- * Makefile.in, cygwin/GNUmakefile.in, */Makefile.sub (RBCONFIG):
- separated time stamp file for rbconfig.rb.
-
- * configure.in: append common.mk to Makefile.
-
- * mkconfig.rb: keep mtime of rbconfig.rb if unchanged.
-
- * win32/rm.bat: remove multiple files.
-
- * wince/mkconfig_wce.rb: use fake.rb instead.
-
-Sun Mar 21 22:17:35 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#virtual_host):
- sort @virtual_hosts in address, port, host order.
-
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#lookup_server):
- hostname should not be match if :ServerAlias is not given.
+ * ruby.1: add -width option to .Bl for old groff.
Sun Mar 21 21:11:16 2004 Keiju Ishitsuka <keiju@ishitsuka.com>
* lib/shell/*: bug fix for Shell#system(command_line_string).
-Sun Mar 21 21:04:42 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+Sat Mar 20 20:57:10 2004 David Black <dblack@wobblini.net>
- * ruby.1: add -width option to .Bl for old groff.
-
-Sun Mar 21 18:57:37 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * test/rss/*: Test::Unit::TestCase -> RSS::TestCase and
- Test::Unit::Assertions -> RSS::Assertions.
-
-Sun Mar 21 18:48:20 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/{rss,dublincore,syndication}.rb: handled W3CDTF correctly.
-
-Sun Mar 21 18:15:29 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * test/rss/test_xml-stylesheet.rb: added tests for xml-stylesheet.
-
- * lib/rss/xml-stylesheet.rb: added xml-stylesheet parsing
- function.
+ * lib/scanf.rb: Backported 1.9 branch
+ modifications/corrections to 1.8 branch
Sat Mar 20 23:51:03 2004 WATANABE Hirofumi <eban@ruby-lang.org>
@@ -17868,164 +14907,58 @@ Sat Mar 20 23:51:03 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* eval.c (rb_f_raise): should not clear backtrace information if
exception object already have one.
-Sat Mar 20 21:21:03 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * ext/extmk.rb: rm -rf $extout, not extout.
-
Sat Mar 20 15:25:36 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/template/html/html.rb (RDoc::Page): Force
page background to white.
-Sat Mar 20 09:33:36 2004 Tadayoshi Funaba <tadf@dotrb.org>
+Sat Mar 20 09:52:33 2004 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date.rb, lib/date/format.rb: _parse() now accepts fractional
part of second minute that follows a comma or a full stop.
-Fri Mar 19 21:06:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (assoc_list): allow {sym: val} style Hash. [Ruby2]
- this change is done by Nobuyoshi Nakada <nobu@ruby-lang.org>.
-
-Fri Mar 19 15:15:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * variable.c (rb_cvar_set): class variables become private to the
- particular class/module. [Ruby2]
-
- * variable.c (rb_cvar_get): ditto.
-
- * variable.c (rb_cvar_defined): ditto.
-
-Fri Mar 19 11:31:32 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * lib/mkmf.rb ($beos, $solaris): add OS flags.
-
- * lib/mkmf.rb (RUBY): / is not recognized as path separator on
- nmake/bmake. [ruby-list:39388]
-
- * lib/mkmf.rb (CLEANLIBS, CLEANOBJS): should remove *.exp with *.so.
-
Fri Mar 19 01:55:57 2004 Mauricio Fernandez <batsman.geo@yahoo.com>
* io.c (rb_io_sync): need not to check writable. [ruby-core:02674]
-Thu Mar 18 19:47:44 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * instruby.rb, rubytest.rb: do not depend on srcdir.
+Thu Mar 18 21:44:38 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-Thu Mar 18 18:50:06 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * mkconfig.rb: no longer embed srcdir and compile_dir into
- rbconfig.rb.
+ * lib/drb/drb.rb: backport drb.rb 1.16.
- * ext/extmk.rb, lib/mkmf.rb: obtain top_srcdir and topdir from library
- paths.
+Fri Mar 18 17:49:51 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
-Thu Mar 18 17:46:35 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+ * struct.c (make_struct): allow const_id for accessor names.
+ [ruby-core:04585]
- * lib/drb/drb.rb: do not undef :to_a.
+ * eval.c (rb_attr): check if attribute name is local_id or
+ const_id.
Thu Mar 18 16:22:38 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (proc_eq): avoid false positive by using scope and
dyna_vars. no longer use frame.uniq.
- * eval.c (proc_arity): arity is now defined as number of
- parameters that would not be ignored. i.e. Proc.new{}.arity
- returns zero. update test suites too.
-
-Thu Mar 18 15:27:25 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c: remove specialized version of rb_Array(). use simple
- one defined in object.c.
-
- * object.c (Init_Object): remove Kernel#to_a.
-
- * enum.c (enum_zip): use "to_a" instead of "to_ary".
-
-Wed Mar 17 00:22:03 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * oniguruma.h: imported Oniguruma 2.2.5.
- * regparse.c: ditto.
-
-Tue Mar 16 11:14:17 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (fnmatch_helper): File.fnmatch('\.', '.') should return true.
- (Rev1.112 lost compatiblity)
-
- * dir.c (fnmatch_helper): File.fnmatch('\/', '/', File::FNM_PATHNAME)
- should return true. (Rev1.112 lost compatiblity)
-
- * dir.c (fnmatch): File.fnmatch('**/.boo', '.foo/.boo',
- File::FNM_PATHNAME) should return false because of leading period.
-
-Mon Mar 15 17:01:07 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * error.c (exc_initialize): calling 'to_str' each time just for
- type checking is too heavy. [ruby-core:02661]
+Wed Mar 17 14:44:43 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-Mon Mar 15 10:14:51 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SocketForwarder):
- add do_not_reverse_lookup.
+ * dir.c (range): fix possible "\0" overrun. (in case of "\0-")
Mon Mar 15 07:39:13 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_yield_0): should not re-submit TAG_BREAK if this
yield is not break destination. [ruby-dev:23197]
-Sun Mar 14 22:07:38 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (rb_thread_raise): err at unstarted thread. (PR#1302)
-
-Sat Mar 13 14:56:32 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * test/drb/ut_drb.rb: use 'druby://localhost:0'. [ruby-dev:23078]
-
- * test/drb/ut_eval.rb: ditto.
-
- * test/drb/ut_large.rb: ditto.
-
- * test/drb/ut_safe1.rb: ditto.
-
- * test/drb/ut_drb_drbssl.rb: use 'drbssl://localhost:0'.
+Sat Mar 13 14:28:16 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-Fri Mar 12 23:52:56 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+ * test/drb/test_drbssl.rb: rescue LoadError. (Barkport from main
+ trunk)
- * dir.c (fnmatch): directory recursion '**/' can be used with
- File::FNM_PATHNAME. [ruby-dev:22901]
-
- * dir.c (fnmatch, fnmatch_helper): only '/' is accepted as path
- separator even in DOSISH environment. [ruby-dev:22974]
- [ruby-list:39337]
-
- * dir.c (fnmatch_helper): faster '*' matching.
-
-Fri Mar 12 20:19:16 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (rb_cv_noreturn): default for platforms not support
- prototypes.
-
- * ruby.c (ruby_init_loadpath): buffer for path name should have
- MAXPATHLEN.
-
- * lib/mkmf.rb (configuration): include topdir and hdrdir in VPATH.
-
- * lib/mkmf.rb (create_makefile): default dependency rule.
-
-Fri Mar 12 07:35:36 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/config.rb (WEBrick::Config::General): add
- :DoNotReverseLookup.
-
- * lib/webrick/server.rb (WEBrick::GenericServer#accept): call
- do_not_reverse_lookup for each socket if :DoNotReverseLookup
- is set. [ruby-code:02357]
+ * test/drb/test_drbunix.rb: ditto.
-Wed Mar 10 22:26:25 2004 Minero Aoki <aamine@loveruby.net>
+Wed Mar 10 22:28:09 2004 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (remove_dir): should handle symlink correctly.
This patch is contributed by Christian Loew. [ruby-talk:94635]
+ (Backport from main trunk)
Wed Mar 10 16:28:42 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -18036,337 +14969,54 @@ Wed Mar 10 16:28:42 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_yield_0): set exit_value for block break.
-Wed Mar 10 16:00:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * struct.c (rb_struct_s_def): Struct::new executes block with
- generated struct class. [ruby-talk:02606]
-
Wed Mar 10 15:58:43 2004 Ryan Davis <ryand@zenspider.com>
* eval.c (eval): Only print backtrace if generating the backtrace
doesn't generate an exception. [ruby-core:02621]
-Wed Mar 10 10:15:16 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * ruby.c (opt_W_getter): get rid of warning.
-
- * bcc32/Makefile.sub, win32/Makefile.sub, wince/Makefile.sub:
- fixed dependency.
-
Tue Mar 9 13:04:26 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_ungetc): raise IOError instead of calling
rb_sys_fail(). [ruby-talk:23181]
-Tue Mar 9 10:03:40 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * bcc32/Makefile.sub, win32/Makefile.sub, wince/Makefile.sub:
- replaced regex.c entry with Oniguruma files.
-
-Tue Mar 9 01:09:46 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * Makefile.in: replaced regex.c entry with Oniguruma files.
-
-Mon Mar 8 23:16:07 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: HTTPHeader did not initialized correctly.
-
- * lib/net/http.rb (connect): does same debug output.
-
-Mon Mar 8 21:38:18 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb (add_header): remove warning. [ruby-dev:23170]
-
-Mon Mar 8 21:09:39 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (range): Cancel change for incomplete '['. More discussion
- is needed.
-
-Mon Mar 8 19:35:13 2004 akira yamada <akira@arika.org>
+Mon Mar 8 19:32:28 2004 akira yamada <akira@ruby-lang.org>
* lib/uri/common.rb (URI::REGEXP::PATTERN::HOSTPORT): (?:#{PORT})
-> (?::#{PORT}). [ruby-dev:23170]
-Mon Mar 8 15:03:24 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Mar 8 15:31:41 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* dir.c (range): treat incomplete '[' as ordinary character (like
- has_magic does). fix buffer overrun at incomplete escape like '[\'.
-
-Mon Mar 8 13:35:32 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+ has_magic does).
- * regparse.c (parse_exp): need to separate initialization for bcc32.
- [ruby-dev:23169]
+ * dir.c (range): Cancel above change. More discussion is needed.
- * oniguruma.h (ONIG_EXTERN): check __GNUC__ instead of __CYGWIN__.
+Sun Mar 7 22:37:46 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-Mon Mar 8 01:05:55 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/config.rb (WEBrick::Config::HTTP): rename :RequestHander
- to :RequestCallback and add new option :ServerAlias.
+ * test/drb/ut_drb.rb: use 'druby://localhost:0'. [ruby-dev:23078]
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): use
- :RequestCallback and warn if :RequestHandler is in server's option.
+ * test/drb/ut_eval.rb: ditto.
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): should print
- error message for WEBrick::HTTPSataus::Error.
+ * test/drb/ut_large.rb: ditto.
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#lookup_server):
- lookup for hostname from :ServerAlias if the req.host is not match
- to :ServerName.
+ * test/drb/ut_safe1.rb: ditto.
- * lib/webrick/httpservlet.rb (WEBrick::HTTPServlet::CGIHandler#do_GET):
- use $?.exitstatus and refine log message.
+ * test/drb/ut_drb_drbssl.rb: use 'drbssl://localhost:0'.
Sun Mar 7 16:22:26 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* Makefile.in (lex.c): use $? instead of $<.
- * lib/pstore.rb (commit_new): use FileUtils.copy_stream for Cygwin.
- [ruby-dev:23157]
-
-Sun Mar 7 05:34:42 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: HTTPHeader keeps its header fields as an array.
-
- * lib/net/http.rb: new method HTTPHeader#add_header, get_fields.
-
- * lib/net/http.rb: new method HTTPHeader#content_length=.
-
- * lib/net/http.rb: new method HTTPHeader#content_type, main_type,
- sub_type, type_params, content_type=, set_content_type.
-
- * lib/net/http.rb (HTTPHeader#basic_encode): result of pack(m) may
- contain multiple LFs.
-
-Sun Mar 7 03:11:00 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: new method Net::HTTPRequest#body(=).
-
- * lib/net/http.rb: new method Net::HTTPRequest#body_stream(=).
-
-Sun Mar 7 02:06:07 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: spin off https code again.
-
- * lib/net/https.rb: new file.
-
- * ext/openssl/lib/net/https.rb: removed. moved to net/https with
- slight modifications.
-
- * ext/openssl/lib/net/protocols.rb: removed. merged with net/http.
-
- * lib/net/protocol.rb: new class BufferedIO.
-
- * lib/net/protocol.rb: InternetMessageIO < BufferedIO.
-
- * lib/net/protocol.rb: BufferedIO.new takes an IO.
-
- * lib/net/smtp.rb: follow InternetMessageIO's change.
-
- * lib/net/pop.rb: ditto.
-
-Sun Mar 7 00:55:03 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/protocol.rb: remove method: InternetMessageIO#address,
- port, ip_address, read_timeout(=), socket.
+Fri Mar 5 00:54:14 2004 Dave Thomas <dave@pragprog.com>
- * lib/net/protocol.rb: simplify code.
-
- * lib/net/protocol.rb: apply latest coding style.
-
-Sat Mar 6 15:15:05 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/strscan/depend: depends on re.h and regex.h.
-
- * ext/strscan/strscan.c: no version check needed.
-
- * ext/strscan/strscan.c (strscan_init_copy): struct re_registers must
- not be bitwise copied.
-
-Sat Mar 6 11:14:33 2004 David Black <dblack@wobblini.net>
-
- * lib/scanf.rb: refixed the previous fix in IO#block_scanf
-
-Sat Mar 6 10:49:40 2004 David Black <dblack@wobblini.net>
-
- * lib/scanf.rb: fixed a logic glitch in IO#block_scanf
-
-Sat Mar 6 02:00:19 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: net/https is merged.
-
- * ext/openssl/lib/net/https.rb: ditto.
-
-Sat Mar 6 00:39:21 2004 Kazuo Saito <ksaito@uranus.dti.ne.jp>
-
- * oniggnu.h: imported from Oniguruma library.
- * oniguruma.h: ditto.
- * regcomp.c: ditto.
- * regenc.c: ditto.
- * regenc.h: ditto.
- * regerror.c: ditto.
- * regex.c: ditto.
- * regexec.c: ditto.
- * reggnu.c: ditto.
- * regint.h: ditto.
- * regparse.c: ditto.
- * regparse.h: ditto.
- * ascii.c: ditto.
- * euc_jp.c: ditto.
- * sjis.c: ditto.
- * utf8.c: ditto.
-
- * MANIFEST: added Oniguruma files listed above.
-
- * LEGAL: added Oniguruma license.
-
- * regex.h: now includes oniggnu.h.
-
- * re.c: applied Oniguruma patch.
-
-Fri Mar 5 23:13:08 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: support WebDAV methods, PROPPATCH, LOCK,
- UNLOCK, OPTIONS, PROPFIND, DELETE, MOVE, COPY, MKCOL.
- This patch is contributed by Tatsuki Sugiura.
-
-Fri Mar 5 20:58:37 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb: Net::HTTPResponse#response is obsolete.
- [ruby-core:02592]
-
- * lib/net/http.rb: Net::HTTPResponse#header is obsolete.
-
- * lib/net/http.rb: Net::HTTPResponse#read_header is obsolete.
-
-Fri Mar 5 20:10:57 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/strscan/strscan.c: new method StringScanner#initialize_copy
- to allow #dup and #clone.
-
- * test/strscan/test_strscan.rb: test StringScanner#dup.
-
-Fri Mar 5 19:42:09 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb (HTTPResponse#to_ary): should return an object
- which does not respond to #to_ary. It causes infinite loop in
- puts. [ruby-core:02578]
-
-Fri Mar 5 00:51:35 2004 Dave Thomas <dave@pragprog.com>
-
- * lib/test/unit.rb: Move RDoc documentation so that you can
+ * lib/test/unit.rb: MOve RDoc documentation so that you can
now say 'ri Test::Unit'
-Thu Mar 4 22:31:40 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * Makefile.in: miniruby is not needed for cross compile.
-
- * configure.in (PREP): miniruby for native compile.
-
-Thu Mar 4 11:46:32 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/drb/extservm.rb (DRb::ExtServManager#invoke_service_command):
- detach server processes to get rid of zombies.
-
-Thu Mar 4 10:41:25 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ruby.h (T_MASK): save 1 bit in flags bits by shifting T_xxx
- values.
-
-Thu Mar 4 08:08:36 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/syck/rubyext.c: get rid of warnings.
-
- * lib/rss/taxonomy.rb: ditto.
-
- * lib/rdoc/ri/ri_formatter.rb: ditto.
-
- * test/ruby/test_assignment.rb: ditto.
-
-Thu Mar 4 01:17:28 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/rdoc/ri/ri_display.rb (DefaultDisplay::page): wait until the
- pager terminates.
-
-Wed Mar 3 13:10:56 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (method_hash): new method. [ruby-talk:93968]
-
- * eval.c (proc_eq): do not compare dyna_vars.
-
- * eval.c (proc_hash): new method.
-
- * eval.c (rb_yield_0): protect break/return from within orphan (or
- lambda) Proc object.
-
-Wed Mar 3 09:52:05 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/mkmf.rb ($topdir): use compile_dir only when not installed yet.
- [ruby-talk:94098]
-
-Wed Mar 3 01:18:52 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/converter.rb: handled Uconv::Error.
-
- * lib/rss/dublincore.rb: DublincoreModel -> DublinCoreModel
-
-Wed Mar 3 00:59:30 2004 David Black <dblack@wobblini.net>
-
- * lib/scanf.rb: soak_up_spaces only ungetc's non-space last
- character
-
- * lib/scanf.rb: IO#block_scanf now returns partial last iteration
- array if format string matches partly
-
-Tue Mar 2 16:30:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (pipe_open): erred program name should be reported by
- exceptions, instead of the first argument.
-
- * process.c (rb_spawn): ditto.
-
- * process.c (proc_spawn_v): use first argument as program name.
-
- * win32/win32.c (rb_w32_aspawn): ditto.
-
- * win32/win32.c (CreateChild): search executable file if no program
- name given.
-
- * lib/drb/extservm.rb (invoke_service_command): use Process.spawn.
- [ruby-dev:23103]
-
- * lib/rdoc/ri/ri_display.rb (setup_pager): use IO.popen.
- [ruby-dev:23086], [ruby-dev:23103]
-
- * lib/rdoc/diagram.rb (convert_to_png): ditto.
-
- * lib/rdoc/generators/chm_generator.rb (compile_project): ditto.
-
-Tue Mar 2 12:24:03 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Mar 2 12:32:59 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/Makefile.sub, wince/Makefile.sub (config.h): shouldn't check
defined? NORETURN. [ruby-dev:23100]
-Tue Mar 2 11:28:40 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/ruby/test_iterator.rb (test_ljump): cannot use
- assert_nothing_raised due to passing block.
-
-Tue Mar 2 06:23:14 2004 David Black <dblack@wobblini.net>
-
- * lib/scanf.rb: fixed Kernel#scanf to propagate code block
-
-Mon Mar 1 23:25:40 2004 David Black <dblack@wobblini.net>
-
- * lib/scanf.rb: Partial fix so STDIN#scanf works with new
- STDIN#pos behavior
-
-Mon Mar 1 19:42:05 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * bcc32/setup.mak: configure's default is "--enable-install-doc"
-
- * win32/setup.mak: ditto.
-
Mon Mar 1 12:24:10 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_alias):
@@ -18377,105 +15027,38 @@ Sun Feb 29 23:14:53 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_class):
Handle :nodoc: on singleton classes.
-Sat Feb 28 21:50:20 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * bcc32/Makefile.sub, bcc32/README.bcc32, bcc32/configure.bat,
- bcc32/setup.mak: new configure scheme. use ``configure --prefix=dir''
- instead of ``make DESTDIR=dir install''.
- --with-static-linked-ext support on bccwin32. [ruby-dev:23034]
-
-Sat Feb 28 21:50:20 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * bcc32/setup.mak: "configure --disable-install-doc" is now working.
-
- * win32/setup.mak: ditto.
-
-Sat Feb 28 15:09:49 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * bcc32/configure.bat: append missing label ":exit".
-
- * bcc32/configure.bat: fix typo.
-
-Sat Feb 28 10:31:03 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sat Feb 28 10:58:49 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* MANIFEST: add test_erb.rb
* lib/erb.rb, test/erb/test_erb.rb: don't forget filename,
if both filename and safe_level given. [ruby-dev:23050]
-Sat Feb 28 01:08:40 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (yylex): should not allow symbol for invalid global
- variable (e.g. `:$-)`). [ruby-core:02518]
-
-Fri Feb 27 20:37:09 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (proc_invoke): no orphan block check is needed when pcall
- is true.
-
- * eval.c (localjump_destination): update localjump condition.
-
-Fri Feb 27 02:10:49 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (localjump_destination): lambda should not interfere
- return from the yielded block.
-
-Fri Feb 27 00:53:49 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Fri Feb 27 01:00:09 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb, test/drb/drbtest.rb: require drb/eq.rb by default
-Thu Feb 26 12:15:02 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c (make_cmdvector): adjust successive double-quote
- handling.
-
-Thu Feb 26 09:42:56 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * hash.c (delete_if_i): use st_delete_safe() (via
- rb_hash_delete()) instead of returning ST_DELETE.
-
-Thu Feb 26 02:35:10 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (rb_f_exec): get rid of SEGV when exec failed for command
- in single string.
-
-Wed Feb 25 21:17:33 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * gc.c (obj_free), io.c (rb_io_fptr_finalize), rubyio.h (OpenFile):
- sharing OpenFile.
-
- * io.c (rb_io_initialize): accept IO instance. [ruby-dev:22195]
-
-Wed Feb 25 21:16:10 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Feb 25 21:16:25 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* instruby.rb (with_destdir): should return the given argument if no
DESTDIR is given.
* instruby.rb: use path name expansion of cmd.exe.
-Wed Feb 25 20:44:45 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Feb 25 09:35:22 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * lib/cgi-lib.rb, lib/getopts.rb, lib/importenv.rb, lib/parsearg.rb:
- warn with caller position.
+ * error.c (NameError::Message): new class for lazy evaluation of
+ message to ensure replaced before marshalling. merge from HEAD.
+ (ruby-bugs-ja:PR#588)
- * test/rss/test_content.rb, test/rss/test_dublincore.rb,
- test/rss/test_syndication.rb, test/rss/test_trackback.rb: use cgi
- instead of cgi-lib.
+ * eval.c (rb_method_missing): use NameError::Message. merge from
+ HEAD. (ruby-bugs-ja:PR#588)
-Tue Feb 24 18:42:03 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Tue Feb 24 18:59:37 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* dir.c (glob_helper): '**/' should not match leading period
unless File::FNM_DOTMATCH is set. (like '*/') [ruby-dev:23014]
-Tue Feb 24 18:03:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/ruby/test_file.rb (test_fnmatch): test for dir.c:1.108.
-
-Tue Feb 24 17:07:17 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (fnmatch): File.fnmatch with File::FNM_PATHNAME was broken
- for the pattern including '*' followed by '/'.
-
Tue Feb 24 13:22:21 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/rdoc.rb (RDoc::RDoc::normalized_file_list): Attempt to get better
@@ -18493,6 +15076,11 @@ Tue Feb 24 06:40:14 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RubyLex::identify_identifier): Handle
class variables in code listings
+Tue Feb 24 06:40:14 2004 Dave Thomas <dave@pragprog.com>
+
+ * lib/rdoc/parsers/parse_rb.rb (RubyLex::identify_identifier): Handle
+ class variables in code listings
+
Tue Feb 24 06:32:27 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::do_aliases): Handle
@@ -18521,164 +15109,88 @@ Tue Feb 24 03:45:06 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_config.c (Init_ossl_config): include Enumerable.
-Mon Feb 23 09:09:44 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * instruby.rb (parse_args): use optparse instead of getopts.
+Mon Feb 23 09:16:35 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* instruby.rb (DOSISH): embedded path in batch files should not be
prefixed by DESTDIR. [ruby-core:02186]
-Sun Feb 22 14:58:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb: $extstatic is Array or nil now. [ruby-talk:93383]
-
- * Makefile.in, bcc32/Makefile.sub, win32/Makefile.sub: terminate options.
-
- * lib/mkmf.rb (init_mkmf): $INCFLAGS also should be lazy-evaluated.
-
-Sun Feb 22 13:05:37 2004 akira yamada <akira@ruby-lang.org>
-
- * lib/uri/mailto.rb (URI::MailTo::to_s): should include fragment.
-
-Sun Feb 22 12:58:35 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb: use optparse instead of getopts.
+Sun Feb 22 09:54:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
- * Makefile.in, bcc32/Makefile.sub, win32/Makefile.sub: ditto.
+ * re.c: corrected documentation format (again)
-Sun Feb 22 09:51:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+Sun Feb 22 09:43:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
* re.c: corrected documentation format (rb_reg_initialize_m)
-Sat Feb 21 22:41:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+Sat Feb 21 22:36:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
* ext/zlib/zlib.c: documented, but needs more effort.
-Sat Feb 21 14:33:20 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb: prefer relative path. [ruby-talk:93037]
-
-Sat Feb 21 11:12:08 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat Feb 21 11:12:15 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* missing/os2.c, missing/x68.c: typo fix. pointed out by greentea.
-Fri Feb 20 19:11:20 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/ostruct.rb (OpenStruct#initialize_copy): should not share
- members. [ruby-dev:22966]
-
Fri Feb 20 18:59:47 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/irb/init.rb (IRB::IRB.parse_opts): add -I option to
irb. [ruby-dev:39243]
-Fri Feb 20 12:55:27 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * io.c (pipe_open): fix typo.
-
- * win32/win32.c (CreateChild): first argument to CreateProcess() must
- have path, not just basename.
-
Thu Feb 19 23:24:16 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/html_generator.rb (Generators::HtmlClass::build_attribute_list):
Support visibility modifiers for attributes
-Thu Feb 19 22:39:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+Thu Feb 19 23:24:16 2004 Dave Thomas <dave@pragprog.com>
- * lib/ostruct.rb: documented
+ * lib/rdoc/generators/html_generator.rb (Generators::HtmlClass::build_attribute_list):
+ Support visibility modifiers for attributes
Thu Feb 19 22:39:04 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/rinda/test_rinda.rb: DRb.start_service only once in testsuites.
DRb.start_service could handle this.
-Thu Feb 19 22:24:04 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+Thu Feb 19 22:19:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
- * lib/soap/mapping/rubytypeFactory.rb: should not dump singleton class.
- [ruby-dev:22588]
- c = class << Object.new; class C; self; end; end; SOAPMarshal.dump(c)
+ * lib/ostruct.rb: documented
-Thu Feb 19 18:08:18 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+Thu Feb 19 21:28:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
* ext/strscan/strscan.c: improved documentation
-Thu Feb 19 18:08:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * win32/win32.c, win32/win32.h: fixed prototypes.
-
- * win32/win32.c (wait): same as waitpid() with -1.
-
-Thu Feb 19 02:34:28 2004 Dave Thomas <dave@pragprog.com>
-
- * lib/rdoc/markup/simple_markup/preprocess.rb (SM::PreProcess::include_file):
- Only strip comment markers if all lines start with comments.
-
-Thu Feb 19 03:05:49 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/strscan/strscan.c: StringScanner#restsize is obsolete;
- use #rest_size instead.
-
- * ext/strscan/strscan.c: StringScanner#matchedsize is obsolete;
- use #matched_size instead.
+Thu Feb 19 03:10:52 2004 Minero Aoki <aamine@loveruby.net>
-Thu Feb 19 02:42:19 2004 Minero Aoki <aamine@loveruby.net>
+ * ext/strscan/strscan.c: synchronized with main trunk (rev 1.11).
- * ext/strscan/strscan.c: don't use rb_eval_string, it defines
- classes under the module when required in module clauses.
- [ruby-dev:22951]
+Thu Feb 19 02:30:34 2004 Minero Aoki <aamine@loveruby.net>
-Thu Feb 19 02:37:28 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/strscan/strscan.c: merge documentation from 1.8 branch.
- Thanks Gavin Sinclair.
-
-Thu Feb 19 00:20:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
-
- * lib/cgi-lib.rb: deprecated after 1.8.1
-
- * lib/getopts.rb: ditto
-
- * lib/importenv.rb: ditto
-
- * lib/parsearg.rb: ditto
+ * ext/strscan/strscan.c: documentation checked.
Thu Feb 19 00:11:05 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/markup/simple_markup/preprocess.rb (SM::PreProcess::handle):
Strip extraneous space from filenames in :include:
-Wed Feb 18 22:53:41 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Wed Feb 18 22:52:00 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * lib/drb/unix.rb: remove O_NONBLOCk, thanks \ay
+ * lib/drb/unix.rb: remove O_NONBLOCK, thanks \ay
-Wed Feb 18 22:42:19 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Wed Feb 18 22:47:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
- * test/rinda/test_rinda.rb: improt test_rinda.rb
+ * ext/strscan/strscan.c: documented
Wed Feb 18 22:03:11 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/*: should not depend on $KCODE.
-Wed Feb 18 18:07:09 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * test/ruby/test_sprintf.rb: added tests.
-
Wed Feb 18 17:18:01 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* ext/win32ole/win32ole.c: need to include <olectl.h> on Cygwin.
Wed Feb 18 10:40:38 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * sprintf.c (rb_f_sprintf): sign bit extension should not be done
- if FPLUS flag is specified. [ruby-list:39224]
-
* sprintf.c (rb_f_sprintf): do not prepend dots for negative
- numbers if FZERO is specified. [ruby-dev:39218]
-
-Wed Feb 18 10:23:34 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * sprintf.c (rb_f_sprintf): clean up.
+ numbers if FZERO is specified. [ruby-list:39218]
Tue Feb 17 23:40:34 2004 Guy Decoux <ts@moulon.inra.fr>
@@ -18687,11 +15199,6 @@ Tue Feb 17 23:40:34 2004 Guy Decoux <ts@moulon.inra.fr>
Tue Feb 17 23:28:45 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
- * test/soap/marshal/test_marshal.rb, test/ruby/test_marshal.rb: do $:
- trick to share the testcase test/ruby/marshaltestlib.rb.
-
-Tue Feb 17 23:13:23 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
* test/ruby/marshaltestlib.rb: common marshal testcase added.
* test/ruby/test_marshal.rb: use above testsuite.
@@ -18700,282 +15207,108 @@ Tue Feb 17 23:13:23 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/soap/marshal/cmarshal.rb: removed (not used).
-Tue Feb 17 19:34:26 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb (extmake): $extout_prefix doesn't vary for libraries.
-
- * ext/extmk.rb (extmake): remove compile directory if empty.
-
- * ext/extmk.rb (parse_args) lib/mkmf.rb (create_makefile): move
- initialization of $extout_prefix from lib/mkmf.rb. [ruby-dev:22928]
-
- * ext/extmk.rb: clear ext and extout directory when cleaning.
-
- * lib/mkmf.rb (CLEANLIBS): should be under $(arch) directory.
-
-Tue Feb 17 18:02:10 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/strscan/strscan.c: ScanError may be (wrongly) garbage
- collected. (thanks Gavin Sinclair)
-
- * ext/strscan/strscan.c: move ::ScanError to StringScanner::Error.
- ::ScanError is also defined for backward compatibility.
-
- * ext/strscan/strscan.c: #peep is obsolete, use #peek.
-
- * ext/strscan/strscan.c: #empty? is obsolete, use #eos?.
+Tue Feb 17 10:51:23 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * ext/strscan/strscan.c: #clear is obsolete, use #terminate.
-
- * ext/strscan/strscan.c: #getbyte is obsolete, use #get_byte.
+ * ext/syck/rubyext.c (syck_emitter_end_object): takes only one arg.
-Tue Feb 17 12:12:47 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Feb 17 01:35:28 2004 Tanaka Akira <akr@m17n.org>
- * ext/extmk.rb (parse_args): delay expanding $(extout) until invoking
- make.
+ * eval.c (rb_eval): care that another thread replace NODE_DREGX_ONCE
+ to NODE_LIT. [ruby-dev:22920]
- * lib/mkmf.rb (CLEANLIBS): should remove files have specific
- extensions.
+Tue Feb 17 01:24:35 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-Tue Feb 17 11:33:30 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * bcc32/Makefile.sub, win32/Makefile.sub (config.h): define
+ STACK_GROW_DIRECTION. [ruby-dev:22910]
- * lib/rss/rexmlparser.rb: REXML version may be 4 digits.
+ * bcc32/Makefile.sub (config.h): add newer checks.
-Tue Feb 17 10:45:59 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+ * wince/Makefile.sub (config.h): define NEED_IO_SEEK_BETWEEN_RW.
- * ext/syck/rubyext.c (syck_emitter_end_object): takes only one arg.
+Tue Feb 17 00:38:10 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-Tue Feb 17 07:48:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * lib/rinda/tuplespace.rb: TupleSpace#initialize, stop doubling timeout
- * lib/rexml/encodings/SHIFT_JIS: wrong library name.
+Tue Feb 17 00:18:03 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-Tue Feb 17 01:35:28 2004 Tanaka Akira <akr@m17n.org>
+ * test/rinda/test_rinda.rb: import test_rinda.rb
- * eval.c (rb_eval): care that another thread replace NODE_DREGX_ONCE
- to NODE_LIT. [ruby-dev:22920]
+Tue Feb 17 00:14:30 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-Tue Feb 17 01:20:57 2004 Minero Aoki <aamine@loveruby.net>
+ * bcc32/Makefile.sub: avoid warning "Redefinition of macro
+ 'HAVE_GETLOGIN'".
- * lib/fileutils.rb: new module FileUtils::DryRun.
+ * vms/config.h_in: ditto.
Mon Feb 16 23:28:14 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/csv.rb: document reduction. [ruby-core:02429]
- * test/yaml/test_yaml.rb: added 0..1 test with "0".."1" on display.
- it should be defined that the specification about what kind of Range
- is supported in ruby's custom type in YAML.
-
-Mon Feb 16 22:22:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+Mon Feb 16 22:08:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
* lib/generator.rb: corrected doc format
-
* lib/rinda/rinda.rb: added documentation (from Hugh Sasse)
-
* lib/rinda/tuplespace.rb: ditto
- [Note: rinda files actually committed Wed Feb 18 07:27:00 2004]
-
-Mon Feb 16 20:28:52 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Feb 16 20:41:32 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* bcc32/Makefile.sub: show more warnings. (refering to mingw)
* bcc32/setup.mak: ditto.
-Mon Feb 16 18:35:58 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/Makefile.sub (config.status): should create *.pdb on ext/,
- not .ext/.
-
- * win32/Makefile.sub (config.status): convert the name of import
- library.
-
- * lib/mkmf.rb (create_makefile): now don't need to remove
- $(TARGET).lib.
-
-Mon Feb 16 15:45:22 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in: check functions, fork spawnv.
-
- * io.c (rb_io_s_popen): accept argv not only single command line.
+Mon Feb 16 13:39:44 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
- * process.c (rb_proc_exec_n): export.
+ * dir.c (rb_glob, rb_globi): add const.
- * process.c (rb_check_argv): check if arguments are safe to invoke.
+ * ruby.h: ditto.
- * process.c (rb_fork): retry to fork.
-
- * process.c (rb_spawn): spawn child process asynchronously.
-
- * process.c (rb_f_system): raise an exception if the command could not
- execute.
-
- * win32/win32.c (rb_w32_argv_size): count necessary size for joined
- arguments.
-
- * win32/win32.c (rb_w32_join_argv): join arguments with quoting.
-
- * win32/win32.c (rb_w32_pipe_exec, rb_w32_spawn, rb_w32_aspawn):
- accept program name adding to command line.
-
-Mon Feb 16 15:18:33 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/racc/parser.rb: add note for Racc full package.
-
-Mon Feb 16 15:13:01 2004 Minero Aoki <aamine@loveruby.net>
-
- * ext/racc/cparse/README: new file.
-
- * ext/racc/cparse/MANIFEST: add README.
-
-Mon Feb 16 12:29:10 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/iconv.c (iconv_s_list): new method Iconv.list
- (libiconv only).
-
-Mon Feb 16 10:29:52 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (CompareImpl): File.fnmatch and Dir.glob get better performance
- in Win32. This is achived by calling downcase() for single-byte
- characters. (CharLower() is slower than downcase())
-
-Mon Feb 16 02:14:29 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Feb 16 02:16:33 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* bcc32/Makefile.sub: should warn suspicious pointer conversion.
* bcc32/setup.mak: ditto.
-Sun Feb 15 20:56:22 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (push_braces): remove wrong const. [ruby-dev:22891]
-
-Sun Feb 15 20:41:15 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * sample/soap/calc/httpd.rb, sample/soap/exchange/httpd.rb,
- sample/soap/sampleStruct/httpd.rb, sample/wsdl/googleSearch/httpd.rb:
- use soap/property instead of getopts for configuring DocumentRoot
- and port# of httpd. see samplehttpd.conf below.
+Sun Feb 15 19:06:42 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
- * sample/soap/calc/samplehttpd.conf,
- sample/soap/exchange/samplehttpd.conf,
- sample/soap/sampleStruct/samplehttpd.conf,
- sample/wsdl/googleSearch/samplehttpd.conf: added.
+ * lib/rinda/tuplespace.rb: TupleSpace#read(tpl, 0), raise
+ RequestExpiredError if not found.
-Sun Feb 15 19:13:33 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
-
- * lib/rinda/tuplespace.rb: read(tpl,0), raise RequestExpiredError
- if not found.
-
-Sun Feb 15 15:48:57 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
+Sun Feb 15 15:56:46 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c: add IDispatch wrapper in val2variant.
Thanks, arton.
-Sun Feb 15 15:23:29 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * ruby.h, dir.c (rb_glob): add const.
-
Sun Feb 15 01:46:05 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/mkmf.rb: absolute path of ruby is assigned to $(RUBY).
[ruby-dev:22870]
-Sat Feb 14 23:59:11 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * mkconfig.rb: use fileutils.rb instead of ftools.rb.
-
- * bcc32/Makefile.sub, win32/Makefile.sub (config.h): define
- STACK_GROW_DIRECTION.
-
- * bcc32/Makefile.sub (config.h): add newer checks.
-
- * wince/Makefile.sub (config.h): define NEED_IO_SEEK_BETWEEN_RW.
-
-Sat Feb 14 23:26:27 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * lib/un.rb: use OptionParser instead of getopts.
-
-Sat Feb 14 11:28:14 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sat Feb 14 11:29:41 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* sample/drb/*: import lib/drb/sample
-Sat Feb 14 11:14:12 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Sat Feb 14 11:08:23 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb: add pretty_print, thanks gotoken.
-Fri Feb 13 21:51:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
-
- * lib/fileutils.rb: slighly improved documentation (sync with 1.8)
-
-Fri Feb 13 19:57:01 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * test/rss/test_trackback.rb: added tests for TrackBack with RSS
- 2.0.
-
- * test/rss/common.rb: added methods make RSS 2.0.
+Fri Feb 13 12:35:08 2004 Minero Aoki <aamine@loveruby.net>
- * lib/rss/trackback.rb: TrackBack API is decided.
+ * test/fileutils/test_fileutils.rb: File.link may raise EINVAL and
+ EACCES on Windows.
- * lib/rss/rss.rb: RSS::VERSION 0.0.7 -> 0.0.8.
-
- * lib/rss/parser.rb, lib/rss/rss.rb: replaced $DEBUG by RSS::DEBUG.
-
- * lib/rss/2.0.rb: removed RSS 2.0 URI. Because RSS 2.0 doesn't
- have URI.
-
-Fri Feb 13 14:41:00 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk.rb: en-bugged at last commit (Feb 11 23:24:22 2004)
-
-Fri Feb 13 12:26:37 2004 Minero Aoki <aamine@loveruby.net>
-
- * test/fileutils/test_fileutils.rb: rescue SystemCallError instead
- of EINVAL. File.link may raise EACCES on network file systems.
-
-Fri Feb 13 05:18:58 2004 Minero Aoki <aamine@loveruby.net>
-
- * test/fileutils/test_fileutils.rb: File.link raises EINVAL on
- Win9x. [ruby-dev:22713]
-
-Thu Feb 12 21:49:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+Thu Feb 12 21:45:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
* lib/ftools.rb: documented
-Thu Feb 12 21:19:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+Thu Feb 12 21:25:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
- * lib/base64.rb: added and tidied documentation
+ * lib/base64.rb: backported from HEAD (modularised and documented)
-Thu Feb 12 20:45:01 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/protocol.rb (WriteAdapater#puts): must append "\n" to
- the string, don't prepend. (ruby-bugs:PR#1280)
-
-Thu Feb 12 20:31:43 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Feb 12 20:31:48 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (create_tmpsrc): cpp32 of Borland C++ ignores #error
directives in DOS line-ending files at all.
-Thu Feb 12 15:23:20 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (rparen): ignore preceding newlines to right parentheses.
- (ruby-bugs:PR#1221) [ruby-dev:22858]
-
-Thu Feb 12 14:17:43 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * configure.in: set ac_cv_func_link to yes to enable link() on MinGW.
- [ruby-dev:22241]
-
-Thu Feb 12 13:32:49 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/win32.c (link): raise NotImplementedError on Win9X.
- contributed by Tietew. [ruby-dev:22713]
-
- * win32/win32.c, win32/win32.h (link): add const.
-
-Thu Feb 12 09:56:19 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/tk/lib/tk.rb (TkComm::tk_split_list): suppress a warning.
-
Thu Feb 12 02:23:56 2004 Tanaka Akira <akr@m17n.org>
* lib/pathname.rb: use assert_raise instead of assert_raises.
@@ -18987,91 +15320,26 @@ Thu Feb 12 02:23:56 2004 Tanaka Akira <akr@m17n.org>
* lib/tsort.rb: ditto.
use TSortHash and TSortArray instead of Hash and Array in test.
-Wed Feb 11 23:24:22 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk.rb: properly treat a Tcl/Tk's string with escaping
- special characters.
-
-Tue Feb 10 20:49:07 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (method_proc): return bound Proc object. [ruby-dev:22854]
-
- * eval.c (rb_mod_define_method): bind method body itself for Method
- object.
-
- * node.h (NODE_DMETHOD): deprecated.
-
- * object.c (rb_class_inherited_p): export.
-
-Tue Feb 10 16:43:50 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (umethod_bind): purge unused check. [ruby-dev:22850]
-
-Tue Feb 10 14:33:08 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * string.c (rb_str_match): raise TypeError when both arguments are
- strings. [ruby-dev:22851]
-
- * string.c (rb_str_match2): removed.
-
- * Makefile.in, bcc32/Makefile.sub, win32/Makefile.sub,
- wince/Makefile.sub (string.c): now not depend on version.h.
-
-Mon Feb 9 17:46:07 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * Makefile.in, bcc32/Makefile.sub, win32/Makefile.sub, configure.in,
- runruby.rb: run rdoc, test and so on with compiled extension
- libraries. [ruby-dev:22688]
-
- * ext/extmk.rb, lib/mkmf.rb: make extension libraries in separated
- directory, similar to the actual directory structure.
-
- * lib/fileutils.rb (FileUtils.copy_file): use the mode of the original
- file to create new file.
-
- * lib/rdoc/ri/ri_paths.rb (RI::Paths::SYSDIR): get rid of unexpected
- influence by envirionment variable.
-
- * bcc32/configure.bat, win32/configure.bat: add install-doc options.
-
- * win32/win32.c, win32/win32.h (rb_w32_fstat): fix Borland C runtime
- bug which returns wrong mode. [ruby-dev:22846]
-
-Mon Feb 9 16:30:12 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * process.c (detach_process_watcher): return the last status.
- [ruby-dev:22841]
-
-Sun Feb 8 16:46:08 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/pp.rb (PP::PPMethods::object_address_group): suppress negative
- sign for higher heap areas.
-
-Sun Feb 8 16:18:27 2004 akira yamada <akira@ruby-lang.org>
-
- * test/yaml/test_yaml.rb (YAML_Unit_Tests::test_range_cycle):
- added tests.
-
-Sun Feb 8 15:51:57 2004 akira yamada <akira@ruby-lang.org>
+Wed Feb 11 20:01:12 2004 akira yamada <akira@ruby-lang.org>
* test/ruby/test_file.rb (TestFile::test_fnmatch): added tests for
File.fnmatch. [ruby-dev:22815][ruby-dev:22819]
-Sun Feb 8 15:41:45 2004 akira yamada <akira@ruby-lang.org>
+ * test/ruby/test_proc.rb (TestProc::test_eq): added a
+ test. [ruby-dev:22599]
- * test/yaml/test_yaml.rb (YAML_Unit_Tests::test_range_cycle):
- added tests. [ruby-core:02306] [ruby-core:02311]
+ * test/ruby/test_proc.rb (TestProc::test_eq): added tests for
+ Proc#==. [ruby-dev:22592], [ruby-dev:22601]
-Sun Feb 8 14:24:35 2004 Minero Aoki <aamine@loveruby.net>
+Tue Feb 10 16:43:56 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/net/http.rb (HTTP#request): should not overwrite Connection
- header. (ruby-bugs:PR#1274)
+ * eval.c (umethod_bind): purge unused check. [ruby-dev:22850]
-Sun Feb 8 10:11:21 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Feb 9 17:16:00 2004 WATANABE Hirofumi <eban@ruby-lang.org>
- * dir.c (glob_helper): Dir.glob('**/') did not work. [ruby-dev:22832]
+ * lib/rdoc/parsers/parse_c.rb: escape '{' and '}' to avoid warnings.
-Sun Feb 8 00:29:26 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
+Mon Feb 9 13:00:55 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* dir.c (fnmatch): File.fnmatch('*?', 'a') should return true.
[ruby-dev:22815]
@@ -19079,14 +15347,10 @@ Sun Feb 8 00:29:26 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* dir.c (fnmatch): File.fnmatch('\[1\]' , '[1]') should return true.
[ruby-dev:22819]
- * dir.c: Did some styles (no change to behavior)
-
-Sat Feb 7 19:56:11 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/irb/init.rb (IRB.rc_files): yield possible rc file names.
+Sun Feb 8 16:46:13 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * lib/irb/input-method.rb (IRB::ReadlineInputMethod::initialize):
- load and save history automatically. [ruby-core:02352]
+ * lib/pp.rb (PP::PPMethods::object_address_group): suppress negative
+ sign for higher heap areas.
Fri Feb 6 22:48:16 2004 Dave Thomas <dave@pragprog.com>
@@ -19103,27 +15367,6 @@ Fri Feb 6 22:22:50 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/pp.rb (PPInspectTest#test_to_s_with_iv): remove instance
variable which is defined in the test.
-Fri Feb 6 18:54:18 2004 akira yamada <akira@ruby-lang.org>
-
- * test/ruby/test_proc.rb (TestProc::test_eq): added a
- test. [ruby-dev:22599]
-
-Fri Feb 6 18:26:00 2004 akira yamada <akira@ruby-lang.org>
-
- * test/ruby/test_proc.rb (TestProc::test_eq): added tests for
- Proc#==. [ruby-dev:22592], [ruby-dev:22601]
-
-Fri Feb 6 10:12:06 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/socket/socket.c (bsock_do_not_reverse_lookup): control reverse
- lookup for every instance. [ruby-core:02346]
-
-Fri Feb 6 09:15:11 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/irb/extend-command.rb: add irb_help command. [ruby-talk:91610]
-
- * lib/irb/cmd/help.rb (IRB::ExtendCommand::Help): show RDoc.
-
Fri Feb 6 00:48:37 2004 Tanaka Akira <akr@m17n.org>
* lib/prettyprint.rb (PrettyPrint#first?): obsoleted.
@@ -19140,10 +15383,6 @@ Thu Feb 5 23:56:55 2004 Tanaka Akira <akr@m17n.org>
* lib/set.rb (Set#pretty_print): use seplist.
-Wed Feb 4 22:39:46 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * file.c (rb_stat_mode): should not sign-expand, so backout.
-
Wed Feb 4 02:12:06 2004 Tanaka Akira <akr@m17n.org>
* file.c (test_l): fix wrong method name in document.
@@ -19154,37 +15393,19 @@ Wed Feb 4 02:12:06 2004 Tanaka Akira <akr@m17n.org>
(test_sgid): ditto.
(test_sticky): ditto.
-Tue Feb 3 22:36:25 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/2.0.rb, lib/rss/content.rb, lib/rss/dublincore.rb,
- lib/rss/rss.rb, lib/rss/syndication.rb: removed warnings.
-
- * lib/rss/converter.rb: removed handling load error of nkf.
-
- * test/rss/test_syndication.rb, test/rss/test_trackback.rb,
- test/rss/test_dublincore.rb, test/rss/test_content.rb: replaced
- 'require "rss/parser"' by 'require "rss/1.0"'.
-
- * test/rss/test_parser.rb, test/rss/test_accessor.rb: removed
- 'require "rss/parser"'.
-
-Tue Feb 3 11:23:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * parse.y (reduce_nodes): remove tail returns. [ruby-talk:90934]
-
Tue Feb 3 08:04:57 2004 Tanaka Akira <akr@m17n.org>
* lib/pp.rb (Struct#pretty_print_cycle): follow 1.8 style.
-Mon Feb 2 22:06:31 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Feb 2 19:33:49 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+
+ * configure.in: backport from 1.9 for Interix.
- * parse.y (block_append, new_evstr, void_expr0): remove no longer used
- labels.
+ * dln.c (dln_load): ditto.
-Mon Feb 2 18:45:50 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+Mon Feb 2 13:31:51 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * dln.c (dln_load): don't specify RTLD_GLOBAL on Interix,
- because it caused SEGV when running runner.rb.
+ * lib/net/http.rb (canonical_each): fix merge miss.
Mon Feb 2 01:54:00 2004 Tanaka Akira <akr@m17n.org>
@@ -19206,14 +15427,12 @@ Mon Feb 2 01:54:00 2004 Tanaka Akira <akr@m17n.org>
(UDPSocket#send): recognize 3 arguments form. try all addresses on
4 arguments form.
-Sun Feb 1 23:00:00 2004 Shigeo Kobayashi <shigek@ruby-lang.org>
+Sun Feb 1 18:17:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
- * ext/bigdecimal.c: Bug in BigDecimal("1e#{n}").add BigDecimal('.5'),n)
- reported and fixed by Javier Goizueta.
+ * lib/net/http.rb: merged coding style changes from HEAD.
-Sun Feb 1 18:21:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
+Sun Feb 1 16:15:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
- From ruby_1_8 branch:
* lib/test/unit.rb: rearranged documentation for RDoc's sake.
* lib/matrix.rb: improved documentation.
* lib/net/http.rb: slight documentation formatting improvement.
@@ -19224,32 +15443,27 @@ Sun Feb 1 05:30:06 2004 Tanaka Akira <akr@m17n.org>
raise an errror on non-http proxy URI.
(OpenURI::Buffer#<<): make a tempfile binmode. [ruby-talk:90793]
-Sun Feb 1 00:57:41 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss/parser.rb (RSS::Parser): added @@default_parser. Used
- XML parser became selectable.
- * test/rss/test_parser.rb: added tests for
- RSS::Parser.default_parser.
+Sat Jan 31 09:20:32 2004 NAKAMURA, Hiroshi <nakahiro@sairon.co.jp>
-Sat Jan 31 02:28:15 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+ * sample/openssl/gen_csr.rb: wrong usage string.
- * configure.in (RPATHFLAG): set to -Wl,-R like NetBSD on Interix.
+Sat Jan 31 01:00:32 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-Sat Jan 31 01:09:41 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * lib/logger.rb: leading 0 padding of timestamp usec part.
+ * lib/soap/wsdlDriver.rb, lib/wsdl/soap/operation.rb: add support of
+ "parts" attribute of soap:body element in WSDL.
-Fri Jan 30 18:53:23 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/wsdl/xmlSchema/schema.rb: friendly warning message for
+ simpleType element which is not supported for now.
- * re.c (KR_REHASH): wrong hash value on sizeof(long) > sizeof(int).
+ * lib/soap/mapping/factory.rb: deleted unused methods.
-Thu Jan 29 23:11:57 2004 WATANABE Hirofumi <eban@ruby-lang.org>
+ * lib/soap/mapping/rubytypeFactory.rb: do no ignore case while xsi:type
+ string <-> Ruby class name matching.
- * configure.in (DLEXT2): removed. Ruby does not treat
- ".dll" as a extention library anymore.
+ * test/wsdl/soap/{soapbodyparts.wsdl,test_soapbodyparts.wsdl}: new
+ files.
- * bcc32/Makefile.sub, win32/Makefile.sub, wince/Makefile.sub (DLEXT2):
- ditto.
+Thu Jan 29 23:56:00 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* util.c (mblen): fix overrun. [ruby-dev:22672]
@@ -19258,83 +15472,36 @@ Thu Jan 29 22:41:53 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/html_generator.rb: Allow 'link:' in Tidylinks.
THis means you can write "see f1[link:files/f1_rb.html]".
-Thu Jan 29 22:24:47 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * sample/openssl/gen_csr.rb: follow OpenSSL::X509::Name change.
- ASN.1 type of subject DN elements were wrong.
+Thu Jan 29 15:33:23 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-Thu Jan 29 22:19:51 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * test/*: remove $: trick. [ruby-dev:22763] use test/runner.rb to
- run test.
-
-Thu Jan 29 19:28:16 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb (Request#initialize): reject only when a path is
- empty. [ruby-dev:22771]
-
-Thu Jan 29 18:54:08 2004 H.Yamamoto <ocean@m2.ccsnet.ne.jp>
-
- * dir.c (glob_helper): infinite loop bug in win32 code.
- [ruby-dev:22770]
-
-Thu Jan 29 17:03:49 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * dir.c: merge tuning from H.Yamamoto <ocean@m2.ccsnet.ne.jp>.
- [ruby-dev:22761]
-
-Thu Jan 29 11:32:14 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * test/rss/test_*: do $: trick while searching a module in the current
- directory.
-
- * test/xsd/test_xmlschemaparser.rb, test/wsdl/test_emptycomplextype.rb,
- test/soap/helloworld/test_helloworld.rb,
- test/soap/calc/{test_calc.rb,test_calc2.rb}: do File.expand_path
- before using __FILE__.
-
- * test/yaml/test_yaml.rb: assert_equals -> assert_equal.
-
-Thu Jan 29 01:56:02 2004 why the lucky stiff <why@ruby-lang.org>
-
- * ext/syck/rubyext.c: usec round-tripping skew. [ruby-core:2305]
-
- * lib/yaml/rubytypes.rb: character Range now round-trips. [ruby-core:2306]
-
- * test/yaml/test_yaml.rb: add Time and Range tests.
-
-Thu Jan 29 00:00:46 2004 Kouhei Sutou <kou@cozmixng.org>
-
- * lib/rss: rss/parser.rb is always required.
-
-Wed Jan 28 15:09:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/openssl/ossl_x509hame.c (ossl_x509name_initialize): change
+ second argument. it expected to be a Hash not an Integer.
- * test/rss/*.rb: remove "test/" prefix.
+ * ext/openssl/ossl_x509name.c (ossl_x509name_add_entry): add new
+ function for OpenSSL::X509::Name#add_entry.
-Wed Jan 28 13:07:02 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * ext/openssl/ossl_x509name.c (ossl_x509name_to_a): append ASN.1
+ tag number to each element of return value.
- * ext/iconv/extconf.rb: include iconv.h for libiconv. [ruby-dev:22715]
+ * ext/openssl/ossl_x509name.c (Init_ossl_x509name): add constants
+ OpenSSL::X509::Name::DEFAULT_OBJECT_TYPE and OBJECT_TYPE_TEMPLATE.
-Wed Jan 28 12:43:07 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * ext/openssl/lib/openssl/x509.rb (OpenSSL::X509::Name#initialize):
+ second argument takes OBJECT_TYPE_TEMPLATE by default.
- * lib/rss: rss library imported. [ruby-dev:22726]
+ * sample/openssl/gen_csr.rb: use OpenSSL::X509::Name.parse.
Wed Jan 28 04:29:41 2004 Eric Schwartz <emschwar@fc.hp.com>
* lib/cgi/session.rb: use LOCK_SH to read, and a few other
improvements. [ruby-core:02328]
-Tue Jan 27 15:00:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * misc/ruby-mode.el: better support for general delimited
- strings. [ruby-dev:22695]
-
-Tue Jan 27 11:04:40 2004 FUKUMOTO Atsushi <fukumoto@nospam.imasy.or.jp>
+Tue Jan 27 11:09:29 2004 FUKUMOTO Atsushi <fukumoto@nospam.imasy.or.jp>
* ext/socket/socket.c (s_recvfrom): sending length should be an
invariant while retrying on EAGAIN. [ruby-talk:89962]
-Tue Jan 27 10:31:28 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Tue Jan 27 10:35:18 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/win32ole/win32ole.c (set_argv): fix condition.
@@ -19343,14 +15510,19 @@ Tue Jan 27 02:26:31 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httputils.rb (WEBrick:HTTPUtils::parse_header):
refine regex for header-name.
+Tue Jan 27 00:30:11 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/Makefile.sub: rollback.
+
Mon Jan 26 22:53:04 2004 Dave Thomas <dave@pragprog.com>
* io.c: Remove documentation references to $defout.
-Mon Jan 26 14:41:46 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+Mon Jan 26 15:11:47 2004 NAKAMURA Usaku <usa@ruby-lang.org>
- * lib/weakref.rb (WeakRef::initialize): set up @__id before
- calling "super".
+ * sample/exyacc.rb: escape '}' to avoid warning.
+
+Mon Jan 26 14:41:46 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/delegate.rb (Delegator::initialize): preserve
singleton_method_added method [ruby-dev:22685]
@@ -19358,11 +15530,11 @@ Mon Jan 26 14:41:46 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/delegate.rb (Delegator::initialize): use Kernel::raise
instead of mere raise. [ruby-dev:22681]
-Mon Jan 26 12:45:23 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+Mon Jan 26 12:47:17 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c: define CONST84 when TCL_MAJOR_VERSION == 7
-Mon Jan 26 11:30:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Jan 26 11:35:23 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb: Makefiles should depend on also rbconfig.rb.
(ruby-bugs:PR#1256)
@@ -19370,112 +15542,18 @@ Mon Jan 26 11:30:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/win32ole/win32ole.c (set_argv): set real arguments to
WIN32OLE::ARGV. [ruby-list:39073]
-Sun Jan 25 18:25:26 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_x509name.c (ossl_x509name_add_entry): third
- argument become optional.
-
- * ext/openssl/ossl_x509name.c (ossl_x509name_initialize): ditto.
-
- * ext/openssl/ossl_x509name.c (Init_x509name): emailAddress and
- domainComponent should be IA5String.
-
-Sun Jan 25 01:45:38 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): support
- virtual host.
-
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#virtual_host): add
- new method to register virtual hosting server.
-
- * lib/webrick/httpserver.rb (WEBrick::HTTPServer#lookup_server): add
- new method to lookup virtual hosting server.
-
-Sat Jan 24 13:06:26 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
- * ext/openssl/ossl_x509hame.c (ossl_x509name_initialize): change
- second argument. it expected to be a Hash not an Integer.
-
- * ext/openssl/ossl_x509name.c (ossl_x509name_add_entry): add new
- function for OpenSSL::X509::Name#add_entry.
-
- * ext/openssl/ossl_x509name.c (Init_ossl_x509name): add constants
- OpenSSL::X509::Name::DEFAULT_OBJECT_TYPE and OBJECT_TYPE_TEMPLATE.
-
- * ext/openssl/lib/openssl/x509.rb (OpenSSL::X509::Name#initialize):
- second argument takes OBJECT_TYPE_TEMPLATE by default.
-
-Fri Jan 23 02:26:30 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * pack.c (num2i32): pack should not raise RangeError.
- [ruby-dev:22654]
-
- * pack.c (pack_pack): do not auto convert nil to zero.
-
Thu Jan 22 22:54:53 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (BEG_REGEXP): allow 8-bit characters in quoted
strings for Novell GroupWise Internet Agent.
-
* lib/net/imap.rb (DATA_REGEXP): ditto.
-Thu Jan 22 18:35:49 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * lib/e2mmap.rb (VERSION): remove unnecessary version checking.
-
-Thu Jan 22 16:21:02 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Jan 22 16:21:33 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (string_content): reset lexical states at the beginning of
string contents. [ruby-list:39061]
-Thu Jan 22 08:08:50 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (opt_rescue): use NODE_ERRINFO() instead of
- NODE_GVAR("$!"), to avoid confusion from variable aliasing.
- [ruby-talk:90074]
-
- * version.c (Init_version): remove obsolete constants VERSION
- etc. [ruby-dev:22643]
-
-Thu Jan 22 01:46:32 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (newline_node): do not use NODE_NEWLINE node anymore,
- use NEWLINE flag instead.
-
-Thu Jan 22 01:12:12 2004 Siena. <siena@faculty.chiba-u.jp>
-
- * missing/os2.c (chdir, getcwd):
- use _chdir2 and _getcwd2 supporting multiple drives in OS/2 with EMX.
-
-Thu Jan 22 00:33:52 2004 Siena. <siena@faculty.chiba-u.jp>
-
- * configure.in: check availability of link(). [ruby-dev:22237]
- * file.c (rb_file_s_link): raise an exception when link() is unavailable.
- * missing/os2.c (link): removed. File#link isn't supported.
- * bcc32/Makefile.sub: define HAVE_LINK to enable link(). [ruby-dev:22241]
- * win32/Makefile.sub: ditto.
-
-Thu Jan 22 00:26:25 2004 Siena. <siena@faculty.chiba-u.jp>
-
- * ChangeLog: typo: RUBY_MBCHAR_MAX was RUBY_MBCHAR_MAXSIZE.
-
-Thu Jan 22 00:12:51 2004 Siena. <siena@faculty.chiba-u.jp>
-
- * defines.h: define RUBY_MBCHAR_MAX instead of MB_CUR_MAX.
- * dir.c (Next, emx_mblen): use RUBY_MBCHAR_MAX for mblen().
- * file.c (CharNext): ditto.
- * ruby.c (translate_char): ditto.
- * util.c (__crt0_glob_function): ditto.
-
-Thu Jan 22 00:10:01 2004 Dave Thomas <dave@pragprog.com>
-
- * lib/base64.rb: :nodoc: the Deprecated module
-
-Wed Jan 21 23:52:39 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * configure.in: Interix(SFU) support.
-
-Wed Jan 21 23:03:45 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+Wed Jan 21 21:55:51 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb: remove O_NONBLOCK, thanks \ay
* lib/drb/extserv.rb: typo
@@ -19488,28 +15566,21 @@ Wed Jan 21 17:57:56 2004 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (ensure_nz_number): show a detailed error
message.
-Wed Jan 21 16:44:15 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Jan 21 16:44:20 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (merge_libs): squeeze successive same libraries.
[ruby-dev:22652]
-Wed Jan 21 16:10:36 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * lib/base64.rb: enclosed in a module. [ruby-core:02285]
-
-Wed Jan 21 16:01:26 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Jan 21 16:01:37 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/digest/rmd160/extconf.rb: have_library appends found library.
Wed Jan 21 11:36:00 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * ext/socket/socket.c (sock_gethostbyname): returns host if
- ai_canonname is NULL. (ruby-bugs PR#1243)
-
* parse.y (block_append): update nd_end for "real" head node.
[ruby-list:39058]
-Tue Jan 20 14:48:28 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Tue Jan 20 14:48:13 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/extconf.rb: should check <openssl/conf_api.h> instead
of OPENSSL_VERSION_NUMBER. [ruby-list:39056]
@@ -19529,57 +15600,25 @@ Tue Jan 20 13:22:39 2004 Dave Thomas <dave@pragprog.com>
* lib/English.rb: Document English.rb.
-Tue Jan 20 04:41:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/ruby/test_marshal.rb (MarshalTestLib::test_exception): test
- for [ruby-dev:22604].
-
- * test/ruby/test_marshal.rb (MarshalTestLibtest_singleton): test
- for [ruby-dev:22588].
-
-Tue Jan 20 02:38:13 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * marshal.c (w_class): should not dump singleton class.
- [ruby-dev:22631]
-
Tue Jan 20 02:49:22 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/extconf.rb: add check for OpenSSL version.
[ruby-list:39054]
-Mon Jan 19 23:56:20 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * error.c (name_err_mesg_to_str): inverted condition for result of
- inspection. [ruby-dev:22628]
-
-Mon Jan 19 22:24:28 2004 WATANABE Hirofumi <eban@ruby-lang.org>
-
- * sample/exyacc.rb: escape '}' to avoid warning.
-
- * lib/rdoc/parsers/parse_c.rb: escape '{' and '}' to avoid warnings.
-
-Mon Jan 19 21:28:06 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/digest/defs.h, win32/win3.c, win32/win32.h, file.c: remove
- useless casts for Borland C.
-
-Mon Jan 19 17:39:38 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * error.c (NameError::message): internal use only.
+Tue Jan 20 02:38:13 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
- * eval.c (rb_method_missing): use hidden constant.
+ * marshal.c (w_class): should not dump singleton class.
+ [ruby-dev:22631]
-Mon Jan 19 16:30:53 2004 akira yamada <akira@ruby-lang.org>
+Tue Jan 20 01:31:36 2004 WATANABE Hirofumi <eban@ruby-lang.org>
- * test/ruby/test_time.rb: added tests for [ruby-dev:22614] and
- [ruby-dev:22617].
+ * io.c (lineno): typo fix(FIX2INT -> INT2FIX).
-Mon Jan 19 13:09:21 2004 NAKAMURA Usaku <usa@ruby-lang.org>
+Mon Jan 19 21:53:38 2004 akira yamada <akira@ruby-lang.org>
- * ext/extmk.rb, win32/Makefile.sub, win32/configure.bat,
- win32/setup.mak: --with-static-linked-ext support on mswin32.
+ * io.c, re.c, string.c, time.c: fixed up positions of RDocs.
-Mon Jan 19 06:49:07 2004 Tadayoshi Funaba <tadf@dotrb.org>
+Mon Jan 19 07:09:20 2004 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date.rb: zone was wrong when it was behind UTC.
Thanks Mark J. Reed.
@@ -19589,53 +15628,10 @@ Mon Jan 19 06:49:07 2004 Tadayoshi Funaba <tadf@dotrb.org>
* sample/cal.rb: added a class, anyway.
-Mon Jan 19 01:08:39 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * class.c, error.c, eval.c, intern.h, object.c, variable.c:
- do not set path if it is a singleton class. [ruby-dev:22588]
-
- * lib/cgi.rb (CGI::QueryExtension): give extended string, not a
- delegater object.
-
-Sun Jan 18 23:59:44 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/iconv/charset_alias.rb: prefer us_EN locale encodings or
- former. [ruby-dev:22609]
-
- * ext/iconv/iconv.c (iconv_create): raise InvalidEncoding
- exception when EINVAL.
-
-Sun Jan 18 23:16:34 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * class.c, error.c, file.c, io.c, numeric.c, object.c, re.c, struct.c,
- time.c: marked init_copy functions nodoc.
-
Sun Jan 18 20:47:35 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* ruby.c: use translate_char() on Cygwin.
-Sun Jan 18 20:00:16 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * lib/soap/wsdlDriver.rb, lib/wsdl/soap/operation.rb: add support of
- "parts" attribute of soap:body element in WSDL.
-
- * lib/wsdl/xmlSchema/schema.rb: friendly warning message for
- simpleType element which is not supported for now.
-
- * test/wsdl/soap/{soapbodyparts.wsdl,test_soapbodyparts.wsdl}: new
- files.
-
-Sun Jan 18 16:46:48 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * time.c (time_overflow_p): should return results. [ruby-dev:22614]
-
-Sun Jan 18 12:07:24 2004 Siena. <siena@faculty.chiba-u.jp>
-
- * test/ruby/test_time.rb: new test case to test Time#[+-].
-
- * time.c (time_plus, time_minus): fix RangeError for a negative
- argument in environments whose time_t is unsigned. [ruby-dev:22608]
-
Sun Jan 18 02:33:26 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* defines.h (_WIN32): undef _WIN32 on Cygwin before defining DOSISH.
@@ -19645,136 +15641,59 @@ Sun Jan 18 00:23:55 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* marshal.c (class2path): check anonymous class/module before
checking referable, and allow singleton classes.
-Sat Jan 17 23:58:51 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * error.c (NameError::Message): new class for lazy evaluation of
- message to ensure replaced before marshalling. [ruby-dev:22604]
-
- * eval.c (rb_method_missing): use NameError::Message.
-
-Sat Jan 17 21:49:50 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * lib/time.rb (test_rfc2822, test_rfc3339, test_encode_xmlschema):
- should not expect that all platforms handle negative time_t value.
-
-Fri Jan 16 23:53:09 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * eval.c (proc_eq): compare also arguments and environment
- (including local variables). [ruby-dev:22590]
-
Fri Jan 16 14:33:35 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* marshal.c (class2path): get class path and check referable.
[ruby-dev:22588]
-Thu Jan 15 12:58:26 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Jan 16 09:52:23 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (proc_eq): Proc with empty body may not be equal.
+ [ruby-dev:22590]
+
+Thu Jan 15 13:03:10 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (argf_read): do not append EOF. (ruby-bugs-ja:PR#585)
* io.c (rb_io_fwrite): ad-hockery hack to get rid of HP-UX stdio
weird behavior. [ruby-dev:22424]
-Wed Jan 14 21:13:06 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/inlinetest.rb (InlineTest::eval_part): eval under the top
- level environment.
-
-Wed Jan 14 17:54:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/inlinetest.rb (InlineTest::loadtest): require instead of
- load, to get rid of multiple loading.
-
-Wed Jan 14 13:30:52 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Jan 14 13:31:06 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/iconv/extconf.rb: wrapper iconv.rb is dependent on platform.
-Wed Jan 14 09:32:02 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * MANIFEST: add test/net/test_httpheader.rb. (commit miss?)
+Tue Jan 13 18:54:28 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-Wed Jan 14 00:58:35 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * eval.c (Init_Proc): move SystemStackError from under
- StandardError to Exception. [ruby-talk:89782]
-
-Tue Jan 13 18:03:02 2004 Ian Macdonald <ian@caliban.org>
-
- * file.c (rb_stat_wr, rb_stat_ww): New functions
- implementing new methods (File::Stat#world_readable?,
- File::Stat#world_writable?).
-
-Tue Jan 13 16:53:25 2004 why the lucky stiff <why@ruby-lang.org>
-
- * ext/syck/rubyext.c: omission of Date library code caused
- test suite failure. [ruby-core:2251]
-
-Tue Jan 13 16:50:03 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk.rb: use $0 as the default application class name.
-
-Tue Jan 13 14:48:00 2004 Ian Macdonald <ian@caliban.org>
-
- * lib/pathname.rb: New methods (Pathname#world_readable?,
- Pathname#world_writable?).
-
-Tue Jan 13 14:48:01 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * parse.y (primary): allow no "when" case. [ruby-dev:22578]
+ * lib/logger.rb(Logger#msg2str): no special treatment for the object
+ which responds to :to_str. commited at 2004-01-11T21:46:27 by
+ gsinclair.
- * ruby.h (rb_class_of): reduce branch. [ruby-dev:22577]
+ * lib/logger.rb(LogDevice#initialize): remove type checking if the
+ given object is a String. Kernel.open handles it correctly.
+ commited at 2004-01-11T21:46:27 by gsinclair.
- * ruby.h (rb_type): ditto.
+ * test/logger/test_logger.rb: follow above change (ArgumentError ->
+ TypeError.) follow above commit.
-Tue Jan 13 14:26:59 2004 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
+Tue Jan 13 14:27:13 2004 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* lib/test/unit/ui/testrunnerutilities.rb (TestRunnerUtilities):
moved run method which allows output level. [ruby-dev:22554]
-Tue Jan 13 13:04:24 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * test/test_*.rb: Pathname#parent -> Pathname#dirname.
-
-Tue Jan 13 11:38:58 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * test/yaml/test_yaml.rb (YAML_Unit_Tests::test_spec_type_{int,float}):
- fix syntax error.
-
-Tue Jan 13 07:52:40 2004 why the lucky stiff <why@ruby-lang.org>
-
- * ext/syck/bytecode.c: turn off default implicit typing.
-
- * ext/syck/implicit.c: detect base60 integers.
-
- * ext/syck/rubyext.c: handle base60, as well as hex and octal
- with commas. implicit typing of ruby symbols.
-
- * test/yaml/test_yaml.rb: add test.
-
Tue Jan 13 04:29:52 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_driver.rb (RiDriver::report_method_stuff):
Show fully-qualified class names in class list.
-Tue Jan 13 01:24:17 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * file.c (test_wr): Rdoc fix. [ruby-core:02225]
-
Tue Jan 13 01:04:37 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_paths.rb (RI::Paths): First attempt at
incorporating DESTDIR in the rdoc installation.
-Mon Jan 12 23:26:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Jan 12 23:27:19 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (primary): fix position after FCALL. [ruby-dev:22574]
-Mon Jan 12 18:00:11 2004 Ian Macdonald <ian@caliban.org>
-
- * file.c (test_wr, test_ww): New functions implementing new
- methods (File::world_readable?, File::world_writable?).
-
- * file.c (S_IRUGO, S_IGUGO): New macros.
-
Mon Jan 12 12:07:22 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::do_methods):
@@ -19792,22 +15711,29 @@ Mon Jan 12 12:07:22 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_formatter.rb (RI::HtmlFormatter::break_to_newline):
HTML formats need explicit line breaks.
+Mon Jan 12 11:46:30 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * configure.in (LIBPATHFLAG, RPATHFLAG): enclose paths with single
+ quotes. [ruby-dev:22564]
+
+ * lib/mkmf.rb (libpathflag): do not enclose with quotes always.
+
+ * {bcc32,win32,wince}/Makefile.sub (LIBPATHFLAG): quoted.
+
Mon Jan 12 02:24:07 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_formatter.rb (RI::HtmlFormatter): Add HTML
generation support to ri (Elliot Hughes)
-Sun Jan 11 23:54:41 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * env.h (ruby_frame, ruby_scope, ruby_in_eval, ruby_class,
- ruby_dyna_vars): export. [ruby-dev:22566]
+Mon Jan 12 02:24:07 2004 Dave Thomas <dave@pragprog.com>
-Sun Jan 11 02:35:53 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * lib/rdoc/ri/ri_formatter.rb (RI::HtmlFormatter): Add HTML
+ generation support to ri (Elliot Hughes)
- * ext/socket/socket.c (make_hostent): a bug in brace position.
+Sun Jan 11 02:07:47 2004 Dave Thomas <dave@pragprog.com>
- * configure.in: install rdoc by default. if you do not want to
- install rdoc, specify --disable-install-doc.
+ * lib/rdoc/ri/ri_options.rb (RI::Options::OptionList::OptionList):
+ Also accept command line options via the 'RI' environment variable.
Sun Jan 11 02:07:47 2004 Dave Thomas <dave@pragprog.com>
@@ -19828,49 +15754,7 @@ Sat Jan 10 01:54:50 2004 Eric Sunshine <sunshine@sunshineco.com>
correctly on Rhapsody when -arch compiler flag was used (via
configure's --enable-fat-binary option).
-Sat Jan 10 23:01:41 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * configure.in (LIBPATHFLAG, RPATHFLAG): enclose paths with single
- quotes. [ruby-dev:22564]
-
- * lib/mkmf.rb (libpathflag): do not enclose with quotes always.
-
- * {bcc32,win32,wince}/Makefile.sub (LIBPATHFLAG): quoted.
-
-Sat Jan 10 22:46:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dir.c (dir_inspect): new method, Dir#inspect. [ruby-dev:22562]
-
-Fri Jan 9 17:36:51 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * ext/socket/socket.c (make_hostent): getaddrinfo(3) on BSD do not
- fill ai_canonname if serv is not supplied. (ruby-bugs PR#1243)
-
-Fri Jan 9 13:14:59 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * lib/test/unit/collector/dir.rb: do not ignore exceptions(LoadError
- and SystemExitError) while loading a testcase. smell of bug.
-
- * test/testunit/collector/test_dir.rb: add new test of the LoadError.
-
- * test/drb/{test_drbssl.rb,test_drbunix.rb}: do not define testcase if
- openssl is not installed.
-
- * test/testunit/collector/test_dir.rb: assert_raises -> assert_raise.
-
-Fri Jan 9 11:52:16 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * rubysig.h: <errno.h> is needed to use errno which may be a macro.
-
-Fri Jan 9 11:20:24 2004 Siena. <siena@faculty.chiba-u.jp>
-
- * ext/extmk.rb (extmake): should not reduce necessary libraries.
- [ruby-dev:22440]
-
- * lib/mkmf.rb (merge_libs): merge libraries according to
- dependency.
-
-Fri Jan 9 10:05:23 2004 Siena. <siena@faculty.chiba-u.jp>
+Fri Jan 9 10:05:14 2004 Siena. <siena@faculty.chiba-u.jp>
* lib/mkmf.rb (libpathflag): use single quotes. [ruby-dev:22440]
@@ -19880,7 +15764,7 @@ Thu Jan 8 23:49:21 2004 WATANABE Hirofumi <eban@ruby-lang.org>
rdoc documentation, you need to run configure with
--enable-install-doc.
-Thu Jan 8 21:17:43 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Jan 8 21:29:43 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_pkey.c (ossl_pkey_to_der): removed; it returns
public key only.
@@ -19894,10 +15778,6 @@ Thu Jan 8 21:17:43 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_pkey_rsa.c (ossl_rsa_to_der): new function for
OpenSSL::PKey::RSA#to_der.
-Thu Jan 8 18:25:29 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dir.c (glob_helper): should not recurse in exceptional status.
-
Thu Jan 8 16:51:04 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/wsdl/datetime/test_datetime.rb: fixed a stupid testcase which
@@ -19907,58 +15787,15 @@ Thu Jan 8 11:20:01 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* eval.c, object.c, process.c, re.c: don't use C++ style comments.
-Thu Jan 8 08:46:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/syck/rubyext.c (yaml_org_handler): lazy-load Date for
- static-ext.
-
-Thu Jan 8 07:06:30 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * ext/extmk.rb: preserve order in Setup. [ruby-dev:22503]
-
- * ext/extmk.rb: move dependent libraries just after depended
- libraries.
-
- * ext/digest/*/extconf.rb: depend on digest.
-
-Thu Jan 8 04:36:17 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
+Thu Jan 8 04:36:21 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/cgi.rb (WEBrick::CGI#initialize): should create
@config[:Logger] if it was not given.
-Wed Jan 7 22:28:12 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dir.c (glob_helper): fix memory leak.
-
-Wed Jan 7 21:15:07 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
-
* sample/webrick/*: new files.
* MANIFEST: add sample/webrick/*
-Wed Jan 7 20:51:51 2004 Minero Aoki <aamine@loveruby.net>
-
- * test/net/test_httpheader.rb: new file.
-
- * MANIFEST: add test/net/test_httpheader.rb.
-
-Wed Jan 7 20:42:06 2004 Minero Aoki <aamine@loveruby.net>
-
- * lib/net/http.rb (HTTPHeader#content_length): should return nil
- unless header exists. [ruby-dev:22519]
-
-Wed Jan 7 14:26:05 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
-
- * ext/tk/lib/tk.rb (TkPanedWindow): use epath for embedded windows.
-
- * ext/tk/lib/tktext.rb: use epath for embedded windows.
-
- * ext/tk/lib/tkcanvas.rb: use epath for window items.
-
-Wed Jan 7 14:24:04 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * lib/soap/{attachment.rb,mimemessage.rb}: added from soap4r/1.5.2.
-
Wed Jan 7 13:00:18 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_driver.rb: Fix problem where ri was
@@ -19982,71 +15819,16 @@ Tue Jan 6 22:13:34 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_mod_modfunc): should break if m has no super class.
[ruby-dev:22498]
-Tue Jan 6 21:51:37 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Jan 6 21:55:02 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (fptr_finalize): should save errno just after failure.
[ruby-dev:22492]
-Tue Jan 6 20:51:10 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * lib/logger.rb(Logger#msg2str): no special treatment for the object
- which responds to :to_str.
-
- * lib/logger.rb(LogDevice#initialize): remove type checking if the
- given object is a String. Kernel.open handles it correctly.
-
- * test/logger/test_logger.rb: follow above change (ArgumentError ->
- TypeError.)
-
Tue Jan 6 14:53:14 2004 Dave Thomas <dave@pragprog.com>
* bin/ri: split out the display side, making it pluggable. Added
new ri_driver and ri_display files in lib/rdoc/ri.
-Tue Jan 6 11:29:43 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * test/inlinetest.rb, test/{test_generator.rb,test_ipaddr.rb,
- test_pathname.rb,test_pp.rb,test_prettyprint.rb,test_set.rb,
- test_time.rb,test_tsort.rb: added.
-
-Tue Jan 6 09:38:27 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
- * import soap4r/1.5.2;
-
- * lib/soap/{attachment.rb,baseData.rb,encodingstyle/soapHandler.rb}:
- introduce SOAPExternalReference class as a referenct to SOAPEnvelope
- external content.
-
- * lib/soap/{attachment.rb,mimemessage.rb}: great SwA (SOAP messages
- with Attachments) support code by Jamie Herre.
-
- * lib/soap/{element.rb,marshal.rb,parser.rb,processor.rb,
- streamHandler.rb,wsdlDriver.rb}: SwA support.
-
- * lib/soap/rpc/{cgistub.rb,driver.rb,element.rb,proxy.rb,router.rb,
- soaplet.rb}: SwA support and refactoring.
-
- * lib/soap/generator.rb, lib/soap/mapping/mapping.rb: follow
- SOAPReference#initialize signature change.
-
- * lib/soap/mapping/factory.rb: deleted unused methods.
-
- * lib/soap/mapping/rubytypeFactory.rb: do no ignore case while xsi:type
- string <-> Ruby class name matching.
-
- * lib/xsd/datatypes.rb: check the smallest positive non-zero
- single-precision float exactly instead of packing with "f".
- [ruby-talk:88822]
-
- * test/soap/test_basetype.rb, test/xsd/test_xsd.rb: use 1.402e-45, not
- 1.4e-45. 1.4e-45 is smaller than 2 ** -149...
-
- * test/soap/test_basetype.rb, test/soap/marshal/test_marshal.rb,
- test/xsd/test_xsd.rb: use "(-1.0 / (1.0 / 0.0))" instead of "-0.0".
-
- * test/soap/test_streamhandler.rb: revert to the previous test that
- warns "basic_auth unsupported under net/http".
-
Tue Jan 6 06:37:53 2004 Dave Thomas <dave@pragprog.com>
* bin/rdoc: Add --ri-system switch
@@ -20067,45 +15849,6 @@ Tue Jan 6 00:04:40 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_method_or_yield_parameters):
fix parsing if there are braces in a method parameter list
-Tue Jan 6 01:01:04 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * win32/dir.h, win32/win32.c: fix patch miss.
-
- * win32/Makefile.sub: fix file dependency.
-
-Mon Jan 5 20:32:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
-
- * lib/logger.rb: enhanced documentation.
-
-Mon Jan 5 18:58:47 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * dir.c: merge tuning from H.Yamamoto <ocean@m2.ccsnet.ne.jp>.
- [ruby-dev:22486]
-
- * pack.c (pack_unpack): unpack requires big endian offet (OFF16B
- and OFF32B). The patch is from Minero Aoki in [ruby-dev:22489]
-
- * pack.c (OFF16B): add big-endian offset again.
-
-Mon Jan 5 03:00:53 2004 Minero Aoki <aamine@loveruby.net>
-
- * test/ruby/test_pack.rb: new test test_unpack_N.
-
-Mon Jan 5 01:47:53 2004 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * lib/mkmf.rb (create_makefile): remove duplicated object files
- from $objs on DOSISH platforms.
-
-Sat Jan 3 02:44:48 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * rubysig.h (TRAP_END): preserve errno before switching context.
- [ruby-core:02137]
-
-Sat Jan 3 01:18:08 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
-
- * dir.c: merge tuning from H.Yamamoto <ocean@m2.ccsnet.ne.jp>.
- [ruby-dev:22476]
-
Fri Jan 2 14:54:11 2004 Dave Thomas <dave@pragprog.com>
* bin/ri: Add new --classes option, and arrange for
@@ -20124,23 +15867,10 @@ Fri Jan 2 01:50:13 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (argf_eof): ARGF.eof? should not have any side effect.
[ruby-dev:22469]
-Thu Jan 1 09:03:20 2004 Dave Thomas <dave@pragprog.com>
-
- * bin/ri (report_class_stuff): Fix problem with ambiguous nested
- classes not matching.
-
Wed Dec 31 17:25:17 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (argf_each_byte): should return self. [ruby-dev:22465]
-Wed Dec 31 15:05:00 2003 Gavin Sinclair <gsinclair@soyabean.com.au>
-
- * lib/pathname.rb: Corrected small coding error.
-
-Wed Dec 31 15:00:00 2003 Gavin Sinclair <gsinclair@soyabean.com.au>
-
- * lib/pathname.rb: Completed documentation.
-
Wed Dec 31 11:20:34 2003 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::do_methods): Make
@@ -20176,23 +15906,21 @@ Tue Dec 30 12:30:30 2003 Dave Thomas <dave@pragprog.com>
class and a method have the same name, finding Xxx.abc was trying
to find 'abc' in method 'Xxx', not class 'Xxx'.
+
Tue Dec 30 08:32:32 2003 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_method):
- Handle undoing nsting of yield parameters correctly for:
-
- def each_entry(&b) Dir.foreach(@path) {|f| yield P.new(f) } end
+ Handle undoing nesting of yield parameters correctly for:
-Tue Dec 30 07:30:00 2003 Gavin Sinclair <gsinclair@soyabean.com.au>
+ def each_entry(&b) Dir.foreach(@path) {|f| yield P.new(f) } end
- * lib/pathname.rb: Added documentation.
-Mon Dec 29 20:08:17 2003 Minero Aoki <aamine@loveruby.net>
+Tue Dec 30 08:32:32 2003 Dave Thomas <dave@pragprog.com>
- * lib/net/http.rb (GenericRequest#initialize): check if path
- begins with '/'.
+ * lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_method):
+ Handle undoing nesting of yield parameters correctly for:
- * lib/net/http.rb: def m( arg ) -> def m(arg)
+ def each_entry(&block) Dir.foreach(@path) {|f| yield Pathname.new(f) } end
Mon Dec 29 12:51:02 2003 Dave Thomas <dave@pragprog.com>
@@ -20206,25 +15934,10 @@ Mon Dec 29 05:05:51 2003 Dave Thomas <dave@pragprog.com>
* struct.c, random: Add RDoc comments
-Mon Dec 29 02:25:00 2003 Gavin Sinclair <gsinclair@soyabean.com.au>
-
- * lib/optparse.rb: Improved documentation.
-
Mon Dec 29 02:20:54 2003 Dave Thomas <dave@pragprog.com>
* eval.c: Add RDoc for class Proc, Method, UnboundMethod
-Mon Dec 29 02:20:26 2003 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * instruby.rb: fix install directory if destdir and compile_dir are
- not in the same drive.
-
- * ext/extmk.rb: ditto. [ruby-list:39009]
-
- * win32/Makefile.sub, win32/README.win32, win32/configure.bat,
- win32/setup.mak: new configure scheme. use ``configure --prefix=dir''
- instead of ``nmake DESTDIR=dir install''.
-
Mon Dec 29 00:41:44 2003 Dave Thomas <dave@pragprog.com>
* math.c: Add RDoc comments
@@ -20258,7 +15971,7 @@ Sun Dec 28 03:50:05 2003 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::find_override_comment):
Escape method names used in regexp
-Sun Dec 28 01:46:02 2003 Dave Thomas <dave@wireless_3.local.thomases.com>
+Sun Dec 28 01:46:02 2003 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_formatter.rb (RI::TextFormatter::display_flow_item):
Add support for rules in 'ri' output.
@@ -20276,27 +15989,27 @@ Sun Dec 28 01:05:31 2003 Dave Thomas <dave@pragprog.com>
* marshal.c, signal.c: RDoc collemts added by Elliott Hughes
-Sun Dec 28 00:46:25 2003 Dave Thomas <dave@pragprog.com>
+Sun Dec 28 00:48:47 2003 Dave Thomas <dave@pragprog.com>
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser::find_class_comment):
- Some Ruby source uses lower-case class names for the
- Init_Xxx C function name.
+ Some source files use lower case class or module names
+ when naming the Init_XXX function in C.
Sat Dec 27 23:41:46 2003 WATANABE Hirofumi <eban@ruby-lang.org>
* configure.in: fix "test: too many arguments" error.
-Sat Dec 27 15:32:40 2003 Dave Thomas <dave@wireless_3.local.thomases.com>
+Sat Dec 27 15:32:19 2003 Dave Thomas <dave@wireless_3.local.thomases.com>
- * time.c: Add RDoc comments for Time class.
+ * time.c: RDoc comments added
-Sat Dec 27 15:07:26 2003 Dave Thomas <dave@pragprog.com>
+Sat Dec 27 15:07:57 2003 Dave Thomas <dave@pragprog.com>
* object.c: Add RDoc comments for Symbol class.
-Sat Dec 27 14:39:53 2003 Dave Thomas <dave@pragprog.com>
+Sat Dec 27 14:42:30 2003 Dave Thomas <dave@pragprog.com>
- * numeric.c (Init_Numeric): Add RDoc comments.
+ * numeric.c: Add RDoc comments.
Sat Dec 27 00:44:00 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -20314,7 +16027,7 @@ Fri Dec 26 23:02:09 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_getline): should return nil when read_all gives
empty string, even when nil rs is specified. [ruby-core:02077]
-Fri Dec 26 18:33:54 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Dec 26 18:50:59 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in: check if getcontext and setcontext are available.
@@ -20324,26 +16037,14 @@ Fri Dec 26 16:40:53 2003 Tanaka Akira <akr@m17n.org>
* lib/pathname.rb (PathnameTest#test_plus): add 2 assertions.
-Fri Dec 26 14:05:13 2003 Minero Aoki <aamine@loveruby.net>
-
- * test/ruby/test_pack.rb: new test test_pack_N.
-
-Fri Dec 26 12:53:26 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+Fri Dec 26 09:26:58 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (pack_pack): add sign check for 'i', and 'l'.
[ruby-dev:22427]
* bignum.c (rb_quad_pack): add range check for 'quad int'.
-Fri Dec 26 10:58:58 2003 NAKAMURA Usaku <usa@ruby-lang.org>
-
- * MANIFEST: add vms/config.h and remove vms/config.h_in.
-
-Fri Dec 26 10:42:00 2003 AKIYOSHI, Masamichi <masamichi.akiyoshi@hp.com>
-
- * io.c: [VMS] "rfm=stmlf" is specified for open() and fopen().
-
-Thu Dec 25 22:29:53 2003 NAKAMURA Usaku <usa@ruby-lang.org>
+Thu Dec 25 22:39:59 2003 NAKAMURA Usaku <usa@ruby-lang.org>
* string.c (rb_str_update): don't return any value.
@@ -22607,6 +18308,11 @@ Mon Oct 20 09:45:12 2003 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/debug.rb (debug_command): remove debug print.
+Wed Oct 20 00:25:41 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (search_required): required name must not be changed before
+ loading. [ruby-dev:24492]
+
Sun Oct 19 13:12:30 2003 Tanaka Akira <akr@m17n.org>
* lib/pathname.rb (foreachline, dir_foreach): add obsolete warning.
@@ -23590,6 +19296,35 @@ Thu Oct 2 00:21:11 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/soap/calc/*: give httpd config param "CGIInterpreter".
"/usr/bin/env ruby" thing does not work under non-Unix boxes.
+Sat Oct 2 00:42:20 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * marshal.c (r_byte): retrieve pointer from string value for each
+ time. [ruby-dev:24404]
+
+ * marshal.c (r_bytes0): ditto.
+
+ * enum.c (sort_by_i): re-entrance check added. [ruby-dev:24399]
+
+ * io.c (io_read): should freeze all reading buffer.
+ [ruby-dev:24400]
+
+ * string.c (rb_str_sum): should use bignums when bits is greater
+ than or equals to sizeof(long)*CHAR_BITS. [ruby-dev:24395]
+
+ * eval.c (specific_eval): defer pointer retrieval to prevent
+ unsafe sourcefile string modification. [ruby-dev:24382]
+
+ * string.c (rb_str_sum): wrong cast caused wrong result.
+ [ruby-dev:24385]
+
+ * enum.c (enum_sort_by): hide temporary array from
+ ObjectSpace.each_object. [ruby-dev:24386]
+
+ * string.c (rb_str_sum): check was done with false pointer.
+ [ruby-dev:24383]
+
+ * string.c (rb_str_sum): string may be altered. [ruby-dev:24381]
+
Thu Oct 2 00:25:21 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* signal.c (ruby_signal_name): adjust to the prototype.
@@ -23753,6 +19488,20 @@ Sat Sep 27 09:44:18 2003 Minero Aoki <aamine@loveruby.net>
* test/fileutils/test_nowrite.rb: ditto.
+Mon Sep 27 09:14:03 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * array.c (rb_ary_delete): comparison may change the capacity.
+ [ruby-dev:24348]
+
+ * array.c (rb_ary_fill): fill should honor length argument.
+ [ruby-dev:24346]
+
+ * array.c (rb_ary_replace): should not use ptr from shared array.
+ [ruby-dev:24345]
+
+ * ext/socket/socket.c (s_accept): don't retry for EWOULDBLOCK.
+ [ruby-talk:113807]
+
Sat Sep 27 04:57:07 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/ruby/test_file.rb: new file. only asserts unlink-before-close
diff --git a/LEGAL b/LEGAL
index 8dd957bd3e..908eb270f5 100644
--- a/LEGAL
+++ b/LEGAL
@@ -5,27 +5,34 @@ All the files in this distribution are covered under either the Ruby's
license (see the file COPYING) or public-domain except some files
mentioned below.
-oniguruma.h:
-regcomp.c:
-regenc.[ch]:
-regerror.c:
-regex.c:
-regexec.c:
-regint.h:
-regparse.[ch]:
-ascii.c:
-euc_jp.c:
-sjis.c:
-utf8.c:
-
-Oniguruma ---- (C) K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
-
-http://www.geocities.jp/kosako3/oniguruma/
-http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/oniguruma/
-http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/oniguruma/
-
- When this software is partly used or it is distributed with Ruby,
- this of Ruby follows the license of Ruby.
+regex.[ch]:
+
+ These files are under LGPL. Treat them as LGPL says. (See the file
+ LGPL for details)
+
+ Extended regular expression matching and search library.
+ Copyright (C) 1993, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file LGPL. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ Multi-byte extension added May, 1993 by t^2 (Takahiro Tanimoto)
+ Last change: May 21, 1993 by t^2
+ removed gapped buffer support, multiple syntax support by matz <matz@nts.co.jp>
+ Perl5 extension added by matz <matz@caelum.co.jp>
+ UTF-8 extension added Jan 16 1999 by Yoshida Masato <yoshidam@tau.bekkoame.ne.jp>
configure:
diff --git a/Makefile.in b/Makefile.in
index d5d2b9f3ed..314e1ed256 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,4 +1,5 @@
SHELL = /bin/sh
+NULLCMD = :
#### Start of system configuration section. ####
@@ -6,7 +7,7 @@ srcdir = @srcdir@
VPATH = $(srcdir):$(srcdir)/missing
CC = @CC@
-YACC = bison
+YACC = @YACC@
PURIFY =
AUTOCONF = autoconf
@SET_MAKE@
@@ -33,9 +34,8 @@ RIDATADIR = $(DESTDIR)$(datadir)/ri/$(MAJOR).$(MINOR)/system
empty =
OUTFLAG = @OUTFLAG@$(empty)
-CFLAGS = @CFLAGS@ @ARCH_FLAG@
-XCFLAGS = -I. -I$(srcdir) @XCFLAGS@
-CPPFLAGS = @CPPFLAGS@
+CFLAGS = @CFLAGS@ @XCFLAGS@ @ARCH_FLAG@
+CPPFLAGS = -I. -I$(srcdir) @CPPFLAGS@
LDFLAGS = @STATIC@ $(CFLAGS) @LDFLAGS@
EXTLDFLAGS =
XLDFLAGS = @XLDFLAGS@ $(EXTLDFLAGS)
@@ -156,14 +156,16 @@ $(srcdir)/configure: $(srcdir)/configure.in
lex.c: keywords
@-$(RM) $@
- gperf -C -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? > $@ || \
+ gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? > $@ || \
cp "$(srcdir)/$@" .
.y.c:
- $(YACC) $(YFLAGS) -o $@ $<
+ $(YACC) $<
+ sed '/^#/s|y\.tab\.c|$@|' y.tab.c > $@
+ rm -f y.tab.c
.c.@OBJEXT@:
- $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -c $<
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c $<
.s.@OBJEXT@:
$(AS) $(ASFLAGS) -o $@ $<
@@ -175,4 +177,4 @@ distclean-local::
@$(RM) ext/config.cache $(RBCONFIG)
ext/extinit.$(OBJEXT): ext/extinit.c $(SETUP)
- $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -o$@ -c ext/extinit.c
+ $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(OUTFLAG)$@ -c ext/extinit.c
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000000..de1dafb533
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,115 @@
+= NEWS
+
+This document is a list of user visible feature changes made between
+releases excluding bug fixes.
+
+Note that each entry is kept so brief that no reason behind or
+reference information is supplied with. For a full list of changes
+with all sufficient information, see the ChangeLog file.
+
+== Changes with Ruby 1.8.5
+
+=== New platforms/build tools support
+
+* IA64 HP-UX
+
+* Visual C++ 8 SP1
+
+* autoconf 2.6x
+
+=== Library updates (outstanding ones only)
+
+* date
+
+ * Updated based on date2 4.0.3.
+
+* digest
+
+ * New internal APIs for C and Ruby.
+
+ * Support for autoloading.
+
+ * See below for new features and compatibility issues.
+
+* nkf
+
+ * Updated based on nkf as of 2007-01-28.
+
+* tk
+
+ * Tk::X_Scrollable (Y_Scrollable) is renamed to Tk::XScrollable
+ (YScrollable). Tk::X_Scrollable (Y_Scrollable) is still available,
+ but it is an alias name.
+
+ * Updated Tile extension support based on Tile 0.7.8.
+
+ * Support --without-X11 configure option for non-X11 versions of
+ Tcl/Tk (e.g. Tcl/Tk Aqua).
+
+ * New sample script: irbtkw.rbw -- IRB on Ruby/Tk. It has no trouble
+ about STDIN blocking on Windows.
+
+=== New methods and features
+
+* builtin classes
+
+ * New method: Kernel#instance_variable_defined?
+
+ * New method: Module#class_variable_defined?
+
+ * New feature: Dir::glob() can now take an array of glob patterns.
+
+* digest
+
+ * New digest class methods: file
+
+ * New digest instance methods: clone, reset, new,
+ inspect, digest_length (alias size or length),
+ block_length()
+
+ * New library: digest/bubblebabble
+
+ * New function: Digest(name)
+
+* fileutils
+
+ * New option for FileUtils.cp_r(): :remove_destination
+
+* thread
+
+ * Replaced with much faster mutex implementation in C.
+ The former implementation is available with a
+ configure option `--disable-fastthread'.
+
+* webrick
+
+ * New method: WEBrick::Cookie.parse_set_cookies()
+
+=== Compatibility issues (excluding feature bug fixes)
+
+* builtin classes
+
+ * String#intern now raises SecurityError when $SAFE level is greater
+ than zero.
+
+* fileutils
+
+ * A minor implementation change breaks Rake <=0.7.1.
+ Updating Rake to 0.7.2 fixes the problem.
+
+* digest
+
+ * The constructor does no longer take an initial
+ string to feed; digest() and hexdigest() now do,
+ instead. The following examples show how to
+ migrate:
+
+ # Before
+ md = Digest::MD5.new("string")
+ # After (works with any version)
+ md = Digest::MD5.new.update("string")
+
+ # Before
+ hd = Digest::MD5.new("string").hexdigest
+ # After (works with any version)
+ hd = Digest::MD5.hexdigest("string")
diff --git a/README b/README
index d4580076b0..cf836415ad 100644
--- a/README
+++ b/README
@@ -22,16 +22,24 @@ Perl). It is simple, straight-forward, and extensible.
* How to get Ruby
-The Ruby distribution can be found on:
+The Ruby distribution files can be found in the following FTP site:
ftp://ftp.ruby-lang.org/pub/ruby/
-You can get it by anonymous CVS. How to check out is:
+The latest source code of this version series can be checked out
+through SVN with the following command:
- $ cvs -d :pserver:anonymous@cvs.ruby-lang.org:/src login
- (Logging in to anonymous@cvs.ruby-lang.org)
- CVS password: anonymous
- $ cvs -z4 -d :pserver:anonymous@cvs.ruby-lang.org:/src checkout ruby
+ $ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6/
+
+The trunk of the Ruby source tree can be checked out with the
+following command:
+
+ $ svn co http://svn.ruby-lang.org/repos/ruby/trunk/ ruby
+
+There are some other branches under development. Try the following
+command and see the list of branches:
+
+ $ svn ls http://svn.ruby-lang.org/repos/ruby/branches/
* Ruby home-page
diff --git a/README.EXT b/README.EXT
index 283de48b7f..2fc2fd606a 100644
--- a/README.EXT
+++ b/README.EXT
@@ -115,10 +115,10 @@ can be cast to retrieve the pointer to the struct. The casting macro
will be of the form RXXXX for each data type; for instance, RARRAY(obj).
See "ruby.h".
-There are some accessing macros for structure members, for example
-`RSTRING_LEN(s)' to to get the size of the Ruby String object. The
-allocated region can be accessed by `RSTRING_PTR(str). For arrays, use
-`RARRAY_LEN(ary) and `RARRAY_PTR(ary) respectively.
+For example, `RSTRING(str)->len' is the way to get the size of the
+Ruby String object. The allocated region can be accessed by
+`RSTRING(str)->ptr'. For arrays, use `RARRAY(ary)->len' and
+`RARRAY(ary)->ptr' respectively.
Notice: Do not change the value of the structure directly, unless you
are responsible for the result. This ends up being the cause of interesting
diff --git a/README.EXT.ja b/README.EXT.ja
index 20c5a362a6..30c4d520ba 100644
--- a/README.EXT.ja
+++ b/README.EXT.ja
@@ -129,11 +129,10 @@ obsolete ¤È¤Ê¤ê¡¢Âå¤ï¤ê¤Ë StringValue() ¤È StringValuePtr()
ruby.h¤Ç¤Ï¹½Â¤ÂΤإ­¥ã¥¹¥È¤¹¤ë¥Þ¥¯¥í¤â¡ÖRXXXXX()¡×(Á´ÉôÂçʸ
»ú¤Ë¤·¤¿¤â¤Î)¤È¤¤¤¦Ì¾Á°¤ÇÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹(Îã: RSTRING())¡¥
-¹½Â¤ÂΤ«¤é¥Ç¡¼¥¿¤ò¼è¤ê½Ð¤¹¥Þ¥¯¥í¤¬Ä󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£Ê¸»úÎó
-str¤ÎŤµ¤òÆÀ¤ë¤¿¤á¤Ë¤Ï¡ÖRSTRING_LEN(str)¡×¤È¤·¡¤Ê¸»úÎóstr¤ò
-char*¤È¤·¤ÆÆÀ¤ë¤¿¤á¤Ë¤Ï¡ÖRSTRING_PTR(str)¡×¤È¤·¤Þ¤¹¡¥ÇÛÎó¤Î
-¾ì¹ç¤Ë¤Ï¡¤¤½¤ì¤¾¤ì¡ÖRARRAY_LEN(ary)¡×¡¤¡ÖRARRAY_PTR(ary)¡×¤È
-¤Ê¤ê¤Þ¤¹¡¥
+Î㤨¤Ð¡¤Ê¸»úÎóstr¤ÎŤµ¤òÆÀ¤ë¤¿¤á¤Ë¤Ï¡ÖRSTRING(str)->len¡×¤È
+¤·¡¤Ê¸»úÎóstr¤òchar*¤È¤·¤ÆÆÀ¤ë¤¿¤á¤Ë¤Ï¡ÖRSTRING(str)->ptr¡×
+¤È¤·¤Þ¤¹¡¥ÇÛÎó¤Î¾ì¹ç¤Ë¤Ï¡¤¤½¤ì¤¾¤ì¡ÖRARRAY(ary)->len¡×¡¤
+¡ÖRARRAY(ary)->ptr¡×¤È¤Ê¤ê¤Þ¤¹¡¥
Ruby¤Î¹½Â¤ÂΤòľÀÜ¥¢¥¯¥»¥¹¤¹¤ë»þ¤Ëµ¤¤ò¤Ä¤±¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤³
¤È¤Ï¡¤ÇÛÎó¤äʸ»úÎó¤Î¹½Â¤ÂΤÎÃæ¿È¤Ï»²¾È¤¹¤ë¤À¤±¤Ç¡¤Ä¾ÀÜÊѹ¹¤·
@@ -381,7 +380,8 @@ C¤«¤éʸ»úÎó¤ò·Ðͳ¤»¤º¤ËRuby¤Î¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤â¤Ç¤­¤Þ
¤¹¡¥¤½¤ÎÁ°¤Ë¡¤Ruby¥¤¥ó¥¿¥×¥ê¥¿Æâ¤Ç¥á¥½¥Ã¥É¤äÊÑ¿ô̾¤ò»ØÄꤹ¤ë
»þ¤Ë»È¤ï¤ì¤Æ¤¤¤ëID¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤ª¤­¤Þ¤·¤ç¤¦¡¥
-ID¤È¤ÏÊÑ¿ô̾¡¤¥á¥½¥Ã¥É̾¤òɽ¤¹À°¿ô¤Ç¤¹¡¥Ruby¤ÎÃæ¤Ç¤Ï
+ID¤È¤ÏÊÑ¿ô̾¡¤¥á¥½¥Ã¥É̾¤òɽ¤¹À°¿ô¤Ç¤¹¡¥Ruby¤Ç¤ÏID¤ËÂбþ¤¹¤ë
+¥ª¥Ö¥¸¥§¥¯¥È¤È¤·¤Æ¥·¥ó¥Ü¥ë(Symbol)¤¬¤¢¤ê¡¤
:¼±ÊÌ»Ò
@@ -394,6 +394,14 @@ ID¤È¤ÏÊÑ¿ô̾¡¤¥á¥½¥Ã¥É̾¤òɽ¤¹À°¿ô¤Ç¤¹¡¥Ruby¤ÎÃæ¤Ç¤Ï
rb_to_id(VALUE symbol)
+ID¤«¤é¥·¥ó¥Ü¥ë¤òÆÀ¤ë¤¿¤á¤Ë¤Ï°Ê²¼¤Î¥Þ¥¯¥í¤ò»È¤¤¤Þ¤¹¡¥
+
+ VALUE ID2SYM(ID id)
+
+¥·¥ó¥Ü¥ë¤«¤éID¤òÆÀ¤ë¤¿¤á¤Ë¤Ï°Ê²¼¤Î¥Þ¥¯¥í¤ò»È¤¤¤Þ¤¹¡¥
+
+ ID SYM2ID(VALUE symbol)
+
2.2.3 C¤«¤éRuby¤Î¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹
C¤«¤éʸ»úÎó¤ò·Ðͳ¤»¤º¤ËRuby¤Î¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹¤¿¤á¤Ë¤Ï°Ê²¼
@@ -1137,32 +1145,6 @@ void ruby_script(char *name)
Ruby¤Î¥¹¥¯¥ê¥×¥È̾($0)¤òÀßÄꤹ¤ë¡¥
-** ¥¤¥ó¥¿¥×¥ê¥¿¤Î¥¤¥Ù¥ó¥È¤Î¥Õ¥Ã¥¯
-
- void rb_add_event_hook(rb_event_hook_func_t func, rb_event_t events)
-
-»ØÄꤵ¤ì¤¿¥¤¥ó¥¿¥×¥ê¥¿¤Î¥¤¥Ù¥ó¥È¤ËÂФ¹¤ë¥Õ¥Ã¥¯´Ø¿ô¤òÄɲä·¤Þ¤¹¡¥
-events¤Ï°Ê²¼¤ÎÃͤÎor¤Ç¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó:
-
- RUBY_EVENT_LINE
- RUBY_EVENT_CLASS
- RUBY_EVENT_END
- RUBY_EVENT_CALL
- RUBY_EVENT_RETURN
- RUBY_EVENT_C_CALL
- RUBY_EVENT_C_RETURN
- RUBY_EVENT_RAISE
- RUBY_EVENT_ALL
-
-rb_event_hook_func_t¤ÎÄêµÁ¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¹:
-
- typedef void (*rb_event_hook_func_t)(rb_event_t event, NODE *node,
- VALUE self, ID id, VALUE klass)
-
- int rb_remove_event_hook(rb_event_hook_func_t func)
-
-»ØÄꤵ¤ì¤¿¥Õ¥Ã¥¯´Ø¿ô¤òºï½ü¤·¤Þ¤¹¡¥
-
Appendix C. extconf.rb¤Ç»È¤¨¤ë´Ø¿ô¤¿¤Á
diff --git a/README.ja b/README.ja
index fc502dd440..df8cfc03f4 100644
--- a/README.ja
+++ b/README.ja
@@ -26,18 +26,25 @@ Ruby¤Ï¥Æ¥­¥¹¥È½èÍý´Ø·¸¤ÎǽÎϤʤɤËÍ¥¤ì¡¤Perl¤ÈƱ¤¸¤¯¤é¤¤¶¯ÎÏ
* Æþ¼êË¡
-** ftp¤Ç
+** FTP¤Ç
°Ê²¼¤Î¾ì½ê¤Ë¤ª¤¤¤Æ¤¢¤ê¤Þ¤¹¡¥
ftp://ftp.ruby-lang.org/pub/ruby/
-** CVS¤Ç
+** Subversion¤Ç
- $ cvs -d :pserver:anonymous@cvs.ruby-lang.org:/src login
- (Logging in to anonymous@cvs.ruby-lang.org)
- CVS password: anonymous
- $ cvs -z4 -d :pserver:anonymous@cvs.ruby-lang.org:src checkout ruby
+ËÜ¥Ö¥é¥ó¥Á¤ÎRuby¤ÎºÇ¿·¤Î¥½¡¼¥¹¥³¡¼¥É¤Ï¼¡¤Î¥³¥Þ¥ó¥É¤Ç¼èÆÀ¤Ç¤­¤Þ¤¹¡¥
+
+ $ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6/
+
+³«È¯Àèü¤Î¥½¡¼¥¹¥³¡¼¥É¤Ï¼¡¤Î¥³¥Þ¥ó¥É¤Ç¼èÆÀ¤Ç¤­¤Þ¤¹¡¥
+
+ $ svn co http://svn.ruby-lang.org/repos/ruby/trunk/ ruby
+
+¾¤Ë³«È¯Ãæ¤Î¥Ö¥é¥ó¥Á¤Î°ìÍ÷¤Ï¼¡¤Î¥³¥Þ¥ó¥É¤Ç¸«¤é¤ì¤Þ¤¹¡¥
+
+ $ svn ls http://svn.ruby-lang.org/repos/ruby/branches/
* ¥Û¡¼¥à¥Ú¡¼¥¸
diff --git a/ToDo b/ToDo
index 7e5ef523a8..b55e399edf 100644
--- a/ToDo
+++ b/ToDo
@@ -2,10 +2,6 @@ Language Spec.
- Class#allocate - basicNew
- class Foo::Bar<Baz .. end, module Boo::Bar .. end
-- raise exception by `` error
-- a +1 to be a+1, not a(+1).
-- clarify evaluation order of operator argument (=~, .., ...)
-- :symbol => value hash in the form of {symbol: value, ...} ??
* operator !! for rescue. ???
* objectify characters
* ../... outside condition invokes operator method too.
@@ -18,6 +14,7 @@ Language Spec.
* def Class#method .. end ??
* def Foo::Bar::baz() .. end ??
* I18N (or M17N) script/string/regexp
+* Fixnum 0 as false ????
* discourage use of symbol variables (e.g. $/, etc.) in manual
* discourage use of Perlish features by giving warnings.
* non confusing in-block local variable (is it possible?)
@@ -25,9 +22,12 @@ Language Spec.
+ variables appears within block may have independent values.
* Regexp: make /o thread safe.
* decide whether begin with rescue or ensure make do..while loop.
+* a +1 to be a+1, not a(+1).
* unify == and eql? again
* to_i returns nil if str contains no digit.
+* raise exception by `` error
* jar like combined library package. -> RubyGems?
+* resumable Exception via Exception#resume.
* method combination, e.g. before, after, around, etc.
* .. or something like defadvice in Emacs.
* property - for methods, or for objects in general.
@@ -35,6 +35,8 @@ Language Spec.
* selector namespace - something like generic-flet in CLOS, to help RubyBehavior
* private instance variable (as in Python?) @_foo in class Foo => @_Foo_foo
* warn/error "bare word" method, like "foo", you should type "foo()"
+* clarify evaluation order of operator argument (=~, .., ...)
+* :symbol => value hash in the form of {symbol: value, ...} ??
Hacking Interpreter
@@ -81,7 +83,7 @@ Standard Libraries
- use Mersenne Twister RNG for random.
- deprecate Array#indexes, and Array#indices.
- remove dependency on MAXPATHLEN.
-- String#scanf(?)
+* String#scanf(?)
* Object#fmt(?)
* Time::strptime
* Integer[num], Float[num]; Fixnum[num]?
@@ -115,7 +117,7 @@ Extension Libraries
Ruby Libraries
-- urllib.rb, nttplib.rb, etc.
+* urllib.rb, nttplib.rb, etc.
* format like perl's
Tools
diff --git a/array.c b/array.c
index 18d8f84580..503a7adba3 100644
--- a/array.c
+++ b/array.c
@@ -15,16 +15,17 @@
#include "ruby.h"
#include "util.h"
#include "st.h"
-#include "node.h"
VALUE rb_cArray;
-
static ID id_cmp;
#define ARY_DEFAULT_SIZE 16
+#define ARY_MAX_SIZE (LONG_MAX / sizeof(VALUE))
void
-rb_mem_clear(register VALUE *mem, register long size)
+rb_mem_clear(mem, size)
+ register VALUE *mem;
+ register long size;
{
while (size--) {
*mem++ = Qnil;
@@ -32,34 +33,21 @@ rb_mem_clear(register VALUE *mem, register long size)
}
static inline void
-memfill(register VALUE *mem, register long size, register VALUE val)
+memfill(mem, size, val)
+ register VALUE *mem;
+ register long size;
+ register VALUE val;
{
while (size--) {
*mem++ = val;
}
}
-#define ARY_TMPLOCK FL_USER1
-#define ARY_SHARED_P(a) FL_TEST(a, ELTS_SHARED)
-
-#define ARY_SET_LEN(ary, n) do { \
- RARRAY(ary)->len = (n);\
-} while (0)
-
-#define ARY_CAPA(ary) RARRAY(ary)->aux.capa
-#define RESIZE_CAPA(ary,capacity) do {\
- REALLOC_N(RARRAY(ary)->ptr, VALUE, (capacity));\
- RARRAY(ary)->aux.capa = (capacity);\
-} while (0)
-
-static VALUE *
-rb_ary_ptr(VALUE ary)
-{
- return RARRAY_PTR(ary);
-}
+#define ARY_TMPLOCK FL_USER1
static inline void
-rb_ary_modify_check(VALUE ary)
+rb_ary_modify_check(ary)
+ VALUE ary;
{
if (OBJ_FROZEN(ary)) rb_error_frozen("array");
if (FL_TEST(ary, ARY_TMPLOCK))
@@ -69,22 +57,24 @@ rb_ary_modify_check(VALUE ary)
}
static void
-rb_ary_modify(VALUE ary)
+rb_ary_modify(ary)
+ VALUE ary;
{
VALUE *ptr;
rb_ary_modify_check(ary);
- if (ARY_SHARED_P(ary)) {
- ptr = ALLOC_N(VALUE, RARRAY_LEN(ary));
+ if (FL_TEST(ary, ELTS_SHARED)) {
+ ptr = ALLOC_N(VALUE, RARRAY(ary)->len);
FL_UNSET(ary, ELTS_SHARED);
- RARRAY(ary)->aux.capa = RARRAY_LEN(ary);
- MEMCPY(ptr, RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary));
+ RARRAY(ary)->aux.capa = RARRAY(ary)->len;
+ MEMCPY(ptr, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
RARRAY(ary)->ptr = ptr;
}
}
VALUE
-rb_ary_freeze(VALUE ary)
+rb_ary_freeze(ary)
+ VALUE ary;
{
return rb_obj_freeze(ary);
}
@@ -98,15 +88,18 @@ rb_ary_freeze(VALUE ary)
*/
static VALUE
-rb_ary_frozen_p(VALUE ary)
+rb_ary_frozen_p(ary)
+ VALUE ary;
{
if (OBJ_FROZEN(ary)) return Qtrue;
if (FL_TEST(ary, ARY_TMPLOCK)) return Qtrue;
return Qfalse;
}
+static VALUE ary_alloc _((VALUE));
static VALUE
-ary_alloc(VALUE klass)
+ary_alloc(klass)
+ VALUE klass;
{
NEWOBJ(ary, struct RArray);
OBJSETUP(ary, klass, T_ARRAY);
@@ -119,17 +112,18 @@ ary_alloc(VALUE klass)
}
static VALUE
-ary_new(VALUE klass, long len)
+ary_new(klass, len)
+ VALUE klass;
+ long len;
{
- VALUE ary;
+ VALUE ary = ary_alloc(klass);
if (len < 0) {
rb_raise(rb_eArgError, "negative array size (or size too big)");
}
- if (len > 0 && len * sizeof(VALUE) <= len) {
+ if (len > ARY_MAX_SIZE) {
rb_raise(rb_eArgError, "array size too big");
}
- ary = ary_alloc(klass);
if (len == 0) len++;
RARRAY(ary)->ptr = ALLOC_N(VALUE, len);
RARRAY(ary)->aux.capa = len;
@@ -138,22 +132,35 @@ ary_new(VALUE klass, long len)
}
VALUE
-rb_ary_new2(long len)
+rb_ary_new2(len)
+ long len;
{
return ary_new(rb_cArray, len);
}
VALUE
-rb_ary_new(void)
+rb_ary_new()
{
return rb_ary_new2(ARY_DEFAULT_SIZE);
}
+#ifdef HAVE_STDARG_PROTOTYPES
#include <stdarg.h>
+#define va_init_list(a,b) va_start(a,b)
+#else
+#include <varargs.h>
+#define va_init_list(a,b) va_start(a)
+#endif
VALUE
+#ifdef HAVE_STDARG_PROTOTYPES
rb_ary_new3(long n, ...)
+#else
+rb_ary_new3(n, va_alist)
+ long n;
+ va_dcl
+#endif
{
va_list ar;
VALUE ary;
@@ -161,9 +168,9 @@ rb_ary_new3(long n, ...)
ary = rb_ary_new2(n);
- va_start(ar, n);
+ va_init_list(ar, n);
for (i=0; i<n; i++) {
- RARRAY_PTR(ary)[i] = va_arg(ar, VALUE);
+ RARRAY(ary)->ptr[i] = va_arg(ar, VALUE);
}
va_end(ar);
@@ -172,72 +179,52 @@ rb_ary_new3(long n, ...)
}
VALUE
-rb_ary_new4(long n, const VALUE *elts)
+rb_ary_new4(n, elts)
+ long n;
+ const VALUE *elts;
{
VALUE ary;
ary = rb_ary_new2(n);
if (n > 0 && elts) {
- MEMCPY(RARRAY_PTR(ary), elts, VALUE, n);
- RARRAY(ary)->len = n;
+ MEMCPY(RARRAY(ary)->ptr, elts, VALUE, n);
}
- return ary;
-}
+ /* This assignment to len will be moved to the above "if" block in Ruby 1.9 */
+ RARRAY(ary)->len = n;
-void
-rb_ary_free(VALUE ary)
-{
- if (!ARY_SHARED_P(ary)) {
- xfree(RARRAY(ary)->ptr);
- }
+ return ary;
}
-static VALUE
-ary_make_shared(VALUE ary)
+VALUE
+rb_assoc_new(car, cdr)
+ VALUE car, cdr;
{
- if (ARY_SHARED_P(ary)) {
- return RARRAY(ary)->aux.shared;
- }
- else {
- NEWOBJ(shared, struct RArray);
- OBJSETUP(shared, 0, T_ARRAY);
+ VALUE ary;
- shared->len = RARRAY(ary)->len;
- shared->ptr = RARRAY(ary)->ptr;
- shared->aux.capa = RARRAY(ary)->aux.capa;
- RARRAY(ary)->aux.shared = (VALUE)shared;
- FL_SET(ary, ELTS_SHARED);
- OBJ_FREEZE(shared);
- return (VALUE)shared;
- }
-}
+ ary = rb_ary_new2(2);
+ RARRAY(ary)->ptr[0] = car;
+ RARRAY(ary)->ptr[1] = cdr;
+ RARRAY(ary)->len = 2;
-VALUE
-rb_assoc_new(VALUE car, VALUE cdr)
-{
- return rb_ary_new3(2, car, cdr);
+ return ary;
}
static VALUE
-to_ary(VALUE ary)
+to_ary(ary)
+ VALUE ary;
{
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
}
-static VALUE
-to_a(VALUE ary)
-{
- return rb_convert_type(ary, T_ARRAY, "Array", "to_a");
-}
-
VALUE
-rb_check_array_type(VALUE ary)
+rb_check_array_type(ary)
+ VALUE ary;
{
return rb_check_convert_type(ary, T_ARRAY, "Array", "to_ary");
}
-static VALUE rb_ary_replace(VALUE, VALUE);
+static VALUE rb_ary_replace _((VALUE, VALUE));
/*
* call-seq:
@@ -278,16 +265,16 @@ static VALUE rb_ary_replace(VALUE, VALUE);
*/
static VALUE
-rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
+rb_ary_initialize(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
long len;
VALUE size, val;
rb_ary_modify(ary);
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
- if (RARRAY_PTR(ary) && !ARY_SHARED_P(ary)) {
- free(RARRAY(ary)->ptr);
- }
RARRAY(ary)->len = 0;
if (rb_block_given_p()) {
rb_warning("given block not used");
@@ -307,11 +294,13 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
if (len < 0) {
rb_raise(rb_eArgError, "negative array size");
}
- if (len > 0 && len * (long)sizeof(VALUE) <= len) {
+ if (len > ARY_MAX_SIZE) {
rb_raise(rb_eArgError, "array size too big");
}
- rb_ary_modify(ary);
- RESIZE_CAPA(ary, len);
+ if (len > RARRAY(ary)->aux.capa) {
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
+ RARRAY(ary)->aux.capa = len;
+ }
if (rb_block_given_p()) {
long i;
@@ -324,9 +313,10 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
}
}
else {
- memfill(RARRAY_PTR(ary), len, val);
+ memfill(RARRAY(ary)->ptr, len, val);
RARRAY(ary)->len = len;
}
+
return ary;
}
@@ -340,95 +330,62 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
*/
static VALUE
-rb_ary_s_create(int argc, VALUE *argv, VALUE klass)
+rb_ary_s_create(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE ary = ary_alloc(klass);
- if (argc < 0) {
- rb_raise(rb_eArgError, "negative array size");
+ if (argc > 0) {
+ RARRAY(ary)->ptr = ALLOC_N(VALUE, argc);
+ MEMCPY(RARRAY(ary)->ptr, argv, VALUE, argc);
}
- RARRAY(ary)->ptr = ALLOC_N(VALUE, argc);
- RARRAY(ary)->aux.capa = argc;
- MEMCPY(RARRAY_PTR(ary), argv, VALUE, argc);
- RARRAY(ary)->len = argc;
+ RARRAY(ary)->len = RARRAY(ary)->aux.capa = argc;
return ary;
}
void
-rb_ary_store(VALUE ary, long idx, VALUE val)
+rb_ary_store(ary, idx, val)
+ VALUE ary;
+ long idx;
+ VALUE val;
{
if (idx < 0) {
- idx += RARRAY_LEN(ary);
+ idx += RARRAY(ary)->len;
if (idx < 0) {
rb_raise(rb_eIndexError, "index %ld out of array",
- idx - RARRAY_LEN(ary));
+ 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 >= ARY_CAPA(ary)) {
- long new_capa = ARY_CAPA(ary) / 2;
+ if (idx >= RARRAY(ary)->aux.capa) {
+ long new_capa = RARRAY(ary)->aux.capa / 2;
if (new_capa < ARY_DEFAULT_SIZE) {
new_capa = ARY_DEFAULT_SIZE;
}
- if (new_capa + idx < new_capa) {
- rb_raise(rb_eArgError, "index too big");
+ 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");
- }
- RESIZE_CAPA(ary, new_capa);
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, new_capa);
+ RARRAY(ary)->aux.capa = new_capa;
}
- if (idx > RARRAY_LEN(ary)) {
- rb_mem_clear(RARRAY_PTR(ary) + RARRAY_LEN(ary),
- idx-RARRAY_LEN(ary) + 1);
+ if (idx > RARRAY(ary)->len) {
+ rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len,
+ idx-RARRAY(ary)->len + 1);
}
- if (idx >= RARRAY_LEN(ary)) {
+ if (idx >= RARRAY(ary)->len) {
RARRAY(ary)->len = idx + 1;
}
- RARRAY_PTR(ary)[idx] = val;
-}
-
-static VALUE
-ary_shared_array(VALUE klass, VALUE ary)
-{
- VALUE val = ary_alloc(klass);
-
- ary_make_shared(ary);
- RARRAY(val)->ptr = RARRAY(ary)->ptr;
- RARRAY(val)->len = RARRAY(ary)->len;
- RARRAY(val)->aux.shared = RARRAY(ary)->aux.shared;
- FL_SET(val, ELTS_SHARED);
- return val;
-}
-
-static VALUE
-ary_shared_first(int argc, VALUE *argv, VALUE ary, int last)
-{
- VALUE nv, result;
- long n;
- long offset = 0;
-
- rb_scan_args(argc, argv, "1", &nv);
- n = NUM2LONG(nv);
- if (n > RARRAY_LEN(ary)) {
- n = RARRAY_LEN(ary);
- }
- else if (n < 0) {
- rb_raise(rb_eArgError, "negative array size");
- }
- if (last) {
- offset = RARRAY_LEN(ary) - n;
- }
- result = ary_shared_array(rb_cArray, ary);
- RARRAY(result)->ptr += offset;
- RARRAY(result)->len = n;
-
- return result;
+ RARRAY(ary)->ptr[idx] = val;
}
/*
@@ -445,9 +402,11 @@ ary_shared_first(int argc, VALUE *argv, VALUE ary, int last)
*/
VALUE
-rb_ary_push(VALUE ary, VALUE item)
+rb_ary_push(ary, item)
+ VALUE ary;
+ VALUE item;
{
- rb_ary_store(ary, RARRAY_LEN(ary), item);
+ rb_ary_store(ary, RARRAY(ary)->len, item);
return ary;
}
@@ -465,7 +424,10 @@ rb_ary_push(VALUE ary, VALUE item)
*/
static VALUE
-rb_ary_push_m(int argc, VALUE *argv, VALUE ary)
+rb_ary_push_m(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
while (argc--) {
rb_ary_push(ary, *argv++);
@@ -473,23 +435,6 @@ rb_ary_push_m(int argc, VALUE *argv, VALUE ary)
return ary;
}
-VALUE
-rb_ary_pop(VALUE ary)
-{
- long n;
- rb_ary_modify_check(ary);
- if (RARRAY_LEN(ary) == 0) return Qnil;
- if (!ARY_SHARED_P(ary) &&
- RARRAY_LEN(ary) * 3 < ARY_CAPA(ary) &&
- ARY_CAPA(ary) > ARY_DEFAULT_SIZE)
- {
- RESIZE_CAPA(ary, RARRAY_LEN(ary) * 2);
- }
- n = RARRAY_LEN(ary)-1;
- RARRAY(ary)->len = n;
- return RARRAY_PTR(ary)[n];
-}
-
/*
* call-seq:
* array.pop -> obj or nil
@@ -497,48 +442,45 @@ rb_ary_pop(VALUE ary)
* Removes the last element from <i>self</i> and returns it, or
* <code>nil</code> if the array is empty.
*
- * a = [ "a", "b", "c", "d" ]
- * a.pop #=> "d"
- * a.pop(2) #=> ["b", "c"]
- * a #=> ["a"]
+ * a = [ "a", "m", "z" ]
+ * a.pop #=> "z"
+ * a #=> ["a", "m"]
*/
-static VALUE
-rb_ary_pop_m(int argc, VALUE *argv, VALUE ary)
+VALUE
+rb_ary_pop(ary)
+ VALUE ary;
{
- VALUE result;
-
- if (argc == 0) {
- return rb_ary_pop(ary);
- }
-
rb_ary_modify_check(ary);
- result = ary_shared_first(argc, argv, ary, Qtrue);
- RARRAY(ary)->len -= RARRAY_LEN(result);
- return result;
+ if (RARRAY(ary)->len == 0) return Qnil;
+ if (!FL_TEST(ary, ELTS_SHARED) &&
+ RARRAY(ary)->len * 2 < RARRAY(ary)->aux.capa &&
+ RARRAY(ary)->aux.capa > ARY_DEFAULT_SIZE) {
+ RARRAY(ary)->aux.capa = RARRAY(ary)->len * 2;
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
+ }
+ return RARRAY(ary)->ptr[--RARRAY(ary)->len];
}
-VALUE
-rb_ary_shift(VALUE ary)
+static VALUE
+ary_make_shared(ary)
+ VALUE ary;
{
- VALUE top;
+ if (!FL_TEST(ary, ELTS_SHARED)) {
+ NEWOBJ(shared, struct RArray);
+ OBJSETUP(shared, rb_cArray, T_ARRAY);
- rb_ary_modify_check(ary);
- if (RARRAY_LEN(ary) == 0) return Qnil;
- top = RARRAY_PTR(ary)[0];
- if (!ARY_SHARED_P(ary)) {
- if (RARRAY_LEN(ary) < ARY_DEFAULT_SIZE) {
- MEMMOVE(RARRAY_PTR(ary), RARRAY_PTR(ary)+1, VALUE, RARRAY_LEN(ary)-1);
- RARRAY(ary)->len--;
- return top;
- }
- RARRAY_PTR(ary)[0] = Qnil;
- ary_make_shared(ary);
+ shared->len = RARRAY(ary)->len;
+ shared->ptr = RARRAY(ary)->ptr;
+ shared->aux.capa = RARRAY(ary)->aux.capa;
+ RARRAY(ary)->aux.shared = (VALUE)shared;
+ FL_SET(ary, ELTS_SHARED);
+ OBJ_FREEZE(shared);
+ return (VALUE)shared;
+ }
+ else {
+ return RARRAY(ary)->aux.shared;
}
- RARRAY(ary)->ptr++; /* shift ptr */
- RARRAY(ary)->len--;
-
- return top;
}
/*
@@ -550,37 +492,55 @@ rb_ary_shift(VALUE ary)
* is empty.
*
* args = [ "-m", "-q", "filename" ]
- * args.shift #=> "-m"
- * args #=> ["-q", "filename"]
- *
- * args = [ "-m", "-q", "filename" ]
- * args.shift(2) #=> ["-m", "-q"]
- * args #=> ["filename"]
+ * args.shift #=> "-m"
+ * args #=> ["-q", "filename"]
*/
-static VALUE
-rb_ary_shift_m(int argc, VALUE *argv, VALUE ary)
+VALUE
+rb_ary_shift(ary)
+ VALUE ary;
{
- VALUE result;
- long n;
-
- if (argc == 0) {
- return rb_ary_shift(ary);
- }
+ VALUE top;
rb_ary_modify_check(ary);
- result = ary_shared_first(argc, argv, ary, Qfalse);
- n = RARRAY_LEN(result);
- if (ARY_SHARED_P(ary)) {
- RARRAY(ary)->ptr += n;
- RARRAY(ary)->len -= n;
+ if (RARRAY(ary)->len == 0) return Qnil;
+ top = RARRAY(ary)->ptr[0];
+ if (RARRAY_LEN(ary) < ARY_DEFAULT_SIZE && !FL_TEST(ary, ELTS_SHARED)) {
+ MEMMOVE(RARRAY_PTR(ary), RARRAY_PTR(ary)+1, VALUE, RARRAY_LEN(ary)-1);
}
else {
- MEMMOVE(RARRAY_PTR(ary), RARRAY_PTR(ary)+n, VALUE, RARRAY_LEN(ary)-n);
- RARRAY(ary)->len -= n;
+ if (!FL_TEST(ary, ELTS_SHARED)) {
+ RARRAY(ary)->ptr[0] = Qnil;
+ }
+ ary_make_shared(ary);
+ RARRAY(ary)->ptr++; /* shift ptr */
+ }
+ RARRAY(ary)->len--;
+
+ return top;
+}
+
+VALUE
+rb_ary_unshift(ary, item)
+ VALUE ary, item;
+{
+ rb_ary_modify(ary);
+ if (RARRAY(ary)->len == RARRAY(ary)->aux.capa) {
+ long capa_inc = RARRAY(ary)->aux.capa / 2;
+ if (capa_inc < ARY_DEFAULT_SIZE) {
+ capa_inc = ARY_DEFAULT_SIZE;
+ }
+ RARRAY(ary)->aux.capa += capa_inc;
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
}
- return result;
+ /* sliding items */
+ MEMMOVE(RARRAY(ary)->ptr + 1, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
+
+ RARRAY(ary)->len++;
+ RARRAY(ary)->ptr[0] = item;
+
+ return ary;
}
/*
@@ -596,61 +556,62 @@ rb_ary_shift_m(int argc, VALUE *argv, VALUE ary)
*/
static VALUE
-rb_ary_unshift_m(int argc, VALUE *argv, VALUE ary)
+rb_ary_unshift_m(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
long len = RARRAY(ary)->len;
if (argc == 0) return ary;
- rb_ary_modify(ary);
- if (RARRAY(ary)->aux.capa <= RARRAY_LEN(ary)+argc) {
- RESIZE_CAPA(ary, RARRAY(ary)->aux.capa + ARY_DEFAULT_SIZE);
- }
+
+ /* make rooms by setting the last item */
+ rb_ary_store(ary, len + argc - 1, Qnil);
/* sliding items */
MEMMOVE(RARRAY(ary)->ptr + argc, RARRAY(ary)->ptr, VALUE, len);
MEMCPY(RARRAY(ary)->ptr, argv, VALUE, argc);
- RARRAY(ary)->len += argc;
return ary;
}
-VALUE
-rb_ary_unshift(VALUE ary, VALUE item)
-{
- return rb_ary_unshift_m(1,&item,ary);
-}
-
/* faster version - use this if you don't need to treat negative offset */
static inline VALUE
-rb_ary_elt(VALUE ary, long offset)
+rb_ary_elt(ary, offset)
+ VALUE ary;
+ long offset;
{
- if (RARRAY_LEN(ary) == 0) return Qnil;
- if (offset < 0 || RARRAY_LEN(ary) <= offset) {
+ if (RARRAY(ary)->len == 0) return Qnil;
+ if (offset < 0 || RARRAY(ary)->len <= offset) {
return Qnil;
}
- return RARRAY_PTR(ary)[offset];
+ return RARRAY(ary)->ptr[offset];
}
VALUE
-rb_ary_entry(VALUE ary, long offset)
+rb_ary_entry(ary, offset)
+ VALUE ary;
+ long offset;
{
if (offset < 0) {
- offset += RARRAY_LEN(ary);
+ offset += RARRAY(ary)->len;
}
return rb_ary_elt(ary, offset);
}
static VALUE
-rb_ary_subseq(VALUE ary, long beg, long len)
+rb_ary_subseq(ary, beg, len)
+ VALUE ary;
+ long beg, len;
{
VALUE klass, ary2, shared;
VALUE *ptr;
- if (beg > RARRAY_LEN(ary)) return Qnil;
+ if (beg > RARRAY(ary)->len) return Qnil;
if (beg < 0 || len < 0) return Qnil;
- if (beg + len > RARRAY_LEN(ary)) {
- len = RARRAY_LEN(ary) - beg;
+ if (RARRAY(ary)->len < len || RARRAY(ary)->len < beg + len) {
+ len = RARRAY(ary)->len - beg;
if (len < 0)
len = 0;
}
@@ -658,7 +619,7 @@ rb_ary_subseq(VALUE ary, long beg, long len)
if (len == 0) return ary_new(klass, 0);
shared = ary_make_shared(ary);
- ptr = RARRAY_PTR(ary);
+ ptr = RARRAY(ary)->ptr;
ary2 = ary_alloc(klass);
RARRAY(ary2)->ptr = ptr + beg;
RARRAY(ary2)->len = len;
@@ -701,16 +662,22 @@ rb_ary_subseq(VALUE ary, long beg, long len)
*/
VALUE
-rb_ary_aref(int argc, VALUE *argv, VALUE ary)
+rb_ary_aref(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
VALUE arg;
long beg, len;
if (argc == 2) {
+ if (SYMBOL_P(argv[0])) {
+ rb_raise(rb_eTypeError, "Symbol as array index");
+ }
beg = NUM2LONG(argv[0]);
len = NUM2LONG(argv[1]);
if (beg < 0) {
- beg += RARRAY_LEN(ary);
+ beg += RARRAY(ary)->len;
}
return rb_ary_subseq(ary, beg, len);
}
@@ -722,8 +689,11 @@ rb_ary_aref(int argc, VALUE *argv, VALUE ary)
if (FIXNUM_P(arg)) {
return rb_ary_entry(ary, FIX2LONG(arg));
}
+ if (SYMBOL_P(arg)) {
+ rb_raise(rb_eTypeError, "Symbol as array index");
+ }
/* check if idx is Range */
- switch (rb_range_beg_len(arg, &beg, &len, RARRAY_LEN(ary), 0)) {
+ switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) {
case Qfalse:
break;
case Qnil:
@@ -750,34 +720,49 @@ rb_ary_aref(int argc, VALUE *argv, VALUE ary)
*/
static VALUE
-rb_ary_at(VALUE ary, VALUE pos)
+rb_ary_at(ary, pos)
+ VALUE ary, pos;
{
return rb_ary_entry(ary, NUM2LONG(pos));
}
/*
* call-seq:
- * array.first -> obj or nil
- * array.first(n) -> an_array
+ * array.first -> obj or nil
+ * array.first(n) -> an_array
*
* Returns the first element, or the first +n+ elements, of the array.
* If the array is empty, the first form returns <code>nil</code>, and the
* second form returns an empty array.
- *
+ *
* a = [ "q", "r", "s", "t" ]
- * a.first #=> "q"
- * a.first(2) #=> ["q", "r"]
+ * a.first #=> "q"
+ * a.first(1) #=> ["q"]
+ * a.first(3) #=> ["q", "r", "s"]
*/
static VALUE
-rb_ary_first(int argc, VALUE *argv, VALUE ary)
+rb_ary_first(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
if (argc == 0) {
- if (RARRAY_LEN(ary) == 0) return Qnil;
- return RARRAY_PTR(ary)[0];
+ if (RARRAY(ary)->len == 0) return Qnil;
+ return RARRAY(ary)->ptr[0];
}
else {
- return ary_shared_first(argc, argv, ary, Qfalse);
+ VALUE nv, result;
+ long n, i;
+
+ rb_scan_args(argc, argv, "01", &nv);
+ n = NUM2LONG(nv);
+ if (n > RARRAY(ary)->len) n = RARRAY(ary)->len;
+ result = rb_ary_new2(n);
+ for (i=0; i<n; i++) {
+ rb_ary_push(result, RARRAY(ary)->ptr[i]);
+ }
+ return result;
}
}
@@ -789,20 +774,31 @@ rb_ary_first(int argc, VALUE *argv, VALUE ary)
* Returns the last element(s) of <i>self</i>. If the array is empty,
* the first form returns <code>nil</code>.
*
- * a = [ "w", "x", "y", "z" ]
- * a.last #=> "z"
- * a.last(2) #=> ["y", "z"]
+ * [ "w", "x", "y", "z" ].last #=> "z"
*/
static VALUE
-rb_ary_last(int argc, VALUE *argv, VALUE ary)
+rb_ary_last(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
if (argc == 0) {
- if (RARRAY_LEN(ary) == 0) return Qnil;
- return RARRAY_PTR(ary)[RARRAY_LEN(ary)-1];
+ if (RARRAY(ary)->len == 0) return Qnil;
+ return RARRAY(ary)->ptr[RARRAY(ary)->len-1];
}
else {
- return ary_shared_first(argc, argv, ary, Qtrue);
+ VALUE nv, result;
+ long n, i;
+
+ rb_scan_args(argc, argv, "01", &nv);
+ n = NUM2LONG(nv);
+ if (n > RARRAY(ary)->len) n = RARRAY(ary)->len;
+ result = rb_ary_new2(n);
+ for (i=RARRAY(ary)->len-n; n--; i++) {
+ rb_ary_push(result, RARRAY(ary)->ptr[i]);
+ }
+ return result;
}
}
@@ -827,7 +823,10 @@ rb_ary_last(int argc, VALUE *argv, VALUE ary)
*/
static VALUE
-rb_ary_fetch(int argc, VALUE *argv, VALUE ary)
+rb_ary_fetch(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
VALUE pos, ifnone;
long block_given;
@@ -841,53 +840,41 @@ rb_ary_fetch(int argc, VALUE *argv, VALUE ary)
idx = NUM2LONG(pos);
if (idx < 0) {
- idx += RARRAY_LEN(ary);
+ idx += RARRAY(ary)->len;
}
- if (idx < 0 || RARRAY_LEN(ary) <= idx) {
+ if (idx < 0 || RARRAY(ary)->len <= idx) {
if (block_given) return rb_yield(pos);
if (argc == 1) {
rb_raise(rb_eIndexError, "index %ld out of array", idx);
}
return ifnone;
}
- return RARRAY_PTR(ary)[idx];
+ return RARRAY(ary)->ptr[idx];
}
/*
* call-seq:
- * array.index(obj) -> int or nil
- * array.index {|item| block} -> int or nil
+ * array.index(obj) -> int or nil
*
- * Returns the index of the first object in <i>self</i> such that is
- * <code>==</code> to <i>obj</i>. If a block is given instead of an
- * argument, returns first object for which <em>block</em> is true.
- * Returns <code>nil</code> if no match is found.
+ * Returns the index of the first object in <i>self</i> such that is
+ * <code>==</code> to <i>obj</i>. Returns <code>nil</code> if
+ * no match is found.
*
* a = [ "a", "b", "c" ]
- * a.index("b") #=> 1
- * a.index("z") #=> nil
- * a.index{|x|x=="b"} #=> 1
+ * a.index("b") #=> 1
+ * a.index("z") #=> nil
*/
static VALUE
-rb_ary_index(int argc, VALUE *argv, VALUE ary)
-{
+rb_ary_index(ary, val)
+ VALUE ary;
VALUE val;
+{
long i;
- if (rb_scan_args(argc, argv, "01", &val) == 0) {
- RETURN_ENUMERATOR(ary, 0, 0);
- for (i=0; i<RARRAY_LEN(ary); i++) {
- if (RTEST(rb_yield(RARRAY_PTR(ary)[i]))) {
- return LONG2NUM(i);
- }
- }
- }
- else {
- for (i=0; i<RARRAY_LEN(ary); i++) {
- if (rb_equal(RARRAY_PTR(ary)[i], val))
- return LONG2NUM(i);
- }
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ if (rb_equal(RARRAY(ary)->ptr[i], val))
+ return LONG2NUM(i);
}
return Qnil;
}
@@ -896,112 +883,136 @@ rb_ary_index(int argc, VALUE *argv, VALUE ary)
* call-seq:
* array.rindex(obj) -> int or nil
*
- * Returns the index of the last object in <i>array</i>
- * <code>==</code> to <i>obj</i>. If a block is given instead of an
- * argument, returns first object for which <em>block</em> is
- * true. Returns <code>nil</code> if no match is found.
+ * Returns the index of the last object in <i>array</i>
+ * <code>==</code> to <i>obj</i>. Returns <code>nil</code> if
+ * no match is found.
*
* a = [ "a", "b", "b", "b", "c" ]
- * a.rindex("b") #=> 3
- * a.rindex("z") #=> nil
- * a.rindex{|x|x=="b"} #=> 3
+ * a.rindex("b") #=> 3
+ * a.rindex("z") #=> nil
*/
static VALUE
-rb_ary_rindex(int argc, VALUE *argv, VALUE ary)
-{
+rb_ary_rindex(ary, val)
+ VALUE ary;
VALUE val;
- long i = RARRAY_LEN(ary);
-
- if (rb_scan_args(argc, argv, "01", &val) == 0) {
- while (i--) {
- RETURN_ENUMERATOR(ary, 0, 0);
- if (RTEST(rb_yield(RARRAY_PTR(ary)[i])))
- return LONG2NUM(i);
- if (i > RARRAY_LEN(ary)) {
- i = RARRAY_LEN(ary);
- }
- }
- }
- else {
- while (i--) {
- if (rb_equal(RARRAY_PTR(ary)[i], val))
- return LONG2NUM(i);
- if (i > RARRAY_LEN(ary)) {
- i = RARRAY_LEN(ary);
- }
+{
+ long i = RARRAY(ary)->len;
+
+ while (i--) {
+ if (i > RARRAY(ary)->len) {
+ i = RARRAY(ary)->len;
+ continue;
}
+ if (rb_equal(RARRAY(ary)->ptr[i], val))
+ return LONG2NUM(i);
}
return Qnil;
}
+/*
+ * call-seq:
+ * array.indexes( i1, i2, ... iN ) -> an_array
+ * array.indices( i1, i2, ... iN ) -> an_array
+ *
+ * Deprecated; use <code>Array#values_at</code>.
+ */
+
+static VALUE
+rb_ary_indexes(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
+{
+ VALUE new_ary;
+ long i;
+
+ rb_warn("Array#%s is deprecated; use Array#values_at", rb_id2name(rb_frame_last_func()));
+ new_ary = rb_ary_new2(argc);
+ for (i=0; i<argc; i++) {
+ rb_ary_push(new_ary, rb_ary_aref(1, argv+i, ary));
+ }
+
+ return new_ary;
+}
+
VALUE
-rb_ary_to_ary(VALUE obj)
+rb_ary_to_ary(obj)
+ VALUE obj;
{
if (TYPE(obj) == T_ARRAY) {
return obj;
}
if (rb_respond_to(obj, rb_intern("to_ary"))) {
- return to_ary(obj);
+ return rb_convert_type(obj, T_ARRAY, "Array", "to_ary");
}
return rb_ary_new3(1, obj);
}
static void
-rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
+rb_ary_splice(ary, beg, len, rpl)
+ VALUE ary;
+ long beg, len;
+ VALUE rpl;
{
long rlen;
if (len < 0) rb_raise(rb_eIndexError, "negative length (%ld)", len);
if (beg < 0) {
- beg += RARRAY_LEN(ary);
+ beg += RARRAY(ary)->len;
if (beg < 0) {
- beg -= RARRAY_LEN(ary);
+ beg -= RARRAY(ary)->len;
rb_raise(rb_eIndexError, "index %ld out of array", beg);
}
}
- if (beg + len > RARRAY_LEN(ary)) {
- len = RARRAY_LEN(ary) - beg;
+ if (RARRAY(ary)->len < len || RARRAY(ary)->len < beg + len) {
+ len = RARRAY(ary)->len - beg;
}
- if (rpl == Qundef) {
+ if (NIL_P(rpl)) {
rlen = 0;
}
else {
rpl = rb_ary_to_ary(rpl);
- rlen = RARRAY_LEN(rpl);
+ rlen = RARRAY(rpl)->len;
}
rb_ary_modify(ary);
- if (beg >= RARRAY_LEN(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 >= ARY_CAPA(ary)) {
- RESIZE_CAPA(ary, len);
+ if (len >= RARRAY(ary)->aux.capa) {
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
+ RARRAY(ary)->aux.capa = len;
}
- rb_mem_clear(RARRAY_PTR(ary) + RARRAY_LEN(ary), beg - RARRAY_LEN(ary));
+ rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len, beg - RARRAY(ary)->len);
if (rlen > 0) {
- MEMCPY(RARRAY_PTR(ary) + beg, RARRAY_PTR(rpl), VALUE, rlen);
+ MEMCPY(RARRAY(ary)->ptr + beg, RARRAY(rpl)->ptr, VALUE, rlen);
}
RARRAY(ary)->len = len;
}
else {
long alen;
- if (beg + len > RARRAY_LEN(ary)) {
- len = RARRAY_LEN(ary) - beg;
+ if (beg + len > RARRAY(ary)->len) {
+ len = RARRAY(ary)->len - beg;
}
- alen = RARRAY_LEN(ary) + rlen - len;
- if (alen >= ARY_CAPA(ary)) {
- RESIZE_CAPA(ary, alen);
+ alen = RARRAY(ary)->len + rlen - len;
+ if (alen >= RARRAY(ary)->aux.capa) {
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, alen);
+ RARRAY(ary)->aux.capa = alen;
}
if (len != rlen) {
- MEMMOVE(RARRAY_PTR(ary) + beg + rlen, RARRAY_PTR(ary) + beg + len,
- VALUE, RARRAY_LEN(ary) - (beg + len));
+ MEMMOVE(RARRAY(ary)->ptr + beg + rlen, RARRAY(ary)->ptr + beg + len,
+ VALUE, RARRAY(ary)->len - (beg + len));
RARRAY(ary)->len = alen;
}
if (rlen > 0) {
- MEMMOVE(RARRAY_PTR(ary) + beg, RARRAY_PTR(rpl), VALUE, rlen);
+ MEMMOVE(RARRAY(ary)->ptr + beg, RARRAY(rpl)->ptr, VALUE, rlen);
}
}
}
@@ -1019,8 +1030,9 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
* the current capacity of the array, the array grows
* automatically. A negative indices will count backward
* from the end of the array. Inserts elements if _length_ is
- * zero. An +IndexError+ is raised if a negative index points
- * past the beginning of the array. See also
+ * zero. If +nil+ is used in the second and third form,
+ * deletes elements from _self_. An +IndexError+ is raised if a
+ * negative index points past the beginning of the array. See also
* <code>Array#push</code>, and <code>Array#unshift</code>.
*
* a = Array.new
@@ -1030,16 +1042,24 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
* a[0, 2] = "?" #=> ["?", 2, nil, "4"]
* a[0..2] = "A" #=> ["A", "4"]
* a[-1] = "Z" #=> ["A", "Z"]
- * a[1..-1] = nil #=> ["A", nil]
- * a[1..-1] = [] #=> ["A"]
+ * a[1..-1] = nil #=> ["A"]
*/
static VALUE
-rb_ary_aset(int argc, VALUE *argv, VALUE ary)
+rb_ary_aset(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
long offset, beg, len;
if (argc == 3) {
+ if (SYMBOL_P(argv[0])) {
+ rb_raise(rb_eTypeError, "Symbol as array index");
+ }
+ if (SYMBOL_P(argv[1])) {
+ rb_raise(rb_eTypeError, "Symbol as subarray length");
+ }
rb_ary_splice(ary, NUM2LONG(argv[0]), NUM2LONG(argv[1]), argv[2]);
return argv[2];
}
@@ -1050,7 +1070,10 @@ rb_ary_aset(int argc, VALUE *argv, VALUE ary)
offset = FIX2LONG(argv[0]);
goto fixnum;
}
- if (rb_range_beg_len(argv[0], &beg, &len, RARRAY_LEN(ary), 1)) {
+ if (SYMBOL_P(argv[0])) {
+ rb_raise(rb_eTypeError, "Symbol as array index");
+ }
+ if (rb_range_beg_len(argv[0], &beg, &len, RARRAY(ary)->len, 1)) {
/* check if idx is Range */
rb_ary_splice(ary, beg, len, argv[1]);
return argv[1];
@@ -1075,7 +1098,10 @@ fixnum:
*/
static VALUE
-rb_ary_insert(int argc, VALUE *argv, VALUE ary)
+rb_ary_insert(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
long pos;
@@ -1085,7 +1111,7 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary)
}
pos = NUM2LONG(argv[0]);
if (pos == -1) {
- pos = RARRAY_LEN(ary);
+ pos = RARRAY(ary)->len;
}
if (pos < 0) {
pos++;
@@ -1110,13 +1136,13 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary)
*/
VALUE
-rb_ary_each(VALUE ary)
+rb_ary_each(ary)
+ VALUE ary;
{
long i;
- RETURN_ENUMERATOR(ary, 0, 0);
- for (i=0; i<RARRAY_LEN(ary); i++) {
- rb_yield(RARRAY_PTR(ary)[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ rb_yield(RARRAY(ary)->ptr[i]);
}
return ary;
}
@@ -1137,12 +1163,12 @@ rb_ary_each(VALUE ary)
*/
static VALUE
-rb_ary_each_index(VALUE ary)
+rb_ary_each_index(ary)
+ VALUE ary;
{
long i;
- RETURN_ENUMERATOR(ary, 0, 0);
- for (i=0; i<RARRAY_LEN(ary); i++) {
+ for (i=0; i<RARRAY(ary)->len; i++) {
rb_yield(LONG2NUM(i));
}
return ary;
@@ -1164,15 +1190,15 @@ rb_ary_each_index(VALUE ary)
*/
static VALUE
-rb_ary_reverse_each(VALUE ary)
+rb_ary_reverse_each(ary)
+ VALUE ary;
{
- long len = RARRAY_LEN(ary);
+ long len = RARRAY(ary)->len;
- RETURN_ENUMERATOR(ary, 0, 0);
while (len--) {
- rb_yield(RARRAY_PTR(ary)[len]);
- if (RARRAY_LEN(ary) < len) {
- len = RARRAY_LEN(ary);
+ rb_yield(RARRAY(ary)->ptr[len]);
+ if (RARRAY(ary)->len < len) {
+ len = RARRAY(ary)->len;
}
}
return ary;
@@ -1188,10 +1214,10 @@ rb_ary_reverse_each(VALUE ary)
*/
static VALUE
-rb_ary_length(VALUE ary)
+rb_ary_length(ary)
+ VALUE ary;
{
- long len = RARRAY_LEN(ary);
- return LONG2NUM(len);
+ return LONG2NUM(RARRAY(ary)->len);
}
/*
@@ -1204,68 +1230,71 @@ rb_ary_length(VALUE ary)
*/
static VALUE
-rb_ary_empty_p(VALUE ary)
+rb_ary_empty_p(ary)
+ VALUE ary;
{
- if (RARRAY_LEN(ary) == 0)
+ if (RARRAY(ary)->len == 0)
return Qtrue;
return Qfalse;
}
VALUE
-rb_ary_dup(VALUE ary)
+rb_ary_dup(ary)
+ VALUE ary;
{
- VALUE dup = rb_ary_new2(RARRAY_LEN(ary));
-
- MEMCPY(RARRAY_PTR(dup), RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary));
- RARRAY(dup)->len = RARRAY_LEN(ary);
- OBJ_INFECT(dup, ary);
+ VALUE dup = rb_ary_new2(RARRAY(ary)->len);
+ DUPSETUP(dup, ary);
+ MEMCPY(RARRAY(dup)->ptr, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
+ RARRAY(dup)->len = RARRAY(ary)->len;
return dup;
}
extern VALUE rb_output_fs;
static VALUE
-recursive_join(VALUE ary, VALUE argp, int recur)
+inspect_join(ary, arg)
+ VALUE ary;
+ VALUE *arg;
{
- VALUE *arg = (VALUE *)argp;
- if (recur) {
- return rb_str_new2("[...]");
- }
return rb_ary_join(arg[0], arg[1]);
}
VALUE
-rb_ary_join(VALUE ary, VALUE sep)
+rb_ary_join(ary, sep)
+ VALUE ary, sep;
{
long len = 1, i;
int taint = Qfalse;
VALUE result, tmp;
- if (RARRAY_LEN(ary) == 0) return rb_str_new(0, 0);
+ if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
if (OBJ_TAINTED(ary) || OBJ_TAINTED(sep)) taint = Qtrue;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- tmp = rb_check_string_type(RARRAY_PTR(ary)[i]);
- len += NIL_P(tmp) ? 10 : RSTRING_LEN(tmp);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ tmp = rb_check_string_type(RARRAY(ary)->ptr[i]);
+ len += NIL_P(tmp) ? 10 : RSTRING(tmp)->len;
}
if (!NIL_P(sep)) {
StringValue(sep);
- len += RSTRING_LEN(sep) * (RARRAY_LEN(ary) - 1);
+ len += RSTRING(sep)->len * (RARRAY(ary)->len - 1);
}
result = rb_str_buf_new(len);
- for (i=0; i<RARRAY_LEN(ary); i++) {
- tmp = RARRAY_PTR(ary)[i];
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ tmp = RARRAY(ary)->ptr[i];
switch (TYPE(tmp)) {
case T_STRING:
break;
case T_ARRAY:
- {
+ if (rb_inspecting_p(tmp)) {
+ tmp = rb_str_new2("[...]");
+ }
+ else {
VALUE args[2];
args[0] = tmp;
args[1] = sep;
- tmp = rb_exec_recursive(recursive_join, ary, (VALUE)args);
+ tmp = rb_protect_inspect(inspect_join, ary, (VALUE)args);
}
break;
default:
@@ -1293,7 +1322,10 @@ rb_ary_join(VALUE ary, VALUE sep)
*/
static VALUE
-rb_ary_join_m(int argc, VALUE *argv, VALUE ary)
+rb_ary_join_m(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
VALUE sep;
@@ -1303,17 +1335,118 @@ rb_ary_join_m(int argc, VALUE *argv, VALUE ary)
return rb_ary_join(ary, sep);
}
+/*
+ * call-seq:
+ * array.to_s -> string
+ *
+ * Returns _self_<code>.join</code>.
+ *
+ * [ "a", "e", "i", "o" ].to_s #=> "aeio"
+ *
+ */
+
+VALUE
+rb_ary_to_s(ary)
+ VALUE ary;
+{
+ if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
+
+ return rb_ary_join(ary, rb_output_fs);
+}
+
+static ID inspect_key;
+
+struct inspect_arg {
+ VALUE (*func)();
+ VALUE arg1, arg2;
+};
+
+static VALUE
+inspect_call(arg)
+ struct inspect_arg *arg;
+{
+ return (*arg->func)(arg->arg1, arg->arg2);
+}
+
+static VALUE
+get_inspect_tbl(create)
+ int create;
+{
+ VALUE inspect_tbl = rb_thread_local_aref(rb_thread_current(), inspect_key);
+
+ if (NIL_P(inspect_tbl)) {
+ if (create) {
+ tbl_init:
+ inspect_tbl = rb_ary_new();
+ rb_thread_local_aset(rb_thread_current(), inspect_key, inspect_tbl);
+ }
+ }
+ else if (TYPE(inspect_tbl) != T_ARRAY) {
+ rb_warn("invalid inspect_tbl value");
+ if (create) goto tbl_init;
+ rb_thread_local_aset(rb_thread_current(), inspect_key, Qnil);
+ return Qnil;
+ }
+ return inspect_tbl;
+}
+
static VALUE
-inspect_ary(VALUE ary, VALUE dummy, int recur)
+inspect_ensure(obj)
+ VALUE obj;
+{
+ VALUE inspect_tbl;
+
+ inspect_tbl = get_inspect_tbl(Qfalse);
+ if (!NIL_P(inspect_tbl)) {
+ rb_ary_pop(inspect_tbl);
+ }
+ return 0;
+}
+
+VALUE
+rb_protect_inspect(func, obj, arg)
+ VALUE (*func)(ANYARGS);
+ VALUE obj, arg;
+{
+ struct inspect_arg iarg;
+ VALUE inspect_tbl;
+ VALUE id;
+
+ inspect_tbl = get_inspect_tbl(Qtrue);
+ id = rb_obj_id(obj);
+ if (rb_ary_includes(inspect_tbl, id)) {
+ return (*func)(obj, arg);
+ }
+ rb_ary_push(inspect_tbl, id);
+ iarg.func = func;
+ iarg.arg1 = obj;
+ iarg.arg2 = arg;
+
+ return rb_ensure(inspect_call, (VALUE)&iarg, inspect_ensure, obj);
+}
+
+VALUE
+rb_inspecting_p(obj)
+ VALUE obj;
+{
+ VALUE inspect_tbl;
+
+ inspect_tbl = get_inspect_tbl(Qfalse);
+ if (NIL_P(inspect_tbl)) return Qfalse;
+ return rb_ary_includes(inspect_tbl, rb_obj_id(obj));
+}
+
+static VALUE
+inspect_ary(ary)
+ VALUE ary;
{
int tainted = OBJ_TAINTED(ary);
long i;
VALUE s, str;
- if (recur) return rb_tainted_str_new2("[...]");
str = rb_str_buf_new2("[");
- for (i=0; i<RARRAY_LEN(ary); i++) {
- s = rb_inspect(RARRAY_PTR(ary)[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ s = rb_inspect(RARRAY(ary)->ptr[i]);
if (OBJ_TAINTED(s)) tainted = Qtrue;
if (i > 0) rb_str_buf_cat2(str, ", ");
rb_str_buf_append(str, s);
@@ -1325,23 +1458,18 @@ inspect_ary(VALUE ary, VALUE dummy, int recur)
/*
* call-seq:
- * array.to_s -> string
* array.inspect -> string
*
* Create a printable version of <i>array</i>.
*/
static VALUE
-rb_ary_inspect(VALUE ary)
-{
- if (RARRAY_LEN(ary) == 0) return rb_str_new2("[]");
- return rb_exec_recursive(inspect_ary, ary, 0);
-}
-
-VALUE
-rb_ary_to_s(VALUE ary)
+rb_ary_inspect(ary)
+ VALUE ary;
{
- return rb_ary_inspect(ary);
+ if (RARRAY(ary)->len == 0) return rb_str_new2("[]");
+ if (rb_inspecting_p(ary)) return rb_str_new2("[...]");
+ return rb_protect_inspect(inspect_ary, ary, 0);
}
/*
@@ -1353,10 +1481,11 @@ rb_ary_to_s(VALUE ary)
*/
static VALUE
-rb_ary_to_a(VALUE ary)
+rb_ary_to_a(ary)
+ VALUE ary;
{
if (rb_obj_class(ary) != rb_cArray) {
- VALUE dup = rb_ary_new2(RARRAY_LEN(ary));
+ VALUE dup = rb_ary_new2(RARRAY(ary)->len);
rb_ary_replace(dup, ary);
return dup;
}
@@ -1371,21 +1500,23 @@ rb_ary_to_a(VALUE ary)
*/
static VALUE
-rb_ary_to_ary_m(VALUE ary)
+rb_ary_to_ary_m(ary)
+ VALUE ary;
{
return ary;
}
VALUE
-rb_ary_reverse(VALUE ary)
+rb_ary_reverse(ary)
+ VALUE ary;
{
VALUE *p1, *p2;
VALUE tmp;
rb_ary_modify(ary);
- if (RARRAY_LEN(ary) > 1) {
- p1 = RARRAY_PTR(ary);
- p2 = p1 + RARRAY_LEN(ary) - 1; /* points last item */
+ if (RARRAY(ary)->len > 1) {
+ p1 = RARRAY(ary)->ptr;
+ p2 = p1 + RARRAY(ary)->len - 1; /* points last item */
while (p1 < p2) {
tmp = *p1;
@@ -1408,7 +1539,8 @@ rb_ary_reverse(VALUE ary)
*/
static VALUE
-rb_ary_reverse_bang(VALUE ary)
+rb_ary_reverse_bang(ary)
+ VALUE ary;
{
return rb_ary_reverse(ary);
}
@@ -1424,7 +1556,8 @@ rb_ary_reverse_bang(VALUE ary)
*/
static VALUE
-rb_ary_reverse_m(VALUE ary)
+rb_ary_reverse_m(ary)
+ VALUE ary;
{
return rb_ary_reverse(rb_ary_dup(ary));
}
@@ -1436,30 +1569,34 @@ struct ary_sort_data {
};
static void
-ary_sort_check(struct ary_sort_data *data)
+ary_sort_check(data)
+ struct ary_sort_data *data;
{
- if (RARRAY_PTR(data->ary) != data->ptr || RARRAY_LEN(data->ary) != data->len) {
- rb_raise(rb_eRuntimeError, "array modified during sort");
+ if (RARRAY(data->ary)->ptr != data->ptr || RARRAY(data->ary)->len != data->len) {
+ rb_raise(rb_eArgError, "array modified during sort");
}
}
static int
-sort_1(const void *ap, const void *bp, void *data)
+sort_1(a, b, data)
+ VALUE *a, *b;
+ struct ary_sort_data *data;
{
- VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
- VALUE retval = rb_yield_values(2, a, b);
+ VALUE retval = rb_yield_values(2, *a, *b);
int n;
- n = rb_cmpint(retval, a, b);
- ary_sort_check((struct ary_sort_data *)data);
+ n = rb_cmpint(retval, *a, *b);
+ ary_sort_check(data);
return n;
}
static int
-sort_2(const void *ap, const void *bp, void *data)
+sort_2(ap, bp, data)
+ VALUE *ap, *bp;
+ struct ary_sort_data *data;
{
VALUE retval;
- VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
+ VALUE a = *ap, b = *bp;
int n;
if (FIXNUM_P(a) && FIXNUM_P(b)) {
@@ -1473,25 +1610,27 @@ sort_2(const void *ap, const void *bp, void *data)
retval = rb_funcall(a, id_cmp, 1, b);
n = rb_cmpint(retval, a, b);
- ary_sort_check((struct ary_sort_data *)data);
+ ary_sort_check(data);
return n;
}
static VALUE
-sort_internal(VALUE ary)
+sort_internal(ary)
+ VALUE ary;
{
struct ary_sort_data data;
data.ary = ary;
- data.ptr = RARRAY_PTR(ary); data.len = RARRAY_LEN(ary);
- ruby_qsort(RARRAY_PTR(ary), RARRAY_LEN(ary), sizeof(VALUE),
- rb_block_given_p()?sort_1:sort_2, &data);
+ data.ptr = RARRAY(ary)->ptr; data.len = RARRAY(ary)->len;
+ qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
+ rb_block_given_p()?sort_1:sort_2, &data);
return ary;
}
static VALUE
-sort_unlock(VALUE ary)
+sort_unlock(ary)
+ VALUE ary;
{
FL_UNSET(ary, ARY_TMPLOCK);
return ary;
@@ -1514,10 +1653,11 @@ sort_unlock(VALUE ary)
*/
VALUE
-rb_ary_sort_bang(VALUE ary)
+rb_ary_sort_bang(ary)
+ VALUE ary;
{
rb_ary_modify(ary);
- if (RARRAY_LEN(ary) > 1) {
+ if (RARRAY(ary)->len > 1) {
FL_SET(ary, ARY_TMPLOCK); /* prohibit modification during sort */
rb_ensure(sort_internal, ary, sort_unlock, ary);
}
@@ -1541,7 +1681,8 @@ rb_ary_sort_bang(VALUE ary)
*/
VALUE
-rb_ary_sort(VALUE ary)
+rb_ary_sort(ary)
+ VALUE ary;
{
ary = rb_ary_dup(ary);
rb_ary_sort_bang(ary);
@@ -1563,15 +1704,19 @@ rb_ary_sort(VALUE ary)
*/
static VALUE
-rb_ary_collect(VALUE ary)
+rb_ary_collect(ary)
+ VALUE ary;
{
long i;
VALUE collect;
- RETURN_ENUMERATOR(ary, 0, 0);
- collect = rb_ary_new2(RARRAY_LEN(ary));
- for (i = 0; i < RARRAY_LEN(ary); i++) {
- rb_ary_push(collect, rb_yield(RARRAY_PTR(ary)[i]));
+ if (!rb_block_given_p()) {
+ return rb_ary_new4(RARRAY(ary)->len, RARRAY(ary)->ptr);
+ }
+
+ collect = rb_ary_new2(RARRAY(ary)->len);
+ for (i = 0; i < RARRAY(ary)->len; i++) {
+ rb_ary_push(collect, rb_yield(RARRAY(ary)->ptr[i]));
}
return collect;
}
@@ -1591,20 +1736,25 @@ rb_ary_collect(VALUE ary)
*/
static VALUE
-rb_ary_collect_bang(VALUE ary)
+rb_ary_collect_bang(ary)
+ VALUE ary;
{
long i;
- RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
- for (i = 0; i < RARRAY_LEN(ary); i++) {
- rb_ary_store(ary, i, rb_yield(RARRAY_PTR(ary)[i]));
+ for (i = 0; i < RARRAY(ary)->len; i++) {
+ rb_ary_store(ary, i, rb_yield(RARRAY(ary)->ptr[i]));
}
return ary;
}
VALUE
-rb_get_values_at(VALUE obj, long olen, int argc, VALUE *argv, VALUE (*func) (VALUE, long))
+rb_values_at(obj, olen, argc, argv, func)
+ VALUE obj;
+ long olen;
+ int argc;
+ VALUE *argv;
+ VALUE (*func) _((VALUE,long));
{
VALUE result = rb_ary_new2(argc);
long beg, len, i, j;
@@ -1648,9 +1798,12 @@ rb_get_values_at(VALUE obj, long olen, int argc, VALUE *argv, VALUE (*func) (VAL
*/
static VALUE
-rb_ary_values_at(int argc, VALUE *argv, VALUE ary)
+rb_ary_values_at(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
- return rb_get_values_at(ary, RARRAY_LEN(ary), argc, argv, rb_ary_entry);
+ return rb_values_at(ary, RARRAY(ary)->len, argc, argv, rb_ary_entry);
}
/*
@@ -1666,15 +1819,15 @@ rb_ary_values_at(int argc, VALUE *argv, VALUE ary)
*/
static VALUE
-rb_ary_select(VALUE ary)
+rb_ary_select(ary)
+ VALUE ary;
{
VALUE result;
long i;
- RETURN_ENUMERATOR(ary, 0, 0);
- result = rb_ary_new2(RARRAY_LEN(ary));
- for (i = 0; i < RARRAY_LEN(ary); i++) {
- if (RTEST(rb_yield(RARRAY_PTR(ary)[i]))) {
+ result = rb_ary_new2(RARRAY(ary)->len);
+ for (i = 0; i < RARRAY(ary)->len; i++) {
+ if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
rb_ary_push(result, rb_ary_elt(ary, i));
}
}
@@ -1699,12 +1852,14 @@ rb_ary_select(VALUE ary)
*/
VALUE
-rb_ary_delete(VALUE ary, VALUE item)
+rb_ary_delete(ary, item)
+ VALUE ary;
+ VALUE item;
{
long i1, i2;
- for (i1 = i2 = 0; i1 < RARRAY_LEN(ary); i1++) {
- VALUE e = RARRAY_PTR(ary)[i1];
+ for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
+ VALUE e = RARRAY(ary)->ptr[i1];
if (rb_equal(e, item)) continue;
if (i1 != i2) {
@@ -1712,7 +1867,7 @@ rb_ary_delete(VALUE ary, VALUE item)
}
i2++;
}
- if (RARRAY_LEN(ary) == i2) {
+ if (RARRAY(ary)->len == i2) {
if (rb_block_given_p()) {
return rb_yield(item);
}
@@ -1720,11 +1875,12 @@ rb_ary_delete(VALUE ary, VALUE item)
}
rb_ary_modify(ary);
- if (RARRAY_LEN(ary) > i2) {
+ if (RARRAY(ary)->len > i2) {
RARRAY(ary)->len = i2;
- if (i2 * 2 < ARY_CAPA(ary) &&
- ARY_CAPA(ary) > ARY_DEFAULT_SIZE) {
- RESIZE_CAPA(ary, i2*2);
+ if (i2 * 2 < RARRAY(ary)->aux.capa &&
+ RARRAY(ary)->aux.capa > ARY_DEFAULT_SIZE) {
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, i2 * 2);
+ RARRAY(ary)->aux.capa = i2 * 2;
}
}
@@ -1732,9 +1888,11 @@ rb_ary_delete(VALUE ary, VALUE item)
}
VALUE
-rb_ary_delete_at(VALUE ary, long pos)
+rb_ary_delete_at(ary, pos)
+ VALUE ary;
+ long pos;
{
- long i, len = RARRAY_LEN(ary);
+ long i, len = RARRAY(ary)->len;
VALUE del;
if (pos >= len) return Qnil;
@@ -1744,10 +1902,11 @@ rb_ary_delete_at(VALUE ary, long pos)
}
rb_ary_modify(ary);
- del = RARRAY_PTR(ary)[pos];
- MEMMOVE(RARRAY_PTR(ary)+pos, RARRAY_PTR(ary)+pos+1, VALUE,
- RARRAY_LEN(ary)-pos-1);
- RARRAY(ary)->len--;
+ del = RARRAY(ary)->ptr[pos];
+ for (i = pos + 1; i < len; i++, pos++) {
+ RARRAY(ary)->ptr[pos] = RARRAY(ary)->ptr[i];
+ }
+ RARRAY(ary)->len = pos;
return del;
}
@@ -1767,7 +1926,8 @@ rb_ary_delete_at(VALUE ary, long pos)
*/
static VALUE
-rb_ary_delete_at_m(VALUE ary, VALUE pos)
+rb_ary_delete_at_m(ary, pos)
+ VALUE ary, pos;
{
return rb_ary_delete_at(ary, NUM2LONG(pos));
}
@@ -1798,7 +1958,10 @@ rb_ary_delete_at_m(VALUE ary, VALUE pos)
*/
static VALUE
-rb_ary_slice_bang(int argc, VALUE *argv, VALUE ary)
+rb_ary_slice_bang(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
VALUE arg1, arg2;
long pos, len;
@@ -1808,14 +1971,14 @@ rb_ary_slice_bang(int argc, VALUE *argv, VALUE ary)
len = NUM2LONG(arg2);
delete_pos_len:
if (pos < 0) {
- pos = RARRAY_LEN(ary) + pos;
+ pos = RARRAY(ary)->len + pos;
}
arg2 = rb_ary_subseq(ary, pos, len);
- rb_ary_splice(ary, pos, len, Qundef); /* Qnil/rb_ary_new2(0) */
+ rb_ary_splice(ary, pos, len, Qnil); /* Qnil/rb_ary_new2(0) */
return arg2;
}
- if (!FIXNUM_P(arg1) && rb_range_beg_len(arg1, &pos, &len, RARRAY_LEN(ary), 1)) {
+ if (!FIXNUM_P(arg1) && rb_range_beg_len(arg1, &pos, &len, RARRAY(ary)->len, 1)) {
goto delete_pos_len;
}
@@ -1833,22 +1996,22 @@ rb_ary_slice_bang(int argc, VALUE *argv, VALUE ary)
*/
static VALUE
-rb_ary_reject_bang(VALUE ary)
+rb_ary_reject_bang(ary)
+ VALUE ary;
{
long i1, i2;
- RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
- for (i1 = i2 = 0; i1 < RARRAY_LEN(ary); i1++) {
- VALUE v = RARRAY_PTR(ary)[i1];
+ for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
+ VALUE v = RARRAY(ary)->ptr[i1];
if (RTEST(rb_yield(v))) continue;
if (i1 != i2) {
rb_ary_store(ary, i2, v);
}
i2++;
}
- if (RARRAY_LEN(ary) == i2) return Qnil;
- if (i2 < RARRAY_LEN(ary))
+ if (RARRAY(ary)->len == i2) return Qnil;
+ if (i2 < RARRAY(ary)->len)
RARRAY(ary)->len = i2;
return ary;
@@ -1863,9 +2026,9 @@ rb_ary_reject_bang(VALUE ary)
*/
static VALUE
-rb_ary_reject(VALUE ary)
+rb_ary_reject(ary)
+ VALUE ary;
{
- RETURN_ENUMERATOR(ary, 0, 0);
ary = rb_ary_dup(ary);
rb_ary_reject_bang(ary);
return ary;
@@ -1883,7 +2046,8 @@ rb_ary_reject(VALUE ary)
*/
static VALUE
-rb_ary_delete_if(VALUE ary)
+rb_ary_delete_if(ary)
+ VALUE ary;
{
rb_ary_reject_bang(ary);
return ary;
@@ -1912,17 +2076,20 @@ rb_ary_delete_if(VALUE ary)
*/
static VALUE
-rb_ary_zip(int argc, VALUE *argv, VALUE ary)
+rb_ary_zip(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
int i, j;
long len;
VALUE result;
for (i=0; i<argc; i++) {
- argv[i] = to_a(argv[i]);
+ argv[i] = to_ary(argv[i]);
}
if (rb_block_given_p()) {
- for (i=0; i<RARRAY_LEN(ary); i++) {
+ for (i=0; i<RARRAY(ary)->len; i++) {
VALUE tmp = rb_ary_new2(argc+1);
rb_ary_push(tmp, rb_ary_elt(ary, i));
@@ -1933,7 +2100,7 @@ rb_ary_zip(int argc, VALUE *argv, VALUE ary)
}
return Qnil;
}
- len = RARRAY_LEN(ary);
+ len = RARRAY(ary)->len;
result = rb_ary_new2(len);
for (i=0; i<len; i++) {
VALUE tmp = rb_ary_new2(argc+1);
@@ -1959,25 +2126,26 @@ rb_ary_zip(int argc, VALUE *argv, VALUE ary)
*/
static VALUE
-rb_ary_transpose(VALUE ary)
+rb_ary_transpose(ary)
+ VALUE ary;
{
long elen = -1, alen, i, j;
VALUE tmp, result = 0;
- alen = RARRAY_LEN(ary);
+ alen = RARRAY(ary)->len;
if (alen == 0) return rb_ary_dup(ary);
for (i=0; i<alen; i++) {
tmp = to_ary(rb_ary_elt(ary, i));
if (elen < 0) { /* first element */
- elen = RARRAY_LEN(tmp);
+ elen = RARRAY(tmp)->len;
result = rb_ary_new2(elen);
for (j=0; j<elen; j++) {
rb_ary_store(result, j, rb_ary_new2(alen));
}
}
- else if (elen != RARRAY_LEN(tmp)) {
- rb_raise(rb_eIndexError, "element size differs (%ld should be %ld)",
- RARRAY_LEN(tmp), elen);
+ else if (elen != RARRAY(tmp)->len) {
+ rb_raise(rb_eIndexError, "element size differs (%d should be %d)",
+ RARRAY(tmp)->len, elen);
}
for (j=0; j<elen; j++) {
rb_ary_store(rb_ary_elt(result, j), i, rb_ary_elt(tmp, j));
@@ -1999,19 +2167,19 @@ rb_ary_transpose(VALUE ary)
*/
static VALUE
-rb_ary_replace(VALUE copy, VALUE orig)
+rb_ary_replace(copy, orig)
+ VALUE copy, orig;
{
VALUE shared;
- VALUE *ptr;
rb_ary_modify(copy);
orig = to_ary(orig);
if (copy == orig) return copy;
shared = ary_make_shared(orig);
- ptr = RARRAY(copy)->ptr;
- xfree(ptr);
- RARRAY(copy)->ptr = RARRAY(shared)->ptr;
- RARRAY(copy)->len = RARRAY(shared)->len;
+ if (RARRAY(copy)->ptr && !FL_TEST(copy, ELTS_SHARED))
+ free(RARRAY(copy)->ptr);
+ RARRAY(copy)->ptr = RARRAY(orig)->ptr;
+ RARRAY(copy)->len = RARRAY(orig)->len;
RARRAY(copy)->aux.shared = shared;
FL_SET(copy, ELTS_SHARED);
@@ -2029,12 +2197,14 @@ rb_ary_replace(VALUE copy, VALUE orig)
*/
VALUE
-rb_ary_clear(VALUE ary)
+rb_ary_clear(ary)
+ VALUE ary;
{
rb_ary_modify(ary);
RARRAY(ary)->len = 0;
- if (ARY_DEFAULT_SIZE * 2 < ARY_CAPA(ary)) {
- RESIZE_CAPA(ary, ARY_DEFAULT_SIZE * 2);
+ if (ARY_DEFAULT_SIZE * 2 < RARRAY(ary)->aux.capa) {
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, ARY_DEFAULT_SIZE * 2);
+ RARRAY(ary)->aux.capa = ARY_DEFAULT_SIZE * 2;
}
return ary;
}
@@ -2064,7 +2234,10 @@ rb_ary_clear(VALUE ary)
*/
static VALUE
-rb_ary_fill(int argc, VALUE *argv, VALUE ary)
+rb_ary_fill(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
{
VALUE item, arg1, arg2;
long beg = 0, end = 0, len = 0;
@@ -2082,29 +2255,36 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary)
switch (argc) {
case 1:
beg = 0;
- len = RARRAY_LEN(ary);
+ len = RARRAY(ary)->len;
break;
case 2:
- if (rb_range_beg_len(arg1, &beg, &len, RARRAY_LEN(ary), 1)) {
+ if (rb_range_beg_len(arg1, &beg, &len, RARRAY(ary)->len, 1)) {
break;
}
/* fall through */
case 3:
beg = NIL_P(arg1) ? 0 : NUM2LONG(arg1);
if (beg < 0) {
- beg = RARRAY_LEN(ary) + beg;
+ beg = RARRAY(ary)->len + beg;
if (beg < 0) beg = 0;
}
- len = NIL_P(arg2) ? RARRAY_LEN(ary) - beg : NUM2LONG(arg2);
+ len = NIL_P(arg2) ? RARRAY(ary)->len - beg : NUM2LONG(arg2);
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_LEN(ary)) {
- if (end >= ARY_CAPA(ary)) {
- RESIZE_CAPA(ary, end);
+ if (end > RARRAY(ary)->len) {
+ if (end >= RARRAY(ary)->aux.capa) {
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, end);
+ RARRAY(ary)->aux.capa = end;
}
- rb_mem_clear(RARRAY_PTR(ary) + RARRAY_LEN(ary), end - RARRAY_LEN(ary));
+ rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len, end - RARRAY(ary)->len);
RARRAY(ary)->len = end;
}
@@ -2114,12 +2294,12 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary)
for (i=beg; i<end; i++) {
v = rb_yield(LONG2NUM(i));
- if (i>=RARRAY_LEN(ary)) break;
- RARRAY_PTR(ary)[i] = v;
+ if (i>=RARRAY(ary)->len) break;
+ RARRAY(ary)->ptr[i] = v;
}
}
else {
- p = RARRAY_PTR(ary) + beg;
+ p = RARRAY(ary)->ptr + beg;
pend = p + len;
while (p < pend) {
*p++ = item;
@@ -2139,16 +2319,17 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary)
*/
VALUE
-rb_ary_plus(VALUE x, VALUE y)
+rb_ary_plus(x, y)
+ VALUE x, y;
{
VALUE z;
long len;
y = to_ary(y);
- len = RARRAY_LEN(x) + RARRAY_LEN(y);
+ len = RARRAY(x)->len + RARRAY(y)->len;
z = rb_ary_new2(len);
- MEMCPY(RARRAY_PTR(z), RARRAY_PTR(x), VALUE, RARRAY_LEN(x));
- MEMCPY(RARRAY_PTR(z) + RARRAY_LEN(x), RARRAY_PTR(y), VALUE, RARRAY_LEN(y));
+ MEMCPY(RARRAY(z)->ptr, RARRAY(x)->ptr, VALUE, RARRAY(x)->len);
+ MEMCPY(RARRAY(z)->ptr + RARRAY(x)->len, RARRAY(y)->ptr, VALUE, RARRAY(y)->len);
RARRAY(z)->len = len;
return z;
}
@@ -2164,11 +2345,12 @@ rb_ary_plus(VALUE x, VALUE y)
VALUE
-rb_ary_concat(VALUE x, VALUE y)
+rb_ary_concat(x, y)
+ VALUE x, y;
{
y = to_ary(y);
- if (RARRAY_LEN(y) > 0) {
- rb_ary_splice(x, RARRAY_LEN(x), 0, y);
+ if (RARRAY(y)->len > 0) {
+ rb_ary_splice(x, RARRAY(x)->len, 0, y);
}
return x;
}
@@ -2190,7 +2372,8 @@ rb_ary_concat(VALUE x, VALUE y)
*/
static VALUE
-rb_ary_times(VALUE ary, VALUE times)
+rb_ary_times(ary, times)
+ VALUE ary, times;
{
VALUE ary2, tmp;
long i, len;
@@ -2205,16 +2388,16 @@ rb_ary_times(VALUE ary, VALUE times)
if (len < 0) {
rb_raise(rb_eArgError, "negative argument");
}
- if (LONG_MAX/len < RARRAY_LEN(ary)) {
+ if (ARY_MAX_SIZE/len < RARRAY(ary)->len) {
rb_raise(rb_eArgError, "argument too big");
}
- len *= RARRAY_LEN(ary);
+ len *= RARRAY(ary)->len;
ary2 = ary_new(rb_obj_class(ary), len);
RARRAY(ary2)->len = len;
- for (i=0; i<len; i+=RARRAY_LEN(ary)) {
- MEMCPY(RARRAY_PTR(ary2)+i, RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary));
+ for (i=0; i<len; i+=RARRAY(ary)->len) {
+ MEMCPY(RARRAY(ary2)->ptr+i, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
}
OBJ_INFECT(ary2, ary);
@@ -2242,16 +2425,17 @@ rb_ary_times(VALUE ary, VALUE times)
*/
VALUE
-rb_ary_assoc(VALUE ary, VALUE key)
+rb_ary_assoc(ary, key)
+ VALUE ary, key;
{
long i;
VALUE v;
- for (i = 0; i < RARRAY_LEN(ary); ++i) {
- v = RARRAY_PTR(ary)[i];
+ for (i = 0; i < RARRAY(ary)->len; ++i) {
+ v = RARRAY(ary)->ptr[i];
if (TYPE(v) == T_ARRAY &&
- RARRAY_LEN(v) > 0 &&
- rb_equal(RARRAY_PTR(v)[0], key))
+ RARRAY(v)->len > 0 &&
+ rb_equal(RARRAY(v)->ptr[0], key))
return v;
}
return Qnil;
@@ -2272,21 +2456,35 @@ rb_ary_assoc(VALUE ary, VALUE key)
*/
VALUE
-rb_ary_rassoc(VALUE ary, VALUE value)
+rb_ary_rassoc(ary, value)
+ VALUE ary, value;
{
long i;
VALUE v;
- for (i = 0; i < RARRAY_LEN(ary); ++i) {
- v = RARRAY_PTR(ary)[i];
+ for (i = 0; i < RARRAY(ary)->len; ++i) {
+ v = RARRAY(ary)->ptr[i];
if (TYPE(v) == T_ARRAY &&
- RARRAY_LEN(v) > 1 &&
- rb_equal(RARRAY_PTR(v)[1], value))
+ RARRAY(v)->len > 1 &&
+ rb_equal(RARRAY(v)->ptr[1], value))
return v;
}
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
@@ -2302,10 +2500,9 @@ rb_ary_rassoc(VALUE ary, VALUE value)
*/
static VALUE
-rb_ary_equal(VALUE ary1, VALUE ary2)
+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"))) {
@@ -2313,9 +2510,19 @@ rb_ary_equal(VALUE ary1, VALUE ary2)
}
return rb_equal(ary2, ary1);
}
- if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return Qfalse;
- for (i=0; i<RARRAY_LEN(ary1); i++) {
- if (!rb_equal(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
+ 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)))
return Qfalse;
}
return Qtrue;
@@ -2330,33 +2537,29 @@ rb_ary_equal(VALUE ary1, VALUE ary2)
*/
static VALUE
-rb_ary_eql(VALUE ary1, VALUE ary2)
+rb_ary_eql(ary1, ary2)
+ VALUE ary1, ary2;
{
- long i;
-
if (ary1 == ary2) return Qtrue;
if (TYPE(ary2) != T_ARRAY) return Qfalse;
- if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return Qfalse;
- for (i=0; i<RARRAY_LEN(ary1); i++) {
- if (!rb_eql(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
- return Qfalse;
- }
- return Qtrue;
+ 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(VALUE ary, VALUE dummy, int recur)
+recursive_hash(ary)
+ VALUE ary;
{
long i, h;
VALUE n;
- if (recur) {
- return LONG2FIX(0);
- }
- h = RARRAY_LEN(ary);
- for (i=0; i<RARRAY_LEN(ary); i++) {
+ h = RARRAY(ary)->len;
+ for (i=0; i<RARRAY(ary)->len; i++) {
h = (h << 1) | (h<0 ? 1 : 0);
- n = rb_hash(RARRAY_PTR(ary)[i]);
+ n = rb_hash(RARRAY(ary)->ptr[i]);
h ^= NUM2LONG(n);
}
return LONG2FIX(h);
@@ -2371,9 +2574,13 @@ recursive_hash(VALUE ary, VALUE dummy, int recur)
*/
static VALUE
-rb_ary_hash(VALUE ary)
+rb_ary_hash(ary)
+ VALUE ary;
{
- return rb_exec_recursive(recursive_hash, ary, 0);
+ if (rb_inspecting_p(ary)) {
+ return LONG2FIX(0);
+ }
+ return rb_protect_inspect(recursive_hash, ary, 0);
}
/*
@@ -2390,18 +2597,38 @@ rb_ary_hash(VALUE ary)
*/
VALUE
-rb_ary_includes(VALUE ary, VALUE item)
+rb_ary_includes(ary, item)
+ VALUE ary;
+ VALUE item;
{
long i;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- if (rb_equal(RARRAY_PTR(ary)[i], item)) {
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ if (rb_equal(RARRAY(ary)->ptr[i], item)) {
return Qtrue;
}
}
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:
@@ -2424,39 +2651,36 @@ rb_ary_includes(VALUE ary, VALUE item)
*/
VALUE
-rb_ary_cmp(VALUE ary1, VALUE ary2)
+rb_ary_cmp(ary1, ary2)
+ VALUE ary1, ary2;
{
- long i, len;
+ long len;
+ VALUE v;
ary2 = to_ary(ary2);
- len = RARRAY_LEN(ary1);
- if (len > RARRAY_LEN(ary2)) {
- len = RARRAY_LEN(ary2);
- }
- 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_LEN(ary1) - RARRAY_LEN(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 - RARRAY(ary2)->len;
if (len == 0) return INT2FIX(0);
if (len > 0) return INT2FIX(1);
return INT2FIX(-1);
}
static VALUE
-ary_make_hash(VALUE ary1, VALUE ary2)
+ary_make_hash(ary1, ary2)
+ VALUE ary1, ary2;
{
VALUE hash = rb_hash_new();
long i;
- for (i=0; i<RARRAY_LEN(ary1); i++) {
- rb_hash_aset(hash, RARRAY_PTR(ary1)[i], Qtrue);
+ for (i=0; i<RARRAY(ary1)->len; i++) {
+ rb_hash_aset(hash, RARRAY(ary1)->ptr[i], Qtrue);
}
if (ary2) {
- for (i=0; i<RARRAY_LEN(ary2); i++) {
- rb_hash_aset(hash, RARRAY_PTR(ary2)[i], Qtrue);
+ for (i=0; i<RARRAY(ary2)->len; i++) {
+ rb_hash_aset(hash, RARRAY(ary2)->ptr[i], Qtrue);
}
}
return hash;
@@ -2475,7 +2699,8 @@ ary_make_hash(VALUE ary1, VALUE ary2)
*/
static VALUE
-rb_ary_diff(VALUE ary1, VALUE ary2)
+rb_ary_diff(ary1, ary2)
+ VALUE ary1, ary2;
{
VALUE ary3;
volatile VALUE hash;
@@ -2484,8 +2709,8 @@ rb_ary_diff(VALUE ary1, VALUE ary2)
hash = ary_make_hash(to_ary(ary2), 0);
ary3 = rb_ary_new();
- for (i=0; i<RARRAY_LEN(ary1); i++) {
- if (st_lookup(RHASH(hash)->tbl, RARRAY_PTR(ary1)[i], 0)) continue;
+ for (i=0; i<RARRAY(ary1)->len; i++) {
+ if (st_lookup(RHASH(hash)->tbl, RARRAY(ary1)->ptr[i], 0)) continue;
rb_ary_push(ary3, rb_ary_elt(ary1, i));
}
return ary3;
@@ -2503,17 +2728,18 @@ rb_ary_diff(VALUE ary1, VALUE ary2)
static VALUE
-rb_ary_and(VALUE ary1, VALUE ary2)
+rb_ary_and(ary1, ary2)
+ VALUE ary1, ary2;
{
VALUE hash, ary3, v, vv;
long i;
ary2 = to_ary(ary2);
- ary3 = rb_ary_new2(RARRAY_LEN(ary1) < RARRAY_LEN(ary2) ?
- RARRAY_LEN(ary1) : RARRAY_LEN(ary2));
+ ary3 = rb_ary_new2(RARRAY(ary1)->len < RARRAY(ary2)->len ?
+ RARRAY(ary1)->len : RARRAY(ary2)->len);
hash = ary_make_hash(ary2, 0);
- for (i=0; i<RARRAY_LEN(ary1); i++) {
+ for (i=0; i<RARRAY(ary1)->len; i++) {
v = vv = rb_ary_elt(ary1, i);
if (st_delete(RHASH(hash)->tbl, (st_data_t*)&vv, 0)) {
rb_ary_push(ary3, v);
@@ -2535,23 +2761,24 @@ rb_ary_and(VALUE ary1, VALUE ary2)
*/
static VALUE
-rb_ary_or(VALUE ary1, VALUE ary2)
+rb_ary_or(ary1, ary2)
+ VALUE ary1, ary2;
{
VALUE hash, ary3;
VALUE v, vv;
long i;
ary2 = to_ary(ary2);
- ary3 = rb_ary_new2(RARRAY_LEN(ary1)+RARRAY_LEN(ary2));
+ ary3 = rb_ary_new2(RARRAY(ary1)->len+RARRAY(ary2)->len);
hash = ary_make_hash(ary1, ary2);
- for (i=0; i<RARRAY_LEN(ary1); i++) {
+ for (i=0; i<RARRAY(ary1)->len; i++) {
v = vv = rb_ary_elt(ary1, i);
if (st_delete(RHASH(hash)->tbl, (st_data_t*)&vv, 0)) {
rb_ary_push(ary3, v);
}
}
- for (i=0; i<RARRAY_LEN(ary2); i++) {
+ for (i=0; i<RARRAY(ary2)->len; i++) {
v = vv = rb_ary_elt(ary2, i);
if (st_delete(RHASH(hash)->tbl, (st_data_t*)&vv, 0)) {
rb_ary_push(ary3, v);
@@ -2575,17 +2802,18 @@ rb_ary_or(VALUE ary1, VALUE ary2)
*/
static VALUE
-rb_ary_uniq_bang(VALUE ary)
+rb_ary_uniq_bang(ary)
+ VALUE ary;
{
VALUE hash, v, vv;
long i, j;
hash = ary_make_hash(ary, 0);
- if (RARRAY_LEN(ary) == RHASH(hash)->tbl->num_entries) {
+ if (RARRAY(ary)->len == RHASH(hash)->tbl->num_entries) {
return Qnil;
}
- for (i=j=0; i<RARRAY_LEN(ary); i++) {
+ for (i=j=0; i<RARRAY(ary)->len; i++) {
v = vv = rb_ary_elt(ary, i);
if (st_delete(RHASH(hash)->tbl, (st_data_t*)&vv, 0)) {
rb_ary_store(ary, j++, v);
@@ -2607,7 +2835,8 @@ rb_ary_uniq_bang(VALUE ary)
*/
static VALUE
-rb_ary_uniq(VALUE ary)
+rb_ary_uniq(ary)
+ VALUE ary;
{
ary = rb_ary_dup(ary);
rb_ary_uniq_bang(ary);
@@ -2626,25 +2855,24 @@ rb_ary_uniq(VALUE ary)
*/
static VALUE
-rb_ary_compact_bang(VALUE ary)
+rb_ary_compact_bang(ary)
+ VALUE ary;
{
VALUE *p, *t, *end;
- long n;
rb_ary_modify(ary);
- p = t = RARRAY_PTR(ary);
- end = p + RARRAY_LEN(ary);
+ p = t = RARRAY(ary)->ptr;
+ end = p + RARRAY(ary)->len;
while (t < end) {
if (NIL_P(*t)) t++;
else *p++ = *t++;
}
- if (RARRAY_LEN(ary) == (p - RARRAY_PTR(ary))) {
+ if (RARRAY(ary)->len == (p - RARRAY(ary)->ptr)) {
return Qnil;
}
- n = p - RARRAY_PTR(ary);
- RESIZE_CAPA(ary, n);
- RARRAY(ary)->len = n;
+ RARRAY(ary)->len = RARRAY(ary)->aux.capa = (p - RARRAY(ary)->ptr);
+ REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
return ary;
}
@@ -2660,7 +2888,8 @@ rb_ary_compact_bang(VALUE ary)
*/
static VALUE
-rb_ary_compact(VALUE ary)
+rb_ary_compact(ary)
+ VALUE ary;
{
ary = rb_ary_dup(ary);
rb_ary_compact_bang(ary);
@@ -2670,68 +2899,55 @@ rb_ary_compact(VALUE ary)
/*
* call-seq:
* array.nitems -> int
- * array.nitems { |item| block } -> int
*
* Returns the number of non-<code>nil</code> elements in _self_.
- * If a block is given, the elements yielding a true value are
- * counted.
- *
* May be zero.
*
* [ 1, nil, 3, nil, 5 ].nitems #=> 3
- * [5,6,7,8,9].nitems { |x| x % 2 != 0 } #=> 3
*/
static VALUE
-rb_ary_nitems(VALUE ary)
+rb_ary_nitems(ary)
+ VALUE ary;
{
long n = 0;
-
- if (rb_block_given_p()) {
- long i;
+ VALUE *p, *pend;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- VALUE v = RARRAY_PTR(ary)[i];
- if (RTEST(rb_yield(v))) n++;
- }
- }
- else {
- VALUE *p = RARRAY_PTR(ary);
- VALUE *pend = p + RARRAY_LEN(ary);
+ p = RARRAY(ary)->ptr;
+ pend = p + RARRAY(ary)->len;
- while (p < pend) {
- if (!NIL_P(*p)) n++;
- p++;
- }
+ while (p < pend) {
+ if (!NIL_P(*p)) n++;
+ p++;
}
return LONG2NUM(n);
}
static long
-flatten(VALUE ary, long idx, VALUE ary2, VALUE memo, int level)
+flatten(ary, idx, ary2, memo)
+ VALUE ary;
+ long idx;
+ VALUE ary2, memo;
{
VALUE id;
long i = idx;
- long n, lim = idx + RARRAY_LEN(ary2);
+ long n, lim = idx + RARRAY(ary2)->len;
- level--;
id = rb_obj_id(ary2);
if (rb_ary_includes(memo, id)) {
rb_raise(rb_eArgError, "tried to flatten recursive array");
}
rb_ary_push(memo, id);
rb_ary_splice(ary, idx, 1, ary2);
- if (level != 0) {
- while (i < lim) {
- VALUE tmp;
-
- tmp = rb_check_array_type(rb_ary_elt(ary, i));
- if (!NIL_P(tmp)) {
- n = flatten(ary, i, tmp, memo, level);
- i += n; lim += n;
- }
- i++;
+ while (i < lim) {
+ VALUE tmp;
+
+ tmp = rb_check_array_type(rb_ary_elt(ary, i));
+ if (!NIL_P(tmp)) {
+ n = flatten(ary, i, tmp, memo);
+ i += n; lim += n;
}
+ i++;
}
rb_ary_pop(memo);
@@ -2740,36 +2956,28 @@ flatten(VALUE ary, long idx, VALUE ary2, VALUE memo, int level)
/*
* call-seq:
- * array.flatten! -> array or nil
- * array.flatten!(level) -> array or nil
+ * array.flatten! -> array or nil
*
* Flattens _self_ in place.
* Returns <code>nil</code> if no modifications were made (i.e.,
- * <i>array</i> contains no subarrays.) If the optional <i>level</i>
- * argument determins the level of recursion to flatten.
+ * <i>array</i> contains no subarrays.)
*
* a = [ 1, 2, [3, [4, 5] ] ]
- * a.flatten! #=> [1, 2, 3, 4, 5]
- * a.flatten! #=> nil
- * a #=> [1, 2, 3, 4, 5]
- * a = [ 1, 2, [3, [4, 5] ] ]
- * a.flatten!(1) #=> [1, 2, 3, [4, 5]]
+ * a.flatten! #=> [1, 2, 3, 4, 5]
+ * a.flatten! #=> nil
+ * a #=> [1, 2, 3, 4, 5]
*/
static VALUE
-rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary)
+rb_ary_flatten_bang(ary)
+ VALUE ary;
{
long i = 0;
int mod = 0;
- int level = -1;
VALUE memo = Qnil;
- VALUE lv;
- rb_scan_args(argc, argv, "01", &lv);
- if (!NIL_P(lv)) level = FIX2INT(lv);
- if (level == 0) return ary;
- while (i<RARRAY_LEN(ary)) {
- VALUE ary2 = RARRAY_PTR(ary)[i];
+ while (i<RARRAY(ary)->len) {
+ VALUE ary2 = RARRAY(ary)->ptr[i];
VALUE tmp;
tmp = rb_check_array_type(ary2);
@@ -2777,7 +2985,7 @@ rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary)
if (NIL_P(memo)) {
memo = rb_ary_new();
}
- i += flatten(ary, i, tmp, memo, level);
+ i += flatten(ary, i, tmp, memo);
mod = 1;
}
i++;
@@ -2789,67 +2997,23 @@ rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary)
/*
* call-seq:
* array.flatten -> an_array
- * array.flatten(level) -> an_array
*
* Returns a new array that is a one-dimensional flattening of this
* array (recursively). That is, for every element that is an array,
- * extract its elements into the new array. If the optional
- * <i>level</i> argument determins the level of recursion to flatten.
+ * extract its elements into the new array.
*
* s = [ 1, 2, 3 ] #=> [1, 2, 3]
* t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
* a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
* a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- * a = [ 1, 2, [3, [4, 5] ] ]
- * a.flatten(1) #=> [1, 2, 3, [4, 5]]
- */
-
-static VALUE
-rb_ary_flatten(int argc, VALUE *argv, VALUE ary)
-{
- ary = rb_ary_dup(ary);
- rb_ary_flatten_bang(argc, argv, ary);
- return ary;
-}
-
-/*
- * call-seq:
- * array.shuffle! -> array or
- *
- * Shuffles elements in _self_ in place.
- */
-
-
-static VALUE
-rb_ary_shuffle_bang(VALUE ary)
-{
- long i = RARRAY_LEN(ary);
-
- while (i) {
- long j = genrand_real()*i;
- VALUE tmp = RARRAY_PTR(ary)[--i];
- RARRAY_PTR(ary)[i] = RARRAY_PTR(ary)[j];
- RARRAY_PTR(ary)[j] = tmp;
- }
- return ary;
-}
-
-
-/*
- * call-seq:
- * array.shuffle -> an_array
- *
- * Returns a new array with elements of this array shuffled.
- *
- * a = [ 1, 2, 3 ] #=> [1, 2, 3]
- * a.shuffle #=> [2, 3, 1]
*/
static VALUE
-rb_ary_shuffle(VALUE ary)
+rb_ary_flatten(ary)
+ VALUE ary;
{
ary = rb_ary_dup(ary);
- rb_ary_shuffle_bang(ary);
+ rb_ary_flatten_bang(ary);
return ary;
}
@@ -2862,7 +3026,7 @@ rb_ary_shuffle(VALUE ary)
*/
void
-Init_Array(void)
+Init_Array()
{
rb_cArray = rb_define_class("Array", rb_cObject);
rb_include_module(rb_cArray, rb_mEnumerable);
@@ -2872,10 +3036,9 @@ Init_Array(void)
rb_define_method(rb_cArray, "initialize", rb_ary_initialize, -1);
rb_define_method(rb_cArray, "initialize_copy", rb_ary_replace, 1);
- rb_define_method(rb_cArray, "to_s", rb_ary_inspect, 0);
+ rb_define_method(rb_cArray, "to_s", rb_ary_to_s, 0);
rb_define_method(rb_cArray, "inspect", rb_ary_inspect, 0);
rb_define_method(rb_cArray, "to_a", rb_ary_to_a, 0);
- rb_define_method(rb_cArray, "to_splat", rb_ary_to_a, 0);
rb_define_method(rb_cArray, "to_ary", rb_ary_to_ary_m, 0);
rb_define_method(rb_cArray, "frozen?", rb_ary_frozen_p, 0);
@@ -2892,8 +3055,8 @@ Init_Array(void)
rb_define_method(rb_cArray, "concat", rb_ary_concat, 1);
rb_define_method(rb_cArray, "<<", rb_ary_push, 1);
rb_define_method(rb_cArray, "push", rb_ary_push_m, -1);
- rb_define_method(rb_cArray, "pop", rb_ary_pop_m, -1);
- rb_define_method(rb_cArray, "shift", rb_ary_shift_m, -1);
+ rb_define_method(rb_cArray, "pop", rb_ary_pop, 0);
+ rb_define_method(rb_cArray, "shift", rb_ary_shift, 0);
rb_define_method(rb_cArray, "unshift", rb_ary_unshift_m, -1);
rb_define_method(rb_cArray, "insert", rb_ary_insert, -1);
rb_define_method(rb_cArray, "each", rb_ary_each, 0);
@@ -2902,8 +3065,10 @@ Init_Array(void)
rb_define_method(rb_cArray, "length", rb_ary_length, 0);
rb_define_alias(rb_cArray, "size", "length");
rb_define_method(rb_cArray, "empty?", rb_ary_empty_p, 0);
- rb_define_method(rb_cArray, "index", rb_ary_index, -1);
- rb_define_method(rb_cArray, "rindex", rb_ary_rindex, -1);
+ rb_define_method(rb_cArray, "index", rb_ary_index, 1);
+ rb_define_method(rb_cArray, "rindex", rb_ary_rindex, 1);
+ rb_define_method(rb_cArray, "indexes", rb_ary_indexes, -1);
+ rb_define_method(rb_cArray, "indices", rb_ary_indexes, -1);
rb_define_method(rb_cArray, "join", rb_ary_join_m, -1);
rb_define_method(rb_cArray, "reverse", rb_ary_reverse_m, 0);
rb_define_method(rb_cArray, "reverse!", rb_ary_reverse_bang, 0);
@@ -2945,11 +3110,10 @@ Init_Array(void)
rb_define_method(rb_cArray, "uniq!", rb_ary_uniq_bang, 0);
rb_define_method(rb_cArray, "compact", rb_ary_compact, 0);
rb_define_method(rb_cArray, "compact!", rb_ary_compact_bang, 0);
- rb_define_method(rb_cArray, "flatten", rb_ary_flatten, -1);
- rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, -1);
+ rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0);
+ rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, 0);
rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0);
- rb_define_method(rb_cArray, "shuffle!", rb_ary_shuffle_bang, 0);
- rb_define_method(rb_cArray, "shuffle", rb_ary_shuffle, 0);
id_cmp = rb_intern("<=>");
+ inspect_key = rb_intern("__inspect_key__");
}
diff --git a/ascii.c b/ascii.c
deleted file mode 100644
index 64be21d7ff..0000000000
--- a/ascii.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/**********************************************************************
- ascii.c - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2004 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "regenc.h"
-
-static int
-ascii_is_code_ctype(OnigCodePoint code, unsigned int ctype)
-{
- if (code < 128)
- return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
- else
- return FALSE;
-}
-
-OnigEncodingType OnigEncodingASCII = {
- onigenc_single_byte_mbc_enc_len,
- "US-ASCII", /* name */
- 1, /* max byte length */
- 1, /* min byte length */
- ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE,
- {
- (OnigCodePoint )'\\' /* esc */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar '.' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anytime '*' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* zero or one time '?' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* one or more time '+' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar anytime */
- },
- onigenc_is_mbc_newline_0x0a,
- onigenc_single_byte_mbc_to_code,
- onigenc_single_byte_code_to_mbclen,
- onigenc_single_byte_code_to_mbc,
- onigenc_ascii_mbc_to_normalize,
- onigenc_ascii_is_mbc_ambiguous,
- onigenc_ascii_get_all_pair_ambig_codes,
- onigenc_nothing_get_all_comp_ambig_codes,
- ascii_is_code_ctype,
- onigenc_not_support_get_ctype_code_range,
- onigenc_single_byte_left_adjust_char_head,
- onigenc_always_true_is_allowed_reverse_match
-};
diff --git a/bcc32/Makefile.sub b/bcc32/Makefile.sub
index baff3e3947..b5546104d0 100644
--- a/bcc32/Makefile.sub
+++ b/bcc32/Makefile.sub
@@ -49,8 +49,7 @@ CPP = cpp32
RC = brcc32
!endif
!ifndef YACC
-YACC = bison
-YFLAGS = -o y.tab.c
+YACC = byacc
!endif
!ifndef AR
AR = tlib
@@ -95,7 +94,7 @@ exec_prefix = $(prefix)
libdir = $(exec_prefix)/lib
!endif
!if !defined(datadir)
-datadir = $(prefix)/share
+datadir = /share
!endif
!ifndef EXTOUT
EXTOUT = .ext
@@ -110,16 +109,13 @@ TESTUI = console
TESTS =
!endif
!ifndef RDOCTARGET
-RDOCTARGET = install-doc
+RDOCTARGET = install-nodoc
!endif
OUTFLAG = -o
!ifndef CFLAGS
CFLAGS = -q -tWR -tWC $(DEBUGFLAGS) $(OPTFLAGS) $(PROCESSOR_FLAG) -w- -wsus -wcpt -wdup -wext -wrng -wrpt -wzdi
!endif
-!ifndef CXXFLAGS
-CXXFLAGS = $(CFLAGS)
-!endif
!ifndef LDFLAGS
LDFLAGS = -S:$(STACK)
!endif
@@ -139,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
@@ -158,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)
@@ -178,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)
@@ -187,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)
@@ -209,21 +205,20 @@ 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
\#define HAVE_STRING_H 1
\#define HAVE_MEMORY_H 1
-\#define HAVE_LONG_LONG 1
\#define HAVE_OFF_T 1
\#define SIZEOF_INT 4
\#define SIZEOF_SHORT 2
\#define SIZEOF_LONG 4
\#define SIZEOF_LONG_LONG 0
\#define SIZEOF___INT64 8
-\#define SIZEOF_OFF_T 8
+\#define SIZEOF_OFF_T 4
\#define SIZEOF_VOIDP 4
\#define SIZEOF_FLOAT 4
\#define SIZEOF_DOUBLE 8
@@ -258,8 +253,6 @@ $(CONFIG_H): $(MKFILES) $(srcdir)bcc32/Makefile.sub
\#define HAVE_STRTOD 1
\#define HAVE_STRTOL 1
\#define HAVE_STRTOUL 1
-\#define HAVE_SNPRINTF 1
-\#define HAVE_VSNPRINTF 1
\#define HAVE_ISNAN 1
\#define HAVE_FINITE 1
\#define HAVE_HYPOT 1
@@ -267,9 +260,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)bcc32/Makefile.sub
\#define HAVE_WAITPID 1
\#define HAVE_FSYNC 1
\#define HAVE_GETCWD 1
-\#define HAVE_TRUNCATE 1
-\#define HAVE_FSEEKO 1
-\#define HAVE_FTELLO 1
+\#define HAVE_CHSIZE 1
\#define HAVE_TIMES 1
\#define HAVE_FCNTL 1
\#define HAVE_LINK 1
@@ -295,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.
@@ -309,7 +300,7 @@ s,@FFLAGS@,$(FFLAGS),;t t
s,@LDFLAGS@,,;t t
s,@LIBS@,$(LIBS),;t t
s,@exec_prefix@,$${prefix},;t t
-s,@prefix@,$(prefix),;t t
+s,@prefix@,,;t t
s,@program_transform_name@,s,,,,;t t
s,@bindir@,$${exec_prefix}/bin,;t t
s,@sbindir@,$${exec_prefix}/sbin,;t t
@@ -340,8 +331,6 @@ s,@target_vendor@,pc,;t t
s,@target_os@,$(OS),;t t
s,@CC@,$(CC),;t t
s,@CPP@,cpp32,;t t
-s,@CXX@,$$(CC),;t t
-s,@LD@,$(LD),;t t
s,@YACC@,$(YACC),;t t
s,@RANLIB@,,;t t
s,@AR@,$(AR),;t t
@@ -399,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,;t t
+s,@COMMON_MACROS@,WIN32_LEAN_AND_MEAN WIN32,;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
@@ -437,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)
@@ -472,7 +461,6 @@ ext/extinit.obj: ext/extinit.c $(SETUP)
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -o$@ -c ext/extinit.c
main.$(OBJEXT): win32.h
-ascii.$(OBJEXT): win32.h
array.$(OBJEXT): win32.h
bignum.$(OBJEXT): win32.h
class.$(OBJEXT): win32.h
@@ -481,7 +469,6 @@ dir.$(OBJEXT): dir.h win32.h
dln.$(OBJEXT): win32.h
enum.$(OBJEXT): win32.h
error.$(OBJEXT): win32.h
-euc_jp.$(OBJEXT): win32.h
eval.$(OBJEXT): win32.h
file.$(OBJEXT): win32.h
gc.$(OBJEXT): win32.h
@@ -499,21 +486,14 @@ prec.$(OBJEXT): win32.h
random.$(OBJEXT): win32.h
range.$(OBJEXT): win32.h
re.$(OBJEXT): win32.h
-regcomp.$(OBJEXT): win32.h
-regenc.$(OBJEXT): win32.h
-regerror.$(OBJEXT): win32.h
-regexec.$(OBJEXT): win32.h
-reggnu.$(OBJEXT): win32.h
-regparse.$(OBJEXT): win32.h
+regex.$(OBJEXT): win32.h
ruby.$(OBJEXT): win32.h
signal.$(OBJEXT): win32.h
-sjis.$(OBJEXT): win32.h
sprintf.$(OBJEXT): win32.h
st.$(OBJEXT): win32.h
string.$(OBJEXT): win32.h
struct.$(OBJEXT): win32.h
time.$(OBJEXT): win32.h
-utf8.$(OBJEXT): win32.h
util.$(OBJEXT): win32.h
variable.$(OBJEXT): win32.h
version.$(OBJEXT): win32.h
diff --git a/bcc32/README.bcc32 b/bcc32/README.bcc32
index fb19906c75..c27a1261f1 100644
--- a/bcc32/README.bcc32
+++ b/bcc32/README.bcc32
@@ -16,7 +16,7 @@
* ilink32
(3) If you want to build from CVS source, following commands are required.
- * bison ((<URL:http://gnuwin32.sourceforge.net/packages/bison.htm>))
+ * byacc ((<URL:http://gnuwin32.sourceforge.net/packages/byacc.htm>))
* sed ((<URL:http://gnuwin32.sourceforge.net/packages/sed.htm>))
(4) We strongly recommend to build ruby on C++Builder, to link following files.
@@ -30,12 +30,7 @@
== How to compile and install
(1) Execute bcc32\configure.bat on your build directory.
- ex. c:\src\ruby> bcc32\configure.bat
- You can specify the target platform as an argument.
- For example, run `((%configure i686-bccwin32%))'
- You can also specify the install directory.
- For example, run `((%configure --prefix=<install_directory>%))'
- Default of the install directory is /usr .
+ ex. c:\ruby-1.6.7>bcc32\configure.bat
(2) Change ((|RUBY_INSTALL_NAME|)) and ((|RUBY_SO_NAME|)) in (({Makefile}))
if you want to change the name of the executable files.
@@ -46,7 +41,7 @@
(4) Run `((%make test%))'
-(5) Run `((%make install%))'
+(5) Run `((%make DESTDIR=<install_directory> install%))'
This command will create following directories and install files onto them.
* <install_directory>\bin
@@ -59,7 +54,7 @@
* <install_directory>\lib\ruby\site_ruby\<MAJOR>.<MINOR>\<PLATFORM>
* <install_directory>\man\man1
If Ruby's version is `x.y.z', the ((|<MAJOR>|)) is `x' and the ((|<MINOR>|)) is `y'.
- The default ((|<PLATFORM>|)) is `(({i386-bccwin32}))'.
+ The ((|<PLATFORM>|)) is usually `(({i586-bccwin32}))'.
(6) Requires dynamic RTL (cc3250.dll on C++Builder5) and borlndmm.dll (If built with
usebormm.lib) to use installed binary. These files are ordinary in bcc32's bin
@@ -95,10 +90,10 @@ in Japanese, but you can download at least.
C:
cd \ruby
- bcc32\configure --prefix=/usr/local
+ bcc32\configure
make
make test
- make install
+ make DESTDIR=/usr/local install
* Build on the relative directory from the ruby source directory and CPU type
i386.
@@ -113,10 +108,10 @@ in Japanese, but you can download at least.
cd \ruby
mkdir bccwin32
cd bccwin32
- ..\bcc32\configure --prefix=/usr/local
+ ..\bcc32\configure target i386-bccwin32
make
make test
- make install
+ make DESTDIR=/usr/local install
* Build on the different drive.
@@ -127,10 +122,10 @@ in Japanese, but you can download at least.
D:
cd D:\build\ruby
- C:\src\ruby\bcc32\configure --prefix=C:/usr/local
+ C:\src\ruby\bcc32\configure
make
make test
- make install
+ make DESTDIR=C:/usr/local install
== Bugs
diff --git a/bcc32/configure.bat b/bcc32/configure.bat
index 6e3056ff38..143ad947f0 100644..100755
--- a/bcc32/configure.bat
+++ b/bcc32/configure.bat
@@ -78,12 +78,12 @@ goto :loop
echo --help display this help
echo --srcdir=DIR find the sources in DIR [configure dir or `..']
echo Installation directories:
- echo --prefix=PREFIX install files in PREFIX [/usr]
+ echo --prefix=PREFIX install files in PREFIX (ignored currently)
echo System types:
echo --target=TARGET configure for TARGET [i386-bccwin32]
echo Optional Package:
echo --with-static-linked-ext link external modules statically
- echo --disable-install-doc do not install rdoc indexes during install
+ echo --enable-install-doc install rdoc indexes during install
del ~tmp~.mak
goto :exit
:end
diff --git a/bcc32/mkexports.rb b/bcc32/mkexports.rb
index 1b498f8515..dc523e2541 100644..100755
--- a/bcc32/mkexports.rb
+++ b/bcc32/mkexports.rb
@@ -1,24 +1,27 @@
#!./miniruby -s
-$:.unshift(File.expand_path("../..", __FILE__))
-require 'win32/mkexports'
+$name = $library = $description = nil
-class Exports::Bcc < Exports
- Forwards = /^rb_w32_(\w+)/
-
- def forwarding(internal, export)
- internal[/\A_?/]+export
+SYM = {}
+STDIN.reopen(open("nul"))
+ARGV.each do |obj|
+ IO.foreach("|tdump -q -oiPUBDEF -oiPUBD32 #{obj.tr('/', '\\')}") do |l|
+ next unless /(?:PUBDEF|PUBD32)/ =~ l
+ SYM[$1] = true if /'(.*?)'/ =~ l
end
+end
- def each_export(objs)
- objs.each do |obj|
- opt = /\.(?:so|dll)\z/i =~ obj ? "-ee" : "-oiPUBDEF -oiPUBD32"
- IO.foreach("|tdump -q #{opt} #{obj.tr('/', '\\')} < nul") do |l|
- next unless /(?:PUBDEF|PUBD32|EXPORT)/ =~ l
- yield $1 if /'(.*?)'/ =~ l
- end
- end
- yield "_strcasecmp", "_stricmp"
- yield "_strncasecmp", "_strnicmp"
- end
+exports = []
+if $name
+ exports << "Name " + $name
+elsif $library
+ exports << "Library " + $library
+end
+exports << "Description " + $description.dump if $description
+exports << "EXPORTS" << SYM.keys.sort
+
+if $output
+ open($output, 'w') {|f| f.puts exports.join("\n")}
+else
+ puts exports.join("\n")
end
diff --git a/bcc32/setup.mak b/bcc32/setup.mak
index 8f73b4f9f7..b7a2539d0a 100644
--- a/bcc32/setup.mak
+++ b/bcc32/setup.mak
@@ -1,15 +1,15 @@
# -*- 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
-!if "$(prefix)" == ""
+!ifndef prefix
prefix = /usr
!endif
OS = bccwin32
@@ -62,7 +62,7 @@ if exist usebormm.tds echo MEMLIB = usebormm.lib
@usebormm.bat >> $(MAKEFILE)
@del usebormm.*
- @cpp32 -I$(srcdir) -P- -DRUBY_EXTERN="//" -o$(MAKEFILE) > nul &&|
+ @cpp32 -I$(srcdir) -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 f0c3a0f63a..c23b76b1fe 100644
--- a/bignum.c
+++ b/bignum.c
@@ -11,6 +11,7 @@
**********************************************************************/
#include "ruby.h"
+#include "rubysig.h"
#include <math.h>
#include <ctype.h>
@@ -36,10 +37,27 @@ VALUE rb_cBignum;
#define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1)))
#define BDIGMAX ((BDIGIT)-1)
-#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || (RBIGNUM(x)->len == 1 && BDIGITS(x)[0] == 0))
+#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;
+}
static VALUE
-bignew_1(VALUE klass, long len, int sign)
+bignew_1(klass, len, sign)
+ VALUE klass;
+ long len;
+ int sign;
{
NEWOBJ(big, struct RBignum);
OBJSETUP(big, klass, T_BIGNUM);
@@ -53,7 +71,8 @@ bignew_1(VALUE klass, long len, int sign)
#define bignew(len,sign) bignew_1(rb_cBignum,len,sign)
VALUE
-rb_big_clone(VALUE x)
+rb_big_clone(x)
+ VALUE x;
{
VALUE z = bignew_1(CLASS_OF(x), RBIGNUM(x)->len, RBIGNUM(x)->sign);
@@ -63,12 +82,14 @@ rb_big_clone(VALUE x)
/* modify a bignum by 2's complement */
static void
-get2comp(VALUE x)
+get2comp(x)
+ VALUE x;
{
long i = RBIGNUM(x)->len;
BDIGIT *ds = BDIGITS(x);
BDIGIT_DBL num;
+ if (!i) return;
while (i--) ds[i] = ~ds[i];
i = 0; num = 1;
do {
@@ -79,53 +100,72 @@ get2comp(VALUE x)
if (num != 0) {
REALLOC_N(RBIGNUM(x)->digits, BDIGIT, ++RBIGNUM(x)->len);
ds = BDIGITS(x);
- ds[RBIGNUM(x)->len-1] = 1;
+ ds[RBIGNUM(x)->len-1] = RBIGNUM(x)->sign ? ~0 : 1;
}
}
void
-rb_big_2comp(VALUE x) /* get 2's complement */
+rb_big_2comp(x) /* get 2's complement */
+ VALUE x;
{
get2comp(x);
}
static VALUE
-bignorm(VALUE x)
+bigtrunc(x)
+ VALUE x;
{
- if (FIXNUM_P(x)) {
- return x;
- }
- else if (TYPE(x) == T_BIGNUM) {
- long len = RBIGNUM(x)->len;
- BDIGIT *ds = BDIGITS(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;
+}
- while (len-- && !ds[len]) ;
- RBIGNUM(x)->len = ++len;
+static VALUE
+bigfixize(VALUE x)
+{
+ long len = RBIGNUM(x)->len;
+ BDIGIT *ds = BDIGITS(x);
- if (len*SIZEOF_BDIGITS <= sizeof(VALUE)) {
- SIGNED_VALUE num = 0;
- while (len--) {
- num = BIGUP(num) + ds[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 (num >= 0) {
- if (RBIGNUM(x)->sign) {
- if (POSFIXABLE(num)) return LONG2FIX(num);
- }
- else if (NEGFIXABLE(-(long)num)) return LONG2FIX(-(long)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(VALUE x)
+rb_big_norm(x)
+ VALUE x;
{
return bignorm(x);
}
VALUE
-rb_uint2big(VALUE n)
+rb_uint2big(n)
+ unsigned long n;
{
BDIGIT_DBL num = n;
long i = 0;
@@ -146,7 +186,8 @@ rb_uint2big(VALUE n)
}
VALUE
-rb_int2big(SIGNED_VALUE n)
+rb_int2big(n)
+ long n;
{
long neg = 0;
VALUE big;
@@ -163,14 +204,16 @@ rb_int2big(SIGNED_VALUE n)
}
VALUE
-rb_uint2inum(VALUE n)
+rb_uint2inum(n)
+ unsigned long n;
{
if (POSFIXABLE(n)) return LONG2FIX(n);
return rb_uint2big(n);
}
VALUE
-rb_int2inum(SIGNED_VALUE n)
+rb_int2inum(n)
+ long n;
{
if (FIXABLE(n)) return LONG2FIX(n);
return rb_int2big(n);
@@ -179,7 +222,9 @@ rb_int2inum(SIGNED_VALUE n)
#ifdef HAVE_LONG_LONG
void
-rb_quad_pack(char *buf, VALUE val)
+rb_quad_pack(buf, val)
+ char *buf;
+ VALUE val;
{
LONG_LONG q;
@@ -191,9 +236,8 @@ rb_quad_pack(char *buf, VALUE val)
long len = RBIGNUM(val)->len;
BDIGIT *ds;
- if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS) {
- len = SIZEOF_LONG_LONG/SIZEOF_BDIGITS;
- }
+ if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS)
+ rb_raise(rb_eRangeError, "bignum too big to convert into `quad int'");
ds = BDIGITS(val);
q = 0;
while (len--) {
@@ -206,7 +250,9 @@ rb_quad_pack(char *buf, VALUE val)
}
VALUE
-rb_quad_unpack(const char *buf, int sign)
+rb_quad_unpack(buf, sign)
+ const char *buf;
+ int sign;
{
unsigned LONG_LONG q;
long neg = 0;
@@ -249,7 +295,9 @@ rb_quad_unpack(const char *buf, int sign)
#define QUAD_SIZE 8
void
-rb_quad_pack(char *buf, VALUE val)
+rb_quad_pack(buf, val)
+ char *buf;
+ VALUE val;
{
long len;
@@ -275,7 +323,9 @@ rb_quad_pack(char *buf, VALUE val)
#define BNEG(b) (RSHIFT(((BDIGIT*)b)[QUAD_SIZE/SIZEOF_BDIGITS-1],BITSPERDIG-1) != 0)
VALUE
-rb_quad_unpack(const char *buf, int sign)
+rb_quad_unpack(buf, sign)
+ const char *buf;
+ int sign;
{
VALUE big = bignew(QUAD_SIZE/SIZEOF_BDIGITS, 1);
@@ -297,7 +347,10 @@ rb_quad_unpack(const char *buf, int sign)
#endif
VALUE
-rb_cstr_to_inum(const char *str, int base, int badcheck)
+rb_cstr_to_inum(str, base, badcheck)
+ const char *str;
+ int base;
+ int badcheck;
{
const char *s = str;
char *end;
@@ -309,11 +362,23 @@ rb_cstr_to_inum(const char *str, int base, int 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);
}
- while (ISSPACE(*str)) str++;
+ if (badcheck) {
+ while (ISSPACE(*str)) str++;
+ }
+ else {
+ while (ISSPACE(*str) || *str == '_') str++;
+ }
if (str[0] == '+') {
str++;
@@ -396,14 +461,20 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
}
if (*str == '0') { /* squeeze preceeding 0s */
while (*++str == '0');
- --str;
+ if (!(c = *str) || ISSPACE(c)) --str;
+ }
+ c = *str;
+ c = conv_digit(c);
+ if (c < 0 || c >= base) {
+ if (badcheck) goto bad;
+ return INT2FIX(0);
}
len *= strlen(str)*sizeof(char);
if (len <= (sizeof(VALUE)*CHAR_BIT)) {
- unsigned long val = strtoul(str, &end, base);
+ unsigned long val = strtoul((char*)str, &end, base);
- if (str < end && *end == '_') goto bigparse;
+ if (*end == '_') goto bigparse;
if (badcheck) {
if (end == str) goto bad; /* no number */
while (*end && ISSPACE(*end)) end++;
@@ -430,7 +501,7 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
z = bignew(len, sign);
zds = BDIGITS(z);
for (i=len;i--;) zds[i]=0;
- while (c = *str++) {
+ while ((c = *str++) != 0) {
if (c == '_') {
if (badcheck) {
if (nondigit) goto bad;
@@ -438,19 +509,7 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
}
continue;
}
- 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 {
+ else if ((c = conv_digit(c)) < 0) {
break;
}
if (c >= base) break;
@@ -484,7 +543,10 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
}
VALUE
-rb_str_to_inum(VALUE str, int base, int badcheck)
+rb_str_to_inum(str, base, badcheck)
+ VALUE str;
+ int base;
+ int badcheck;
{
char *s;
long len;
@@ -494,10 +556,10 @@ rb_str_to_inum(VALUE str, int base, int badcheck)
s = StringValueCStr(str);
}
else {
- s = RSTRING_PTR(str);
+ s = RSTRING(str)->ptr;
}
if (s) {
- len = RSTRING_LEN(str);
+ len = RSTRING(str)->len;
if (s[len]) { /* no sentinel somehow */
char *p = ALLOCA_N(char, len+1);
@@ -511,8 +573,9 @@ rb_str_to_inum(VALUE str, int base, int badcheck)
#if HAVE_LONG_LONG
-static VALUE
-rb_ull2big(unsigned LONG_LONG n)
+VALUE
+rb_ull2big(n)
+ unsigned LONG_LONG n;
{
BDIGIT_DBL num = n;
long i = 0;
@@ -532,8 +595,9 @@ rb_ull2big(unsigned LONG_LONG n)
return big;
}
-static VALUE
-rb_ll2big(LONG_LONG n)
+VALUE
+rb_ll2big(n)
+ LONG_LONG n;
{
long neg = 0;
VALUE big;
@@ -550,14 +614,16 @@ rb_ll2big(LONG_LONG n)
}
VALUE
-rb_ull2inum(unsigned LONG_LONG n)
+rb_ull2inum(n)
+ unsigned LONG_LONG n;
{
if (POSFIXABLE(n)) return LONG2FIX(n);
return rb_ull2big(n);
}
VALUE
-rb_ll2inum(LONG_LONG n)
+rb_ll2inum(n)
+ LONG_LONG n;
{
if (FIXABLE(n)) return LONG2FIX(n);
return rb_ll2big(n);
@@ -566,20 +632,27 @@ rb_ll2inum(LONG_LONG n)
#endif /* HAVE_LONG_LONG */
VALUE
-rb_cstr2inum(const char *str, int base)
+rb_cstr2inum(str, base)
+ const char *str;
+ int base;
{
return rb_cstr_to_inum(str, base, base==0);
}
VALUE
-rb_str2inum(VALUE str, int base)
+rb_str2inum(str, base)
+ VALUE str;
+ int base;
{
return rb_str_to_inum(str, base, base==0);
}
const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
VALUE
-rb_big2str0(VALUE x, int base, int trim)
+rb_big2str0(x, base, trim)
+ VALUE x;
+ int base;
+ int trim;
{
volatile VALUE t;
BDIGIT *ds;
@@ -590,10 +663,13 @@ rb_big2str0(VALUE x, int base, int trim)
if (FIXNUM_P(x)) {
return rb_fix2str(x, base);
}
+ i = RBIGNUM(x)->len;
if (BIGZEROP(x)) {
return rb_str_new2("0");
}
- i = RBIGNUM(x)->len;
+ 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;
@@ -601,10 +677,10 @@ rb_big2str0(VALUE x, int base, int trim)
j = j * 53L / 84 + 1;
break;
case 4: case 5: case 6: case 7:
- j /= 2;
+ j = (j + 1) / 2;
break;
case 8: case 9:
- j /= 3;
+ j = (j + 2) / 3;
break;
case 10: case 11: case 12: case 13: case 14: case 15:
j = j * 28L / 93 + 1;
@@ -612,10 +688,10 @@ rb_big2str0(VALUE x, int base, int 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 /= 4;
+ j = (j + 3) / 4;
break;
case 32: case 33: case 34: case 35: case 36:
- j /= 5;
+ j = (j + 4) / 5;
break;
default:
rb_raise(rb_eArgError, "illegal radix %d", base);
@@ -631,9 +707,10 @@ rb_big2str0(VALUE x, int base, int trim)
t = rb_big_clone(x);
ds = BDIGITS(t);
ss = rb_str_new(0, j+1);
- s = RSTRING_PTR(ss);
+ s = RSTRING(ss)->ptr;
s[0] = RBIGNUM(x)->sign ? '+' : '-';
+ TRAP_BEG;
while (i && j > 1) {
long k = i;
BDIGIT_DBL num = 0;
@@ -648,20 +725,22 @@ rb_big2str0(VALUE x, int base, int 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;
}
}
if (trim) {while (s[j] == '0') j++;}
- i = RSTRING_LEN(ss) - j;
+ i = RSTRING(ss)->len - j;
if (RBIGNUM(x)->sign) {
memmove(s, s+j, i);
- i--;
+ RSTRING(ss)->len = i-1;
}
else {
memmove(s+1, s+j, i);
+ RSTRING(ss)->len = i;
}
- rb_str_set_len(ss, i);
+ s[RSTRING(ss)->len] = '\0';
+ TRAP_END;
return ss;
}
@@ -687,7 +766,10 @@ rb_big2str(VALUE x, int base)
*/
static VALUE
-rb_big_to_s(int argc, VALUE *argv, VALUE x)
+rb_big_to_s(argc, argv, x)
+ int argc;
+ VALUE *argv;
+ VALUE x;
{
VALUE b;
int base;
@@ -698,18 +780,17 @@ rb_big_to_s(int argc, VALUE *argv, VALUE x)
return rb_big2str(x, base);
}
-static VALUE
-big2ulong(VALUE x, const char *type, int check)
+static unsigned long
+big2ulong(x, type)
+ VALUE x;
+ char *type;
{
long len = RBIGNUM(x)->len;
BDIGIT_DBL num;
BDIGIT *ds;
- if (len > SIZEOF_VALUE/SIZEOF_BDIGITS) {
- if (check)
- rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
- len = SIZEOF_VALUE/SIZEOF_BDIGITS;
- }
+ if (len > SIZEOF_LONG/SIZEOF_BDIGITS)
+ rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
ds = BDIGITS(x);
num = 0;
while (len--) {
@@ -719,23 +800,25 @@ big2ulong(VALUE x, const char *type, int check)
return num;
}
-VALUE
-rb_big2ulong_pack(VALUE x)
-{
- VALUE num = big2ulong(x, "unsigned long", Qfalse);
+unsigned long
+rb_big2ulong_pack(x)
+ VALUE x;
+{
+ unsigned long num = big2ulong(x, "unsigned long");
if (!RBIGNUM(x)->sign) {
return -num;
}
return num;
-}
+}
-VALUE
-rb_big2ulong(VALUE x)
+unsigned long
+rb_big2ulong(x)
+ VALUE x;
{
- VALUE num = big2ulong(x, "unsigned long", Qtrue);
+ unsigned long num = big2ulong(x, "unsigned long");
if (!RBIGNUM(x)->sign) {
- if ((SIGNED_VALUE)num < 0) {
+ if ((long)num < 0) {
rb_raise(rb_eRangeError, "bignum out of range of unsigned long");
}
return -num;
@@ -743,23 +826,25 @@ rb_big2ulong(VALUE x)
return num;
}
-SIGNED_VALUE
-rb_big2long(VALUE x)
+long
+rb_big2long(x)
+ VALUE x;
{
- VALUE num = big2ulong(x, "long", Qtrue);
+ unsigned long num = big2ulong(x, "long");
- if ((SIGNED_VALUE)num < 0 &&
- (RBIGNUM(x)->sign || (SIGNED_VALUE)num != LONG_MIN)) {
+ if ((long)num < 0 && (RBIGNUM(x)->sign || (long)num != LONG_MIN)) {
rb_raise(rb_eRangeError, "bignum too big to convert into `long'");
}
- if (!RBIGNUM(x)->sign) return -(SIGNED_VALUE)num;
+ if (!RBIGNUM(x)->sign) return -(long)num;
return num;
}
#if HAVE_LONG_LONG
static unsigned LONG_LONG
-big2ull(VALUE x, const char *type)
+big2ull(x, type)
+ VALUE x;
+ char *type;
{
long len = RBIGNUM(x)->len;
BDIGIT_DBL num;
@@ -777,7 +862,8 @@ big2ull(VALUE x, const char *type)
}
unsigned LONG_LONG
-rb_big2ull(VALUE x)
+rb_big2ull(x)
+ VALUE x;
{
unsigned LONG_LONG num = big2ull(x, "unsigned long long");
@@ -786,7 +872,8 @@ rb_big2ull(VALUE x)
}
LONG_LONG
-rb_big2ll(VALUE x)
+rb_big2ll(x)
+ VALUE x;
{
unsigned LONG_LONG num = big2ull(x, "long long");
@@ -801,7 +888,8 @@ rb_big2ll(VALUE x)
#endif /* HAVE_LONG_LONG */
static VALUE
-dbl2big(double d)
+dbl2big(d)
+ double d;
{
long i = 0;
BDIGIT c;
@@ -833,13 +921,15 @@ dbl2big(double d)
}
VALUE
-rb_dbl2big(double d)
+rb_dbl2big(d)
+ double d;
{
return bignorm(dbl2big(d));
}
double
-rb_big2dbl(VALUE x)
+rb_big2dbl(x)
+ VALUE x;
{
double d = 0.0;
long i = RBIGNUM(x)->len;
@@ -866,7 +956,8 @@ rb_big2dbl(VALUE x)
*/
static VALUE
-rb_big_to_f(VALUE x)
+rb_big_to_f(x)
+ VALUE x;
{
return rb_float_new(rb_big2dbl(x));
}
@@ -881,8 +972,9 @@ rb_big_to_f(VALUE x)
*
*/
-VALUE
-rb_big_cmp(VALUE x, VALUE y)
+static VALUE
+rb_big_cmp(x, y)
+ VALUE x, y;
{
long xlen = RBIGNUM(x)->len;
@@ -926,8 +1018,9 @@ rb_big_cmp(VALUE x, VALUE y)
* 68719476736 == 68719476736.0 #=> true
*/
-VALUE
-rb_big_eq(VALUE x, VALUE y)
+static VALUE
+rb_big_eq(x, y)
+ VALUE x, y;
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -965,7 +1058,8 @@ rb_big_eq(VALUE x, VALUE y)
*/
static VALUE
-rb_big_eql(VALUE x, VALUE y)
+rb_big_eql(x, y)
+ VALUE x, y;
{
if (TYPE(y) != T_BIGNUM) return Qfalse;
if (RBIGNUM(x)->sign != RBIGNUM(y)->sign) return Qfalse;
@@ -982,7 +1076,8 @@ rb_big_eql(VALUE x, VALUE y)
*/
static VALUE
-rb_big_uminus(VALUE x)
+rb_big_uminus(x)
+ VALUE x;
{
VALUE z = rb_big_clone(x);
@@ -1004,18 +1099,18 @@ rb_big_uminus(VALUE x)
*/
static VALUE
-rb_big_neg(VALUE x)
+rb_big_neg(x)
+ VALUE x;
{
VALUE z = rb_big_clone(x);
- BDIGIT *ds;
long i;
+ BDIGIT *ds;
if (!RBIGNUM(x)->sign) get2comp(z);
ds = BDIGITS(z);
i = RBIGNUM(x)->len;
- while (i--) {
- ds[i] = ~ds[i];
- }
+ if (!i) return INT2FIX(~0);
+ while (i--) ds[i] = ~ds[i];
RBIGNUM(z)->sign = !RBIGNUM(z)->sign;
if (RBIGNUM(x)->sign) get2comp(z);
@@ -1023,7 +1118,8 @@ rb_big_neg(VALUE x)
}
static VALUE
-bigsub(VALUE x, VALUE y)
+bigsub(x, y)
+ VALUE x, y;
{
VALUE z = 0;
BDIGIT *zds;
@@ -1069,7 +1165,9 @@ bigsub(VALUE x, VALUE y)
}
static VALUE
-bigadd(VALUE x, VALUE y, int sign)
+bigadd(x, y, sign)
+ VALUE x, y;
+ int sign;
{
VALUE z;
BDIGIT_DBL num;
@@ -1119,7 +1217,8 @@ bigadd(VALUE x, VALUE y, int sign)
*/
VALUE
-rb_big_plus(VALUE x, VALUE y)
+rb_big_plus(x, y)
+ VALUE x, y;
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -1144,7 +1243,8 @@ rb_big_plus(VALUE x, VALUE y)
*/
VALUE
-rb_big_minus(VALUE x, VALUE y)
+rb_big_minus(x, y)
+ VALUE x, y;
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -1161,14 +1261,16 @@ rb_big_minus(VALUE x, VALUE y)
}
}
-static VALUE
-rb_big_mul0(VALUE x, VALUE y)
+VALUE
+rb_big_mul0(x, y)
+ VALUE x, y;
{
long i, j;
BDIGIT_DBL n = 0;
VALUE z;
BDIGIT *zds;
+ if (FIXNUM_P(x)) x = rb_int2big(FIX2LONG(x));
switch (TYPE(y)) {
case T_FIXNUM:
y = rb_int2big(FIX2LONG(y));
@@ -1202,6 +1304,7 @@ rb_big_mul0(VALUE x, VALUE y)
zds[i + j] = n;
}
}
+
return z;
}
@@ -1213,13 +1316,16 @@ rb_big_mul0(VALUE x, VALUE y)
*/
VALUE
-rb_big_mul(VALUE x, VALUE y)
+rb_big_mul(x, y)
+ VALUE x, y;
{
return bignorm(rb_big_mul0(x, y));
}
static void
-bigdivrem(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
+bigdivrem(x, y, divp, modp)
+ VALUE x, y;
+ VALUE *divp, *modp;
{
long nx = RBIGNUM(x)->len, ny = RBIGNUM(y)->len;
long i, j;
@@ -1249,7 +1355,7 @@ bigdivrem(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
}
RBIGNUM(z)->sign = RBIGNUM(x)->sign==RBIGNUM(y)->sign;
if (modp) {
- *modp = rb_uint2big((VALUE)t2);
+ *modp = rb_uint2big((unsigned long)t2);
RBIGNUM(*modp)->sign = RBIGNUM(x)->sign;
}
if (divp) *divp = z;
@@ -1262,8 +1368,8 @@ bigdivrem(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
dd = 0;
q = yds[ny-1];
- while ((q & (1UL<<(BITSPERDIG-1))) == 0) {
- q <<= 1UL;
+ while ((q & (1<<(BITSPERDIG-1))) == 0) {
+ q <<= 1;
dd++;
}
if (dd) {
@@ -1347,7 +1453,9 @@ bigdivrem(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
}
static void
-bigdivmod(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
+bigdivmod(x, y, divp, modp)
+ VALUE x, y;
+ VALUE *divp, *modp;
{
VALUE mod;
@@ -1370,8 +1478,9 @@ bigdivmod(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
* Divides big by other, returning the result.
*/
-VALUE
-rb_big_div(VALUE x, VALUE y)
+static VALUE
+rb_big_div(x, y)
+ VALUE x, y;
{
VALUE z;
@@ -1403,8 +1512,9 @@ rb_big_div(VALUE x, VALUE y)
* information.
*/
-VALUE
-rb_big_modulo(VALUE x, VALUE y)
+static VALUE
+rb_big_modulo(x, y)
+ VALUE x, y;
{
VALUE z;
@@ -1434,7 +1544,8 @@ rb_big_modulo(VALUE x, VALUE y)
* -1234567890987654321.remainder(13731.24) #=> -9906.22531493148
*/
static VALUE
-rb_big_remainder(VALUE x, VALUE y)
+rb_big_remainder(x, y)
+ VALUE x, y;
{
VALUE z;
@@ -1454,6 +1565,20 @@ rb_big_remainder(VALUE x, VALUE 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
@@ -1462,7 +1587,8 @@ rb_big_remainder(VALUE x, VALUE y)
*
*/
VALUE
-rb_big_divmod(VALUE x, VALUE y)
+rb_big_divmod(x, y)
+ VALUE x, y;
{
VALUE div, mod;
@@ -1495,7 +1621,8 @@ rb_big_divmod(VALUE x, VALUE y)
*/
static VALUE
-rb_big_quo(VALUE x, VALUE y)
+rb_big_quo(x, y)
+ VALUE x, y;
{
double dx = rb_big2dbl(x);
double dy;
@@ -1533,7 +1660,8 @@ rb_big_quo(VALUE x, VALUE y)
*/
VALUE
-rb_big_pow(VALUE x, VALUE y)
+rb_big_pow(x, y)
+ VALUE x, y;
{
double d;
long yy;
@@ -1553,8 +1681,10 @@ rb_big_pow(VALUE x, VALUE y)
yy = FIX2LONG(y);
if (yy > 0) {
VALUE z = x;
+ const long BIGLEN_LIMIT = 1024*1024 / SIZEOF_BDIGITS;
- if (RBIGNUM(x)->len * SIZEOF_BDIGITS * yy > 1024*1024) {
+ if ((RBIGNUM(x)->len > BIGLEN_LIMIT) ||
+ (RBIGNUM(x)->len > BIGLEN_LIMIT / yy)) {
rb_warn("in a**b, b may be too big");
d = (double)yy;
break;
@@ -1565,10 +1695,10 @@ rb_big_pow(VALUE x, VALUE y)
while (yy % 2 == 0) {
yy /= 2;
x = rb_big_mul0(x, x);
- if (!BDIGITS(x)[RBIGNUM(x)->len-1]) RBIGNUM(x)->len--;
+ bigtrunc(x);
}
z = rb_big_mul0(z, x);
- if (!BDIGITS(z)[RBIGNUM(z)->len-1]) RBIGNUM(z)->len--;
+ bigtrunc(z);
}
return bignorm(z);
}
@@ -1589,7 +1719,8 @@ rb_big_pow(VALUE x, VALUE y)
*/
VALUE
-rb_big_and(VALUE xx, VALUE yy)
+rb_big_and(xx, yy)
+ VALUE xx, yy;
{
volatile VALUE x, y, z;
BDIGIT *ds1, *ds2, *zds;
@@ -1644,7 +1775,8 @@ rb_big_and(VALUE xx, VALUE yy)
*/
VALUE
-rb_big_or(VALUE xx, VALUE yy)
+rb_big_or(xx, yy)
+ VALUE xx, yy;
{
volatile VALUE x, y, z;
BDIGIT *ds1, *ds2, *zds;
@@ -1656,7 +1788,6 @@ rb_big_or(VALUE xx, VALUE yy)
if (FIXNUM_P(y)) {
y = rb_int2big(FIX2LONG(y));
}
-
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
get2comp(y);
@@ -1701,7 +1832,8 @@ rb_big_or(VALUE xx, VALUE yy)
*/
VALUE
-rb_big_xor(VALUE xx, VALUE yy)
+rb_big_xor(xx, yy)
+ VALUE xx, yy;
{
volatile VALUE x, y;
VALUE z;
@@ -1714,7 +1846,6 @@ rb_big_xor(VALUE xx, VALUE yy)
if (FIXNUM_P(y)) {
y = rb_int2big(FIX2LONG(y));
}
-
if (!RBIGNUM(y)->sign) {
y = rb_big_clone(y);
get2comp(y);
@@ -1753,7 +1884,15 @@ rb_big_xor(VALUE xx, VALUE yy)
return bignorm(z);
}
-static VALUE rb_big_rshift(VALUE,VALUE);
+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;
+}
/*
* call-seq:
@@ -1763,17 +1902,49 @@ static VALUE rb_big_rshift(VALUE,VALUE);
*/
VALUE
-rb_big_lshift(VALUE x, VALUE y)
+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;
- int shift = NUM2INT(y);
- int s1 = shift/BITSPERDIG;
+ long 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);
@@ -1797,20 +1968,53 @@ rb_big_lshift(VALUE x, VALUE y)
* Shifts big right _numeric_ positions (left if _numeric_ is negative).
*/
+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
-rb_big_rshift(VALUE x, VALUE y)
+big_rshift(x, shift)
+ VALUE x;
+ unsigned long shift;
{
BDIGIT *xds, *zds;
- int shift = NUM2INT(y);
long s1 = shift/BITSPERDIG;
- long s2 = shift%BITSPERDIG;
+ int 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);
@@ -1863,32 +2067,43 @@ rb_big_rshift(VALUE x, VALUE y)
*/
static VALUE
-rb_big_aref(VALUE x, VALUE y)
+rb_big_aref(x, y)
+ VALUE x, y;
{
BDIGIT *xds;
- int shift;
- long s1, s2;
+ BDIGIT_DBL num;
+ unsigned long shift;
+ long i, s1, s2;
if (TYPE(y) == T_BIGNUM) {
- if (!RBIGNUM(y)->sign || RBIGNUM(x)->sign)
+ if (!RBIGNUM(y)->sign)
return INT2FIX(0);
- return INT2FIX(1);
+ 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;
}
- 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) {
- if (s1 >= RBIGNUM(x)->len) return INT2FIX(1);
- x = rb_big_clone(x);
- get2comp(x);
+ xds = BDIGITS(x);
+ i = 0; num = 1;
+ while (num += ~xds[i], ++i <= s1) {
+ num = BIGDN(num);
+ }
}
else {
- if (s1 >= RBIGNUM(x)->len) return INT2FIX(0);
+ num = BDIGITS(x)[s1];
}
- xds = BDIGITS(x);
- if (xds[s1] & (1<<s2))
+ if (num & ((BDIGIT_DBL)1<<s2))
return INT2FIX(1);
return INT2FIX(0);
}
@@ -1901,12 +2116,17 @@ rb_big_aref(VALUE x, VALUE y)
*/
static VALUE
-rb_big_hash(VALUE x)
+rb_big_hash(x)
+ VALUE x;
{
- int hash;
+ long i, len, key;
+ BDIGIT *digits;
- hash = rb_memhash(BDIGITS(x), BITSPERDIG*RBIGNUM(x)->len) ^ RBIGNUM(x)->sign;
- return INT2FIX(hash);
+ key = 0; digits = BDIGITS(x); len = RBIGNUM(x)->len;
+ for (i=0; i<len; i++) {
+ key ^= *digits++;
+ }
+ return LONG2FIX(key);
}
/*
@@ -1914,7 +2134,8 @@ rb_big_hash(VALUE x)
*/
static VALUE
-rb_big_coerce(VALUE x, VALUE y)
+rb_big_coerce(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
return rb_assoc_new(rb_int2big(FIX2LONG(y)), x);
@@ -1940,7 +2161,8 @@ rb_big_coerce(VALUE x, VALUE y)
*/
static VALUE
-rb_big_abs(VALUE x)
+rb_big_abs(x)
+ VALUE x;
{
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
@@ -1949,6 +2171,27 @@ rb_big_abs(VALUE x)
return x;
}
+VALUE
+rb_big_rand(max, rand_buf)
+ VALUE max;
+ double *rand_buf;
+{
+ VALUE v;
+ long len = RBIGNUM(max)->len;
+
+ if (BIGZEROP(max)) {
+ return rb_float_new(rand_buf[0]);
+ }
+ v = bignew(len,1);
+ len--;
+ BDIGITS(v)[len] = BDIGITS(max)[len] * rand_buf[len];
+ while (len--) {
+ BDIGITS(v)[len] = ((BDIGIT)~0) * rand_buf[len];
+ }
+
+ return v;
+}
+
/*
* call-seq:
* big.size -> integer
@@ -1962,7 +2205,8 @@ rb_big_abs(VALUE x)
*/
static VALUE
-rb_big_size(VALUE big)
+rb_big_size(big)
+ VALUE big;
{
return LONG2FIX(RBIGNUM(big)->len*SIZEOF_BDIGITS);
}
@@ -1986,7 +2230,7 @@ rb_big_size(VALUE big)
*/
void
-Init_Bignum(void)
+Init_Bignum()
{
rb_cBignum = rb_define_class("Bignum", rb_cInteger);
diff --git a/class.c b/class.c
index c7fc1df370..096c7fbdf1 100644
--- a/class.c
+++ b/class.c
@@ -19,7 +19,8 @@
extern st_table *rb_class_tbl;
VALUE
-rb_class_boot(VALUE super)
+rb_class_boot(super)
+ VALUE super;
{
NEWOBJ(klass, struct RClass);
OBJSETUP(klass, rb_cClass, T_CLASS);
@@ -33,43 +34,49 @@ rb_class_boot(VALUE super)
return (VALUE)klass;
}
-void
-rb_check_inheritable(VALUE super)
-{
- if (TYPE(super) != T_CLASS) {
- rb_raise(rb_eTypeError, "superclass must be a Class (%s given)",
- rb_obj_classname(super));
- }
- if (RBASIC(super)->flags & FL_SINGLETON) {
- rb_raise(rb_eTypeError, "can't make subclass of singleton class");
- }
-}
-
VALUE
-rb_class_new(VALUE super)
+rb_class_new(super)
+ VALUE super;
{
Check_Type(super, T_CLASS);
- rb_check_inheritable(super);
if (super == rb_cClass) {
rb_raise(rb_eTypeError, "can't make subclass of Class");
}
+ if (FL_TEST(super, FL_SINGLETON)) {
+ rb_raise(rb_eTypeError, "can't make subclass of virtual class");
+ }
return rb_class_boot(super);
}
+struct clone_method_data {
+ st_table *tbl;
+ VALUE klass;
+};
+
static int
-clone_method(ID mid, NODE *body, st_table *tbl)
+clone_method(mid, body, data)
+ ID mid;
+ NODE *body;
+ struct clone_method_data *data;
{
- st_insert(tbl, mid, (st_data_t)NEW_METHOD(body->nd_body, body->nd_noex));
+ NODE *fbody = body->nd_body;
+
+ if (fbody && nd_type(fbody) == NODE_SCOPE) {
+ fbody = rb_copy_node_scope(fbody, ruby_cref);
+ }
+ st_insert(data->tbl, mid, (st_data_t)NEW_METHOD(fbody, body->nd_noex));
return ST_CONTINUE;
}
/* :nodoc: */
VALUE
-rb_mod_init_copy(VALUE clone, VALUE orig)
+rb_mod_init_copy(clone, orig)
+ VALUE clone, orig;
{
rb_obj_init_copy(clone, orig);
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
- RBASIC(clone)->klass = rb_singleton_class_clone(orig);
+ RBASIC(clone)->klass = RBASIC(orig)->klass;
+ RBASIC(clone)->klass = rb_singleton_class_clone(clone);
}
RCLASS(clone)->super = RCLASS(orig)->super;
if (RCLASS(orig)->iv_tbl) {
@@ -82,9 +89,12 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
st_delete(RCLASS(clone)->iv_tbl, (st_data_t*)&id, 0);
}
if (RCLASS(orig)->m_tbl) {
- RCLASS(clone)->m_tbl = st_init_numtable();
- st_foreach(RCLASS(orig)->m_tbl, clone_method,
- (st_data_t)RCLASS(clone)->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);
}
return clone;
@@ -92,7 +102,8 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
/* :nodoc: */
VALUE
-rb_class_init_copy(VALUE clone, VALUE orig)
+rb_class_init_copy(clone, orig)
+ VALUE clone, orig;
{
if (RCLASS(clone)->super != 0) {
rb_raise(rb_eTypeError, "already initialized class");
@@ -104,7 +115,8 @@ rb_class_init_copy(VALUE clone, VALUE orig)
}
VALUE
-rb_singleton_class_clone(VALUE obj)
+rb_singleton_class_clone(obj)
+ VALUE obj;
{
VALUE klass = RBASIC(obj)->klass;
@@ -128,9 +140,22 @@ rb_singleton_class_clone(VALUE obj)
if (RCLASS(klass)->iv_tbl) {
clone->iv_tbl = st_copy(RCLASS(klass)->iv_tbl);
}
- clone->m_tbl = st_init_numtable();
- st_foreach(RCLASS(klass)->m_tbl, clone_method,
- (st_data_t)clone->m_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);
+ }
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
FL_SET(clone, FL_SINGLETON);
return (VALUE)clone;
@@ -138,7 +163,8 @@ rb_singleton_class_clone(VALUE obj)
}
void
-rb_singleton_class_attached(VALUE klass, VALUE obj)
+rb_singleton_class_attached(klass, obj)
+ VALUE klass, obj;
{
if (FL_TEST(klass, FL_SINGLETON)) {
if (!RCLASS(klass)->iv_tbl) {
@@ -149,30 +175,33 @@ rb_singleton_class_attached(VALUE klass, VALUE obj)
}
VALUE
-rb_make_metaclass(VALUE obj, VALUE super)
+rb_make_metaclass(obj, super)
+ VALUE obj, super;
{
+ VALUE klass = rb_class_boot(super);
+ FL_SET(klass, FL_SINGLETON);
+ RBASIC(obj)->klass = klass;
+ rb_singleton_class_attached(klass, obj);
if (BUILTIN_TYPE(obj) == T_CLASS && FL_TEST(obj, FL_SINGLETON)) {
- return RBASIC(obj)->klass = rb_cClass;
+ RBASIC(klass)->klass = klass;
+ RCLASS(klass)->super = RBASIC(rb_class_real(RCLASS(obj)->super))->klass;
}
else {
- VALUE metasuper;
- VALUE klass = rb_class_boot(super);
+ VALUE metasuper = RBASIC(rb_class_real(super))->klass;
- FL_SET(klass, FL_SINGLETON);
- RBASIC(obj)->klass = klass;
- rb_singleton_class_attached(klass, obj);
-
- metasuper = RBASIC(rb_class_real(super))->klass;
/* metaclass of a superclass may be NULL at boot time */
if (metasuper) {
RBASIC(klass)->klass = metasuper;
}
- return klass;
}
+
+ return klass;
}
VALUE
-rb_define_class_id(ID id, VALUE super)
+rb_define_class_id(id, super)
+ ID id;
+ VALUE super;
{
VALUE klass;
@@ -183,15 +212,31 @@ rb_define_class_id(ID id, VALUE super)
return klass;
}
+void
+rb_check_inheritable(super)
+ VALUE super;
+{
+ if (TYPE(super) != T_CLASS) {
+ rb_raise(rb_eTypeError, "superclass must be a Class (%s given)",
+ rb_obj_classname(super));
+ }
+ if (RBASIC(super)->flags & FL_SINGLETON) {
+ rb_raise(rb_eTypeError, "can't make subclass of virtual class");
+ }
+}
+
VALUE
-rb_class_inherited(VALUE super, VALUE klass)
+rb_class_inherited(super, klass)
+ VALUE super, klass;
{
if (!super) super = rb_cObject;
return rb_funcall(super, rb_intern("inherited"), 1, klass);
}
VALUE
-rb_define_class(const char *name, VALUE super)
+rb_define_class(name, super)
+ const char *name;
+ VALUE super;
{
VALUE klass;
ID id;
@@ -220,7 +265,10 @@ rb_define_class(const char *name, VALUE super)
}
VALUE
-rb_define_class_under(VALUE outer, const char *name, VALUE super)
+rb_define_class_under(outer, name, super)
+ VALUE outer;
+ const char *name;
+ VALUE super;
{
VALUE klass;
ID id;
@@ -249,7 +297,7 @@ rb_define_class_under(VALUE outer, const char *name, VALUE super)
}
VALUE
-rb_module_new(void)
+rb_module_new()
{
NEWOBJ(mdl, struct RClass);
OBJSETUP(mdl, rb_cModule, T_MODULE);
@@ -263,7 +311,8 @@ rb_module_new(void)
}
VALUE
-rb_define_module_id(ID id)
+rb_define_module_id(id)
+ ID id;
{
VALUE mdl;
@@ -274,7 +323,8 @@ rb_define_module_id(ID id)
}
VALUE
-rb_define_module(const char *name)
+rb_define_module(name)
+ const char *name;
{
VALUE module;
ID id;
@@ -294,7 +344,9 @@ rb_define_module(const char *name)
}
VALUE
-rb_define_module_under(VALUE outer, const char *name)
+rb_define_module_under(outer, name)
+ VALUE outer;
+ const char *name;
{
VALUE module;
ID id;
@@ -315,7 +367,8 @@ rb_define_module_under(VALUE outer, const char *name)
}
static VALUE
-include_class_new(VALUE module, VALUE super)
+include_class_new(module, super)
+ VALUE module, super;
{
NEWOBJ(klass, struct RClass);
OBJSETUP(klass, rb_cClass, T_ICLASS);
@@ -342,7 +395,8 @@ include_class_new(VALUE module, VALUE super)
}
void
-rb_include_module(VALUE klass, VALUE module)
+rb_include_module(klass, module)
+ VALUE klass, module;
{
VALUE p, c;
int changed = 0;
@@ -405,7 +459,8 @@ rb_include_module(VALUE klass, VALUE module)
*/
VALUE
-rb_mod_included_modules(VALUE mod)
+rb_mod_included_modules(mod)
+ VALUE mod;
{
VALUE ary = rb_ary_new();
VALUE p;
@@ -438,7 +493,9 @@ rb_mod_included_modules(VALUE mod)
*/
VALUE
-rb_mod_include_p(VALUE mod, VALUE mod2)
+rb_mod_include_p(mod, mod2)
+ VALUE mod;
+ VALUE mod2;
{
VALUE p;
@@ -468,7 +525,8 @@ rb_mod_include_p(VALUE mod, VALUE mod2)
*/
VALUE
-rb_mod_ancestors(VALUE mod)
+rb_mod_ancestors(mod)
+ VALUE mod;
{
VALUE p, ary = rb_ary_new();
@@ -489,14 +547,17 @@ rb_mod_ancestors(VALUE mod)
#define VISI_CHECK(x,f) (VISI(x) == (f))
static int
-ins_methods_push(ID name, long type, VALUE ary, long visi)
+ins_methods_push(name, type, ary, visi)
+ ID name;
+ long type;
+ VALUE ary;
+ long visi;
{
if (type == -1) return ST_CONTINUE;
switch (visi) {
case NOEX_PRIVATE:
case NOEX_PROTECTED:
case NOEX_PUBLIC:
- case NOEX_LOCAL:
visi = (type == visi);
break;
default:
@@ -504,43 +565,52 @@ ins_methods_push(ID name, long type, VALUE ary, long visi)
break;
}
if (visi) {
- rb_ary_push(ary, ID2SYM(name));
+ rb_ary_push(ary, rb_str_new2(rb_id2name(name)));
}
return ST_CONTINUE;
}
static int
-ins_methods_i(ID name, long type, VALUE ary)
+ins_methods_i(name, type, ary)
+ ID name;
+ long type;
+ VALUE ary;
{
return ins_methods_push(name, type, ary, -1); /* everything but private */
}
static int
-ins_methods_prot_i(ID name, long type, VALUE ary)
+ins_methods_prot_i(name, type, ary)
+ ID name;
+ long type;
+ VALUE ary;
{
return ins_methods_push(name, type, ary, NOEX_PROTECTED);
}
static int
-ins_methods_priv_i(ID name, long type, VALUE ary)
+ins_methods_priv_i(name, type, ary)
+ ID name;
+ long type;
+ VALUE ary;
{
return ins_methods_push(name, type, ary, NOEX_PRIVATE);
}
static int
-ins_methods_pub_i(ID name, long type, VALUE ary)
+ins_methods_pub_i(name, type, ary)
+ ID name;
+ long type;
+ VALUE ary;
{
return ins_methods_push(name, type, ary, NOEX_PUBLIC);
}
static int
-ins_methods_local_i(ID name, long type, VALUE ary)
-{
- return ins_methods_push(name, type, ary, NOEX_LOCAL);
-}
-
-static int
-method_entry(ID key, NODE *body, st_table *list)
+method_entry(key, body, list)
+ ID key;
+ NODE *body;
+ st_table *list;
{
long type;
@@ -554,7 +624,11 @@ method_entry(ID key, NODE *body, st_table *list)
}
static VALUE
-class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (ID, long, VALUE))
+class_instance_method_list(argc, argv, mod, func)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
+ int (*func) _((ID, long, VALUE));
{
VALUE ary;
int recur;
@@ -611,7 +685,10 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (ID, lo
*/
VALUE
-rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
+rb_class_instance_methods(argc, argv, mod)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
{
return class_instance_method_list(argc, argv, mod, ins_methods_i);
}
@@ -626,7 +703,10 @@ rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
*/
VALUE
-rb_class_protected_instance_methods(int argc, VALUE *argv, VALUE mod)
+rb_class_protected_instance_methods(argc, argv, mod)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
{
return class_instance_method_list(argc, argv, mod, ins_methods_prot_i);
}
@@ -649,7 +729,10 @@ rb_class_protected_instance_methods(int argc, VALUE *argv, VALUE mod)
*/
VALUE
-rb_class_private_instance_methods(int argc, VALUE *argv, VALUE mod)
+rb_class_private_instance_methods(argc, argv, mod)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
{
return class_instance_method_list(argc, argv, mod, ins_methods_priv_i);
}
@@ -664,26 +747,16 @@ rb_class_private_instance_methods(int argc, VALUE *argv, VALUE mod)
*/
VALUE
-rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod)
+rb_class_public_instance_methods(argc, argv, mod)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
{
return class_instance_method_list(argc, argv, mod, ins_methods_pub_i);
}
/*
* call-seq:
- * mod.local_methods => array
- *
- * Returns a list of the local methods defined in <i>mod</i>.
- */
-
-VALUE
-rb_class_local_methods(VALUE mod)
-{
- return class_instance_method_list(0, 0, mod, ins_methods_local_i);
-}
-
-/*
- * call-seq:
* obj.singleton_methods(all=true) => array
*
* Returns an array of the names of singleton methods for <i>obj</i>.
@@ -715,7 +788,10 @@ rb_class_local_methods(VALUE mod)
*/
VALUE
-rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
+rb_obj_singleton_methods(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE recur, ary, klass;
st_table *list;
@@ -744,31 +820,53 @@ rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
}
void
-rb_define_method_id(VALUE klass, ID name, VALUE (*func)(ANYARGS), int argc)
+rb_define_method_id(klass, name, func, argc)
+ VALUE klass;
+ ID name;
+ VALUE (*func)();
+ int argc;
{
rb_add_method(klass, name, NEW_CFUNC(func,argc), NOEX_PUBLIC);
}
void
-rb_define_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
+rb_define_method(klass, name, func, argc)
+ VALUE klass;
+ const char *name;
+ VALUE (*func)();
+ int argc;
{
- rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PUBLIC);
+ ID id = rb_intern(name);
+ int ex = NOEX_PUBLIC;
+
+
+ rb_add_method(klass, id, NEW_CFUNC(func, argc), ex);
}
void
-rb_define_protected_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
+rb_define_protected_method(klass, name, func, argc)
+ VALUE klass;
+ const char *name;
+ VALUE (*func)();
+ int argc;
{
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PROTECTED);
}
void
-rb_define_private_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
+rb_define_private_method(klass, name, func, argc)
+ VALUE klass;
+ const char *name;
+ VALUE (*func)();
+ int argc;
{
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PRIVATE);
}
void
-rb_undef_method(VALUE klass, const char *name)
+rb_undef_method(klass, name)
+ VALUE klass;
+ const char *name;
{
rb_add_method(klass, rb_intern(name), 0, NOEX_UNDEF);
}
@@ -780,7 +878,8 @@ rb_undef_method(VALUE klass, const char *name)
} while (0)
VALUE
-rb_singleton_class(VALUE obj)
+rb_singleton_class(obj)
+ VALUE obj;
{
VALUE klass;
@@ -815,47 +914,77 @@ rb_singleton_class(VALUE obj)
}
void
-rb_define_singleton_method(VALUE obj, const char *name, VALUE (*func)(ANYARGS), int argc)
+rb_define_singleton_method(obj, name, func, argc)
+ VALUE obj;
+ const char *name;
+ VALUE (*func)();
+ int argc;
{
rb_define_method(rb_singleton_class(obj), name, func, argc);
}
void
-rb_define_module_function(VALUE module, const char *name, VALUE (*func)(ANYARGS), int argc)
+rb_define_module_function(module, name, func, argc)
+ VALUE module;
+ const char *name;
+ VALUE (*func)();
+ int argc;
{
rb_define_private_method(module, name, func, argc);
rb_define_singleton_method(module, name, func, argc);
}
void
-rb_define_global_function(const char *name, VALUE (*func)(ANYARGS), int argc)
+rb_define_global_function(name, func, argc)
+ const char *name;
+ VALUE (*func)();
+ int argc;
{
rb_define_module_function(rb_mKernel, name, func, argc);
}
void
-rb_define_alias(VALUE klass, const char *name1, const char *name2)
+rb_define_alias(klass, name1, name2)
+ VALUE klass;
+ const char *name1, *name2;
{
rb_alias(klass, rb_intern(name1), rb_intern(name2));
}
void
-rb_define_attr(VALUE klass, const char *name, int read, int write)
+rb_define_attr(klass, name, read, write)
+ VALUE klass;
+ const char *name;
+ int read, write;
{
rb_attr(klass, rb_intern(name), read, write, Qfalse);
}
+#ifdef HAVE_STDARG_PROTOTYPES
#include <stdarg.h>
+#define va_init_list(a,b) va_start(a,b)
+#else
+#include <varargs.h>
+#define va_init_list(a,b) va_start(a)
+#endif
int
+#ifdef HAVE_STDARG_PROTOTYPES
rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
+#else
+rb_scan_args(argc, argv, fmt, va_alist)
+ int argc;
+ const VALUE *argv;
+ const char *fmt;
+ va_dcl
+#endif
{
int n, i = 0;
const char *p = fmt;
VALUE *var;
va_list vargs;
- va_start(vargs, fmt);
+ va_init_list(vargs, fmt);
if (*p == '*') goto rest_arg;
diff --git a/common.mk b/common.mk
index 1fabb641c5..6d5b35dee6 100644
--- a/common.mk
+++ b/common.mk
@@ -3,7 +3,6 @@ lib: $(LIBRUBY)
dll: $(LIBRUBY_SO)
RUBYOPT =
-NULLCMD =
STATIC_RUBY = static-ruby
@@ -18,16 +17,13 @@ EXTOBJS =
DLDOBJS = $(DMYEXT)
OBJS = array.$(OBJEXT) \
- ascii.$(OBJEXT) \
bignum.$(OBJEXT) \
class.$(OBJEXT) \
compar.$(OBJEXT) \
dir.$(OBJEXT) \
dln.$(OBJEXT) \
enum.$(OBJEXT) \
- enumerator.$(OBJEXT) \
error.$(OBJEXT) \
- euc_jp.$(OBJEXT) \
eval.$(OBJEXT) \
file.$(OBJEXT) \
gc.$(OBJEXT) \
@@ -45,20 +41,14 @@ OBJS = array.$(OBJEXT) \
random.$(OBJEXT) \
range.$(OBJEXT) \
re.$(OBJEXT) \
- regcomp.$(OBJEXT) \
- regenc.$(OBJEXT) \
- regerror.$(OBJEXT) \
- regexec.$(OBJEXT) \
- regparse.$(OBJEXT) \
+ regex.$(OBJEXT) \
ruby.$(OBJEXT) \
signal.$(OBJEXT) \
- sjis.$(OBJEXT) \
sprintf.$(OBJEXT) \
st.$(OBJEXT) \
string.$(OBJEXT) \
struct.$(OBJEXT) \
time.$(OBJEXT) \
- utf8.$(OBJEXT) \
util.$(OBJEXT) \
variable.$(OBJEXT) \
version.$(OBJEXT) \
@@ -307,7 +297,7 @@ $(RBCONFIG): $(srcdir)/mkconfig.rb config.status $(PREP)
.PRECIOUS: $(MKFILES)
-.PHONY: test install install-nodoc install-doc
+.PHONY: test install install-nodoc install-doc dist
PHONY:
@@ -323,6 +313,7 @@ flock.$(OBJEXT): {$(VPATH)}flock.c
memcmp.$(OBJEXT): {$(VPATH)}memcmp.c
memmove.$(OBJEXT): {$(VPATH)}memmove.c
mkdir.$(OBJEXT): {$(VPATH)}mkdir.c
+vsnprintf.$(OBJEXT): {$(VPATH)}vsnprintf.c
strcasecmp.$(OBJEXT): {$(VPATH)}strcasecmp.c
strncasecmp.$(OBJEXT): {$(VPATH)}strncasecmp.c
strchr.$(OBJEXT): {$(VPATH)}strchr.c
@@ -349,10 +340,9 @@ win32.$(OBJEXT): {$(VPATH)}win32.c
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
-ascii.$(OBJEXT): {$(VPATH)}ascii.c {$(VPATH)}regenc.h \
- {$(VPATH)}oniguruma.h config.h
bignum.$(OBJEXT): {$(VPATH)}bignum.c {$(VPATH)}ruby.h config.h \
- {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
+ {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
+ {$(VPATH)}rubysig.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
@@ -371,13 +361,9 @@ dmyext.$(OBJEXT): {$(VPATH)}dmyext.c
enum.$(OBJEXT): {$(VPATH)}enum.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}node.h {$(VPATH)}util.h
-enumerator.$(OBJEXT): {$(VPATH)}enumerator.c {$(VPATH)}ruby.h config.h \
- {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
error.$(OBJEXT): {$(VPATH)}error.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}env.h {$(VPATH)}st.h
-euc_jp.$(OBJEXT): {$(VPATH)}euc_jp.c {$(VPATH)}regenc.h \
- {$(VPATH)}oniguruma.h
eval.$(OBJEXT): {$(VPATH)}eval.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}node.h {$(VPATH)}env.h {$(VPATH)}util.h \
@@ -389,8 +375,7 @@ file.$(OBJEXT): {$(VPATH)}file.c {$(VPATH)}ruby.h config.h \
gc.$(OBJEXT): {$(VPATH)}gc.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}rubysig.h {$(VPATH)}st.h {$(VPATH)}node.h \
- {$(VPATH)}env.h {$(VPATH)}re.h {$(VPATH)}regex.h {$(VPATH)}regint.h \
- {$(VPATH)}oniguruma.h
+ {$(VPATH)}env.h {$(VPATH)}re.h {$(VPATH)}regex.h
hash.$(OBJEXT): {$(VPATH)}hash.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}st.h {$(VPATH)}util.h {$(VPATH)}rubysig.h
@@ -398,7 +383,8 @@ inits.$(OBJEXT): {$(VPATH)}inits.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
io.$(OBJEXT): {$(VPATH)}io.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
- {$(VPATH)}rubyio.h {$(VPATH)}rubysig.h {$(VPATH)}util.h
+ {$(VPATH)}rubyio.h {$(VPATH)}rubysig.h {$(VPATH)}util.h \
+ {$(VPATH)}env.h
main.$(OBJEXT): {$(VPATH)}main.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
marshal.$(OBJEXT): {$(VPATH)}marshal.c {$(VPATH)}ruby.h config.h \
@@ -429,37 +415,24 @@ range.$(OBJEXT): {$(VPATH)}range.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
re.$(OBJEXT): {$(VPATH)}re.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
- {$(VPATH)}re.h {$(VPATH)}regex.h {$(VPATH)}regint.h {$(VPATH)}oniguruma.h
-regcomp.$(OBJEXT): {$(VPATH)}regcomp.c {$(VPATH)}oniguruma.h \
- {$(VPATH)}regint.h {$(VPATH)}regparse.h {$(VPATH)}regenc.h config.h
-regenc.$(OBJEXT): {$(VPATH)}regenc.c {$(VPATH)}regint.h \
- {$(VPATH)}regenc.h {$(VPATH)}oniguruma.h config.h
-regerror.$(OBJEXT): {$(VPATH)}regerror.c {$(VPATH)}regint.h \
- {$(VPATH)}regenc.h {$(VPATH)}oniguruma.h config.h
-regexec.$(OBJEXT): {$(VPATH)}regexec.c {$(VPATH)}regint.h \
- {$(VPATH)}regenc.h {$(VPATH)}oniguruma.h config.h
-regparse.$(OBJEXT): {$(VPATH)}regparse.c {$(VPATH)}oniguruma.h \
- {$(VPATH)}regint.h {$(VPATH)}regparse.h {$(VPATH)}regenc.h config.h
+ {$(VPATH)}re.h {$(VPATH)}regex.h
+regex.$(OBJEXT): {$(VPATH)}regex.c config.h {$(VPATH)}regex.h
ruby.$(OBJEXT): {$(VPATH)}ruby.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}dln.h {$(VPATH)}node.h {$(VPATH)}util.h
signal.$(OBJEXT): {$(VPATH)}signal.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}rubysig.h
-sjis.$(OBJEXT): {$(VPATH)}sjis.c {$(VPATH)}regenc.h \
- {$(VPATH)}oniguruma.h config.h
sprintf.$(OBJEXT): {$(VPATH)}sprintf.c {$(VPATH)}ruby.h config.h \
- {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h {$(VPATH)}vsnprintf.c
+ {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
st.$(OBJEXT): {$(VPATH)}st.c config.h {$(VPATH)}st.h
string.$(OBJEXT): {$(VPATH)}string.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
- {$(VPATH)}re.h {$(VPATH)}regex.h {$(VPATH)}regint.h {$(VPATH)}oniguruma.h
+ {$(VPATH)}re.h {$(VPATH)}regex.h
struct.$(OBJEXT): {$(VPATH)}struct.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
time.$(OBJEXT): {$(VPATH)}time.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h
-utf8.$(OBJEXT): {$(VPATH)}utf8.c {$(VPATH)}regenc.h \
- {$(VPATH)}oniguruma.h config.h
util.$(OBJEXT): {$(VPATH)}util.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}util.h
@@ -469,3 +442,6 @@ variable.$(OBJEXT): {$(VPATH)}variable.c {$(VPATH)}ruby.h config.h \
version.$(OBJEXT): {$(VPATH)}version.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}version.h
+
+dist: $(PROGRAM)
+ $(RUNRUBY) $(srcdir)/distruby.rb
diff --git a/compar.c b/compar.c
index 80c4c70ca6..1488b2c65d 100644
--- a/compar.c
+++ b/compar.c
@@ -17,7 +17,8 @@ VALUE rb_mComparable;
static ID cmp;
int
-rb_cmpint(VALUE val, VALUE a, VALUE b)
+rb_cmpint(val, a, b)
+ VALUE val, a, b;
{
if (NIL_P(val)) {
rb_cmperr(a, b);
@@ -33,7 +34,8 @@ rb_cmpint(VALUE val, VALUE a, VALUE b)
}
void
-rb_cmperr(VALUE x, VALUE y)
+rb_cmperr(x, y)
+ VALUE x, y;
{
const char *classname;
@@ -48,20 +50,23 @@ rb_cmperr(VALUE x, VALUE y)
rb_obj_classname(x), classname);
}
+#define cmperr() (rb_cmperr(x, y), Qnil)
+
static VALUE
-cmp_eq(VALUE *a)
+cmp_eq(a)
+ VALUE *a;
{
VALUE c = rb_funcall(a[0], cmp, 1, a[1]);
- if (NIL_P(c)) return Qfalse;
+ if (NIL_P(c)) return Qnil;
if (rb_cmpint(c, a[0], a[1]) == 0) return Qtrue;
return Qfalse;
}
static VALUE
-cmp_failed(void)
+cmp_failed()
{
- return Qfalse;
+ return Qnil;
}
/*
@@ -74,7 +79,8 @@ cmp_failed(void)
*/
static VALUE
-cmp_equal(VALUE x, VALUE y)
+cmp_equal(x, y)
+ VALUE x, y;
{
VALUE a[2];
@@ -93,10 +99,12 @@ cmp_equal(VALUE x, VALUE y)
*/
static VALUE
-cmp_gt(VALUE x, VALUE y)
+cmp_gt(x, y)
+ VALUE x, y;
{
VALUE c = rb_funcall(x, cmp, 1, y);
+ if (NIL_P(c)) return cmperr();
if (rb_cmpint(c, x, y) > 0) return Qtrue;
return Qfalse;
}
@@ -110,10 +118,12 @@ cmp_gt(VALUE x, VALUE y)
*/
static VALUE
-cmp_ge(VALUE x, VALUE y)
+cmp_ge(x, y)
+ VALUE x, y;
{
VALUE c = rb_funcall(x, cmp, 1, y);
+ if (NIL_P(c)) return cmperr();
if (rb_cmpint(c, x, y) >= 0) return Qtrue;
return Qfalse;
}
@@ -127,14 +137,17 @@ cmp_ge(VALUE x, VALUE y)
*/
static VALUE
-cmp_lt(VALUE x, VALUE y)
+cmp_lt(x, y)
+ VALUE x, y;
{
VALUE c = rb_funcall(x, cmp, 1, y);
+ if (NIL_P(c)) return cmperr();
if (rb_cmpint(c, x, y) < 0) return Qtrue;
return Qfalse;
}
+
/*
* call-seq:
* obj <= other => true or false
@@ -144,10 +157,12 @@ cmp_lt(VALUE x, VALUE y)
*/
static VALUE
-cmp_le(VALUE x, VALUE y)
+cmp_le(x, y)
+ VALUE x, y;
{
VALUE c = rb_funcall(x, cmp, 1, y);
+ if (NIL_P(c)) return cmperr();
if (rb_cmpint(c, x, y) <= 0) return Qtrue;
return Qfalse;
}
@@ -168,7 +183,8 @@ cmp_le(VALUE x, VALUE y)
*/
static VALUE
-cmp_between(VALUE x, VALUE min, VALUE max)
+cmp_between(x, min, max)
+ VALUE x, min, max;
{
if (RTEST(cmp_lt(x, min))) return Qfalse;
if (RTEST(cmp_gt(x, max))) return Qfalse;
@@ -213,7 +229,7 @@ cmp_between(VALUE x, VALUE min, VALUE max)
*/
void
-Init_Comparable(void)
+Init_Comparable()
{
rb_mComparable = rb_define_module("Comparable");
rb_define_method(rb_mComparable, "==", cmp_equal, 1);
diff --git a/config.sub b/config.sub
index 463186dbfd..506d3ab77f 100644
--- a/config.sub
+++ b/config.sub
@@ -3,7 +3,7 @@
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
-timestamp='2004-01-05'
+timestamp='2004-06-11'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
@@ -1130,7 +1130,7 @@ case $os in
os=-sysv4.2uw
;;
-gnu/linux*)
- os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+ os=`echo $os | sed -e 's|gnu/linux|linux|'`
;;
# First accept the basic system types.
# The portable systems comes first.
@@ -1183,7 +1183,7 @@ case $os in
os=-linux-dietlibc
;;
-linux*)
- os=`echo $os | sed -e 's|linux|linux-gnu|'`
+ os=-linux
;;
-sunos5*)
os=`echo $os | sed -e 's|sunos5|solaris2|'`
diff --git a/configure.in b/configure.in
index e7e611eee5..136fe7c661 100644
--- a/configure.in
+++ b/configure.in
@@ -148,8 +148,12 @@ if test x"${build}" != x"${host}"; then
AC_CHECK_TOOL(CC, gcc)
fi
AC_PROG_CC
-AC_PROG_CXX
AC_PROG_GCC_TRADITIONAL
+if test "$GCC" = yes; then
+ linker_flag=-Wl,
+else
+ linker_flag=
+fi
RUBY_PROG_GNU_LD
RUBY_CPPOUTFILE
@@ -159,6 +163,11 @@ AC_SUBST(OUTFLAG)
RUBY_MINGW32
+AC_PROG_YACC
+if test "$YACC" = "yacc"; then
+ AC_DEFINE([OLD_YACC])
+fi
+
AC_CHECK_TOOL(RANLIB, ranlib, :)
AC_CHECK_TOOL(AR, ar)
if test -z "$AR"; then
@@ -187,6 +196,15 @@ cygwin*|mingw*)
sed -n '/^[[ ]]*dll name: \(msvc.*\)\.dll$/{s//\1/p;q;}'`],
[rb_cv_msvcrt=msvcrt])
test "$rb_cv_msvcrt" = "" && rb_cv_msvcrt=msvcrt])
+ AC_ARG_WITH(winsock2,
+ [ --with-winsock2 link winsock2 (MinGW only)], [
+ case $withval in
+ yes) with_winsock2=yes;;
+ *) with_winsock2=no;;
+ esac], [with_winsock2=no])
+ if test "$with_winsock2" = yes; then
+ AC_DEFINE(USE_WINSOCK2)
+ fi
esac
: ${enable_shared=yes}
;;
@@ -216,14 +234,12 @@ else
fi
dnl check for large file stuff
+mv confdefs.h confdefs1.h
+: > confdefs.h
AC_SYS_LARGEFILE
-
-case "$target_os" in
-mingw*)
- ac_cv_type_off_t=yes
- ac_cv_sizeof_off_t=8
- ;;
-esac
+mv confdefs.h largefile.h
+mv confdefs1.h confdefs.h
+cat largefile.h >> confdefs.h
AC_CHECK_TYPES([long long, off_t])
@@ -315,10 +331,7 @@ AS_VAR_POPDEF([rbcv])
])
RUBY_FUNC_ATTRIBUTE(noreturn, NORETURN)
-RUBY_FUNC_ATTRIBUTE(deprecated, DEPRECATED)
RUBY_FUNC_ATTRIBUTE(noinline, NOINLINE)
-RUBY_FUNC_ATTRIBUTE(stdcall)
-RUBY_FUNC_ATTRIBUTE(cdecl)
AC_CACHE_CHECK([for RUBY_EXTERN], rb_cv_ruby_extern,
[rb_cv_ruby_extern=no
@@ -347,6 +360,11 @@ AC_ARG_ENABLE(pthread,
[ --enable-pthread use pthread library.],
[enable_pthread=$enableval], [enable_pthread=no])
+AC_ARG_ENABLE(fastthread,
+ [ --disable-fastthread do not use the fastthread mutex], [
+ : handled by ext/thread/extconf.rb
+ ])
+
dnl Checks for libraries.
case "$target_os" in
nextstep*) ;;
@@ -359,12 +377,13 @@ human*) ac_cv_func_getpgrp_void=yes
ac_cv_func_setitimer=no
;;
beos*) ac_cv_func_link=no;;
-cygwin*) rb_cv_have_daylight=no
- ac_cv_var_tzname=no
- ac_cv_func__setjmp=no
- ac_cv_func_setitimer=no
- ;;
-mingw*) LIBS="-lshell32 -lws2_32 $LIBS"
+cygwin*) ;;
+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
@@ -377,7 +396,6 @@ mingw*) LIBS="-lshell32 -lws2_32 $LIBS"
ac_cv_func_times=yes
ac_cv_func_waitpid=yes
ac_cv_func_fsync=yes
- ac_cv_func_snprintf=yes
ac_cv_func_vsnprintf=yes
ac_cv_func_seekdir=yes
ac_cv_func_telldir=yes
@@ -385,9 +403,6 @@ mingw*) LIBS="-lshell32 -lws2_32 $LIBS"
ac_cv_func_isnan=yes
ac_cv_func_finite=yes
ac_cv_func_link=yes
- ac_cv_func_truncate=yes
- ac_cv_func_fseeko=yes
- ac_cv_func_ftello=yes
ac_cv_lib_crypt_crypt=no
ac_cv_func_getpgrp_void=no
ac_cv_func_setpgrp_void=yes
@@ -396,14 +411,15 @@ mingw*) LIBS="-lshell32 -lws2_32 $LIBS"
rb_cv_binary_elf=no
rb_cv_negative_time_t=no
enable_pthread=no
+ ac_cv_func_fcntl=yes
;;
os2-emx*) LIBS="-lm $LIBS"
ac_cv_lib_dir_opendir=no;;
msdosdjgpp*) LIBS="-lm $LIBS"
ac_cv_func_getpgrp_void=yes
ac_cv_func_setitimer=no
- ac_cv_sizeof_rlim_t=4
- ac_cv_func_fork=no
+ ac_cv_sizeof_rlim_t=4
+ ac_cv_func_setrlimit=no
;;
bsdi*) LIBS="-lm $LIBS"
ac_cv_sizeof_rlim_t=8;;
@@ -446,17 +462,17 @@ bow) ac_cv_func_setitimer=no
;;
superux*) ac_cv_func_setitimer=no
;;
-solaris*2.10) if test -z "$GCC"; then
- ac_cv_func_isinf=yes
+solaris*2.1*) 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(socket, socketpair) # SunOS/Solaris
+AC_CHECK_LIB(rt, clock_gettime) # GNU/Linux
case "$target_cpu" in
alpha*) case "$target_os"::"$GCC" in
@@ -498,20 +514,6 @@ AC_STRUCT_ST_BLKSIZE
AC_STRUCT_ST_BLOCKS
AC_STRUCT_ST_RDEV
-AC_CHECK_TYPE(fd_mask, [AC_DEFINE(HAVE_RB_FD_INIT, 1)])
-
-AC_CACHE_CHECK(for stack end address, rb_cv_stack_end_address,
-[rb_cv_stack_end_address=no
-for addr in __libc_stack_end _SEND; do
- AC_TRY_LINK(
- [extern void *$addr;],
- [if (!$addr) return 1;],
- [rb_cv_stack_end_address="$addr"; break])
-done])
-if test $rb_cv_stack_end_address != no; then
- AC_DEFINE_UNQUOTED(STACK_END_ADDRESS, $rb_cv_stack_end_address)
-fi
-
dnl Checks for library functions.
AC_TYPE_GETGROUPS
AC_TYPE_SIGNAL
@@ -527,18 +529,42 @@ powerpc-darwin*)
;;
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_broken_glibc_ia64_erfc,
+ [AC_TRY_RUN([
+#include <math.h>
+int
+main()
+{
+ erfc(10000.0);
+ return 0;
+}
+],
+ rb_broken_glibc_ia64_erfc=no,
+ rb_broken_glibc_ia64_erfc=yes,
+ rb_broken_glibc_ia64_erfc=no)])
+case $rb_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\
+ strchr strstr strtoul crypt flock vsnprintf\
isnan finite isinf hypot acosh erf)
-AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall chroot fsync getcwd eaccess\
- truncate chsize times utimes fcntl lockf lstat link symlink readlink\
- setitimer setruid seteuid setreuid setresuid setproctitle socketpair\
- setrgid setegid setregid setresgid issetugid pause lchown lchmod\
- getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
- getpriority getrlimit setrlimit sysconf\
- dlopen sigprocmask sigaction _setjmp vsnprintf snprintf\
- setsid telldir seekdir fchmod mktime timegm cosh sinh tanh log2\
- setuid setgid daemon select_large_fdset setenv unsetenv)
+AC_CHECK_FUNCS(fmod killpg wait4 waitpid syscall chroot fsync getcwd eaccess\
+ truncate ftruncate 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)
AC_ARG_ENABLE(setreuid,
[ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.],
[use_setreuid=$enableval])
@@ -564,6 +590,42 @@ 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>
@@ -605,6 +667,7 @@ 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>
@@ -627,7 +690,7 @@ main()
],
rb_cv_bsd_signal=yes,
rb_cv_bsd_signal=no,
- rb_cv_bsd_signal=no)])
+ rb_cv_bsd_signal=$ac_cv_func_sigsetmask)])
if test "$rb_cv_bsd_signal" = yes; then
AC_DEFINE(BSD_SIGNAL)
fi
@@ -741,6 +804,69 @@ else
fi
fi
+AC_DEFUN([RUBY_CHECK_IO_NEED],
+[AC_CACHE_CHECK(whether need to [$1], [$2],
+ [AC_TRY_RUN([
+#include <stdio.h>
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif
+#ifndef SEEK_CUR
+#define SEEK_CUR 1
+#endif
+#define before_seek(f) ]ifelse(index($2,flush_before_seek),-1,[fflush(f)],[(f,0)])[
+#define reset_rw(f) ]ifelse(index($2,seek_between_rw),-1,[do_seek(f,SEEK_CUR)],[(f,0)])[
+#define do_seek(f, w) (before_seek(f), fseek(f,0,w))
+
+char *fn = "conftest.dat";
+char *wombat = "wombat\n";
+char *koara = "koara\n";
+char *kangaroo = "kangaroo\n";
+
+int main()
+{
+ char buf[BUFSIZ];
+ FILE *f;
+ int r = 1;
+
+ if (!(f = fopen(fn, "w+"))) return 1;
+ fputs(wombat, f);
+ do_seek(f, SEEK_SET);
+ if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
+ reset_rw(f);
+ fputs(koara, f);
+ fputs(kangaroo, f);
+ do_seek(f, SEEK_SET);
+ if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
+ if (!fgets(buf, BUFSIZ, f) || strcmp(buf, koara)) goto fail;
+ if (!fgets(buf, BUFSIZ, f) || strcmp(buf, kangaroo)) goto fail;
+ do_seek(f, SEEK_SET);
+ if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
+ reset_rw(f);
+ fputc('X', f);
+ reset_rw(f);
+ if (!fgets(buf, BUFSIZ, f) || strcmp(buf, koara+1)) goto fail;
+ if (!fgets(buf, BUFSIZ, f) || strcmp(buf, kangaroo)) goto fail;
+ do_seek(f, SEEK_SET);
+ if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
+ if (!fgets(buf, BUFSIZ, f) || buf[0] != 'X' || strcmp(buf+1, koara+1)) goto fail;
+ if (!fgets(buf, BUFSIZ, f) || strcmp(buf, kangaroo)) goto fail;
+ r = 0;
+ fail:
+ fclose(f);
+ unlink(fn);
+ return r;
+}
+], [$2]=no, [$2]=yes, [$2]=[$3])])])
+RUBY_CHECK_IO_NEED(seek between R/W, rb_cv_need_io_seek_between_rw, yes)
+if test "$rb_cv_need_io_seek_between_rw" = yes; then
+ AC_DEFINE(NEED_IO_SEEK_BETWEEN_RW, 1)
+fi
+dnl RUBY_CHECK_IO_NEED(flush before seek, rb_cv_need_io_flush_before_seek, no)
+dnl if test "$rb_cv_need_io_flush_before_seek" = yes; then
+dnl AC_DEFINE(NEED_IO_FLUSH_BEFORE_SEEK, 1)
+dnl fi
+
AC_CACHE_CHECK([whether st_ino is huge], rb_cv_huge_st_ino,
[AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([
#include <sys/stat.h>
@@ -895,13 +1021,12 @@ AC_SUBST(ARCH_FLAG)dnl
AC_SUBST(STATIC)dnl
AC_SUBST(CCDLFLAGS)dnl
AC_SUBST(LDSHARED)dnl
-AC_SUBST(LDSHAREDXX)dnl
AC_SUBST(DLEXT)dnl
AC_SUBST(DLEXT2)dnl
AC_SUBST(LIBEXT)dnl
STATIC=
-: ${LIBPATHFLAG=' -L"%s"'}
+: ${LIBPATHFLAG=' -L%s'}
: ${PATHFLAG=''}
if test "$with_dln_a_out" != yes; then
@@ -965,7 +1090,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
@@ -995,15 +1120,12 @@ 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'}
- DLDFLAGS='-G -eInit_$(TARGET)'
- LDFLAGS='-brtl'
- XLDFLAGS='-bE:ruby.imp'
- fi
+ fi
+ DLDFLAGS="${linker_flag}-G"' -eInit_$(TARGET)'
+ LDFLAGS="${LDFLAGS} ${linker_flag}-brtl"
+ XLDFLAGS="${linker_flag}-bE:ruby.imp"
: ${ARCHFILE="ruby.imp"}
TRY_LINK='$(CC) $(LDFLAGS) -oconftest $(INCFLAGS) -I$(hdrdir) $(CPPFLAGS)'
TRY_LINK="$TRY_LINK"' $(CFLAGS) $(src) $(LIBPATH) $(LOCAL_LIBS) $(LIBS)'
@@ -1032,7 +1154,7 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes;;
cygwin*|mingw*) : ${LDSHARED="${CC} -shared -s"}
XLDFLAGS="$XLDFLAGS -Wl,--stack,0x02000000"
- DLDFLAGS="${DLDFLAGS} -Wl,--enable-auto-import,--export-all"
+ DLDFLAGS="${DLDFLAGS} -Wl,--enable-auto-image-base,--enable-auto-import,--export-all"
: ${LIBPATHENV=""}
rb_cv_dlopen=yes ;;
hiuxmpp) : ${LDSHARED='ld -r'} ;;
@@ -1048,30 +1170,10 @@ 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'"
- if test "$GCC" = yes; then
- RPATHFLAG=" -Wl,-R'%1\$-s'"
- else
- RPATHFLAG=" -R'%1\$-s'"
- fi
+ LIBPATHFLAG=" -L%1\$-s"
+ RPATHFLAG=" ${linker_flag}-R%1\$-s"
fi
fi
-if test "${LDSHAREDXX}" = ""; then
- case "${LDSHARED}" in
- *'$(CC)'*)
- LDSHAREDXX=`echo "${LDSHARED}" | sed 's/\$(CC)/$(CXX)/'`
- ;;
- *'${CC}'*)
- LDSHAREDXX=`echo "${LDSHARED}" | sed 's/\${CC}/${CXX}/'`
- ;;
- *$CC*)
- LDSHAREDXX=`echo "${LDSHARED}" | sed "s|$CC|$CXX|"`
- ;;
- ld" "*)
- ;;
- esac
-fi
-
AC_SUBST(LINK_SO)
AC_SUBST(LIBPATHFLAG)
AC_SUBST(RPATHFLAG)
@@ -1104,28 +1206,24 @@ if test "$dln_a_out_works" = yes; then
STATIC=-Bstatic
fi
DLEXT=so
- AC_DEFINE(DLEXT, ".so")
CCDLFLAGS=
else
case "$target_os" in
- hpux*) DLEXT=sl
- AC_DEFINE(DLEXT, ".sl");;
- nextstep*) DLEXT=bundle
- AC_DEFINE(DLEXT, ".bundle");;
- openstep*) DLEXT=bundle
- AC_DEFINE(DLEXT, ".bundle");;
- rhapsody*) DLEXT=bundle
- AC_DEFINE(DLEXT, ".bundle");;
- darwin*) DLEXT=bundle
- AC_DEFINE(DLEXT, ".bundle");;
- os2-emx*) DLEXT=dll
- AC_DEFINE(DLEXT, ".dll");;
- cygwin*|mingw*) DLEXT=so
- AC_DEFINE(DLEXT, ".so");;
- *) DLEXT=so
- AC_DEFINE(DLEXT, ".so");;
+ hpux*) DLEXT=sl;;
+ nextstep*|openstep*|rhapsody*|darwin*)
+ DLEXT=bundle;;
+ os2-emx*) DLEXT=dll;;
+ cygwin*|mingw*)
+ DLEXT=so DLEXT2=dll;;
+ *) DLEXT=so;;
esac
fi
+len=2 # .rb
+n=`expr "$DLEXT" : '.*'`; test "$n" -gt "$len" && len=$n
+n=`expr "$DLEXT2" : '.*'`; test "$n" -gt "$len" && len=$n
+AC_DEFINE_UNQUOTED(DLEXT_MAXLEN, `expr $len + 1`)
+test ".$DLEXT" = "." || AC_DEFINE_UNQUOTED(DLEXT, ".$DLEXT")
+test ".$DLEXT2" = "." || AC_DEFINE_UNQUOTED(DLEXT2, ".$DLEXT2")
AC_SUBST(STRIP)dnl
if test "$with_dln_a_out" = yes; then
@@ -1161,7 +1259,7 @@ case "$target_os" in
human*)
AC_CHECK_LIB(signal, _harderr)
AC_CHECK_LIB(hmem, hmemset)
- AC_CHECK_FUNCS(select gettimeofday)
+ AC_CHECK_FUNCS(select)
AC_CACHE_CHECK(whether PD libc _dtos18 fail to convert big number,
rb_cv_missing__dtos18,
[AC_TRY_RUN(
@@ -1323,12 +1421,7 @@ if test "$enable_shared" = 'yes'; then
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).sl.$(MAJOR).$(MINOR) lib$(RUBY_SO_NAME).sl'
;;
aix*)
- if test "$GCC" = yes; then
- LIBRUBY_DLDFLAGS='-Wl,-G -Wl,-bnoentry'
- else
- LIBRUBY_DLDFLAGS='-G -bnoentry'
- fi
- LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS $XLDFLAGS"
+ LIBRUBY_DLDFLAGS="${linker_flag}-G ${linker_flag}-bnoentry $XLDFLAGS"
LIBRUBYARG_SHARED='-L${libdir} -l${RUBY_SO_NAME}'
SOLIBS='-lm -lc'
;;
@@ -1346,34 +1439,33 @@ if test "$enable_shared" = 'yes'; then
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_SO_NAME).dylib'
;;
interix*)
- LIBRUBYARG_SHARED='-L${libdir} -L. -l$(RUBY_SO_NAME)'
+ LIBRUBYARG_SHARED='-L. -L${libdir} -l$(RUBY_SO_NAME)'
;;
*)
;;
esac
fi
if test "$enable_rpath" = yes; then
- 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
+ LIBRUBYARG_SHARED="${linker_flag}-R ${linker_flag}\$(libdir) -L\$(libdir) $LIBRUBYARG_SHARED"
fi
-XLDFLAGS="$XLDFLAGS -L."
+LDFLAGS="-L. $LDFLAGS"
AC_SUBST(ARCHFILE)
dnl build rdoc index if requested
RDOCTARGET=""
AC_ARG_ENABLE(install-doc,
- [ --disable-install-doc do not install rdoc indexes during install ],
- [install_doc=$enableval], [install_doc=yes])
+ [ --enable-install-doc build and install rdoc indexes during install ],
+ [install_doc=$enableval], [install_doc=no])
if test "$install_doc" != no; then
RDOCTARGET="install-doc"
fi
AC_SUBST(RDOCTARGET)
case "$target_os" in
+ linux*)
+ XCFLAGS="$XCFLAGS -D_GNU_SOURCE=1"
+ ;;
netbsd*)
CFLAGS="$CFLAGS -pipe"
;;
@@ -1393,6 +1485,7 @@ case "$target_os" in
;;
darwin*)
CFLAGS="$CFLAGS -pipe -fno-common"
+ MINIOBJS=dmydln.o
;;
os2-emx)
CFLAGS="$CFLAGS -DOS2 -Zmts"
@@ -1415,7 +1508,7 @@ case "$target_os" in
rm -f /tmp/main.o
CFLAGS="$CFLAGS -std"
fi
- ;;
+ ;;
beos*)
case "$target_cpu" in
powerpc*)
@@ -1424,32 +1517,30 @@ case "$target_os" in
esac
;;
cygwin*|mingw*)
- LIBRUBY_DLDFLAGS="${DLDFLAGS}"' -Wl,--out-implib=$(LIBRUBY)'
case "$target_os" in
cygwin*)
if test x"$enable_shared" = xyes; then
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}
if test x"$enable_shared" = xyes; then
LIBRUBY_SO='$(RUBY_SO_NAME)'.dll
- LIBRUBY_DLDFLAGS="${LIBRUBY_DLDFLAGS}"' $(RUBYDEF)'
+ LIBRUBY='lib$(LIBRUBY_SO).a'
fi
AC_LIBOBJ([win32])
COMMON_LIBS=m
# COMMON_MACROS="WIN32_LEAN_AND_MEAN="
- COMMON_HEADERS="winsock2.h windows.h"
+ COMMON_HEADERS="windows.h winsock.h"
;;
esac
+ LIBRUBY_DLDFLAGS="${DLDFLAGS}"' -Wl,--out-implib=$(LIBRUBY)'
LIBRUBY_ALIASES=''
FIRSTMAKEFILE=GNUmakefile:cygwin/GNUmakefile.in
SOLIBS='$(LIBS)'
- if test x"$enable_shared" = xyes; then
- LIBRUBY='lib$(RUBY_SO_NAME).dll.a'
- else
+ if test x"$enable_shared" = xno; then
LIBRUBY_SO=dummy
LIBRUBY='lib$(RUBY_SO_NAME).a'
LIBRUBYARG='-l$(RUBY_SO_NAME)'
@@ -1473,6 +1564,7 @@ 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)
@@ -1531,7 +1623,7 @@ AC_ARG_WITH(sitedir,
[ --with-sitedir=DIR site libraries in DIR [PREFIX/lib/ruby/site_ruby]],
[sitedir=$withval],
[sitedir='${prefix}/lib/ruby/site_ruby'])
-SITE_DIR="`eval \"echo ${sitedir}\"`"
+SITE_DIR=`eval echo \\"${sitedir}\\"`
case "$target_os" in
cygwin*|mingw*|*djgpp*|os2-emx*)
RUBY_SITE_LIB_PATH="`expr "$SITE_DIR" : "$prefix\(/.*\)"`" ||
@@ -1609,12 +1701,14 @@ else
echo "creating config.h"
tr -d '\015' < confdefs.h > config.h
fi
-: > confdefs.h
+tr -d '\015' < largefile.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
-} >> Makefile], [RUBY_INSTALL_NAME=$RUBY_INSTALL_NAME EXEEXT=$EXEEXT])
+ } >> confmk$$.tmp && mv -f confmk$$.tmp Makefile],
+[RUBY_INSTALL_NAME=$RUBY_INSTALL_NAME EXEEXT=$EXEEXT])
AC_OUTPUT
diff --git a/cygwin/GNUmakefile.in b/cygwin/GNUmakefile.in
index c9283d84b1..03208df11c 100644
--- a/cygwin/GNUmakefile.in
+++ b/cygwin/GNUmakefile.in
@@ -28,7 +28,6 @@ WPROGRAM = $(RUBYW_INSTALL_NAME)$(EXEEXT)
SOLIBS := $(DLL_BASE_NAME).res.@OBJEXT@ $(SOLIBS)
EXTOBJS += $(@:$(EXEEXT)=.res.@OBJEXT@)
RCFILES = $(RUBY_INSTALL_NAME).rc $(RUBYW_INSTALL_NAME).rc $(DLL_BASE_NAME).rc
-RUBYDEF = $(RUBY_SO_NAME).def
ruby: $(PROGRAM)
rubyw: $(WPROGRAM)
@@ -62,11 +61,6 @@ GNUmakefile: $(srcdir)/cygwin/GNUmakefile.in
ifeq (@target_os@,mingw32)
$(OBJS) $(MAINOBJ): win32/win32.h
-
-$(LIBRUBY_SO): $(RUBYDEF)
-
-$(RUBYDEF): $(LIBRUBY_A) $(PREP) $(RBCONFIG)
- $(MINIRUBY) $(srcdir)/win32/mkexports.rb -output=$@ $(LIBRUBY_A)
endif
ifeq (@target_os@,cygwin)
diff --git a/defines.h b/defines.h
index 9e26a2522b..7b62c5cd02 100644
--- a/defines.h
+++ b/defines.h
@@ -42,18 +42,14 @@
#endif
#define xmalloc ruby_xmalloc
-#define xmalloc2 ruby_xmalloc2
#define xcalloc ruby_xcalloc
#define xrealloc ruby_xrealloc
-#define xrealloc2 ruby_xrealloc2
#define xfree ruby_xfree
-void *xmalloc(size_t);
-void *xmalloc2(size_t,size_t);
-void *xcalloc(size_t,size_t);
-void *xrealloc(void*,size_t);
-void *xrealloc2(void*,size_t,size_t);
-void xfree(void*);
+void *xmalloc _((long));
+void *xcalloc _((long,long));
+void *xrealloc _((void*,long));
+void xfree _((void*));
#if SIZEOF_LONG_LONG > 0
# define LONG_LONG long long
@@ -188,7 +184,7 @@ void xfree(void*);
#endif
#if defined(__VMS)
-#include "vms/vms.h"
+#include "vms.h"
#endif
#if defined(__BEOS__)
@@ -222,9 +218,7 @@ flush_register_windows(void)
#endif
# if defined(__sparc_v9__) || defined(__sparcv9) || defined(__arch64__)
("flushw")
-# elif defined(linux) || defined(__linux__)
- ("ta 0x83")
-# else /* Solaris, OpenBSD, NetBSD, etc. */
+# else
("ta 0x03")
# endif /* trap always to flush register windows if we are on a Sparc system */
;
@@ -257,6 +251,18 @@ 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
+
#ifndef RUBY_PLATFORM
#define RUBY_PLATFORM "unknown-unknown"
#endif
diff --git a/dir.c b/dir.c
index 22d3400fe4..0dd12ffd7d 100644
--- a/dir.c
+++ b/dir.c
@@ -56,7 +56,7 @@ char *getenv();
#endif
#ifndef HAVE_STRING_H
-char *strchr(char*,char);
+char *strchr _((char*,char));
#endif
#include <ctype.h>
@@ -174,10 +174,10 @@ CompareImpl(const char *p1, const char *p2, int nocase)
#endif /* environment */
static char *
-bracket(
- const char *p, /* pattern (next to '[') */
- const char *s, /* string */
- int flags)
+bracket(p, s, flags)
+ const char *p; /* pattern (next to '[') */
+ const char *s; /* string */
+ int flags;
{
const int nocase = flags & FNM_CASEFOLD;
const int escape = !(flags & FNM_NOESCAPE);
@@ -224,10 +224,10 @@ bracket(
#define RETURN(val) return *pcur = p, *scur = s, (val);
static int
-fnmatch_helper(
- const char **pcur, /* pattern */
- const char **scur, /* string */
- int flags)
+fnmatch_helper(pcur, scur, flags)
+ const char **pcur; /* pattern */
+ const char **scur; /* string */
+ int flags;
{
const int period = !(flags & FNM_DOTMATCH);
const int pathname = flags & FNM_PATHNAME;
@@ -301,10 +301,10 @@ fnmatch_helper(
}
static int
-fnmatch(
- const char *p, /* pattern */
- const char *s, /* string */
- int flags)
+fnmatch(p, s, flags)
+ const char *p; /* pattern */
+ const char *s; /* string */
+ int flags;
{
const int period = !(flags & FNM_DOTMATCH);
const int pathname = flags & FNM_PATHNAME;
@@ -354,7 +354,8 @@ struct dir_data {
};
static void
-free_dir(struct dir_data *dir)
+free_dir(dir)
+ struct dir_data *dir;
{
if (dir) {
if (dir->dir) closedir(dir->dir);
@@ -363,10 +364,12 @@ free_dir(struct dir_data *dir)
free(dir);
}
-static VALUE dir_close(VALUE);
+static VALUE dir_close _((VALUE));
+static VALUE dir_s_alloc _((VALUE));
static VALUE
-dir_s_alloc(VALUE klass)
+dir_s_alloc(klass)
+ VALUE klass;
{
struct dir_data *dirp;
VALUE obj = Data_Make_Struct(klass, struct dir_data, 0, free_dir, dirp);
@@ -384,27 +387,28 @@ dir_s_alloc(VALUE klass)
* Returns a new directory object for the named directory.
*/
static VALUE
-dir_initialize(VALUE dir, VALUE dirname)
+dir_initialize(dir, dirname)
+ VALUE dir, dirname;
{
struct dir_data *dp;
- FilePathValue(dirname);
+ SafeStringValue(dirname);
Data_Get_Struct(dir, struct dir_data, dp);
if (dp->dir) closedir(dp->dir);
if (dp->path) free(dp->path);
dp->dir = NULL;
dp->path = NULL;
- dp->dir = opendir(RSTRING_PTR(dirname));
+ dp->dir = opendir(RSTRING(dirname)->ptr);
if (dp->dir == NULL) {
if (errno == EMFILE || errno == ENFILE) {
rb_gc();
- dp->dir = opendir(RSTRING_PTR(dirname));
+ dp->dir = opendir(RSTRING(dirname)->ptr);
}
if (dp->dir == NULL) {
- rb_sys_fail(RSTRING_PTR(dirname));
+ rb_sys_fail(RSTRING(dirname)->ptr);
}
}
- dp->path = strdup(RSTRING_PTR(dirname));
+ dp->path = strdup(RSTRING(dirname)->ptr);
return dir;
}
@@ -420,8 +424,10 @@ dir_initialize(VALUE dir, VALUE dirname)
* the block, and <code>Dir::open</code> returns the value of the
* block.
*/
+
static VALUE
-dir_s_open(VALUE klass, VALUE dirname)
+dir_s_open(klass, dirname)
+ VALUE klass, dirname;
{
struct dir_data *dp;
VALUE dir = Data_Make_Struct(klass, struct dir_data, 0, free_dir, dp);
@@ -435,13 +441,14 @@ dir_s_open(VALUE klass, VALUE dirname)
}
static void
-dir_closed(void)
+dir_closed()
{
rb_raise(rb_eIOError, "closed directory");
}
static void
-dir_check(VALUE dir)
+dir_check(dir)
+ VALUE dir;
{
if (!OBJ_TAINTED(dir) && rb_safe_level() >= 4)
rb_raise(rb_eSecurityError, "Insecure: operation on untainted Dir");
@@ -461,7 +468,8 @@ dir_check(VALUE dir)
* Return a string describing this Dir object.
*/
static VALUE
-dir_inspect(VALUE dir)
+dir_inspect(dir)
+ VALUE dir;
{
struct dir_data *dirp;
@@ -486,7 +494,8 @@ dir_inspect(VALUE dir)
* d.path #=> ".."
*/
static VALUE
-dir_path(VALUE dir)
+dir_path(dir)
+ VALUE dir;
{
struct dir_data *dirp;
@@ -508,7 +517,8 @@ dir_path(VALUE dir)
* d.read #=> "config.h"
*/
static VALUE
-dir_read(VALUE dir)
+dir_read(dir)
+ VALUE dir;
{
struct dir_data *dirp;
struct dirent *dp;
@@ -546,12 +556,12 @@ dir_read(VALUE dir)
* Got main.rb
*/
static VALUE
-dir_each(VALUE dir)
+dir_each(dir)
+ VALUE dir;
{
struct dir_data *dirp;
struct dirent *dp;
- RETURN_ENUMERATOR(dir, 0, 0);
GetDIR(dir, dirp);
rewinddir(dirp->dir);
for (dp = readdir(dirp->dir); dp != NULL; dp = readdir(dirp->dir)) {
@@ -575,7 +585,8 @@ dir_each(VALUE dir)
* d.tell #=> 12
*/
static VALUE
-dir_tell(VALUE dir)
+dir_tell(dir)
+ VALUE dir;
{
#ifdef HAVE_TELLDIR
struct dir_data *dirp;
@@ -604,7 +615,8 @@ dir_tell(VALUE dir)
* d.read #=> ".."
*/
static VALUE
-dir_seek(VALUE dir, VALUE pos)
+dir_seek(dir, pos)
+ VALUE dir, pos;
{
struct dir_data *dirp;
off_t p = NUM2OFFT(pos);
@@ -633,7 +645,8 @@ dir_seek(VALUE dir, VALUE pos)
* d.read #=> ".."
*/
static VALUE
-dir_set_pos(VALUE dir, VALUE pos)
+dir_set_pos(dir, pos)
+ VALUE dir, pos;
{
dir_seek(dir, pos);
return pos;
@@ -651,7 +664,8 @@ dir_set_pos(VALUE dir, VALUE pos)
* d.read #=> "."
*/
static VALUE
-dir_rewind(VALUE dir)
+dir_rewind(dir)
+ VALUE dir;
{
struct dir_data *dirp;
@@ -674,7 +688,8 @@ dir_rewind(VALUE dir)
* d.close #=> nil
*/
static VALUE
-dir_close(VALUE dir)
+dir_close(dir)
+ VALUE dir;
{
struct dir_data *dirp;
@@ -686,10 +701,11 @@ dir_close(VALUE dir)
}
static void
-dir_chdir(VALUE path)
+dir_chdir(path)
+ VALUE path;
{
- if (chdir(RSTRING_PTR(path)) < 0)
- rb_sys_fail(RSTRING_PTR(path));
+ if (chdir(RSTRING(path)->ptr) < 0)
+ rb_sys_fail(RSTRING(path)->ptr);
}
static int chdir_blocking = 0;
@@ -701,7 +717,8 @@ struct chdir_data {
};
static VALUE
-chdir_yield(struct chdir_data *args)
+chdir_yield(args)
+ struct chdir_data *args;
{
dir_chdir(args->new_path);
args->done = Qtrue;
@@ -712,7 +729,8 @@ chdir_yield(struct chdir_data *args)
}
static VALUE
-chdir_restore(struct chdir_data *args)
+chdir_restore(args)
+ struct chdir_data *args;
{
if (args->done) {
chdir_blocking--;
@@ -763,13 +781,16 @@ chdir_restore(struct chdir_data *args)
* /var/spool/mail
*/
static VALUE
-dir_s_chdir(int argc, VALUE *argv, VALUE obj)
+dir_s_chdir(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE path = Qnil;
rb_secure(2);
if (rb_scan_args(argc, argv, "01", &path) == 1) {
- FilePathValue(path);
+ SafeStringValue(path);
}
else {
const char *dist = getenv("HOME");
@@ -811,7 +832,8 @@ dir_s_chdir(int argc, VALUE *argv, VALUE obj)
* Dir.getwd #=> "/tmp"
*/
static VALUE
-dir_s_getwd(VALUE dir)
+dir_s_getwd(dir)
+ VALUE dir;
{
char *path;
VALUE cwd;
@@ -824,14 +846,16 @@ dir_s_getwd(VALUE dir)
return cwd;
}
+static void check_dirname _((volatile VALUE *));
static void
-check_dirname(volatile VALUE *dir)
+check_dirname(dir)
+ volatile VALUE *dir;
{
char *path, *pend;
+ SafeStringValue(*dir);
rb_secure(2);
- FilePathValue(*dir);
- path = RSTRING_PTR(*dir);
+ path = RSTRING(*dir)->ptr;
if (path && *(pend = rb_path_end(rb_path_skip_prefix(path)))) {
*dir = rb_str_new(path, pend - path);
}
@@ -847,13 +871,14 @@ check_dirname(volatile VALUE *dir)
* information.
*/
static VALUE
-dir_s_chroot(VALUE dir, VALUE path)
+dir_s_chroot(dir, path)
+ VALUE dir, path;
{
#if defined(HAVE_CHROOT) && !defined(__CHECKER__)
check_dirname(&path);
- if (chroot(RSTRING_PTR(path)) == -1)
- rb_sys_fail(RSTRING_PTR(path));
+ if (chroot(RSTRING(path)->ptr) == -1)
+ rb_sys_fail(RSTRING(path)->ptr);
return INT2FIX(0);
#else
@@ -876,7 +901,10 @@ dir_s_chroot(VALUE dir, VALUE path)
*
*/
static VALUE
-dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
+dir_s_mkdir(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE path, vmode;
int mode;
@@ -889,8 +917,8 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
}
check_dirname(&path);
- if (mkdir(RSTRING_PTR(path), mode) == -1)
- rb_sys_fail(RSTRING_PTR(path));
+ if (mkdir(RSTRING(path)->ptr, mode) == -1)
+ rb_sys_fail(RSTRING(path)->ptr);
return INT2FIX(0);
}
@@ -905,17 +933,19 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
* <code>SystemCallError</code> if the directory isn't empty.
*/
static VALUE
-dir_s_rmdir(VALUE obj, VALUE dir)
+dir_s_rmdir(obj, dir)
+ VALUE obj, dir;
{
check_dirname(&dir);
- if (rmdir(RSTRING_PTR(dir)) < 0)
- rb_sys_fail(RSTRING_PTR(dir));
+ if (rmdir(RSTRING(dir)->ptr) < 0)
+ rb_sys_fail(RSTRING(dir)->ptr);
return INT2FIX(0);
}
static void
-sys_warning_1(const char* mesg)
+sys_warning_1(mesg)
+ const char* mesg;
{
rb_sys_warning("%s", mesg);
}
@@ -928,13 +958,19 @@ sys_warning_1(const char* 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 && errno != ENOENT)
+ if (ret < 0 && !to_be_ignored(errno))
sys_warning(path);
return ret;
@@ -944,7 +980,7 @@ static int
do_lstat(const char *path, struct stat *pst, int flags)
{
int ret = lstat(path, pst);
- if (ret < 0 && errno != ENOENT)
+ if (ret < 0 && !to_be_ignored(errno))
sys_warning(path);
return ret;
@@ -954,7 +990,7 @@ static DIR *
do_opendir(const char *path, int flags)
{
DIR *dirp = opendir(path);
- if (dirp == NULL && errno != ENOENT && errno != ENOTDIR)
+ if (dirp == NULL && !to_be_ignored(errno))
sys_warning(path);
return dirp;
@@ -962,7 +998,9 @@ do_opendir(const char *path, int flags)
/* Return nonzero if S has any special globbing chars in it. */
static int
-has_magic(const char *s, int flags)
+has_magic(s, flags)
+ const char *s;
+ int flags;
{
const int escape = !(flags & FNM_NOESCAPE);
const int nocase = flags & FNM_CASEFOLD;
@@ -1029,9 +1067,10 @@ find_dirsep(const char *s, int flags)
return (char *)p-1;
}
-/* Remove escaping baskclashes */
+/* Remove escaping backslashes */
static void
-remove_backslashes(char *p)
+remove_backslashes(p)
+ char *p;
{
char *t = p;
char *s = p;
@@ -1149,10 +1188,6 @@ join_path(const char *path, int dirsep, const char *name)
enum answer { YES, NO, UNKNOWN };
-#ifndef S_ISDIR
-# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
-#endif
-
#ifndef S_ISLNK
# ifndef S_IFLNK
# define S_ISLNK(m) (0)
@@ -1161,34 +1196,43 @@ enum answer { YES, NO, UNKNOWN };
# endif
#endif
+#ifndef S_ISDIR
+# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
+#endif
+
struct glob_args {
- void (*func)(const char *, VALUE);
- const char *path;
- VALUE value;
+ void (*func) _((const char*, VALUE));
+ const char *c;
+ VALUE v;
};
+static VALUE glob_func_caller _((VALUE));
+
static VALUE
-glob_func_caller(VALUE val)
+glob_func_caller(val)
+ VALUE val;
{
struct glob_args *args = (struct glob_args *)val;
- (*args->func)(args->path, args->value);
+ (*args->func)(args->c, args->v);
return Qnil;
}
#define glob_call_func(func, path, arg) (*func)(path, arg)
+static int glob_helper _((const char *, int, enum answer, enum answer, struct glob_pattern **, struct glob_pattern **, int, ruby_glob_func *, VALUE));
+
static int
-glob_helper(
- const char *path,
- int dirsep, /* '/' should be placed before appending child entry's name to 'path'. */
- enum answer exist, /* Does 'path' indicate an existing entry? */
- enum answer isdir, /* Does 'path' indicate a directory or a symlink to a directory? */
- struct glob_pattern **beg,
- struct glob_pattern **end,
- int flags,
- ruby_glob_func *func,
- VALUE arg)
+glob_helper(path, dirsep, exist, isdir, beg, end, flags, func, arg)
+ const char *path;
+ int dirsep; /* '/' should be placed before appending child entry's name to 'path'. */
+ enum answer exist; /* Does 'path' indicate an existing entry? */
+ enum answer isdir; /* Does 'path' indicate a directory or a symlink to a directory? */
+ struct glob_pattern **beg;
+ struct glob_pattern **end;
+ int flags;
+ ruby_glob_func *func;
+ VALUE arg;
{
struct stat st;
int status = 0;
@@ -1363,7 +1407,11 @@ glob_helper(
}
static int
-ruby_glob0(const char *path, int flags, ruby_glob_func *func, VALUE arg)
+ruby_glob0(path, flags, func, arg)
+ const char *path;
+ int flags;
+ ruby_glob_func *func;
+ VALUE arg;
{
struct glob_pattern *list;
const char *root, *start;
@@ -1398,29 +1446,41 @@ ruby_glob0(const char *path, int flags, ruby_glob_func *func, VALUE arg)
}
int
-ruby_glob(const char *path, int flags, ruby_glob_func *func, VALUE arg)
+ruby_glob(path, flags, func, arg)
+ const char *path;
+ int flags;
+ ruby_glob_func *func;
+ VALUE arg;
{
return ruby_glob0(path, flags & ~GLOB_VERBOSE, func, arg);
}
+static int rb_glob_caller _((const char *, VALUE));
+
static int
-rb_glob_caller(const char *path, VALUE a)
+rb_glob_caller(path, a)
+ const char *path;
+ VALUE a;
{
int status;
struct glob_args *args = (struct glob_args *)a;
- args->path = path;
+ args->c = path;
rb_protect(glob_func_caller, a, &status);
return status;
}
static int
-rb_glob2(const char *path, int flags, void (*func)(const char *, VALUE), VALUE arg)
+rb_glob2(path, flags, func, arg)
+ const char *path;
+ int flags;
+ void (*func) _((const char *, VALUE));
+ VALUE arg;
{
struct glob_args args;
args.func = func;
- args.value = arg;
+ args.v = arg;
if (flags & FNM_SYSCASE) {
rb_warning("Dir.glob() ignores File::FNM_CASEFOLD");
@@ -1430,20 +1490,30 @@ rb_glob2(const char *path, int flags, void (*func)(const char *, VALUE), VALUE a
}
void
-rb_glob(const char *path, void (*func)(const char *, VALUE), VALUE arg)
+rb_glob(path, func, arg)
+ const char *path;
+ void (*func) _((const char*, VALUE));
+ VALUE arg;
{
int status = rb_glob2(path, 0, func, arg);
if (status) GLOB_JUMP_TAG(status);
}
+static void push_pattern _((const char* path, VALUE ary));
static void
-push_pattern(const char *path, VALUE ary)
+push_pattern(path, ary)
+ const char *path;
+ VALUE ary;
{
rb_ary_push(ary, rb_tainted_str_new2(path));
}
int
-ruby_brace_expand(const char *str, int flags, ruby_glob_func *func, VALUE arg)
+ruby_brace_expand(str, flags, func, arg)
+ const char *str;
+ int flags;
+ ruby_glob_func *func;
+ VALUE arg;
{
const int escape = !(flags & FNM_NOESCAPE);
const char *p = str;
@@ -1504,8 +1574,11 @@ struct brace_args {
int flags;
};
+static int glob_brace _((const char *, VALUE));
static int
-glob_brace(const char *path, VALUE val)
+glob_brace(path, val)
+ const char *path;
+ VALUE val;
{
struct brace_args *arg = (struct brace_args *)val;
@@ -1513,7 +1586,11 @@ glob_brace(const char *path, VALUE val)
}
static int
-ruby_brace_glob0(const char *str, int flags, ruby_glob_func *func, VALUE arg)
+ruby_brace_glob0(str, flags, func, arg)
+ const char *str;
+ int flags;
+ ruby_glob_func *func;
+ VALUE arg;
{
struct brace_args args;
@@ -1524,7 +1601,11 @@ ruby_brace_glob0(const char *str, int flags, ruby_glob_func *func, VALUE arg)
}
int
-ruby_brace_glob(const char *str, int flags, ruby_glob_func *func, VALUE arg)
+ruby_brace_glob(str, flags, func, arg)
+ const char *str;
+ int flags;
+ ruby_glob_func *func;
+ VALUE arg;
{
return ruby_brace_glob0(str, flags & ~GLOB_VERBOSE, func, arg);
}
@@ -1535,37 +1616,42 @@ push_glob(VALUE ary, const char *str, int flags)
struct glob_args args;
args.func = push_pattern;
- args.value = ary;
+ args.v = ary;
return ruby_brace_glob0(str, flags | GLOB_VERBOSE, rb_glob_caller, (VALUE)&args);
}
static VALUE
-rb_push_glob(VALUE str, int flags) /* '\0' is delimiter */
+rb_push_glob(str, flags) /* '\0' is delimiter */
+ VALUE str;
+ int flags;
{
long offset = 0;
VALUE ary;
- StringValue(str);
ary = rb_ary_new();
+ SafeStringValue(str);
while (offset < RSTRING_LEN(str)) {
- int status = push_glob(ary, RSTRING_PTR(str) + offset, flags);
+ int status = push_glob(ary, RSTRING(str)->ptr + offset, flags);
char *p, *pend;
if (status) GLOB_JUMP_TAG(status);
if (offset >= RSTRING_LEN(str)) break;
- p = RSTRING_PTR(str) + offset;
+ p = RSTRING(str)->ptr + offset;
p += strlen(p) + 1;
- pend = RSTRING_PTR(str) + RSTRING_LEN(str);
+ pend = RSTRING(str)->ptr + RSTRING_LEN(str);
while (p < pend && !*p)
p++;
- offset = p - RSTRING_PTR(str);
+ offset = p - RSTRING(str)->ptr;
}
return ary;
}
static VALUE
-dir_globs(long argc, VALUE *argv, int flags)
+dir_globs(argc, argv, flags)
+ long argc;
+ VALUE *argv;
+ int flags;
{
VALUE ary = rb_ary_new();
long i;
@@ -1574,7 +1660,7 @@ dir_globs(long argc, VALUE *argv, int flags)
int status;
VALUE str = argv[i];
StringValue(str);
- status = push_glob(ary, RSTRING_PTR(str), flags);
+ status = push_glob(ary, RSTRING(str)->ptr, flags);
if (status) GLOB_JUMP_TAG(status);
}
@@ -1593,12 +1679,12 @@ dir_globs(long argc, VALUE *argv, int flags)
*/
static VALUE
dir_s_aref(int argc, VALUE *argv, VALUE obj)
-{
+ {
if (argc == 1) {
return rb_push_glob(argv[0], 0);
}
return dir_globs(argc, argv, 0);
-}
+ }
/*
* call-seq:
@@ -1661,7 +1747,10 @@ dir_s_aref(int argc, VALUE *argv, VALUE obj)
* Dir.glob(librbfiles) #=> ["lib/song.rb"]
*/
static VALUE
-dir_s_glob(int argc, VALUE *argv, VALUE obj)
+dir_s_glob(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE str, rflags, ary;
int flags;
@@ -1688,7 +1777,8 @@ dir_s_glob(int argc, VALUE *argv, VALUE obj)
}
static VALUE
-dir_open_dir(VALUE path)
+dir_open_dir(path)
+ VALUE path;
{
VALUE dir = rb_funcall(rb_cDir, rb_intern("open"), 1, path);
@@ -1719,7 +1809,8 @@ dir_open_dir(VALUE path)
*
*/
static VALUE
-dir_foreach(VALUE io, VALUE dirname)
+dir_foreach(io, dirname)
+ VALUE io, dirname;
{
VALUE dir;
@@ -1740,7 +1831,8 @@ dir_foreach(VALUE io, VALUE dirname)
*
*/
static VALUE
-dir_entries(VALUE io, VALUE dirname)
+dir_entries(io, dirname)
+ VALUE io, dirname;
{
VALUE dir;
@@ -1830,7 +1922,10 @@ dir_entries(VALUE io, VALUE dirname)
* File.fnmatch(pattern, 'a/.b/c/foo', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true
*/
static VALUE
-file_s_fnmatch(int argc, VALUE *argv, VALUE obj)
+file_s_fnmatch(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE pattern, path;
VALUE rflags;
@@ -1844,7 +1939,7 @@ file_s_fnmatch(int argc, VALUE *argv, VALUE obj)
StringValue(pattern);
StringValue(path);
- if (fnmatch(RSTRING_PTR(pattern), RSTRING_PTR(path), flags) == 0)
+ if (fnmatch(RSTRING(pattern)->ptr, RSTRING(path)->ptr, flags) == 0)
return Qtrue;
return Qfalse;
@@ -1862,7 +1957,7 @@ file_s_fnmatch(int argc, VALUE *argv, VALUE obj)
* (<code>.</code>).
*/
void
-Init_Dir(void)
+Init_Dir()
{
rb_cDir = rb_define_class("Dir", rb_cObject);
@@ -1875,7 +1970,6 @@ Init_Dir(void)
rb_define_method(rb_cDir,"initialize", dir_initialize, 1);
rb_define_method(rb_cDir,"path", dir_path, 0);
- rb_define_method(rb_cDir,"inspect", dir_inspect, 0);
rb_define_method(rb_cDir,"read", dir_read, 0);
rb_define_method(rb_cDir,"each", dir_each, 0);
rb_define_method(rb_cDir,"rewind", dir_rewind, 0);
diff --git a/distruby.rb b/distruby.rb
new file mode 100644
index 0000000000..613da0eb9c
--- /dev/null
+++ b/distruby.rb
@@ -0,0 +1,59 @@
+#!./miniruby
+
+if RUBY_PATCHLEVEL.zero?
+ dirname = sprintf 'ruby-%s', RUBY_VERSION
+ tagname = dirname.gsub /ruby-(\d)\.(\d)\.(\d)/, 'v\1_\2_\3'
+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'
+repos = 'http://svn.ruby-lang.org/repos/ruby/tags/' + tagname
+
+STDERR.puts 'exporting sources...'
+system 'svn', 'export', '-q', repos, dirname
+Dir.chdir dirname do
+ STDERR.puts 'generating configure...'
+ system 'autoconf'
+ system 'rm', '-rf', 'autom4te.cache'
+
+ STDERR.puts 'generating parse.c...'
+ 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
+end
+
+
+
+#
+# Local Variables:
+# mode: ruby
+# code: utf-8
+# indent-tabs-mode: t
+# tab-width: 3
+# ruby-indent-level: 3
+# fill-column: 79
+# default-justification: full
+# End:
+# vi: ts=3 sw=3
+
diff --git a/djgpp/configure.bat b/djgpp/configure.bat
index e6a5d79d4a..e6a5d79d4a 100644..100755
--- a/djgpp/configure.bat
+++ b/djgpp/configure.bat
diff --git a/dln.c b/dln.c
index 221e1a1f2e..ae12758d19 100644
--- a/dln.c
+++ b/dln.c
@@ -101,7 +101,9 @@ char *getenv();
#endif
static int
-init_funcname_len(char **buf, const char *file)
+init_funcname_len(buf, file)
+ char **buf;
+ const char *file;
{
char *p;
const char *slash;
@@ -182,7 +184,10 @@ static st_table *undef_tbl;
static int load_lib();
static int
-load_header(int fd, struct exec *hdrp, long disp)
+load_header(fd, hdrp, disp)
+ int fd;
+ struct exec *hdrp;
+ long disp;
{
int size;
@@ -252,7 +257,10 @@ static int reloc_r_length[] = {
#endif
static struct relocation_info *
-load_reloc(int fd, struct exec *hdrp, long disp)
+load_reloc(fd, hdrp, disp)
+ int fd;
+ struct exec *hdrp;
+ long disp;
{
struct relocation_info *reloc;
int size;
@@ -275,7 +283,10 @@ load_reloc(int fd, struct exec *hdrp, long disp)
}
static struct nlist *
-load_sym(int fd, struct exec *hdrp, long disp)
+load_sym(fd, hdrp, disp)
+ int fd;
+ struct exec *hdrp;
+ long disp;
{
struct nlist * buffer;
struct nlist * sym;
@@ -316,7 +327,9 @@ load_sym(int fd, struct exec *hdrp, long disp)
}
static st_table *
-sym_hash(struct exec *hdrp, struct nlist *syms)
+sym_hash(hdrp, syms)
+ struct exec *hdrp;
+ struct nlist *syms;
{
st_table *tbl;
struct nlist *sym = syms;
@@ -336,7 +349,8 @@ sym_hash(struct exec *hdrp, struct nlist *syms)
}
static int
-dln_init(const char *prog)
+dln_init(prog)
+ const char *prog;
{
char *file;
int fd;
@@ -410,7 +424,11 @@ dln_init(const char *prog)
}
static long
-load_text_data(int fd, struct exec *hdrp, int bss, long disp)
+load_text_data(fd, hdrp, bss, disp)
+ int fd;
+ struct exec *hdrp;
+ int bss;
+ long disp;
{
int size;
unsigned char* addr;
@@ -444,7 +462,8 @@ load_text_data(int fd, struct exec *hdrp, int bss, long disp)
}
static int
-undef_print(char *key, char *value)
+undef_print(key, value)
+ char *key, *value;
{
fprintf(stderr, " %s\n", key);
return ST_CONTINUE;
@@ -481,7 +500,10 @@ struct undef {
static st_table *reloc_tbl = NULL;
static void
-link_undef(const char *name, long base, struct relocation_info *reloc)
+link_undef(name, base, reloc)
+ const char *name;
+ long base;
+ struct relocation_info *reloc;
{
static int u_no = 0;
struct undef *obj;
@@ -514,7 +536,10 @@ struct reloc_arg {
};
static int
-reloc_undef(int no, struct undef *undef, struct reloc_arg *arg)
+reloc_undef(no, undef, arg)
+ int no;
+ struct undef *undef;
+ struct reloc_arg *arg;
{
int datum;
char *address;
@@ -575,7 +600,9 @@ reloc_undef(int no, struct undef *undef, struct reloc_arg *arg)
}
static void
-unlink_undef(const char *name, long value)
+unlink_undef(name, value)
+ const char *name;
+ long value;
{
struct reloc_arg arg;
@@ -590,7 +617,10 @@ struct indr_data {
};
static int
-reloc_repl(int no, struct undef *undef, struct indr_data *data)
+reloc_repl(no, undef, data)
+ int no;
+ struct undef *undef;
+ struct indr_data *data;
{
if (strcmp(data->name0, undef->name) == 0) {
free(undef->name);
@@ -601,7 +631,10 @@ reloc_repl(int no, struct undef *undef, struct indr_data *data)
#endif
static int
-load_1(int fd, long disp, const char *need_init)
+load_1(fd, disp, need_init)
+ int fd;
+ long disp;
+ const char *need_init;
{
static char *libc = LIBC_NAME;
struct exec hdr;
@@ -882,7 +915,10 @@ load_1(int fd, long disp, const char *need_init)
static int target_offset;
static int
-search_undef(const char *key, int value, st_table *lib_tbl)
+search_undef(key, value, lib_tbl)
+ const char *key;
+ int value;
+ st_table *lib_tbl;
{
long offset;
@@ -899,7 +935,8 @@ struct symdef {
char *dln_librrb_ary_path = DLN_DEFAULT_LIB_PATH;
static int
-load_lib(const char *lib)
+load_lib(lib)
+ const char *lib;
{
char *path, *file;
char armagic[SARMAG];
@@ -1036,7 +1073,8 @@ load_lib(const char *lib)
}
static int
-load(const char *file)
+load(file)
+ const char *file;
{
int fd;
int result;
@@ -1061,7 +1099,8 @@ load(const char *file)
}
void*
-dln_sym(const char *name)
+dln_sym(name)
+ const char *name;
{
struct nlist *sym;
@@ -1073,7 +1112,12 @@ dln_sym(const char *name)
#endif /* USE_DLN_A_OUT */
#ifdef USE_DLN_DLOPEN
-# include <dlfcn.h>
+# if defined(__NetBSD__) && defined(__NetBSD_Version__) && __NetBSD_Version__ < 105000000
+# include <nlist.h>
+# include <link.h>
+# else
+# include <dlfcn.h>
+# endif
#endif
#ifdef __hpux
@@ -1116,7 +1160,7 @@ dln_sym(const char *name)
#endif
static const char *
-dln_strerror(void)
+dln_strerror()
{
#ifdef USE_DLN_A_OUT
char *strerror();
@@ -1214,10 +1258,24 @@ aix_loaderror(const char *pathname)
}
#endif
+#if defined(__VMS)
+#include <starlet.h>
+#include <rms.h>
+#include <stsdef.h>
+#include <unixlib.h>
+#include <descrip.h>
+#include <lib$routines.h>
+
+static char *vms_filespec;
+static int vms_fileact(char *filespec, int type);
+static long vms_fisexh(long *sigarr, long *mecarr);
+#endif
+
#endif /* NO_DLN_LOAD */
void*
-dln_load(const char *file)
+dln_load(file)
+ const char *file;
{
#ifdef NO_DLN_LOAD
rb_raise(rb_eLoadError, "this executable file can't load extension libraries");
@@ -1519,9 +1577,16 @@ dln_load(const char *file)
#if defined(__VMS)
#define DLN_DEFINED
{
- void *handle, (*init_fct)();
+ long status;
+ void (*init_fct)();
char *fname, *p1, *p2;
+ $DESCRIPTOR(fname_d, "");
+ $DESCRIPTOR(image_d, "");
+ $DESCRIPTOR(buf_d, "");
+
+ decc$to_vms(file, vms_fileact, 0, 0);
+
fname = (char *)__alloca(strlen(file)+1);
strcpy(fname,file);
if (p1 = strrchr(fname,'/'))
@@ -1529,19 +1594,35 @@ dln_load(const char *file)
if (p2 = strrchr(fname,'.'))
*p2 = '\0';
- if ((handle = (void*)dlopen(fname, 0)) == NULL) {
+ fname_d.dsc$w_length = strlen(fname);
+ fname_d.dsc$a_pointer = fname;
+ image_d.dsc$w_length = strlen(vms_filespec);
+ image_d.dsc$a_pointer = vms_filespec;
+ buf_d.dsc$w_length = strlen(buf);
+ buf_d.dsc$a_pointer = buf;
+
+ lib$establish(vms_fisexh);
+
+ status = lib$find_image_symbol (
+ &fname_d,
+ &buf_d,
+ &init_fct,
+ &image_d);
+
+ lib$establish(0);
+
+ if (status == RMS$_FNF) {
error = dln_strerror();
goto failed;
- }
-
- if ((init_fct = (void (*)())dlsym(handle, buf)) == NULL) {
+ } else if (!$VMS_STATUS_SUCCESS(status)) {
error = DLN_ERROR();
- dlclose(handle);
goto failed;
}
+
/* Call the init code */
(*init_fct)();
- return handle;
+
+ return 1;
}
#endif /* __VMS */
@@ -1560,10 +1641,12 @@ dln_load(const char *file)
return 0; /* dummy return */
}
-static char *dln_find_1(const char *fname, const char *path, int exe_flag);
+static char *dln_find_1();
char *
-dln_find_exe(const char *fname, const char *path)
+dln_find_exe(fname, path)
+ const char *fname;
+ const char *path;
{
if (!path) {
path = getenv(PATH_ENV);
@@ -1580,7 +1663,9 @@ dln_find_exe(const char *fname, const char *path)
}
char *
-dln_find_file(const char *fname, const char *path)
+dln_find_file(fname, path)
+ const char *fname;
+ const char *path;
{
#ifndef __MACOS__
if (!path) path = ".";
@@ -1591,62 +1676,37 @@ dln_find_file(const char *fname, const char *path)
#endif
}
-#if defined(__CYGWIN32__)
-const char *
-conv_to_posix_path(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 *
-dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking for executable. */)
+dln_find_1(fname, path, exe_flag)
+ char *fname;
+ char *path;
+ int exe_flag; /* non 0 if looking for executable. */
{
- register const char *dp;
- register const char *ep;
+ register char *dp;
+ register char *ep;
register char *bp;
struct stat st;
#ifdef __MACOS__
const char* mac_fullpath;
#endif
-#define RETURN_IF(expr) if (expr) return (char *)fname;
-
- RETURN_IF(!fname);
- RETURN_IF(fname[0] == '/');
- RETURN_IF(strncmp("./", fname, 2) == 0 || strncmp("../", fname, 3) == 0);
- RETURN_IF(exe_flag && strchr(fname, '/'));
+ if (!fname) return fname;
+ if (fname[0] == '/') return fname;
+ if (strncmp("./", fname, 2) == 0 || strncmp("../", fname, 3) == 0)
+ return fname;
+ if (exe_flag && strchr(fname, '/')) return fname;
#ifdef DOSISH
- RETURN_IF(fname[0] == '\\');
+ if (fname[0] == '\\') return fname;
# ifdef DOSISH_DRIVE_LETTER
- RETURN_IF(strlen(fname) > 2 && fname[1] == ':');
+ if (strlen(fname) > 2 && fname[1] == ':') return fname;
# endif
- RETURN_IF(strncmp(".\\", fname, 2) == 0 || strncmp("..\\", fname, 3) == 0);
- RETURN_IF(exe_flag && strchr(fname, '\\'));
+ if (strncmp(".\\", fname, 2) == 0 || strncmp("..\\", fname, 3) == 0)
+ return fname;
+ if (exe_flag && strchr(fname, '\\')) return fname;
#endif
-#undef RETURN_IF
-
for (dp = path;; dp = ++ep) {
register int l;
int i;
@@ -1712,26 +1772,9 @@ dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking
}
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[] = {
+ static const char extension[][5] = {
#if defined(MSDOS)
".com", ".exe", ".bat",
#if defined(DJGPP)
@@ -1744,11 +1787,10 @@ dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking
".r", ".R", ".x", ".X", ".bat", ".BAT",
/* __human68k__ */
#endif
- (char *) NULL
};
int j;
- for (j = 0; extension[j]; j++) {
+ for (j = 0; j < sizeof(extension) / sizeof(extension[0]); j++) {
if (fspace < strlen(extension[j])) {
fprintf(stderr, "openpath: pathname too long (ignored)\n");
fprintf(stderr, "\tDirectory \"%.*s\"\n", (int) (bp - fbuf), fbuf);
@@ -1765,9 +1807,28 @@ dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking
#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') {
@@ -1777,3 +1838,24 @@ dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking
/* otherwise try the next component in the search path */
}
}
+
+#if defined(__VMS)
+
+/* action routine for decc$to_vms */
+static int vms_fileact(char *filespec, int type)
+{
+ if (vms_filespec)
+ free(vms_filespec);
+ vms_filespec = malloc(strlen(filespec)+1);
+ strcpy(vms_filespec, filespec);
+ return 1;
+}
+
+/* exception handler for LIB$FIND_IMAGE_SYMBOL */
+static long vms_fisexh(long *sigarr, long *mecarr)
+{
+ sys$unwind(1, 0);
+ return 1;
+}
+
+#endif /* __VMS */
diff --git a/dln.h b/dln.h
index 4fd51cbee0..182cf9f9f4 100644
--- a/dln.h
+++ b/dln.h
@@ -29,12 +29,12 @@
# define _(args) ()
#endif
-char *dln_find_exe(const char*,const char*);
-char *dln_find_file(const char*,const char*);
+char *dln_find_exe _((const char*,const char*));
+char *dln_find_file _((const char*,const char*));
#ifdef USE_DLN_A_OUT
extern char *dln_argv0;
#endif
-void *dln_load(const char*);
+void *dln_load _((const char*));
#endif
diff --git a/dmyext.c b/dmyext.c
index 4d273f7faf..4120d493c3 100644
--- a/dmyext.c
+++ b/dmyext.c
@@ -1,4 +1,4 @@
void
-Init_ext(void)
+Init_ext()
{
}
diff --git a/doc/NEWS b/doc/NEWS-1.8.0
index b4445fa59f..b4445fa59f 100644
--- a/doc/NEWS
+++ b/doc/NEWS-1.8.0
diff --git a/enum.c b/enum.c
index 4836aef72b..2a29272ae9 100644
--- a/enum.c
+++ b/enum.c
@@ -17,8 +17,16 @@
VALUE rb_mEnumerable;
static ID id_each, id_eqq, id_cmp;
+VALUE
+rb_each(obj)
+ VALUE obj;
+{
+ return rb_funcall(obj, id_each, 0, 0);
+}
+
static VALUE
-grep_i(VALUE i, VALUE *arg)
+grep_i(i, arg)
+ VALUE i, *arg;
{
if (RTEST(rb_funcall(arg[0], id_eqq, 1, i))) {
rb_ary_push(arg[1], i);
@@ -27,7 +35,8 @@ grep_i(VALUE i, VALUE *arg)
}
static VALUE
-grep_iter_i(VALUE i, VALUE *arg)
+grep_iter_i(i, arg)
+ VALUE i, *arg;
{
if (RTEST(rb_funcall(arg[0], id_eqq, 1, i))) {
rb_ary_push(arg[1], rb_yield(i));
@@ -54,7 +63,8 @@ grep_iter_i(VALUE i, VALUE *arg)
*/
static VALUE
-enum_grep(VALUE obj, VALUE pat)
+enum_grep(obj, pat)
+ VALUE obj, pat;
{
VALUE ary = rb_ary_new();
VALUE arg[2];
@@ -62,68 +72,15 @@ enum_grep(VALUE obj, VALUE pat)
arg[0] = pat;
arg[1] = ary;
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? grep_iter_i : grep_i, (VALUE)arg);
+ rb_iterate(rb_each, obj, rb_block_given_p() ? grep_iter_i : grep_i, (VALUE)arg);
return ary;
}
static VALUE
-count_i(VALUE i, VALUE *arg)
-{
- if (rb_equal(i, arg[0])) {
- arg[1]++;
- }
- return Qnil;
-}
-
-static VALUE
-count_iter_i(VALUE i, long *n)
-{
- if (RTEST(rb_yield(i))) {
- (*n)++;
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.count(item) => int
- * enum.count {| obj | block } => int
- *
- * Returns the number of items in <i>enum</i> for which equals to <i>item</i>.
- * If a block is given, counts the number of elements yielding a true value.
- *
- * ary = [1, 2, 4, 2]
- * ary.count(2) # => 2
- * ary.count{|x|x%2==0} # => 3
- *
- */
-
-static VALUE
-enum_count(int argc, VALUE *argv, VALUE obj)
-{
- if (argc == 1) {
- VALUE item, args[2];
-
- if (rb_block_given_p()) {
- rb_warn("given block not used");
- }
- rb_scan_args(argc, argv, "1", &item);
- args[0] = item;
- args[1] = 0;
- rb_block_call(obj, id_each, 0, 0, count_i, (VALUE)&args);
- return INT2NUM(args[1]);
- }
- else {
- long n = 0;
-
- rb_block_call(obj, id_each, 0, 0, count_iter_i, (VALUE)&n);
- return INT2NUM(n);
- }
-}
-
-static VALUE
-find_i(VALUE i, VALUE *memo)
+find_i(i, memo)
+ VALUE i;
+ VALUE *memo;
{
if (RTEST(rb_yield(i))) {
*memo = i;
@@ -148,14 +105,16 @@ find_i(VALUE i, VALUE *memo)
*/
static VALUE
-enum_find(int argc, VALUE *argv, VALUE obj)
+enum_find(argc, argv, obj)
+ int argc;
+ VALUE* argv;
+ VALUE obj;
{
VALUE memo = Qundef;
VALUE if_none;
rb_scan_args(argc, argv, "01", &if_none);
- RETURN_ENUMERATOR(obj, argc, argv);
- rb_block_call(obj, id_each, 0, 0, find_i, (VALUE)&memo);
+ rb_iterate(rb_each, obj, find_i, (VALUE)&memo);
if (memo != Qundef) {
return memo;
}
@@ -166,46 +125,8 @@ enum_find(int argc, VALUE *argv, VALUE obj)
}
static VALUE
-find_index_i(VALUE i, VALUE *memo)
-{
- if (RTEST(rb_yield(i))) {
- memo[0] = UINT2NUM(memo[1]);
- rb_iter_break();
- }
- memo[1]++;
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.find_index(ifnone = nil) {| obj | block } => int
- *
- * Passes each entry in <i>enum</i> to <em>block</em>. Returns the
- * index for the first for which <em>block</em> is not <code>false</code>.
- * If no object matches, returns <code>nil</code>
- *
- * (1..10).find_index {|i| i % 5 == 0 and i % 7 == 0 } #=> nil
- * (1..100).find_index {|i| i % 5 == 0 and i % 7 == 0 } #=> 35
- *
- */
-
-static VALUE
-enum_find_index(VALUE obj)
-{
- VALUE memo[2];
-
- RETURN_ENUMERATOR(obj, 0, 0);
- memo[0] = Qundef;
- memo[1] = 0;
- rb_block_call(obj, id_each, 0, 0, find_index_i, (VALUE)memo);
- if (memo[0] != Qundef) {
- return memo[0];
- }
- return Qnil;
-}
-
-static VALUE
-find_all_i(VALUE i, VALUE ary)
+find_all_i(i, ary)
+ VALUE i, ary;
{
if (RTEST(rb_yield(i))) {
rb_ary_push(ary, i);
@@ -227,20 +148,19 @@ find_all_i(VALUE i, VALUE ary)
*/
static VALUE
-enum_find_all(VALUE obj)
+enum_find_all(obj)
+ VALUE obj;
{
- VALUE ary;
+ VALUE ary = rb_ary_new();
- RETURN_ENUMERATOR(obj, 0, 0);
-
- ary = rb_ary_new();
- rb_block_call(obj, id_each, 0, 0, find_all_i, ary);
+ rb_iterate(rb_each, obj, find_all_i, ary);
return ary;
}
static VALUE
-reject_i(VALUE i, VALUE ary)
+reject_i(i, ary)
+ VALUE i, ary;
{
if (!RTEST(rb_yield(i))) {
rb_ary_push(ary, i);
@@ -260,20 +180,19 @@ reject_i(VALUE i, VALUE ary)
*/
static VALUE
-enum_reject(VALUE obj)
+enum_reject(obj)
+ VALUE obj;
{
- VALUE ary;
+ VALUE ary = rb_ary_new();
- RETURN_ENUMERATOR(obj, 0, 0);
-
- ary = rb_ary_new();
- rb_block_call(obj, id_each, 0, 0, reject_i, ary);
+ rb_iterate(rb_each, obj, reject_i, ary);
return ary;
}
static VALUE
-collect_i(VALUE i, VALUE ary)
+collect_i(i, ary)
+ VALUE i, ary;
{
rb_ary_push(ary, rb_yield(i));
@@ -281,7 +200,8 @@ collect_i(VALUE i, VALUE ary)
}
static VALUE
-collect_all(VALUE i, VALUE ary)
+collect_all(i, ary)
+ VALUE i, ary;
{
rb_ary_push(ary, i);
@@ -302,14 +222,12 @@ collect_all(VALUE i, VALUE ary)
*/
static VALUE
-enum_collect(VALUE obj)
+enum_collect(obj)
+ VALUE obj;
{
- VALUE ary;
-
- RETURN_ENUMERATOR(obj, 0, 0);
+ VALUE ary = rb_ary_new();
- ary = rb_ary_new();
- rb_block_call(obj, id_each, 0, 0, collect_i, ary);
+ rb_iterate(rb_each, obj, rb_block_given_p() ? collect_i : collect_all, ary);
return ary;
}
@@ -325,17 +243,20 @@ enum_collect(VALUE obj)
* { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]
*/
static VALUE
-enum_to_a(VALUE obj)
+enum_to_a(obj)
+ VALUE obj;
{
VALUE ary = rb_ary_new();
- rb_block_call(obj, id_each, 0, 0, collect_all, ary);
+ rb_iterate(rb_each, obj, collect_all, ary);
return ary;
}
static VALUE
-inject_i(VALUE i, VALUE *memo)
+inject_i(i, memo)
+ VALUE i;
+ VALUE *memo;
{
if (*memo == Qundef) {
*memo = i;
@@ -378,19 +299,22 @@ inject_i(VALUE i, VALUE *memo)
*/
static VALUE
-enum_inject(int argc, VALUE *argv, VALUE obj)
+enum_inject(argc, argv, obj)
+ int argc;
+ VALUE *argv, obj;
{
VALUE memo = Qundef;
if (rb_scan_args(argc, argv, "01", &memo) == 0)
memo = Qundef;
- rb_block_call(obj, id_each, 0, 0, inject_i, (VALUE)&memo);
+ rb_iterate(rb_each, obj, inject_i, (VALUE)&memo);
if (memo == Qundef) return Qnil;
return memo;
}
static VALUE
-partition_i(VALUE i, VALUE *ary)
+partition_i(i, ary)
+ VALUE i, *ary;
{
if (RTEST(rb_yield(i))) {
rb_ary_push(ary[0], i);
@@ -414,111 +338,18 @@ partition_i(VALUE i, VALUE *ary)
*/
static VALUE
-enum_partition(VALUE obj)
+enum_partition(obj)
+ VALUE obj;
{
VALUE ary[2];
- RETURN_ENUMERATOR(obj, 0, 0);
-
ary[0] = rb_ary_new();
ary[1] = rb_ary_new();
- rb_block_call(obj, id_each, 0, 0, partition_i, (VALUE)ary);
+ rb_iterate(rb_each, obj, partition_i, (VALUE)ary);
return rb_assoc_new(ary[0], ary[1]);
}
-static VALUE
-group_by_i(VALUE i, VALUE hash)
-{
- VALUE group = rb_yield(i);
- VALUE values;
-
- values = rb_hash_aref(hash, group);
- if (NIL_P(values)) {
- values = rb_ary_new3(1, i);
- rb_hash_aset(hash, group, values);
- }
- else {
- rb_ary_push(values, i);
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.group_by {| obj | block } => a_hash
- *
- * Returns a hash, which keys are evaluated result from the
- * block, and values are arrays of elements in <i>enum</i>
- * corresponding to the key.
- *
- * (1..6).group_by {|i| i%3} #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}
- *
- */
-
-static VALUE
-enum_group_by(VALUE obj)
-{
- VALUE hash;
-
- RETURN_ENUMERATOR(obj, 0, 0);
-
- hash = rb_hash_new();
- rb_block_call(obj, id_each, 0, 0, group_by_i, hash);
-
- return hash;
-}
-
-static VALUE
-first_i(VALUE i, VALUE *ary)
-{
- if (NIL_P(ary[0])) {
- ary[1] = i;
- rb_iter_break();
- }
- else {
- long n = NUM2LONG(ary[0]);
-
- if (n <= 0) {
- rb_iter_break();
- }
- rb_ary_push(ary[1], i);
- n--;
- ary[0] = INT2NUM(n);
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.first -> obj or nil
- * enum.first(n) -> an_array
- *
- * Returns the first element, or the first +n+ elements, of the enumerable.
- * If the enumerable is empty, the first form returns <code>nil</code>, and the
- * second form returns an empty array.
- *
- */
-
-static VALUE
-enum_first(int argc, VALUE *argv, VALUE obj)
-{
- VALUE n, ary[2];
-
- rb_scan_args(argc, argv, "01", &n);
-
- if (NIL_P(n)) {
- ary[0] = ary[1] = Qnil;
- }
- else {
- ary[0] = n;
- ary[1] = rb_ary_new2(NUM2LONG(n));
- }
- rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)ary);
-
- return ary[1];
-}
-
/*
* call-seq:
* enum.sort => array
@@ -537,13 +368,15 @@ enum_first(int argc, VALUE *argv, VALUE obj)
*/
static VALUE
-enum_sort(VALUE obj)
+enum_sort(obj)
+ VALUE obj;
{
return rb_ary_sort(enum_to_a(obj));
}
static VALUE
-sort_by_i(VALUE i, VALUE ary)
+sort_by_i(i, ary)
+ VALUE i, ary;
{
VALUE v;
NODE *memo;
@@ -558,10 +391,11 @@ sort_by_i(VALUE i, VALUE ary)
}
static int
-sort_by_cmp(const void *ap, const void *bp, void *data)
+sort_by_cmp(aa, bb)
+ NODE **aa, **bb;
{
- VALUE a = (*(NODE *const *)ap)->u1.value;
- VALUE b = (*(NODE *const *)bp)->u1.value;
+ VALUE a = aa[0]->u1.value;
+ VALUE b = bb[0]->u1.value;
return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b);
}
@@ -574,7 +408,7 @@ sort_by_cmp(const void *ap, const void *bp, void *data)
* values in <i>enum</i> through the given block.
*
* %w{ apple pear fig }.sort_by {|word| word.length}
- #=> ["fig", "pear", "apple"]
+ #=> ["fig", "pear", "apple"]
*
* The current implementation of <code>sort_by</code> generates an
* array of tuples containing the original collection element and the
@@ -636,36 +470,37 @@ sort_by_cmp(const void *ap, const void *bp, void *data)
*/
static VALUE
-enum_sort_by(VALUE obj)
+enum_sort_by(obj)
+ VALUE obj;
{
VALUE ary;
long i;
- RETURN_ENUMERATOR(obj, 0, 0);
-
if (TYPE(obj) == T_ARRAY) {
- ary = rb_ary_new2(RARRAY_LEN(obj));
+ ary = rb_ary_new2(RARRAY(obj)->len);
}
else {
ary = rb_ary_new();
}
RBASIC(ary)->klass = 0;
- rb_block_call(obj, id_each, 0, 0, sort_by_i, ary);
- if (RARRAY_LEN(ary) > 1) {
- ruby_qsort(RARRAY_PTR(ary), RARRAY_LEN(ary), sizeof(VALUE), sort_by_cmp, 0);
+ rb_iterate(rb_each, obj, sort_by_i, ary);
+ if (RARRAY(ary)->len > 1) {
+ qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), sort_by_cmp, 0);
}
if (RBASIC(ary)->klass) {
rb_raise(rb_eRuntimeError, "sort_by reentered");
}
- for (i=0; i<RARRAY_LEN(ary); i++) {
- RARRAY_PTR(ary)[i] = RNODE(RARRAY_PTR(ary)[i])->u2.value;
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ RARRAY(ary)->ptr[i] = RNODE(RARRAY(ary)->ptr[i])->u2.value;
}
RBASIC(ary)->klass = rb_cArray;
return ary;
}
static VALUE
-all_iter_i(VALUE i, VALUE *memo)
+all_iter_i(i, memo)
+ VALUE i;
+ VALUE *memo;
{
if (!RTEST(rb_yield(i))) {
*memo = Qfalse;
@@ -675,7 +510,9 @@ all_iter_i(VALUE i, VALUE *memo)
}
static VALUE
-all_i(VALUE i, VALUE *memo)
+all_i(i, memo)
+ VALUE i;
+ VALUE *memo;
{
if (!RTEST(i)) {
*memo = Qfalse;
@@ -695,23 +532,26 @@ all_i(VALUE i, VALUE *memo)
* <code>all?</code> will return <code>true</code> only if none of the
* collection members are <code>false</code> or <code>nil</code>.)
*
- * %w{ant bear cat}.all? {|word| word.length >= 3} #=> true
- * %w{ant bear cat}.all? {|word| word.length >= 4} #=> false
- * [ nil, true, 99 ].all? #=> false
+ * %w{ ant bear cat}.all? {|word| word.length >= 3} #=> true
+ * %w{ ant bear cat}.all? {|word| word.length >= 4} #=> false
+ * [ nil, true, 99 ].all? #=> false
*
*/
static VALUE
-enum_all(VALUE obj)
+enum_all(obj)
+ VALUE obj;
{
VALUE result = Qtrue;
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? all_iter_i : all_i, (VALUE)&result);
+ rb_iterate(rb_each, obj, rb_block_given_p() ? all_iter_i : all_i, (VALUE)&result);
return result;
}
static VALUE
-any_iter_i(VALUE i, VALUE *memo)
+any_iter_i(i, memo)
+ VALUE i;
+ VALUE *memo;
{
if (RTEST(rb_yield(i))) {
*memo = Qtrue;
@@ -721,7 +561,9 @@ any_iter_i(VALUE i, VALUE *memo)
}
static VALUE
-any_i(VALUE i, VALUE *memo)
+any_i(i, memo)
+ VALUE i;
+ VALUE *memo;
{
if (RTEST(i)) {
*memo = Qtrue;
@@ -742,121 +584,26 @@ any_i(VALUE i, VALUE *memo)
* of the collection members is not <code>false</code> or
* <code>nil</code>.
*
- * %w{ant bear cat}.any? {|word| word.length >= 3} #=> true
- * %w{ant bear cat}.any? {|word| word.length >= 4} #=> true
- * [ nil, true, 99 ].any? #=> true
+ * %w{ ant bear cat}.any? {|word| word.length >= 3} #=> true
+ * %w{ ant bear cat}.any? {|word| word.length >= 4} #=> true
+ * [ nil, true, 99 ].any? #=> true
*
*/
static VALUE
-enum_any(VALUE obj)
+enum_any(obj)
+ VALUE obj;
{
VALUE result = Qfalse;
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? any_iter_i : any_i, (VALUE)&result);
+ rb_iterate(rb_each, obj, rb_block_given_p() ? any_iter_i : any_i, (VALUE)&result);
return result;
}
static VALUE
-one_iter_i(VALUE i, VALUE *memo)
-{
- if (RTEST(rb_yield(i))) {
- if (*memo == Qundef) {
- *memo = Qtrue;
- }
- else if (*memo == Qtrue) {
- *memo = Qfalse;
- }
- }
- return Qnil;
-}
-
-static VALUE
-one_i(VALUE i, VALUE *memo)
-{
- if (RTEST(i)) {
- if (*memo == Qundef) {
- *memo = Qtrue;
- }
- else if (*memo == Qtrue) {
- *memo = Qfalse;
- }
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.one? [{|obj| block }] => true or false
- *
- * Passes each element of the collection to the given block. The method
- * returns <code>true</code> if the block returns <code>true</code>
- * exactly once. If the block is not given, <code>one?</code> will return
- * <code>true</code> only if exactly one of the collection members are
- * true.
- *
- * %w{ant bear cat}.one? {|word| word.length == 4} #=> true
- * %w{ant bear cat}.one? {|word| word.length >= 4} #=> false
- * [ nil, true, 99 ].one? #=> true
- *
- */
-
-static VALUE
-enum_one(VALUE obj)
-{
- VALUE result = Qundef;
-
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? one_iter_i : one_i, (VALUE)&result);
- if (result == Qundef) return Qfalse;
- return result;
-}
-
-static VALUE
-none_iter_i(VALUE i, VALUE *memo)
-{
- if (RTEST(rb_yield(i))) {
- *memo = Qfalse;
- rb_iter_break();
- }
- return Qnil;
-}
-
-static VALUE
-none_i(VALUE i, VALUE *memo)
-{
- if (RTEST(i)) {
- *memo = Qfalse;
- rb_iter_break();
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.none? [{|obj| block }] => true or false
- *
- * Passes each element of the collection to the given block. The method
- * returns <code>true</code> if the block never returns <code>true</code>
- * for all elements. If the block is not given, <code>one?</code> will return
- * <code>true</code> only if any of the collection members is true.
- *
- * %w{ant bear cat}.one? {|word| word.length == 4} #=> true
- * %w{ant bear cat}.one? {|word| word.length >= 4} #=> false
- * [ nil, true, 99 ].one? #=> true
- *
- */
-
-static VALUE
-enum_none(VALUE obj)
-{
- VALUE result = Qtrue;
-
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? none_iter_i : none_i, (VALUE)&result);
- return result;
-}
-
-static VALUE
-min_i(VALUE i, VALUE *memo)
+min_i(i, memo)
+ VALUE i;
+ VALUE *memo;
{
VALUE cmp;
@@ -873,7 +620,9 @@ min_i(VALUE i, VALUE *memo)
}
static VALUE
-min_ii(VALUE i, VALUE *memo)
+min_ii(i, memo)
+ VALUE i;
+ VALUE *memo;
{
VALUE cmp;
@@ -905,17 +654,34 @@ min_ii(VALUE i, VALUE *memo)
*/
static VALUE
-enum_min(VALUE obj)
+enum_min(obj)
+ VALUE obj;
{
VALUE result = Qundef;
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? min_ii : min_i, (VALUE)&result);
+ rb_iterate(rb_each, obj, rb_block_given_p() ? min_ii : min_i, (VALUE)&result);
if (result == Qundef) return Qnil;
return result;
}
+/*
+ * call-seq:
+ * enum.max => obj
+ * enum.max {| a,b | block } => obj
+ *
+ * Returns the object in <i>enum</i> with the maximum value. The
+ * first form assumes all objects implement <code>Comparable</code>;
+ * the second uses the block to return <em>a <=> b</em>.
+ *
+ * a = %w(albatross dog horse)
+ * a.max #=> "horse"
+ * a.max {|a,b| a.length <=> b.length } #=> "albatross"
+ */
+
static VALUE
-max_i(VALUE i, VALUE *memo)
+max_i(i, memo)
+ VALUE i;
+ VALUE *memo;
{
VALUE cmp;
@@ -932,7 +698,9 @@ max_i(VALUE i, VALUE *memo)
}
static VALUE
-max_ii(VALUE i, VALUE *memo)
+max_ii(i, memo)
+ VALUE i;
+ VALUE *memo;
{
VALUE cmp;
@@ -963,99 +731,20 @@ max_ii(VALUE i, VALUE *memo)
*/
static VALUE
-enum_max(VALUE obj)
+enum_max(obj)
+ VALUE obj;
{
VALUE result = Qundef;
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? max_ii : max_i, (VALUE)&result);
+ rb_iterate(rb_each, obj, rb_block_given_p() ? max_ii : max_i, (VALUE)&result);
if (result == Qundef) return Qnil;
return result;
}
static VALUE
-min_by_i(VALUE i, VALUE *memo)
-{
- VALUE v;
-
- v = rb_yield(i);
- if (memo[0] == Qundef) {
- memo[0] = v;
- memo[1] = i;
- }
- else if (rb_cmpint(rb_funcall(v, id_cmp, 1, memo[0]), v, memo[0]) < 0) {
- memo[0] = v;
- memo[1] = i;
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.min_by {| obj| block } => obj
- *
- * Returns the object in <i>enum</i> that gives the minimum
- * value from the given block.
- *
- * a = %w(albatross dog horse)
- * a.min_by {|x| x.length } #=> "dog"
- */
-
-static VALUE
-enum_min_by(VALUE obj)
-{
- VALUE memo[2];
-
- RETURN_ENUMERATOR(obj, 0, 0);
-
- memo[0] = Qundef;
- memo[1] = Qnil;
- rb_block_call(obj, id_each, 0, 0, min_by_i, (VALUE)memo);
- return memo[1];
-}
-
-static VALUE
-max_by_i(VALUE i, VALUE *memo)
-{
- VALUE v;
-
- v = rb_yield(i);
- if (memo[0] == Qundef) {
- memo[0] = v;
- memo[1] = i;
- }
- else if (rb_cmpint(rb_funcall(v, id_cmp, 1, memo[0]), v, memo[0]) > 0) {
- memo[0] = v;
- memo[1] = i;
- }
- return Qnil;
-}
-
-/*
- * call-seq:
- * enum.max_by {| obj| block } => obj
- *
- * Returns the object in <i>enum</i> that gives the maximum
- * value from the given block.
- *
- * a = %w(albatross dog horse)
- * a.max_by {|x| x.length } #=> "albatross"
- */
-
-static VALUE
-enum_max_by(VALUE obj)
-{
- VALUE memo[2];
-
- RETURN_ENUMERATOR(obj, 0, 0);
-
- memo[0] = Qundef;
- memo[1] = Qnil;
- rb_block_call(obj, id_each, 0, 0, max_by_i, (VALUE)memo);
- return memo[1];
-}
-
-static VALUE
-member_i(VALUE item, VALUE *memo)
+member_i(item, memo)
+ VALUE item;
+ VALUE *memo;
{
if (rb_equal(item, memo[0])) {
memo[1] = Qtrue;
@@ -1078,18 +767,21 @@ member_i(VALUE item, VALUE *memo)
*/
static VALUE
-enum_member(VALUE obj, VALUE val)
+enum_member(obj, val)
+ VALUE obj, val;
{
VALUE memo[2];
memo[0] = val;
memo[1] = Qfalse;
- rb_block_call(obj, id_each, 0, 0, member_i, (VALUE)memo);
+ rb_iterate(rb_each, obj, member_i, (VALUE)memo);
return memo[1];
}
static VALUE
-each_with_index_i(VALUE val, VALUE *memo)
+each_with_index_i(val, memo)
+ VALUE val;
+ VALUE *memo;
{
rb_yield_values(2, val, INT2FIX(*memo));
++*memo;
@@ -1112,18 +804,20 @@ each_with_index_i(VALUE val, VALUE *memo)
*/
static VALUE
-enum_each_with_index(VALUE obj)
+enum_each_with_index(obj)
+ VALUE obj;
{
VALUE memo = 0;
- RETURN_ENUMERATOR(obj, 0, 0);
-
- rb_block_call(obj, id_each, 0, 0, each_with_index_i, (VALUE)&memo);
+ rb_need_block();
+ rb_iterate(rb_each, obj, each_with_index_i, (VALUE)&memo);
return obj;
}
static VALUE
-zip_i(VALUE val, VALUE *memo)
+zip_i(val, memo)
+ VALUE val;
+ VALUE *memo;
{
VALUE result = memo[0];
VALUE args = memo[1];
@@ -1131,10 +825,10 @@ zip_i(VALUE val, VALUE *memo)
VALUE tmp;
int i;
- tmp = rb_ary_new2(RARRAY_LEN(args) + 1);
+ tmp = rb_ary_new2(RARRAY(args)->len + 1);
rb_ary_store(tmp, 0, val);
- for (i=0; i<RARRAY_LEN(args); i++) {
- rb_ary_push(tmp, rb_ary_entry(RARRAY_PTR(args)[i], idx));
+ for (i=0; i<RARRAY(args)->len; i++) {
+ rb_ary_push(tmp, rb_ary_entry(RARRAY(args)->ptr[i], idx));
}
if (rb_block_given_p()) {
rb_yield(tmp);
@@ -1169,7 +863,10 @@ zip_i(VALUE val, VALUE *memo)
*/
static VALUE
-enum_zip(int argc, VALUE *argv, VALUE obj)
+enum_zip(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
int i;
VALUE result;
@@ -1178,12 +875,11 @@ enum_zip(int argc, VALUE *argv, VALUE obj)
for (i=0; i<argc; i++) {
argv[i] = rb_convert_type(argv[i], T_ARRAY, "Array", "to_a");
}
- RETURN_ENUMERATOR(obj, argc, argv);
result = rb_block_given_p() ? Qnil : rb_ary_new();
memo[0] = result;
memo[1] = rb_ary_new4(argc, argv);
memo[2] = 0;
- rb_block_call(obj, id_each, 0, 0, zip_i, (VALUE)memo);
+ rb_iterate(rb_each, obj, zip_i, (VALUE)memo);
return result;
}
@@ -1200,7 +896,7 @@ enum_zip(int argc, VALUE *argv, VALUE obj)
*/
void
-Init_Enumerable(void)
+Init_Enumerable()
{
rb_mEnumerable = rb_define_module("Enumerable");
@@ -1210,10 +906,8 @@ Init_Enumerable(void)
rb_define_method(rb_mEnumerable,"sort", enum_sort, 0);
rb_define_method(rb_mEnumerable,"sort_by", enum_sort_by, 0);
rb_define_method(rb_mEnumerable,"grep", enum_grep, 1);
- rb_define_method(rb_mEnumerable,"count", enum_count, -1);
rb_define_method(rb_mEnumerable,"find", enum_find, -1);
rb_define_method(rb_mEnumerable,"detect", enum_find, -1);
- rb_define_method(rb_mEnumerable,"find_index", enum_find_index, 0);
rb_define_method(rb_mEnumerable,"find_all", enum_find_all, 0);
rb_define_method(rb_mEnumerable,"select", enum_find_all, 0);
rb_define_method(rb_mEnumerable,"reject", enum_reject, 0);
@@ -1221,16 +915,10 @@ Init_Enumerable(void)
rb_define_method(rb_mEnumerable,"map", enum_collect, 0);
rb_define_method(rb_mEnumerable,"inject", enum_inject, -1);
rb_define_method(rb_mEnumerable,"partition", enum_partition, 0);
- rb_define_method(rb_mEnumerable,"group_by", enum_group_by, 0);
- rb_define_method(rb_mEnumerable,"first", enum_first, -1);
rb_define_method(rb_mEnumerable,"all?", enum_all, 0);
rb_define_method(rb_mEnumerable,"any?", enum_any, 0);
- rb_define_method(rb_mEnumerable,"one?", enum_one, 0);
- rb_define_method(rb_mEnumerable,"none?", enum_none, 0);
rb_define_method(rb_mEnumerable,"min", enum_min, 0);
rb_define_method(rb_mEnumerable,"max", enum_max, 0);
- rb_define_method(rb_mEnumerable,"min_by", enum_min_by, 0);
- rb_define_method(rb_mEnumerable,"max_by", enum_max_by, 0);
rb_define_method(rb_mEnumerable,"member?", enum_member, 1);
rb_define_method(rb_mEnumerable,"include?", enum_member, 1);
rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, 0);
diff --git a/enumerator.c b/enumerator.c
deleted file mode 100644
index 3f176a77a9..0000000000
--- a/enumerator.c
+++ /dev/null
@@ -1,364 +0,0 @@
-/************************************************
-
- enumerator.c - provides Enumerator class
-
- $Author$
-
- Copyright (C) 2001-2003 Akinori MUSHA
-
- $Idaemons: /home/cvs/rb/enumerator/enumerator.c,v 1.1.1.1 2001/07/15 10:12:48 knu Exp $
- $RoughId: enumerator.c,v 1.6 2003/07/27 11:03:24 nobu Exp $
- $Id$
-
-************************************************/
-
-#include "ruby.h"
-
-/*
- * Document-class: Enumerable::Enumerator
- *
- * A class which provides a method `each' to be used as an Enumerable
- * object.
- */
-static VALUE rb_cEnumerator;
-static VALUE sym_each, sym_each_with_index, sym_each_slice, sym_each_cons;
-
-static VALUE
-proc_call(VALUE proc, VALUE args)
-{
- if (TYPE(args) != T_ARRAY) {
- args = rb_ary_new3(1, args);
- }
- return rb_proc_call(proc, args);
-}
-
-struct enumerator {
- VALUE method;
- VALUE proc;
- VALUE args;
- VALUE (*iter)(VALUE, struct enumerator *);
-};
-
-static void
-enumerator_mark(void *p)
-{
- struct enumerator *ptr = p;
- rb_gc_mark(ptr->method);
- rb_gc_mark(ptr->proc);
- rb_gc_mark(ptr->args);
-}
-
-static struct enumerator *
-enumerator_ptr(VALUE obj)
-{
- struct enumerator *ptr;
-
- Data_Get_Struct(obj, struct enumerator, ptr);
- if (RDATA(obj)->dmark != enumerator_mark) {
- rb_raise(rb_eTypeError,
- "wrong argument type %s (expected Enumerable::Enumerator)",
- rb_obj_classname(obj));
- }
- if (!ptr) {
- rb_raise(rb_eArgError, "uninitialized enumerator");
- }
- return ptr;
-}
-
-static VALUE
-enumerator_iter_i(VALUE i, struct enumerator *e)
-{
- return rb_yield(proc_call(e->proc, i));
-}
-
-/*
- * call-seq:
- * obj.to_enum(method = :each, *args)
- * obj.enum_for(method = :each, *args)
- *
- * Returns Enumerable::Enumerator.new(self, method, *args).
- *
- * e.g.:
- * str = "xyz"
- *
- * enum = str.enum_for(:each_byte)
- * a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
- *
- * # protects an array from being modified
- * a = [1, 2, 3]
- * some_method(a.to_enum)
- *
- */
-static VALUE
-obj_to_enum(int argc, VALUE *argv, VALUE obj)
-{
- VALUE meth = sym_each;
-
- if (argc > 0) {
- --argc;
- meth = *argv++;
- }
- return rb_enumeratorize(obj, meth, argc, argv);
-}
-
-static VALUE
-each_slice_i(VALUE val, VALUE *memo)
-{
- VALUE ary = memo[0];
- VALUE v = Qnil;
- long size = (long)memo[1];
-
- rb_ary_push(ary, val);
-
- if (RARRAY_LEN(ary) == size) {
- v = rb_yield(ary);
- memo[0] = rb_ary_new2(size);
- }
-
- return v;
-}
-
-/*
- * call-seq:
- * e.each_slice(n) {...}
- *
- * Iterates the given block for each slice of <n> elements.
- *
- * e.g.:
- * (1..10).each_slice(3) {|a| p a}
- * # outputs below
- * [1, 2, 3]
- * [4, 5, 6]
- * [7, 8, 9]
- * [10]
- *
- */
-static VALUE
-enum_each_slice(VALUE obj, VALUE n)
-{
- long size = NUM2LONG(n);
- VALUE args[2], ary;
-
- if (size <= 0) rb_raise(rb_eArgError, "invalid slice size");
- RETURN_ENUMERATOR(obj, 1, &n);
- args[0] = rb_ary_new2(size);
- args[1] = (VALUE)size;
-
- rb_block_call(obj, rb_intern("each"), 0, 0, each_slice_i, (VALUE)args);
-
- ary = args[0];
- if (RARRAY_LEN(ary) > 0) rb_yield(ary);
-
- return Qnil;
-}
-
-static VALUE
-each_cons_i(VALUE val, VALUE *memo)
-{
- VALUE ary = memo[0];
- VALUE v = Qnil;
- long size = (long)memo[1];
-
- if (RARRAY_LEN(ary) == size) {
- rb_ary_shift(ary);
- }
- rb_ary_push(ary, val);
- if (RARRAY_LEN(ary) == size) {
- v = rb_yield(rb_ary_dup(ary));
- }
- return v;
-}
-
-/*
- * call-seq:
- * each_cons(n) {...}
- *
- * Iterates the given block for each array of consecutive <n>
- * elements.
- *
- * e.g.:
- * (1..10).each_cons(3) {|a| p a}
- * # outputs below
- * [1, 2, 3]
- * [2, 3, 4]
- * [3, 4, 5]
- * [4, 5, 6]
- * [5, 6, 7]
- * [6, 7, 8]
- * [7, 8, 9]
- * [8, 9, 10]
- *
- */
-static VALUE
-enum_each_cons(VALUE obj, VALUE n)
-{
- long size = NUM2LONG(n);
- VALUE args[2];
-
- if (size <= 0) rb_raise(rb_eArgError, "invalid size");
- RETURN_ENUMERATOR(obj, 1, &n);
- args[0] = rb_ary_new2(size);
- args[1] = (VALUE)size;
-
- rb_block_call(obj, rb_intern("each"), 0, 0, each_cons_i, (VALUE)args);
-
- return Qnil;
-}
-
-static VALUE
-enumerator_allocate(VALUE klass)
-{
- struct enumerator *ptr;
- return Data_Make_Struct(klass, struct enumerator,
- enumerator_mark, -1, ptr);
-}
-
-static VALUE
-enumerator_init(VALUE enum_obj, VALUE obj, VALUE meth, int argc, VALUE *argv)
-{
- struct enumerator *ptr = enumerator_ptr(enum_obj);
-
- ptr->method = rb_obj_method(obj, meth);
- if (rb_block_given_p()) {
- ptr->proc = rb_block_proc();
- ptr->iter = enumerator_iter_i;
- }
- else {
- ptr->iter = (VALUE (*)(VALUE, struct enumerator *))rb_yield;
- }
- if (argc) ptr->args = rb_ary_new4(argc, argv);
-
- return enum_obj;
-}
-
-/*
- * call-seq:
- * Enumerable::Enumerator.new(obj, method = :each, *args)
- *
- * Creates a new Enumerable::Enumerator object, which is to be
- * used as an Enumerable object using the given object's given
- * method with the given arguments.
- *
- * e.g.:
- * str = "xyz"
- *
- * enum = Enumerable::Enumerator.new(str, :each_byte)
- * a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
- *
- */
-static VALUE
-enumerator_initialize(int argc, VALUE *argv, VALUE obj)
-{
- VALUE recv, meth = sym_each;
-
- if (argc == 0)
- rb_raise(rb_eArgError, "wrong number of argument (0 for 1)");
- recv = *argv++;
- if (--argc) {
- meth = *argv++;
- --argc;
- }
- return enumerator_init(obj, recv, meth, argc, argv);
-}
-
-VALUE
-rb_enumeratorize(VALUE obj, VALUE meth, int argc, VALUE *argv)
-{
- return enumerator_init(enumerator_allocate(rb_cEnumerator), obj, meth, argc, argv);
-}
-
-/*
- * call-seq:
- * enum.each {...}
- *
- * Iterates the given block using the object and the method specified
- * in the first place.
- *
- */
-static VALUE
-enumerator_each(VALUE obj)
-{
- struct enumerator *e;
- int argc = 0;
- VALUE *argv = 0;
-
- if (!rb_block_given_p()) return obj;
- e = enumerator_ptr(obj);
- if (e->args) {
- argc = RARRAY_LEN(e->args);
- argv = RARRAY_PTR(e->args);
- }
- return rb_block_call(e->method, rb_intern("call"), argc, argv, e->iter, (VALUE)e);
-}
-
-static VALUE
-enumerator_with_index_i(VALUE val, VALUE *memo)
-{
- val = rb_yield_values(2, val, INT2FIX(*memo));
- ++*memo;
- return val;
-}
-
-/*
- * call-seq:
- * e.with_index {|(*args), idx| ... }
- *
- * Iterates the given block for each elements with an index, which
- * start from 0.
- *
- */
-static VALUE
-enumerator_with_index(VALUE obj)
-{
- struct enumerator *e = enumerator_ptr(obj);
- VALUE memo = 0;
- int argc = 0;
- VALUE *argv = 0;
-
-/* RETURN_ENUMERATOR(obj, 0, 0); ?? */
- if (e->args) {
- argc = RARRAY_LEN(e->args);
- argv = RARRAY_PTR(e->args);
- }
- return rb_block_call(e->method, rb_intern("call"), argc, argv,
- enumerator_with_index_i, (VALUE)&memo);
-}
-
-/*
- * call-seq:
- * e.to_splat => array
- *
- * Convert this enumerator object to an array to splat.
- */
-
-static VALUE
-enumerator_to_splat(VALUE range)
-{
- return rb_convert_type(range, T_ARRAY, "Array", "to_a");
-}
-
-void
-Init_Enumerator(void)
-{
- rb_define_method(rb_mKernel, "to_enum", obj_to_enum, -1);
- rb_define_method(rb_mKernel, "enum_for", obj_to_enum, -1);
-
- rb_define_method(rb_mEnumerable, "each_slice", enum_each_slice, 1);
- rb_define_method(rb_mEnumerable, "each_cons", enum_each_cons, 1);
-
- rb_cEnumerator = rb_define_class_under(rb_mEnumerable, "Enumerator", rb_cObject);
- rb_include_module(rb_cEnumerator, rb_mEnumerable);
-
- rb_define_alloc_func(rb_cEnumerator, enumerator_allocate);
- rb_define_method(rb_cEnumerator, "initialize", enumerator_initialize, -1);
- rb_define_method(rb_cEnumerator, "each", enumerator_each, 0);
- rb_define_method(rb_cEnumerator, "with_index", enumerator_with_index, 0);
- rb_define_method(rb_cEnumerator, "to_splat", enumerator_to_splat, 0);
-
- sym_each = ID2SYM(rb_intern("each"));
- sym_each_with_index = ID2SYM(rb_intern("each_with_index"));
- sym_each_slice = ID2SYM(rb_intern("each_slice"));
- sym_each_cons = ID2SYM(rb_intern("each_cons"));
-
- rb_provide("enumerator.so"); /* for backward compatibility */
-}
diff --git a/env.h b/env.h
index c6b079d301..c50103f71e 100644
--- a/env.h
+++ b/env.h
@@ -13,26 +13,26 @@
#ifndef ENV_H
#define ENV_H
-RUBY_EXTERN struct FRAME {
+extern struct FRAME {
VALUE self;
int argc;
- ID callee;
- ID this_func;
- VALUE this_class;
+ ID last_func;
+ ID orig_func;
+ VALUE last_class;
struct FRAME *prev;
struct FRAME *tmp;
struct RNode *node;
- struct BLOCK *block;
+ int iter;
int flags;
unsigned long uniq;
} *ruby_frame;
-void rb_gc_mark_frame(struct FRAME *);
+void rb_gc_mark_frame _((struct FRAME *));
#define FRAME_DMETH 1
#define FRAME_FUNC 2
-RUBY_EXTERN struct SCOPE {
+extern struct SCOPE {
struct RBasic super;
ID *local_tbl;
VALUE *local_vars;
@@ -43,10 +43,11 @@ RUBY_EXTERN struct SCOPE {
#define SCOPE_MALLOC 1
#define SCOPE_NOSTACK 2
#define SCOPE_DONT_RECYCLE 4
+#define SCOPE_CLONE 8
-RUBY_EXTERN int ruby_in_eval;
-VALUE ruby_current_class_object(void);
-#define ruby_class ruby_current_class_object()
+extern int ruby_in_eval;
+
+extern VALUE ruby_class;
struct RVarmap {
struct RBasic super;
@@ -54,37 +55,6 @@ struct RVarmap {
VALUE val;
struct RVarmap *next;
};
-RUBY_EXTERN struct RVarmap *ruby_dyna_vars;
-
-struct METHOD {
- VALUE klass, rklass;
- VALUE recv;
- ID id, oid;
- int safe_level;
- struct RNode *body;
-};
-
-struct BLOCK {
- struct RNode *var;
- struct RNode *body;
- VALUE self;
- struct FRAME frame;
- struct SCOPE *scope;
- VALUE klass;
- struct RNode *cref;
- int vmode;
- int flags;
- int uniq;
- struct RVarmap *dyna_vars;
- VALUE orig_thread;
- VALUE wrapper;
- VALUE block_obj;
-};
-
-#define BLOCK_D_SCOPE 1
-#define BLOCK_LAMBDA 2
-#define BLOCK_FROM_METHOD 4
-
-RUBY_EXTERN VALUE ruby_wrapper;
+extern struct RVarmap *ruby_dyna_vars;
#endif /* ENV_H */
diff --git a/error.c b/error.c
index 87ac7a7132..73d7934815 100644
--- a/error.c
+++ b/error.c
@@ -15,7 +15,13 @@
#include "st.h"
#include <stdio.h>
+#ifdef HAVE_STDARG_PROTOTYPES
#include <stdarg.h>
+#define va_init_list(a,b) va_start(a,b)
+#else
+#include <varargs.h>
+#define va_init_list(a,b) va_start(a)
+#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
@@ -28,7 +34,9 @@ extern const char ruby_version[], ruby_release_date[], ruby_platform[];
int ruby_nerrs;
static int
-err_position(char *buf, long len)
+err_position(buf, len)
+ char *buf;
+ long len;
{
ruby_set_current_source();
if (!ruby_sourcefile) {
@@ -43,7 +51,11 @@ err_position(char *buf, long len)
}
static void
-err_snprintf(char *buf, long len, const char *fmt, va_list args)
+err_snprintf(buf, len, fmt, args)
+ char *buf;
+ long len;
+ const char *fmt;
+ va_list args;
{
long n;
@@ -53,9 +65,11 @@ err_snprintf(char *buf, long len, const char *fmt, va_list args)
}
}
-static void err_append(const char*);
+static void err_append _((const char*));
static void
-err_print(const char *fmt, va_list args)
+err_print(fmt, args)
+ const char *fmt;
+ va_list args;
{
char buf[BUFSIZ];
@@ -64,30 +78,44 @@ err_print(const char *fmt, va_list args)
}
void
+#ifdef HAVE_STDARG_PROTOTYPES
rb_compile_error(const char *fmt, ...)
+#else
+rb_compile_error(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
{
va_list args;
- va_start(args, fmt);
+ va_init_list(args, fmt);
err_print(fmt, args);
va_end(args);
ruby_nerrs++;
}
void
+#ifdef HAVE_STDARG_PROTOTYPES
rb_compile_error_append(const char *fmt, ...)
+#else
+rb_compile_error_append(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
{
va_list args;
char buf[BUFSIZ];
- va_start(args, fmt);
+ va_init_list(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
err_append(buf);
}
static void
-warn_print(const char *fmt, va_list args)
+warn_print(fmt, args)
+ const char *fmt;
+ va_list args;
{
char buf[BUFSIZ];
int len;
@@ -99,7 +127,13 @@ warn_print(const char *fmt, va_list args)
}
void
+#ifdef HAVE_STDARG_PROTOTYPES
rb_warn(const char *fmt, ...)
+#else
+rb_warn(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
{
char buf[BUFSIZ];
va_list args;
@@ -108,14 +142,20 @@ rb_warn(const char *fmt, ...)
snprintf(buf, BUFSIZ, "warning: %s", fmt);
- va_start(args, fmt);
+ va_init_list(args, fmt);
warn_print(buf, args);
va_end(args);
}
/* rb_warning() reports only in verbose mode */
void
+#ifdef HAVE_STDARG_PROTOTYPES
rb_warning(const char *fmt, ...)
+#else
+rb_warning(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
{
char buf[BUFSIZ];
va_list args;
@@ -124,7 +164,7 @@ rb_warning(const char *fmt, ...)
snprintf(buf, BUFSIZ, "warning: %s", fmt);
- va_start(args, fmt);
+ va_init_list(args, fmt);
warn_print(buf, args);
va_end(args);
}
@@ -138,7 +178,8 @@ rb_warning(const char *fmt, ...)
*/
static VALUE
-rb_warn_m(VALUE self, VALUE mesg)
+rb_warn_m(self, mesg)
+ VALUE self, mesg;
{
if (!NIL_P(ruby_verbose)) {
rb_io_write(rb_stderr, mesg);
@@ -148,7 +189,13 @@ rb_warn_m(VALUE self, VALUE mesg)
}
void
+#ifdef HAVE_STDARG_PROTOTYPES
rb_bug(const char *fmt, ...)
+#else
+rb_bug(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
{
char buf[BUFSIZ];
va_list args;
@@ -158,7 +205,7 @@ rb_bug(const char *fmt, ...)
if (fwrite(buf, 1, len, out) == len ||
fwrite(buf, 1, len, (out = stdout)) == len) {
fputs("[BUG] ", out);
- va_start(args, fmt);
+ va_init_list(args, fmt);
vfprintf(out, fmt, args);
va_end(args);
fprintf(out, "\nruby %s (%s) [%s]\n\n",
@@ -198,7 +245,9 @@ static struct types {
};
void
-rb_check_type(VALUE x, int t)
+rb_check_type(x, t)
+ VALUE x;
+ int t;
{
struct types *type = builtin_types;
@@ -209,7 +258,7 @@ rb_check_type(VALUE x, int t)
if (TYPE(x) != t) {
while (type->type >= 0) {
if (type->type == t) {
- const char *etype;
+ char *etype;
if (NIL_P(x)) {
etype = "nil";
@@ -221,7 +270,7 @@ rb_check_type(VALUE x, int t)
etype = "Symbol";
}
else if (rb_special_const_p(x)) {
- etype = RSTRING_PTR(rb_obj_as_string(x));
+ etype = RSTRING(rb_obj_as_string(x))->ptr;
}
else {
etype = rb_obj_classname(x);
@@ -231,7 +280,7 @@ rb_check_type(VALUE x, int t)
}
type++;
}
- rb_bug("unknown type 0x%x (0x%x given)", t, TYPE(x));
+ rb_bug("unknown type 0x%x", t);
}
}
@@ -248,7 +297,6 @@ VALUE rb_eRuntimeError;
VALUE rb_eTypeError;
VALUE rb_eArgError;
VALUE rb_eIndexError;
-VALUE rb_eKeyError;
VALUE rb_eRangeError;
VALUE rb_eNameError;
VALUE rb_eNoMethodError;
@@ -263,22 +311,27 @@ VALUE rb_eLoadError;
VALUE rb_eSystemCallError;
VALUE rb_mErrno;
-static VALUE eNOERROR;
VALUE
-rb_exc_new(VALUE etype, const char *ptr, long len)
+rb_exc_new(etype, ptr, len)
+ VALUE etype;
+ const char *ptr;
+ long len;
{
return rb_funcall(etype, rb_intern("new"), 1, rb_str_new(ptr, len));
}
VALUE
-rb_exc_new2(VALUE etype, const char *s)
+rb_exc_new2(etype, s)
+ VALUE etype;
+ const char *s;
{
return rb_exc_new(etype, s, strlen(s));
}
VALUE
-rb_exc_new3(VALUE etype, VALUE str)
+rb_exc_new3(etype, str)
+ VALUE etype, str;
{
StringValue(str);
return rb_funcall(etype, rb_intern("new"), 1, str);
@@ -293,7 +346,10 @@ rb_exc_new3(VALUE etype, VALUE str)
*/
static VALUE
-exc_initialize(int argc, VALUE *argv, VALUE exc)
+exc_initialize(argc, argv, exc)
+ int argc;
+ VALUE *argv;
+ VALUE exc;
{
VALUE arg;
@@ -318,7 +374,10 @@ exc_initialize(int argc, VALUE *argv, VALUE exc)
*/
static VALUE
-exc_exception(int argc, VALUE *argv, VALUE self)
+exc_exception(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE exc;
@@ -339,7 +398,8 @@ exc_exception(int argc, VALUE *argv, VALUE self)
*/
static VALUE
-exc_to_s(VALUE exc)
+exc_to_s(exc)
+ VALUE exc;
{
VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
@@ -351,6 +411,7 @@ exc_to_s(VALUE exc)
/*
* call-seq:
* exception.message => string
+ * exception.to_str => string
*
* Returns the result of invoking <code>exception.to_s</code>.
* Normally this returns the exception's message or name. By
@@ -359,7 +420,8 @@ exc_to_s(VALUE exc)
*/
static VALUE
-exc_message(VALUE exc)
+exc_to_str(exc)
+ VALUE exc;
{
return rb_funcall(exc, rb_intern("to_s"), 0, 0);
}
@@ -372,13 +434,14 @@ exc_message(VALUE exc)
*/
static VALUE
-exc_inspect(VALUE exc)
+exc_inspect(exc)
+ VALUE exc;
{
VALUE str, klass;
klass = CLASS_OF(exc);
exc = rb_obj_as_string(exc);
- if (RSTRING_LEN(exc) == 0) {
+ if (RSTRING(exc)->len == 0) {
return rb_str_dup(rb_class_name(klass));
}
@@ -422,19 +485,21 @@ exc_inspect(VALUE exc)
*/
static VALUE
-exc_backtrace(VALUE exc)
+exc_backtrace(exc)
+ VALUE exc;
{
- ID bt = rb_intern("bt");
+ static ID bt;
- if (!rb_ivar_defined(exc, bt)) return Qnil;
- return rb_ivar_get(exc, bt);
+ if (!bt) bt = rb_intern("bt");
+ return rb_attr_get(exc, bt);
}
-static VALUE
-check_backtrace(VALUE bt)
+VALUE
+rb_check_backtrace(bt)
+ VALUE bt;
{
long i;
- static const char *err = "backtrace must be Array of String";
+ static char *err = "backtrace must be Array of String";
if (!NIL_P(bt)) {
int t = TYPE(bt);
@@ -443,8 +508,8 @@ check_backtrace(VALUE bt)
if (t != T_ARRAY) {
rb_raise(rb_eTypeError, err);
}
- for (i=0;i<RARRAY_LEN(bt);i++) {
- if (TYPE(RARRAY_PTR(bt)[i]) != T_STRING) {
+ for (i=0;i<RARRAY(bt)->len;i++) {
+ if (TYPE(RARRAY(bt)->ptr[i]) != T_STRING) {
rb_raise(rb_eTypeError, err);
}
}
@@ -463,33 +528,11 @@ check_backtrace(VALUE bt)
*/
static VALUE
-exc_set_backtrace(VALUE exc, VALUE bt)
-{
- return rb_iv_set(exc, "bt", check_backtrace(bt));
-}
-
-/*
- * call-seq:
- * exc == obj => true or false
- *
- * Equality---If <i>obj</i> is not an <code>Exception</code>, returns
- * <code>false</code>. Otherwise, returns <code>true</code> if <i>exc</i> and
- * <i>obj</i> share same class, messages, and backtrace.
- */
-
-static VALUE
-exc_equal(VALUE exc, VALUE obj)
+exc_set_backtrace(exc, bt)
+ VALUE exc;
+ VALUE bt;
{
- ID id_mesg = rb_intern("mesg");
-
- if (exc == obj) return Qtrue;
- if (rb_obj_class(exc) != rb_obj_class(obj))
- return Qfalse;
- if (!rb_equal(rb_attr_get(exc, id_mesg), rb_attr_get(obj, id_mesg)))
- return Qfalse;
- if (!rb_equal(exc_backtrace(exc), exc_backtrace(obj)))
- return Qfalse;
- return Qtrue;
+ return rb_iv_set(exc, "bt", rb_check_backtrace(bt));
}
/*
@@ -500,7 +543,10 @@ exc_equal(VALUE exc, VALUE obj)
*/
static VALUE
-exit_initialize(int argc, VALUE *argv, VALUE exc)
+exit_initialize(argc, argv, exc)
+ int argc;
+ VALUE *argv;
+ VALUE exc;
{
VALUE status = INT2FIX(EXIT_SUCCESS);
if (argc > 0 && FIXNUM_P(argv[0])) {
@@ -521,7 +567,8 @@ exit_initialize(int argc, VALUE *argv, VALUE exc)
*/
static VALUE
-exit_status(VALUE exc)
+exit_status(exc)
+ VALUE exc;
{
return rb_attr_get(exc, rb_intern("status"));
}
@@ -535,7 +582,8 @@ exit_status(VALUE exc)
*/
static VALUE
-exit_success_p(VALUE exc)
+exit_success_p(exc)
+ VALUE exc;
{
VALUE status = rb_attr_get(exc, rb_intern("status"));
if (NIL_P(status)) return Qtrue;
@@ -544,13 +592,20 @@ exit_success_p(VALUE exc)
}
void
+#ifdef HAVE_STDARG_PROTOTYPES
rb_name_error(ID id, const char *fmt, ...)
+#else
+rb_name_error(id, fmt, va_alist)
+ ID id;
+ const char *fmt;
+ va_dcl
+#endif
{
VALUE exc, argv[2];
va_list args;
char buf[BUFSIZ];
- va_start(args, fmt);
+ va_init_list(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
@@ -570,7 +625,10 @@ rb_name_error(ID id, const char *fmt, ...)
*/
static VALUE
-name_err_initialize(int argc, VALUE *argv, VALUE self)
+name_err_initialize(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE name;
@@ -588,7 +646,8 @@ name_err_initialize(int argc, VALUE *argv, VALUE self)
*/
static VALUE
-name_err_name(VALUE self)
+name_err_name(self)
+ VALUE self;
{
return rb_attr_get(self, rb_intern("name"));
}
@@ -601,10 +660,10 @@ name_err_name(VALUE self)
*/
static VALUE
-name_err_to_s(VALUE exc)
+name_err_to_s(exc)
+ VALUE exc;
{
- VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
- VALUE str = mesg;
+ VALUE mesg = rb_attr_get(exc, rb_intern("mesg")), str = mesg;
if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
StringValue(str);
@@ -626,7 +685,10 @@ name_err_to_s(VALUE exc)
*/
static VALUE
-nometh_err_initialize(int argc, VALUE *argv, VALUE self)
+nometh_err_initialize(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE args = (argc > 2) ? argv[--argc] : Qnil;
name_err_initialize(argc, argv, self);
@@ -636,14 +698,16 @@ nometh_err_initialize(int argc, VALUE *argv, VALUE self)
/* :nodoc: */
static void
-name_err_mesg_mark(VALUE *ptr)
+name_err_mesg_mark(ptr)
+ VALUE *ptr;
{
rb_gc_mark_locations(ptr, ptr+3);
}
/* :nodoc: */
static VALUE
-name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
+name_err_mesg_new(obj, mesg, recv, method)
+ VALUE obj, mesg, recv, method;
{
VALUE *ptr = ALLOC_N(VALUE, 3);
@@ -655,27 +719,8 @@ name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
/* :nodoc: */
static VALUE
-name_err_mesg_equal(VALUE obj1, VALUE obj2)
-{
- VALUE *ptr1, *ptr2;
- int i;
-
- if (obj1 == obj2) return Qtrue;
- if (rb_obj_class(obj2) != rb_cNameErrorMesg)
- return Qfalse;
-
- Data_Get_Struct(obj1, VALUE, ptr1);
- Data_Get_Struct(obj2, VALUE, ptr2);
- for (i=0; i<3; i++) {
- if (!rb_equal(ptr1[i], ptr2[i]))
- return Qfalse;
- }
- return Qtrue;
-}
-
-/* :nodoc: */
-static VALUE
-name_err_mesg_to_str(VALUE obj)
+name_err_mesg_to_str(obj)
+ VALUE obj;
{
VALUE *ptr, mesg;
Data_Get_Struct(obj, VALUE, ptr);
@@ -683,7 +728,7 @@ name_err_mesg_to_str(VALUE obj)
mesg = ptr[0];
if (NIL_P(mesg)) return Qnil;
else {
- const char *desc = 0;
+ char *desc = 0;
VALUE d = 0, args[3];
obj = ptr[1];
@@ -699,10 +744,10 @@ name_err_mesg_to_str(VALUE obj)
break;
default:
d = rb_protect(rb_inspect, obj, 0);
- if (NIL_P(d) || RSTRING_LEN(d) > 65) {
+ if (NIL_P(d) || RSTRING(d)->len > 65) {
d = rb_any_to_s(obj);
}
- desc = RSTRING_PTR(d);
+ desc = RSTRING(d)->ptr;
break;
}
if (desc && desc[0] != '#') {
@@ -721,7 +766,8 @@ name_err_mesg_to_str(VALUE obj)
/* :nodoc: */
static VALUE
-name_err_mesg_load(VALUE klass, VALUE str)
+name_err_mesg_load(klass, str)
+ VALUE klass, str;
{
return str;
}
@@ -735,17 +781,19 @@ name_err_mesg_load(VALUE klass, VALUE str)
*/
static VALUE
-nometh_err_args(VALUE self)
+nometh_err_args(self)
+ VALUE self;
{
return rb_attr_get(self, rb_intern("args"));
}
void
-rb_invalid_str(const char *str, const char *type)
+rb_invalid_str(str, type)
+ const char *str, *type;
{
VALUE s = rb_str_inspect(rb_str_new2(str));
- rb_raise(rb_eArgError, "invalid value for %s: %s", type, RSTRING_PTR(s));
+ rb_raise(rb_eArgError, "invalid value for %s: %s", type, RSTRING(s)->ptr);
}
/*
@@ -782,7 +830,9 @@ rb_invalid_str(const char *str, const char *type)
static st_table *syserr_tbl;
static VALUE
-set_syserr(int n, const char *name)
+set_syserr(n, name)
+ int n;
+ const char *name;
{
VALUE error;
@@ -798,7 +848,8 @@ set_syserr(int n, const char *name)
}
static VALUE
-get_syserr(int n)
+get_syserr(n)
+ int n;
{
VALUE error;
@@ -823,12 +874,15 @@ get_syserr(int n)
*/
static VALUE
-syserr_initialize(int argc, VALUE *argv, VALUE self)
+syserr_initialize(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
#if !defined(_WIN32) && !defined(__VMS)
char *strerror();
#endif
- const char *err;
+ char *err;
VALUE mesg, error;
VALUE klass = rb_obj_class(self);
@@ -853,10 +907,14 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
else err = "unknown error";
if (!NIL_P(mesg)) {
VALUE str = mesg;
+ size_t len;
StringValue(str);
- mesg = rb_sprintf("%s - %.*s", err,
- (int)RSTRING_LEN(str), RSTRING_PTR(str));
+ len = strlen(err)+RSTRING(str)->len+3;
+ mesg = rb_str_new(0, len);
+ snprintf(RSTRING(mesg)->ptr, len+1, "%s - %.*s", err,
+ (int)RSTRING(str)->len, RSTRING(str)->ptr);
+ rb_str_resize(mesg, strlen(RSTRING(mesg)->ptr));
}
else {
mesg = rb_str_new2(err);
@@ -874,7 +932,8 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
*/
static VALUE
-syserr_errno(VALUE self)
+syserr_errno(self)
+ VALUE self;
{
return rb_attr_get(self, rb_intern("errno"));
}
@@ -887,8 +946,10 @@ syserr_errno(VALUE self)
* if the error numbers _self_ and _other_ are the same.
*/
+
static VALUE
-syserr_eqq(VALUE self, VALUE exc)
+syserr_eqq(self, exc)
+ VALUE self, exc;
{
VALUE num, e;
@@ -911,18 +972,6 @@ syserr_eqq(VALUE self, VALUE exc)
}
/*
- * call-seq:
- * Errno.const_missing => SystemCallError
- *
- * Returns default SystemCallError class.
- */
-static VALUE
-errno_missing(VALUE self, VALUE id)
-{
- return eNOERROR;
-}
-
-/*
* Descendents of class <code>Exception</code> are used to communicate
* between <code>raise</code> methods and <code>rescue</code>
* statements in <code>begin/end</code> blocks. <code>Exception</code>
@@ -933,15 +982,15 @@ errno_missing(VALUE self, VALUE id)
*/
void
-Init_Exception(void)
+Init_Exception()
{
rb_eException = rb_define_class("Exception", rb_cObject);
rb_define_singleton_method(rb_eException, "exception", rb_class_new_instance, -1);
rb_define_method(rb_eException, "exception", exc_exception, -1);
rb_define_method(rb_eException, "initialize", exc_initialize, -1);
- rb_define_method(rb_eException, "==", exc_equal, 1);
rb_define_method(rb_eException, "to_s", exc_to_s, 0);
- rb_define_method(rb_eException, "message", exc_message, 0);
+ rb_define_method(rb_eException, "to_str", exc_to_str, 0);
+ rb_define_method(rb_eException, "message", exc_to_str, 0);
rb_define_method(rb_eException, "inspect", exc_inspect, 0);
rb_define_method(rb_eException, "backtrace", exc_backtrace, 0);
rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
@@ -959,21 +1008,13 @@ Init_Exception(void)
rb_eTypeError = rb_define_class("TypeError", rb_eStandardError);
rb_eArgError = rb_define_class("ArgumentError", rb_eStandardError);
rb_eIndexError = rb_define_class("IndexError", rb_eStandardError);
- rb_eKeyError = rb_define_class("KeyError", rb_eIndexError);
rb_eRangeError = rb_define_class("RangeError", rb_eStandardError);
-
- rb_eScriptError = rb_define_class("ScriptError", rb_eException);
- rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError);
- rb_eLoadError = rb_define_class("LoadError", rb_eScriptError);
- rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError);
-
- rb_eNameError = rb_define_class("NameError", rb_eScriptError);
+ rb_eNameError = rb_define_class("NameError", rb_eStandardError);
rb_define_method(rb_eNameError, "initialize", name_err_initialize, -1);
rb_define_method(rb_eNameError, "name", name_err_name, 0);
rb_define_method(rb_eNameError, "to_s", name_err_to_s, 0);
rb_cNameErrorMesg = rb_define_class_under(rb_eNameError, "message", rb_cData);
rb_define_singleton_method(rb_cNameErrorMesg, "!", name_err_mesg_new, 3);
- rb_define_method(rb_cNameErrorMesg, "==", name_err_mesg_equal, 1);
rb_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0);
rb_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_to_str, 1);
rb_define_singleton_method(rb_cNameErrorMesg, "_load", name_err_mesg_load, 1);
@@ -981,6 +1022,11 @@ Init_Exception(void)
rb_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1);
rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0);
+ rb_eScriptError = rb_define_class("ScriptError", rb_eException);
+ rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError);
+ rb_eLoadError = rb_define_class("LoadError", rb_eScriptError);
+ rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError);
+
rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError);
rb_eSecurityError = rb_define_class("SecurityError", rb_eStandardError);
rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
@@ -992,50 +1038,68 @@ Init_Exception(void)
rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);
rb_mErrno = rb_define_module("Errno");
- rb_define_singleton_method(rb_mErrno, "const_missing", errno_missing, 1);
rb_define_global_function("warn", rb_warn_m, 1);
}
void
+#ifdef HAVE_STDARG_PROTOTYPES
rb_raise(VALUE exc, const char *fmt, ...)
+#else
+rb_raise(exc, fmt, va_alist)
+ VALUE exc;
+ const char *fmt;
+ va_dcl
+#endif
{
va_list args;
char buf[BUFSIZ];
- va_start(args,fmt);
+ va_init_list(args,fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
rb_exc_raise(rb_exc_new2(exc, buf));
}
void
+#ifdef HAVE_STDARG_PROTOTYPES
rb_loaderror(const char *fmt, ...)
+#else
+rb_loaderror(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
{
va_list args;
char buf[BUFSIZ];
- va_start(args, fmt);
+ va_init_list(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
rb_exc_raise(rb_exc_new2(rb_eLoadError, buf));
}
void
-rb_notimplement(void)
+rb_notimplement()
{
rb_raise(rb_eNotImpError,
- "The %s() function is unimplemented on this machine",
- rb_id2name(ruby_frame->callee));
+ "%s() function is unimplemented on this machine",
+ rb_id2name(ruby_frame->last_func));
}
void
+#ifdef HAVE_STDARG_PROTOTYPES
rb_fatal(const char *fmt, ...)
+#else
+rb_fatal(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
{
va_list args;
char buf[BUFSIZ];
- va_start(args, fmt);
+ va_init_list(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
@@ -1044,7 +1108,8 @@ rb_fatal(const char *fmt, ...)
}
void
-rb_sys_fail(const char *mesg)
+rb_sys_fail(mesg)
+ const char *mesg;
{
int n = errno;
VALUE arg;
@@ -1059,7 +1124,13 @@ rb_sys_fail(const char *mesg)
}
void
+#ifdef HAVE_STDARG_PROTOTYPES
rb_sys_warning(const char *fmt, ...)
+#else
+rb_sys_warning(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
{
char buf[BUFSIZ];
va_list args;
@@ -1072,32 +1143,35 @@ rb_sys_warning(const char *fmt, ...)
snprintf(buf, BUFSIZ, "warning: %s", fmt);
snprintf(buf+strlen(buf), BUFSIZ-strlen(buf), ": %s", strerror(errno_save));
- va_start(args, fmt);
+ va_init_list(args, fmt);
warn_print(buf, args);
va_end(args);
errno = errno_save;
}
void
-rb_load_fail(const char *path)
+rb_load_fail(path)
+ const char *path;
{
rb_loaderror("%s -- %s", strerror(errno), path);
}
void
-rb_error_frozen(const char *what)
+rb_error_frozen(what)
+ const char *what;
{
- rb_raise(rb_eRuntimeError, "can't modify frozen %s", what);
+ rb_raise(rb_eTypeError, "can't modify frozen %s", what);
}
void
-rb_check_frozen(VALUE obj)
+rb_check_frozen(obj)
+ VALUE obj;
{
if (OBJ_FROZEN(obj)) rb_error_frozen(rb_obj_classname(obj));
}
void
-Init_syserr(void)
+Init_syserr()
{
#ifdef EPERM
set_syserr(EPERM, "EPERM");
@@ -1465,11 +1539,11 @@ Init_syserr(void)
#ifdef EDQUOT
set_syserr(EDQUOT, "EDQUOT");
#endif
- eNOERROR = set_syserr(0, "NOERROR");
}
static void
-err_append(const char *s)
+err_append(s)
+ const char *s;
{
extern VALUE ruby_errinfo;
diff --git a/euc_jp.c b/euc_jp.c
deleted file mode 100644
index 71c81ee9fe..0000000000
--- a/euc_jp.c
+++ /dev/null
@@ -1,228 +0,0 @@
-/**********************************************************************
- euc_jp.c - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2005 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "regenc.h"
-
-#define eucjp_islead(c) ((UChar )((c) - 0xa1) > 0xfe - 0xa1)
-
-static const int EncLen_EUCJP[] = {
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1
-};
-
-static int
-eucjp_mbc_enc_len(const UChar* p)
-{
- return EncLen_EUCJP[*p];
-}
-
-static OnigCodePoint
-eucjp_mbc_to_code(const UChar* p, const UChar* end)
-{
- int c, i, len;
- OnigCodePoint n;
-
- len = enc_len(ONIG_ENCODING_EUC_JP, p);
- n = (OnigCodePoint )*p++;
- if (len == 1) return n;
-
- for (i = 1; i < len; i++) {
- if (p >= end) break;
- c = *p++;
- n <<= 8; n += c;
- }
- return n;
-}
-
-static int
-eucjp_code_to_mbclen(OnigCodePoint code)
-{
- if (ONIGENC_IS_CODE_ASCII(code)) return 1;
- else if ((code & 0xff0000) != 0) return 3;
- else if ((code & 0xff00) != 0) return 2;
- else return 0;
-}
-
-#if 0
-static int
-eucjp_code_to_mbc_first(OnigCodePoint code)
-{
- int first;
-
- if ((code & 0xff0000) != 0) {
- first = (code >> 16) & 0xff;
- }
- else if ((code & 0xff00) != 0) {
- first = (code >> 8) & 0xff;
- }
- else {
- return (int )code;
- }
- return first;
-}
-#endif
-
-static int
-eucjp_code_to_mbc(OnigCodePoint code, UChar *buf)
-{
- UChar *p = buf;
-
- if ((code & 0xff0000) != 0) *p++ = (UChar )(((code >> 16) & 0xff));
- if ((code & 0xff00) != 0) *p++ = (UChar )(((code >> 8) & 0xff));
- *p++ = (UChar )(code & 0xff);
-
-#if 1
- if (enc_len(ONIG_ENCODING_EUC_JP, buf) != (p - buf))
- return ONIGENCERR_INVALID_WIDE_CHAR_VALUE;
-#endif
- return p - buf;
-}
-
-static int
-eucjp_mbc_to_normalize(OnigAmbigType flag,
- const UChar** pp, const UChar* end, UChar* lower)
-{
- int len;
- const UChar* p = *pp;
-
- if (ONIGENC_IS_MBC_ASCII(p)) {
- if ((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0) {
- *lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
- }
- else {
- *lower = *p;
- }
-
- (*pp)++;
- return 1;
- }
- else {
- len = enc_len(ONIG_ENCODING_EUC_JP, p);
- if (lower != p) {
- int i;
- for (i = 0; i < len; i++) {
- *lower++ = *p++;
- }
- }
- (*pp) += len;
- return len; /* return byte length of converted char to lower */
- }
-}
-
-static int
-eucjp_is_mbc_ambiguous(OnigAmbigType flag, const UChar** pp, const UChar* end)
-{
- return onigenc_mbn_is_mbc_ambiguous(ONIG_ENCODING_EUC_JP, flag, pp, end);
-}
-
-static int
-eucjp_is_code_ctype(OnigCodePoint code, unsigned int ctype)
-{
- if (code < 128)
- return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
- else {
- if ((ctype & (ONIGENC_CTYPE_WORD |
- ONIGENC_CTYPE_GRAPH | ONIGENC_CTYPE_PRINT)) != 0) {
- return (eucjp_code_to_mbclen(code) > 1 ? TRUE : FALSE);
- }
- }
-
- return FALSE;
-}
-
-static UChar*
-eucjp_left_adjust_char_head(const UChar* start, const UChar* s)
-{
- /* In this encoding
- mb-trail bytes doesn't mix with single bytes.
- */
- const UChar *p;
- int len;
-
- if (s <= start) return (UChar* )s;
- p = s;
-
- while (!eucjp_islead(*p) && p > start) p--;
- len = enc_len(ONIG_ENCODING_EUC_JP, p);
- if (p + len > s) return (UChar* )p;
- p += len;
- return (UChar* )(p + ((s - p) & ~1));
-}
-
-static int
-eucjp_is_allowed_reverse_match(const UChar* s, const UChar* end)
-{
- const UChar c = *s;
- if (c <= 0x7e || c == 0x8e || c == 0x8f)
- return TRUE;
- else
- return FALSE;
-}
-
-OnigEncodingType OnigEncodingEUC_JP = {
- eucjp_mbc_enc_len,
- "EUC-JP", /* name */
- 3, /* max enc length */
- 1, /* min enc length */
- ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE,
- {
- (OnigCodePoint )'\\' /* esc */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar '.' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anytime '*' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* zero or one time '?' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* one or more time '+' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar anytime */
- },
- onigenc_is_mbc_newline_0x0a,
- eucjp_mbc_to_code,
- eucjp_code_to_mbclen,
- eucjp_code_to_mbc,
- eucjp_mbc_to_normalize,
- eucjp_is_mbc_ambiguous,
- onigenc_ascii_get_all_pair_ambig_codes,
- onigenc_nothing_get_all_comp_ambig_codes,
- eucjp_is_code_ctype,
- onigenc_not_support_get_ctype_code_range,
- eucjp_left_adjust_char_head,
- eucjp_is_allowed_reverse_match
-};
diff --git a/eval.c b/eval.c
index b9c0c71b56..b176b885ec 100644
--- a/eval.c
+++ b/eval.c
@@ -56,12 +56,24 @@ void *alloca ();
# endif /* HAVE_ALLOCA_H */
#endif /* __GNUC__ */
+#ifdef HAVE_STDARG_PROTOTYPES
#include <stdarg.h>
+#define va_init_list(a,b) va_start(a,b)
+#else
+#include <varargs.h>
+#define va_init_list(a,b) va_start(a)
+#endif
+
+#ifndef HAVE_STRING_H
+char *strrchr _((const char*,const char));
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#include <time.h>
+
#ifdef __BEOS__
#include <net/socket.h>
#endif
@@ -78,7 +90,9 @@ void *alloca ();
NORETURN(static void rb_jump_context(rb_jmpbuf_t, int));
static inline void
-rb_jump_context(rb_jmpbuf_t env, int val)
+rb_jump_context(env, val)
+ rb_jmpbuf_t env;
+ int val;
{
env->status = val;
setcontext(&env->context);
@@ -106,7 +120,7 @@ rb_jump_context(rb_jmpbuf_t env, int val)
* But it has not the problem because gcc knows setjmp may return twice.
* gcc detects setjmp and generates setjmp safe code.
*
- * So setjmp calls before and after getcontext call makes the code
+ * So setjmp calls before and after the getcontext call makes the code
* somewhat safe.
* It fix the problem on IA64.
* It is not required that setjmp is called at run time, since the problem is
@@ -135,13 +149,13 @@ rb_jump_context(rb_jmpbuf_t env, int val)
({ __asm__ volatile ("" : : : \
"%o0", "%o1", "%o2", "%o3", "%o4", "%o5", "%o7", \
"%l0", "%l1", "%l2", "%l3", "%l4", "%l5", "%l6", \
- "%i0", "%i1", "%i2", "%i3", "%i4", "%i5", "%i7"); }),
+ "%i0", "%i1", "%i2", "%i3", "%i4", "%i5", "%i7"); })
# else
# define PRE_GETCONTEXT \
({ __asm__ volatile ("" : : : \
"%o0", "%o1", "%o2", "%o3", "%o4", "%o5", "%o7", \
"%l0", "%l1", "%l2", "%l3", "%l4", "%l5", "%l6", "%l7", \
- "%i0", "%i1", "%i2", "%i3", "%i4", "%i5", "%i7"); }),
+ "%i0", "%i1", "%i2", "%i3", "%i4", "%i5", "%i7"); })
# endif
# define POST_GETCONTEXT PRE_GETCONTEXT
# elif GCC_VERSION_BEFORE(4,0,3) && defined(__ia64)
@@ -151,11 +165,11 @@ int function_call_may_return_twice_false_2 = 0;
# define PRE_GETCONTEXT \
(function_call_may_return_twice_false_1 ? \
setjmp(function_call_may_return_twice_jmp_buf) : \
- 0),
+ 0)
# define POST_GETCONTEXT \
(function_call_may_return_twice_false_2 ? \
setjmp(function_call_may_return_twice_jmp_buf) : \
- 0),
+ 0)
# elif defined(__FreeBSD__) && __FreeBSD__ < 7
/*
* workaround for FreeBSD/i386 getcontext/setcontext bug.
@@ -165,20 +179,20 @@ int function_call_may_return_twice_false_2 = 0;
*/
static int volatile freebsd_clear_carry_flag = 0;
# define PRE_GETCONTEXT \
- (freebsd_clear_carry_flag ? (freebsd_clear_carry_flag = 0) : 0),
+ (freebsd_clear_carry_flag ? (freebsd_clear_carry_flag = 0) : 0)
# endif
# ifndef PRE_GETCONTEXT
-# define PRE_GETCONTEXT
+# define PRE_GETCONTEXT 0
# endif
# ifndef POST_GETCONTEXT
-# define POST_GETCONTEXT
+# define POST_GETCONTEXT 0
# endif
# define ruby_longjmp(env, val) rb_jump_context(env, val)
# define ruby_setjmp(just_before_setjmp, j) ((j)->status = 0, \
(just_before_setjmp), \
- PRE_GETCONTEXT \
+ PRE_GETCONTEXT, \
getcontext(&(j)->context), \
- POST_GETCONTEXT \
+ POST_GETCONTEXT, \
(j)->status)
#else
# if !defined(setjmp) && defined(HAVE__SETJMP)
@@ -204,56 +218,35 @@ static int volatile freebsd_clear_carry_flag = 0;
#include <sys/select.h>
#endif
-/*
- Solaris sys/select.h switches select to select_large_fdset to support larger
- file descriptors if FD_SETSIZE is larger than 1024 on 32bit environment.
- But Ruby doesn't change FD_SETSIZE because fd_set is allocated dynamically.
- So following definition is required to use select_large_fdset.
-*/
-#ifdef HAVE_SELECT_LARGE_FDSET
-#define select(n, r, w, e, t) select_large_fdset(n, r, w, e, t)
-#endif
-
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-
#include <sys/stat.h>
VALUE rb_cProc;
VALUE rb_cBinding;
-static VALUE proc_alloc(VALUE,struct BLOCK*,int);
-static VALUE proc_invoke(VALUE,VALUE,VALUE,VALUE,int);
-#define INVOKE_CALL (YIELD_CALL|YIELD_VALUES)
-#define INVOKE_VALUES YIELD_VALUES
-
-static VALUE proc_lambda(void);
-static VALUE rb_f_binding(VALUE);
-static void rb_f_END(void);
-static struct BLOCK *passing_block(VALUE,struct BLOCK*);
-static int block_orphan(struct BLOCK *data);
+static VALUE proc_invoke _((VALUE,VALUE,VALUE,VALUE));
+static VALUE rb_f_binding _((VALUE));
+static void rb_f_END _((void));
+static VALUE rb_f_block_given_p _((void));
+static VALUE block_pass _((VALUE,NODE*));
VALUE rb_cMethod;
+static VALUE method_call _((int, VALUE*, VALUE));
VALUE rb_cUnboundMethod;
-static VALUE umethod_bind(VALUE, VALUE);
-static VALUE rb_mod_define_method(int, VALUE*, VALUE);
-static VALUE rb_obj_define_method(int, VALUE*, VALUE);
-NORETURN(static void rb_raise_jump(VALUE));
-static VALUE rb_make_exception(int argc, VALUE *argv);
-
-static int vis_mode;
-#define VIS_PUBLIC 0
-#define VIS_PRIVATE 1
-#define VIS_PROTECTED 2
-#define VIS_MODFUNC 5
-#define VIS_LOCAL 8
-#define VIS_MASK 15
-#define VIS_SET(f) (vis_mode=(f))
-#define VIS_TEST(f) (vis_mode&(f))
-#define VIS_MODE() (vis_mode)
-
-VALUE (*ruby_sandbox_save)(struct thread *) = NULL;
-VALUE (*ruby_sandbox_restore)(struct thread *) = NULL;
+static VALUE umethod_bind _((VALUE, VALUE));
+static VALUE rb_mod_define_method _((int, VALUE*, VALUE));
+NORETURN(static void rb_raise_jump _((VALUE)));
+static VALUE rb_make_exception _((int argc, VALUE *argv));
+
+static int scope_vmode;
+#define SCOPE_PUBLIC 0
+#define SCOPE_PRIVATE 1
+#define SCOPE_PROTECTED 2
+#define SCOPE_MODFUNC 5
+#define SCOPE_MASK 7
+#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));
NODE* ruby_current_node;
int ruby_safe_level = 0;
/* safe-level:
@@ -264,16 +257,17 @@ int ruby_safe_level = 0;
4 - no global (non-tainted) variable modification/no direct output
*/
-static VALUE safe_getter(void);
-static void safe_setter(VALUE val);
+static VALUE safe_getter _((void));
+static void safe_setter _((VALUE val));
void
-rb_secure(int level)
+rb_secure(level)
+ int level;
{
if (level <= ruby_safe_level) {
- if (ruby_frame->callee) {
+ if (ruby_frame->last_func) {
rb_raise(rb_eSecurityError, "Insecure operation `%s' at level %d",
- rb_id2name(ruby_frame->callee), ruby_safe_level);
+ rb_id2name(ruby_frame->last_func), ruby_safe_level);
}
else {
rb_raise(rb_eSecurityError, "Insecure operation at level %d", ruby_safe_level);
@@ -282,18 +276,20 @@ rb_secure(int level)
}
void
-rb_secure_update(VALUE obj)
+rb_secure_update(obj)
+ VALUE obj;
{
if (!OBJ_TAINTED(obj)) rb_secure(4);
}
void
-rb_check_safe_obj(VALUE x)
+rb_check_safe_obj(x)
+ VALUE x;
{
if (ruby_safe_level > 0 && OBJ_TAINTED(x)){
- if (ruby_frame->callee) {
+ if (ruby_frame->last_func) {
rb_raise(rb_eSecurityError, "Insecure operation - %s",
- rb_id2name(ruby_frame->callee));
+ rb_id2name(ruby_frame->last_func));
}
else {
rb_raise(rb_eSecurityError, "Insecure operation: -r");
@@ -303,7 +299,8 @@ rb_check_safe_obj(VALUE x)
}
void
-rb_check_safe_str(VALUE x)
+rb_check_safe_str(x)
+ VALUE x;
{
rb_check_safe_obj(x);
if (TYPE(x)!= T_STRING) {
@@ -312,9 +309,11 @@ rb_check_safe_str(VALUE x)
}
}
-NORETURN(static void raise_undef(VALUE, ID));
+NORETURN(static void print_undef _((VALUE, ID)));
static void
-raise_undef(VALUE klass, ID id)
+print_undef(klass, id)
+ VALUE klass;
+ ID id;
{
rb_name_error(id, "undefined method `%s' for %s `%s'",
rb_id2name(id),
@@ -328,7 +327,7 @@ static ID removed, singleton_removed, undefined, singleton_undefined;
#define CACHE_MASK 0x7ff
#define EXPR1(c,m) ((((c)>>3)^(m))&CACHE_MASK)
-struct cache_entry { /* method hash table. */
+struct cache_entry { /* method hash table. */
ID mid; /* method's id */
ID mid0; /* method's original id */
VALUE klass; /* receiver's class */
@@ -337,79 +336,87 @@ struct cache_entry { /* method hash table. */
int noex;
};
-static struct cache_entry cache[2][CACHE_SIZE];
+static struct cache_entry cache[CACHE_SIZE];
static int ruby_running = 0;
void
rb_clear_cache()
{
- int i;
+ struct cache_entry *ent, *end;
if (!ruby_running) return;
- for (i=0; i<CACHE_SIZE; i++) {
- cache[0][i].mid = cache[1][i].mid = 0;
+ ent = cache; end = ent + CACHE_SIZE;
+ while (ent < end) {
+ ent->mid = 0;
+ ent++;
}
}
static void
-rb_clear_cache_for_remove(VALUE klass, ID id)
+rb_clear_cache_for_undef(klass, id)
+ VALUE klass;
+ ID id;
{
- int i, j;
+ struct cache_entry *ent, *end;
if (!ruby_running) return;
- for (i=0; i<CACHE_SIZE; i++) {
- for (j=0; j<2; j++) {
- struct cache_entry *ent = cache[j]+i;
- if (ent->mid == id &&
- RCLASS(ent->origin)->m_tbl == RCLASS(klass)->m_tbl) {
- ent->mid = 0;
- }
+ ent = cache; end = ent + CACHE_SIZE;
+ while (ent < end) {
+ if (ent->mid == id &&
+ RCLASS(ent->origin)->m_tbl == RCLASS(klass)->m_tbl) {
+ ent->mid = 0;
}
+ ent++;
}
}
static void
-rb_clear_cache_by_id(ID id)
+rb_clear_cache_by_id(id)
+ ID id;
{
- int i, j;
+ struct cache_entry *ent, *end;
if (!ruby_running) return;
- for (i=0; i<CACHE_SIZE; i++) {
- for (j=0; j<2; j++) {
- struct cache_entry *ent = cache[j]+i;
- if (ent->mid == id) {
- ent->mid = 0;
- }
+ ent = cache; end = ent + CACHE_SIZE;
+ while (ent < end) {
+ if (ent->mid == id) {
+ ent->mid = 0;
}
+ ent++;
}
}
void
-rb_clear_cache_by_class(VALUE klass)
+rb_clear_cache_by_class(klass)
+ VALUE klass;
{
- int i, j;
+ struct cache_entry *ent, *end;
if (!ruby_running) return;
- for (i=0; i<CACHE_SIZE; i++) {
- for (j=0; j<2; j++) {
- struct cache_entry *ent = cache[j]+i;
- if (ent->klass == klass || ent->origin == klass) {
- ent->mid = 0;
- }
+ ent = cache; end = ent + CACHE_SIZE;
+ while (ent < end) {
+ if (ent->klass == klass || ent->origin == klass) {
+ ent->mid = 0;
}
+ ent++;
}
}
static ID init, eqq, each, aref, aset, match, missing;
static ID added, singleton_added;
-static ID object_id, __send, __send_bang, respond_to;
+static ID __id__, __send__, respond_to;
-#define NOEX_SAFE(n) ((n) >> 5)
-#define NOEX_WITH(n, v) ((n) | (v) << 5)
+#define NOEX_TAINTED 8
+#define NOEX_SAFE(n) ((n) >> 4)
+#define NOEX_WITH(n, v) ((n) | (v) << 4)
#define NOEX_WITH_SAFE(n) NOEX_WITH(n, ruby_safe_level)
void
-rb_add_method(VALUE klass, ID mid, NODE *node, int noex)
+rb_add_method(klass, mid, node, noex)
+ VALUE klass;
+ ID mid;
+ NODE *node;
+ int noex;
{
NODE *body;
@@ -443,62 +450,55 @@ rb_add_method(VALUE klass, ID mid, NODE *node, int noex)
}
void
-rb_define_alloc_func(VALUE klass, VALUE (*func) (VALUE))
+rb_define_alloc_func(klass, func)
+ VALUE klass;
+ VALUE (*func) _((VALUE));
{
Check_Type(klass, T_CLASS);
- rb_add_method(CLASS_OF(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0), NOEX_PRIVATE);
+ rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0),
+ NOEX_PRIVATE);
}
void
-rb_undef_alloc_func(VALUE klass)
+rb_undef_alloc_func(klass)
+ VALUE klass;
{
Check_Type(klass, T_CLASS);
- rb_add_method(CLASS_OF(klass), ID_ALLOCATOR, 0, NOEX_UNDEF);
+ rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, 0, NOEX_UNDEF);
}
-#define LOOKUP_NORMAL 0
-#define LOOKUP_FCALL 1
-#define LOOKUP_NOSKIP 2
-#define LOOKUP_LOCAL 1
-
static NODE*
-search_method(VALUE klass, ID id, VALUE *origin, int flag, int *out)
+search_method(klass, id, origin)
+ VALUE klass, *origin;
+ ID id;
{
- NODE *body;
+ st_data_t body;
- if (flag == LOOKUP_FCALL && ruby_frame->this_class) {
- if (st_lookup(RCLASS(ruby_frame->this_class)->m_tbl, id, (st_data_t *)&body) &&
- body->nd_noex == NOEX_LOCAL) {
- if (origin) *origin = ruby_frame->this_class;
- if (out) *out = LOOKUP_LOCAL;
- return body;
- }
- }
- for (;klass; klass = RCLASS(klass)->super) {
- if (st_lookup(RCLASS(klass)->m_tbl, id, (st_data_t *)&body) &&
- (flag == LOOKUP_NOSKIP || body->nd_noex != NOEX_LOCAL)) {
- if (origin) *origin = klass;
- if (out) *out = LOOKUP_NORMAL;
- return body;
- }
+ if (!klass) return 0;
+ while (!st_lookup(RCLASS(klass)->m_tbl, id, &body)) {
+ klass = RCLASS(klass)->super;
+ if (!klass) return 0;
}
- return 0;
+
+ if (origin) *origin = klass;
+ return (NODE *)body;
}
static NODE*
-rb_get_method_body(VALUE *klassp, ID *idp, int *noexp)
+rb_get_method_body(klassp, idp, noexp)
+ VALUE *klassp;
+ ID *idp;
+ int *noexp;
{
ID id = *idp;
VALUE klass = *klassp;
VALUE origin;
NODE * volatile body;
struct cache_entry *ent;
- int noex = *noexp;
- int lc;
- if ((body = search_method(klass, id, &origin, noex, &lc)) == 0 || !body->nd_body) {
+ if ((body = search_method(klass, id, &origin)) == 0 || !body->nd_body) {
/* store empty info in cache */
- ent = cache[noex] + EXPR1(klass, id);
+ ent = cache + EXPR1(klass, id);
ent->klass = klass;
ent->origin = klass;
ent->mid = ent->mid0 = id;
@@ -509,11 +509,10 @@ rb_get_method_body(VALUE *klassp, ID *idp, int *noexp)
}
if (ruby_running) {
- VALUE c = (lc == LOOKUP_LOCAL) ? origin : klass;
/* store in cache */
- ent = cache[lc] + EXPR1(c, id);
- ent->klass = c;
- ent->noex = body->nd_noex;
+ ent = cache + EXPR1(klass, id);
+ ent->klass = klass;
+ ent->noex = body->nd_noex;
if (noexp) *noexp = body->nd_noex;
body = body->nd_body;
if (nd_type(body) == NODE_FBODY) {
@@ -547,23 +546,22 @@ rb_get_method_body(VALUE *klassp, ID *idp, int *noexp)
}
NODE*
-rb_method_node(VALUE klass, ID id)
+rb_method_node(klass, id)
+ VALUE klass;
+ ID id;
{
- int noex = LOOKUP_NORMAL;
- struct cache_entry *ent;
-
- ent = cache[0] + EXPR1(klass, id);
- if (ent->mid == id && ent->klass == klass && ent->method){
- return ent->method;
- }
+ int noex;
return rb_get_method_body(&klass, &id, &noex);
}
static void
-remove_method(VALUE klass, ID mid)
+remove_method(klass, mid)
+ VALUE klass;
+ ID mid;
{
- NODE *body;
+ st_data_t data;
+ NODE *body = 0;
if (klass == rb_cObject) {
rb_secure(4);
@@ -572,15 +570,21 @@ remove_method(VALUE klass, ID mid)
rb_raise(rb_eSecurityError, "Insecure: can't remove method");
}
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
- if (mid == object_id || mid == __send || mid == __send_bang || mid == init) {
+ if (mid == __id__ || mid == __send__ || mid == init) {
rb_warn("removing `%s' may cause serious problem", rb_id2name(mid));
}
- if (!st_delete(RCLASS(klass)->m_tbl, &mid, (st_data_t *)&body) ||
- !body->nd_body) {
+ 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) {
rb_name_error(mid, "method `%s' not defined in %s",
rb_id2name(mid), rb_class2name(klass));
}
- rb_clear_cache_for_remove(klass, mid);
+ rb_clear_cache_for_undef(klass, mid);
if (FL_TEST(klass, FL_SINGLETON)) {
rb_funcall(rb_iv_get(klass, "__attached__"), singleton_removed, 1, ID2SYM(mid));
}
@@ -590,7 +594,9 @@ remove_method(VALUE klass, ID mid)
}
void
-rb_remove_method(VALUE klass, const char *name)
+rb_remove_method(klass, name)
+ VALUE klass;
+ const char *name;
{
remove_method(klass, rb_intern(name));
}
@@ -604,7 +610,10 @@ rb_remove_method(VALUE klass, const char *name)
*/
static VALUE
-rb_mod_remove_method(int argc, VALUE *argv, VALUE mod)
+rb_mod_remove_method(argc, argv, mod)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
{
int i;
@@ -618,19 +627,26 @@ rb_mod_remove_method(int argc, VALUE *argv, VALUE mod)
#undef rb_enable_super
void
-rb_disable_super(VALUE klass, const char *name)
+rb_disable_super(klass, name)
+ VALUE klass;
+ const char *name;
{
/* obsolete - no use */
}
void
-rb_enable_super(VALUE klass, const char *name)
+rb_enable_super(klass, name)
+ VALUE klass;
+ const char *name;
{
- rb_warning("rb_enable_super() is obsolete");
+ rb_warn("rb_enable_super() is obsolete");
}
static void
-rb_export_method(VALUE klass, ID name, ID noex)
+rb_export_method(klass, name, noex)
+ VALUE klass;
+ ID name;
+ ID noex;
{
NODE *body;
VALUE origin;
@@ -638,12 +654,12 @@ rb_export_method(VALUE klass, ID name, ID noex)
if (klass == rb_cObject) {
rb_secure(4);
}
- body = search_method(klass, name, &origin, LOOKUP_NOSKIP, 0);
+ body = search_method(klass, name, &origin);
if (!body && TYPE(klass) == T_MODULE) {
- body = search_method(rb_cObject, name, &origin, LOOKUP_NOSKIP, 0);
+ body = search_method(rb_cObject, name, &origin);
}
if (!body || !body->nd_body) {
- raise_undef(klass, name);
+ print_undef(klass, name);
}
if (body->nd_noex != noex) {
if (klass == origin) {
@@ -655,60 +671,52 @@ rb_export_method(VALUE klass, ID name, ID noex)
}
}
-static int
-method_exists(VALUE klass, ID id, int noex)
+int
+rb_method_boundp(klass, id, ex)
+ VALUE klass;
+ ID id;
+ int ex;
{
struct cache_entry *ent;
- int nx = noex;
-
- switch (noex) {
- case LOOKUP_NORMAL:
- case LOOKUP_FCALL:
- /* is it in the method cache? */
- ent = cache[noex] + EXPR1(klass, id);
- if (ent->mid == id && ent->klass == klass) {
- if (nx == LOOKUP_NORMAL) {
- if (ent->noex == NOEX_PRIVATE) return Qfalse;
- }
- else if (ent->noex != NOEX_LOCAL) {
- if (!ent->method) return Qfalse;
- return Qtrue;
- }
- }
- /* fall through */
- default:
- if (rb_get_method_body(&klass, &id, &noex)) {
- if (nx == LOOKUP_NORMAL && noex == NOEX_PRIVATE)
- return Qfalse;
- return Qtrue;
- }
- return Qfalse;
- }
-}
+ int noex;
-int
-rb_method_boundp(VALUE klass, ID id, int pub)
-{
- return method_exists(klass, id, pub ? LOOKUP_NORMAL : LOOKUP_FCALL);
+ /* is it in the method cache? */
+ ent = cache + EXPR1(klass, id);
+ if (ent->mid == id && ent->klass == klass) {
+ if (ex && (ent->noex & NOEX_PRIVATE))
+ return Qfalse;
+ if (!ent->method) return Qfalse;
+ return Qtrue;
+ }
+ if (rb_get_method_body(&klass, &id, &noex)) {
+ if (ex && (noex & NOEX_PRIVATE))
+ return Qfalse;
+ return Qtrue;
+ }
+ return Qfalse;
}
void
-rb_attr(VALUE klass, ID id, int read, int write, int noex)
+rb_attr(klass, id, read, write, ex)
+ VALUE klass;
+ ID id;
+ int read, write, ex;
{
const char *name;
char *buf;
ID attriv;
+ int noex;
size_t len;
- if (!noex) noex = NOEX_PUBLIC;
+ if (!ex) noex = NOEX_PUBLIC;
else {
- if (VIS_TEST(VIS_PRIVATE)) {
+ if (SCOPE_TEST(SCOPE_PRIVATE)) {
noex = NOEX_PRIVATE;
- rb_warning((VIS_MODE() == VIS_MODFUNC) ?
+ rb_warning((scope_vmode == SCOPE_MODFUNC) ?
"attribute accessor as module_function" :
"private attribute?");
}
- else if (VIS_TEST(VIS_PROTECTED)) {
+ else if (SCOPE_TEST(SCOPE_PROTECTED)) {
noex = NOEX_PROTECTED;
}
else {
@@ -735,7 +743,11 @@ rb_attr(VALUE klass, ID id, int read, int write, int noex)
}
}
+extern int ruby_in_compile;
+
VALUE ruby_errinfo = Qnil;
+extern NODE *ruby_eval_tree_begin;
+extern NODE *ruby_eval_tree;
extern int ruby_nerrs;
VALUE rb_eLocalJumpError;
@@ -748,21 +760,17 @@ struct SCOPE *ruby_scope;
static struct FRAME *top_frame;
static struct SCOPE *top_scope;
-static unsigned long frame_unique = 1;
+static unsigned long frame_unique = 0;
-#define PUSH_FRAME(link) do { \
- struct FRAME _frame; \
+#define PUSH_FRAME() do { \
+ volatile struct FRAME _frame; \
_frame.prev = ruby_frame; \
_frame.tmp = 0; \
_frame.node = ruby_current_node; \
+ _frame.iter = ruby_iter->iter; \
_frame.argc = 0; \
- _frame.self = (link)?ruby_frame->self:0;\
- _frame.block = (link)?ruby_frame->block:0;\
_frame.flags = 0; \
_frame.uniq = frame_unique++; \
- _frame.callee = 0; \
- _frame.this_func = 0; \
- _frame.this_class = 0; \
ruby_frame = &_frame
#define POP_FRAME() \
@@ -770,33 +778,59 @@ static unsigned long frame_unique = 1;
ruby_frame = _frame.prev; \
} while (0)
+struct BLOCK {
+ NODE *var;
+ NODE *body;
+ VALUE self;
+ struct FRAME frame;
+ struct SCOPE *scope;
+ VALUE klass;
+ NODE *cref;
+ int iter;
+ int vmode;
+ int flags;
+ int uniq;
+ struct RVarmap *dyna_vars;
+ VALUE orig_thread;
+ VALUE wrapper;
+ VALUE block_obj;
+ struct BLOCK *outer;
+ struct BLOCK *prev;
+};
+
+#define BLOCK_D_SCOPE 1
+#define BLOCK_LAMBDA 2
+
+static struct BLOCK *ruby_block;
static unsigned long block_unique = 1;
-#define PUSH_BLOCK(v,iv,b) do { \
+#define PUSH_BLOCK(v,b) do { \
struct BLOCK _block; \
- _block.var = (iv); \
+ _block.var = (v); \
_block.body = (b); \
_block.self = self; \
_block.frame = *ruby_frame; \
+ _block.klass = ruby_class; \
_block.cref = ruby_cref; \
_block.frame.node = ruby_current_node;\
_block.scope = ruby_scope; \
- _block.vmode = vis_mode; \
+ _block.prev = ruby_block; \
+ _block.outer = ruby_block; \
+ _block.iter = ruby_iter->iter; \
+ _block.vmode = scope_vmode; \
_block.flags = BLOCK_D_SCOPE; \
_block.dyna_vars = ruby_dyna_vars; \
_block.wrapper = ruby_wrapper; \
_block.block_obj = 0; \
+ _block.uniq = (b)?block_unique++:0; \
if (b) { \
- _block.uniq = block_unique++; \
prot_tag->blkid = _block.uniq; \
} \
- else { \
- _block.uniq = 0; \
- prot_tag->blkid = 0; \
- } \
- (v) = &_block
+ ruby_block = &_block
-#define POP_BLOCK() } while (0)
+#define POP_BLOCK() \
+ ruby_block = _block.prev; \
+} while (0)
struct RVarmap *ruby_dyna_vars;
#define PUSH_VARS() do { \
@@ -817,7 +851,10 @@ struct RVarmap *ruby_dyna_vars;
#define DMETHOD_P() (ruby_frame->flags & FRAME_DMETH)
static struct RVarmap*
-new_dvar(ID id, VALUE value, struct RVarmap *prev)
+new_dvar(id, value, prev)
+ ID id;
+ VALUE value;
+ struct RVarmap *prev;
{
NEWOBJ(vars, struct RVarmap);
OBJSETUP(vars, 0, T_VARMAP);
@@ -829,7 +866,8 @@ new_dvar(ID id, VALUE value, struct RVarmap *prev)
}
VALUE
-rb_dvar_defined(ID id)
+rb_dvar_defined(id)
+ ID id;
{
struct RVarmap *vars = ruby_dyna_vars;
@@ -841,7 +879,8 @@ rb_dvar_defined(ID id)
}
VALUE
-rb_dvar_curr(ID id)
+rb_dvar_curr(id)
+ ID id;
{
struct RVarmap *vars = ruby_dyna_vars;
@@ -854,7 +893,8 @@ rb_dvar_curr(ID id)
}
VALUE
-rb_dvar_ref(ID id)
+rb_dvar_ref(id)
+ ID id;
{
struct RVarmap *vars = ruby_dyna_vars;
@@ -868,13 +908,18 @@ rb_dvar_ref(ID id)
}
void
-rb_dvar_push(ID id, VALUE value)
+rb_dvar_push(id, value)
+ ID id;
+ VALUE value;
{
ruby_dyna_vars = new_dvar(id, value, ruby_dyna_vars);
}
static void
-dvar_asgn_internal(ID id, VALUE value, int curr)
+dvar_asgn_internal(id, value, curr)
+ ID id;
+ VALUE value;
+ int curr;
{
int n = 0;
struct RVarmap *vars = ruby_dyna_vars;
@@ -901,19 +946,24 @@ dvar_asgn_internal(ID id, VALUE value, int curr)
}
static inline void
-dvar_asgn(ID id, VALUE value)
+dvar_asgn(id, value)
+ ID id;
+ VALUE value;
{
dvar_asgn_internal(id, value, 0);
}
static inline void
-dvar_asgn_curr(ID id, VALUE value)
+dvar_asgn_curr(id, value)
+ ID id;
+ VALUE value;
{
dvar_asgn_internal(id, value, 1);
}
VALUE *
-rb_svar(int cnt)
+rb_svar(cnt)
+ int cnt;
{
struct RVarmap *vars = ruby_dyna_vars;
ID id;
@@ -929,9 +979,31 @@ rb_svar(int cnt)
return &ruby_scope->local_vars[cnt];
}
+struct iter {
+ int iter;
+ struct iter *prev;
+};
+static struct iter *ruby_iter;
+
+#define ITER_NOT 0
+#define ITER_PRE 1
+#define ITER_CUR 2
+#define ITER_PAS 3
+
+#define PUSH_ITER(i) do { \
+ struct iter _iter; \
+ _iter.prev = ruby_iter; \
+ _iter.iter = (i); \
+ ruby_iter = &_iter
+
+#define POP_ITER() \
+ ruby_iter = _iter.prev; \
+} while (0)
+
struct tag {
rb_jmpbuf_t buf;
struct FRAME *frame;
+ struct iter *iter;
VALUE tag;
VALUE retval;
struct SCOPE *scope;
@@ -945,10 +1017,11 @@ static struct tag *prot_tag;
struct tag _tag; \
_tag.retval = Qnil; \
_tag.frame = ruby_frame; \
+ _tag.iter = ruby_iter; \
_tag.prev = prot_tag; \
_tag.scope = ruby_scope; \
_tag.tag = ptag; \
- _tag.dst = -1; \
+ _tag.dst = 0; \
_tag.blkid = 0; \
prot_tag = &_tag
@@ -958,12 +1031,12 @@ static struct tag *prot_tag;
#define PROT_LOOP INT2FIX(1) /* 3 */
#define PROT_LAMBDA INT2FIX(2) /* 5 */
#define PROT_YIELD INT2FIX(3) /* 7 */
-#define PROT_TOP INT2FIX(4) /* 9 */
#define EXEC_TAG() (FLUSH_REGISTER_WINDOWS, ruby_setjmp(((void)0), prot_tag->buf))
#define JUMP_TAG(st) do { \
ruby_frame = prot_tag->frame; \
+ ruby_iter = prot_tag->iter; \
ruby_longjmp(prot_tag->buf,(st)); \
} while (0)
@@ -981,11 +1054,17 @@ static struct tag *prot_tag;
#define TAG_RAISE 0x6
#define TAG_THROW 0x7
#define TAG_FATAL 0x8
-#define TAG_CONTCALL 0x9
-#define TAG_THREAD 0xa
#define TAG_MASK 0xf
-VALUE ruby_wrapper; /* security wrapper */
+VALUE ruby_class;
+static VALUE ruby_wrapper; /* security wrapper */
+
+#define PUSH_CLASS(c) do { \
+ volatile VALUE _class = ruby_class; \
+ ruby_class = (c)
+
+#define POP_CLASS() ruby_class = _class; \
+} while (0)
NODE *ruby_cref = 0;
NODE *ruby_top_cref;
@@ -993,7 +1072,7 @@ NODE *ruby_top_cref;
#define POP_CREF() ruby_cref = ruby_cref->nd_next
#define PUSH_SCOPE() do { \
- volatile int _vmode = vis_mode; \
+ volatile int _vmode = scope_vmode; \
struct SCOPE * volatile _old; \
NEWOBJ(_scope, struct SCOPE); \
OBJSETUP(_scope, 0, T_SCOPE); \
@@ -1002,11 +1081,14 @@ NODE *ruby_top_cref;
_scope->flags = 0; \
_old = ruby_scope; \
ruby_scope = _scope; \
- vis_mode = VIS_PUBLIC
+ scope_vmode = SCOPE_PUBLIC
-rb_thread_t curr_thread = 0;
-rb_thread_t main_thread;
-static void scope_dup(struct SCOPE *);
+rb_thread_t rb_curr_thread;
+rb_thread_t rb_main_thread;
+#define main_thread rb_main_thread
+#define curr_thread rb_curr_thread
+
+static void scope_dup _((struct SCOPE *));
#define POP_SCOPE() \
if (ruby_scope->flags & SCOPE_DONT_RECYCLE) {\
@@ -1022,57 +1104,26 @@ static void scope_dup(struct SCOPE *);
} \
ruby_scope->flags |= SCOPE_NOSTACK; \
ruby_scope = _old; \
- vis_mode = _vmode; \
+ scope_vmode = _vmode; \
} while (0)
-struct ruby_env {
- struct ruby_env *prev;
- struct FRAME *frame;
- struct SCOPE *scope;
- struct BLOCK *block;
- struct tag *tag;
- NODE *cref;
-};
-
-static void push_thread_anchor(struct ruby_env *);
-static void pop_thread_anchor(struct ruby_env *);
-
-#define PUSH_THREAD_TAG() PUSH_TAG(PROT_THREAD); \
- do { \
- struct ruby_env _interp; \
- push_thread_anchor(&_interp);
-#define POP_THREAD_TAG() \
- pop_thread_anchor(&_interp); \
- } while (0); \
- POP_TAG()
-
-static VALUE rb_eval(VALUE,NODE*);
-static VALUE eval(VALUE,VALUE,VALUE,const char*,int);
-static NODE *compile(VALUE, const char*, int);
+static VALUE rb_eval _((VALUE,NODE*));
+static VALUE eval _((VALUE,VALUE,VALUE,char*,int));
+static NODE *compile _((VALUE, char*, int));
-static VALUE rb_yield_0(VALUE, VALUE, VALUE, int);
+static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int, int));
-#define YIELD_CALL 1
-#define YIELD_VALUES 2
-#define YIELD_PROC_INVOKE 4
-#define YIELD_PUBLIC_DEF 8
+#define YIELD_LAMBDA_CALL 1
+#define YIELD_PROC_CALL 2
+#define YIELD_PUBLIC_DEF 4
#define YIELD_FUNC_AVALUE 1
#define YIELD_FUNC_SVALUE 2
-typedef enum calling_scope {
- CALLING_NORMAL,
- CALLING_FUNCALL,
- CALLING_FCALL,
- CALLING_VCALL,
- CALLING_SUPER,
-} calling_scope_t;
+static VALUE rb_call _((VALUE,VALUE,ID,int,const VALUE*,int,VALUE));
+static VALUE module_setup _((VALUE,NODE*));
-static VALUE rb_call(VALUE,VALUE,ID,int,const VALUE*,struct BLOCK*,calling_scope_t,int,VALUE);
-static VALUE module_setup(VALUE,NODE*);
-
-static VALUE massign(VALUE,NODE*,VALUE,int);
-static void assign(VALUE,NODE*,VALUE,int);
-static int formal_assign(VALUE, NODE*, int, const VALUE*, VALUE*);
+static VALUE massign _((VALUE,NODE*,VALUE,int));
+static void assign _((VALUE,NODE*,VALUE,int));
typedef struct event_hook {
rb_event_hook_func_t func;
@@ -1099,7 +1150,7 @@ static rb_event_hook_t *event_hooks;
static VALUE trace_func = 0;
static int tracing = 0;
-static void call_trace_func(rb_event_t,NODE*,VALUE,ID,VALUE);
+static void call_trace_func _((rb_event_t,NODE*,VALUE,ID,VALUE));
#if 0
#define SET_CURRENT_SOURCE() (ruby_sourcefile = ruby_current_node->nd_file, \
@@ -1109,7 +1160,7 @@ static void call_trace_func(rb_event_t,NODE*,VALUE,ID,VALUE);
#endif
void
-ruby_set_current_source(void)
+ruby_set_current_source()
{
if (ruby_current_node) {
ruby_sourcefile = ruby_current_node->nd_file;
@@ -1118,103 +1169,69 @@ ruby_set_current_source(void)
}
static void
+#ifdef HAVE_STDARG_PROTOTYPES
warn_printf(const char *fmt, ...)
+#else
+warn_printf(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
{
char buf[BUFSIZ];
va_list args;
- va_start(args, fmt);
+ va_init_list(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
rb_write_error(buf);
}
-static VALUE
-error_line(struct FRAME *frame, NODE *node)
-{
- char *file;
- int line;
+#define warn_print(x) rb_write_error(x)
+#define warn_print2(x,l) rb_write_error2(x,l)
- if (node) {
- file = node->nd_file;
- line = nd_line(node);
- }
- else {
- file = ruby_sourcefile;
- line = ruby_sourceline;
- }
+static void
+error_pos()
+{
ruby_set_current_source();
if (ruby_sourcefile) {
- if (frame->callee) {
- if (frame->flags & FRAME_FUNC) {
- return rb_sprintf("%s:%d:in `%s'", file, line,
- rb_id2name(frame->this_func));
- }
- else {
- VALUE oklass = frame->this_class;
- char *rec = 0;
-
- switch (TYPE(frame->self)) {
- case T_NIL:
- rec = "nil"; break;
- case T_TRUE:
- rec = "true"; break;
- case T_FALSE:
- rec = "false"; break;
- }
- if (rec) {
- return rb_sprintf("%s:%d:in `%s.%s'", file, line, rec,
- rb_id2name(frame->this_func));
- }
- if (TYPE(oklass) == T_ICLASS) {
- oklass = RBASIC(oklass)->klass;
- }
- else if (FL_TEST(oklass, FL_SINGLETON)) {
- oklass = rb_iv_get(oklass, "__attached__");
- }
- return rb_sprintf("%s:%d:in `%s#%s'", file, line,
- rb_class2name(oklass),
- rb_id2name(frame->this_func));
- }
+ if (ruby_frame->last_func) {
+ warn_printf("%s:%d:in `%s'", ruby_sourcefile, ruby_sourceline,
+ rb_id2name(ruby_frame->orig_func));
}
- else if (!node && ruby_sourceline == 0) {
- return rb_str_new2(ruby_sourcefile);
+ else if (ruby_sourceline == 0) {
+ warn_printf("%s", ruby_sourcefile);
+ }
+ else {
+ warn_printf("%s:%d", ruby_sourcefile, ruby_sourceline);
}
}
- return rb_sprintf("%s:%d", file, line);
}
-#define warn_print(x) rb_write_error(x)
-#define warn_print2(x,l) rb_write_error2(x,l)
-
-static void
-error_pos(void)
-{
- VALUE pos = error_line(ruby_frame, 0);
- warn_printf("%s", StringValueCStr(pos));
-}
+VALUE rb_check_backtrace(VALUE);
static VALUE
-get_backtrace(VALUE info)
+get_backtrace(info)
+ VALUE info;
{
if (NIL_P(info)) return Qnil;
info = rb_funcall(info, rb_intern("backtrace"), 0);
if (NIL_P(info)) return Qnil;
- return rb_check_array_type(info);
+ return rb_check_backtrace(info);
}
static void
-set_backtrace(VALUE info, VALUE bt)
+set_backtrace(info, bt)
+ VALUE info, bt;
{
rb_funcall(info, rb_intern("set_backtrace"), 1, bt);
}
static void
-error_print(void)
+error_print()
{
VALUE errat = Qnil; /* OK */
volatile VALUE eclass, e;
- const char *einfo;
+ char *einfo;
long elen;
if (NIL_P(ruby_errinfo)) return;
@@ -1234,24 +1251,24 @@ error_print(void)
else
warn_printf("%d", ruby_sourceline);
}
- else if (RARRAY_LEN(errat) == 0) {
+ else if (RARRAY(errat)->len == 0) {
error_pos();
}
else {
- VALUE mesg = RARRAY_PTR(errat)[0];
+ VALUE mesg = RARRAY(errat)->ptr[0];
if (NIL_P(mesg)) error_pos();
else {
- warn_print2(RSTRING_PTR(mesg), RSTRING_LEN(mesg));
+ warn_print2(RSTRING(mesg)->ptr, RSTRING(mesg)->len);
}
}
eclass = CLASS_OF(ruby_errinfo);
if (EXEC_TAG() == 0) {
- e = rb_funcall(ruby_errinfo, rb_intern("message"), 0, 0);
- StringValue(e);
- einfo = RSTRING_PTR(e);
- elen = RSTRING_LEN(e);
+ e = rb_funcall(ruby_errinfo, rb_intern("message"), 0, 0);
+ StringValue(e);
+ einfo = RSTRING(e)->ptr;
+ elen = RSTRING(e)->len;
}
else {
einfo = "";
@@ -1267,15 +1284,15 @@ error_print(void)
epath = rb_class_name(eclass);
if (elen == 0) {
warn_print(": ");
- warn_print2(RSTRING_PTR(epath), RSTRING_LEN(epath));
+ warn_print2(RSTRING(epath)->ptr, RSTRING(epath)->len);
warn_print("\n");
}
else {
char *tail = 0;
long len = elen;
- if (RSTRING_PTR(epath)[0] == '#') epath = 0;
- if (tail = memchr(einfo, '\n', elen)) {
+ if (RSTRING(epath)->ptr[0] == '#') epath = 0;
+ if ((tail = memchr(einfo, '\n', elen)) != 0) {
len = tail - einfo;
tail++; /* skip newline */
}
@@ -1283,30 +1300,33 @@ error_print(void)
warn_print2(einfo, len);
if (epath) {
warn_print(" (");
- warn_print2(RSTRING_PTR(epath), RSTRING_LEN(epath));
+ warn_print2(RSTRING(epath)->ptr, RSTRING(epath)->len);
warn_print(")\n");
}
- if (tail) {
+ if (tail && elen>len+1) {
warn_print2(tail, elen-len-1);
+ if (einfo[elen-1] != '\n') warn_print2("\n", 1);
}
}
}
if (!NIL_P(errat)) {
long i;
+ struct RArray *ep = RARRAY(errat);
#define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5)
#define TRACE_HEAD 8
#define TRACE_TAIL 5
- for (i=1; i<RARRAY_LEN(errat); i++) {
- if (TYPE(RARRAY_PTR(errat)[i]) == T_STRING) {
- warn_printf("\tfrom %s\n", RSTRING_PTR(RARRAY_PTR(errat)[i]));
+ ep = RARRAY(errat);
+ for (i=1; i<ep->len; i++) {
+ if (TYPE(ep->ptr[i]) == T_STRING) {
+ warn_printf("\tfrom %s\n", RSTRING(ep->ptr[i])->ptr);
}
- if (i == TRACE_HEAD && RARRAY_LEN(errat) > TRACE_MAX) {
+ if (i == TRACE_HEAD && ep->len > TRACE_MAX) {
warn_printf("\t ... %ld levels...\n",
- RARRAY_LEN(errat) - TRACE_HEAD - TRACE_TAIL);
- i = RARRAY_LEN(errat) - TRACE_TAIL;
+ ep->len - TRACE_HEAD - TRACE_TAIL);
+ i = ep->len - TRACE_TAIL;
}
}
}
@@ -1321,35 +1341,34 @@ extern char **environ;
#endif
char **rb_origenviron;
-void rb_call_inits(void);
-void Init_stack(VALUE*);
-void Init_heap(void);
-void Init_ext(void);
+void rb_call_inits _((void));
+void Init_stack _((VALUE*));
+void Init_heap _((void));
+void Init_ext _((void));
#ifdef HAVE_NATIVETHREAD
static rb_nativethread_t ruby_thid;
-int
-is_ruby_native_thread(void)
-{
+int
+is_ruby_native_thread() {
return NATIVETHREAD_EQUAL(ruby_thid, NATIVETHREAD_CURRENT());
}
# ifdef HAVE_NATIVETHREAD_KILL
void
-ruby_native_thread_kill(int sig)
+ruby_native_thread_kill(sig)
+ int sig;
{
NATIVETHREAD_KILL(ruby_thid, sig);
}
# endif
#endif
-NORETURN(static void rb_thread_start_1(void));
-
void
-ruby_init(void)
+ruby_init()
{
static int initialized = 0;
static struct FRAME frame;
+ static struct iter iter;
int state;
if (initialized)
@@ -1360,6 +1379,7 @@ ruby_init(void)
#endif
ruby_frame = top_frame = &frame;
+ ruby_iter = &iter;
#ifdef __MACOS__
rb_origenviron = 0;
@@ -1370,13 +1390,16 @@ ruby_init(void)
Init_stack((void*)&state);
Init_heap();
PUSH_SCOPE();
+ ruby_scope->local_vars = 0;
+ ruby_scope->local_tbl = 0;
top_scope = ruby_scope;
/* default visibility is private at toplevel */
- VIS_SET(VIS_PRIVATE);
+ SCOPE_SET(SCOPE_PRIVATE);
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
rb_call_inits();
+ ruby_class = rb_cObject;
ruby_frame->self = ruby_top_self;
ruby_top_cref = rb_node_newnode(NODE_CREF,rb_cObject,0,0);
ruby_cref = ruby_top_cref;
@@ -1401,24 +1424,25 @@ ruby_init(void)
}
static VALUE
-eval_node(VALUE self, NODE *node)
+eval_node(self, node)
+ VALUE self;
+ NODE *node;
{
- if (!node) return Qnil;
- if (nd_type(node) == NODE_PRELUDE) {
- rb_eval(self, node->nd_head);
- node = node->nd_body;
+ NODE *beg_tree = ruby_eval_tree_begin;
+
+ ruby_eval_tree_begin = 0;
+ if (beg_tree) {
+ rb_eval(self, beg_tree);
}
+
if (!node) return Qnil;
return rb_eval(self, node);
}
int ruby_in_eval;
-static void rb_thread_cleanup(void);
-static void rb_thread_wait_other_threads(void);
-
-static int thread_set_raised(void);
-static int thread_reset_raised(void);
+static void rb_thread_cleanup _((void));
+static void rb_thread_wait_other_threads _((void));
static int thread_no_ensure _((void));
@@ -1426,18 +1450,22 @@ static VALUE exception_error;
static VALUE sysstack_error;
static int
-sysexit_status(VALUE err)
+sysexit_status(err)
+ VALUE err;
{
VALUE st = rb_iv_get(err, "status");
return NUM2INT(st);
}
static int
-error_handle(int ex)
+error_handle(ex)
+ int ex;
{
int status = EXIT_FAILURE;
+ rb_thread_t th = curr_thread;
- if (thread_set_raised()) return EXIT_FAILURE;
+ if (rb_thread_set_raised(th))
+ return EXIT_FAILURE;
switch (ex & TAG_MASK) {
case 0:
status = EXIT_SUCCESS;
@@ -1479,6 +1507,9 @@ error_handle(int ex)
if (rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
status = sysexit_status(ruby_errinfo);
}
+ else if (rb_obj_is_instance_of(ruby_errinfo, rb_eSignal)) {
+ /* no message when exiting by signal */
+ }
else {
error_print();
}
@@ -1487,35 +1518,34 @@ error_handle(int ex)
rb_bug("Unknown longjmp status %d", ex);
break;
}
- thread_reset_raised();
+ rb_thread_reset_raised(th);
return status;
}
void
-ruby_options(int argc, char **argv)
+ruby_options(argc, argv)
+ int argc;
+ char **argv;
{
int state;
Init_stack((void*)&state);
- PUSH_THREAD_TAG();
+ PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
ruby_process_options(argc, argv);
}
else {
- if (state == TAG_THREAD) {
- rb_thread_start_1();
- }
trace_func = 0;
tracing = 0;
exit(error_handle(state));
}
- POP_THREAD_TAG();
+ POP_TAG();
}
-void rb_exec_end_proc(void);
+void rb_exec_end_proc _((void));
static void
-ruby_finalize_0(void)
+ruby_finalize_0()
{
PUSH_TAG(PROT_NONE);
if (EXEC_TAG() == 0) {
@@ -1526,7 +1556,7 @@ ruby_finalize_0(void)
}
static void
-ruby_finalize_1(void)
+ruby_finalize_1()
{
signal(SIGINT, SIG_DFL);
ruby_errinfo = 0;
@@ -1536,67 +1566,97 @@ ruby_finalize_1(void)
}
void
-ruby_finalize(void)
+ruby_finalize()
{
ruby_finalize_0();
ruby_finalize_1();
}
int
-ruby_cleanup(int ex)
+ruby_cleanup(ex)
+ int ex;
{
int state;
- volatile VALUE err = ruby_errinfo;
+ volatile VALUE errs[2];
+ int nerr;
+ errs[1] = ruby_errinfo;
ruby_safe_level = 0;
- Init_stack((void*)&state);
- PUSH_THREAD_TAG();
+ Init_stack((void *)&state);
+ ruby_finalize_0();
+ errs[0] = ruby_errinfo;
+ PUSH_TAG(PROT_NONE);
+ PUSH_ITER(ITER_NOT);
if ((state = EXEC_TAG()) == 0) {
- ruby_finalize_0();
- if (ruby_errinfo) err = ruby_errinfo;
rb_thread_cleanup();
rb_thread_wait_other_threads();
}
- else if (state == TAG_THREAD) {
- rb_thread_start_1();
- }
else if (ex == 0) {
ex = state;
}
- ruby_errinfo = err;
+ POP_ITER();
+ ruby_errinfo = errs[1];
ex = error_handle(ex);
ruby_finalize_1();
- POP_THREAD_TAG();
+ POP_TAG();
+
+ for (nerr = 0; nerr < sizeof(errs) / sizeof(errs[0]); ++nerr) {
+ VALUE err = errs[nerr];
+
+ if (!RTEST(err)) continue;
+
+ if (rb_obj_is_kind_of(err, rb_eSystemExit)) {
+ return sysexit_status(err);
+ }
+ 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 (err && rb_obj_is_kind_of(err, rb_eSystemExit)) {
- VALUE st = rb_iv_get(err, "status");
- return NUM2INT(st);
+#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;
}
-extern NODE *ruby_eval_tree;
-
static int
-ruby_exec_internal(void)
+ruby_exec_internal()
{
int state;
- PUSH_THREAD_TAG();
+ PUSH_TAG(PROT_NONE);
+ PUSH_ITER(ITER_NOT);
/* default visibility is private at toplevel */
- VIS_SET(VIS_PRIVATE);
+ SCOPE_SET(SCOPE_PRIVATE);
if ((state = EXEC_TAG()) == 0) {
eval_node(ruby_top_self, ruby_eval_tree);
}
- else if (state == TAG_THREAD) {
- rb_thread_start_1();
- }
- POP_THREAD_TAG();
+ POP_ITER();
+ POP_TAG();
return state;
}
+void
+ruby_stop(ex)
+ int ex;
+{
+ exit(ruby_cleanup(ex));
+}
+
int
-ruby_exec(void)
+ruby_exec()
{
volatile NODE *tmp;
@@ -1605,13 +1665,7 @@ ruby_exec(void)
}
void
-ruby_stop(int ex)
-{
- exit(ruby_cleanup(ex));
-}
-
-void
-ruby_run(void)
+ruby_run()
{
int state;
static int ex;
@@ -1623,7 +1677,8 @@ ruby_run(void)
}
static void
-compile_error(const char *at)
+compile_error(at)
+ const char *at;
{
VALUE str;
@@ -1641,7 +1696,8 @@ compile_error(const char *at)
}
VALUE
-rb_eval_string(const char *str)
+rb_eval_string(str)
+ const char *str;
{
VALUE v;
NODE *oldsrc = ruby_current_node;
@@ -1655,24 +1711,31 @@ rb_eval_string(const char *str)
}
VALUE
-rb_eval_string_protect(const char *str, int *state)
+rb_eval_string_protect(str, state)
+ const char *str;
+ int *state;
{
- return rb_protect((VALUE (*)(VALUE))rb_eval_string, (VALUE)str, state);
+ return rb_protect((VALUE (*)_((VALUE)))rb_eval_string, (VALUE)str, state);
}
VALUE
-rb_eval_string_wrap(const char *str, int *state)
+rb_eval_string_wrap(str, state)
+ const char *str;
+ int *state;
{
int status;
VALUE self = ruby_top_self;
VALUE wrapper = ruby_wrapper;
VALUE val;
+ PUSH_CLASS(ruby_wrapper = rb_module_new());
ruby_top_self = rb_obj_clone(ruby_top_self);
rb_extend_object(ruby_top_self, ruby_wrapper);
- PUSH_FRAME(Qfalse);
+ PUSH_FRAME();
+ ruby_frame->last_func = 0;
+ ruby_frame->last_class = 0;
ruby_frame->self = self;
- PUSH_CREF(ruby_wrapper = rb_module_new());
+ PUSH_CREF(ruby_wrapper);
PUSH_SCOPE();
val = rb_eval_string_protect(str, &status);
@@ -1680,6 +1743,7 @@ rb_eval_string_wrap(const char *str, int *state)
POP_SCOPE();
POP_FRAME();
+ POP_CLASS();
ruby_wrapper = wrapper;
if (state) {
*state = status;
@@ -1690,9 +1754,12 @@ rb_eval_string_wrap(const char *str, int *state)
return val;
}
-NORETURN(static void localjump_error(const char*, VALUE, int, VALUE));
+NORETURN(static void localjump_error(const char*, VALUE, int));
static void
-localjump_error(const char *mesg, VALUE value, int reason, VALUE bt)
+localjump_error(mesg, value, reason)
+ const char *mesg;
+ VALUE value;
+ int reason;
{
VALUE exc = rb_exc_new2(rb_eLocalJumpError, mesg);
ID id;
@@ -1710,10 +1777,9 @@ localjump_error(const char *mesg, VALUE value, int reason, VALUE bt)
case TAG_RETURN:
id = rb_intern("return"); break;
default:
- id = rb_intern("yield"); break;
+ id = rb_intern("noreason"); break;
}
rb_iv_set(exc, "@reason", ID2SYM(id));
- if (bt) set_backtrace(exc, bt);
rb_exc_raise(exc);
}
@@ -1724,7 +1790,8 @@ localjump_error(const char *mesg, VALUE value, int reason, VALUE bt)
* Returns the exit value associated with this +LocalJumpError+.
*/
static VALUE
-localjump_xvalue(VALUE exc)
+localjump_xvalue(exc)
+ VALUE exc;
{
return rb_iv_get(exc, "@exit_value");
}
@@ -1734,18 +1801,21 @@ localjump_xvalue(VALUE exc)
* local_jump_error.reason => symbol
*
* The reason this block was terminated:
- * :break, :redo, :retry, :next, :return, or :yield.
+ * :break, :redo, :retry, :next, :return, or :noreason.
*/
static VALUE
-localjump_reason(VALUE exc)
+localjump_reason(exc)
+ VALUE exc;
{
return rb_iv_get(exc, "@reason");
}
-NORETURN(static void jump_tag_but_local_jump(int,VALUE));
+NORETURN(static void jump_tag_but_local_jump _((int,VALUE)));
static void
-jump_tag_but_local_jump(int state, VALUE val)
+jump_tag_but_local_jump(state, val)
+ int state;
+ VALUE val;
{
if (val == Qundef) val = prot_tag->retval;
@@ -1753,19 +1823,19 @@ jump_tag_but_local_jump(int state, VALUE val)
case 0:
break;
case TAG_RETURN:
- localjump_error("unexpected return", val, state, 0);
+ localjump_error("unexpected return", val, state);
break;
case TAG_BREAK:
- localjump_error("unexpected break", val, state, 0);
+ localjump_error("unexpected break", val, state);
break;
case TAG_NEXT:
- localjump_error("unexpected next", val, state, 0);
+ localjump_error("unexpected next", val, state);
break;
case TAG_REDO:
- localjump_error("unexpected redo", Qnil, state, 0);
+ localjump_error("unexpected redo", Qnil, state);
break;
case TAG_RETRY:
- localjump_error("retry outside of rescue clause", Qnil, state, 0);
+ localjump_error("retry outside of rescue clause", Qnil, state);
break;
default:
break;
@@ -1774,7 +1844,9 @@ jump_tag_but_local_jump(int state, VALUE val)
}
VALUE
-rb_eval_cmd(VALUE cmd, VALUE arg, int level)
+rb_eval_cmd(cmd, arg, level)
+ VALUE cmd, arg;
+ int level;
{
int state;
VALUE val = Qnil; /* OK */
@@ -1785,21 +1857,24 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
level = 4;
}
if (TYPE(cmd) != T_STRING) {
+ PUSH_ITER(ITER_NOT);
PUSH_TAG(PROT_NONE);
ruby_safe_level = level;
if ((state = EXEC_TAG()) == 0) {
- val = rb_funcall2(cmd, rb_intern("yield"),
- RARRAY_LEN(arg), RARRAY_PTR(arg));
+ val = rb_funcall2(cmd, rb_intern("call"), RARRAY(arg)->len, RARRAY(arg)->ptr);
}
ruby_safe_level = safe;
POP_TAG();
+ POP_ITER();
if (state) JUMP_TAG(state);
return val;
}
saved_scope = ruby_scope;
ruby_scope = top_scope;
- PUSH_FRAME(Qfalse);
+ PUSH_FRAME();
+ ruby_frame->last_func = 0;
+ ruby_frame->last_class = 0;
ruby_frame->self = ruby_top_self;
PUSH_CREF(ruby_wrapper ? ruby_wrapper : rb_cObject);
@@ -1816,35 +1891,66 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
POP_TAG();
POP_FRAME();
- jump_tag_but_local_jump(state, val);
+ if (state) jump_tag_but_local_jump(state, val);
return val;
}
#define ruby_cbase (ruby_cref->nd_clss)
-VALUE
-ruby_current_class_object()
-{
- return ruby_cbase;
-}
static VALUE
-ev_const_defined(ID id, VALUE self)
+ev_const_defined(cref, id, self)
+ NODE *cref;
+ ID id;
+ VALUE self;
{
- VALUE cbase = ruby_cbase;
- if (NIL_P(cbase)) cbase = rb_obj_class(self);
- return rb_const_defined_fallback(cbase, id, ruby_cref->nd_next);
+ NODE *cbase = cref;
+ VALUE result;
+
+ while (cbase && cbase->nd_next) {
+ struct RClass *klass = RCLASS(cbase->nd_clss);
+
+ if (!NIL_P(klass)) {
+ if (klass->iv_tbl && st_lookup(klass->iv_tbl, id, &result)) {
+ if (result == Qundef && NIL_P(rb_autoload_p((VALUE)klass, id))) {
+ return Qfalse;
+ }
+ return Qtrue;
+ }
+ }
+ cbase = cbase->nd_next;
+ }
+ return rb_const_defined(cref->nd_clss, id);
}
static VALUE
-ev_const_get(ID id, VALUE self)
+ev_const_get(cref, id, self)
+ NODE *cref;
+ ID id;
+ VALUE self;
{
- VALUE cbase = ruby_cbase;
- if (NIL_P(cbase)) cbase = rb_obj_class(self);
- return rb_const_get_fallback(cbase, id, ruby_cref->nd_next);
+ NODE *cbase = cref;
+ VALUE result;
+
+ while (cbase && cbase->nd_next) {
+ VALUE klass = cbase->nd_clss;
+
+ if (!NIL_P(klass)) {
+ while (RCLASS(klass)->iv_tbl &&
+ st_lookup(RCLASS(klass)->iv_tbl, id, &result)) {
+ if (result == Qundef) {
+ if (!RTEST(rb_autoload_load(klass, id))) break;
+ continue;
+ }
+ return result;
+ }
+ }
+ cbase = cbase->nd_next;
+ }
+ return rb_const_get(NIL_P(cref->nd_clss) ? CLASS_OF(self): cref->nd_clss, id);
}
static VALUE
-cvar_cbase(void)
+cvar_cbase()
{
NODE *cref = ruby_cref;
@@ -1876,7 +1982,7 @@ cvar_cbase(void)
*/
static VALUE
-rb_mod_nesting(void)
+rb_mod_nesting()
{
NODE *cbase = ruby_cref;
VALUE ary = rb_ary_new();
@@ -1885,7 +1991,7 @@ rb_mod_nesting(void)
if (!NIL_P(cbase->nd_clss)) rb_ary_push(ary, cbase->nd_clss);
cbase = cbase->nd_next;
}
- if (ruby_wrapper && RARRAY_LEN(ary) == 0) {
+ if (ruby_wrapper && RARRAY(ary)->len == 0) {
rb_ary_push(ary, ruby_wrapper);
}
return ary;
@@ -1906,7 +2012,7 @@ rb_mod_nesting(void)
*/
static VALUE
-rb_mod_s_constants(void)
+rb_mod_s_constants()
{
NODE *cbase = ruby_cref;
void *data = 0;
@@ -1918,16 +2024,17 @@ rb_mod_s_constants(void)
cbase = cbase->nd_next;
}
- if (NIL_P(ruby_cbase)) {
+ if (!NIL_P(ruby_cbase)) {
data = rb_mod_const_of(ruby_cbase, data);
}
return rb_const_list(data);
}
void
-rb_frozen_class_p(VALUE klass)
+rb_frozen_class_p(klass)
+ VALUE klass;
{
- const char *desc = "something(?!)";
+ char *desc = "something(?!)";
if (OBJ_FROZEN(klass)) {
if (FL_TEST(klass, FL_SINGLETON))
@@ -1946,7 +2053,9 @@ rb_frozen_class_p(VALUE klass)
}
void
-rb_undef(VALUE klass, ID id)
+rb_undef(klass, id)
+ VALUE klass;
+ ID id;
{
VALUE origin;
NODE *body;
@@ -1958,12 +2067,12 @@ rb_undef(VALUE klass, ID id)
rb_raise(rb_eSecurityError, "Insecure: can't undef `%s'", rb_id2name(id));
}
rb_frozen_class_p(klass);
- if (id == object_id || id == __send || id == __send_bang || id == init) {
+ if (id == __id__ || id == __send__ || id == init) {
rb_warn("undefining `%s' may cause serious problem", rb_id2name(id));
}
- body = search_method(klass, id, &origin, LOOKUP_NOSKIP, 0);
+ body = search_method(klass, id, &origin);
if (!body || !body->nd_body) {
- const char *s0 = " class";
+ char *s0 = " class";
VALUE c = klass;
if (FL_TEST(c, FL_SINGLETON)) {
@@ -2036,7 +2145,10 @@ rb_undef(VALUE klass, ID id)
*/
static VALUE
-rb_mod_undef_method(int argc, VALUE *argv, VALUE mod)
+rb_mod_undef_method(argc, argv, mod)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
{
int i;
@@ -2047,25 +2159,28 @@ rb_mod_undef_method(int argc, VALUE *argv, VALUE mod)
}
void
-rb_alias(VALUE klass, ID name, ID def)
+rb_alias(klass, name, def)
+ VALUE klass;
+ ID name, def;
{
VALUE origin;
NODE *orig, *body, *node;
VALUE singleton = 0;
+ st_data_t data;
rb_frozen_class_p(klass);
if (name == def) return;
if (klass == rb_cObject) {
rb_secure(4);
}
- orig = search_method(klass, def, &origin, LOOKUP_NOSKIP, 0);
+ orig = search_method(klass, def, &origin);
if (!orig || !orig->nd_body) {
if (TYPE(klass) == T_MODULE) {
- orig = search_method(rb_cObject, def, &origin, LOOKUP_NOSKIP, 0);
+ orig = search_method(rb_cObject, def, &origin);
}
}
if (!orig || !orig->nd_body) {
- raise_undef(klass, def);
+ print_undef(klass, def);
}
if (FL_TEST(klass, FL_SINGLETON)) {
singleton = rb_iv_get(klass, "__attached__");
@@ -2079,7 +2194,8 @@ rb_alias(VALUE klass, ID name, ID def)
}
rb_clear_cache_by_id(name);
- if (RTEST(ruby_verbose) && st_lookup(RCLASS(klass)->m_tbl, name, (st_data_t *)&node)) {
+ if (RTEST(ruby_verbose) && st_lookup(RCLASS(klass)->m_tbl, name, &data)) {
+ node = (NODE *)data;
if (node->nd_cnt == 0 && node->nd_body) {
rb_warning("discarding old %s", rb_id2name(name));
}
@@ -2087,6 +2203,9 @@ rb_alias(VALUE klass, ID name, ID def)
st_insert(RCLASS(klass)->m_tbl, name,
(st_data_t)NEW_METHOD(NEW_FBODY(body, def, origin),
NOEX_WITH_SAFE(orig->nd_noex)));
+
+ if (!ruby_running) return;
+
if (singleton) {
rb_funcall(singleton, singleton_added, 1, ID2SYM(name));
}
@@ -2118,17 +2237,19 @@ rb_alias(VALUE klass, ID name, ID def)
*/
static VALUE
-rb_mod_alias_method(VALUE mod, VALUE newname, VALUE oldname)
+rb_mod_alias_method(mod, newname, oldname)
+ VALUE mod, newname, oldname;
{
rb_alias(mod, rb_to_id(newname), rb_to_id(oldname));
return mod;
}
-static NODE*
-copy_node_scope(NODE *node, NODE *rval)
+NODE *
+rb_copy_node_scope(node, rval)
+ NODE *node;
+ NODE *rval;
{
- NODE *cref = NEW_NODE(NODE_CREF,rval->nd_clss,0,rval->nd_next);
- NODE *copy = NEW_NODE(NODE_SCOPE,0,cref,node->nd_next);
+ NODE *copy = NEW_NODE(NODE_SCOPE,0,rval,node->nd_next);
if (node->nd_tbl) {
copy->nd_tbl = ALLOC_N(ID, node->nd_tbl[0]+1);
@@ -2151,21 +2272,17 @@ copy_node_scope(NODE *node, NODE *rval)
# define TMP_ALLOC(n) ALLOCA_N(VALUE,n)
#endif
-#define CALLARGS int argc; VALUE *argv; struct BLOCK *block = 0, _block
#define SETUP_ARGS0(anode,extra) do {\
- NODE *n = anode, *bpass = 0;\
- if (n && nd_type(n) == NODE_BLOCK_PASS) {\
- bpass = n;\
- n = n->nd_head;\
- }\
+ NODE *n = anode;\
if (!n) {\
argc = 0;\
argv = 0;\
}\
else if (nd_type(n) == NODE_ARRAY) {\
- argc=n->nd_alen;\
+ argc=anode->nd_alen;\
if (argc > 0) {\
int i;\
+ n = anode;\
argv = TMP_ALLOC(argc+extra);\
for (i=0;i<argc;i++) {\
argv[i] = rb_eval(self,n->nd_head);\
@@ -2181,39 +2298,40 @@ copy_node_scope(NODE *node, NODE *rval)
VALUE args = rb_eval(self,n);\
if (TYPE(args) != T_ARRAY)\
args = rb_ary_to_ary(args);\
- argc = RARRAY_LEN(args);\
+ argc = RARRAY(args)->len;\
argv = TMP_ALLOC(argc+extra);\
- MEMCPY(argv, RARRAY_PTR(args), VALUE, argc);\
- }\
- if (bpass) {\
- volatile VALUE save_block = rb_eval(self, bpass->nd_body); \
- block = passing_block(save_block, &_block);\
+ MEMCPY(argv, RARRAY(args)->ptr, VALUE, argc);\
}\
} while (0)
#define SETUP_ARGS(anode) SETUP_ARGS0(anode,0)
-#define ZSUPER_ARGS() do {\
- argc = ruby_frame->argc;\
- if (argc && DMETHOD_P()) {\
- if (TYPE(RBASIC(ruby_scope)->klass) != T_ARRAY ||\
- RARRAY_LEN(RBASIC(ruby_scope)->klass) != argc) {\
- rb_raise(rb_eRuntimeError, \
- "super: specify arguments explicitly");\
- }\
- argv = RARRAY_PTR(RBASIC(ruby_scope)->klass);\
+#define BEGIN_CALLARGS do {\
+ struct BLOCK *tmp_block = ruby_block;\
+ int tmp_iter = ruby_iter->iter;\
+ switch (tmp_iter) {\
+ case ITER_PRE:\
+ if (ruby_block) ruby_block = ruby_block->outer;\
+ case ITER_PAS:\
+ tmp_iter = ITER_NOT;\
}\
- else {\
- argv = ruby_scope->local_vars + 2;\
- }\
-} while (0)
+ PUSH_ITER(tmp_iter)
+
+#define END_CALLARGS \
+ ruby_block = tmp_block;\
+ POP_ITER();\
+} while (0)
#define MATCH_DATA *rb_svar(node->nd_cnt)
-static const char* is_defined(VALUE, NODE*, char*, int);
+static char* is_defined _((VALUE, NODE*, char*));
static char*
-arg_defined(VALUE self, NODE *node, char *buf, char *type)
+arg_defined(self, node, buf, type)
+ VALUE self;
+ NODE *node;
+ char *buf;
+ char *type;
{
int argc;
int i;
@@ -2223,33 +2341,36 @@ arg_defined(VALUE self, NODE *node, char *buf, char *type)
argc=node->nd_alen;
if (argc > 0) {
for (i=0;i<argc;i++) {
- if (!is_defined(self, node->nd_head, buf, 0))
+ if (!is_defined(self, node->nd_head, buf))
return 0;
node = node->nd_next;
}
}
}
- else if (!is_defined(self, node, buf, 0)) {
+ else if (!is_defined(self, node, buf)) {
return 0;
}
return type;
}
-static const char*
-is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval)
+static char*
+is_defined(self, node, buf)
+ VALUE self;
+ NODE *node; /* OK */
+ char *buf;
{
VALUE val; /* OK */
- int state, noex;
- static const char *ex = "expression";
+ int state;
- if (!node) return ex;
+ again:
+ if (!node) return "expression";
switch (nd_type(node)) {
case NODE_SUPER:
case NODE_ZSUPER:
- if (ruby_frame->this_func == 0) return 0;
- else if (ruby_frame->this_class == 0) return 0;
- val = ruby_frame->this_class;
- if (method_exists(RCLASS(val)->super, ruby_frame->this_func, LOOKUP_FCALL)) {
+ if (ruby_frame->last_func == 0) return 0;
+ else if (ruby_frame->last_class == 0) return 0;
+ val = ruby_frame->last_class;
+ if (rb_method_boundp(RCLASS(val)->super, ruby_frame->orig_func, 0)) {
if (nd_type(node) == NODE_SUPER) {
return arg_defined(self, node->nd_args, buf, "super");
}
@@ -2260,30 +2381,40 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval)
case NODE_VCALL:
case NODE_FCALL:
val = self;
- noex = LOOKUP_FCALL;
goto check_bound;
case NODE_ATTRASGN:
val = self;
if (node->nd_recv == (NODE *)1) goto check_bound;
case NODE_CALL:
- if (!is_defined(self, node->nd_recv, buf, Qtrue)) return 0;
- if (noeval) return ex;
- noex = LOOKUP_NORMAL;
- val = rb_eval(self, node->nd_recv);
+ PUSH_TAG(PROT_NONE);
+ if ((state = EXEC_TAG()) == 0) {
+ val = rb_eval(self, node->nd_recv);
+ }
+ POP_TAG();
+ if (state) {
+ ruby_errinfo = Qnil;
+ return 0;
+ }
check_bound:
{
- ID id = node->nd_mid;
+ int call = nd_type(node)==NODE_CALL;
val = CLASS_OF(val);
- if (!rb_get_method_body(&val, &id, &noex))
- return 0;
- if (nd_type(node) == NODE_CALL) {
- if ((noex & NOEX_PRIVATE)) return 0;
+ if (call) {
+ int noex;
+ ID id = node->nd_mid;
+
+ if (!rb_get_method_body(&val, &id, &noex))
+ break;
+ if ((noex & NOEX_PRIVATE))
+ break;
if ((noex & NOEX_PROTECTED) &&
!rb_obj_is_kind_of(self, rb_class_real(val)))
- return 0;
+ break;
}
+ else if (!rb_method_boundp(val, node->nd_mid, call))
+ break;
return arg_defined(self, node->nd_args, buf,
nd_type(node) == NODE_ATTRASGN ?
"assignment" : "method");
@@ -2315,6 +2446,8 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval)
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:
@@ -2344,7 +2477,7 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval)
break;
case NODE_CONST:
- if (ev_const_defined(node->nd_vid, self)) {
+ if (ev_const_defined(ruby_cref, node->nd_vid, self)) {
return "constant";
}
break;
@@ -2356,18 +2489,26 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval)
break;
case NODE_COLON2:
- if (!is_defined(self, node->nd_recv, buf, Qtrue)) return 0;
- if (noeval) return ex;
- val = rb_eval(self, node->nd_recv);
- switch (TYPE(val)) {
- case T_CLASS:
- case T_MODULE:
- if (rb_const_defined_from(val, node->nd_mid))
- return "constant";
- break;
- default:
- if (rb_method_boundp(CLASS_OF(val), node->nd_mid, Qtrue)) {
- return "method";
+ PUSH_TAG(PROT_NONE);
+ if ((state = EXEC_TAG()) == 0) {
+ val = rb_eval(self, node->nd_head);
+ }
+ POP_TAG();
+ if (state) {
+ ruby_errinfo = Qnil;
+ return 0;
+ }
+ else {
+ switch (TYPE(val)) {
+ case T_CLASS:
+ case T_MODULE:
+ if (rb_const_defined_from(val, node->nd_mid))
+ return "constant";
+ break;
+ default:
+ if (rb_method_boundp(CLASS_OF(val), node->nd_mid, 1)) {
+ return "method";
+ }
}
}
break;
@@ -2380,7 +2521,6 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval)
case NODE_NTH_REF:
if (RTEST(rb_reg_nth_defined(node->nd_nth, MATCH_DATA))) {
- if (!buf) return ex;
sprintf(buf, "$%d", (int)node->nd_nth);
return buf;
}
@@ -2388,12 +2528,15 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval)
case NODE_BACK_REF:
if (RTEST(rb_reg_nth_defined(0, MATCH_DATA))) {
- if (!buf) return ex;
sprintf(buf, "$%c", (char)node->nd_nth);
return buf;
}
break;
+ case NODE_NEWLINE:
+ node = node->nd_next;
+ goto again;
+
default:
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
@@ -2401,7 +2544,7 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval)
}
POP_TAG();
if (!state) {
- return ex;
+ return "expression";
}
ruby_errinfo = Qnil;
break;
@@ -2409,12 +2552,13 @@ is_defined(VALUE self, NODE *node /* OK */, char *buf, int noeval)
return 0;
}
-static int handle_rescue(VALUE,NODE*);
+static int handle_rescue _((VALUE,NODE*));
-static void blk_free(struct BLOCK *data);
+static void blk_free();
static VALUE
-rb_obj_is_proc(VALUE proc)
+rb_obj_is_proc(proc)
+ VALUE proc;
{
if (TYPE(proc) == T_DATA && RDATA(proc)->dfree == (RUBY_DATA_FUNC)blk_free) {
return Qtrue;
@@ -2423,7 +2567,9 @@ rb_obj_is_proc(VALUE proc)
}
void
-rb_add_event_hook(rb_event_hook_func_t func, rb_event_t events)
+rb_add_event_hook(func, events)
+ rb_event_hook_func_t func;
+ rb_event_t events;
{
rb_event_hook_t *hook;
@@ -2435,9 +2581,9 @@ rb_add_event_hook(rb_event_hook_func_t func, rb_event_t events)
}
int
-rb_remove_event_hook(rb_event_hook_func_t func)
+rb_remove_event_hook(func)
+ rb_event_hook_func_t func;
{
-
rb_event_hook_t *prev, *hook;
prev = NULL;
@@ -2504,7 +2650,8 @@ rb_remove_event_hook(rb_event_hook_func_t func)
static VALUE
-set_trace_func(VALUE obj, VALUE trace)
+set_trace_func(obj, trace)
+ VALUE obj, trace;
{
rb_event_hook_t *hook;
@@ -2526,7 +2673,7 @@ set_trace_func(VALUE obj, VALUE trace)
return trace;
}
-static const char *
+static char *
get_event_name(rb_event_t event)
{
switch (event) {
@@ -2552,27 +2699,34 @@ get_event_name(rb_event_t event)
}
static void
-call_trace_func(rb_event_t event, NODE *node, VALUE self, ID id, VALUE klass /* OK */)
+call_trace_func(event, node, self, id, klass)
+ rb_event_t event;
+ NODE *node;
+ VALUE self;
+ ID id;
+ VALUE klass; /* OK */
{
int state, raised;
struct FRAME *prev;
NODE *node_save;
VALUE srcfile;
- const char *event_name;
+ char *event_name;
+ rb_thread_t th = curr_thread;
if (!trace_func) return;
if (tracing) return;
+ if (ruby_in_compile) return;
if (id == ID_ALLOCATOR) return;
- if (!node && ruby_sourceline == 0) return;
if (!(node_save = ruby_current_node)) {
- node_save = NEW_BEGIN(0);
+ node_save = NEW_NEWLINE(0);
}
tracing = 1;
prev = ruby_frame;
- PUSH_FRAME(Qfalse);
+ PUSH_FRAME();
*ruby_frame = *prev;
ruby_frame->prev = prev;
+ ruby_frame->iter = 0; /* blocks not available anyway */
if (node) {
ruby_current_node = node;
@@ -2589,7 +2743,7 @@ call_trace_func(rb_event_t event, NODE *node, VALUE self, ID id, VALUE klass /*
}
}
PUSH_TAG(PROT_NONE);
- raised = thread_reset_raised();
+ raised = rb_thread_reset_raised(th);
if ((state = EXEC_TAG()) == 0) {
srcfile = rb_str_new2(ruby_sourcefile?ruby_sourcefile:"(ruby)");
event_name = get_event_name(event);
@@ -2597,11 +2751,11 @@ call_trace_func(rb_event_t event, NODE *node, VALUE self, ID id, VALUE klass /*
srcfile,
INT2FIX(ruby_sourceline),
id?ID2SYM(id):Qnil,
- self ? rb_f_binding(self) : Qnil,
- klass?klass:Qnil),
- Qundef, 0, 0);
+ self?rb_f_binding(self):Qnil,
+ klass),
+ Qundef, 0);
}
- if (raised) thread_set_raised();
+ if (raised) rb_thread_set_raised(th);
POP_TAG();
POP_FRAME();
@@ -2612,15 +2766,46 @@ call_trace_func(rb_event_t event, NODE *node, VALUE self, ID id, VALUE klass /*
}
static VALUE
-splat(VALUE v, int strict)
+avalue_to_svalue(v)
+ VALUE v;
{
- VALUE tmp;
+ VALUE tmp, top;
+
+ tmp = rb_check_array_type(v);
+ if (NIL_P(tmp)) {
+ return v;
+ }
+ if (RARRAY(tmp)->len == 0) {
+ return Qundef;
+ }
+ if (RARRAY(tmp)->len == 1) {
+ top = rb_check_array_type(RARRAY(tmp)->ptr[0]);
+ if (NIL_P(top)) {
+ return RARRAY(tmp)->ptr[0];
+ }
+ if (RARRAY(top)->len > 1) {
+ return v;
+ }
+ return top;
+ }
+ return tmp;
+}
+
+static VALUE
+svalue_to_avalue(v)
+ VALUE v;
+{
+ VALUE tmp, top;
if (v == Qundef) return rb_ary_new2(0);
- tmp = rb_check_convert_type(v, T_ARRAY, "Array", "to_splat");
+ tmp = rb_check_array_type(v);
if (NIL_P(tmp)) {
- if (strict) {
- rb_raise(rb_eTypeError, "failed to splat");
+ return rb_ary_new3(1, v);
+ }
+ if (RARRAY(tmp)->len == 1) {
+ top = rb_check_array_type(RARRAY(tmp)->ptr[0]);
+ if (!NIL_P(top) && RARRAY(top)->len > 1) {
+ return tmp;
}
return rb_ary_new3(1, v);
}
@@ -2628,19 +2813,77 @@ splat(VALUE v, int strict)
}
static VALUE
-svalue_to_avalue(VALUE v)
+svalue_to_mrhs(v, lhs)
+ VALUE v;
+ NODE *lhs;
{
- return splat(v, Qfalse);
+ VALUE tmp;
+
+ if (v == Qundef) return rb_ary_new2(0);
+ tmp = rb_check_array_type(v);
+ if (NIL_P(tmp)) {
+ return rb_ary_new3(1, v);
+ }
+ /* no lhs means splat lhs only */
+ if (!lhs) {
+ return rb_ary_new3(1, v);
+ }
+ return tmp;
}
static VALUE
-splat_value(VALUE v)
+avalue_splat(v)
+ VALUE v;
{
- return splat(v, Qtrue);
+ if (RARRAY(v)->len == 0) {
+ return Qundef;
+ }
+ if (RARRAY(v)->len == 1) {
+ return RARRAY(v)->ptr[0];
+ }
+ return v;
}
+#if 1
+VALUE
+rb_Array(val)
+ VALUE val;
+{
+ VALUE tmp = rb_check_array_type(val);
+
+ if (NIL_P(tmp)) {
+ /* hack to avoid invoke Object#to_a */
+ VALUE origin;
+ ID id = rb_intern("to_a");
+
+ if (search_method(CLASS_OF(val), id, &origin) &&
+ RCLASS(origin)->m_tbl != RCLASS(rb_mKernel)->m_tbl) { /* exclude Kernel#to_a */
+ val = rb_funcall(val, id, 0);
+ if (TYPE(val) != T_ARRAY) {
+ rb_raise(rb_eTypeError, "`to_a' did not return Array");
+ }
+ return val;
+ }
+ else {
+ return rb_ary_new3(1, val);
+ }
+ }
+ return tmp;
+}
+#endif
+
static VALUE
-class_prefix(VALUE self, NODE *cpath)
+splat_value(v)
+ VALUE v;
+{
+ if (NIL_P(v)) return rb_ary_new3(1, Qnil);
+ return rb_Array(v);
+}
+
+static VALUE
+class_prefix(self, cpath)
+ VALUE self;
+ NODE *cpath;
{
if (!cpath) {
rb_bug("class path missing");
@@ -2653,7 +2896,7 @@ class_prefix(VALUE self, NODE *cpath)
break;
default:
rb_raise(rb_eTypeError, "%s is not a class/module",
- RSTRING_PTR(rb_obj_as_string(c)));
+ RSTRING(rb_obj_as_string(c))->ptr);
}
return c;
}
@@ -2674,85 +2917,37 @@ class_prefix(VALUE self, NODE *cpath)
}\
} while (0)
-NORETURN(static void return_jump(VALUE));
-NORETURN(static void break_jump(VALUE));
-NORETURN(static void next_jump(VALUE));
-NORETURN(static void unknown_node(NODE * volatile));
-
-static VALUE call_super(int, const VALUE*, struct BLOCK*);
-static VALUE call_super_0(VALUE, VALUE, ID mid, int argc, const VALUE*, struct BLOCK *);
+NORETURN(static void return_jump _((VALUE)));
+NORETURN(static void break_jump _((VALUE)));
+NORETURN(static void next_jump _((VALUE)));
+NORETURN(static void unknown_node _((NODE * volatile)));
static void
-unknown_node(NODE *volatile node)
+unknown_node(node)
+ NODE *volatile node;
{
ruby_current_node = 0;
if (node->flags == 0) {
- rb_bug("terminated node (%p)", node);
+ rb_bug("terminated node (0x%lx)", node);
}
else if (BUILTIN_TYPE(node) != T_NODE) {
- rb_bug("not a node 0x%02lx (%p)", BUILTIN_TYPE(node), node);
+ rb_bug("not a node 0x%02lx (0x%lx)", BUILTIN_TYPE(node), node);
}
else {
- rb_bug("unknown node type %d (%p)", nd_type(node), node);
- }
-}
-
-static int
-when_cond(VALUE v1, VALUE v2)
-{
- if (v1 == Qundef) {
- return RTEST(v2);
- }
- return RTEST(rb_funcall2(v2, eqq, 1, &v1));
-}
-
-static int
-when_check(NODE *tag, VALUE val, VALUE self)
-{
- VALUE elm;
- long i;
-
- switch (nd_type(tag)) {
- case NODE_ARRAY:
- while (tag) {
- elm = rb_eval(self, tag->nd_head);
- if (when_cond(val, elm)) {
- return Qtrue;
- }
- tag = tag->nd_next;
- }
- break;
- case NODE_SPLAT:
- tag = tag->nd_head;
- splat:
- elm = splat_value(rb_eval(self, tag));
- for (i=0; i<RARRAY_LEN(elm); i++) {
- if (when_cond(val, RARRAY_PTR(elm)[i])) {
- return Qtrue;
- }
- }
- break;
- case NODE_ARGSCAT:
- if (when_check(tag->nd_head, val, self)) return Qtrue;
- tag = tag->nd_body;
- goto splat;
- case NODE_ARGSPUSH:
- if (when_check(tag->nd_head, val, self)) return Qtrue;
- if (when_cond(val, rb_eval(self, tag->nd_body))) return Qtrue;
- default:
- if (when_cond(val, rb_eval(self, tag))) return Qtrue;
- break;
+ rb_bug("unknown node type %d (0x%lx)", nd_type(node), node);
}
- return Qfalse;
}
static VALUE
-rb_eval(VALUE self, NODE *n)
+rb_eval(self, n)
+ VALUE self;
+ NODE *n;
{
NODE * volatile contnode = 0;
NODE * volatile node = n;
int state;
volatile VALUE result = Qnil;
+ st_data_t data;
#define RETURN(v) do { \
result = (v); \
@@ -2763,11 +2958,6 @@ rb_eval(VALUE self, NODE *n)
if (!node) RETURN(Qnil);
ruby_current_node = node;
- if (node->flags & NODE_NEWLINE) {
- EXEC_EVENT_HOOK(RUBY_EVENT_LINE, node, self,
- ruby_frame->this_func,
- ruby_frame->this_class);
- }
switch (nd_type(node)) {
case NODE_BLOCK:
if (contnode) {
@@ -2779,11 +2969,7 @@ rb_eval(VALUE self, NODE *n)
goto again;
case NODE_POSTEXE:
- PUSH_FRAME(Qtrue);
- PUSH_BLOCK(ruby_frame->block, 0, node->nd_body);
rb_f_END();
- POP_BLOCK();
- POP_FRAME();
nd_set_type(node, NODE_NIL); /* exec just once */
result = Qnil;
break;
@@ -2860,13 +3046,10 @@ rb_eval(VALUE self, NODE *n)
case NODE_FALSE:
RETURN(Qfalse);
- case NODE_ERRINFO:
- RETURN(ruby_errinfo);
-
case NODE_IF:
EXEC_EVENT_HOOK(RUBY_EVENT_LINE, node, self,
- ruby_frame->this_func,
- ruby_frame->this_class);
+ ruby_frame->last_func,
+ ruby_frame->last_class);
if (RTEST(rb_eval(self, node->nd_cond))) {
node = node->nd_body;
}
@@ -2875,23 +3058,76 @@ rb_eval(VALUE self, NODE *n)
}
goto again;
+ case NODE_WHEN:
+ while (node) {
+ NODE *tag;
+
+ if (nd_type(node) != NODE_WHEN) goto again;
+ tag = node->nd_head;
+ while (tag) {
+ EXEC_EVENT_HOOK(RUBY_EVENT_LINE, tag, self,
+ ruby_frame->last_func,
+ ruby_frame->last_class);
+ if (tag->nd_head && nd_type(tag->nd_head) == NODE_WHEN) {
+ VALUE v = rb_eval(self, tag->nd_head->nd_head);
+ long i;
+
+ if (TYPE(v) != T_ARRAY) v = rb_ary_to_ary(v);
+ for (i=0; i<RARRAY(v)->len; i++) {
+ if (RTEST(RARRAY(v)->ptr[i])) {
+ node = node->nd_body;
+ goto again;
+ }
+ }
+ tag = tag->nd_next;
+ continue;
+ }
+ if (RTEST(rb_eval(self, tag->nd_head))) {
+ node = node->nd_body;
+ goto again;
+ }
+ tag = tag->nd_next;
+ }
+ node = node->nd_next;
+ }
+ RETURN(Qnil);
+
case NODE_CASE:
{
- VALUE val = Qundef;
+ VALUE val;
- if (node->nd_head)
- val = rb_eval(self, node->nd_head);
+ val = rb_eval(self, node->nd_head);
node = node->nd_body;
while (node) {
+ NODE *tag;
+
if (nd_type(node) != NODE_WHEN) {
goto again;
}
- EXEC_EVENT_HOOK(RUBY_EVENT_LINE, node->nd_head, self,
- ruby_frame->this_func,
- ruby_frame->this_class);
- if (when_check(node->nd_head, val, self)) {
- node = node->nd_body;
- goto again;
+ tag = node->nd_head;
+ while (tag) {
+ EXEC_EVENT_HOOK(RUBY_EVENT_LINE, tag, self,
+ ruby_frame->last_func,
+ ruby_frame->last_class);
+ if (tag->nd_head && nd_type(tag->nd_head) == NODE_WHEN) {
+ VALUE v = rb_eval(self, tag->nd_head->nd_head);
+ long i;
+
+ if (TYPE(v) != T_ARRAY) v = rb_ary_to_ary(v);
+ for (i=0; i<RARRAY(v)->len; i++) {
+ if (RTEST(rb_funcall2(RARRAY(v)->ptr[i], eqq, 1, &val))){
+ node = node->nd_body;
+ goto again;
+ }
+ }
+ tag = tag->nd_next;
+ continue;
+ }
+ if (RTEST(rb_funcall2(rb_eval(self, tag->nd_head), eqq, 1, &val))) {
+ node = node->nd_body;
+ goto again;
+ }
+ tag = tag->nd_next;
}
node = node->nd_next;
}
@@ -2968,15 +3204,53 @@ rb_eval(VALUE self, NODE *n)
if (state) JUMP_TAG(state);
RETURN(result);
- case NODE_LAMBDA:
- PUSH_TAG(PROT_LOOP);
- PUSH_FRAME(Qtrue);
- PUSH_BLOCK(ruby_frame->block, node->nd_var, node->nd_body);
- state = EXEC_TAG();
- result = proc_lambda();
- POP_BLOCK();
- POP_FRAME();
- POP_TAG();
+ case NODE_BLOCK_PASS:
+ result = block_pass(self, node);
+ break;
+
+ case NODE_ITER:
+ case NODE_FOR:
+ {
+ PUSH_TAG(PROT_LOOP);
+ PUSH_BLOCK(node->nd_var, node->nd_body);
+
+ state = EXEC_TAG();
+ if (state == 0) {
+ iter_retry:
+ PUSH_ITER(ITER_PRE);
+ if (nd_type(node) == NODE_ITER) {
+ result = rb_eval(self, node->nd_iter);
+ }
+ else {
+ VALUE recv;
+
+ _block.flags &= ~BLOCK_D_SCOPE;
+ BEGIN_CALLARGS;
+ recv = rb_eval(self, node->nd_iter);
+ END_CALLARGS;
+ ruby_current_node = node;
+ SET_CURRENT_SOURCE();
+ result = rb_call(CLASS_OF(recv),recv,each,0,0,0,self);
+ }
+ POP_ITER();
+ }
+ else if (state == TAG_BREAK && TAG_DST()) {
+ result = prot_tag->retval;
+ state = 0;
+ }
+ else if (state == TAG_RETRY) {
+ state = 0;
+ goto iter_retry;
+ }
+ POP_BLOCK();
+ POP_TAG();
+ switch (state) {
+ case 0:
+ break;
+ default:
+ JUMP_TAG(state);
+ }
+ }
break;
case NODE_BREAK:
@@ -3006,6 +3280,11 @@ rb_eval(VALUE self, NODE *n)
result = rb_ary_to_ary(rb_eval(self, node->nd_head));
break;
+ case NODE_SVALUE:
+ result = avalue_splat(rb_eval(self, node->nd_head));
+ if (result == Qundef) result = Qnil;
+ break;
+
case NODE_YIELD:
if (node->nd_head) {
result = rb_eval(self, node->nd_head);
@@ -3015,7 +3294,7 @@ rb_eval(VALUE self, NODE *n)
result = Qundef; /* no arg */
}
SET_CURRENT_SOURCE();
- result = rb_yield_0(result, 0, 0, node->nd_state ? YIELD_VALUES : 0);
+ result = rb_yield_0(result, 0, 0, 0, node->nd_state);
break;
case NODE_RESCUE:
@@ -3111,7 +3390,7 @@ rb_eval(VALUE self, NODE *n)
VALUE beg = rb_eval(self, node->nd_beg);
VALUE end = rb_eval(self, node->nd_end);
result = rb_range_new(beg, end, nd_type(node) == NODE_DOT3);
- }
+ }
break;
case NODE_FLIP2: /* like AWK */
@@ -3174,185 +3453,109 @@ rb_eval(VALUE self, NODE *n)
case NODE_ATTRASGN:
{
VALUE recv;
- calling_scope_t scope;
- CALLARGS;
+ int argc; VALUE *argv; /* used in SETUP_ARGS */
+ int scope;
TMP_PROTECT;
+ BEGIN_CALLARGS;
if (node->nd_recv == (NODE *)1) {
recv = self;
- scope = CALLING_FCALL;
+ scope = 1;
}
else {
recv = rb_eval(self, node->nd_recv);
- scope = CALLING_NORMAL;
+ scope = 0;
}
SETUP_ARGS(node->nd_args);
+ END_CALLARGS;
ruby_current_node = node;
SET_CURRENT_SOURCE();
- rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,block,scope,0,self);
+ rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,scope,self);
result = argv[argc-1];
}
break;
- case NODE_FOR:
- {
- VALUE recv;
- int state;
- struct BLOCK *block;
-
- PUSH_TAG(PROT_LOOP);
- PUSH_BLOCK(block, node->nd_var, node->nd_body);
- state = EXEC_TAG();
- if (state == 0) {
- for_retry:
- block->flags &= ~BLOCK_D_SCOPE;
- recv = rb_eval(self, node->nd_iter);
- ruby_current_node = node;
- SET_CURRENT_SOURCE();
- result = rb_call(CLASS_OF(recv),recv,each,0,0,
- block,CALLING_NORMAL,1,self);
- }
- else if (state == TAG_BREAK && TAG_DST()) {
- result = prot_tag->retval;
- state = 0;
- }
- else if (state == TAG_RETRY) {
- state = 0;
- goto for_retry;
- }
- POP_BLOCK();
- POP_TAG();
- if (state) JUMP_TAG(state);
- }
- break;
-
- case NODE_ITER:
- {
- VALUE recv = self;
- calling_scope_t scope;
- struct BLOCK *block_given;
-
- PUSH_TAG(PROT_LOOP);
- PUSH_BLOCK(block_given, node->nd_var, node->nd_body);
- node = node->nd_iter; /* should be NODE_CALL */
- switch (nd_type(node)) {
- case NODE_CALL:
- scope = CALLING_NORMAL; break;
- case NODE_FCALL:
- scope = CALLING_FCALL; break;
- case NODE_VCALL:
- scope = CALLING_VCALL; break;
- case NODE_SUPER:
- case NODE_ZSUPER:
- scope = CALLING_SUPER; break;
- default:
- /* error! */
- unknown_node(node);
- }
- state = EXEC_TAG();
- if (state == 0) {
- CALLARGS;
- TMP_PROTECT;
-
- iter_retry:
- if (scope == CALLING_NORMAL) {
- recv = rb_eval(self, node->nd_recv);
- }
- if (nd_type(node) == NODE_ZSUPER) {
- ZSUPER_ARGS();
- }
- else {
- SETUP_ARGS(node->nd_args);
- ruby_current_node = node;
- }
- SET_CURRENT_SOURCE();
- switch (scope) {
- case CALLING_SUPER:
- result = call_super(argc, argv, block_given);
- break;
- default:
- result = rb_call(CLASS_OF(recv),recv,node->nd_mid,
- argc,argv,block_given,scope,1,self);
- break;
- }
- }
- else if (state == TAG_BREAK && TAG_DST()) {
- result = prot_tag->retval;
- state = 0;
- }
- else if (state == TAG_RETRY) {
- state = 0;
- goto iter_retry;
- }
- POP_BLOCK();
- POP_TAG();
- if (state) JUMP_TAG(state);
- }
- break;
-
case NODE_CALL:
{
VALUE recv;
- CALLARGS;
+ int argc; VALUE *argv; /* used in SETUP_ARGS */
TMP_PROTECT;
+ BEGIN_CALLARGS;
recv = rb_eval(self, node->nd_recv);
SETUP_ARGS(node->nd_args);
+ END_CALLARGS;
ruby_current_node = node;
SET_CURRENT_SOURCE();
- result = rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,
- block,CALLING_NORMAL,0,self);
+ result = rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,0,self);
}
break;
case NODE_FCALL:
{
- CALLARGS;
+ int argc; VALUE *argv; /* used in SETUP_ARGS */
TMP_PROTECT;
+ BEGIN_CALLARGS;
SETUP_ARGS(node->nd_args);
+ END_CALLARGS;
ruby_current_node = node;
SET_CURRENT_SOURCE();
- result = rb_call(CLASS_OF(self),self,node->nd_mid,argc,argv,
- block,CALLING_FCALL,0,self);
+ result = rb_call(CLASS_OF(self),self,node->nd_mid,argc,argv,1,self);
}
break;
case NODE_VCALL:
SET_CURRENT_SOURCE();
- result = rb_call(CLASS_OF(self),self,node->nd_mid,0,0,0,CALLING_VCALL,0,self);
+ result = rb_call(CLASS_OF(self),self,node->nd_mid,0,0,2,self);
break;
case NODE_SUPER:
case NODE_ZSUPER:
{
- CALLARGS;
+ int argc; VALUE *argv; /* used in SETUP_ARGS */
TMP_PROTECT;
- if (ruby_frame->this_class == 0) {
- if (ruby_frame->this_func) {
- rb_name_error(ruby_frame->callee,
+ if (ruby_frame->last_class == 0) {
+ if (ruby_frame->last_func) {
+ rb_name_error(ruby_frame->last_func,
"superclass method `%s' disabled",
- rb_id2name(ruby_frame->this_func));
+ rb_id2name(ruby_frame->orig_func));
}
else {
rb_raise(rb_eNoMethodError, "super called outside of method");
}
}
if (nd_type(node) == NODE_ZSUPER) {
- ZSUPER_ARGS();
- SET_CURRENT_SOURCE();
- result = rb_call_super(argc, argv);
+ argc = ruby_frame->argc;
+ if (argc && DMETHOD_P()) {
+ if (TYPE(RBASIC(ruby_scope)->klass) != T_ARRAY ||
+ RARRAY(RBASIC(ruby_scope)->klass)->len != argc) {
+ rb_raise(rb_eRuntimeError,
+ "super: specify arguments explicitly");
+ }
+ argv = RARRAY(RBASIC(ruby_scope)->klass)->ptr;
+ }
+ else if (!ruby_scope->local_vars) {
+ argc = 0;
+ argv = 0;
+ }
+ else {
+ argv = ruby_scope->local_vars + 2;
+ }
}
else {
+ BEGIN_CALLARGS;
SETUP_ARGS(node->nd_args);
+ END_CALLARGS;
ruby_current_node = node;
- SET_CURRENT_SOURCE();
- result = call_super(argc, argv, block);
}
+
+ SET_CURRENT_SOURCE();
+ result = rb_call_super(argc, argv);
}
break;
@@ -3396,14 +3599,14 @@ rb_eval(VALUE self, NODE *n)
case NODE_OP_ASGN1:
{
- CALLARGS;
+ int argc; VALUE *argv; /* used in SETUP_ARGS */
VALUE recv, val, tmp;
NODE *rval;
TMP_PROTECT;
recv = rb_eval(self, node->nd_recv);
rval = node->nd_args->nd_head;
- SETUP_ARGS0(node->nd_args->nd_body,1);
+ SETUP_ARGS0(node->nd_args->nd_body, 1);
val = rb_funcall3(recv, aref, argc, argv);
switch (node->nd_mid) {
case 0: /* OR */
@@ -3419,7 +3622,7 @@ rb_eval(VALUE self, NODE *n)
val = rb_funcall3(val, node->nd_mid, 1, &tmp);
}
argv[argc] = val;
- rb_funcall3(recv, aset, argc+1, argv);
+ rb_funcall2(recv, aset, argc+1, argv);
result = val;
}
break;
@@ -3445,7 +3648,7 @@ rb_eval(VALUE self, NODE *n)
val = rb_funcall3(val, node->nd_next->nd_mid, 1, &tmp);
}
- rb_funcall3(recv, node->nd_next->nd_aid, 1, &val);
+ rb_funcall2(recv, node->nd_next->nd_aid, 1, &val);
result = val;
}
break;
@@ -3457,7 +3660,7 @@ rb_eval(VALUE self, NODE *n)
goto again;
case NODE_OP_ASGN_OR:
- if ((node->nd_aid && !is_defined(self, node->nd_head, 0, 0)) ||
+ if ((node->nd_aid && !is_defined(self, node->nd_head, 0)) ||
!RTEST(result = rb_eval(self, node->nd_head))) {
node = node->nd_value;
goto again;
@@ -3538,7 +3741,7 @@ rb_eval(VALUE self, NODE *n)
break;
case NODE_CONST:
- result = ev_const_get(node->nd_vid, self);
+ result = ev_const_get(ruby_cref, node->nd_vid, self);
break;
case NODE_CVAR:
@@ -3570,7 +3773,7 @@ rb_eval(VALUE self, NODE *n)
break;
default:
rb_raise(rb_eTypeError, "%s is not a class/module",
- RSTRING_PTR(rb_obj_as_string(klass)));
+ RSTRING(rb_obj_as_string(klass))->ptr);
break;
}
}
@@ -3639,37 +3842,20 @@ rb_eval(VALUE self, NODE *n)
i = node->nd_alen;
ary = rb_ary_new2(i);
for (i=0;node;node=node->nd_next) {
- rb_ary_push(ary, rb_eval(self, node->nd_head));
+ RARRAY(ary)->ptr[i++] = rb_eval(self, node->nd_head);
+ RARRAY(ary)->len = i;
}
result = ary;
}
break;
- case NODE_VALUES:
- {
- VALUE val;
- long i;
-
- i = node->nd_alen;
- val = rb_ary_new2(i);
- for (i=0;node;node=node->nd_next) {
- rb_ary_push(val, rb_eval(self, node->nd_head));
- }
-
- result = val;
- }
- break;
-
case NODE_STR:
result = rb_str_new3(node->nd_lit);
break;
case NODE_EVSTR:
- if (!node->nd_body) result = rb_str_new(0,0);
- else {
- result = rb_obj_as_string(rb_eval(self, node->nd_body));
- }
+ result = rb_obj_as_string(rb_eval(self, node->nd_body));
break;
case NODE_DSTR:
@@ -3699,11 +3885,11 @@ rb_eval(VALUE self, NODE *n)
}
switch (nd_type(node)) {
case NODE_DREGX:
- result = rb_reg_new(RSTRING_PTR(str), RSTRING_LEN(str),
+ result = rb_reg_new(RSTRING(str)->ptr, RSTRING(str)->len,
node->nd_cflag);
break;
case NODE_DREGX_ONCE: /* regexp expand once */
- result = rb_reg_new(RSTRING_PTR(str), RSTRING_LEN(str),
+ result = rb_reg_new(RSTRING(str)->ptr, RSTRING(str)->len,
node->nd_cflag);
nd_set_type(node, NODE_LIT);
node->nd_lit = result;
@@ -3738,46 +3924,41 @@ rb_eval(VALUE self, NODE *n)
VALUE origin;
int noex;
- if (NIL_P(ruby_cbase)) {
- rb_raise(rb_eTypeError, "no class/module to define method");
+ if (NIL_P(ruby_class)) {
+ rb_raise(rb_eTypeError, "no class/module to add method");
}
- if (ruby_cbase == rb_cObject && node->nd_mid == init) {
+ if (ruby_class == rb_cObject && node->nd_mid == init) {
rb_warn("redefining Object#initialize may cause infinite loop");
}
- if (node->nd_mid == object_id ||
- node->nd_mid == __send || node->nd_mid == __send_bang) {
+ if (node->nd_mid == __id__ || node->nd_mid == __send__) {
rb_warn("redefining `%s' may cause serious problem",
rb_id2name(node->nd_mid));
}
- rb_frozen_class_p(ruby_cbase);
- body = search_method(ruby_cbase, node->nd_mid, &origin, LOOKUP_NOSKIP, 0);
+ rb_frozen_class_p(ruby_class);
+ body = search_method(ruby_class, node->nd_mid, &origin);
if (body){
- if (RTEST(ruby_verbose) && ruby_cbase == origin &&
- body->nd_cnt == 0 && body->nd_body) {
+ if (RTEST(ruby_verbose) && ruby_class == origin && body->nd_cnt == 0 && body->nd_body) {
rb_warning("method redefined; discarding old %s", rb_id2name(node->nd_mid));
}
}
- if (VIS_TEST(VIS_PRIVATE) || node->nd_mid == init) {
+ if (SCOPE_TEST(SCOPE_PRIVATE) || node->nd_mid == init) {
noex = NOEX_PRIVATE;
}
- else if (VIS_TEST(VIS_LOCAL)) {
- noex = NOEX_LOCAL;
- }
- else if (VIS_TEST(VIS_PROTECTED)) {
+ else if (SCOPE_TEST(SCOPE_PROTECTED)) {
noex = NOEX_PROTECTED;
}
else {
noex = NOEX_PUBLIC;
}
- if (body && origin == ruby_cbase && body->nd_body == 0) {
+ if (body && origin == ruby_class && body->nd_body == 0) {
noex |= NOEX_NOSUPER;
}
- defn = copy_node_scope(node->nd_defn, ruby_cref);
- rb_add_method(ruby_cbase, node->nd_mid, defn, noex);
- if (VIS_MODE() == VIS_MODFUNC) {
- rb_add_method(rb_singleton_class(ruby_cbase),
+ defn = rb_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),
node->nd_mid, defn, NOEX_PUBLIC);
}
result = Qnil;
@@ -3802,7 +3983,8 @@ rb_eval(VALUE self, NODE *n)
if (OBJ_FROZEN(recv)) rb_error_frozen("object");
klass = rb_singleton_class(recv);
- if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, (st_data_t *)&body)) {
+ if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, &data)) {
+ body = (NODE *)data;
if (ruby_safe_level >= 4) {
rb_raise(rb_eSecurityError, "redefining method prohibited");
}
@@ -3810,7 +3992,7 @@ rb_eval(VALUE self, NODE *n)
rb_warning("redefine %s", rb_id2name(node->nd_mid));
}
}
- defn = copy_node_scope(node->nd_defn, ruby_cref);
+ defn = rb_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;
@@ -3818,18 +4000,18 @@ rb_eval(VALUE self, NODE *n)
break;
case NODE_UNDEF:
- if (NIL_P(ruby_cbase)) {
+ if (NIL_P(ruby_class)) {
rb_raise(rb_eTypeError, "no class to undef method");
}
- rb_undef(ruby_cbase, rb_to_id(rb_eval(self, node->u2.node)));
+ rb_undef(ruby_class, rb_to_id(rb_eval(self, node->u2.node)));
result = Qnil;
break;
case NODE_ALIAS:
- if (NIL_P(ruby_cbase)) {
+ if (NIL_P(ruby_class)) {
rb_raise(rb_eTypeError, "no class to make alias");
}
- rb_alias(ruby_cbase, rb_to_id(rb_eval(self, node->u1.node)),
+ rb_alias(ruby_class, rb_to_id(rb_eval(self, node->u1.node)),
rb_to_id(rb_eval(self, node->u2.node)));
result = Qnil;
break;
@@ -3919,12 +4101,12 @@ rb_eval(VALUE self, NODE *n)
module = rb_define_module_id(cname);
rb_set_class_path(module, cbase, rb_id2name(cname));
rb_const_set(cbase, cname, module);
- rb_obj_call_init(module, 0, 0);
}
if (ruby_wrapper) {
rb_extend_object(module, ruby_wrapper);
rb_include_module(module, ruby_wrapper);
}
+
result = module_setup(module, node);
}
break;
@@ -3935,7 +4117,7 @@ rb_eval(VALUE self, NODE *n)
result = rb_eval(self, node->nd_recv);
if (FIXNUM_P(result) || SYMBOL_P(result)) {
- rb_raise(rb_eTypeError, "no singleton class for %s",
+ rb_raise(rb_eTypeError, "no virtual class for %s",
rb_obj_classname(result));
}
if (ruby_safe_level >= 4 && !OBJ_TAINTED(result))
@@ -3954,13 +4136,20 @@ rb_eval(VALUE self, NODE *n)
case NODE_DEFINED:
{
char buf[20];
- const char *desc = is_defined(self, node->nd_head, buf, 0);
+ char *desc = is_defined(self, node->nd_head, buf);
if (desc) result = rb_str_new2(desc);
else result = Qnil;
}
break;
+ case NODE_NEWLINE:
+ EXEC_EVENT_HOOK(RUBY_EVENT_LINE, node, self,
+ ruby_frame->last_func,
+ ruby_frame->last_class);
+ node = node->nd_next;
+ goto again;
+
default:
unknown_node(node);
}
@@ -3975,7 +4164,9 @@ rb_eval(VALUE self, NODE *n)
}
static VALUE
-module_setup(VALUE module, NODE *n)
+module_setup(module, n)
+ VALUE module;
+ NODE *n;
{
NODE * volatile node = n->nd_body;
int state;
@@ -3987,6 +4178,7 @@ module_setup(VALUE module, NODE *n)
frame.tmp = ruby_frame;
ruby_frame = &frame;
+ PUSH_CLASS(module);
PUSH_SCOPE();
PUSH_VARS();
@@ -4003,21 +4195,21 @@ module_setup(VALUE module, NODE *n)
}
PUSH_CREF(module);
- VIS_SET(VIS_PUBLIC);
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
EXEC_EVENT_HOOK(RUBY_EVENT_CLASS, n, ruby_cbase,
- ruby_frame->this_func, ruby_frame->this_class);
+ ruby_frame->last_func, ruby_frame->last_class);
result = rb_eval(ruby_cbase, node->nd_next);
}
POP_TAG();
POP_CREF();
POP_VARS();
POP_SCOPE();
+ POP_CLASS();
ruby_frame = frame.tmp;
- EXEC_EVENT_HOOK(RUBY_EVENT_END, n, 0, ruby_frame->this_func,
- ruby_frame->this_class);
+ EXEC_EVENT_HOOK(RUBY_EVENT_END, n, 0,
+ ruby_frame->last_func, ruby_frame->last_class);
if (state) JUMP_TAG(state);
return result;
@@ -4026,7 +4218,10 @@ module_setup(VALUE module, NODE *n)
static NODE *basic_respond_to = 0;
int
-rb_obj_respond_to(VALUE obj, ID id, int priv)
+rb_obj_respond_to(obj, id, priv)
+ VALUE obj;
+ ID id;
+ int priv;
{
VALUE klass = CLASS_OF(obj);
@@ -4038,12 +4233,14 @@ rb_obj_respond_to(VALUE obj, ID id, int priv)
int n = 0;
args[n++] = ID2SYM(id);
if (priv) args[n++] = Qtrue;
- return rb_funcall2(obj, respond_to, n, args);
+ return RTEST(rb_funcall2(obj, respond_to, n, args));
}
}
int
-rb_respond_to(VALUE obj, ID id)
+rb_respond_to(obj, id)
+ VALUE obj;
+ ID id;
{
return rb_obj_respond_to(obj, id, Qfalse);
}
@@ -4058,7 +4255,10 @@ rb_respond_to(VALUE obj, ID id)
*/
static VALUE
-obj_respond_to(int argc, VALUE *argv, VALUE obj)
+obj_respond_to(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE mid, priv;
ID id;
@@ -4073,12 +4273,11 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj)
/*
* call-seq:
- * mod.method_defined?(symbol, inherit=true) => true or false
+ * mod.method_defined?(symbol) => true or false
*
* Returns +true+ if the named method is defined by
* _mod_ (or its included modules and, if _mod_ is a class,
- * its ancestors, if _inherit_ is true). Public and protected
- * methods are matched.
+ * its ancestors). Public and protected methods are matched.
*
* module A
* def method1() end
@@ -4096,27 +4295,13 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj)
* C.method_defined? "method2" #=> true
* C.method_defined? "method3" #=> true
* C.method_defined? "method4" #=> false
- * C.method_defined?("method2", false) #=> false
*/
static VALUE
-rb_mod_method_defined(int argc, VALUE *argv, VALUE mod)
+rb_mod_method_defined(mod, mid)
+ VALUE mod, mid;
{
- VALUE mid, recur;
- ID id;
-
- if (argc == 1) {
- recur = Qtrue;
- mid = argv[0];
- }
- else {
- rb_scan_args(argc, argv, "11", &mid, &recur);
- }
- id = rb_to_id(mid);
- if (!RTEST(recur)) {
- return st_is_member(RCLASS(mod)->m_tbl, id) ? Qtrue : Qfalse;
- }
- return rb_method_boundp(mod, id, Qtrue);
+ return rb_method_boundp(mod, rb_to_id(mid), 1);
}
#define VISI_CHECK(x,f) (((x)&NOEX_MASK) == (f))
@@ -4148,10 +4333,11 @@ rb_mod_method_defined(int argc, VALUE *argv, VALUE mod)
*/
static VALUE
-rb_mod_public_method_defined(VALUE mod, VALUE mid)
+rb_mod_public_method_defined(mod, mid)
+ VALUE mod, mid;
{
ID id = rb_to_id(mid);
- int noex = LOOKUP_NOSKIP;
+ int noex;
if (rb_get_method_body(&mod, &id, &noex)) {
if (VISI_CHECK(noex, NOEX_PUBLIC))
@@ -4187,10 +4373,11 @@ rb_mod_public_method_defined(VALUE mod, VALUE mid)
*/
static VALUE
-rb_mod_private_method_defined(VALUE mod, VALUE mid)
+rb_mod_private_method_defined(mod, mid)
+ VALUE mod, mid;
{
ID id = rb_to_id(mid);
- int noex = LOOKUP_NOSKIP;
+ int noex;
if (rb_get_method_body(&mod, &id, &noex)) {
if (VISI_CHECK(noex, NOEX_PRIVATE))
@@ -4226,10 +4413,11 @@ rb_mod_private_method_defined(VALUE mod, VALUE mid)
*/
static VALUE
-rb_mod_protected_method_defined(VALUE mod, VALUE mid)
+rb_mod_protected_method_defined(mod, mid)
+ VALUE mod, mid;
{
ID id = rb_to_id(mid);
- int noex = LOOKUP_NOSKIP;
+ int noex;
if (rb_get_method_body(&mod, &id, &noex)) {
if (VISI_CHECK(noex, NOEX_PROTECTED))
@@ -4238,9 +4426,11 @@ rb_mod_protected_method_defined(VALUE mod, VALUE mid)
return Qfalse;
}
-NORETURN(static VALUE terminate_process(int, VALUE));
+NORETURN(static VALUE terminate_process _((int, VALUE)));
static VALUE
-terminate_process(int status, VALUE mesg)
+terminate_process(status, mesg)
+ int status;
+ VALUE mesg;
{
VALUE args[2];
args[0] = INT2NUM(status);
@@ -4250,7 +4440,8 @@ terminate_process(int status, VALUE mesg)
}
void
-rb_exit(int status)
+rb_exit(status)
+ int status;
{
if (prot_tag) {
terminate_process(status, rb_str_new("exit", 4));
@@ -4299,7 +4490,9 @@ rb_exit(int status)
*/
VALUE
-rb_f_exit(int argc, VALUE *argv)
+rb_f_exit(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE status;
int istatus;
@@ -4341,7 +4534,9 @@ rb_f_exit(int argc, VALUE *argv)
*/
VALUE
-rb_f_abort(int argc, VALUE *argv)
+rb_f_abort(argc, argv)
+ int argc;
+ VALUE *argv;
{
rb_secure(4);
if (argc == 0) {
@@ -4362,20 +4557,23 @@ rb_f_abort(int argc, VALUE *argv)
}
void
-rb_iter_break(void)
+rb_iter_break()
{
break_jump(Qnil);
}
-NORETURN(static void rb_longjmp(int, VALUE));
-static VALUE make_backtrace(void);
+NORETURN(static void rb_longjmp _((int, VALUE)));
+static VALUE make_backtrace _((void));
static void
-rb_longjmp(int tag, VALUE mesg)
+rb_longjmp(tag, mesg)
+ int tag;
+ VALUE mesg;
{
VALUE at;
+ rb_thread_t th = curr_thread;
- if (thread_set_raised()) {
+ if (rb_thread_set_raised(th)) {
ruby_errinfo = exception_error;
JUMP_TAG(TAG_FATAL);
}
@@ -4389,6 +4587,9 @@ rb_longjmp(int tag, VALUE 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);
}
}
@@ -4403,18 +4604,18 @@ rb_longjmp(int tag, VALUE mesg)
PUSH_TAG(PROT_NONE);
if ((status = EXEC_TAG()) == 0) {
- e = rb_obj_as_string(e);
+ StringValue(e);
warn_printf("Exception `%s' at %s:%d - %s\n",
rb_obj_classname(ruby_errinfo),
ruby_sourcefile, ruby_sourceline,
- RSTRING_PTR(e));
+ RSTRING(e)->ptr);
}
POP_TAG();
if (status == TAG_FATAL && ruby_errinfo == exception_error) {
ruby_errinfo = mesg;
}
else if (status) {
- thread_reset_raised();
+ rb_thread_reset_raised(th);
JUMP_TAG(status);
}
}
@@ -4423,30 +4624,41 @@ rb_longjmp(int tag, VALUE mesg)
if (tag != TAG_FATAL) {
EXEC_EVENT_HOOK(RUBY_EVENT_RAISE, ruby_current_node,
ruby_frame->self,
- ruby_frame->this_func,
- ruby_frame->this_class);
+ ruby_frame->last_func,
+ ruby_frame->last_class);
}
if (!prot_tag) {
error_print();
}
- thread_reset_raised();
+ rb_thread_raised_clear(th);
JUMP_TAG(tag);
}
void
-rb_exc_raise(VALUE mesg)
+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;
{
rb_longjmp(TAG_RAISE, mesg);
}
void
-rb_exc_fatal(VALUE mesg)
+rb_exc_fatal(mesg)
+ VALUE mesg;
{
rb_longjmp(TAG_FATAL, mesg);
}
void
-rb_interrupt(void)
+rb_interrupt()
{
rb_raise(rb_eInterrupt, "");
}
@@ -4476,14 +4688,18 @@ rb_interrupt(void)
*/
static VALUE
-rb_f_raise(int argc, VALUE *argv)
+rb_f_raise(argc, argv)
+ int argc;
+ VALUE *argv;
{
rb_raise_jump(rb_make_exception(argc, argv));
return Qnil; /* not reached */
}
static VALUE
-rb_make_exception(int argc, VALUE *argv)
+rb_make_exception(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE mesg;
ID exception;
@@ -4528,10 +4744,11 @@ rb_make_exception(int argc, VALUE *argv)
}
static void
-rb_raise_jump(VALUE mesg)
+rb_raise_jump(mesg)
+ VALUE mesg;
{
if (ruby_frame != top_frame) {
- PUSH_FRAME(Qfalse); /* fake frame */
+ PUSH_FRAME(); /* fake frame */
*ruby_frame = *_frame.prev->prev;
rb_longjmp(TAG_RAISE, mesg);
POP_FRAME();
@@ -4540,20 +4757,22 @@ rb_raise_jump(VALUE mesg)
}
void
-rb_jump_tag(int tag)
+rb_jump_tag(tag)
+ int tag;
{
JUMP_TAG(tag);
}
int
-rb_block_given_p(void)
+rb_block_given_p()
{
- if (ruby_frame->block) return Qtrue;
+ if (ruby_frame->iter == ITER_CUR && ruby_block)
+ return Qtrue;
return Qfalse;
}
int
-rb_iterator_p(void)
+rb_iterator_p()
{
return rb_block_given_p();
}
@@ -4581,9 +4800,9 @@ rb_iterator_p(void)
static VALUE
-rb_f_block_given_p(void)
+rb_f_block_given_p()
{
- if (ruby_frame->prev && ruby_frame->prev->block)
+ if (ruby_frame->prev && ruby_frame->prev->iter == ITER_CUR && ruby_block)
return Qtrue;
return Qfalse;
}
@@ -4592,10 +4811,12 @@ VALUE rb_eThreadError;
NORETURN(static void proc_jump_error(int, VALUE));
static void
-proc_jump_error(int state, VALUE result)
+proc_jump_error(state, result)
+ int state;
+ VALUE result;
{
char mesg[32];
- const char *statement;
+ char *statement;
switch (state) {
case TAG_BREAK:
@@ -4608,34 +4829,43 @@ proc_jump_error(int state, VALUE result)
statement = "local-jump"; break; /* should not happen */
}
snprintf(mesg, sizeof mesg, "%s from proc-closure", statement);
- localjump_error(mesg, result, state, 0);
+ localjump_error(mesg, result, state);
}
-NORETURN(static void return_jump(VALUE));
static void
-return_jump(VALUE retval)
+return_jump(retval)
+ VALUE retval;
{
struct tag *tt = prot_tag;
+ int yield = Qfalse;
if (retval == Qundef) retval = Qnil;
while (tt) {
- if ((tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) ||
- (tt->tag == PROT_LAMBDA))
- {
+ if (tt->tag == PROT_YIELD) {
+ yield = Qtrue;
+ tt = tt->prev;
+ }
+ if (tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) {
+ tt->dst = (VALUE)ruby_frame->uniq;
+ tt->retval = retval;
+ JUMP_TAG(TAG_RETURN);
+ }
+ if (tt->tag == PROT_LAMBDA && !yield) {
tt->dst = (VALUE)tt->frame->uniq;
tt->retval = retval;
JUMP_TAG(TAG_RETURN);
}
- if (tt->tag == PROT_THREAD && tt->prev) {
+ if (tt->tag == PROT_THREAD) {
rb_raise(rb_eThreadError, "return can't jump across threads");
}
tt = tt->prev;
}
- localjump_error("unexpected return", retval, TAG_RETURN, 0);
+ localjump_error("unexpected return", retval, TAG_RETURN);
}
static void
-break_jump(VALUE retval)
+break_jump(retval)
+ VALUE retval;
{
struct tag *tt = prot_tag;
@@ -4643,11 +4873,9 @@ break_jump(VALUE retval)
while (tt) {
switch (tt->tag) {
case PROT_THREAD:
- /* skip toplevel tag */
- if (!tt->prev) break;
case PROT_YIELD:
- case PROT_LAMBDA:
case PROT_LOOP:
+ case PROT_LAMBDA:
tt->dst = (VALUE)tt->frame->uniq;
tt->retval = retval;
JUMP_TAG(TAG_BREAK);
@@ -4660,11 +4888,12 @@ break_jump(VALUE retval)
}
tt = tt->prev;
}
- localjump_error("unexpected break", retval, TAG_BREAK, 0);
+ localjump_error("unexpected break", retval, TAG_BREAK);
}
static void
-next_jump(VALUE retval)
+next_jump(retval)
+ VALUE retval;
{
struct tag *tt = prot_tag;
@@ -4672,11 +4901,9 @@ next_jump(VALUE retval)
while (tt) {
switch (tt->tag) {
case PROT_THREAD:
- /* skip toplevel tag */
- if (!tt->prev) break;
case PROT_YIELD:
- case PROT_LAMBDA:
case PROT_LOOP:
+ case PROT_LAMBDA:
case PROT_FUNC:
tt->dst = (VALUE)tt->frame->uniq;
tt->retval = retval;
@@ -4687,24 +4914,23 @@ next_jump(VALUE retval)
}
tt = tt->prev;
}
- localjump_error("unexpected next", retval, TAG_NEXT, 0);
+ localjump_error("unexpected next", retval, TAG_NEXT);
}
-static VALUE bmcall(VALUE, VALUE);
-static int method_arity(VALUE);
-
void
-rb_need_block(void)
+rb_need_block()
{
if (!rb_block_given_p()) {
- localjump_error("no block given", Qnil, 0, 0);
+ localjump_error("no block given", Qnil, 0);
}
}
static VALUE
-rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
+rb_yield_0(val, self, klass, flags, avalue)
+ VALUE val, self, klass; /* OK */
+ int flags, avalue;
{
- NODE *node, *var;
+ NODE *node;
volatile VALUE result = Qnil;
volatile VALUE old_cref;
volatile VALUE old_wrapper;
@@ -4713,13 +4939,13 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
int old_vmode;
struct FRAME frame;
NODE *cnode = ruby_current_node;
- int lambda, call;
- int state, broken = 0;
+ int lambda = flags & YIELD_LAMBDA_CALL;
+ int state;
rb_need_block();
PUSH_VARS();
- block = ruby_frame->block;
+ block = ruby_block;
frame = block->frame;
frame.prev = ruby_frame;
frame.node = cnode;
@@ -4730,8 +4956,9 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
ruby_wrapper = block->wrapper;
old_scope = ruby_scope;
ruby_scope = block->scope;
- old_vmode = vis_mode;
- vis_mode = (flags & YIELD_PUBLIC_DEF) ? VIS_PUBLIC : block->vmode;
+ old_vmode = scope_vmode;
+ scope_vmode = (flags & YIELD_PUBLIC_DEF) ? SCOPE_PUBLIC : block->vmode;
+ ruby_block = block->prev;
if (block->flags & BLOCK_D_SCOPE) {
/* put place holder for dynamic (in-block) local variables */
ruby_dyna_vars = new_dvar(0, 0, block->dyna_vars);
@@ -4740,121 +4967,88 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
/* FOR does not introduce new scope */
ruby_dyna_vars = block->dyna_vars;
}
- if (klass) PUSH_CREF(klass);
- else {
+ PUSH_CLASS(klass ? klass : block->klass);
+ if (!klass) {
self = block->self;
}
node = block->body;
- var = block->var;
- lambda = block->flags & BLOCK_LAMBDA;
- call = flags & YIELD_CALL;
- if (var) {
+
+ if (block->var) {
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
- NODE *bvar = NULL;
- block_var:
- if (var == (NODE*)1) { /* no parameter || */
- if (lambda && val != Qundef) {
- if (TYPE(val) != T_ARRAY) {
- rb_raise(rb_eArgError, "wrong number of arguments (1 for 0)");
- }
- else if (RARRAY_LEN(val) != 0) {
- rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
- RARRAY_LEN(val));
- }
+ if (block->var == (NODE*)1) { /* no parameter || */
+ if (lambda && RARRAY(val)->len != 0) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
+ RARRAY(val)->len);
}
}
- else if (var == (NODE*)2) {
- if (TYPE(val) == T_ARRAY && RARRAY_LEN(val) != 0) {
+ else if (block->var == (NODE*)2) {
+ if (TYPE(val) == T_ARRAY && RARRAY(val)->len != 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
- RARRAY_LEN(val));
+ RARRAY(val)->len);
}
}
- else if (!bvar && nd_type(var) == NODE_BLOCK_PASS) {
- bvar = var->nd_body;
- var = var->nd_args;
- goto block_var;
- }
- else if (nd_type(var) == NODE_ARGS) {
- if (!(flags & YIELD_VALUES)) val = svalue_to_avalue(val);
- formal_assign(self, var, RARRAY_LEN(val), RARRAY_PTR(val), 0);
- }
- else if (nd_type(var) == NODE_BLOCK) {
- if (var->nd_next) {
- bvar = var->nd_next->nd_head;
+ else if (nd_type(block->var) == NODE_MASGN) {
+ if (!avalue) {
+ val = svalue_to_mrhs(val, block->var->nd_head);
}
- var = var->nd_head;
- goto block_var;
- }
- else if (nd_type(var) == NODE_MASGN) {
- massign(self, var, val, lambda);
+ massign(self, block->var, val, lambda);
}
else {
- if (lambda && val == Qundef) {
- rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
- }
- if (call) {
- if (lambda && RARRAY_LEN(val) != 1) {
- rb_raise(rb_eArgError, "wrong number of arguments (%ld for 1)",
- RARRAY_LEN(val));
+ int len = 0;
+ if (avalue) {
+ len = RARRAY(val)->len;
+ if (len == 0) {
+ goto zero_arg;
+ }
+ if (len == 1) {
+ val = RARRAY(val)->ptr[0];
+ }
+ else {
+ goto multi_values;
}
- if (RARRAY_LEN(val) == 0)
- val = Qnil;
- else
- val = RARRAY_PTR(val)[0];
- }
- assign(self, var, val, lambda);
- }
- if (bvar) {
- struct BLOCK *b = ruby_frame->prev->prev->block;
- VALUE blk;
-
- if ((flags & YIELD_PROC_INVOKE) && b) {
- blk = proc_alloc(rb_cProc, b, lambda);
}
- else {
- blk = Qnil;
+ else if (val == Qundef) {
+ zero_arg:
+ val = Qnil;
+ multi_values:
+ {
+ ruby_current_node = block->var;
+ rb_warn("multiple values for a block parameter (%d for 1)\n\tfrom %s:%d",
+ len, cnode->nd_file, nd_line(cnode));
+ ruby_current_node = cnode;
+ }
}
- assign(self, bvar, blk, 0);
+ assign(self, block->var, val, lambda);
}
}
POP_TAG();
if (state) goto pop_state;
}
- else if (lambda && call && RARRAY_LEN(val) != 0 &&
- (!node || nd_type(node) != NODE_IFUNC ||
- node->nd_cfnc != bmcall)) {
- rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
- RARRAY_LEN(val));
- }
if (!node) {
state = 0;
goto pop_state;
}
ruby_current_node = node;
+ PUSH_ITER(block->iter);
PUSH_TAG(lambda ? PROT_NONE : PROT_YIELD);
if ((state = EXEC_TAG()) == 0) {
redo:
if (nd_type(node) == NODE_CFUNC || nd_type(node) == NODE_IFUNC) {
if (node->nd_state == YIELD_FUNC_AVALUE) {
- val = svalue_to_avalue(val);
+ if (!avalue) {
+ val = svalue_to_avalue(val);
+ }
}
else {
+ if (avalue) {
+ val = avalue_to_svalue(val);
+ }
if (val == Qundef && node->nd_state != YIELD_FUNC_SVALUE)
val = Qnil;
}
- if ((block->flags&BLOCK_FROM_METHOD) && RTEST(block->block_obj)) {
- struct BLOCK *data, _block;
- Data_Get_Struct(block->block_obj, struct BLOCK, data);
- _block = *data;
- _block.uniq = block_unique++;
- ruby_frame->block = &_block;
- result = (*node->nd_cfnc)(val, node->nd_tval, self);
- }
- else {
- result = (*node->nd_cfnc)(val, node->nd_tval, self);
- }
+ result = (*node->nd_cfnc)(val, node->nd_tval, self);
}
else {
result = rb_eval(self, node);
@@ -4867,13 +5061,17 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
CHECK_INTS;
goto redo;
case TAG_NEXT:
- state = 0;
- result = prot_tag->retval;
+ if (!lambda) {
+ state = 0;
+ result = prot_tag->retval;
+ }
break;
case TAG_BREAK:
if (TAG_DST()) {
result = prot_tag->retval;
- broken = 1;
+ }
+ else {
+ lambda = Qtrue; /* just pass TAG_BREAK */
}
break;
default:
@@ -4881,7 +5079,9 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
}
}
POP_TAG();
+ POP_ITER();
pop_state:
+ POP_CLASS();
if (ruby_dyna_vars && (block->flags & BLOCK_D_SCOPE) &&
!FL_TEST(ruby_dyna_vars, DVAR_DONT_RECYCLE)) {
struct RVarmap *vars = ruby_dyna_vars;
@@ -4897,23 +5097,23 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
}
}
POP_VARS();
+ ruby_block = block;
ruby_frame = ruby_frame->prev;
ruby_cref = (NODE*)old_cref;
ruby_wrapper = old_wrapper;
if (ruby_scope->flags & SCOPE_DONT_RECYCLE)
scope_dup(old_scope);
ruby_scope = old_scope;
- vis_mode = old_vmode;
+ scope_vmode = old_vmode;
switch (state) {
case 0:
break;
case TAG_BREAK:
- if (broken) {
+ if (!lambda) {
struct tag *tt = prot_tag;
while (tt) {
- if ((tt->tag == PROT_LOOP && tt->blkid == block->uniq) ||
- (lambda && tt->tag == PROT_LAMBDA)) {
+ if (tt->tag == PROT_LOOP && tt->blkid == ruby_block->uniq) {
tt->dst = (VALUE)tt->frame->uniq;
tt->retval = result;
JUMP_TAG(TAG_BREAK);
@@ -4921,7 +5121,8 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
tt = tt->prev;
}
proc_jump_error(TAG_BREAK, result);
- }
+ }
+ /* fall through */
default:
JUMP_TAG(state);
break;
@@ -4931,33 +5132,56 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
}
VALUE
-rb_yield(VALUE val)
+rb_yield(val)
+ VALUE val;
{
- return rb_yield_0(val, 0, 0, 0);
+ return rb_yield_0(val, 0, 0, 0, Qfalse);
}
VALUE
+#ifdef HAVE_STDARG_PROTOTYPES
rb_yield_values(int n, ...)
+#else
+rb_yield_values(n, va_alist)
+ int n;
+ va_dcl
+#endif
{
- int i;
va_list args;
- VALUE val;
+ VALUE ary;
if (n == 0) {
- return rb_yield_0(Qundef, 0, 0, 0);
+ return rb_yield_0(Qundef, 0, 0, 0, Qfalse);
}
- val = rb_ary_new2(n);
- va_start(args, n);
- for (i=0; i<n; i++) {
- rb_ary_push(val, va_arg(args, VALUE));
+ ary = rb_ary_new2(n);
+ va_init_list(args, n);
+ while (n--) {
+ rb_ary_push(ary, va_arg(args, VALUE));
}
va_end(args);
- return rb_yield_0(val, 0, 0, YIELD_VALUES);
+ return rb_yield_0(ary, 0, 0, 0, Qtrue);
+}
+
+VALUE
+rb_yield_splat(values)
+ VALUE values;
+{
+ int avalue = Qfalse;
+
+ if (TYPE(values) == T_ARRAY) {
+ if (RARRAY(values)->len == 0) {
+ values = Qundef;
+ }
+ else {
+ avalue = Qtrue;
+ }
+ }
+ return rb_yield_0(values, 0, 0, 0, avalue);
}
/*
* call-seq:
- * loop {|| block }
+ * loop {|| block }
*
* Repeatedly executes the block.
*
@@ -4970,41 +5194,29 @@ rb_yield_values(int n, ...)
*/
static VALUE
-rb_f_loop(void)
+rb_f_loop()
{
for (;;) {
- rb_yield_0(Qundef, 0, 0, 0);
+ rb_yield_0(Qundef, 0, 0, 0, Qfalse);
CHECK_INTS;
}
return Qnil; /* dummy */
}
static VALUE
-massign(VALUE self, NODE *node, VALUE val, int pcall)
+massign(self, node, val, pcall)
+ VALUE self;
+ NODE *node;
+ VALUE val;
+ int pcall;
{
NODE *list;
long i = 0, len;
- volatile VALUE tmp;
- VALUE *argv;
- if (val == Qundef) {
- argv = 0;
- len = 0;
- }
- else {
- tmp = rb_check_array_type(val);
- if (NIL_P(tmp)) {
- argv = &val;
- len = (val == Qundef) ? 0 : 1;
- }
- else {
- argv = RARRAY_PTR(tmp);
- len = RARRAY_LEN(tmp);
- }
- }
+ len = RARRAY(val)->len;
list = node->nd_head;
for (; list && i<len; i++) {
- assign(self, list->nd_head, argv[i], pcall);
+ assign(self, list->nd_head, RARRAY(val)->ptr[i], pcall);
list = list->nd_next;
}
if (pcall && list) goto arg_error;
@@ -5013,7 +5225,7 @@ massign(VALUE self, NODE *node, VALUE val, int pcall)
/* no check for mere `*' */
}
else if (!list && i<len) {
- assign(self, node->nd_args, rb_ary_new4(len-i, argv+i), pcall);
+ assign(self, node->nd_args, rb_ary_new4(len-i, RARRAY(val)->ptr+i), pcall);
}
else {
assign(self, node->nd_args, rb_ary_new2(0), pcall);
@@ -5039,7 +5251,11 @@ massign(VALUE self, NODE *node, VALUE val, int pcall)
}
static void
-assign(VALUE self, NODE *lhs, VALUE val, int pcall)
+assign(self, lhs, val, pcall)
+ VALUE self;
+ NODE *lhs;
+ VALUE val;
+ int pcall;
{
ruby_current_node = lhs;
if (val == Qundef) {
@@ -5090,28 +5306,27 @@ assign(VALUE self, NODE *lhs, VALUE val, int pcall)
break;
case NODE_MASGN:
- massign(self, lhs, val, pcall);
+ massign(self, lhs, svalue_to_mrhs(val, lhs->nd_head), pcall);
break;
case NODE_CALL:
case NODE_ATTRASGN:
{
VALUE recv;
- calling_scope_t scope;
+ int scope;
if (lhs->nd_recv == (NODE *)1) {
recv = self;
- scope = CALLING_FUNCALL;
+ scope = 1;
}
else {
recv = rb_eval(self, lhs->nd_recv);
- scope = CALLING_NORMAL;
+ scope = 0;
}
if (!lhs->nd_args) {
/* attr set */
ruby_current_node = lhs;
SET_CURRENT_SOURCE();
- rb_call(CLASS_OF(recv), recv, lhs->nd_mid, 1, &val,
- 0, scope, 0, self);
+ rb_call(CLASS_OF(recv), recv, lhs->nd_mid, 1, &val, scope, self);
}
else {
/* array set */
@@ -5122,41 +5337,7 @@ assign(VALUE self, NODE *lhs, VALUE val, int pcall)
ruby_current_node = lhs;
SET_CURRENT_SOURCE();
rb_call(CLASS_OF(recv), recv, lhs->nd_mid,
- RARRAY_LEN(args), RARRAY_PTR(args),
- 0, scope, 0, self);
- }
- }
- break;
-
- case NODE_POSTARG:
- {
- NODE *v = lhs->nd_head;
- int cnt;
- VALUE *p;
-
- if (lhs->nd_args && (long)(lhs->nd_args) != -1) {
- assign(self, lhs->nd_args, val, 0);
- }
- cnt = lhs->nd_head->nd_alen;
- if (RARRAY_LEN(val) < cnt) {
- if (pcall) {
- rb_raise(rb_eArgError, "wrong number of arguments");
- }
- else {
- while (RARRAY_LEN(val) < cnt) {
- v = v->nd_next;
- cnt--;
- }
- }
- }
- p = RARRAY_PTR(val) + RARRAY_LEN(val) - cnt;
- while (cnt--) {
- assign(self, v->nd_head, *p++, 0);
- v = v->nd_next;
- }
- cnt = lhs->nd_head->nd_alen;
- while (cnt--) {
- rb_ary_pop(val);
+ RARRAY(args)->len, RARRAY(args)->ptr, scope, self);
}
}
break;
@@ -5168,7 +5349,9 @@ assign(VALUE self, NODE *lhs, VALUE val, int pcall)
}
VALUE
-rb_iterate(VALUE (*it_proc)(VALUE), VALUE data1, VALUE (*bl_proc)(ANYARGS), VALUE data2)
+rb_iterate(it_proc, data1, bl_proc, data2)
+ VALUE (*it_proc) _((VALUE)), (*bl_proc)(ANYARGS);
+ VALUE data1, data2;
{
int state;
volatile VALUE retval = Qnil;
@@ -5176,11 +5359,11 @@ rb_iterate(VALUE (*it_proc)(VALUE), VALUE data1, VALUE (*bl_proc)(ANYARGS), VALU
VALUE self = ruby_top_self;
PUSH_TAG(PROT_LOOP);
- PUSH_FRAME(Qtrue);
- PUSH_BLOCK(ruby_frame->block, 0, node);
+ PUSH_BLOCK(0, node);
+ PUSH_ITER(ITER_PRE);
state = EXEC_TAG();
if (state == 0) {
- iter_retry:
+ iter_retry:
retval = (*it_proc)(data1);
}
else if (state == TAG_BREAK && TAG_DST()) {
@@ -5191,8 +5374,8 @@ rb_iterate(VALUE (*it_proc)(VALUE), VALUE data1, VALUE (*bl_proc)(ANYARGS), VALU
state = 0;
goto iter_retry;
}
+ POP_ITER();
POP_BLOCK();
- POP_FRAME();
POP_TAG();
switch (state) {
@@ -5204,53 +5387,22 @@ rb_iterate(VALUE (*it_proc)(VALUE), VALUE data1, VALUE (*bl_proc)(ANYARGS), VALU
return retval;
}
-struct iter_method_arg {
- VALUE obj;
- ID mid;
- int argc;
- VALUE *argv;
-};
-
-static VALUE
-iterate_method(VALUE obj)
-{
- struct iter_method_arg *arg;
-
- arg = (struct iter_method_arg*)obj;
- return rb_call(CLASS_OF(arg->obj), arg->obj, arg->mid, arg->argc, arg->argv,
- ruby_frame->block, CALLING_FUNCALL,1,Qundef);
-}
-
-VALUE
-rb_block_call(VALUE obj, ID mid, int argc, VALUE *argv, VALUE (*bl_proc)(ANYARGS), VALUE data2)
-{
- struct iter_method_arg arg;
-
- arg.obj = obj;
- arg.mid = mid;
- arg.argc = argc;
- arg.argv = argv;
- return rb_iterate(iterate_method, (VALUE)&arg, bl_proc, data2);
-}
-
-VALUE
-rb_each(VALUE obj)
-{
- return rb_call(CLASS_OF(obj), obj, rb_intern("each"), 0, 0,
- ruby_frame->block, CALLING_FUNCALL,1,Qundef);
-}
-
static int
-handle_rescue(VALUE self, NODE *node)
+handle_rescue(self, node)
+ VALUE self;
+ NODE *node;
{
- CALLARGS;
+ int argc; VALUE *argv; /* used in SETUP_ARGS */
TMP_PROTECT;
if (!node->nd_args) {
return rb_obj_is_kind_of(ruby_errinfo, rb_eStandardError);
}
+ BEGIN_CALLARGS;
SETUP_ARGS(node->nd_args);
+ END_CALLARGS;
+
while (argc--) {
if (!rb_obj_is_kind_of(argv[0], rb_cModule)) {
rb_raise(rb_eTypeError, "class or module required for rescue clause");
@@ -5262,7 +5414,14 @@ handle_rescue(VALUE self, NODE *node)
}
VALUE
+#ifdef HAVE_STDARG_PROTOTYPES
rb_rescue2(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*r_proc)(ANYARGS), VALUE data2, ...)
+#else
+rb_rescue2(b_proc, data1, r_proc, data2, va_alist)
+ VALUE (*b_proc)(ANYARGS), (*r_proc)(ANYARGS);
+ VALUE data1, data2;
+ va_dcl
+#endif
{
int state;
volatile VALUE result;
@@ -5284,8 +5443,8 @@ rb_rescue2(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*r_proc)(ANYARGS), VALU
case TAG_RAISE:
if (handle) break;
handle = Qfalse;
- va_start(args, data2);
- while (eclass = va_arg(args, VALUE)) {
+ va_init_list(args, data2);
+ while ((eclass = va_arg(args, VALUE)) != 0) {
if (rb_obj_is_kind_of(ruby_errinfo, eclass)) {
handle = Qtrue;
break;
@@ -5311,7 +5470,9 @@ rb_rescue2(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*r_proc)(ANYARGS), VALU
}
VALUE
-rb_rescue(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*r_proc)(ANYARGS), VALUE data2)
+rb_rescue(b_proc, data1, r_proc, data2)
+ VALUE (*b_proc)(), (*r_proc)();
+ VALUE data1, data2;
{
return rb_rescue2(b_proc, data1, r_proc, data2, rb_eStandardError, (VALUE)0);
}
@@ -5319,21 +5480,21 @@ rb_rescue(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*r_proc)(ANYARGS), VALUE
static VALUE cont_protect;
VALUE
-rb_protect(VALUE (*proc) (VALUE), VALUE data, int *state)
+rb_protect(proc, data, state)
+ VALUE (*proc) _((VALUE));
+ VALUE data;
+ int *state;
{
VALUE result = Qnil; /* OK */
int status;
- PUSH_THREAD_TAG();
+ PUSH_TAG(PROT_NONE);
cont_protect = (VALUE)rb_node_newnode(NODE_MEMO, cont_protect, 0, 0);
if ((status = EXEC_TAG()) == 0) {
result = (*proc)(data);
}
- else if (status == TAG_THREAD) {
- rb_thread_start_1();
- }
cont_protect = ((NODE *)cont_protect)->u1.value;
- POP_THREAD_TAG();
+ POP_TAG();
if (state) {
*state = status;
}
@@ -5345,7 +5506,11 @@ rb_protect(VALUE (*proc) (VALUE), VALUE data, int *state)
}
VALUE
-rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE data2)
+rb_ensure(b_proc, data1, e_proc, data2)
+ VALUE (*b_proc)();
+ VALUE data1;
+ VALUE (*e_proc)();
+ VALUE data2;
{
int state;
volatile VALUE result = Qnil;
@@ -5358,7 +5523,7 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE
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);
@@ -5366,7 +5531,9 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE
}
VALUE
-rb_with_disable_interrupt(VALUE (*proc)(ANYARGS), VALUE data)
+rb_with_disable_interrupt(proc, data)
+ VALUE (*proc)();
+ VALUE data;
{
VALUE result = Qnil; /* OK */
int status;
@@ -5389,21 +5556,14 @@ rb_with_disable_interrupt(VALUE (*proc)(ANYARGS), VALUE data)
return result;
}
-static inline void
-stack_check(void)
+static void
+stack_check()
{
- static int overflowing = 0;
+ rb_thread_t th = rb_curr_thread;
- 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);
+ if (!rb_thread_raised_p(th, RAISED_STACKOVERFLOW) && ruby_stack_check()) {
+ rb_thread_raised_set(th, RAISED_STACKOVERFLOW);
+ rb_exc_raise(sysstack_error);
}
}
@@ -5445,11 +5605,14 @@ static int last_call_status;
*/
static VALUE
-rb_method_missing(int argc, const VALUE *argv, VALUE obj)
+rb_method_missing(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
ID id;
VALUE exc = rb_eNoMethodError;
- const char *format = 0;
+ char *format = 0;
NODE *cnode = ruby_current_node;
if (argc == 0 || !SYMBOL_P(argv[0])) {
@@ -5497,16 +5660,19 @@ rb_method_missing(int argc, const VALUE *argv, VALUE obj)
}
static VALUE
-method_missing(VALUE obj, ID id, int argc, const VALUE *argv,
- struct BLOCK *block, int call_status)
+method_missing(obj, id, argc, argv, call_status)
+ VALUE obj;
+ ID id;
+ int argc;
+ const VALUE *argv;
+ int call_status;
{
VALUE *nargv;
last_call_status = call_status;
if (id == missing) {
- PUSH_FRAME(Qfalse);
- ruby_frame->block = block;
+ PUSH_FRAME();
rb_method_missing(argc, argv, obj);
POP_FRAME();
}
@@ -5515,29 +5681,28 @@ method_missing(VALUE obj, ID id, int argc, const VALUE *argv,
}
if (argc < 0) {
VALUE tmp;
- int n;
- argc = -argc;
- n = argc / 256 - 1;
- argc %= 256;
- tmp = svalue_to_avalue(argv[argc]);
- nargv = ALLOCA_N(VALUE, argc + RARRAY_LEN(tmp) + n + 1);
+ argc = -argc-1;
+ tmp = splat_value(argv[argc]);
+ nargv = ALLOCA_N(VALUE, argc + RARRAY(tmp)->len + 1);
MEMCPY(nargv+1, argv, VALUE, argc);
- MEMCPY(nargv+1+argc, RARRAY_PTR(tmp), VALUE, RARRAY_LEN(tmp));
- MEMCPY(nargv+1+argc+RARRAY_LEN(tmp), argv+argc+1, VALUE, n);
- argc += RARRAY_LEN(tmp)+n;
+ MEMCPY(nargv+1+argc, RARRAY(tmp)->ptr, VALUE, RARRAY(tmp)->len);
+ argc += RARRAY(tmp)->len;
}
else {
nargv = ALLOCA_N(VALUE, argc+1);
MEMCPY(nargv+1, argv, VALUE, argc);
}
nargv[0] = ID2SYM(id);
- return rb_call(CLASS_OF(obj), obj, missing, argc+1, nargv,
- block, CALLING_FUNCALL, 0, Qundef);
+ return rb_funcall2(obj, missing, argc+1, nargv);
}
static inline VALUE
-call_cfunc(VALUE (*func)(ANYARGS), VALUE recv, int len, int argc, const VALUE *argv)
+call_cfunc(func, recv, len, argc, argv)
+ VALUE (*func)();
+ VALUE recv;
+ int len, argc;
+ VALUE *argv;
{
if (len >= 0 && argc != len) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
@@ -5620,113 +5785,38 @@ call_cfunc(VALUE (*func)(ANYARGS), VALUE recv, int len, int argc, const VALUE *a
return Qnil; /* not reached */
}
-static int
-formal_assign(VALUE recv, NODE *node, int argc, const VALUE *argv, VALUE *local_vars)
-{
- int i;
- int nopt = 0;
- int npost = 0;
-
- if (nd_type(node) != NODE_ARGS) {
- rb_bug("no argument-node");
- }
-
- i = node->nd_frml ? RARRAY_LEN(node->nd_frml) : 0;
- if (i > argc) {
- rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, i);
- }
- if (!node->nd_rest) {
- NODE *optnode = node->nd_opt;
-
- nopt = i;
- while (optnode) {
- nopt++;
- optnode = optnode->nd_next;
- }
- if (nopt < argc) {
- rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, nopt);
- }
- }
- if (local_vars) {
- if (i > 0) {
- /* +2 for $_ and $~ */
- MEMCPY(local_vars+2, argv, VALUE, i);
- }
- }
- else {
- int j;
- VALUE a = node->nd_frml;
-
- for (j=0; j<i; j++) {
- dvar_asgn_curr(SYM2ID(RARRAY_PTR(a)[j]), argv[j]);
- }
- }
- argv += i; argc -= i;
- if (node->nd_rest && nd_type(node->nd_rest) == NODE_POSTARG) {
- npost = node->nd_rest->nd_head->nd_alen;
- }
- if (node->nd_opt) {
- NODE *opt = node->nd_opt;
- int ac = argc - npost;
-
- while (opt && ac > 0) {
- assign(recv, opt->nd_head, *argv, 1);
- argv++; ac--;
- ++i;
- opt = opt->nd_next;
- }
- if (opt) {
- rb_eval(recv, opt);
- while (opt) {
- ++i;
- opt = opt->nd_next;
- }
- }
- argc = ac + npost;
- }
- if (!node->nd_rest) {
- i = nopt;
- }
- else {
- VALUE v;
- int n = 1;
-
- v = rb_ary_new4(argc,argv);
- n += npost;
- i += n*256;
- i = -i;
- assign(recv, node->nd_rest, v, 1);
- }
- return i;
-}
-
-#define PUSH_METHOD_FRAME() \
- PUSH_FRAME(Qfalse);\
- ruby_frame->callee = id;\
- ruby_frame->this_func = oid;\
- ruby_frame->this_class = (flags & NOEX_NOSUPER)?0:klass;\
- ruby_frame->self = recv;\
- ruby_frame->argc = argc;\
- ruby_frame->block = block;\
- ruby_frame->flags = (flags & NOEX_RECV) ? FRAME_FUNC : 0;
-
static VALUE
-rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
- int argc /* OK */, const VALUE *argv /* OK */,
- struct BLOCK *block,
- NODE *volatile body, int flags)
+rb_call0(klass, recv, id, oid, argc, argv, body, flags)
+ VALUE klass, recv;
+ ID id;
+ ID oid;
+ int argc; /* OK */
+ VALUE *argv; /* OK */
+ NODE * volatile body;
+ int flags;
{
NODE *b2; /* OK */
volatile VALUE result = Qnil;
+ int itr;
static int tick;
- volatile int safe = -1;
TMP_PROTECT;
+ volatile int safe = -1;
- if (NOEX_SAFE(flags) > ruby_safe_level &&
- ruby_safe_level == 0 && NOEX_SAFE(flags) > 2) {
+ if (NOEX_SAFE(flags) > ruby_safe_level && NOEX_SAFE(flags) > 2) {
rb_raise(rb_eSecurityError, "calling insecure method: %s",
rb_id2name(id));
}
+ switch (ruby_iter->iter) {
+ case ITER_PRE:
+ case ITER_PAS:
+ itr = ITER_CUR;
+ break;
+ case ITER_CUR:
+ default:
+ itr = ITER_NOT;
+ break;
+ }
+
if ((++tick & 0xff) == 0) {
CHECK_INTS; /* better than nothing */
stack_check();
@@ -5735,19 +5825,25 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
if (argc < 0) {
VALUE tmp;
VALUE *nargv;
- int n;
- argc = -argc;
- n = argc / 256 - 1;
- argc %= 256;
- tmp = svalue_to_avalue(argv[argc]);
- nargv = TMP_ALLOC(argc + RARRAY_LEN(tmp) + n);
+ argc = -argc-1;
+ tmp = splat_value(argv[argc]);
+ nargv = TMP_ALLOC(argc + RARRAY(tmp)->len);
MEMCPY(nargv, argv, VALUE, argc);
- MEMCPY(nargv+argc, RARRAY_PTR(tmp), VALUE, RARRAY_LEN(tmp));
- MEMCPY(nargv + argc + RARRAY_LEN(tmp), argv + argc + 1, VALUE, n);
- argc += RARRAY_LEN(tmp) + n;
+ MEMCPY(nargv+argc, RARRAY(tmp)->ptr, VALUE, RARRAY(tmp)->len);
+ argc += RARRAY(tmp)->len;
argv = nargv;
}
+ PUSH_ITER(itr);
+ PUSH_FRAME();
+
+ ruby_frame->last_func = id;
+ ruby_frame->orig_func = oid;
+ ruby_frame->last_class = (flags & NOEX_NOSUPER)?0:klass;
+ ruby_frame->self = recv;
+ ruby_frame->argc = argc;
+ ruby_frame->flags = 0;
+
switch (nd_type(body)) {
case NODE_CFUNC:
{
@@ -5757,7 +5853,6 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
rb_bug("bad argc (%d) specified for `%s(%s)'",
len, rb_class2name(klass), rb_id2name(id));
}
- PUSH_METHOD_FRAME();
if (event_hooks) {
int state;
@@ -5776,7 +5871,6 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
else {
result = call_cfunc(body->nd_cfnc, recv, len, argc, argv);
}
- POP_FRAME();
}
break;
@@ -5794,24 +5888,25 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
result = rb_ivar_set(recv, body->nd_vid, argv[0]);
break;
- case NODE_ZSUPER: /* visibility override */
- result = call_super_0(klass, recv, oid, argc, argv, block);
+ case NODE_ZSUPER:
+ result = rb_call_super(argc, argv);
+ break;
+
+ case NODE_DMETHOD:
+ result = method_call(argc, argv, umethod_bind(body->nd_cval, recv));
break;
case NODE_BMETHOD:
- PUSH_METHOD_FRAME();
ruby_frame->flags |= FRAME_DMETH;
if (event_hooks) {
struct BLOCK *data;
Data_Get_Struct(body->nd_cval, struct BLOCK, data);
EXEC_EVENT_HOOK(RUBY_EVENT_CALL, data->body, recv, id, klass);
}
- result = proc_invoke(body->nd_cval, rb_ary_new4(argc, argv), recv, klass,
- INVOKE_CALL);
+ result = proc_invoke(body->nd_cval, rb_ary_new4(argc, argv), recv, klass);
if (event_hooks) {
EXEC_EVENT_HOOK(RUBY_EVENT_RETURN, body, recv, id, klass);
}
- POP_FRAME();
break;
case NODE_SCOPE:
@@ -5820,12 +5915,12 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
VALUE *local_vars; /* OK */
NODE *saved_cref = 0;
- PUSH_METHOD_FRAME();
PUSH_SCOPE();
if (body->nd_rval) {
saved_cref = ruby_cref;
ruby_cref = (NODE*)body->nd_rval;
}
+ PUSH_CLASS(ruby_cbase);
if (body->nd_tbl) {
local_vars = TMP_ALLOC(body->nd_tbl[0]+1);
*local_vars++ = (VALUE)body;
@@ -5847,6 +5942,7 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
PUSH_TAG(PROT_FUNC);
if ((state = EXEC_TAG()) == 0) {
NODE *node = 0;
+ int i, nopt = 0;
if (nd_type(body) == NODE_ARGS) {
node = body;
@@ -5857,10 +5953,70 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
body = body->nd_next;
}
if (node) {
- ruby_frame->argc =
- formal_assign(recv, node, argc, argv, local_vars);
- }
+ if (nd_type(node) != NODE_ARGS) {
+ rb_bug("no argument-node");
+ }
+ i = node->nd_cnt;
+ if (i > argc) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
+ argc, i);
+ }
+ if (!node->nd_rest) {
+ NODE *optnode = node->nd_opt;
+
+ nopt = i;
+ while (optnode) {
+ nopt++;
+ optnode = optnode->nd_next;
+ }
+ if (nopt < argc) {
+ rb_raise(rb_eArgError,
+ "wrong number of arguments (%d for %d)",
+ argc, nopt);
+ }
+ }
+ if (local_vars) {
+ if (i > 0) {
+ /* +2 for $_ and $~ */
+ MEMCPY(local_vars+2, argv, VALUE, i);
+ }
+ }
+ argv += i; argc -= i;
+ if (node->nd_opt) {
+ NODE *opt = node->nd_opt;
+
+ while (opt && argc) {
+ assign(recv, opt->nd_head, *argv, 1);
+ argv++; argc--;
+ ++i;
+ opt = opt->nd_next;
+ }
+ if (opt) {
+ rb_eval(recv, opt);
+ while (opt) {
+ opt = opt->nd_next;
+ ++i;
+ }
+ }
+ }
+ if (!node->nd_rest) {
+ i = nopt;
+ }
+ else {
+ VALUE v;
+
+ if (argc > 0) {
+ v = rb_ary_new4(argc,argv);
+ i = -i - 1;
+ }
+ else {
+ v = rb_ary_new2(0);
+ }
+ assign(recv, node->nd_rest, v, 1);
+ }
+ ruby_frame->argc = i;
+ }
if (event_hooks) {
EXEC_EVENT_HOOK(RUBY_EVENT_CALL, b2, recv, id, klass);
}
@@ -5875,10 +6031,10 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
EXEC_EVENT_HOOK(RUBY_EVENT_RETURN, body, recv, id, klass);
}
POP_VARS();
+ POP_CLASS();
POP_SCOPE();
ruby_cref = saved_cref;
if (safe >= 0) ruby_safe_level = safe;
- POP_FRAME();
switch (state) {
case 0:
break;
@@ -5889,7 +6045,7 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
break;
case TAG_RETRY:
- if (block) JUMP_TAG(state);
+ if (rb_block_given_p()) JUMP_TAG(state);
/* fall through */
default:
jump_tag_but_local_jump(state, result);
@@ -5902,69 +6058,50 @@ rb_call0(VALUE klass, VALUE recv, ID id, ID oid,
unknown_node(body);
break;
}
+ POP_FRAME();
+ POP_ITER();
return result;
}
static VALUE
-rb_call(VALUE klass, VALUE recv, ID mid,
- int argc /* OK */, const VALUE *argv /* OK */, struct BLOCK *block,
- calling_scope_t scope, int iter, VALUE self)
+rb_call(klass, recv, mid, argc, argv, scope, self)
+ VALUE klass, recv;
+ ID mid;
+ int argc; /* OK */
+ const VALUE *argv; /* OK */
+ int scope;
+ VALUE self;
{
NODE *body; /* OK */
int noex;
ID id = mid;
- struct cache_entry *ent = 0;
+ struct cache_entry *ent;
if (!klass) {
- rb_raise(rb_eNotImpError, "method `%s' called on terminated object (%p)",
- rb_id2name(mid), (void*)recv);
- }
- switch (scope) {
- case CALLING_FCALL:
- case CALLING_VCALL:
- if (recv == ruby_frame->self) {
- noex = LOOKUP_LOCAL;
- break;
- }
- /* fall thtough */
- default:
- noex = LOOKUP_NORMAL;
- break;
+ rb_raise(rb_eNotImpError, "method `%s' called on terminated object (0x%lx)",
+ rb_id2name(mid), recv);
}
-
/* is it in the method cache? */
- if (noex == LOOKUP_LOCAL) {
- ent = cache[LOOKUP_FCALL] + EXPR1(ruby_frame->this_class, mid);
- if (ent->mid != mid || ent->klass != ruby_frame->this_class) {
- ent = NULL;
- }
- }
- if (!ent) {
- ent = cache[LOOKUP_NORMAL] + EXPR1(klass, mid);
- if (ent->mid != mid || ent->klass != klass) {
- ent = NULL;
- }
- }
- if (ent) {
+ ent = cache + EXPR1(klass, mid);
+ if (ent->mid == mid && ent->klass == klass) {
if (!ent->method)
- return method_missing(recv, mid, argc, argv, block,
- scope==CALLING_VCALL?CSTAT_VCALL:0);
+ return method_missing(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
klass = ent->origin;
id = ent->mid0;
noex = ent->noex;
body = ent->method;
}
else if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) {
- if (scope == CALLING_SUPER) {
- return method_missing(recv, mid, argc, argv, block, CSTAT_SUPER);
+ if (scope == 3) {
+ return method_missing(recv, mid, argc, argv, CSTAT_SUPER);
}
- return method_missing(recv, mid, argc, argv, block, scope==CALLING_VCALL?CSTAT_VCALL:0);
+ return method_missing(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
}
- if (mid != missing && scope == CALLING_NORMAL) {
+ if (mid != missing && scope == 0) {
/* receiver specified form for private method */
if (noex & NOEX_PRIVATE)
- return method_missing(recv, mid, argc, argv, block, CSTAT_PRIV);
+ return method_missing(recv, mid, argc, argv, CSTAT_PRIV);
/* self must be kind of a specified form for protected method */
if (noex & NOEX_PROTECTED) {
@@ -5975,70 +6112,36 @@ rb_call(VALUE klass, VALUE recv, ID mid,
defined_class = RBASIC(defined_class)->klass;
}
if (!rb_obj_is_kind_of(self, rb_class_real(defined_class)))
- return method_missing(recv, mid, argc, argv, block, CSTAT_PROT);
+ return method_missing(recv, mid, argc, argv, CSTAT_PROT);
}
}
- if (scope > CALLING_NORMAL) { /* pass receiver info */
- noex |= NOEX_RECV;
- }
- if (block && !iter && !block_orphan(block)) {
- VALUE result;
- int state;
- PUSH_TAG(PROT_LOOP);
- state = EXEC_TAG();
- if (state == 0) {
- result = rb_call0(klass, recv, mid, id, argc, argv, block, body, noex);
- }
- else if (state == TAG_BREAK && TAG_DST()) {
- result = prot_tag->retval;
- state = 0;
- }
- POP_TAG();
- if (state) JUMP_TAG(state);
- return result;
- }
- else {
- return rb_call0(klass, recv, mid, id, argc, argv, block, body, noex);
- }
+ return rb_call0(klass, recv, mid, id, argc, argv, body, noex);
}
VALUE
-rb_apply(VALUE recv, ID mid, VALUE args)
+rb_apply(recv, mid, args)
+ VALUE recv;
+ ID mid;
+ VALUE args;
{
int argc;
VALUE *argv;
- argc = RARRAY_LEN(args); /* Assigns LONG, but argc is INT */
+ argc = RARRAY(args)->len; /* Assigns LONG, but argc is INT */
argv = ALLOCA_N(VALUE, argc);
- MEMCPY(argv, RARRAY_PTR(args), VALUE, argc);
- return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0,CALLING_FUNCALL,0,Qundef);
-}
-
-static VALUE
-send_funcall(int argc, VALUE *argv, VALUE recv, calling_scope_t scope)
-{
- VALUE vid;
-
- if (argc == 0) rb_raise(rb_eArgError, "no method name given");
-
- vid = *argv++; argc--;
- vid = rb_call(CLASS_OF(recv), recv, rb_to_id(vid), argc, argv,
- ruby_frame->block, scope, 1, Qundef);
-
- return vid;
+ MEMCPY(argv, RARRAY(args)->ptr, VALUE, argc);
+ return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 1, Qundef);
}
/*
* call-seq:
- * obj.send(symbol [, args...]) => obj
- * obj.__send(symbol [, args...]) => obj
+ * obj.send(symbol [, args...]) => obj
+ * obj.__send__(symbol [, args...]) => obj
*
* Invokes the method identified by _symbol_, passing it any
* arguments specified. You can use <code>\_\_send__</code> if the name
- * +send+ clashes with an existing method in _obj_. Raises an
- * NoMethodError exception for private methods except when it is
- * called in function call style.
+ * +send+ clashes with an existing method in _obj_.
*
* class Klass
* def hello(*args)
@@ -6047,50 +6150,34 @@ send_funcall(int argc, VALUE *argv, VALUE recv, calling_scope_t scope)
* end
* k = Klass.new
* k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
- *
- * 1.send(:puts, "foo") # NoMethodError exception
- * send(:puts, "foo") # prints "foo"
*/
static VALUE
-rb_f_send(int argc, VALUE *argv, VALUE recv)
+rb_f_send(argc, argv, recv)
+ int argc;
+ VALUE *argv;
+ VALUE recv;
{
- calling_scope_t scope;
+ VALUE vid;
- if (ruby_frame->flags & FRAME_FUNC) {
- scope = CALLING_FCALL;
- }
- else {
- scope = CALLING_NORMAL;
- }
- return send_funcall(argc, argv, recv, scope);
-}
+ if (argc == 0) rb_raise(rb_eArgError, "no method name given");
-/*
- * call-seq:
- * obj.funcall(symbol [, args...]) => obj
- * obj.__send!(symbol [, args...]) => obj
- *
- * Invokes the method identified by _symbol_, passing it any
- * arguments specified. Unlike send, which calls private methods only
- * when it is invoked in function call style, funcall always aware of
- * private methods.
- *
- * 1.funcall(:puts, "hello") # prints "foo"
- */
+ vid = *argv++; argc--;
+ PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT);
+ vid = rb_call(CLASS_OF(recv), recv, rb_to_id(vid), argc, argv, 1, Qundef);
+ POP_ITER();
-static VALUE
-rb_f_funcall(int argc, VALUE *argv, VALUE recv)
-{
- return send_funcall(argc, argv, recv, CALLING_FUNCALL);
+ return vid;
}
-VALUE
-rb_funcall(VALUE recv, ID mid, int n, ...)
+static VALUE
+vafuncall(recv, mid, n, ar)
+ VALUE recv;
+ ID mid;
+ int n;
+ va_list *ar;
{
VALUE *argv;
- va_list ar;
- va_start(ar, n);
if (n > 0) {
long i;
@@ -6098,73 +6185,138 @@ rb_funcall(VALUE recv, ID mid, int n, ...)
argv = ALLOCA_N(VALUE, n);
for (i=0;i<n;i++) {
- argv[i] = va_arg(ar, VALUE);
+ argv[i] = va_arg(*ar, VALUE);
}
- va_end(ar);
+ va_end(*ar);
}
else {
argv = 0;
}
- return rb_call(CLASS_OF(recv), recv, mid, n, argv, 0,CALLING_FUNCALL,0,Qundef);
+ return rb_call(CLASS_OF(recv), recv, mid, n, argv, 1, Qundef);
}
VALUE
-rb_funcall2(VALUE recv, ID mid, int argc, const VALUE *argv)
+#ifdef HAVE_STDARG_PROTOTYPES
+rb_funcall(VALUE recv, ID mid, int n, ...)
+#else
+rb_funcall(recv, mid, n, va_alist)
+ VALUE recv;
+ ID mid;
+ int n;
+ va_dcl
+#endif
{
- return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0,CALLING_FUNCALL,0,Qundef);
+ va_list ar;
+ va_init_list(ar, n);
+
+ return vafuncall(recv, mid, n, &ar);
}
VALUE
-rb_funcall3(VALUE recv, ID mid, int argc, const VALUE *argv)
+#ifdef HAVE_STDARG_PROTOTYPES
+rb_funcall_rescue(VALUE recv, ID mid, int n, ...)
+#else
+rb_funcall_rescue(recv, mid, n, va_alist)
+ VALUE recv;
+ ID mid;
+ int n;
+ va_dcl
+#endif
{
- return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0,CALLING_NORMAL,0,Qundef);
-}
+ VALUE result = Qnil; /* OK */
+ int status;
+ va_list ar;
-static VALUE
-call_super_0(VALUE klass, VALUE self, ID mid,
- int argc, const VALUE *argv, struct BLOCK *block)
-{
- if (RCLASS(klass)->super == 0) {
- return method_missing(self, mid, argc, argv, block, CSTAT_SUPER);
+ va_init_list(ar, n);
+
+ PUSH_TAG(PROT_NONE);
+ if ((status = EXEC_TAG()) == 0) {
+ result = vafuncall(recv, mid, n, &ar);
+ }
+ POP_TAG();
+ switch (status) {
+ case 0:
+ return result;
+ case TAG_RAISE:
+ return Qundef;
+ default:
+ JUMP_TAG(status);
}
+}
- return rb_call(RCLASS(klass)->super, self, mid, argc, argv,
- block, CALLING_SUPER, 1, Qundef);
+VALUE
+rb_funcall2(recv, mid, argc, argv)
+ VALUE recv;
+ ID mid;
+ int argc;
+ const VALUE *argv;
+{
+ return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 1, Qundef);
}
-static VALUE
-call_super(int argc, const VALUE *argv, struct BLOCK *block)
+VALUE
+rb_funcall3(recv, mid, argc, argv)
+ VALUE recv;
+ ID mid;
+ int argc;
+ const VALUE *argv;
{
- if (ruby_frame->this_class == 0) {
- rb_name_error(ruby_frame->callee, "calling `super' from `%s' is prohibited",
- rb_id2name(ruby_frame->this_func));
- }
- return call_super_0(ruby_frame->this_class, ruby_frame->self,
- ruby_frame->this_func, argc, argv, block);
+ return rb_call(CLASS_OF(recv), recv, mid, argc, argv, 0, Qundef);
}
VALUE
-rb_call_super(int argc, const VALUE *argv)
+rb_call_super(argc, argv)
+ int argc;
+ const VALUE *argv;
{
- return call_super(argc, argv, ruby_frame->block);
+ VALUE result, self, klass;
+
+ if (ruby_frame->last_class == 0) {
+ rb_name_error(ruby_frame->last_func, "calling `super' from `%s' is prohibited",
+ rb_id2name(ruby_frame->orig_func));
+ }
+
+ self = ruby_frame->self;
+ klass = ruby_frame->last_class;
+ if (RCLASS(klass)->super == 0) {
+ return method_missing(self, ruby_frame->orig_func, argc, argv, CSTAT_SUPER);
+ }
+
+ PUSH_ITER(ruby_iter->iter ? ITER_PRE : ITER_NOT);
+ result = rb_call(RCLASS(klass)->super, self, ruby_frame->orig_func, argc, argv, 3, Qundef);
+ POP_ITER();
+
+ return result;
}
static VALUE
-backtrace(int lev)
+backtrace(lev)
+ int lev;
{
struct FRAME *frame = ruby_frame;
- VALUE str;
- volatile VALUE ary;
+ char buf[BUFSIZ];
+ VALUE ary;
NODE *n;
ary = rb_ary_new();
- if (frame->this_func == ID_ALLOCATOR) {
+ if (frame->last_func == ID_ALLOCATOR) {
frame = frame->prev;
}
if (lev < 0) {
- str = error_line(frame, 0);
- rb_ary_push(ary, str);
+ ruby_set_current_source();
+ if (frame->last_func) {
+ snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
+ ruby_sourcefile, ruby_sourceline,
+ rb_id2name(frame->last_func));
+ }
+ else if (ruby_sourceline == 0) {
+ snprintf(buf, BUFSIZ, "%s", ruby_sourcefile);
+ }
+ else {
+ snprintf(buf, BUFSIZ, "%s:%d", ruby_sourcefile, ruby_sourceline);
+ }
+ rb_ary_push(ary, rb_str_new2(buf));
if (lev < -1) return ary;
}
else {
@@ -6177,16 +6329,18 @@ backtrace(int lev)
}
}
for (; frame && (n = frame->node); frame = frame->prev) {
- if (frame->prev && frame->prev->this_func) {
+ if (frame->prev && frame->prev->last_func) {
if (frame->prev->node == n) {
- if (frame->prev->this_func == frame->this_func) continue;
+ if (frame->prev->last_func == frame->last_func) continue;
}
- str = error_line(frame->prev, n);
+ snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
+ n->nd_file, nd_line(n),
+ rb_id2name(frame->prev->last_func));
}
else {
- str = rb_sprintf("%s:%d", n->nd_file, nd_line(n));
+ snprintf(buf, BUFSIZ, "%s:%d", n->nd_file, nd_line(n));
}
- rb_ary_push(ary, str);
+ rb_ary_push(ary, rb_str_new2(buf));
}
return ary;
@@ -6198,7 +6352,7 @@ backtrace(int lev)
*
* Returns the current execution stack---an array containing strings in
* the form ``<em>file:line</em>'' or ``<em>file:line: in
- * `method'</em>''. The optional <i>start</i>_ parameter
+ * `method'</em>''. The optional _start_ parameter
* determines the number of initial stack entries to omit from the
* result.
*
@@ -6218,7 +6372,9 @@ backtrace(int lev)
*/
static VALUE
-rb_f_caller(int argc, VALUE *argv)
+rb_f_caller(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE level;
int lev;
@@ -6233,31 +6389,34 @@ rb_f_caller(int argc, VALUE *argv)
}
void
-rb_backtrace(void)
+rb_backtrace()
{
long i;
VALUE ary;
ary = backtrace(-1);
- for (i=0; i<RARRAY_LEN(ary); i++) {
- printf("\tfrom %s\n", RSTRING_PTR(RARRAY_PTR(ary)[i]));
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ printf("\tfrom %s\n", RSTRING(RARRAY(ary)->ptr[i])->ptr);
}
}
static VALUE
-make_backtrace(void)
+make_backtrace()
{
return backtrace(-1);
}
ID
-rb_frame_this_func(void)
+rb_frame_last_func()
{
- return ruby_frame->this_func;
+ return ruby_frame->last_func;
}
static NODE*
-compile(VALUE src, const char *file, int line)
+compile(src, file, line)
+ VALUE src;
+ char *file;
+ int line;
{
NODE *node;
int critical;
@@ -6274,17 +6433,22 @@ compile(VALUE src, const char *file, int line)
}
static VALUE
-eval(VALUE self, VALUE src, VALUE scope, const char *file, int line)
+eval(self, src, scope, file, line)
+ VALUE self, src, scope;
+ char *file;
+ int line;
{
struct BLOCK *data = NULL;
volatile VALUE result = Qnil;
struct SCOPE * volatile old_scope;
+ struct BLOCK * volatile old_block;
struct RVarmap * volatile old_dyna_vars;
VALUE volatile old_cref;
int volatile old_vmode;
volatile VALUE old_wrapper;
struct FRAME frame;
NODE *nodesave = ruby_current_node;
+ volatile int iter = ruby_frame->iter;
volatile int safe = ruby_safe_level;
int state;
@@ -6301,10 +6465,12 @@ eval(VALUE self, VALUE src, VALUE scope, const char *file, int line)
ruby_frame = &(frame);
old_scope = ruby_scope;
ruby_scope = data->scope;
+ old_block = ruby_block;
+ ruby_block = data->prev;
old_dyna_vars = ruby_dyna_vars;
ruby_dyna_vars = data->dyna_vars;
- old_vmode = vis_mode;
- vis_mode = data->vmode;
+ old_vmode = scope_vmode;
+ scope_vmode = data->vmode;
old_cref = (VALUE)ruby_cref;
ruby_cref = data->cref;
old_wrapper = ruby_wrapper;
@@ -6316,15 +6482,22 @@ eval(VALUE self, VALUE src, VALUE scope, const char *file, int line)
}
self = data->self;
+ ruby_frame->iter = data->iter;
+ }
+ else {
+ if (ruby_frame->prev) {
+ ruby_frame->iter = ruby_frame->prev->iter;
+ }
}
if (file == 0) {
ruby_set_current_source();
file = ruby_sourcefile;
line = ruby_sourceline;
}
+ PUSH_CLASS(data ? data->klass : ruby_class);
ruby_in_eval++;
- if (TYPE(ruby_cbase) == T_ICLASS) {
- ruby_cbase = RBASIC(ruby_cbase)->klass;
+ if (TYPE(ruby_class) == T_ICLASS) {
+ ruby_class = RBASIC(ruby_class)->klass;
}
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
@@ -6342,6 +6515,7 @@ eval(VALUE self, VALUE src, VALUE scope, const char *file, int line)
result = eval_node(self, node);
}
POP_TAG();
+ POP_CLASS();
ruby_in_eval--;
if (!NIL_P(scope)) {
int dont_recycle = ruby_scope->flags & SCOPE_DONT_RECYCLE;
@@ -6350,8 +6524,10 @@ eval(VALUE self, VALUE src, VALUE scope, const char *file, int line)
ruby_cref = (NODE*)old_cref;
ruby_frame = frame.tmp;
ruby_scope = old_scope;
+ ruby_block = old_block;
ruby_dyna_vars = old_dyna_vars;
- vis_mode = old_vmode;
+ data->vmode = scope_vmode; /* write back visibility mode */
+ scope_vmode = old_vmode;
if (dont_recycle) {
struct tag *tag;
struct RVarmap *vars;
@@ -6365,21 +6541,25 @@ eval(VALUE self, VALUE src, VALUE scope, const char *file, int line)
}
}
}
+ else {
+ ruby_frame->iter = iter;
+ }
ruby_current_node = nodesave;
ruby_set_current_source();
if (state) {
if (state == TAG_RAISE) {
if (strcmp(file, "(eval)") == 0) {
- VALUE mesg, errat;
+ VALUE mesg, errat, bt2;
errat = get_backtrace(ruby_errinfo);
- mesg = rb_attr_get(ruby_errinfo, rb_intern("mesg"));
- if (!NIL_P(errat) && TYPE(errat) == T_ARRAY) {
+ mesg = rb_attr_get(ruby_errinfo, rb_intern("mesg"));
+ if (!NIL_P(errat) && TYPE(errat) == T_ARRAY &&
+ (bt2 = backtrace(-2), RARRAY(bt2)->len > 0)) {
if (!NIL_P(mesg) && TYPE(mesg) == T_STRING) {
rb_str_update(mesg, 0, 0, rb_str_new2(": "));
- rb_str_update(mesg, 0, 0, RARRAY_PTR(errat)[0]);
+ rb_str_update(mesg, 0, 0, RARRAY(errat)->ptr[0]);
}
- RARRAY_PTR(errat)[0] = RARRAY_PTR(backtrace(-2))[0];
+ RARRAY(errat)->ptr[0] = RARRAY(bt2)->ptr[0];
}
}
rb_exc_raise(ruby_errinfo);
@@ -6410,10 +6590,13 @@ eval(VALUE self, VALUE src, VALUE scope, const char *file, int line)
*/
static VALUE
-rb_f_eval(int argc, VALUE *argv, VALUE self)
+rb_f_eval(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE src, scope, vfile, vline;
- const char *file = "(eval)";
+ char *file = "(eval)";
int line = 1;
rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
@@ -6433,13 +6616,13 @@ rb_f_eval(int argc, VALUE *argv, VALUE self)
line = NUM2INT(vline);
}
- if (!NIL_P(vfile)) file = RSTRING_PTR(vfile);
+ if (!NIL_P(vfile)) file = RSTRING(vfile)->ptr;
if (NIL_P(scope) && ruby_frame->prev) {
struct FRAME *prev;
VALUE val;
prev = ruby_frame;
- PUSH_FRAME(Qfalse);
+ PUSH_FRAME();
*ruby_frame = *prev->prev;
ruby_frame->prev = prev;
val = eval(self, src, scope, file, line);
@@ -6452,40 +6635,47 @@ rb_f_eval(int argc, VALUE *argv, VALUE self)
/* function to call func under the specified class/module context */
static VALUE
-exec_under(VALUE (*func) (VALUE), VALUE under, VALUE args)
+exec_under(func, under, cbase, args)
+ VALUE (*func)();
+ VALUE under, cbase;
+ void *args;
{
VALUE val = Qnil; /* OK */
int state;
int mode;
struct FRAME *f = ruby_frame;
- PUSH_CREF(under);
- PUSH_FRAME(Qtrue);
+ PUSH_CLASS(under);
+ PUSH_FRAME();
ruby_frame->self = f->self;
- ruby_frame->callee = f->callee;
- ruby_frame->this_func = f->this_func;
- ruby_frame->this_class = f->this_class;
+ ruby_frame->last_func = f->last_func;
+ ruby_frame->orig_func = f->orig_func;
+ ruby_frame->last_class = f->last_class;
ruby_frame->argc = f->argc;
+ if (cbase) {
+ PUSH_CREF(cbase);
+ }
- mode = vis_mode;
- VIS_SET(VIS_PUBLIC);
+ mode = scope_vmode;
+ SCOPE_SET(SCOPE_PUBLIC);
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
val = (*func)(args);
}
POP_TAG();
- POP_CREF();
- VIS_SET(mode);
+ if (cbase) POP_CREF();
+ SCOPE_SET(mode);
POP_FRAME();
+ POP_CLASS();
if (state) JUMP_TAG(state);
return val;
}
static VALUE
-eval_under_i(VALUE arg)
+eval_under_i(args)
+ VALUE *args;
{
- VALUE *args = (VALUE *)arg;
struct FRAME *f = ruby_frame;
if (f && (f = f->prev) && (f = f->prev)) {
@@ -6496,7 +6686,10 @@ eval_under_i(VALUE arg)
/* string eval under the class/module context */
static VALUE
-eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line)
+eval_under(under, self, src, file, line)
+ VALUE under, self, src;
+ const char *file;
+ int line;
{
VALUE args[4];
@@ -6510,40 +6703,38 @@ eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line)
args[1] = src;
args[2] = (VALUE)file;
args[3] = (VALUE)line;
- return exec_under(eval_under_i, under, (VALUE)args);
+ return exec_under(eval_under_i, under, under, args);
}
static VALUE
-yield_under_i(VALUE arg)
+yield_under_i(self)
+ VALUE self;
{
- VALUE *args = (VALUE *)arg;
- int flags = YIELD_PUBLIC_DEF;
- if (args[0] != Qundef) flags |= YIELD_VALUES;
-
- return rb_yield_0(args[0], args[1], ruby_cbase, flags);
+ return rb_yield_0(self, self, ruby_class, YIELD_PUBLIC_DEF, Qfalse);
}
/* block eval under the class/module context */
static VALUE
-yield_under(VALUE under, VALUE self, VALUE values)
+yield_under(under, self)
+ VALUE under, self;
{
- VALUE args[2];
- args[0] = values;
- args[1] = self;
- return exec_under(yield_under_i, under, (VALUE)args);
+ return exec_under(yield_under_i, under, 0, self);
}
static VALUE
-specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
+specific_eval(argc, argv, klass, self)
+ int argc;
+ VALUE *argv;
+ VALUE klass, self;
{
if (rb_block_given_p()) {
if (argc > 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
}
- return yield_under(klass, self, Qundef);
+ return yield_under(klass, self);
}
else {
- const char *file = "(eval)";
+ char *file = "(eval)";
int line = 1;
if (argc == 0) {
@@ -6558,8 +6749,8 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
}
if (argc > 3) {
rb_raise(rb_eArgError, "wrong number of arguments: %s(src) or %s{..}",
- rb_id2name(ruby_frame->callee),
- rb_id2name(ruby_frame->callee));
+ rb_id2name(ruby_frame->last_func),
+ rb_id2name(ruby_frame->last_func));
}
if (argc > 2) line = NUM2INT(argv[2]);
if (argc > 1) {
@@ -6582,10 +6773,7 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
* instance variables. In the version of <code>instance_eval</code>
* that takes a +String+, the optional second and third
* parameters supply a filename and starting line number that are used
- * when reporting compilation errors. Note that, if a Proc that is
- * converted from a Method object is given as the block,
- * <code>instance_eval</code> will not change the context of this
- * block and it will be evaluated in Method object's original context.
+ * when reporting compilation errors.
*
* class Klass
* def initialize
@@ -6597,7 +6785,10 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
*/
VALUE
-rb_obj_instance_eval(int argc, VALUE *argv, VALUE self)
+rb_obj_instance_eval(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE klass;
@@ -6612,38 +6803,6 @@ rb_obj_instance_eval(int argc, VALUE *argv, VALUE self)
/*
* call-seq:
- * obj.instance_exec(arg...) {|var...| block } => obj
- *
- * Executes the given block within the context of the receiver
- * (_obj_). In order to set the context, the variable +self+ is set
- * to _obj_ while the code is executing, giving the code access to
- * _obj_'s instance variables. Arguments are passed as block parameters.
- *
- * class Klass
- * def initialize
- * @secret = 99
- * end
- * end
- * k = Klass.new
- * k.instance_exec(5) {|x| @secret+x } #=> 104
- */
-
-VALUE
-rb_obj_instance_exec(int argc, VALUE *argv, VALUE self)
-{
- VALUE klass;
-
- if (SPECIAL_CONST_P(self)) {
- klass = Qnil;
- }
- else {
- klass = rb_singleton_class(self);
- }
- return yield_under(klass, self, rb_ary_new4(argc, argv));
-}
-
-/*
- * call-seq:
* mod.class_eval(string [, filename [, lineno]]) => obj
* mod.module_eval {|| block } => obj
*
@@ -6667,56 +6826,38 @@ rb_obj_instance_exec(int argc, VALUE *argv, VALUE self)
*/
VALUE
-rb_mod_module_eval(int argc, VALUE *argv, VALUE mod)
+rb_mod_module_eval(argc, argv, mod)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
{
return specific_eval(argc, argv, mod, mod);
}
-/*
- * call-seq:
- * mod.module_exec(arg...) {|var...| block } => obj
- * mod.class_exec(arg...) {|var...| block } => obj
- *
- * Evaluates the given block in the context of the class/module.
- * The method defined in the block will belong to the receiver.
- *
- * class Thing
- * end
- * Thing.class_exec{
- * def hello() "Hello there!" end
- * }
- * puts Thing.new.hello()
- *
- * <em>produces:</em>
- *
- * Hello there!
- */
-
-VALUE
-rb_mod_module_exec(int argc, VALUE *argv, VALUE mod)
-{
- return yield_under(mod, mod, rb_ary_new4(argc, argv));
-}
-
VALUE rb_load_path;
-NORETURN(static void load_failed(VALUE));
+NORETURN(static void load_failed _((VALUE)));
void
-rb_load(VALUE fname, int wrap)
+rb_load(fname, wrap)
+ VALUE fname;
+ int wrap;
{
VALUE tmp;
int state;
volatile int prohibit_int = rb_prohibit_interrupt;
- volatile ID callee, this_func;
+ volatile ID last_func;
volatile VALUE wrapper = ruby_wrapper;
volatile VALUE self = ruby_top_self;
- NODE * volatile last_node;
+ NODE *volatile last_node;
NODE *saved_cref = ruby_cref;
- TMP_PROTECT;
- if (!wrap) rb_secure(4);
- FilePathValue(fname);
+ if (wrap && ruby_safe_level >= 4) {
+ StringValue(fname);
+ }
+ else {
+ SafeStringValue(fname);
+ }
fname = rb_str_new4(fname);
tmp = rb_find_file(fname);
if (!tmp) {
@@ -6726,43 +6867,45 @@ rb_load(VALUE fname, int wrap)
ruby_errinfo = Qnil; /* ensure */
PUSH_VARS();
+ PUSH_CLASS(ruby_wrapper);
ruby_cref = ruby_top_cref;
if (!wrap) {
rb_secure(4); /* should alter global state */
+ ruby_class = rb_cObject;
ruby_wrapper = 0;
}
else {
/* load in anonymous module as toplevel */
- ruby_wrapper = rb_module_new();
+ ruby_class = ruby_wrapper = rb_module_new();
self = rb_obj_clone(ruby_top_self);
rb_extend_object(self, ruby_wrapper);
PUSH_CREF(ruby_wrapper);
- /* default visibility is private at loading toplevel */
- VIS_SET(VIS_PRIVATE);
}
- PUSH_FRAME(Qfalse);
+ PUSH_ITER(ITER_NOT);
+ PUSH_FRAME();
+ ruby_frame->last_func = 0;
+ ruby_frame->last_class = 0;
ruby_frame->self = self;
PUSH_SCOPE();
- PUSH_TAG(PROT_NONE);
/* default visibility is private at loading toplevel */
- VIS_SET(VIS_PRIVATE);
+ SCOPE_SET(SCOPE_PRIVATE);
+ PUSH_TAG(PROT_NONE);
state = EXEC_TAG();
- callee = ruby_frame->callee;
- this_func = ruby_frame->this_func;
+ last_func = ruby_frame->last_func;
last_node = ruby_current_node;
if (!ruby_current_node && ruby_sourcefile) {
- last_node = NEW_BEGIN(0);
+ last_node = NEW_NEWLINE(0);
}
ruby_current_node = 0;
if (state == 0) {
- NODE * volatile node;
+ NODE *node;
volatile int critical;
DEFER_INTS;
ruby_in_eval++;
critical = rb_thread_critical;
rb_thread_critical = Qtrue;
- rb_load_file(RSTRING_PTR(fname));
+ rb_load_file(RSTRING(fname)->ptr);
ruby_in_eval--;
node = ruby_eval_tree;
rb_thread_critical = critical;
@@ -6771,12 +6914,11 @@ rb_load(VALUE fname, int wrap)
eval_node(self, node);
}
}
- ruby_frame->callee = callee;
- ruby_frame->this_func = this_func;
+ ruby_frame->last_func = last_func;
ruby_current_node = last_node;
ruby_sourcefile = 0;
ruby_set_current_source();
- if (ruby_scope->flags == SCOPE_ALLOCA && ruby_cbase == rb_cObject) {
+ if (ruby_scope->flags == SCOPE_ALLOCA && ruby_class == rb_cObject) {
if (ruby_scope->local_tbl) /* toplevel was empty */
free(ruby_scope->local_tbl);
}
@@ -6785,6 +6927,8 @@ rb_load(VALUE fname, int wrap)
ruby_cref = saved_cref;
POP_SCOPE();
POP_FRAME();
+ POP_ITER();
+ POP_CLASS();
POP_VARS();
ruby_wrapper = wrapper;
if (ruby_nerrs > 0) {
@@ -6797,18 +6941,18 @@ rb_load(VALUE fname, int wrap)
}
void
-rb_load_protect(VALUE fname, int wrap, int *state)
+rb_load_protect(fname, wrap, state)
+ VALUE fname;
+ int wrap;
+ int *state;
{
int status;
- PUSH_THREAD_TAG();
+ PUSH_TAG(PROT_NONE);
if ((status = EXEC_TAG()) == 0) {
rb_load(fname, wrap);
}
- else if (status == TAG_THREAD) {
- rb_thread_start_1();
- }
- POP_THREAD_TAG();
+ POP_TAG();
if (state) *state = status;
}
@@ -6828,7 +6972,9 @@ rb_load_protect(VALUE fname, int wrap, int *state)
static VALUE
-rb_f_load(int argc, VALUE *argv)
+rb_f_load(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE fname, wrap;
@@ -6848,11 +6994,25 @@ static st_table *loading_tbl;
#define IS_DLEXT(e) (strcmp(e, DLEXT) == 0)
#endif
+
+static const char *const loadable_ext[] = {
+ ".rb", DLEXT,
+#ifdef DLEXT2
+ DLEXT2,
+#endif
+ 0
+};
+
+static int rb_feature_p _((const char *, const char *, int));
+static int search_required _((VALUE, VALUE *, VALUE *));
+
static int
-rb_feature_p(const char *feature, const char *ext, int rb)
+rb_feature_p(feature, ext, rb)
+ const char *feature, *ext;
+ int rb;
{
VALUE v;
- char *f, *e;
+ const char *f, *e;
long i, len, elen;
if (ext) {
@@ -6866,7 +7026,8 @@ rb_feature_p(const char *feature, const char *ext, int rb)
for (i = 0; i < RARRAY_LEN(rb_features); ++i) {
v = RARRAY_PTR(rb_features)[i];
f = StringValuePtr(v);
- if (strncmp(f, feature, len) != 0) continue;
+ if (RSTRING_LEN(v) < len || strncmp(f, feature, len) != 0)
+ continue;
if (!*(e = f + len)) {
if (ext) continue;
return 'u';
@@ -6879,71 +7040,99 @@ rb_feature_p(const char *feature, const char *ext, int rb)
return 'r';
}
}
+ if (loading_tbl) {
+ if (st_lookup(loading_tbl, (st_data_t)feature, 0)) {
+ if (!ext) return 'u';
+ return strcmp(ext, ".rb") ? 's' : 'r';
+ }
+ else {
+ char *buf;
+
+ if (ext && *ext) return 0;
+ buf = ALLOCA_N(char, len + DLEXT_MAXLEN + 1);
+ 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, 0)) {
+ return i ? 's' : 'r';
+ }
+ }
+ }
+ }
return 0;
}
-static const char *const loadable_ext[] = {
- ".rb", DLEXT,
-#ifdef DLEXT2
- DLEXT2,
-#endif
- 0
-};
-
-static int search_required(VALUE, VALUE *);
-
int
-rb_provided(const char *feature)
+rb_provided(feature)
+ const char *feature;
{
- int i;
- char *buf;
- VALUE fname;
+ const char *ext = strrchr(feature, '.');
- if (rb_feature_p(feature, 0, Qfalse))
- return Qtrue;
- if (loading_tbl) {
- if (st_lookup(loading_tbl, (st_data_t)feature, 0)) return Qtrue;
- buf = ALLOCA_N(char, strlen(feature)+8);
- strcpy(buf, feature);
- for (i=0; loadable_ext[i]; i++) {
- strcpy(buf+strlen(feature), loadable_ext[i]);
- if (st_lookup(loading_tbl, (st_data_t)buf, 0)) return Qtrue;
+ if (ext && !strchr(ext, '/')) {
+ if (strcmp(".rb", ext) == 0) {
+ if (rb_feature_p(feature, ext, Qtrue)) return Qtrue;
+ return Qfalse;
+ }
+ else if (IS_SOEXT(ext) || IS_DLEXT(ext)) {
+ if (rb_feature_p(feature, ext, Qfalse)) return Qtrue;
+ return Qfalse;
}
}
- if (search_required(rb_str_new2(feature), &fname)) {
- feature = RSTRING_PTR(fname);
- if (rb_feature_p(feature, 0, Qfalse))
- return Qtrue;
- if (loading_tbl && st_lookup(loading_tbl, (st_data_t)feature, 0))
- return Qtrue;
- }
+ if (rb_feature_p(feature, feature + strlen(feature), Qtrue))
+ return Qtrue;
+
return Qfalse;
}
static void
-rb_provide_feature(VALUE feature)
+rb_provide_feature(feature)
+ VALUE feature;
{
rb_ary_push(rb_features, feature);
}
void
-rb_provide(const char *feature)
+rb_provide(feature)
+ const char *feature;
{
rb_provide_feature(rb_str_new2(feature));
}
-static int
-load_wait(char *ftptr)
+static char *
+load_lock(ftptr)
+ const char *ftptr;
{
st_data_t th;
- if (!loading_tbl) return Qfalse;
- if (!st_lookup(loading_tbl, (st_data_t)ftptr, &th)) return Qfalse;
+ if (!loading_tbl ||
+ !st_lookup(loading_tbl, (st_data_t)ftptr, &th))
+ {
+ /* loading ruby library should be serialized. */
+ if (!loading_tbl) {
+ loading_tbl = st_init_strtable();
+ }
+ /* partial state */
+ ftptr = ruby_strdup(ftptr);
+ st_insert(loading_tbl, (st_data_t)ftptr, (st_data_t)curr_thread);
+ return (char *)ftptr;
+ }
do {
- if ((rb_thread_t)th == curr_thread) return Qtrue;
+ if ((rb_thread_t)th == curr_thread) return 0;
CHECK_INTS;
} while (st_lookup(loading_tbl, (st_data_t)ftptr, &th));
- return Qtrue;
+ return 0;
+}
+
+static void
+load_unlock(const char *ftptr)
+{
+ if (ftptr) {
+ st_data_t key = (st_data_t)ftptr;
+
+ if (st_delete(loading_tbl, &key, 0)) {
+ free((char *)key);
+ }
+ }
}
/*
@@ -6969,139 +7158,114 @@ load_wait(char *ftptr)
*/
VALUE
-rb_f_require(VALUE obj, VALUE fname)
+rb_f_require(obj, fname)
+ VALUE obj, fname;
{
return rb_require_safe(fname, ruby_safe_level);
}
static int
-search_required(VALUE fname, VALUE *path)
+search_required(fname, featurep, path)
+ VALUE fname, *featurep, *path;
{
VALUE tmp;
char *ext, *ftptr;
- int type, ft = 0;
+ int type;
+ *featurep = fname;
*path = 0;
ext = strrchr(ftptr = RSTRING_PTR(fname), '.');
if (ext && !strchr(ext, '/')) {
if (strcmp(".rb", ext) == 0) {
if (rb_feature_p(ftptr, ext, Qtrue)) return 'r';
- if (tmp = rb_find_file(fname)) {
- tmp = rb_file_expand_path(tmp, Qnil);
- ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
- if (!rb_feature_p(ftptr, ext, Qtrue))
- *path = tmp;
- 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)) return 's';
tmp = rb_str_new(RSTRING_PTR(fname), ext-RSTRING_PTR(fname));
+ *featurep = tmp;
#ifdef DLEXT2
OBJ_FREEZE(tmp);
if (rb_find_file_ext(&tmp, loadable_ext+1)) {
- tmp = rb_file_expand_path(tmp, Qnil);
- ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
- if (!rb_feature_p(ftptr, ext, Qfalse))
- *path = tmp;
+ *featurep = tmp;
+ *path = rb_find_file(tmp);
return 's';
}
#else
rb_str_cat2(tmp, DLEXT);
OBJ_FREEZE(tmp);
- if (tmp = rb_find_file(tmp)) {
- tmp = rb_file_expand_path(tmp, Qnil);
- ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
- if (!rb_feature_p(ftptr, ext, Qfalse))
- *path = tmp;
+ if ((*path = rb_find_file(tmp)) != 0) {
return 's';
}
#endif
}
else if (IS_DLEXT(ext)) {
if (rb_feature_p(ftptr, ext, Qfalse)) return 's';
- if (tmp = rb_find_file(fname)) {
- tmp = rb_file_expand_path(tmp, Qnil);
- ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
- if (!rb_feature_p(ftptr, ext, Qfalse))
- *path = tmp;
- return 's';
- }
+ if ((*path = rb_find_file(fname)) != 0) return 's';
}
}
- else if ((ft = rb_feature_p(ftptr, 0, Qfalse)) == 'r') {
- return 'r';
- }
tmp = fname;
type = rb_find_file_ext(&tmp, loadable_ext);
- tmp = rb_file_expand_path(tmp, Qnil);
+ *featurep = tmp;
switch (type) {
case 0:
ftptr = RSTRING_PTR(tmp);
- if (ft) break;
return rb_feature_p(ftptr, 0, Qfalse);
default:
- if (ft) break;
- case 1:
- ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
+ ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
if (rb_feature_p(ftptr, ext, !--type)) break;
- *path = tmp;
+ *path = rb_find_file(tmp);
}
return type ? 's' : 'r';
}
static void
-load_failed(VALUE fname)
+load_failed(fname)
+ VALUE fname;
{
- rb_raise(rb_eLoadError, "no such file to load -- %s", RSTRING_PTR(fname));
+ rb_raise(rb_eLoadError, "no such file to load -- %s", RSTRING(fname)->ptr);
}
VALUE
-rb_require_safe(VALUE fname, int safe)
+rb_require_safe(fname, safe)
+ VALUE fname;
+ int safe;
{
VALUE result = Qnil;
volatile VALUE errinfo = ruby_errinfo;
int state;
struct {
NODE *node;
- ID this_func, callee;
- int safe, vmode;
+ ID func;
+ int vmode, safe;
} volatile saved;
char *volatile ftptr = 0;
+ if (OBJ_TAINTED(fname)) {
+ rb_check_safe_obj(fname);
+ }
+ StringValue(fname);
+ fname = rb_str_new4(fname);
+ saved.vmode = scope_vmode;
saved.node = ruby_current_node;
- saved.callee = ruby_frame->callee;
- saved.this_func = ruby_frame->this_func;
+ saved.func = ruby_frame->last_func;
saved.safe = ruby_safe_level;
- saved.vmode = vis_mode;
- PUSH_SCOPE();
- PUSH_CREF(ruby_cbase);
- VIS_SET(VIS_PUBLIC);
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
- VALUE path;
+ VALUE feature, path;
long handle;
int found;
ruby_safe_level = safe;
- FilePathValue(fname);
- *(volatile VALUE *)&fname = rb_str_new4(fname);
- found = search_required(fname, &path);
+ found = search_required(fname, &feature, &path);
if (found) {
- if (!path || load_wait(RSTRING_PTR(path))) {
+ if (!path || !(ftptr = load_lock(RSTRING_PTR(feature)))) {
result = Qfalse;
}
else {
ruby_safe_level = 0;
- /* loading ruby library should be serialized. */
- if (!loading_tbl) {
- loading_tbl = st_init_strtable();
- }
- /* partial state */
- ftptr = ruby_strdup(RSTRING_PTR(path));
- st_insert(loading_tbl, (st_data_t)ftptr, (st_data_t)curr_thread);
switch (found) {
case 'r':
rb_load(path, 0);
@@ -7109,16 +7273,15 @@ rb_require_safe(VALUE fname, int safe)
case 's':
ruby_current_node = 0;
- ruby_sourcefile = rb_source_filename(RSTRING_PTR(path));
+ ruby_sourcefile = rb_source_filename(RSTRING(path)->ptr);
ruby_sourceline = 0;
- ruby_frame->callee = 0;
- ruby_frame->this_func = 0;
- VIS_SET(VIS_PUBLIC);
- handle = (long)dln_load(RSTRING_PTR(path));
+ ruby_frame->last_func = 0;
+ SCOPE_SET(SCOPE_PUBLIC);
+ handle = (long)dln_load(RSTRING(path)->ptr);
rb_ary_push(ruby_dln_librefs, LONG2NUM(handle));
break;
}
- rb_provide_feature(path);
+ rb_provide_feature(feature);
result = Qtrue;
}
}
@@ -7126,17 +7289,10 @@ rb_require_safe(VALUE fname, int safe)
POP_TAG();
ruby_current_node = saved.node;
ruby_set_current_source();
- ruby_frame->this_func = saved.this_func;
- ruby_frame->callee = saved.callee;
+ ruby_frame->last_func = saved.func;
+ SCOPE_SET(saved.vmode);
ruby_safe_level = saved.safe;
- VIS_SET(saved.vmode);
- POP_CREF();
- POP_SCOPE();
- if (ftptr) {
- if (st_delete(loading_tbl, (st_data_t *)&ftptr, 0)) { /* loading done */
- free(ftptr);
- }
- }
+ load_unlock(ftptr);
if (state) JUMP_TAG(state);
if (NIL_P(result)) {
load_failed(fname);
@@ -7147,15 +7303,35 @@ rb_require_safe(VALUE fname, int safe)
}
VALUE
-rb_require(const char *fname)
+rb_require(fname)
+ const char *fname;
{
VALUE fn = rb_str_new2(fname);
OBJ_FREEZE(fn);
return rb_require_safe(fn, ruby_safe_level);
}
+void
+ruby_init_ext(name, init)
+ const char *name;
+ void (*init) _((void));
+{
+ ruby_current_node = 0;
+ ruby_sourcefile = rb_source_filename(name);
+ ruby_sourceline = 0;
+ ruby_frame->last_func = 0;
+ ruby_frame->orig_func = 0;
+ SCOPE_SET(SCOPE_PUBLIC);
+ if (load_lock(name)) {
+ (*init)();
+ rb_provide(name);
+ load_unlock(name);
+ }
+}
+
static void
-secure_visibility(VALUE self)
+secure_visibility(self)
+ VALUE self;
{
if (ruby_safe_level >= 4 && !OBJ_TAINTED(self)) {
rb_raise(rb_eSecurityError, "Insecure: can't change method visibility");
@@ -7163,7 +7339,11 @@ secure_visibility(VALUE self)
}
static void
-set_method_visibility(VALUE self, int argc, VALUE *argv, ID ex)
+set_method_visibility(self, argc, argv, ex)
+ VALUE self;
+ int argc;
+ VALUE *argv;
+ ID ex;
{
int i;
@@ -7171,6 +7351,7 @@ set_method_visibility(VALUE self, int argc, VALUE *argv, ID ex)
for (i=0; i<argc; i++) {
rb_export_method(self, rb_to_id(argv[i]), ex);
}
+ rb_clear_cache_by_class(self);
}
/*
@@ -7184,11 +7365,14 @@ set_method_visibility(VALUE self, int argc, VALUE *argv, ID ex)
*/
static VALUE
-rb_mod_public(int argc, VALUE *argv, VALUE module)
+rb_mod_public(argc, argv, module)
+ int argc;
+ VALUE *argv;
+ VALUE module;
{
secure_visibility(module);
if (argc == 0) {
- VIS_SET(VIS_PUBLIC);
+ SCOPE_SET(SCOPE_PUBLIC);
}
else {
set_method_visibility(module, argc, argv, NOEX_PUBLIC);
@@ -7207,11 +7391,14 @@ rb_mod_public(int argc, VALUE *argv, VALUE module)
*/
static VALUE
-rb_mod_protected(int argc, VALUE *argv, VALUE module)
+rb_mod_protected(argc, argv, module)
+ int argc;
+ VALUE *argv;
+ VALUE module;
{
secure_visibility(module);
if (argc == 0) {
- VIS_SET(VIS_PROTECTED);
+ SCOPE_SET(SCOPE_PROTECTED);
}
else {
set_method_visibility(module, argc, argv, NOEX_PROTECTED);
@@ -7239,11 +7426,14 @@ rb_mod_protected(int argc, VALUE *argv, VALUE module)
*/
static VALUE
-rb_mod_private(int argc, VALUE *argv, VALUE module)
+rb_mod_private(argc, argv, module)
+ int argc;
+ VALUE *argv;
+ VALUE module;
{
secure_visibility(module);
if (argc == 0) {
- VIS_SET(VIS_PRIVATE);
+ SCOPE_SET(SCOPE_PRIVATE);
}
else {
set_method_visibility(module, argc, argv, NOEX_PRIVATE);
@@ -7253,37 +7443,16 @@ rb_mod_private(int argc, VALUE *argv, VALUE module)
/*
* call-seq:
- * local => self
- * local(symbol, ...) => self
- *
- * With no arguments, sets the default visibility for subsequently
- * defined methods to local. With arguments, sets the named methods to
- * have local visibility.
- */
-
-static VALUE
-rb_mod_local(int argc, VALUE *argv, VALUE module)
-{
- secure_visibility(module);
- if (argc == 0) {
- VIS_SET(VIS_LOCAL);
- }
- else {
- set_method_visibility(module, argc, argv, NOEX_LOCAL);
- rb_clear_cache();
- }
- return module;
-}
-
-/*
- * call-seq:
* mod.public_class_method(symbol, ...) => mod
*
* Makes a list of existing class methods public.
*/
static VALUE
-rb_mod_public_method(int argc, VALUE *argv, VALUE obj)
+rb_mod_public_method(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
set_method_visibility(CLASS_OF(obj), argc, argv, NOEX_PUBLIC);
return obj;
@@ -7306,7 +7475,10 @@ rb_mod_public_method(int argc, VALUE *argv, VALUE obj)
*/
static VALUE
-rb_mod_private_method(int argc, VALUE *argv, VALUE obj)
+rb_mod_private_method(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
set_method_visibility(CLASS_OF(obj), argc, argv, NOEX_PRIVATE);
return obj;
@@ -7323,23 +7495,17 @@ rb_mod_private_method(int argc, VALUE *argv, VALUE obj)
*/
static VALUE
-top_public(int argc, VALUE *argv)
+top_public(argc, argv)
+ int argc;
+ VALUE *argv;
{
return rb_mod_public(argc, argv, rb_cObject);
}
-/*
- * call-seq:
- * private => self
- * private(symbol, ...) => self
- *
- * With no arguments, sets the default visibility for subsequently
- * defined methods to private. With arguments, sets the named methods
- * to have private visibility.
- */
-
static VALUE
-top_private(int argc, VALUE *argv)
+top_private(argc, argv)
+ int argc;
+ VALUE *argv;
{
return rb_mod_private(argc, argv, rb_cObject);
}
@@ -7381,7 +7547,10 @@ top_private(int argc, VALUE *argv)
*/
static VALUE
-rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
+rb_mod_modfunc(argc, argv, module)
+ int argc;
+ VALUE *argv;
+ VALUE module;
{
int i;
ID id;
@@ -7393,7 +7562,7 @@ rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
secure_visibility(module);
if (argc == 0) {
- VIS_SET(VIS_MODFUNC);
+ SCOPE_SET(SCOPE_MODFUNC);
return module;
}
@@ -7403,9 +7572,9 @@ rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
id = rb_to_id(argv[i]);
for (;;) {
- body = search_method(m, id, &m, LOOKUP_NOSKIP, 0);
+ body = search_method(m, id, &m);
if (body == 0) {
- body = search_method(rb_cObject, id, &m, LOOKUP_NOSKIP, 0);
+ body = search_method(rb_cObject, id, &m);
}
if (body == 0 || body->nd_body == 0) {
rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
@@ -7434,17 +7603,18 @@ rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
*/
static VALUE
-rb_mod_append_features(VALUE module, VALUE dest)
+rb_mod_append_features(module, include)
+ VALUE module, include;
{
- switch (TYPE(dest)) {
+ switch (TYPE(include)) {
case T_CLASS:
case T_MODULE:
break;
default:
- Check_Type(dest, T_CLASS);
+ Check_Type(include, T_CLASS);
break;
}
- rb_include_module(dest, module);
+ rb_include_module(include, module);
return module;
}
@@ -7457,7 +7627,10 @@ rb_mod_append_features(VALUE module, VALUE dest)
*/
static VALUE
-rb_mod_include(int argc, VALUE *argv, VALUE module)
+rb_mod_include(argc, argv, module)
+ int argc;
+ VALUE *argv;
+ VALUE module;
{
int i;
@@ -7470,14 +7643,19 @@ rb_mod_include(int argc, VALUE *argv, VALUE module)
}
void
-rb_obj_call_init(VALUE obj, int argc, VALUE *argv)
+rb_obj_call_init(obj, argc, argv)
+ VALUE obj;
+ int argc;
+ VALUE *argv;
{
- rb_call(CLASS_OF(obj), obj, init, argc, argv,
- ruby_frame->block, CALLING_FUNCALL, 1, Qundef);
+ PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT);
+ rb_funcall2(obj, init, argc, argv);
+ POP_ITER();
}
void
-rb_extend_object(VALUE obj, VALUE module)
+rb_extend_object(obj, module)
+ VALUE obj, module;
{
rb_include_module(rb_singleton_class(obj), module);
}
@@ -7510,7 +7688,8 @@ rb_extend_object(VALUE obj, VALUE module)
*/
static VALUE
-rb_mod_extend_object(VALUE mod, VALUE obj)
+rb_mod_extend_object(mod, obj)
+ VALUE mod, obj;
{
rb_extend_object(obj, mod);
return obj;
@@ -7542,7 +7721,10 @@ rb_mod_extend_object(VALUE mod, VALUE obj)
*/
static VALUE
-rb_obj_extend(int argc, VALUE *argv, VALUE obj)
+rb_obj_extend(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
int i;
@@ -7567,7 +7749,10 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj)
*/
static VALUE
-top_include(int argc, VALUE *argv, VALUE self)
+top_include(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
rb_secure(4);
if (ruby_wrapper) {
@@ -7577,11 +7762,14 @@ top_include(int argc, VALUE *argv, VALUE self)
return rb_mod_include(argc, argv, rb_cObject);
}
-VALUE rb_f_trace_var(int, VALUE *);
-VALUE rb_f_untrace_var(int, VALUE *);
+VALUE rb_f_trace_var();
+VALUE rb_f_untrace_var();
static void
-errinfo_setter(VALUE val, ID id, VALUE *var)
+errinfo_setter(val, id, var)
+ VALUE val;
+ ID id;
+ VALUE *var;
{
if (!NIL_P(val) && !rb_obj_is_kind_of(val, rb_eException)) {
rb_raise(rb_eTypeError, "assigning non-exception to $!");
@@ -7590,13 +7778,17 @@ errinfo_setter(VALUE val, ID id, VALUE *var)
}
static VALUE
-errat_getter(ID id)
+errat_getter(id)
+ ID id;
{
return get_backtrace(ruby_errinfo);
}
static void
-errat_setter(VALUE val, ID id, VALUE *var)
+errat_setter(val, id, var)
+ VALUE val;
+ ID id;
+ VALUE *var;
{
if (NIL_P(ruby_errinfo)) {
rb_raise(rb_eArgError, "$! not set");
@@ -7618,7 +7810,7 @@ errat_setter(VALUE val, ID id, VALUE *var)
*/
static VALUE
-rb_f_local_variables(void)
+rb_f_local_variables()
{
ID *tbl;
int n, i;
@@ -7630,14 +7822,14 @@ rb_f_local_variables(void)
n = *tbl++;
for (i=2; i<n; i++) { /* skip first 2 ($_ and $~) */
if (!rb_is_local_id(tbl[i])) continue; /* skip flip states */
- rb_ary_push(ary, ID2SYM(tbl[i]));
+ rb_ary_push(ary, rb_str_new2(rb_id2name(tbl[i])));
}
}
vars = ruby_dyna_vars;
while (vars) {
if (vars->id && rb_is_local_id(vars->id)) { /* skip $_, $~ and flip states */
- rb_ary_push(ary, ID2SYM(vars->id));
+ rb_ary_push(ary, rb_str_new2(rb_id2name(vars->id)));
}
vars = vars->next;
}
@@ -7645,8 +7837,8 @@ rb_f_local_variables(void)
return ary;
}
-static VALUE rb_f_catch(VALUE,VALUE);
-NORETURN(static VALUE rb_f_throw(int,VALUE*));
+static VALUE rb_f_catch _((VALUE,VALUE));
+NORETURN(static VALUE rb_f_throw _((int,VALUE*)));
struct end_proc_data {
void (*func)();
@@ -7658,7 +7850,9 @@ struct end_proc_data {
static struct end_proc_data *end_procs, *ephemeral_end_procs, *tmp_end_procs;
void
-rb_set_end_proc(void (*func) (VALUE), VALUE data)
+rb_set_end_proc(func, data)
+ void (*func) _((VALUE));
+ VALUE data;
{
struct end_proc_data *link = ALLOC(struct end_proc_data);
struct end_proc_data **list;
@@ -7673,7 +7867,7 @@ rb_set_end_proc(void (*func) (VALUE), VALUE data)
}
void
-rb_mark_end_proc(void)
+rb_mark_end_proc()
{
struct end_proc_data *link;
@@ -7694,20 +7888,29 @@ rb_mark_end_proc(void)
}
}
+static void call_end_proc _((VALUE data));
+
static void
-call_end_proc(VALUE data)
+call_end_proc(data)
+ VALUE data;
{
- PUSH_FRAME(Qfalse);
+ PUSH_ITER(ITER_NOT);
+ PUSH_FRAME();
ruby_frame->self = ruby_frame->prev->self;
ruby_frame->node = 0;
- proc_invoke(data, rb_ary_new2(0), Qundef, 0, INVOKE_VALUES);
+ ruby_frame->last_func = 0;
+ ruby_frame->last_class = 0;
+ proc_invoke(data, rb_ary_new2(0), Qundef, 0);
POP_FRAME();
+ POP_ITER();
}
static void
-rb_f_END(void)
+rb_f_END()
{
- PUSH_FRAME(Qfalse);
+ PUSH_FRAME();
+ ruby_frame->argc = 0;
+ ruby_frame->iter = ITER_CUR;
rb_set_end_proc(call_end_proc, rb_block_proc());
POP_FRAME();
}
@@ -7734,7 +7937,7 @@ rb_f_END(void)
*/
static VALUE
-rb_f_at_exit(void)
+rb_f_at_exit()
{
VALUE proc;
@@ -7747,7 +7950,7 @@ rb_f_at_exit(void)
}
void
-rb_exec_end_proc(void)
+rb_exec_end_proc()
{
struct end_proc_data *link, *tmp;
int status;
@@ -7792,74 +7995,8 @@ rb_exec_end_proc(void)
ruby_safe_level = safe;
}
-/*
- * call-seq:
- * __method__ => symbol
- *
- * Returns the name of the current method as a Symbol.
- * If called from inside of an aliased method it will return the original
- * nonaliased name.
- * If called outside of a method, it returns <code>nil</code>.
- *
- * def foo
- * __method__
- * end
- * alias bar foo
- *
- * foo # => :foo
- * bar # => :foo
- *
- * See also <code>\_\_callee__</code>.
- *
- */
-
-static VALUE
-rb_f_method_name(void)
-{
- struct FRAME* prev = ruby_frame->prev;
- if (prev && prev->this_func) {
- return ID2SYM(prev->this_func);
- }
- else {
- return Qnil;
- }
-}
-
-/*
- * call-seq:
- * __callee__ => symbol
- *
- * Returns the name of the current method as Symbol.
- * If called from inside of an aliased method it will return the aliased
- * name.
- * If called outside of a method, it returns <code>nil</code>.
- *
- * def foo
- * __callee__
- * end
- * alias bar foo
- *
- * foo # => :foo
- * bar # => :bar
- *
- * See also <code>\_\_method__</code>.
- *
- */
-
-static VALUE
-rb_f_callee_name(void)
-{
- struct FRAME* prev = ruby_frame->prev;
- if (prev && prev->callee) {
- return ID2SYM(prev->callee);
- }
- else {
- return Qnil;
- }
-}
-
void
-Init_eval(void)
+Init_eval()
{
init = rb_intern("initialize");
eqq = rb_intern("===");
@@ -7876,13 +8013,14 @@ Init_eval(void)
undefined = rb_intern("method_undefined");
singleton_undefined = rb_intern("singleton_method_undefined");
- object_id = rb_intern("object_id");
- __send = rb_intern("__send");
- __send_bang = rb_intern("__send!");
+ __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);
- rb_global_variable((VALUE*)&ruby_dyna_vars);
+ rb_global_variable((void *)&ruby_eval_tree);
+ rb_global_variable((void *)&ruby_dyna_vars);
rb_define_virtual_variable("$@", errat_getter, errat_setter);
rb_define_hooked_variable("$!", &ruby_errinfo, 0, errinfo_setter);
@@ -7890,13 +8028,13 @@ Init_eval(void)
rb_define_global_function("eval", rb_f_eval, -1);
rb_define_global_function("iterator?", rb_f_block_given_p, 0);
rb_define_global_function("block_given?", rb_f_block_given_p, 0);
+ rb_define_global_function("method_missing", rb_method_missing, -1);
rb_define_global_function("loop", rb_f_loop, 0);
- rb_define_private_method(rb_cBasicObject, "method_missing", rb_method_missing, -1);
- rb_define_method(rb_cBasicObject, "respond_to?", obj_respond_to, -1);
+ rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1);
respond_to = rb_intern("respond_to?");
- rb_global_variable((VALUE*)&basic_respond_to);
- basic_respond_to = rb_method_node(rb_cBasicObject, respond_to);
+ rb_global_variable((void *)&basic_respond_to);
+ basic_respond_to = rb_method_node(rb_cObject, respond_to);
rb_define_global_function("raise", rb_f_raise, -1);
rb_define_global_function("fail", rb_f_raise, -1);
@@ -7913,17 +8051,9 @@ Init_eval(void)
rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */
rb_define_global_function("local_variables", rb_f_local_variables, 0);
- rb_define_global_function("__method__", rb_f_method_name, 0);
- rb_define_global_function("__callee__", rb_f_callee_name, 0);
-
- rb_define_method(rb_cBasicObject, "send", rb_f_send, -1);
- rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1);
- rb_define_method(rb_cBasicObject, "__send", rb_f_send, -1);
- rb_define_method(rb_cBasicObject, "funcall", rb_f_funcall, -1);
- rb_define_method(rb_cBasicObject, "__send!", rb_f_funcall, -1);
+ rb_define_method(rb_mKernel, "send", rb_f_send, -1);
+ rb_define_method(rb_mKernel, "__send__", rb_f_send, -1);
rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1);
- rb_define_method(rb_mKernel, "instance_exec", rb_obj_instance_exec, -1);
- rb_define_method(rb_mKernel, "define_singleton_method", rb_obj_define_method, -1);
rb_define_private_method(rb_cModule, "append_features", rb_mod_append_features, 1);
rb_define_private_method(rb_cModule, "extend_object", rb_mod_extend_object, 1);
@@ -7931,9 +8061,8 @@ Init_eval(void)
rb_define_private_method(rb_cModule, "public", rb_mod_public, -1);
rb_define_private_method(rb_cModule, "protected", rb_mod_protected, -1);
rb_define_private_method(rb_cModule, "private", rb_mod_private, -1);
- rb_define_private_method(rb_cModule, "local", rb_mod_local, -1);
rb_define_private_method(rb_cModule, "module_function", rb_mod_modfunc, -1);
- rb_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, -1);
+ rb_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, 1);
rb_define_method(rb_cModule, "public_method_defined?", rb_mod_public_method_defined, 1);
rb_define_method(rb_cModule, "private_method_defined?", rb_mod_private_method_defined, 1);
rb_define_method(rb_cModule, "protected_method_defined?", rb_mod_protected_method_defined, 1);
@@ -7941,8 +8070,6 @@ Init_eval(void)
rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1);
rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
- rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1);
- rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1);
rb_undef_method(rb_cClass, "module_function");
@@ -7973,7 +8100,7 @@ Init_eval(void)
* call-seq:
* mod.autoload(name, filename) => nil
*
- * Registers _filename_ to be loaded (using <code>Kernel::require</code>)
+ * Registers _filename_ to be loaded (using <code>Kernel::require</code>)
* the first time that _name_ (which may be a <code>String</code> or
* a symbol) is accessed in the namespace of _mod_.
*
@@ -7984,12 +8111,15 @@ Init_eval(void)
*/
static VALUE
-rb_mod_autoload(VALUE mod, VALUE sym, VALUE file)
+rb_mod_autoload(mod, sym, file)
+ VALUE mod;
+ VALUE sym;
+ VALUE file;
{
ID id = rb_to_id(sym);
Check_SafeStr(file);
- rb_autoload(mod, id, RSTRING_PTR(file));
+ rb_autoload(mod, id, RSTRING(file)->ptr);
return Qnil;
}
@@ -8007,7 +8137,8 @@ rb_mod_autoload(VALUE mod, VALUE sym, VALUE file)
*/
static VALUE
-rb_mod_autoload_p(VALUE mod, VALUE sym)
+rb_mod_autoload_p(mod, sym)
+ VALUE mod, sym;
{
return rb_autoload_p(mod, rb_to_id(sym));
}
@@ -8016,7 +8147,7 @@ rb_mod_autoload_p(VALUE mod, VALUE sym)
* call-seq:
* autoload(module, filename) => nil
*
- * Registers _filename_ to be loaded (using <code>Kernel::require</code>)
+ * Registers _filename_ to be loaded (using <code>Kernel::require</code>)
* the first time that _module_ (which may be a <code>String</code> or
* a symbol) is accessed.
*
@@ -8024,7 +8155,10 @@ rb_mod_autoload_p(VALUE mod, VALUE sym)
*/
static VALUE
-rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
+rb_f_autoload(obj, sym, file)
+ VALUE obj;
+ VALUE sym;
+ VALUE file;
{
if (NIL_P(ruby_cbase)) {
rb_raise(rb_eTypeError, "no class/module for autoload target");
@@ -8034,17 +8168,19 @@ rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
/*
* call-seq:
- * autoload(module) => filename or nil
+ * autoload(module, filename) => nil
*
- * Returns _filename_ to be loaded if _module_ is registered as
- * +autoload+.
+ * Registers _filename_ to be loaded (using <code>Kernel::require</code>)
+ * the first time that _module_ (which may be a <code>String</code> or
+ * a symbol) is accessed.
*
* autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
- * autoload?(:MyModule) # => "/usr/local/lib/modules/my_module.rb"
*/
static VALUE
-rb_f_autoload_p(VALUE obj, VALUE sym)
+rb_f_autoload_p(obj, sym)
+ VALUE obj;
+ VALUE sym;
{
/* use ruby_cbase as same as rb_f_autoload. */
if (NIL_P(ruby_cbase)) {
@@ -8054,7 +8190,7 @@ rb_f_autoload_p(VALUE obj, VALUE sym)
}
void
-Init_load(void)
+Init_load()
{
rb_define_readonly_variable("$:", &rb_load_path);
rb_define_readonly_variable("$-I", &rb_load_path);
@@ -8078,9 +8214,10 @@ Init_load(void)
}
static void
-scope_dup(struct SCOPE *scope)
+scope_dup(scope)
+ struct SCOPE *scope;
{
- volatile ID *tbl;
+ ID *tbl;
VALUE *vars;
scope->flags |= SCOPE_DONT_RECYCLE;
@@ -8097,7 +8234,8 @@ scope_dup(struct SCOPE *scope)
}
static void
-blk_mark(struct BLOCK *data)
+blk_mark(data)
+ struct BLOCK *data;
{
while (data) {
rb_gc_mark_frame(&data->frame);
@@ -8109,12 +8247,13 @@ blk_mark(struct BLOCK *data)
rb_gc_mark((VALUE)data->cref);
rb_gc_mark(data->wrapper);
rb_gc_mark(data->block_obj);
- data = data->frame.block;
+ data = data->prev;
}
}
static void
-frame_free(struct FRAME *frame)
+frame_free(frame)
+ struct FRAME *frame;
{
struct FRAME *tmp;
@@ -8127,20 +8266,22 @@ frame_free(struct FRAME *frame)
}
static void
-blk_free(struct BLOCK *data)
+blk_free(data)
+ struct BLOCK *data;
{
void *tmp;
while (data) {
frame_free(&data->frame);
tmp = data;
- data = data->frame.block;
+ data = data->prev;
free(tmp);
}
}
static void
-frame_dup(struct FRAME *frame)
+frame_dup(frame)
+ struct FRAME *frame;
{
struct FRAME *tmp;
@@ -8154,40 +8295,44 @@ frame_dup(struct FRAME *frame)
}
}
-static void
-dvar_nail_down(struct RVarmap *vars)
-{
- while (vars) {
- if (FL_TEST(vars, DVAR_DONT_RECYCLE)) break;
- FL_SET(vars, DVAR_DONT_RECYCLE);
- vars = vars->next;
- }
-}
static void
-blk_nail_down(struct BLOCK *block)
+blk_copy_prev(block)
+ struct BLOCK *block;
{
struct BLOCK *tmp;
+ struct RVarmap* vars;
- dvar_nail_down(block->dyna_vars);
- while (block->frame.block) {
+ while (block->prev) {
tmp = ALLOC_N(struct BLOCK, 1);
- MEMCPY(tmp, block->frame.block, struct BLOCK, 1);
+ MEMCPY(tmp, block->prev, struct BLOCK, 1);
scope_dup(tmp->scope);
frame_dup(&tmp->frame);
- dvar_nail_down(tmp->dyna_vars);
- block->frame.block = tmp;
+
+ for (vars = tmp->dyna_vars; vars; vars = vars->next) {
+ if (FL_TEST(vars, DVAR_DONT_RECYCLE)) break;
+ FL_SET(vars, DVAR_DONT_RECYCLE);
+ }
+
+ block->prev = tmp;
block = tmp;
}
}
static void
-blk_dup(struct BLOCK *dup, struct BLOCK *orig)
+blk_dup(dup, orig)
+ struct BLOCK *dup, *orig;
{
MEMCPY(dup, orig, struct BLOCK, 1);
frame_dup(&dup->frame);
- blk_nail_down(dup);
+
+ if (dup->iter) {
+ blk_copy_prev(dup);
+ }
+ else {
+ dup->prev = 0;
+ }
}
/*
@@ -8195,7 +8340,8 @@ blk_dup(struct BLOCK *dup, struct BLOCK *orig)
*/
static VALUE
-proc_clone(VALUE self)
+proc_clone(self)
+ VALUE self;
{
struct BLOCK *orig, *data;
VALUE bind;
@@ -8204,7 +8350,6 @@ proc_clone(VALUE self)
bind = Data_Make_Struct(rb_obj_class(self),struct BLOCK,blk_mark,blk_free,data);
CLONESETUP(bind, self);
blk_dup(data, orig);
- if (orig->block_obj) data->block_obj = bind;
return bind;
}
@@ -8213,15 +8358,25 @@ proc_clone(VALUE 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(VALUE self)
+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;
}
@@ -8243,152 +8398,127 @@ proc_dup(VALUE self)
*/
static VALUE
-rb_f_binding(VALUE self)
+rb_f_binding(self)
+ VALUE self;
{
- struct BLOCK *data;
+ struct BLOCK *data, *p;
+ struct RVarmap *vars;
VALUE bind;
- PUSH_FRAME(Qtrue);
- PUSH_BLOCK(ruby_frame->block,0,0);
+ PUSH_BLOCK(0,0);
bind = Data_Make_Struct(rb_cBinding,struct BLOCK,blk_mark,blk_free,data);
- *data = *ruby_frame->block;
+ *data = *ruby_block;
data->orig_thread = rb_thread_current();
data->wrapper = ruby_wrapper;
+ data->iter = rb_f_block_given_p();
frame_dup(&data->frame);
if (ruby_frame->prev) {
- data->frame.callee = ruby_frame->prev->callee;
- data->frame.this_func = ruby_frame->prev->this_func;
- data->frame.this_class = ruby_frame->prev->this_class;
+ data->frame.last_func = ruby_frame->prev->last_func;
+ data->frame.last_class = ruby_frame->prev->last_class;
+ data->frame.orig_func = ruby_frame->prev->orig_func;
+ }
+
+ if (data->iter) {
+ blk_copy_prev(data);
+ }
+ else {
+ data->prev = 0;
+ }
+
+ for (p = data; p; p = p->prev) {
+ for (vars = p->dyna_vars; vars; vars = vars->next) {
+ if (FL_TEST(vars, DVAR_DONT_RECYCLE)) break;
+ FL_SET(vars, DVAR_DONT_RECYCLE);
+ }
}
- blk_nail_down(data);
scope_dup(data->scope);
POP_BLOCK();
- POP_FRAME();
return bind;
}
-/*
- * call-seq:
- * binding.eval(string [, filename [,lineno]]) => obj
- *
- * Evaluates the Ruby expression(s) in <em>string</em>, in the
- * <em>binding</em>'s context. If the optional <em>filename</em> and
- * <em>lineno</em> parameters are present, they will be used when
- * reporting syntax errors.
- *
- * def getBinding(param)
- * return binding
- * end
- * b = getBinding("hello")
- * b.eval("param") #=> "hello"
- */
-
-static VALUE
-bind_eval(int argc, VALUE *argv, VALUE bind)
-{
- struct BLOCK *data;
- VALUE args[4];
-
- rb_scan_args(argc, argv, "12", &args[0], &args[2], &args[3]);
- args[1] = bind;
- Data_Get_Struct(bind, struct BLOCK, data);
-
- return rb_f_eval(argc+1, args, data->self);
-}
-
-#define PROC_TSHIFT (FL_USHIFT+1)
-#define PROC_TMASK (FL_USER1|FL_USER2|FL_USER3)
-#define PROC_TMAX (PROC_TMASK >> PROC_TSHIFT)
-#define PROC_SAFE_SAVED FL_USER4
-
#define SAFE_LEVEL_MAX PROC_TMASK
-#define proc_safe_level_p(data) (RBASIC(data)->flags & PROC_SAFE_SAVED)
-#define proc_delete_safe_level(data) FL_UNSET(data, PROC_SAFE_SAVED)
-
static void
-proc_save_safe_level(VALUE data)
+proc_save_safe_level(data)
+ VALUE data;
{
int safe = ruby_safe_level;
if (safe > PROC_TMAX) safe = PROC_TMAX;
- FL_UNSET(data, PROC_TMASK);
FL_SET(data, (safe << PROC_TSHIFT) & PROC_TMASK);
- FL_SET(data, PROC_SAFE_SAVED);
}
static int
-proc_get_safe_level(VALUE data)
+proc_get_safe_level(data)
+ VALUE data;
{
return (RBASIC(data)->flags & PROC_TMASK) >> PROC_TSHIFT;
}
static void
-proc_set_safe_level(VALUE data)
+proc_set_safe_level(data)
+ VALUE data;
{
- if (!proc_safe_level_p(data)) return;
ruby_safe_level = proc_get_safe_level(data);
}
static VALUE
-proc_alloc(VALUE klass, struct BLOCK *blk, int lambda)
+proc_alloc(klass, proc)
+ VALUE klass;
+ int proc;
{
volatile VALUE block;
- struct BLOCK *data;
+ struct BLOCK *data, *p;
+ struct RVarmap *vars;
- block = Data_Make_Struct(klass, struct BLOCK, blk_mark, blk_free, data);
- *data = *blk;
+ if (!rb_block_given_p() && !rb_f_block_given_p()) {
+ rb_raise(rb_eArgError, "tried to create Proc object without a block");
+ }
+ if (proc && !rb_block_given_p()) {
+ rb_warn("tried to create Proc object without a block");
+ }
- if (!lambda && data->block_obj) {
- return data->block_obj;
+ if (!proc && ruby_block->block_obj && CLASS_OF(ruby_block->block_obj) == klass) {
+ return ruby_block->block_obj;
}
+ block = Data_Make_Struct(klass, struct BLOCK, blk_mark, blk_free, data);
+ *data = *ruby_block;
+
data->orig_thread = rb_thread_current();
data->wrapper = ruby_wrapper;
+ data->iter = data->prev?Qtrue:Qfalse;
+ data->block_obj = block;
frame_dup(&data->frame);
- blk_nail_down(data);
- scope_dup(data->scope);
- proc_save_safe_level(block);
- if (lambda) {
- data->flags |= BLOCK_LAMBDA;
+ if (data->iter) {
+ blk_copy_prev(data);
}
else {
- data->block_obj = block;
+ data->prev = 0;
}
- return block;
-}
-static VALUE
-proc_new(VALUE klass, int lambda)
-{
- volatile VALUE block;
- struct FRAME *frame = ruby_frame;
-
- if (!rb_block_given_p()) {
- if (lambda || !ruby_frame->prev || !ruby_frame->prev->block) {
- rb_raise(rb_eArgError, "tried to create Proc object without a block");
+ for (p = data; p; p = p->prev) {
+ for (vars = p->dyna_vars; vars; vars = vars->next) {
+ if (FL_TEST(vars, DVAR_DONT_RECYCLE)) break;
+ FL_SET(vars, DVAR_DONT_RECYCLE);
}
- frame = ruby_frame->prev;
}
- else if (!lambda && frame->block->block_obj) {
- VALUE obj = frame->block->block_obj;
- if (CLASS_OF(obj) != klass) {
- obj = proc_clone(obj);
- RBASIC(obj)->klass = klass;
- }
- return obj;
+ scope_dup(data->scope);
+ proc_save_safe_level(block);
+ if (proc) {
+ data->flags |= BLOCK_LAMBDA;
}
- block = proc_alloc(klass, frame->block, lambda);
- if (!lambda) {
- frame->block->block_obj = block;
+ else {
+ ruby_block->block_obj = block;
}
+
return block;
}
/*
* call-seq:
- * Proc.new {|...| block } => a_proc
- * Proc.new => a_proc
+ * Proc.new {|...| block } => a_proc
+ * Proc.new => a_proc
*
* Creates a new <code>Proc</code> object, bound to the current
* context. <code>Proc::new</code> may be called without a block only
@@ -8403,36 +8533,33 @@ proc_new(VALUE klass, int lambda)
*/
static VALUE
-proc_s_new(int argc, VALUE *argv, VALUE klass)
+proc_s_new(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
- VALUE block = proc_new(klass, Qfalse);
+ VALUE block = proc_alloc(klass, Qfalse);
rb_obj_call_init(block, argc, argv);
return block;
}
-/*
- * call-seq:
- * proc {|...| block } => a_proc
- *
- * Equivalent to <code>Proc.new</code>.
- */
-
VALUE
-rb_block_proc(void)
+rb_block_proc()
{
- return proc_new(rb_cProc, Qfalse);
+ return proc_alloc(rb_cProc, Qfalse);
}
VALUE
-rb_f_lambda(void)
+rb_f_lambda()
{
rb_warn("rb_f_lambda() is deprecated; use rb_block_proc() instead");
- return proc_new(rb_cProc, Qtrue);
+ return proc_alloc(rb_cProc, Qtrue);
}
/*
* call-seq:
+ * proc { |...| block } => a_proc
* lambda { |...| block } => a_proc
*
* Equivalent to <code>Proc.new</code>, except the resulting Proc objects
@@ -8440,17 +8567,15 @@ rb_f_lambda(void)
*/
static VALUE
-proc_lambda(void)
+proc_lambda()
{
- return proc_new(rb_cProc, Qtrue);
+ return proc_alloc(rb_cProc, Qtrue);
}
static int
-block_orphan(struct BLOCK *data)
+block_orphan(data)
+ struct BLOCK *data;
{
- if (data->flags & (BLOCK_LAMBDA|BLOCK_FROM_METHOD)) {
- return 1;
- }
if (data->scope->flags & SCOPE_NOSTACK) {
return 1;
}
@@ -8461,59 +8586,72 @@ block_orphan(struct BLOCK *data)
}
static VALUE
-proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass, int flags)
+proc_invoke(proc, args, self, klass)
+ VALUE proc, args; /* OK */
+ VALUE self, klass;
{
+ struct BLOCK * volatile old_block;
struct BLOCK _block;
struct BLOCK *data;
volatile VALUE result = Qundef;
int state;
volatile int safe = ruby_safe_level;
volatile VALUE old_wrapper = ruby_wrapper;
- volatile int lambda;
- VALUE bvar = 0;
+ volatile int pcall, avalue = Qtrue;
+ volatile VALUE tmp = args;
- Data_Get_Struct(proc, struct BLOCK, data);
- flags |= YIELD_PROC_INVOKE;
- lambda = data->flags & BLOCK_LAMBDA;
- if (rb_block_given_p() && ruby_frame->callee) {
- if (klass != ruby_frame->this_class)
+ if (rb_block_given_p() && ruby_frame->last_func) {
+ if (klass != ruby_frame->last_class)
klass = rb_obj_class(proc);
+ rb_warning("block for %s#%s is useless",
+ rb_class2name(klass),
+ rb_id2name(ruby_frame->last_func));
+ }
+
+ Data_Get_Struct(proc, struct BLOCK, data);
+ pcall = (data->flags & BLOCK_LAMBDA) ? YIELD_LAMBDA_CALL : 0;
+ if (!pcall && RARRAY(args)->len == 1) {
+ avalue = Qfalse;
+ args = RARRAY(args)->ptr[0];
}
PUSH_VARS();
ruby_wrapper = data->wrapper;
ruby_dyna_vars = data->dyna_vars;
/* PUSH BLOCK from data */
+ old_block = ruby_block;
_block = *data;
- _block.block_obj = bvar;
if (self != Qundef) _block.frame.self = self;
- if (klass) _block.frame.this_class = klass;
- _block.frame.argc = (flags&YIELD_CALL) ? RARRAY_LEN(args) : 1;
+ if (klass) _block.frame.last_class = klass;
+ _block.frame.argc = RARRAY(tmp)->len;
_block.frame.flags = ruby_frame->flags;
- if (_block.frame.argc && (ruby_frame->flags & FRAME_DMETH)) {
+ if (_block.frame.argc && DMETHOD_P()) {
NEWOBJ(scope, struct SCOPE);
- OBJSETUP(scope, args, T_SCOPE);
+ OBJSETUP(scope, tmp, T_SCOPE);
scope->local_tbl = _block.scope->local_tbl;
scope->local_vars = _block.scope->local_vars;
+ scope->flags |= SCOPE_CLONE;
_block.scope = scope;
}
- PUSH_FRAME(Qfalse);
- ruby_frame->block = &_block;
- PUSH_TAG(lambda ? PROT_LAMBDA : PROT_NONE);
+ /* modify current frame */
+ ruby_block = &_block;
+ PUSH_ITER(ITER_CUR);
+ ruby_frame->iter = ITER_CUR;
+ PUSH_TAG(pcall ? PROT_LAMBDA : PROT_NONE);
state = EXEC_TAG();
if (state == 0) {
proc_set_safe_level(proc);
- result = rb_yield_0(args, self, (self!=Qundef)?CLASS_OF(self):0, flags);
+ result = rb_yield_0(args, self, (self!=Qundef)?CLASS_OF(self):0, pcall, avalue);
}
else if (TAG_DST()) {
result = prot_tag->retval;
}
POP_TAG();
- POP_FRAME();
+ POP_ITER();
+ ruby_block = old_block;
ruby_wrapper = old_wrapper;
POP_VARS();
- if (proc_safe_level_p(proc))
- ruby_safe_level = safe;
+ ruby_safe_level = safe;
switch (state) {
case 0:
@@ -8522,13 +8660,14 @@ proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass, int flags)
proc_jump_error(TAG_RETRY, Qnil); /* xxx */
JUMP_TAG(state);
break;
+ case TAG_NEXT:
case TAG_BREAK:
- if (lambda && result != Qundef) break;
- JUMP_TAG(state);
+ if (!pcall && result != Qundef) {
+ proc_jump_error(state, result);
+ }
case TAG_RETURN:
if (result != Qundef) {
- if (flags & YIELD_CALL)
- break;
+ if (pcall) break;
return_jump(result);
}
default:
@@ -8548,9 +8687,9 @@ proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass, int flags)
* <i>params</i> using something close to method calling semantics.
* Generates a warning if multiple values are passed to a proc that
* expects just one (previously this silently converted the parameters
- * to an array).
+ * to an array).
*
- * For procs created using <code>Kernel.proc</code>, generates an
+ * For procs created using <code>Kernel.proc</code>, generates an
* error if the wrong number of parameters
* are passed to a proc with multiple parameters. For procs created using
* <code>Proc.new</code>, extra parameters are silently discarded.
@@ -8571,93 +8710,15 @@ proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass, int flags)
* from prog.rb:5
*/
-VALUE
-rb_proc_call(VALUE proc, VALUE args /* OK */)
-{
- return proc_invoke(proc, args, Qundef, 0, INVOKE_CALL);
-}
-
-/*
- * call-seq:
- * prc.yield(params,...) => obj
- *
- * Invokes the block, setting the block's parameters to the values in
- * <i>params</i> in the same manner the yield statement does.
- *
- * a_proc = Proc.new {|a, *b| b.collect {|i| i*a }}
- * a_proc.yield(9, 1, 2, 3) #=> [9, 18, 27]
- * a_proc.yield([9, 1, 2, 3]) #=> [9, 18, 27]
- * a_proc = Proc.new {|a,b| a}
- * a_proc.yield(1,2,3) # => [1]
- */
-
-VALUE
-rb_proc_yield(int argc, VALUE *argv, VALUE proc)
-{
- switch (argc) {
- case 1:
- if (!NIL_P(argv[0])) {
- return proc_invoke(proc, argv[0], Qundef, 0, 0);
- }
- /* fall through */
- case 0:
- return proc_invoke(proc, Qundef, Qundef, 0, 0);
- default:
- return proc_invoke(proc, rb_ary_new4(argc, argv), Qundef, 0, INVOKE_VALUES);
- }
-}
-
-/* :nodoc: */
static VALUE
-nil_yield(int argc, VALUE *argv)
+proc_call(proc, args)
+ VALUE proc, args; /* OK */
{
- localjump_error("no block given", Qnil, 0, backtrace(0));
- return Qnil; /* not reached */
+ return proc_invoke(proc, args, Qundef, 0);
}
-int
-rb_proc_arity(VALUE proc)
-{
- struct BLOCK *data;
- NODE *var, *list;
- int n;
-
- Data_Get_Struct(proc, struct BLOCK, data);
- var = data->var;
- if (var == 0) {
- if (!data->body) return 0;
- if (nd_type(data->body) == NODE_IFUNC &&
- data->body->nd_cfnc == bmcall) {
- return method_arity(data->body->nd_tval);
- }
- return 0;
- }
- if (var == (NODE*)1) return 0;
- if (var == (NODE*)2) return 0;
- if (nd_type(var) == NODE_BLOCK_ARG) {
- var = var->nd_args;
- if (var == (NODE*)1) return 0;
- if (var == (NODE*)2) return 0;
- }
- switch (nd_type(var)) {
- default:
- return 1;
- case NODE_MASGN:
- list = var->nd_head;
- n = 0;
- while (list) {
- n++;
- list = list->nd_next;
- }
- if (var->nd_args) {
- if (var->nd_args != (NODE *)-1 && nd_type(var->nd_args) == NODE_POSTARG) {
- return -n-1-var->nd_args->nd_head->nd_alen;
- }
- return -n-1;
- }
- return n;
- }
-}
+static VALUE bmcall _((VALUE, VALUE));
+static VALUE method_arity _((VALUE));
/*
* call-seq:
@@ -8680,10 +8741,36 @@ rb_proc_arity(VALUE proc)
*/
static VALUE
-proc_arity(VALUE proc)
+proc_arity(proc)
+ VALUE proc;
{
- int arity = rb_proc_arity(proc);
- return INT2FIX(arity);
+ struct BLOCK *data;
+ NODE *list;
+ int n;
+
+ Data_Get_Struct(proc, struct BLOCK, data);
+ if (data->var == 0) {
+ if (data->body && nd_type(data->body) == NODE_IFUNC &&
+ data->body->nd_cfnc == bmcall) {
+ return method_arity(data->body->nd_tval);
+ }
+ return INT2FIX(-1);
+ }
+ if (data->var == (NODE*)1) return INT2FIX(0);
+ if (data->var == (NODE*)2) return INT2FIX(0);
+ switch (nd_type(data->var)) {
+ default:
+ return INT2FIX(1);
+ case NODE_MASGN:
+ list = data->var->nd_head;
+ n = 0;
+ while (list) {
+ n++;
+ list = list->nd_next;
+ }
+ if (data->var->nd_args) return INT2FIX(-n-1);
+ return INT2FIX(n);
+ }
}
/*
@@ -8695,7 +8782,8 @@ proc_arity(VALUE proc)
*/
static VALUE
-proc_eq(VALUE self, VALUE other)
+proc_eq(self, other)
+ VALUE self, other;
{
struct BLOCK *data, *data2;
@@ -8716,28 +8804,6 @@ proc_eq(VALUE self, VALUE other)
/*
* call-seq:
- * prc.hash => integer
- *
- * Return hash value corresponding to proc body.
- */
-
-static VALUE
-proc_hash(VALUE self)
-{
- struct BLOCK *data;
- long hash;
-
- Data_Get_Struct(self, struct BLOCK, data);
- hash = (long)data->body;
- hash ^= (long)data->var;
- hash ^= data->frame.uniq << 16;
- hash ^= data->flags;
-
- return INT2FIX(hash);
-}
-
-/*
- * call-seq:
* prc.to_s => string
*
* Shows the unique identifier for this proc, along with
@@ -8745,21 +8811,30 @@ proc_hash(VALUE self)
*/
static VALUE
-proc_to_s(VALUE self)
+proc_to_s(self)
+ VALUE self;
{
struct BLOCK *data;
NODE *node;
char *cname = rb_obj_classname(self);
+ const int w = (sizeof(VALUE) * CHAR_BIT) / 4;
+ long len = strlen(cname)+6+w; /* 6:tags 16:addr */
VALUE str;
Data_Get_Struct(self, struct BLOCK, data);
if ((node = data->frame.node) || (node = data->body)) {
- str = rb_sprintf("#<%s:%p@%s:%d>", cname, data->body,
- node->nd_file, nd_line(node));
+ len += strlen(node->nd_file) + 2 + (SIZEOF_LONG*CHAR_BIT-NODE_LSHIFT)/3;
+ str = rb_str_new(0, len);
+ snprintf(RSTRING(str)->ptr, len+1,
+ "#<%s:0x%.*lx@%s:%d>", cname, w, (VALUE)data->body,
+ node->nd_file, nd_line(node));
}
else {
- str = rb_sprintf("#<%s:%p>", cname, data->body);
+ str = rb_str_new(0, len);
+ snprintf(RSTRING(str)->ptr, len+1,
+ "#<%s:0x%.*lx>", cname, w, (VALUE)data->body);
}
+ RSTRING(str)->len = strlen(RSTRING(str)->ptr);
if (OBJ_TAINTED(self)) OBJ_TAINT(str);
return str;
@@ -8775,7 +8850,8 @@ proc_to_s(VALUE self)
*/
static VALUE
-proc_to_self(VALUE self)
+proc_to_self(self)
+ VALUE self;
{
return self;
}
@@ -8798,7 +8874,8 @@ proc_to_self(VALUE self)
*/
static VALUE
-proc_binding(VALUE proc)
+proc_binding(proc)
+ VALUE proc;
{
struct BLOCK *orig, *data;
VALUE bind;
@@ -8807,24 +8884,38 @@ proc_binding(VALUE proc)
bind = Data_Make_Struct(rb_cBinding,struct BLOCK,blk_mark,blk_free,data);
MEMCPY(data, orig, struct BLOCK, 1);
frame_dup(&data->frame);
- blk_nail_down(data);
+
+ if (data->iter) {
+ blk_copy_prev(data);
+ }
+ else {
+ data->prev = 0;
+ }
return bind;
}
-struct block_arg {
+static VALUE
+block_pass(self, node)
VALUE self;
- NODE *iter;
-};
-
-static struct BLOCK *
-passing_block(VALUE proc, struct BLOCK *blockp)
+ NODE *node;
{
+ VALUE proc = rb_eval(self, node->nd_body); /* OK */
VALUE b;
+ struct BLOCK * volatile old_block;
+ struct BLOCK _block;
struct BLOCK *data;
+ volatile VALUE result = Qnil;
+ int state;
volatile int orphan;
+ volatile int safe = ruby_safe_level;
- if (NIL_P(proc)) return 0;
+ if (NIL_P(proc)) {
+ PUSH_ITER(ITER_NOT);
+ result = rb_eval(self, node->nd_iter);
+ POP_ITER();
+ return result;
+ }
if (!rb_obj_is_proc(proc)) {
b = rb_check_convert_type(proc, T_DATA, "Proc", "to_proc");
if (!rb_obj_is_proc(b)) {
@@ -8839,17 +8930,73 @@ passing_block(VALUE proc, struct BLOCK *blockp)
rb_raise(rb_eSecurityError, "Insecure: tainted block value");
}
+ if (ruby_block && ruby_block->block_obj == proc) {
+ PUSH_ITER(ITER_PAS);
+ result = rb_eval(self, node->nd_iter);
+ POP_ITER();
+ return result;
+ }
+
Data_Get_Struct(proc, struct BLOCK, data);
orphan = block_orphan(data);
- if (!orphan) return data;
- *blockp = *data;
- blockp->uniq = block_unique++;
- return blockp;
+ /* PUSH BLOCK from data */
+ old_block = ruby_block;
+ _block = *data;
+ _block.outer = ruby_block;
+ if (orphan) _block.uniq = block_unique++;
+ ruby_block = &_block;
+ PUSH_ITER(ITER_PRE);
+ if (ruby_frame->iter == ITER_NOT)
+ ruby_frame->iter = ITER_PRE;
+
+ PUSH_TAG(PROT_LOOP);
+ state = EXEC_TAG();
+ if (state == 0) {
+ retry:
+ proc_set_safe_level(proc);
+ if (safe > ruby_safe_level)
+ ruby_safe_level = safe;
+ result = rb_eval(self, node->nd_iter);
+ }
+ else if (state == TAG_BREAK && TAG_DST()) {
+ result = prot_tag->retval;
+ state = 0;
+ }
+ else if (state == TAG_RETRY) {
+ state = 0;
+ goto retry;
+ }
+ POP_TAG();
+ POP_ITER();
+ ruby_block = old_block;
+ ruby_safe_level = safe;
+
+ switch (state) {/* escape from orphan block */
+ case 0:
+ break;
+ case TAG_RETURN:
+ if (orphan) {
+ proc_jump_error(state, prot_tag->retval);
+ }
+ default:
+ JUMP_TAG(state);
+ }
+
+ return result;
}
+struct METHOD {
+ VALUE klass, rklass;
+ VALUE recv;
+ ID id, oid;
+ int safe_level;
+ NODE *body;
+};
+
static void
-bm_mark(struct METHOD *data)
+bm_mark(data)
+ struct METHOD *data;
{
rb_gc_mark(data->rklass);
rb_gc_mark(data->klass);
@@ -8858,18 +9005,20 @@ bm_mark(struct METHOD *data)
}
static VALUE
-mnew(VALUE klass, VALUE obj, ID id, VALUE mklass)
+mnew(klass, obj, id, mklass)
+ VALUE klass, obj, mklass;
+ ID id;
{
VALUE method;
NODE *body;
+ int noex;
struct METHOD *data;
VALUE rklass = klass;
ID oid = id;
- int noex = LOOKUP_NORMAL;
again:
if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) {
- raise_undef(rklass, oid);
+ print_undef(rklass, oid);
}
if (nd_type(body) == NODE_ZSUPER) {
@@ -8881,15 +9030,14 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE 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, -1, data);
+ method = Data_Make_Struct(mklass, struct METHOD, bm_mark, free, data);
data->klass = klass;
data->recv = obj;
data->id = id;
data->body = body;
data->rklass = rklass;
data->oid = oid;
- data->safe_level = NOEX_WITH_SAFE(0);
+ data->safe_level = NOEX_WITH_SAFE(noex);
OBJ_INFECT(method, klass);
return method;
@@ -8930,7 +9078,8 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mklass)
static VALUE
-method_eq(VALUE method, VALUE other)
+method_eq(method, other)
+ VALUE method, other;
{
struct METHOD *m1, *m2;
@@ -8950,28 +9099,6 @@ method_eq(VALUE method, VALUE other)
}
/*
- * call-seq:
- * meth.hash => integer
- *
- * Return a hash value corresponding to the method object.
- */
-
-static VALUE
-method_hash(VALUE method)
-{
- struct METHOD *m;
- long hash;
-
- Data_Get_Struct(method, struct METHOD, m);
- hash = (long)m->klass;
- hash ^= (long)m->rklass;
- hash ^= (long)m->recv;
- hash ^= (long)m->body;
-
- return INT2FIX(hash);
-}
-
-/*
* call-seq:
* meth.unbind => unbound_method
*
@@ -8981,7 +9108,8 @@ method_hash(VALUE method)
*/
static VALUE
-method_unbind(VALUE obj)
+method_unbind(obj)
+ VALUE obj;
{
VALUE method;
struct METHOD *orig, *data;
@@ -9007,9 +9135,7 @@ method_unbind(VALUE obj)
* <code>Method</code> object (or raising <code>NameError</code>). The
* <code>Method</code> object acts as a closure in <i>obj</i>'s object
* instance, so instance variables and the value of <code>self</code>
- * remain available. Looks for private methods if optional second
- * argument is true.
-
+ * remain available.
*
* class Demo
* def initialize(n)
@@ -9029,8 +9155,10 @@ method_unbind(VALUE obj)
* m.call #=> "Hello, @iv = Fred"
*/
-VALUE
-rb_obj_method(VALUE obj, VALUE vid)
+static VALUE
+rb_obj_method(obj, vid)
+ VALUE obj;
+ VALUE vid;
{
return mnew(CLASS_OF(obj), obj, rb_to_id(vid), rb_cMethod);
}
@@ -9039,8 +9167,8 @@ rb_obj_method(VALUE obj, VALUE vid)
* call-seq:
* mod.instance_method(symbol) => unbound_method
*
- * Returns an +UnboundMethod+ representing the given instance method
- * in _mod_.
+ * Returns an +UnboundMethod+ representing the given
+ * instance method in _mod_.
*
* class Interpreter
* def do_a() print "there, "; end
@@ -9068,7 +9196,9 @@ rb_obj_method(VALUE obj, VALUE vid)
*/
static VALUE
-rb_mod_method(VALUE mod, VALUE vid)
+rb_mod_method(mod, vid)
+ VALUE mod;
+ VALUE vid;
{
return mnew(mod, Qundef, rb_to_id(vid), rb_cUnboundMethod);
}
@@ -9078,7 +9208,8 @@ rb_mod_method(VALUE mod, VALUE vid)
*/
static VALUE
-method_clone(VALUE self)
+method_clone(self)
+ VALUE self;
{
VALUE clone;
struct METHOD *orig, *data;
@@ -9104,8 +9235,11 @@ method_clone(VALUE self)
* m.call(20) #=> 32
*/
-VALUE
-rb_method_call(int argc, VALUE *argv, VALUE method)
+static VALUE
+method_call(argc, argv, method)
+ int argc;
+ VALUE *argv;
+ VALUE method;
{
VALUE result = Qnil; /* OK */
struct METHOD *data;
@@ -9116,13 +9250,14 @@ rb_method_call(int argc, VALUE *argv, VALUE method)
rb_raise(rb_eTypeError, "can't call unbound method; bind first");
}
if (OBJ_TAINTED(method)) {
- safe = NOEX_WITH(data->safe_level, 4);
+ safe = NOEX_WITH(data->safe_level, 4)|NOEX_TAINTED;
}
else {
safe = data->safe_level;
}
- result = rb_call0(data->klass,data->recv,data->id,data->oid,
- argc,argv,ruby_frame->block,data->body,safe);
+ PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT);
+ result = rb_call0(data->klass,data->recv,data->id,data->oid,argc,argv,data->body,safe);
+ POP_ITER();
return result;
}
@@ -9218,7 +9353,8 @@ rb_method_call(int argc, VALUE *argv, VALUE method)
*/
static VALUE
-umethod_bind(VALUE method, VALUE recv)
+umethod_bind(method, recv)
+ VALUE method, recv;
{
struct METHOD *data, *bound;
VALUE rklass = CLASS_OF(recv);
@@ -9250,43 +9386,6 @@ umethod_bind(VALUE method, VALUE recv)
return method;
}
-int
-rb_node_arity(NODE *body)
-{
- int n;
-
- switch (nd_type(body)) {
- case NODE_CFUNC:
- if (body->nd_argc < 0) return -1;
- return body->nd_argc;
- case NODE_ZSUPER:
- return -1;
- case NODE_ATTRSET:
- return 1;
- case NODE_IVAR:
- return 0;
- case NODE_BMETHOD:
- return rb_proc_arity(body->nd_cval);
- case NODE_SCOPE:
- body = body->nd_next; /* skip NODE_SCOPE */
- if (nd_type(body) == NODE_BLOCK)
- body = body->nd_head;
- if (!body) return 0;
- n = body->nd_frml ? RARRAY_LEN(body->nd_frml) : 0;
- if (body->nd_opt)
- return -n-1;
- if (body->nd_rest) {
- if (nd_type(body->nd_rest) == NODE_POSTARG) {
- return -n-1-body->nd_rest->nd_head->nd_alen;
- }
- n = -n-1;
- }
- return n;
- default:
- rb_raise(rb_eArgError, "invalid node 0x%x", nd_type(body));
- }
-}
-
/*
* call-seq:
* meth.arity => fixnum
@@ -9321,32 +9420,42 @@ rb_node_arity(NODE *body)
*/
static VALUE
-method_arity_m(VALUE method)
-{
- int n = method_arity(method);
- return INT2FIX(n);
-}
-
-static int
-method_arity(VALUE method)
+method_arity(method)
+ VALUE method;
{
struct METHOD *data;
+ NODE *body;
+ int n;
Data_Get_Struct(method, struct METHOD, data);
- return rb_node_arity(data->body);
-}
-int
-rb_mod_method_arity(VALUE mod, ID id)
-{
- NODE *node = rb_method_node(mod, id);
- return rb_node_arity(node);
-}
-
-int
-rb_obj_method_arity(VALUE obj, ID id)
-{
- return rb_mod_method_arity(CLASS_OF(obj), id);
+ body = data->body;
+ switch (nd_type(body)) {
+ case NODE_CFUNC:
+ if (body->nd_argc < 0) return INT2FIX(-1);
+ return INT2FIX(body->nd_argc);
+ case NODE_ZSUPER:
+ return INT2FIX(-1);
+ case NODE_ATTRSET:
+ return INT2FIX(1);
+ case NODE_IVAR:
+ return INT2FIX(0);
+ case NODE_BMETHOD:
+ return proc_arity(body->nd_cval);
+ case NODE_DMETHOD:
+ return method_arity(body->nd_cval);
+ case NODE_SCOPE:
+ body = body->nd_next; /* skip NODE_SCOPE */
+ if (nd_type(body) == NODE_BLOCK)
+ body = body->nd_head;
+ if (!body) return INT2FIX(0);
+ n = body->nd_cnt;
+ if (body->nd_opt || body->nd_rest)
+ n = -n-1;
+ return INT2FIX(n);
+ default:
+ rb_raise(rb_eArgError, "invalid node 0x%x", nd_type(body));
+ }
}
/*
@@ -9360,12 +9469,13 @@ rb_obj_method_arity(VALUE obj, ID id)
*/
static VALUE
-method_inspect(VALUE method)
+method_inspect(method)
+ VALUE method;
{
struct METHOD *data;
VALUE str;
const char *s;
- const char *sharp = "#";
+ char *sharp = "#";
Data_Get_Struct(method, struct METHOD, data);
str = rb_str_buf_new2("#<");
@@ -9394,8 +9504,12 @@ method_inspect(VALUE 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(data->klass));
+ rb_str_buf_cat2(str, rb_class2name(klass));
rb_str_buf_cat2(str, ")");
}
}
@@ -9407,34 +9521,41 @@ method_inspect(VALUE method)
}
static VALUE
-mproc(VALUE method)
+mproc(method)
+ VALUE method;
{
VALUE proc;
+ /* emulate ruby's method call */
+ PUSH_ITER(ITER_CUR);
+ PUSH_FRAME();
proc = rb_block_proc();
- proc_delete_safe_level(proc);
+ POP_FRAME();
+ POP_ITER();
+
return proc;
}
static VALUE
-bmcall(VALUE args, VALUE method)
+bmcall(args, method)
+ VALUE args, method;
{
volatile VALUE a;
VALUE ret;
a = svalue_to_avalue(args);
- ret = rb_method_call(RARRAY_LEN(a), RARRAY_PTR(a), method);
+ ret = method_call(RARRAY(a)->len, RARRAY(a)->ptr, method);
a = Qnil; /* prevent tail call */
return ret;
}
VALUE
-rb_proc_new(
- VALUE (*func)(ANYARGS), /* VALUE yieldarg[, VALUE procarg] */
- VALUE val)
+rb_proc_new(func, val)
+ VALUE (*func)(ANYARGS); /* VALUE yieldarg[, VALUE procarg] */
+ VALUE val;
{
struct BLOCK *data;
- VALUE proc = rb_iterate((VALUE(*)(VALUE))mproc, 0, func, val);
+ VALUE proc = rb_iterate((VALUE(*)_((VALUE)))mproc, 0, func, val);
Data_Get_Struct(proc, struct BLOCK, data);
data->body->nd_state = YIELD_FUNC_AVALUE;
@@ -9449,28 +9570,26 @@ rb_proc_new(
*/
static VALUE
-method_proc(VALUE method)
+method_proc(method)
+ VALUE method;
{
VALUE proc;
struct METHOD *mdata;
struct BLOCK *bdata;
+ proc = rb_iterate((VALUE(*)_((VALUE)))mproc, 0, bmcall, method);
Data_Get_Struct(method, struct METHOD, mdata);
- if (nd_type(mdata->body) == NODE_BMETHOD) {
- return mdata->body->nd_cval;
- }
- proc = rb_iterate((VALUE(*)(VALUE))mproc, 0, bmcall, method);
Data_Get_Struct(proc, struct BLOCK, bdata);
bdata->body->nd_file = mdata->body->nd_file;
nd_set_line(bdata->body, nd_line(mdata->body));
bdata->body->nd_state = YIELD_FUNC_SVALUE;
- bdata->flags |= BLOCK_FROM_METHOD;
return proc;
}
static VALUE
-rb_obj_is_method(VALUE m)
+rb_obj_is_method(m)
+ VALUE m;
{
if (TYPE(m) == T_DATA && RDATA(m)->dmark == (RUBY_DATA_FUNC)bm_mark) {
return Qtrue;
@@ -9516,7 +9635,10 @@ rb_obj_is_method(VALUE m)
*/
static VALUE
-rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
+rb_mod_define_method(argc, argv, mod)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
{
ID id;
VALUE body;
@@ -9539,28 +9661,16 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
}
if (RDATA(body)->dmark == (RUBY_DATA_FUNC)bm_mark) {
- struct METHOD *method = (struct METHOD *)DATA_PTR(body);
- VALUE rklass = method->rklass;
- if (rklass != mod) {
- if (FL_TEST(rklass, FL_SINGLETON)) {
- rb_raise(rb_eTypeError, "can't bind singleton method to a different class");
- }
- if (!RTEST(rb_class_inherited_p(mod, rklass))) {
- rb_raise(rb_eTypeError, "bind argument must be a subclass of %s",
- rb_class2name(rklass));
- }
- }
- node = method->body;
+ node = NEW_DMETHOD(method_unbind(body));
}
else if (RDATA(body)->dmark == (RUBY_DATA_FUNC)blk_mark) {
struct BLOCK *block;
body = proc_clone(body);
- proc_delete_safe_level(body);
Data_Get_Struct(body, struct BLOCK, block);
- block->frame.callee = id;
- block->frame.this_func = id;
- block->frame.this_class = mod;
+ block->frame.last_func = id;
+ block->frame.orig_func = id;
+ block->frame.last_class = mod;
node = NEW_BMETHOD(body);
}
else {
@@ -9568,39 +9678,20 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
rb_raise(rb_eTypeError, "wrong argument type (expected Proc/Method)");
}
- if (VIS_TEST(VIS_PRIVATE)) {
- noex = NOEX_PRIVATE;
- }
- else if (VIS_TEST(VIS_PROTECTED)) {
- noex = NOEX_PROTECTED;
- }
- else {
- noex = NOEX_PUBLIC;
+ noex = NOEX_PUBLIC;
+ if (ruby_cbase == mod) {
+ if (SCOPE_TEST(SCOPE_PRIVATE)) {
+ noex = NOEX_PRIVATE;
+ }
+ else if (SCOPE_TEST(SCOPE_PROTECTED)) {
+ noex = NOEX_PROTECTED;
+ }
}
rb_add_method(mod, id, node, noex);
return body;
}
/*
- * call-seq:
- * obj.define_singleton_method(symbol, method) => new_method
- * obj.define_singleton_method(symbol) { block } => proc
- *
- * Defines a singleton method for the receiver. The _method_
- * parameter can be a +Proc+ or +Method+ object.
- * If a block is specified, it is used as the method body.
- * See <code>Kernel#define_method</code>.
- */
-
-static VALUE
-rb_obj_define_method(int argc, VALUE *argv, VALUE obj)
-{
- VALUE klass = rb_singleton_class(obj);
-
- return rb_mod_define_method(argc, argv, klass);
-}
-
-/*
* <code>Proc</code> objects are blocks of code that have been bound to
* a set of local variables. Once bound, the code may be called in
* different contexts and still access those variables.
@@ -9619,19 +9710,24 @@ rb_obj_define_method(int argc, VALUE *argv, VALUE obj)
*/
void
-Init_Proc(void)
+Init_Proc()
{
rb_eLocalJumpError = rb_define_class("LocalJumpError", rb_eStandardError);
rb_define_method(rb_eLocalJumpError, "exit_value", localjump_xvalue, 0);
rb_define_method(rb_eLocalJumpError, "reason", localjump_reason, 0);
rb_global_variable(&exception_error);
- exception_error = rb_exc_new2(rb_eFatal, "exception reentered");
+ exception_error = rb_exc_new3(rb_eFatal,
+ rb_obj_freeze(rb_str_new2("exception reentered")));
+ OBJ_TAINT(exception_error);
+ OBJ_FREEZE(exception_error);
- rb_eSysStackError = rb_define_class("SystemStackError", rb_eException);
+ rb_eSysStackError = rb_define_class("SystemStackError", rb_eStandardError);
rb_global_variable(&sysstack_error);
- sysstack_error = rb_exc_new2(rb_eSysStackError, "stack level too deep");
+ sysstack_error = rb_exc_new3(rb_eSysStackError,
+ rb_obj_freeze(rb_str_new2("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);
@@ -9639,32 +9735,25 @@ Init_Proc(void)
rb_define_method(rb_cProc, "clone", proc_clone, 0);
rb_define_method(rb_cProc, "dup", proc_dup, 0);
- rb_define_method(rb_cProc, "call", rb_proc_call, -2);
- rb_define_method(rb_cProc, "yield", rb_proc_yield, -1);
+ rb_define_method(rb_cProc, "call", proc_call, -2);
rb_define_method(rb_cProc, "arity", proc_arity, 0);
- rb_define_method(rb_cProc, "[]", rb_proc_call, -2);
+ rb_define_method(rb_cProc, "[]", proc_call, -2);
rb_define_method(rb_cProc, "==", proc_eq, 1);
- rb_define_method(rb_cProc, "eql?", proc_eq, 1);
- rb_define_method(rb_cProc, "hash", proc_hash, 0);
rb_define_method(rb_cProc, "to_s", proc_to_s, 0);
rb_define_method(rb_cProc, "to_proc", proc_to_self, 0);
rb_define_method(rb_cProc, "binding", proc_binding, 0);
- rb_define_global_function("proc", rb_block_proc, 0);
+ rb_define_global_function("proc", proc_lambda, 0);
rb_define_global_function("lambda", proc_lambda, 0);
- rb_define_method(rb_cNilClass, "yield", nil_yield, -1);
-
rb_cMethod = rb_define_class("Method", rb_cObject);
rb_undef_alloc_func(rb_cMethod);
rb_undef_method(CLASS_OF(rb_cMethod), "new");
rb_define_method(rb_cMethod, "==", method_eq, 1);
- rb_define_method(rb_cMethod, "eql?", method_eq, 1);
- rb_define_method(rb_cMethod, "hash", method_hash, 0);
rb_define_method(rb_cMethod, "clone", method_clone, 0);
- rb_define_method(rb_cMethod, "call", rb_method_call, -1);
- rb_define_method(rb_cMethod, "[]", rb_method_call, -1);
- rb_define_method(rb_cMethod, "arity", method_arity_m, 0);
+ rb_define_method(rb_cMethod, "call", method_call, -1);
+ rb_define_method(rb_cMethod, "[]", method_call, -1);
+ rb_define_method(rb_cMethod, "arity", method_arity, 0);
rb_define_method(rb_cMethod, "inspect", method_inspect, 0);
rb_define_method(rb_cMethod, "to_s", method_inspect, 0);
rb_define_method(rb_cMethod, "to_proc", method_proc, 0);
@@ -9675,10 +9764,8 @@ Init_Proc(void)
rb_undef_alloc_func(rb_cUnboundMethod);
rb_undef_method(CLASS_OF(rb_cUnboundMethod), "new");
rb_define_method(rb_cUnboundMethod, "==", method_eq, 1);
- rb_define_method(rb_cUnboundMethod, "eql?", method_eq, 1);
- rb_define_method(rb_cUnboundMethod, "hash", method_hash, 0);
rb_define_method(rb_cUnboundMethod, "clone", method_clone, 0);
- rb_define_method(rb_cUnboundMethod, "arity", method_arity_m, 0);
+ rb_define_method(rb_cUnboundMethod, "arity", method_arity, 0);
rb_define_method(rb_cUnboundMethod, "inspect", method_inspect, 0);
rb_define_method(rb_cUnboundMethod, "to_s", method_inspect, 0);
rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1);
@@ -9687,7 +9774,7 @@ Init_Proc(void)
/*
* Objects of class <code>Binding</code> encapsulate the execution
- * context at some particular place in the code and retain this context
+ * context at some particular place in the code and retain this context
* for future use. The variables, methods, value of <code>self</code>,
* and possibly an iterator block that can be accessed in this context
* are all retained. Binding objects can be created using
@@ -9720,15 +9807,14 @@ Init_Proc(void)
*
*/
-void
-Init_Binding(void)
+void
+Init_Binding()
{
rb_cBinding = rb_define_class("Binding", rb_cObject);
rb_undef_alloc_func(rb_cBinding);
rb_undef_method(CLASS_OF(rb_cBinding), "new");
rb_define_method(rb_cBinding, "clone", proc_clone, 0);
rb_define_method(rb_cBinding, "dup", proc_dup, 0);
- rb_define_method(rb_cBinding, "eval", bind_eval, -1);
rb_define_global_function("binding", rb_f_binding, 0);
}
@@ -9740,7 +9826,7 @@ typedef unsigned long DWORD;
#endif
static inline DWORD
-win32_get_exception_list(void)
+win32_get_exception_list()
{
DWORD p;
# if defined _MSC_VER
@@ -9767,7 +9853,8 @@ win32_get_exception_list(void)
}
static inline void
-win32_set_exception_list(DWORD p)
+win32_set_exception_list(p)
+ DWORD p;
{
# if defined _MSC_VER
# ifdef _M_IX86
@@ -9812,105 +9899,9 @@ extern VALUE rb_last_status;
# endif
#endif
-#if defined(NFDBITS) && defined(HAVE_RB_FD_INIT)
-void
-rb_fd_init(volatile rb_fdset_t *fds)
-{
- fds->maxfd = 0;
- fds->fdset = ALLOC(fd_set);
- FD_ZERO(fds->fdset);
-}
-
-void
-rb_fd_term(rb_fdset_t *fds)
-{
- if (fds->fdset) free(fds->fdset);
- fds->maxfd = 0;
- fds->fdset = 0;
-}
-
-void
-rb_fd_zero(rb_fdset_t *fds)
-{
- if (fds->fdset) {
- MEMZERO(fds->fdset, fd_mask, howmany(fds->maxfd, NFDBITS));
- FD_ZERO(fds->fdset);
- }
-}
-
-static void
-rb_fd_resize(int n, rb_fdset_t *fds)
-{
- int m = howmany(n + 1, NFDBITS) * sizeof(fd_mask);
- int o = howmany(fds->maxfd, NFDBITS) * sizeof(fd_mask);
-
- if (m < sizeof(fd_set)) m = sizeof(fd_set);
- if (o < sizeof(fd_set)) o = sizeof(fd_set);
-
- if (m > o) {
- fds->fdset = realloc(fds->fdset, m);
- memset((char *)fds->fdset + o, 0, m - o);
- }
- if (n >= fds->maxfd) fds->maxfd = n + 1;
-}
-
-void
-rb_fd_set(int n, rb_fdset_t *fds)
-{
- rb_fd_resize(n, fds);
- FD_SET(n, fds->fdset);
-}
-
-void
-rb_fd_clr(int n, rb_fdset_t *fds)
-{
- if (n >= fds->maxfd) return;
- FD_CLR(n, fds->fdset);
-}
-
-int
-rb_fd_isset(int n, const rb_fdset_t *fds)
-{
- if (n >= fds->maxfd) return 0;
- return FD_ISSET(n, fds->fdset) != 0; /* "!= 0" avoids FreeBSD PR 91421 */
-}
-
-void
-rb_fd_copy(rb_fdset_t *dst, const fd_set *src, int max)
-{
- int size = howmany(max, NFDBITS) * sizeof(fd_mask);
-
- if (size < sizeof(fd_set)) size = sizeof(fd_set);
- dst->maxfd = max;
- dst->fdset = realloc(dst->fdset, size);
- memcpy(dst->fdset, src, size);
-}
-
-int
-rb_fd_select(int n, rb_fdset_t *readfds, rb_fdset_t *writefds, rb_fdset_t *exceptfds, struct timeval *timeout)
-{
- rb_fd_resize(n - 1, readfds);
- rb_fd_resize(n - 1, writefds);
- rb_fd_resize(n - 1, exceptfds);
- return select(n, rb_fd_ptr(readfds), rb_fd_ptr(writefds), rb_fd_ptr(exceptfds), timeout);
-}
-
-#undef FD_ZERO
-#undef FD_SET
-#undef FD_CLR
-#undef FD_ISSET
-
-#define FD_ZERO(f) rb_fd_zero(f)
-#define FD_SET(i, f) rb_fd_set(i, f)
-#define FD_CLR(i, f) rb_fd_clr(i, f)
-#define FD_ISSET(i, f) rb_fd_isset(i, f)
-
-#endif
-
-#define THREAD_RAISED 0x200 /* temporary flag */
#define THREAD_TERMINATING 0x400 /* persistent flag */
-#define THREAD_NO_ENSURE 0x800 /* persistent flag */
-#define THREAD_FLAGS_MASK 0xc00 /* mask for persistent flags */
+#define THREAD_NO_ENSURE 0x800 /* persistent flag */
+#define THREAD_FLAGS_MASK 0xfc00 /* 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)
@@ -9929,12 +9920,12 @@ struct thread_status_t {
int safe;
- enum thread_status status;
+ enum rb_thread_status status;
int wait_for;
int fd;
- rb_fdset_t readfds;
- rb_fdset_t writefds;
- rb_fdset_t exceptfds;
+ fd_set readfds;
+ fd_set writefds;
+ fd_set exceptfds;
int select_value;
double delay;
rb_thread_t join;
@@ -9957,27 +9948,30 @@ struct thread_status_t {
(dst)->readfds = (src)->readfds, \
(dst)->writefds = (src)->writefds, \
(dst)->exceptfds = (src)->exceptfds, \
- rb_fd_init(&(src)->readfds), \
- rb_fd_init(&(src)->writefds), \
- rb_fd_init(&(src)->exceptfds), \
(dst)->select_value = (src)->select_value, \
(dst)->delay = (src)->delay, \
(dst)->join = (src)->join, \
0)
-static int
-thread_set_raised(void)
+int
+rb_thread_set_raised(th)
+ rb_thread_t th;
{
- if (curr_thread->flags & THREAD_RAISED) return 1;
- curr_thread->flags |= THREAD_RAISED;
+ if (th->flags & RAISED_EXCEPTION) {
+ return 1;
+ }
+ th->flags |= RAISED_EXCEPTION;
return 0;
}
-static int
-thread_reset_raised(void)
+int
+rb_thread_reset_raised(th)
+ rb_thread_t th;
{
- if (!(curr_thread->flags & THREAD_RAISED)) return 0;
- curr_thread->flags &= ~THREAD_RAISED;
+ if (!(th->flags & RAISED_EXCEPTION)) {
+ return 0;
+ }
+ th->flags &= ~RAISED_EXCEPTION;
return 1;
}
@@ -9987,17 +9981,21 @@ thread_no_ensure()
return ((curr_thread->flags & THREAD_NO_ENSURE) == THREAD_NO_ENSURE);
}
-static void rb_thread_ready(rb_thread_t);
+static void rb_thread_ready _((rb_thread_t));
+static VALUE run_trap_eval _((VALUE));
static VALUE
-run_trap_eval(VALUE arg)
+run_trap_eval(arg)
+ VALUE arg;
{
VALUE *p = (VALUE *)arg;
return rb_eval_cmd(p[0], p[1], (int)p[2]);
}
static VALUE
-rb_trap_eval(VALUE cmd, int sig, int safe)
+rb_trap_eval(cmd, sig, safe)
+ VALUE cmd;
+ int sig, safe;
{
int state;
VALUE val = Qnil; /* OK */
@@ -10009,7 +10007,9 @@ rb_trap_eval(VALUE cmd, int sig, int safe)
arg[2] = (VALUE)safe;
THREAD_COPY_STATUS(curr_thread, &save);
rb_thread_ready(curr_thread);
+ PUSH_ITER(ITER_NOT);
val = rb_protect(run_trap_eval, (VALUE)&arg, &state);
+ POP_ITER();
THREAD_COPY_STATUS(&save, curr_thread);
if (state) {
@@ -10027,7 +10027,8 @@ rb_trap_eval(VALUE cmd, int sig, int safe)
}
static const char *
-thread_status_name(enum thread_status status)
+thread_status_name(status)
+ enum rb_thread_status status;
{
switch (status) {
case THREAD_RUNNABLE:
@@ -10045,7 +10046,8 @@ thread_status_name(enum thread_status status)
/* $SAFE accessor */
void
-rb_set_safe_level(int level)
+rb_set_safe_level(level)
+ int level;
{
if (level > ruby_safe_level) {
if (level > SAFE_LEVEL_MAX) level = SAFE_LEVEL_MAX;
@@ -10055,13 +10057,14 @@ rb_set_safe_level(int level)
}
static VALUE
-safe_getter(void)
+safe_getter()
{
return INT2NUM(ruby_safe_level);
}
static void
-safe_setter(VALUE val)
+safe_setter(val)
+ VALUE val;
{
int level = NUM2INT(val);
@@ -10076,18 +10079,25 @@ safe_setter(VALUE val)
/* Return the current time as a floating-point number */
static double
-timeofday(void)
+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;
}
#define STACK(addr) (th->stk_pos<(VALUE*)(addr) && (VALUE*)(addr)<th->stk_pos+th->stk_len)
#define ADJ(addr) (void*)(STACK(addr)?(((VALUE*)(addr)-th->stk_pos)+th->stk_ptr):(VALUE*)(addr))
-
static void
-thread_mark(rb_thread_t th)
+thread_mark(th)
+ rb_thread_t th;
{
struct FRAME *frame;
struct BLOCK *block;
@@ -10096,6 +10106,7 @@ thread_mark(rb_thread_t th)
rb_gc_mark(th->thread);
if (th->join) rb_gc_mark(th->join->thread);
+ rb_gc_mark(th->klass);
rb_gc_mark(th->wrapper);
rb_gc_mark((VALUE)th->cref);
@@ -10120,7 +10131,7 @@ thread_mark(rb_thread_t th)
#endif
#ifdef __ia64
if (th->bstr_ptr) {
- rb_gc_mark_locations(th->bstr_ptr, th->bstr_ptr+th->bstr_len);
+ rb_gc_mark_locations(th->bstr_ptr, th->bstr_ptr+th->bstr_len);
}
#endif
}
@@ -10143,24 +10154,22 @@ thread_mark(rb_thread_t th)
while (block) {
block = ADJ(block);
rb_gc_mark_frame(&block->frame);
- block = block->frame.block;
+ block = block->prev;
}
}
-static struct {
- rb_thread_t thread;
- VALUE proc, arg;
-} new_thread;
-
static int
-mark_loading_thread(ID key, VALUE value, int lev)
+mark_loading_thread(key, value, lev)
+ ID key;
+ VALUE value;
+ int lev;
{
rb_gc_mark(((rb_thread_t)value)->thread);
return ST_CONTINUE;
}
void
-rb_gc_mark_threads(void)
+rb_gc_mark_threads()
{
rb_thread_t th;
@@ -10182,16 +10191,11 @@ rb_gc_mark_threads(void)
}
rb_gc_mark(th->thread);
} END_FOREACH_FROM(main_thread, th);
- if (new_thread.thread) {
- rb_gc_mark(new_thread.thread->thread);
- rb_gc_mark(new_thread.proc);
- rb_gc_mark(new_thread.arg);
- }
if (loading_tbl) st_foreach(loading_tbl, mark_loading_thread, 0);
}
void
-rb_gc_abort_threads(void)
+rb_gc_abort_threads()
{
rb_thread_t th;
@@ -10208,7 +10212,8 @@ rb_gc_abort_threads(void)
}
static void
-thread_free(rb_thread_t th)
+thread_free(th)
+ rb_thread_t th;
{
if (th->stk_ptr) free(th->stk_ptr);
th->stk_ptr = 0;
@@ -10221,14 +10226,12 @@ thread_free(rb_thread_t th)
if (th->prev) th->prev->next = th->next;
if (th->next) th->next->prev = th->prev;
}
- rb_fd_term(&th->readfds);
- rb_fd_term(&th->writefds);
- rb_fd_term(&th->exceptfds);
if (th != main_thread) free(th);
}
static rb_thread_t
-rb_thread_check(VALUE data)
+rb_thread_check(data)
+ VALUE data;
{
if (TYPE(data) != T_DATA || RDATA(data)->dmark != (RUBY_DATA_FUNC)thread_mark) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Thread)",
@@ -10237,13 +10240,12 @@ rb_thread_check(VALUE data)
return (rb_thread_t)RDATA(data)->data;
}
-static VALUE rb_thread_raise(int, VALUE*, rb_thread_t);
+static VALUE rb_thread_raise _((int, VALUE*, rb_thread_t));
static VALUE th_raise_exception;
static NODE *th_raise_node;
static VALUE th_cmd;
static int th_sig, th_safe;
-static const char *th_signm;
#define RESTORE_NORMAL 1
#define RESTORE_FATAL 2
@@ -10259,7 +10261,8 @@ extern VALUE *rb_gc_register_stack_start;
#endif
static void
-rb_thread_save_context(rb_thread_t th)
+rb_thread_save_context(th)
+ rb_thread_t th;
{
VALUE *pos;
int len;
@@ -10298,11 +10301,14 @@ rb_thread_save_context(rb_thread_t th)
th->frame = ruby_frame;
th->scope = ruby_scope;
ruby_scope->flags |= SCOPE_DONT_RECYCLE;
+ th->klass = ruby_class;
th->wrapper = ruby_wrapper;
th->cref = ruby_cref;
th->dyna_vars = ruby_dyna_vars;
+ th->block = ruby_block;
th->flags &= THREAD_FLAGS_MASK;
- th->flags |= (rb_trap_immediate<<8) | vis_mode;
+ th->flags |= (rb_trap_immediate<<8) | scope_vmode;
+ th->iter = ruby_iter;
th->tag = prot_tag;
th->tracing = tracing;
th->errinfo = ruby_errinfo;
@@ -10323,9 +10329,10 @@ rb_thread_save_context(rb_thread_t th)
}
static int
-rb_thread_switch(int n)
+rb_thread_switch(n)
+ int n;
{
- rb_trap_immediate = (curr_thread->flags&(1<<8))?1:0;
+ rb_trap_immediate = (curr_thread->flags&0x100)?1:0;
switch (n) {
case 0:
return 0;
@@ -10339,13 +10346,12 @@ rb_thread_switch(int n)
rb_trap_eval(th_cmd, th_sig, th_safe);
break;
case RESTORE_RAISE:
- ruby_frame->callee = 0;
- ruby_frame->this_func = 0;
+ ruby_frame->last_func = 0;
ruby_current_node = th_raise_node;
rb_raise_jump(th_raise_exception);
break;
case RESTORE_SIGNAL:
- rb_raise(rb_eSignal, "SIG%s", th_signm);
+ rb_thread_signal_raise(th_sig);
break;
case RESTORE_EXIT:
ruby_errinfo = th_raise_exception;
@@ -10365,14 +10371,13 @@ rb_thread_switch(int n)
#define THREAD_SAVE_CONTEXT(th) \
(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(static void rb_thread_restore_context _((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, void *vp)
{
- /* vp prevents tail call */
static rb_thread_t tmp;
static int ex;
static VALUE tval;
@@ -10384,10 +10389,13 @@ rb_thread_restore_context_0(rb_thread_t th, int exit, void *vp)
}
ruby_frame = th->frame;
ruby_scope = th->scope;
+ ruby_class = th->klass;
ruby_wrapper = th->wrapper;
ruby_cref = th->cref;
- vis_mode = th->flags&VIS_MASK;
ruby_dyna_vars = th->dyna_vars;
+ ruby_block = th->block;
+ scope_vmode = th->flags&SCOPE_MASK;
+ ruby_iter = th->iter;
prot_tag = th->tag;
tracing = th->tracing;
ruby_errinfo = th->errinfo;
@@ -10449,6 +10457,9 @@ register_stack_extend(rb_thread_t th, int exit, void *vp, VALUE *curr_bsp)
#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, VALUE *addr_in_prev_frame)
{
@@ -10461,12 +10472,12 @@ stack_extend(rb_thread_t th, int exit, VALUE *addr_in_prev_frame)
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 */
- if (addr_in_prev_frame > th->stk_pos) stack_extend(th, exit, &space[0]);
+ /* Stack grows downward */
+ if (addr_in_prev_frame > th->stk_pos) stack_extend(th, exit, &space[0]);
}
else {
- /* Stack grows upward */
- if (addr_in_prev_frame < th->stk_pos + th->stk_len) stack_extend(th, exit, &space[STACK_PAD_SIZE-1]);
+ /* Stack grows upward */
+ if (addr_in_prev_frame < th->stk_pos + th->stk_len) stack_extend(th, exit, &space[STACK_PAD_SIZE-1]);
}
#endif
#ifdef __ia64
@@ -10477,7 +10488,9 @@ stack_extend(rb_thread_t th, int exit, VALUE *addr_in_prev_frame)
}
static void
-rb_thread_restore_context(rb_thread_t th, int exit)
+rb_thread_restore_context(th, exit)
+ rb_thread_t th;
+ int exit;
{
VALUE v;
if (!th->stk_ptr) rb_bug("unsaved context");
@@ -10485,7 +10498,8 @@ rb_thread_restore_context(rb_thread_t th, int exit)
}
static void
-rb_thread_ready(rb_thread_t th)
+rb_thread_ready(th)
+ rb_thread_t th;
{
th->wait_for = 0;
if (th->status != THREAD_TO_KILL) {
@@ -10494,7 +10508,8 @@ rb_thread_ready(rb_thread_t th)
}
static void
-rb_thread_die(rb_thread_t th)
+rb_thread_die(th)
+ rb_thread_t th;
{
th->thgroup = 0;
th->status = THREAD_KILLED;
@@ -10503,7 +10518,8 @@ rb_thread_die(rb_thread_t th)
}
static void
-rb_thread_remove(rb_thread_t th)
+rb_thread_remove(th)
+ rb_thread_t th;
{
if (th->status == THREAD_KILLED) return;
@@ -10514,13 +10530,15 @@ rb_thread_remove(rb_thread_t th)
}
static int
-rb_thread_dead(rb_thread_t th)
+rb_thread_dead(th)
+ rb_thread_t th;
{
return th->status == THREAD_KILLED;
}
void
-rb_thread_fd_close(int fd)
+rb_thread_fd_close(fd)
+ int fd;
{
rb_thread_t th;
@@ -10537,9 +10555,11 @@ rb_thread_fd_close(int fd)
END_FOREACH(th);
}
-NORETURN(static void rb_thread_main_jump(VALUE, int));
+NORETURN(static void rb_thread_main_jump _((VALUE, int)));
static void
-rb_thread_main_jump(VALUE err, int tag)
+rb_thread_main_jump(err, tag)
+ VALUE err;
+ int tag;
{
curr_thread = main_thread;
th_raise_exception = err;
@@ -10547,14 +10567,14 @@ rb_thread_main_jump(VALUE err, int tag)
rb_thread_restore_context(main_thread, tag);
}
-NORETURN(static void rb_thread_deadlock(void));
+NORETURN(static void rb_thread_deadlock _((void)));
static void
-rb_thread_deadlock(void)
+rb_thread_deadlock()
{
char msg[21+SIZEOF_LONG*2];
VALUE e;
- sprintf(msg, "Thread(%p): deadlock", (void*)curr_thread->thread);
+ sprintf(msg, "Thread(0x%lx): deadlock", curr_thread->thread);
e = rb_exc_new2(rb_eFatal, msg);
if (curr_thread == main_thread) {
rb_exc_raise(e);
@@ -10563,12 +10583,13 @@ rb_thread_deadlock(void)
}
static void
-copy_fds(rb_fdset_t *dst, rb_fdset_t *src, int max)
+copy_fds(dst, src, max)
+ fd_set *dst, *src;
+ int max;
{
int n = 0;
int i;
- if (max >= rb_fd_max(src)) max = rb_fd_max(src) - 1;
for (i=0; i<=max; i++) {
if (FD_ISSET(i, src)) {
n = i;
@@ -10578,12 +10599,12 @@ copy_fds(rb_fdset_t *dst, rb_fdset_t *src, int max)
}
static int
-match_fds(rb_fdset_t *dst, rb_fdset_t *src, int max)
+match_fds(dst, src, max)
+ fd_set *dst, *src;
+ int max;
{
int i;
- if (max >= rb_fd_max(src)) max = rb_fd_max(src) - 1;
- if (max >= rb_fd_max(dst)) max = rb_fd_max(dst) - 1;
for (i=0; i<=max; i++) {
if (FD_ISSET(i, src) && FD_ISSET(i, dst)) {
return Qtrue;
@@ -10593,11 +10614,12 @@ match_fds(rb_fdset_t *dst, rb_fdset_t *src, int max)
}
static int
-intersect_fds(rb_fdset_t *src, rb_fdset_t *dst, int max)
+intersect_fds(src, dst, max)
+ fd_set *src, *dst;
+ int max;
{
int i, n = 0;
- if (max >= rb_fd_max(dst)) max = rb_fd_max(dst) - 1;
for (i=0; i<=max; i++) {
if (FD_ISSET(i, dst)) {
if (FD_ISSET(i, src)) {
@@ -10614,11 +10636,12 @@ intersect_fds(rb_fdset_t *src, rb_fdset_t *dst, int max)
}
static int
-find_bad_fds(rb_fdset_t *dst, rb_fdset_t *src, int max)
+find_bad_fds(dst, src, max)
+ fd_set *dst, *src;
+ int max;
{
int i, test = Qfalse;
- if (max >= rb_fd_max(src)) max = rb_fd_max(src) - 1;
for (i=0; i<=max; i++) {
if (FD_ISSET(i, src) && !FD_ISSET(i, dst)) {
FD_CLR(i, src);
@@ -10629,16 +10652,16 @@ find_bad_fds(rb_fdset_t *dst, rb_fdset_t *src, int max)
}
void
-rb_thread_schedule(void)
+rb_thread_schedule()
{
rb_thread_t next; /* OK */
rb_thread_t th;
rb_thread_t curr;
int found = 0;
- rb_fdset_t readfds;
- rb_fdset_t writefds;
- rb_fdset_t exceptfds;
+ fd_set readfds;
+ fd_set writefds;
+ fd_set exceptfds;
struct timeval delay_tv, *delay_ptr;
double delay, now; /* OK */
int n, max;
@@ -10650,7 +10673,8 @@ rb_thread_schedule(void)
rb_bug("cross-thread violation on rb_thread_schedule()");
}
#endif
- rb_thread_pending = rb_thread_critical = 0;
+ rb_thread_pending = 0;
+ rb_gc_finalize_deferred();
if (curr_thread == curr_thread->next
&& curr_thread->status == THREAD_RUNNABLE)
return;
@@ -10662,10 +10686,6 @@ rb_thread_schedule(void)
curr = curr->prev;
}
- rb_fd_init(&readfds);
- rb_fd_init(&writefds);
- rb_fd_init(&exceptfds);
-
again:
max = -1;
FD_ZERO(&readfds);
@@ -10739,20 +10759,11 @@ rb_thread_schedule(void)
delay_ptr = &delay_tv;
}
- n = rb_fd_select(max+1, &readfds, &writefds, &exceptfds, delay_ptr);
+ n = select(max+1, &readfds, &writefds, &exceptfds, delay_ptr);
if (n < 0) {
int e = errno;
- if (rb_trap_pending) {
- int status;
- rb_protect((VALUE (*)(VALUE))rb_trap_exec, Qnil, &status);
- if (status) {
- rb_fd_term(&readfds);
- rb_fd_term(&writefds);
- rb_fd_term(&exceptfds);
- rb_jump_tag(status);
- }
- }
+ if (rb_trap_pending) rb_trap_exec();
if (e == EINTR) goto again;
#ifdef ERESTART
if (e == ERESTART) goto again;
@@ -10823,10 +10834,6 @@ rb_thread_schedule(void)
goto again;
}
- rb_fd_term(&readfds);
- rb_fd_term(&writefds);
- rb_fd_term(&exceptfds);
-
FOREACH_THREAD_FROM(curr, th) {
if (th->status == THREAD_TO_KILL) {
next = th;
@@ -10848,13 +10855,13 @@ rb_thread_schedule(void)
TRAP_END;
}
FOREACH_THREAD_FROM(curr, th) {
- warn_printf("deadlock %p: %s:",
+ warn_printf("deadlock 0x%lx: %s:",
th->thread, thread_status_name(th->status));
if (th->wait_for & WAIT_FD) warn_printf("F(%d)", th->fd);
if (th->wait_for & WAIT_SELECT) warn_printf("S");
if (th->wait_for & WAIT_TIME) warn_printf("T(%f)", th->delay);
if (th->wait_for & WAIT_JOIN)
- warn_printf("J(%p)", th->join ? th->join->thread : 0);
+ warn_printf("J(0x%lx)", th->join ? th->join->thread : 0);
if (th->wait_for & WAIT_PID) warn_printf("P");
if (!th->wait_for) warn_printf("-");
warn_printf(" %s - %s:%d\n",
@@ -10894,9 +10901,11 @@ rb_thread_schedule(void)
}
void
-rb_thread_wait_fd(int fd)
+rb_thread_wait_fd(fd)
+ int fd;
{
if (rb_thread_critical) return;
+ if (ruby_in_compile) return;
if (curr_thread == curr_thread->next) return;
if (curr_thread->status == THREAD_TO_KILL) return;
@@ -10907,7 +10916,8 @@ rb_thread_wait_fd(int fd)
}
int
-rb_thread_fd_writable(int fd)
+rb_thread_fd_writable(fd)
+ int fd;
{
if (rb_thread_critical) return Qtrue;
if (curr_thread == curr_thread->next) return Qtrue;
@@ -10926,7 +10936,8 @@ rb_thread_fd_writable(int fd)
}
void
-rb_thread_wait_for(struct timeval time)
+rb_thread_wait_for(time)
+ struct timeval time;
{
double date;
@@ -10978,16 +10989,19 @@ rb_thread_wait_for(struct timeval time)
rb_thread_schedule();
}
-void rb_thread_sleep_forever(void);
+void rb_thread_sleep_forever _((void));
int
-rb_thread_alone(void)
+rb_thread_alone()
{
return curr_thread == curr_thread->next;
}
int
-rb_thread_select(int max, fd_set *read, fd_set *write, fd_set *except, struct timeval *timeout)
+rb_thread_select(max, read, write, except, timeout)
+ int max;
+ fd_set *read, *write, *except;
+ struct timeval *timeout;
{
#ifndef linux
double limit;
@@ -11053,11 +11067,11 @@ rb_thread_select(int max, fd_set *read, fd_set *write, fd_set *except, struct ti
}
curr_thread->status = THREAD_STOPPED;
- if (read) rb_fd_copy(&curr_thread->readfds, read, max);
+ if (read) curr_thread->readfds = *read;
else FD_ZERO(&curr_thread->readfds);
- if (write) rb_fd_copy(&curr_thread->writefds, write, max);
+ if (write) curr_thread->writefds = *write;
else FD_ZERO(&curr_thread->writefds);
- if (except) rb_fd_copy(&curr_thread->exceptfds, except, max);
+ if (except) curr_thread->exceptfds = *except;
else FD_ZERO(&curr_thread->exceptfds);
curr_thread->fd = max;
curr_thread->wait_for = WAIT_SELECT;
@@ -11067,25 +11081,29 @@ rb_thread_select(int max, fd_set *read, fd_set *write, fd_set *except, struct ti
curr_thread->wait_for |= WAIT_TIME;
}
rb_thread_schedule();
- if (read) *read = *rb_fd_ptr(&curr_thread->readfds);
- if (write) *write = *rb_fd_ptr(&curr_thread->writefds);
- if (except) *except = *rb_fd_ptr(&curr_thread->exceptfds);
+ if (read) *read = curr_thread->readfds;
+ if (write) *write = curr_thread->writefds;
+ if (except) *except = curr_thread->exceptfds;
return curr_thread->select_value;
}
+static int rb_thread_join _((rb_thread_t, double));
+
static int
-rb_thread_join(rb_thread_t th, double limit)
+rb_thread_join(th, limit)
+ rb_thread_t th;
+ double limit;
{
- enum thread_status last_status = THREAD_RUNNABLE;
+ enum rb_thread_status last_status = THREAD_RUNNABLE;
if (rb_thread_critical) rb_thread_deadlock();
if (!rb_thread_dead(th)) {
if (th == curr_thread)
- rb_raise(rb_eThreadError, "thread %p tried to join itself",
- (void*)th->thread);
+ rb_raise(rb_eThreadError, "thread 0x%lx tried to join itself",
+ th->thread);
if ((th->wait_for & WAIT_JOIN) && th->join == curr_thread)
- rb_raise(rb_eThreadError, "Thread#join: deadlock %p - mutual join(%p)",
- (void*)curr_thread->thread, (void*)th->thread);
+ rb_raise(rb_eThreadError, "Thread#join: deadlock 0x%lx - mutual join(0x%lx)",
+ curr_thread->thread, th->thread);
if (curr_thread->status == THREAD_TO_KILL)
last_status = THREAD_TO_KILL;
if (limit == 0) return Qfalse;
@@ -11099,12 +11117,12 @@ rb_thread_join(rb_thread_t th, double limit)
if (!rb_thread_dead(th)) return Qfalse;
}
- if (!NIL_P(th->errinfo) && (th->flags & THREAD_RAISED)) {
+ if (!NIL_P(th->errinfo) && (th->flags & RAISED_EXCEPTION)) {
VALUE oldbt = get_backtrace(th->errinfo);
VALUE errat = make_backtrace();
VALUE errinfo = rb_obj_dup(th->errinfo);
- if (TYPE(oldbt) == T_ARRAY && RARRAY_LEN(oldbt) > 0) {
+ if (TYPE(oldbt) == T_ARRAY && RARRAY(oldbt)->len > 0) {
rb_ary_unshift(errat, rb_ary_entry(oldbt, 0));
}
set_backtrace(errinfo, errat);
@@ -11156,7 +11174,10 @@ rb_thread_join(rb_thread_t th, double limit)
*/
static VALUE
-rb_thread_join_m(int argc, VALUE *argv, VALUE thread)
+rb_thread_join_m(argc, argv, thread)
+ int argc;
+ VALUE *argv;
+ VALUE thread;
{
VALUE limit;
double delay = DELAY_INFTY;
@@ -11180,7 +11201,7 @@ rb_thread_join_m(int argc, VALUE *argv, VALUE thread)
*/
VALUE
-rb_thread_current(void)
+rb_thread_current()
{
return curr_thread->thread;
}
@@ -11196,7 +11217,7 @@ rb_thread_current(void)
*/
VALUE
-rb_thread_main(void)
+rb_thread_main()
{
return main_thread->thread;
}
@@ -11223,7 +11244,7 @@ rb_thread_main(void)
*/
VALUE
-rb_thread_list(void)
+rb_thread_list()
{
rb_thread_t th;
VALUE ary = rb_ary_new();
@@ -11260,12 +11281,22 @@ rb_thread_list(void)
*/
VALUE
-rb_thread_wakeup(VALUE thread)
+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)
- rb_raise(rb_eThreadError, "killed thread");
+ return Qnil;
rb_thread_ready(th);
return thread;
@@ -11293,7 +11324,8 @@ rb_thread_wakeup(VALUE thread)
*/
VALUE
-rb_thread_run(VALUE thread)
+rb_thread_run(thread)
+ VALUE thread;
{
rb_thread_wakeup(thread);
if (!rb_thread_critical) rb_thread_schedule();
@@ -11303,7 +11335,7 @@ rb_thread_run(VALUE thread)
static void
-kill_thread(th, flags)
+rb_kill_thread(th, flags)
rb_thread_t th;
int flags;
{
@@ -11333,12 +11365,13 @@ kill_thread(th, flags)
*/
VALUE
-rb_thread_kill(VALUE thread)
+rb_thread_kill(thread)
+ VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
- kill_thread(th, 0);
- return thread;
+ rb_kill_thread(th, 0);
+ return thread;
}
@@ -11360,7 +11393,7 @@ rb_thread_kill_bang(thread)
VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
- kill_thread(th, THREAD_NO_ENSURE);
+ rb_kill_thread(th, THREAD_NO_ENSURE);
return thread;
}
@@ -11379,7 +11412,8 @@ rb_thread_kill_bang(thread)
*/
static VALUE
-rb_thread_s_kill(VALUE obj, VALUE th)
+rb_thread_s_kill(obj, th)
+ VALUE obj, th;
{
return rb_thread_kill(th);
}
@@ -11396,7 +11430,7 @@ rb_thread_s_kill(VALUE obj, VALUE th)
*/
static VALUE
-rb_thread_exit(void)
+rb_thread_exit()
{
return rb_thread_kill(curr_thread->thread);
}
@@ -11423,7 +11457,7 @@ rb_thread_exit(void)
*/
static VALUE
-rb_thread_pass(void)
+rb_thread_pass()
{
rb_thread_schedule();
return Qnil;
@@ -11450,9 +11484,9 @@ rb_thread_pass(void)
*/
VALUE
-rb_thread_stop(void)
+rb_thread_stop()
{
- enum thread_status last_status = THREAD_RUNNABLE;
+ enum rb_thread_status last_status = THREAD_RUNNABLE;
rb_thread_critical = 0;
if (curr_thread == curr_thread->next) {
@@ -11467,10 +11501,10 @@ rb_thread_stop(void)
return Qnil;
}
-struct timeval rb_time_timeval(VALUE time);
+struct timeval rb_time_timeval();
void
-rb_thread_polling(void)
+rb_thread_polling()
{
if (curr_thread != curr_thread->next) {
curr_thread->status = THREAD_STOPPED;
@@ -11481,7 +11515,8 @@ rb_thread_polling(void)
}
void
-rb_thread_sleep(int sec)
+rb_thread_sleep(sec)
+ int sec;
{
if (curr_thread == curr_thread->next) {
TRAP_BEG;
@@ -11493,7 +11528,7 @@ rb_thread_sleep(int sec)
}
void
-rb_thread_sleep_forever(void)
+rb_thread_sleep_forever()
{
int thr_critical = rb_thread_critical;
if (curr_thread == curr_thread->next ||
@@ -11516,15 +11551,18 @@ rb_thread_sleep_forever(void)
/*
* call-seq:
* thr.priority => integer
- *
- * Returns the priority of <i>thr</i>. Default is zero; higher-priority threads
- * will run before lower-priority threads.
- *
+ *
+ * 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.
+ *
* Thread.current.priority #=> 0
*/
static VALUE
-rb_thread_priority(VALUE thread)
+rb_thread_priority(thread)
+ VALUE thread;
{
return INT2NUM(rb_thread_check(thread)->priority);
}
@@ -11533,10 +11571,10 @@ rb_thread_priority(VALUE 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 }
@@ -11554,7 +11592,8 @@ rb_thread_priority(VALUE thread)
*/
static VALUE
-rb_thread_priority_set(VALUE thread, VALUE prio)
+rb_thread_priority_set(thread, prio)
+ VALUE thread, prio;
{
rb_thread_t th;
@@ -11580,7 +11619,8 @@ rb_thread_priority_set(VALUE thread, VALUE prio)
*/
static VALUE
-rb_thread_safe_level(VALUE thread)
+rb_thread_safe_level(thread)
+ VALUE thread;
{
rb_thread_t th;
@@ -11608,7 +11648,7 @@ static VALUE thgroup_default;
*/
static VALUE
-rb_thread_s_abort_exc(void)
+rb_thread_s_abort_exc()
{
return ruby_thread_abort?Qtrue:Qfalse;
}
@@ -11639,7 +11679,8 @@ rb_thread_s_abort_exc(void)
*/
static VALUE
-rb_thread_s_abort_exc_set(VALUE self, VALUE val)
+rb_thread_s_abort_exc_set(self, val)
+ VALUE self, val;
{
rb_secure(4);
ruby_thread_abort = RTEST(val);
@@ -11657,7 +11698,8 @@ rb_thread_s_abort_exc_set(VALUE self, VALUE val)
*/
static VALUE
-rb_thread_abort_exc(VALUE thread)
+rb_thread_abort_exc(thread)
+ VALUE thread;
{
return rb_thread_check(thread)->abort?Qtrue:Qfalse;
}
@@ -11673,7 +11715,8 @@ rb_thread_abort_exc(VALUE thread)
*/
static VALUE
-rb_thread_abort_exc_set(VALUE thread, VALUE val)
+rb_thread_abort_exc_set(thread, val)
+ VALUE thread, val;
{
rb_secure(4);
rb_thread_check(thread)->abort = RTEST(val);
@@ -11681,6 +11724,15 @@ rb_thread_abort_exc_set(VALUE thread, VALUE 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
@@ -11692,7 +11744,8 @@ rb_thread_abort_exc_set(VALUE thread, VALUE val)
*/
VALUE
-rb_thread_group(VALUE thread)
+rb_thread_group(thread)
+ VALUE thread;
{
VALUE group = rb_thread_check(thread)->thgroup;
if (!group) {
@@ -11708,7 +11761,7 @@ rb_thread_group(VALUE thread)
#endif
#define THREAD_ALLOC(th) do {\
- th = ALLOC(struct thread);\
+ th = ALLOC(struct rb_thread);\
\
th->next = 0;\
th->prev = 0;\
@@ -11724,18 +11777,20 @@ rb_thread_group(VALUE thread)
IA64_INIT(th->bstr_ptr = 0);\
IA64_INIT(th->bstr_len = 0);\
IA64_INIT(th->bstr_max = 0);\
- rb_fd_init(&th->readfds);\
- rb_fd_init(&th->writefds);\
- rb_fd_init(&th->exceptfds);\
+ FD_ZERO(&th->readfds);\
+ FD_ZERO(&th->writefds);\
+ FD_ZERO(&th->exceptfds);\
th->delay = 0.0;\
th->join = 0;\
\
th->frame = 0;\
th->scope = 0;\
+ th->klass = 0;\
th->wrapper = 0;\
th->cref = ruby_cref;\
th->dyna_vars = ruby_dyna_vars;\
th->block = 0;\
+ th->iter = 0;\
th->tag = 0;\
th->tracing = 0;\
th->errinfo = Qnil;\
@@ -11752,11 +11807,11 @@ rb_thread_group(VALUE thread)
} else {\
th->sandbox = curr_thread->sandbox;\
}\
- th->anchor = 0;\
} while (0)
static rb_thread_t
-rb_thread_alloc(VALUE klass)
+rb_thread_alloc(klass)
+ VALUE klass;
{
rb_thread_t th;
struct RVarmap *vars;
@@ -11771,11 +11826,12 @@ rb_thread_alloc(VALUE klass)
return th;
}
-static int thread_init = 0;
+static int thread_init;
#if defined(_THREAD_SAFE)
static void
-catch_timer(int sig)
+catch_timer(sig)
+ int sig;
{
#if !defined(POSIX_SIGNAL) && !defined(BSD_SIGNAL)
signal(sig, catch_timer);
@@ -11783,20 +11839,36 @@ catch_timer(int sig)
/* cause EINTR */
}
+static int time_thread_alive_p = 0;
static pthread_t time_thread;
static void*
-thread_timer(void *dummy)
+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);
@@ -11808,6 +11880,7 @@ thread_timer(void *dummy)
}
}
}
+#undef test_cancel
}
void
@@ -11819,9 +11892,30 @@ 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(int sig)
+catch_timer(sig)
+ int sig;
{
#if !defined(POSIX_SIGNAL) && !defined(BSD_SIGNAL)
signal(sig, catch_timer);
@@ -11855,51 +11949,31 @@ rb_thread_stop_timer()
tval.it_value = tval.it_interval;
setitimer(ITIMER_VIRTUAL, &tval, NULL);
}
-#else /* !(_THREAD_SAFE || HAVE_SETITIMER) */
-int rb_thread_tick = THREAD_TICK;
-#endif
-
-NORETURN(static void rb_thread_terminated(rb_thread_t, int, enum thread_status));
-static VALUE rb_thread_yield(VALUE, rb_thread_t);
-static void
-push_thread_anchor(struct ruby_env *ip)
+void
+rb_thread_cancel_timer()
{
- ip->tag = prot_tag;
- ip->frame = ruby_frame;
- ip->scope = ruby_scope;
- ip->cref = ruby_cref;
- ip->prev = curr_thread->anchor;
- curr_thread->anchor = ip;
}
-static void
-pop_thread_anchor(struct ruby_env *ip)
-{
- curr_thread->anchor = ip->prev;
-}
+#else /* !(_THREAD_SAFE || HAVE_SETITIMER) */
+int rb_thread_tick = THREAD_TICK;
-static void
-thread_insert(rb_thread_t th)
+void
+rb_thread_cancel_timer()
{
- if (!th->next) {
- /* merge in thread list */
- th->prev = curr_thread;
- curr_thread->next->prev = th;
- th->next = curr_thread->next;
- curr_thread->next = th;
- th->priority = curr_thread->priority;
- th->thgroup = curr_thread->thgroup;
- }
}
+#endif
static VALUE
-rb_thread_start_0(VALUE (*fn)(ANYARGS), VALUE arg, rb_thread_t th)
+rb_thread_start_0(fn, arg, th)
+ VALUE (*fn)();
+ void *arg;
+ rb_thread_t th;
{
volatile rb_thread_t th_save = th;
volatile VALUE thread = th->thread;
struct BLOCK *volatile saved_block = 0;
- enum thread_status status;
+ enum rb_thread_status status;
int state;
if (OBJ_FROZEN(curr_thread->thgroup)) {
@@ -11918,6 +11992,8 @@ rb_thread_start_0(VALUE (*fn)(ANYARGS), VALUE arg, rb_thread_t 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
@@ -11928,25 +12004,26 @@ rb_thread_start_0(VALUE (*fn)(ANYARGS), VALUE arg, rb_thread_t th)
return thread;
}
- if (fn == rb_thread_yield && curr_thread->anchor) {
- struct ruby_env *ip = curr_thread->anchor;
- new_thread.thread = th;
- new_thread.proc = rb_block_proc();
- new_thread.arg = (VALUE)arg;
- th->anchor = ip;
- thread_insert(th);
- curr_thread = th;
- ruby_longjmp((prot_tag = ip->tag)->buf, TAG_THREAD);
- }
+ if (ruby_block) { /* should nail down higher blocks */
+ struct BLOCK dummy;
- if (ruby_frame->block) { /* should nail down higher blocks */
- blk_nail_down(ruby_frame->block);
+ dummy.prev = ruby_block;
+ blk_copy_prev(&dummy);
+ saved_block = ruby_block = dummy.prev;
}
scope_dup(ruby_scope);
- thread_insert(th);
+ if (!th->next) {
+ /* merge in thread list */
+ th->prev = curr_thread;
+ curr_thread->next->prev = th;
+ th->next = curr_thread->next;
+ curr_thread->next = th;
+ th->priority = curr_thread->priority;
+ th->thgroup = curr_thread->thgroup;
+ }
- PUSH_TAG(PROT_NONE);
+ PUSH_TAG(PROT_THREAD);
if ((state = EXEC_TAG()) == 0) {
if (THREAD_SAVE_CONTEXT(th) == 0) {
curr_thread = th;
@@ -11968,15 +12045,8 @@ rb_thread_start_0(VALUE (*fn)(ANYARGS), VALUE arg, rb_thread_t th)
blk_free(saved_block);
}
- rb_thread_terminated(th, state, status);
- return 0; /* not reached */
-}
-
-static void
-rb_thread_terminated(rb_thread_t th, int state, enum thread_status status)
-{
if (state && status != THREAD_TO_KILL && !NIL_P(ruby_errinfo)) {
- th->flags |= THREAD_RAISED;
+ th->flags |= RAISED_EXCEPTION;
if (state == TAG_FATAL) {
/* fatal error within this thread, need to stop whole script */
main_thread->errinfo = ruby_errinfo;
@@ -11994,7 +12064,7 @@ rb_thread_terminated(rb_thread_t th, int state, enum thread_status status)
rb_thread_main_jump(ruby_errinfo, RESTORE_RAISE);
}
}
- else if (th->safe < 4 && (ruby_thread_abort||th->abort||RTEST(ruby_debug))) {
+ else if (th->safe < 4 && (ruby_thread_abort || th->abort || RTEST(ruby_debug))) {
/* exit on main_thread */
error_print();
rb_thread_main_jump(ruby_errinfo, RESTORE_EXIT);
@@ -12005,60 +12075,26 @@ rb_thread_terminated(rb_thread_t th, int state, enum thread_status status)
}
rb_thread_schedule();
ruby_stop(0); /* last thread termination */
-}
-
-static void
-rb_thread_start_1(void)
-{
- rb_thread_t th = new_thread.thread;
- volatile rb_thread_t th_save = th;
- VALUE proc = new_thread.proc;
- volatile VALUE arg = new_thread.arg;
- struct ruby_env *ip = th->anchor;
- enum thread_status status;
- int state;
-
- ruby_frame = ip->frame;
- ruby_scope = ip->scope;
- ruby_cref = ip->cref;
- ruby_dyna_vars = ((struct BLOCK *)DATA_PTR(proc))->dyna_vars;
- PUSH_FRAME(Qtrue);
- *ruby_frame = *ip->frame;
- ruby_frame->prev = ip->frame;
- PUSH_TAG(PROT_NONE);
- if ((state = EXEC_TAG()) == 0) {
- if (THREAD_SAVE_CONTEXT(th) == 0) {
- new_thread.thread = 0;
- th->result = rb_proc_yield(RARRAY_LEN(arg), RARRAY_PTR(arg), proc);
- }
- th = th_save;
- }
- else if (TAG_DST()) {
- th = th_save;
- th->result = prot_tag->retval;
- }
- POP_TAG();
- POP_FRAME();
- status = th->status;
-
- if (th == main_thread) ruby_stop(state);
- rb_thread_remove(th);
- rb_thread_terminated(th, state, status);
+ return 0; /* not reached */
}
VALUE
-rb_thread_create(VALUE (*fn)(ANYARGS), void *arg)
+rb_thread_create(fn, arg)
+ VALUE (*fn)();
+ void *arg;
{
- Init_stack((VALUE*)&arg);
- return rb_thread_start_0(fn, (VALUE)arg, rb_thread_alloc(rb_cThread));
+ Init_stack((void *)&arg);
+ return rb_thread_start_0(fn, arg, rb_thread_alloc(rb_cThread));
}
static VALUE
-rb_thread_yield(VALUE arg, rb_thread_t th)
+rb_thread_yield(arg, th)
+ VALUE arg;
+ rb_thread_t th;
{
const ID *tbl;
- scope_dup(ruby_frame->block->scope);
+ scope_dup(ruby_block->scope);
tbl = ruby_scope->local_tbl;
if (tbl) {
@@ -12071,9 +12107,9 @@ rb_thread_yield(VALUE arg, rb_thread_t th)
}
rb_dvar_push('_', Qnil);
rb_dvar_push('~', Qnil);
- ruby_frame->block->dyna_vars = ruby_dyna_vars;
+ ruby_block->dyna_vars = ruby_dyna_vars;
- return rb_yield_0(arg, 0, 0, 0);
+ return rb_yield_0(arg, 0, 0, YIELD_LAMBDA_CALL, Qtrue);
}
/*
@@ -12095,7 +12131,10 @@ rb_thread_yield(VALUE arg, rb_thread_t th)
*/
static VALUE
-rb_thread_s_new(int argc, VALUE *argv, VALUE klass)
+rb_thread_s_new(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
rb_thread_t th = rb_thread_alloc(klass);
volatile VALUE *pos;
@@ -12130,7 +12169,8 @@ rb_thread_s_new(int argc, VALUE *argv, VALUE klass)
*/
static VALUE
-rb_thread_initialize(VALUE thread, VALUE args)
+rb_thread_initialize(thread, args)
+ VALUE thread, args;
{
rb_thread_t th;
@@ -12161,7 +12201,8 @@ rb_thread_initialize(VALUE thread, VALUE args)
*/
static VALUE
-rb_thread_start(VALUE klass, VALUE args)
+rb_thread_start(klass, args)
+ VALUE klass, args;
{
if (!rb_block_given_p()) {
rb_raise(rb_eThreadError, "must be called with a block");
@@ -12182,7 +12223,8 @@ rb_thread_start(VALUE klass, VALUE args)
*/
static VALUE
-rb_thread_value(VALUE thread)
+rb_thread_value(thread)
+ VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
@@ -12216,12 +12258,13 @@ rb_thread_value(VALUE thread)
*/
static VALUE
-rb_thread_status(VALUE thread)
+rb_thread_status_name(thread)
+ VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
if (rb_thread_dead(th)) {
- if (!NIL_P(th->errinfo) && (th->flags & THREAD_RAISED))
+ if (!NIL_P(th->errinfo) && (th->flags & RAISED_EXCEPTION))
return Qnil;
return Qfalse;
}
@@ -12242,8 +12285,9 @@ rb_thread_status(VALUE thread)
* thr.alive? #=> false
*/
-static VALUE
-rb_thread_alive_p(VALUE thread)
+VALUE
+rb_thread_alive_p(thread)
+ VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
@@ -12265,7 +12309,8 @@ rb_thread_alive_p(VALUE thread)
*/
static VALUE
-rb_thread_stop_p(VALUE thread)
+rb_thread_stop_p(thread)
+ VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
@@ -12275,7 +12320,7 @@ rb_thread_stop_p(VALUE thread)
}
static void
-rb_thread_wait_other_threads(void)
+rb_thread_wait_other_threads()
{
rb_thread_t th;
int found;
@@ -12296,7 +12341,7 @@ rb_thread_wait_other_threads(void)
}
static void
-rb_thread_cleanup(void)
+rb_thread_cleanup()
{
rb_thread_t curr, th;
@@ -12330,7 +12375,7 @@ int rb_thread_critical;
*/
static VALUE
-rb_thread_critical_get(void)
+rb_thread_critical_get()
{
return rb_thread_critical?Qtrue:Qfalse;
}
@@ -12351,14 +12396,15 @@ rb_thread_critical_get(void)
*/
static VALUE
-rb_thread_critical_set(VALUE obj, VALUE val)
+rb_thread_critical_set(obj, val)
+ VALUE obj, val;
{
rb_thread_critical = RTEST(val);
return val;
}
void
-rb_thread_interrupt(void)
+rb_thread_interrupt()
{
rb_thread_critical = 0;
rb_thread_ready(main_thread);
@@ -12375,13 +12421,16 @@ rb_thread_interrupt(void)
}
void
-rb_thread_signal_raise(const char *sig)
+rb_thread_signal_raise(sig)
+ int sig;
{
- if (sig == 0) return; /* should not happen */
rb_thread_critical = 0;
if (curr_thread == main_thread) {
+ VALUE argv[1];
+
rb_thread_ready(curr_thread);
- rb_raise(rb_eSignal, "SIG%s", sig);
+ argv[0] = INT2FIX(sig);
+ rb_exc_raise(rb_class_new_instance(1, argv, rb_eSignal));
}
rb_thread_ready(main_thread);
if (!rb_thread_dead(curr_thread)) {
@@ -12389,13 +12438,15 @@ rb_thread_signal_raise(const char *sig)
return;
}
}
- th_signm = sig; /* should be literal */
+ th_sig = sig;
curr_thread = main_thread;
rb_thread_restore_context(curr_thread, RESTORE_SIGNAL);
}
void
-rb_thread_trap_eval(VALUE cmd, int sig, int safe)
+rb_thread_trap_eval(cmd, sig, safe)
+ VALUE cmd;
+ int sig, safe;
{
rb_thread_critical = 0;
if (curr_thread == main_thread) {
@@ -12415,7 +12466,7 @@ rb_thread_trap_eval(VALUE cmd, int sig, int safe)
}
void
-rb_thread_signal_exit(void)
+rb_thread_signal_exit()
{
VALUE args[2];
@@ -12437,7 +12488,10 @@ rb_thread_signal_exit(void)
}
static VALUE
-rb_thread_raise(int argc, VALUE *argv, rb_thread_t th)
+rb_thread_raise(argc, argv, th)
+ int argc;
+ VALUE *argv;
+ rb_thread_t th;
{
volatile rb_thread_t th_save = th;
VALUE exc;
@@ -12487,7 +12541,10 @@ rb_thread_raise(int argc, VALUE *argv, rb_thread_t th)
*/
static VALUE
-rb_thread_raise_m(int argc, VALUE *argv, VALUE thread)
+rb_thread_raise_m(argc, argv, thread)
+ int argc;
+ VALUE *argv;
+ VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
@@ -12499,7 +12556,9 @@ rb_thread_raise_m(int argc, VALUE *argv, VALUE thread)
}
VALUE
-rb_thread_local_aref(VALUE thread, ID id)
+rb_thread_local_aref(thread, id)
+ VALUE thread;
+ ID id;
{
rb_thread_t th;
VALUE val;
@@ -12538,13 +12597,17 @@ rb_thread_local_aref(VALUE thread, ID id)
*/
static VALUE
-rb_thread_aref(VALUE thread, VALUE id)
+rb_thread_aref(thread, id)
+ VALUE thread, id;
{
return rb_thread_local_aref(thread, rb_to_id(id));
}
VALUE
-rb_thread_local_aset(VALUE thread, ID id, VALUE val)
+rb_thread_local_aset(thread, id, val)
+ VALUE thread;
+ ID id;
+ VALUE val;
{
rb_thread_t th = rb_thread_check(thread);
@@ -12575,7 +12638,8 @@ rb_thread_local_aset(VALUE thread, ID id, VALUE val)
*/
static VALUE
-rb_thread_aset(VALUE thread, VALUE id, VALUE val)
+rb_thread_aset(thread, id, val)
+ VALUE thread, id, val;
{
return rb_thread_local_aset(thread, rb_to_id(id), val);
}
@@ -12595,7 +12659,8 @@ rb_thread_aset(VALUE thread, VALUE id, VALUE val)
*/
static VALUE
-rb_thread_key_p(VALUE thread, VALUE id)
+rb_thread_key_p(thread, id)
+ VALUE thread, id;
{
rb_thread_t th = rb_thread_check(thread);
@@ -12606,7 +12671,9 @@ rb_thread_key_p(VALUE thread, VALUE id)
}
static int
-thread_keys_i(ID key, VALUE value, VALUE ary)
+thread_keys_i(key, value, ary)
+ ID key;
+ VALUE value, ary;
{
rb_ary_push(ary, ID2SYM(key));
return ST_CONTINUE;
@@ -12628,7 +12695,8 @@ thread_keys_i(ID key, VALUE value, VALUE ary)
*/
static VALUE
-rb_thread_keys(VALUE thread)
+rb_thread_keys(thread)
+ VALUE thread;
{
rb_thread_t th = rb_thread_check(thread);
VALUE ary = rb_ary_new();
@@ -12647,21 +12715,25 @@ rb_thread_keys(VALUE thread)
*/
static VALUE
-rb_thread_inspect(VALUE thread)
+rb_thread_inspect(thread)
+ VALUE thread;
{
char *cname = rb_obj_classname(thread);
rb_thread_t th = rb_thread_check(thread);
const char *status = thread_status_name(th->status);
VALUE str;
+ size_t len = strlen(cname)+7+16+9+1;
- str = rb_sprintf("#<%s:%p %s>", cname, (void*)thread, status);
+ str = rb_str_new(0, len); /* 7:tags 16:addr 9:status 1:nul */
+ snprintf(RSTRING(str)->ptr, len, "#<%s:0x%lx %s>", cname, thread, status);
+ RSTRING(str)->len = strlen(RSTRING(str)->ptr);
OBJ_INFECT(str, thread);
return str;
}
void
-rb_thread_atfork(void)
+rb_thread_atfork()
{
rb_thread_t th;
@@ -12736,13 +12808,14 @@ VALUE rb_cCont;
* cause the <code>callcc</code> to return (as will falling through the
* end of the block). The value returned by the <code>callcc</code> is
* the value of the block, or the value passed to
- * <em>cont</em><code>.call</code>. See class <code>Continuation</code>
+ * <em>cont</em><code>.call</code>. See class <code>Continuation</code>
* for more details. Also see <code>Kernel::throw</code> for
* an alternative mechanism for unwinding a call stack.
*/
static VALUE
-rb_callcc(VALUE self)
+rb_callcc(self)
+ VALUE self;
{
volatile VALUE cont;
rb_thread_t th;
@@ -12775,7 +12848,7 @@ rb_callcc(VALUE self)
/*
* call-seq:
- * cont.call(args, ...)
+ * cont.call(args, ...)
* cont[args, ...]
*
* Invokes the continuation. The program continues from the end of the
@@ -12790,7 +12863,10 @@ rb_callcc(VALUE self)
*/
static VALUE
-rb_cont_call(int argc, VALUE *argv, VALUE cont)
+rb_cont_call(argc, argv, cont)
+ int argc;
+ VALUE *argv;
+ VALUE cont;
{
rb_thread_t th = rb_thread_check(cont);
@@ -12834,8 +12910,10 @@ struct thgroup {
* were created.
*/
+static VALUE thgroup_s_alloc _((VALUE));
static VALUE
-thgroup_s_alloc(VALUE klass)
+thgroup_s_alloc(klass)
+ VALUE klass;
{
VALUE group;
struct thgroup *data;
@@ -12859,7 +12937,8 @@ thgroup_s_alloc(VALUE klass)
*/
static VALUE
-thgroup_list(VALUE group)
+thgroup_list(group)
+ VALUE group;
{
struct thgroup *data;
rb_thread_t th;
@@ -12898,7 +12977,8 @@ thgroup_list(VALUE group)
*/
static VALUE
-thgroup_enclose(VALUE group)
+thgroup_enclose(group)
+ VALUE group;
{
struct thgroup *data;
@@ -12918,7 +12998,8 @@ thgroup_enclose(VALUE group)
*/
static VALUE
-thgroup_enclosed_p(VALUE group)
+thgroup_enclosed_p(group)
+ VALUE group;
{
struct thgroup *data;
@@ -12955,7 +13036,8 @@ thgroup_enclosed_p(VALUE group)
*/
static VALUE
-thgroup_add(VALUE group, VALUE thread)
+thgroup_add(group, thread)
+ VALUE group, thread;
{
rb_thread_t th;
struct thgroup *data;
@@ -12990,21 +13072,18 @@ thgroup_add(VALUE group, VALUE thread)
return group;
}
-/* variables for recursive traversals */
-static ID recursive_key;
-
/*
* +Thread+ encapsulates the behavior of a thread of
* execution, including the main thread of the Ruby script.
*
* In the descriptions of the methods in this class, the parameter _sym_
- * refers to a symbol, which is either a quoted string or a
+ * refers to a symbol, which is either a quoted string or a
* +Symbol+ (such as <code>:name</code>).
*/
void
-Init_Thread(void)
+Init_Thread()
{
VALUE cThGroup;
@@ -13040,7 +13119,7 @@ Init_Thread(void)
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, 0);
+ rb_define_method(rb_cThread, "status", rb_thread_status_name, 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);
@@ -13082,7 +13161,6 @@ Init_Thread(void)
/* allocate main thread */
main_thread = rb_thread_alloc(rb_cThread);
curr_thread = main_thread->prev = main_thread->next = main_thread;
- recursive_key = rb_intern("__recursive_key__");
}
/*
@@ -13117,7 +13195,8 @@ Init_Thread(void)
*/
static VALUE
-rb_f_catch(VALUE dmy, VALUE tag)
+rb_f_catch(dmy, tag)
+ VALUE dmy, tag;
{
int state;
VALUE val = Qnil; /* OK */
@@ -13125,7 +13204,7 @@ rb_f_catch(VALUE dmy, VALUE tag)
tag = ID2SYM(rb_to_id(tag));
PUSH_TAG(tag);
if ((state = EXEC_TAG()) == 0) {
- val = rb_yield_0(tag, 0, 0, 0);
+ val = rb_yield_0(tag, 0, 0, 0, Qfalse);
}
else if (state == TAG_THROW && tag == prot_tag->dst) {
val = prot_tag->retval;
@@ -13137,12 +13216,20 @@ rb_f_catch(VALUE dmy, VALUE tag)
return val;
}
-VALUE
-rb_catch(const char *tag, VALUE (*func)(ANYARGS), VALUE data)
+static VALUE
+catch_i(tag)
+ VALUE tag;
{
- VALUE vtag = ID2SYM(rb_intern(tag));
+ return rb_funcall(Qnil, rb_intern("catch"), 1, tag);
+}
- return rb_block_call(Qnil, rb_intern("catch"), 1, &vtag, func, data);
+VALUE
+rb_catch(tag, func, data)
+ const char *tag;
+ VALUE (*func)();
+ VALUE data;
+{
+ return rb_iterate((VALUE(*)_((VALUE)))catch_i, ID2SYM(rb_intern(tag)), func, data);
}
/*
@@ -13158,7 +13245,9 @@ rb_catch(const char *tag, VALUE (*func)(ANYARGS), VALUE data)
*/
static VALUE
-rb_f_throw(int argc, VALUE *argv)
+rb_f_throw(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE tag, value;
struct tag *tt = prot_tag;
@@ -13173,7 +13262,7 @@ rb_f_throw(int argc, VALUE *argv)
break;
}
if (tt->tag == PROT_THREAD) {
- rb_raise(rb_eThreadError, "uncaught throw `%s' in thread %p",
+ rb_raise(rb_eThreadError, "uncaught throw `%s' in thread 0x%lx",
rb_id2name(SYM2ID(tag)),
curr_thread);
}
@@ -13190,7 +13279,9 @@ rb_f_throw(int argc, VALUE *argv)
}
void
-rb_throw(const char *tag, VALUE val)
+rb_throw(tag, val)
+ const char *tag;
+ VALUE val;
{
VALUE argv[2];
@@ -13198,86 +13289,3 @@ rb_throw(const char *tag, VALUE val)
argv[1] = val;
rb_f_throw(2, argv);
}
-
-static VALUE
-recursive_check(VALUE obj)
-{
- VALUE hash = rb_thread_local_aref(rb_thread_current(), recursive_key);
-
- if (NIL_P(hash) || TYPE(hash) != T_HASH) {
- return Qfalse;
- }
- else {
- VALUE list = rb_hash_aref(hash, ID2SYM(ruby_frame->this_func));
-
- if (NIL_P(list) || TYPE(list) != T_ARRAY) return Qfalse;
- return rb_ary_includes(list, rb_obj_id(obj));
- }
-}
-
-static void
-recursive_push(VALUE obj)
-{
- VALUE hash = rb_thread_local_aref(rb_thread_current(), recursive_key);
- VALUE list, sym;
-
- sym = ID2SYM(ruby_frame->this_func);
- if (NIL_P(hash) || TYPE(hash) != T_HASH) {
- hash = rb_hash_new();
- rb_thread_local_aset(rb_thread_current(), recursive_key, hash);
- list = Qnil;
- }
- else {
- list = rb_hash_aref(hash, sym);
- }
- if (NIL_P(list) || TYPE(list) != T_ARRAY) {
- list = rb_ary_new();
- rb_hash_aset(hash, sym, list);
- }
- rb_ary_push(list, rb_obj_id(obj));
-}
-
-static void
-recursive_pop(void)
-{
- VALUE hash = rb_thread_local_aref(rb_thread_current(), recursive_key);
- VALUE list, sym;
-
- sym = ID2SYM(ruby_frame->this_func);
- if (NIL_P(hash) || TYPE(hash) != T_HASH) {
- VALUE symname = rb_inspect(sym);
- VALUE thrname = rb_inspect(rb_thread_current());
- rb_raise(rb_eTypeError, "invalid inspect_tbl hash for %s in %s",
- StringValuePtr(symname), StringValuePtr(thrname));
- }
- list = rb_hash_aref(hash, sym);
- if (NIL_P(list) || TYPE(list) != T_ARRAY) {
- VALUE symname = rb_inspect(sym);
- VALUE thrname = rb_inspect(rb_thread_current());
- rb_raise(rb_eTypeError, "invalid inspect_tbl list for %s in %s",
- StringValuePtr(symname), StringValuePtr(thrname));
- }
- rb_ary_pop(list);
-}
-
-VALUE
-rb_exec_recursive(VALUE (*func)(VALUE, VALUE, int), VALUE obj, VALUE arg)
-{
- if (recursive_check(obj)) {
- return (*func)(obj, arg, Qtrue);
- }
- else {
- VALUE result;
- int state;
-
- recursive_push(obj);
- PUSH_TAG(PROT_NONE);
- if ((state = EXEC_TAG()) == 0) {
- result = (*func)(obj, arg, Qfalse);
- }
- POP_TAG();
- recursive_pop();
- if (state) JUMP_TAG(state);
- return result;
- }
-}
diff --git a/ext/.document b/ext/.document
index e9f791facc..ba8182593e 100644
--- a/ext/.document
+++ b/ext/.document
@@ -1,11 +1,7 @@
# Add files to this as they become documented
-bigdecimal/bigdecimal.c
-digest/digest.c
-etc/etc.c
-fcntl/fcntl.c
+enumerator/enumerator.c
iconv/iconv.c
-io/wait/wait.c
nkf/lib/kconv.rb
nkf/nkf.c
socket/socket.c
diff --git a/ext/Setup b/ext/Setup
index b0f29b9f7b..d0d6317a5e 100644
--- a/ext/Setup
+++ b/ext/Setup
@@ -10,23 +10,25 @@
#digest/sha1
#digest/sha2
#dl
+#enumerator
#etc
#fcntl
#gdbm
#iconv
#io/wait
#nkf
-#openssl
#pty
+#openssl
#racc/cparse
#readline
-#ripper
#sdbm
#socket
#stringio
#strscan
#syck
#syslog
+#tcltklib
+#thread
#tk
#win32ole
#zlib
diff --git a/ext/Setup.atheos b/ext/Setup.atheos
index 6e0b8ae5a6..6bda3a4cfb 100644
--- a/ext/Setup.atheos
+++ b/ext/Setup.atheos
@@ -17,17 +17,18 @@ gdbm
iconv
io/wait
nkf
-#openssl
pty
+#openssl
racc/parse
readline
-ripper
sdbm
socket
stringio
strscan
syck
syslog
+#tcltklib
+thread
#tk
#win32ole
zlib
diff --git a/ext/Setup.dj b/ext/Setup.dj
index 5276b125a1..4f94788886 100644
--- a/ext/Setup.dj
+++ b/ext/Setup.dj
@@ -17,17 +17,18 @@ gdbm
#iconv
#io/wait
nkf
-#openssl
#pty
+#openssl
racc/cparse
readline
-ripper
sdbm
#socket
stringio
strscan
syck
#syslog
+#tcltklib
+thread
#tk
#win32ole
zlib
diff --git a/ext/Setup.emx b/ext/Setup.emx
index fade917e92..afc5923577 100644
--- a/ext/Setup.emx
+++ b/ext/Setup.emx
@@ -17,17 +17,18 @@ fcntl
#iconv
#io/wait
nkf
-#openssl
#pty
+#openssl
racc/cparse
#readline
-#ripper
#sdbm
socket
stringio
strscan
#syck
#syslog
+#tcltklib
+thread
#tk
#win32ole
#zlib
diff --git a/ext/Setup.nt b/ext/Setup.nt
index c8574ba70a..9f8abf9b8d 100644
--- a/ext/Setup.nt
+++ b/ext/Setup.nt
@@ -17,17 +17,18 @@ fcntl
#iconv
#io/wait
nkf
-#openssl
#pty
+#openssl
racc/cparse
#readline
-#ripper
sdbm
socket
stringio
strscan
syck
#syslog
+#tcltklib
+thread
#tk
win32ole
#zlib
diff --git a/ext/Setup.x68 b/ext/Setup.x68
index 03f5d2d50d..0966e737e9 100644
--- a/ext/Setup.x68
+++ b/ext/Setup.x68
@@ -17,17 +17,18 @@ fcntl
#iconv
#io/wait
nkf
-#openssl
#pty
+#openssl
racc/cparse
#readline
-#ripper
#sdbm
#socket
stringio
strscan
#syck
#syslog
+#tcltklib
+thread
#tk
#win32ole
#zlib
diff --git a/ext/Win32API/Win32API.c b/ext/Win32API/Win32API.c
index 9a2de01f2d..a4fd0396f0 100644
--- a/ext/Win32API/Win32API.c
+++ b/ext/Win32API/Win32API.c
@@ -50,18 +50,18 @@ Win32API_initialize(self, dllname, proc, import, export)
SafeStringValue(dllname);
SafeStringValue(proc);
- hdll = LoadLibrary(RSTRING_PTR(dllname));
+ hdll = LoadLibrary(RSTRING(dllname)->ptr);
if (!hdll)
- rb_raise(rb_eRuntimeError, "LoadLibrary: %s\n", RSTRING_PTR(dllname));
+ rb_raise(rb_eRuntimeError, "LoadLibrary: %s\n", RSTRING(dllname)->ptr);
rb_iv_set(self, "__hdll__", Data_Wrap_Struct(rb_cData, 0, Win32API_FreeLibrary, (void*)hdll));
- hproc = (HANDLE)GetProcAddress(hdll, RSTRING_PTR(proc));
+ hproc = (HANDLE)GetProcAddress(hdll, RSTRING(proc)->ptr);
if (!hproc) {
str = rb_str_new3(proc);
str = rb_str_cat(str, "A", 1);
- hproc = (HANDLE)GetProcAddress(hdll, RSTRING_PTR(str));
+ hproc = (HANDLE)GetProcAddress(hdll, RSTRING(str)->ptr);
if (!hproc)
rb_raise(rb_eRuntimeError, "GetProcAddress: %s or %s\n",
- RSTRING_PTR(proc), RSTRING_PTR(str));
+ RSTRING(proc)->ptr, RSTRING(str)->ptr);
}
rb_iv_set(self, "__dll__", UINT2NUM((unsigned long)hdll));
rb_iv_set(self, "__dllname__", dllname);
@@ -72,10 +72,10 @@ Win32API_initialize(self, dllname, proc, import, export)
case T_NIL:
break;
case T_ARRAY:
- ptr = RARRAY_PTR(import);
- for (i = 0, len = RARRAY_LEN(import); i < len; i++) {
+ ptr = RARRAY(import)->ptr;
+ for (i = 0, len = RARRAY(import)->len; i < len; i++) {
SafeStringValue(ptr[i]);
- switch (*(char *)RSTRING_PTR(ptr[i])) {
+ switch (*(char *)RSTRING(ptr[i])->ptr) {
case 'N': case 'n': case 'L': case 'l':
rb_ary_push(a_import, INT2FIX(_T_NUMBER));
break;
@@ -90,8 +90,8 @@ Win32API_initialize(self, dllname, proc, import, export)
break;
default:
SafeStringValue(import);
- s = RSTRING_PTR(import);
- for (i = 0, len = RSTRING_LEN(import); i < len; i++) {
+ s = RSTRING(import)->ptr;
+ for (i = 0, len = RSTRING(import)->len; i < len; i++) {
switch (*s++) {
case 'N': case 'n': case 'L': case 'l':
rb_ary_push(a_import, INT2FIX(_T_NUMBER));
@@ -107,8 +107,8 @@ Win32API_initialize(self, dllname, proc, import, export)
break;
}
- if (16 < RARRAY_LEN(a_import)) {
- rb_raise(rb_eRuntimeError, "too many parameters: %d\n", RARRAY_LEN(a_import));
+ if (16 < RARRAY(a_import)->len) {
+ rb_raise(rb_eRuntimeError, "too many parameters: %ld\n", RARRAY(a_import)->len);
}
rb_iv_set(self, "__import__", a_import);
@@ -117,7 +117,7 @@ Win32API_initialize(self, dllname, proc, import, export)
ex = _T_VOID;
} else {
SafeStringValue(export);
- switch (*RSTRING_PTR(export)) {
+ switch (*RSTRING(export)->ptr) {
case 'V': case 'v':
ex = _T_VOID;
break;
@@ -159,7 +159,7 @@ Win32API_Call(argc, argv, obj)
VALUE obj_export = rb_iv_get(obj, "__export__");
FARPROC ApiFunction = (FARPROC)NUM2ULONG(obj_proc);
int items = rb_scan_args(argc, argv, "0*", &args);
- int nimport = RARRAY_LEN(obj_import);
+ int nimport = RARRAY(obj_import)->len;
if (items != nimport)
diff --git a/ext/Win32API/lib/win32/registry.rb b/ext/Win32API/lib/win32/registry.rb
index 2671551a33..9a2f3827b7 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] || $& }
+ str.gsub(/%([^%]+)%/) { ENV[$1] || ENV[$1.upcase] || $& }
end
@@type2name = { }
diff --git a/ext/Win32API/lib/win32/resolv.rb b/ext/Win32API/lib/win32/resolv.rb
index 6534d20760..92336fac28 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.join(path.gsub(/\\/, File::SEPARATOR), 'hosts')
+ path = File.expand_path('hosts', path)
File.exist?(path) ? path : nil
end
diff --git a/ext/bigdecimal/.cvsignore b/ext/bigdecimal/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/bigdecimal/.cvsignore
+++ b/ext/bigdecimal/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index f0e05a9799..636c0907d6 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -332,7 +332,7 @@ BigDecimal_load(VALUE self, VALUE str)
unsigned long m=0;
SafeStringValue(str);
- pch = RSTRING_PTR(str);
+ pch = (unsigned char *)RSTRING_PTR(str);
/* First get max prec */
while((*pch)!=(unsigned char)'\0' && (ch=*pch++)!=(unsigned char)':') {
if(!ISDIGIT(ch)) {
@@ -341,7 +341,7 @@ BigDecimal_load(VALUE self, VALUE str)
m = m*10 + (unsigned long)(ch-'0');
}
if(m>VpBaseFig()) m -= VpBaseFig();
- GUARD_OBJ(pv,VpNewRbClass(m,pch,self));
+ GUARD_OBJ(pv,VpNewRbClass(m,(char *)pch,self));
m /= VpBaseFig();
if(m && pv->MaxPrec>m) pv->MaxPrec = m+1;
return ToValue(pv);
@@ -586,19 +586,22 @@ BigDecimal_to_f(VALUE self)
{
ENTER(1);
Real *p;
- double d, d2;
+ double d;
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;
- d2 = pow(10.0,(double)e);
- if((errno == ERANGE && e>0) || (d2>1.0 && (fabs(d) > (DBL_MAX / d2)))) {
+ d = strtod(buf, 0);
+ if(errno == ERANGE) {
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*d2);
+ return rb_float_new(d);
}
/* The coerce method provides support for Ruby type coercion. It is not
@@ -781,17 +784,6 @@ BigDecimal_eq(VALUE self, VALUE r)
return BigDecimalCmp(self, r, '=');
}
-/* Returns true if the values are not equal in value. Values may be coerced
- * to perform the comparison:
- *
- * BigDecimal.new('1.0') != 1.0 -> false
- */
-static VALUE
-BigDecimal_ne(VALUE self, VALUE r)
-{
- return BigDecimalCmp(self, r, '!');
-}
-
/* call-seq:
* a < b
*
@@ -1062,7 +1054,7 @@ static VALUE
BigDecimal_remainder(VALUE self, VALUE r) /* remainder */
{
VALUE f;
- Real *d,*rv;
+ Real *d,*rv=0;
f = BigDecimal_divremain(self,r,&d,&rv);
if(f!=(VALUE)0) return f;
return ToValue(rv);
@@ -1516,7 +1508,7 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
} else if(*psz=='+') {
fPlus = 2; psz++;
}
- while(ch=*psz++) {
+ while((ch=*psz++)!=0) {
if(ISSPACE(ch)) continue;
if(!ISDIGIT(ch)) {
if(ch=='F' || ch=='f') fmt = 1; /* F format */
@@ -1811,76 +1803,94 @@ Init_bigdecimal(void)
/* Exceptions */
/*
- * Determines whether overflow, underflow or zero divide result in
+ * 0xff: Determines whether overflow, underflow or zero divide result in
* an exception being thrown. See BigDecimal.mode.
*/
rb_define_const(rb_cBigDecimal, "EXCEPTION_ALL",INT2FIX(VP_EXCEPTION_ALL));
/*
- * Determines what happens when the result of a computation is not a
+ * 0x02: Determines what happens when the result of a computation is not a
* number (NaN). See BigDecimal.mode.
*/
rb_define_const(rb_cBigDecimal, "EXCEPTION_NaN",INT2FIX(VP_EXCEPTION_NaN));
/*
- * Determines what happens when the result of a computation is infinity.
- * See BigDecimal.mode.
+ * 0x01: Determines what happens when the result of a computation is
+ * infinity. See BigDecimal.mode.
*/
rb_define_const(rb_cBigDecimal, "EXCEPTION_INFINITY",INT2FIX(VP_EXCEPTION_INFINITY));
/*
- * Determines what happens when the result of a computation is an underflow
- * (a result too small to be represented). See BigDecimal.mode.
+ * 0x04: Determines what happens when the result of a computation is an
+ * underflow (a result too small to be represented). See BigDecimal.mode.
*/
rb_define_const(rb_cBigDecimal, "EXCEPTION_UNDERFLOW",INT2FIX(VP_EXCEPTION_UNDERFLOW));
/*
- * Determines what happens when the result of a computation is an underflow
- * (a result too large to be represented). See BigDecimal.mode.
+ * 0x01: Determines what happens when the result of a computation is an
+ * underflow (a result too large to be represented). See BigDecimal.mode.
*/
rb_define_const(rb_cBigDecimal, "EXCEPTION_OVERFLOW",INT2FIX(VP_EXCEPTION_OVERFLOW));
/*
- * Determines what happens when a division by zero is performed.
+ * 0x01: Determines what happens when a division by zero is performed.
* See BigDecimal.mode.
*/
rb_define_const(rb_cBigDecimal, "EXCEPTION_ZERODIVIDE",INT2FIX(VP_EXCEPTION_ZERODIVIDE));
/*
- * Determines what happens when a result must be rounded in order to
- * fit in the appropriate number of significant digits. See
+ * 0x100: Determines what happens when a result must be rounded in order to
+ * fit in the appropriate number of significant digits. See
* BigDecimal.mode.
*/
rb_define_const(rb_cBigDecimal, "ROUND_MODE",INT2FIX(VP_ROUND_MODE));
- /* Indicates that values should be rounded away from zero. See BigDecimal.mode. */
+ /* 1: Indicates that values should be rounded away from zero. See
+ * BigDecimal.mode.
+ */
rb_define_const(rb_cBigDecimal, "ROUND_UP",INT2FIX(VP_ROUND_UP));
- /* Indicates that values should be rounded towards zero. See BigDecimal.mode. */
+
+ /* 2: Indicates that values should be rounded towards zero. See
+ * BigDecimal.mode.
+ */
rb_define_const(rb_cBigDecimal, "ROUND_DOWN",INT2FIX(VP_ROUND_DOWN));
- /* Indicates that digits >= 5 should be rounded up, others rounded down. See BigDecimal.mode. */
+
+ /* 3: Indicates that digits >= 5 should be rounded up, others rounded down.
+ * See BigDecimal.mode. */
rb_define_const(rb_cBigDecimal, "ROUND_HALF_UP",INT2FIX(VP_ROUND_HALF_UP));
- /* Indicates that digits >= 6 should be rounded up, others rounded down. See BigDecimal.mode. */
+
+ /* 4: Indicates that digits >= 6 should be rounded up, others rounded down.
+ * See BigDecimal.mode.
+ */
rb_define_const(rb_cBigDecimal, "ROUND_HALF_DOWN",INT2FIX(VP_ROUND_HALF_DOWN));
- /* Round towards +infinity. See BigDecimal.mode. */
+ /* 5: Round towards +infinity. See BigDecimal.mode. */
rb_define_const(rb_cBigDecimal, "ROUND_CEILING",INT2FIX(VP_ROUND_CEIL));
- /* Round towards -infinity. See BigDecimal.mode. */
+
+ /* 6: Round towards -infinity. See BigDecimal.mode. */
rb_define_const(rb_cBigDecimal, "ROUND_FLOOR",INT2FIX(VP_ROUND_FLOOR));
- /* Round towards the even neighbor. See BigDecimal.mode. */
+
+ /* 7: Round towards the even neighbor. See BigDecimal.mode. */
rb_define_const(rb_cBigDecimal, "ROUND_HALF_EVEN",INT2FIX(VP_ROUND_HALF_EVEN));
- /* Indicates that a value is not a number. See BigDecimal.sign. */
+ /* 0: Indicates that a value is not a number. See BigDecimal.sign. */
rb_define_const(rb_cBigDecimal, "SIGN_NaN",INT2FIX(VP_SIGN_NaN));
- /* Indicates that a value is +0. See BigDecimal.sign. */
+
+ /* 1: Indicates that a value is +0. See BigDecimal.sign. */
rb_define_const(rb_cBigDecimal, "SIGN_POSITIVE_ZERO",INT2FIX(VP_SIGN_POSITIVE_ZERO));
- /* Indicates that a value is -0. See BigDecimal.sign. */
+
+ /* -1: Indicates that a value is -0. See BigDecimal.sign. */
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_ZERO",INT2FIX(VP_SIGN_NEGATIVE_ZERO));
- /* Indicates that a value is positive and finite. See BigDecimal.sign. */
+
+ /* 2: Indicates that a value is positive and finite. See BigDecimal.sign. */
rb_define_const(rb_cBigDecimal, "SIGN_POSITIVE_FINITE",INT2FIX(VP_SIGN_POSITIVE_FINITE));
- /* Indicates that a value is negative and finite. See BigDecimal.sign. */
+
+ /* -2: Indicates that a value is negative and finite. See BigDecimal.sign. */
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_FINITE",INT2FIX(VP_SIGN_NEGATIVE_FINITE));
- /* Indicates that a value is positive and infinite. See BigDecimal.sign. */
+
+ /* 3: Indicates that a value is positive and infinite. See BigDecimal.sign. */
rb_define_const(rb_cBigDecimal, "SIGN_POSITIVE_INFINITE",INT2FIX(VP_SIGN_POSITIVE_INFINITE));
- /* Indicates that a value is negative and infinite. See BigDecimal.sign. */
+
+ /* -3: Indicates that a value is negative and infinite. See BigDecimal.sign. */
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_INFINITE",INT2FIX(VP_SIGN_NEGATIVE_INFINITE));
/* instance methods */
@@ -1921,7 +1931,6 @@ Init_bigdecimal(void)
rb_define_method(rb_cBigDecimal, "==", BigDecimal_eq, 1);
rb_define_method(rb_cBigDecimal, "===", BigDecimal_eq, 1);
rb_define_method(rb_cBigDecimal, "eql?", BigDecimal_eq, 1);
- rb_define_method(rb_cBigDecimal, "!=", BigDecimal_ne, 1);
rb_define_method(rb_cBigDecimal, "<", BigDecimal_lt, 1);
rb_define_method(rb_cBigDecimal, "<=", BigDecimal_le, 1);
rb_define_method(rb_cBigDecimal, ">", BigDecimal_gt, 1);
@@ -1956,17 +1965,27 @@ 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 */
-static U_LONG maxnr = 100; /* Maximum iterations for calcurating sqrt. */
+#define maxnr 100UL /* Maximum iterations for calcurating sqrt. */
/* used in VpSqrt() */
/* ETC */
@@ -2083,8 +2102,8 @@ VpSetRoundMode(unsigned long n)
* (to let the compiler know they may be changed in outside
* (... but not actually..)).
*/
-volatile double gZero_ABCED9B1_CE73__00400511F31D = 0.0;
-volatile double gOne_ABCED9B4_CE73__00400511F31D = 1.0;
+volatile const double gZero_ABCED9B1_CE73__00400511F31D = 0.0;
+volatile const double gOne_ABCED9B4_CE73__00400511F31D = 1.0;
static double
Zero(void)
{
@@ -2356,16 +2375,15 @@ 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(
@@ -2382,6 +2400,8 @@ 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");
@@ -2390,15 +2410,6 @@ 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);
@@ -2501,7 +2512,7 @@ VpAlloc(U_LONG mx, const char *szVal)
psz = ALLOCA_N(char,strlen(szVal)+1);
i = 0;
ipn = 0;
- while(psz[i]=szVal[ipn]) {
+ while((psz[i]=szVal[ipn])!=0) {
if(ISDIGIT(psz[i])) ++ni;
if(psz[i]=='_') {
if(ni>0) {ipn++;continue;}
@@ -2544,7 +2555,7 @@ VpAlloc(U_LONG mx, const char *szVal)
else if(szVal[i] == '+') ++i;
/* Skip digits */
ni = 0; /* digits in mantissa */
- while(v = szVal[i]) {
+ while((v = szVal[i]) != 0) {
if(!ISDIGIT(v)) break;
++i;
++ni;
@@ -2558,7 +2569,7 @@ VpAlloc(U_LONG mx, const char *szVal)
if(szVal[i] == '.') { /* xxx. */
++i;
ipf = i;
- while(v = szVal[i]) { /* get fraction part. */
+ while((v = szVal[i]) != 0) { /* get fraction part. */
if(!ISDIGIT(v)) break;
++i;
++nf;
@@ -2576,7 +2587,7 @@ VpAlloc(U_LONG mx, const char *szVal)
ipe = i;
v = szVal[i];
if((v == '-') ||(v == '+')) ++i;
- while(v=szVal[i]) {
+ while((v=szVal[i])!=0) {
if(!ISDIGIT(v)) break;
++i;
++ne;
@@ -3915,7 +3926,7 @@ VpCtoV(Real *a, const char *int_chr, U_LONG ni, const char *frac, U_LONG nf, con
/* get integer part */
i = 0;
sign = 1;
- if(ni > 0) {
+ if(ni >= 0) {
if(int_chr[0] == '-') {
sign = -1;
++i;
@@ -4428,7 +4439,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=v/10) nf--;
+ while((v /= 10) != 0) nf--;
nf += (BASE_FIG-1);
return VpMidRound(y,f,nf);
}
diff --git a/ext/bigdecimal/extconf.rb b/ext/bigdecimal/extconf.rb
index a68a656044..864aaad862 100644
--- a/ext/bigdecimal/extconf.rb
+++ b/ext/bigdecimal/extconf.rb
@@ -1,2 +1,12 @@
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/.cvsignore b/ext/curses/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/curses/.cvsignore
+++ b/ext/curses/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/curses/curses.c b/ext/curses/curses.c
index 9e448bf881..9c51a2127f 100644
--- a/ext/curses/curses.c
+++ b/ext/curses/curses.c
@@ -54,8 +54,8 @@
# define USE_MOUSE 1
#endif
-#define NUM2CH NUM2CHR
-#define CH2FIX CHR2FIX
+#define NUM2CH NUM2LONG
+#define CH2FIX LONG2FIX
static VALUE mCurses;
static VALUE mKey;
@@ -77,7 +77,7 @@ static VALUE window_attron();
static VALUE window_attrset();
static void
-no_window(void)
+no_window()
{
rb_raise(rb_eRuntimeError, "already closed window");
}
@@ -90,7 +90,8 @@ no_window(void)
} while (0)
static void
-free_window(struct windata *winp)
+free_window(winp)
+ struct windata *winp;
{
if (winp->window && winp->window != stdscr) delwin(winp->window);
winp->window = 0;
@@ -98,7 +99,9 @@ free_window(struct windata *winp)
}
static VALUE
-prep_window(VALUE class, WINDOW *window)
+prep_window(class, window)
+ VALUE class;
+ WINDOW *window;
{
VALUE obj;
struct windata *winp;
@@ -118,7 +121,7 @@ prep_window(VALUE class, WINDOW *window)
/* def init_screen */
static VALUE
-curses_init_screen(void)
+curses_init_screen()
{
rb_secure(4);
if (rb_stdscr) return rb_stdscr;
@@ -136,7 +139,7 @@ curses_init_screen(void)
/* def close_screen */
static VALUE
-curses_close_screen(void)
+curses_close_screen()
{
#ifdef HAVE_ISENDWIN
if (!isendwin())
@@ -161,7 +164,7 @@ curses_finalize(VALUE dummy)
/* def closed? */
static VALUE
-curses_closed(void)
+curses_closed()
{
#ifdef HAVE_ISENDWIN
if (isendwin()) {
@@ -175,7 +178,8 @@ curses_closed(void)
/* def clear */
static VALUE
-curses_clear(VALUE obj)
+curses_clear(obj)
+ VALUE obj;
{
curses_stdscr();
wclear(stdscr);
@@ -184,7 +188,7 @@ curses_clear(VALUE obj)
/* def clrtoeol */
static VALUE
-curses_clrtoeol(void)
+curses_clrtoeol()
{
curses_stdscr();
clrtoeol();
@@ -193,7 +197,8 @@ curses_clrtoeol(void)
/* def refresh */
static VALUE
-curses_refresh(VALUE obj)
+curses_refresh(obj)
+ VALUE obj;
{
curses_stdscr();
refresh();
@@ -202,7 +207,8 @@ curses_refresh(VALUE obj)
/* def doupdate */
static VALUE
-curses_doupdate(VALUE obj)
+curses_doupdate(obj)
+ VALUE obj;
{
curses_stdscr();
#ifdef HAVE_DOUPDATE
@@ -215,7 +221,8 @@ curses_doupdate(VALUE obj)
/* def echo */
static VALUE
-curses_echo(VALUE obj)
+curses_echo(obj)
+ VALUE obj;
{
curses_stdscr();
echo();
@@ -224,7 +231,8 @@ curses_echo(VALUE obj)
/* def noecho */
static VALUE
-curses_noecho(VALUE obj)
+curses_noecho(obj)
+ VALUE obj;
{
curses_stdscr();
noecho();
@@ -233,7 +241,8 @@ curses_noecho(VALUE obj)
/* def raw */
static VALUE
-curses_raw(VALUE obj)
+curses_raw(obj)
+ VALUE obj;
{
curses_stdscr();
raw();
@@ -242,7 +251,8 @@ curses_raw(VALUE obj)
/* def noraw */
static VALUE
-curses_noraw(VALUE obj)
+curses_noraw(obj)
+ VALUE obj;
{
curses_stdscr();
noraw();
@@ -251,7 +261,8 @@ curses_noraw(VALUE obj)
/* def cbreak */
static VALUE
-curses_cbreak(VALUE obj)
+curses_cbreak(obj)
+ VALUE obj;
{
curses_stdscr();
cbreak();
@@ -260,7 +271,8 @@ curses_cbreak(VALUE obj)
/* def nocbreak */
static VALUE
-curses_nocbreak(VALUE obj)
+curses_nocbreak(obj)
+ VALUE obj;
{
curses_stdscr();
nocbreak();
@@ -269,7 +281,8 @@ curses_nocbreak(VALUE obj)
/* def nl */
static VALUE
-curses_nl(VALUE obj)
+curses_nl(obj)
+ VALUE obj;
{
curses_stdscr();
nl();
@@ -278,7 +291,8 @@ curses_nl(VALUE obj)
/* def nonl */
static VALUE
-curses_nonl(VALUE obj)
+curses_nonl(obj)
+ VALUE obj;
{
curses_stdscr();
nonl();
@@ -287,7 +301,8 @@ curses_nonl(VALUE obj)
/* def beep */
static VALUE
-curses_beep(VALUE obj)
+curses_beep(obj)
+ VALUE obj;
{
#ifdef HAVE_BEEP
curses_stdscr();
@@ -298,7 +313,8 @@ curses_beep(VALUE obj)
/* def flash */
static VALUE
-curses_flash(VALUE obj)
+curses_flash(obj)
+ VALUE obj;
{
#ifdef HAVE_FLASH
curses_stdscr();
@@ -309,7 +325,9 @@ curses_flash(VALUE obj)
/* def ungetch */
static VALUE
-curses_ungetch(VALUE obj, VALUE ch)
+curses_ungetch(obj, ch)
+ VALUE obj;
+ VALUE ch;
{
#ifdef HAVE_UNGETCH
curses_stdscr();
@@ -322,7 +340,10 @@ curses_ungetch(VALUE obj, VALUE ch)
/* def setpos(y, x) */
static VALUE
-curses_setpos(VALUE obj, VALUE y, VALUE x)
+curses_setpos(obj, y, x)
+ VALUE obj;
+ VALUE y;
+ VALUE x;
{
curses_stdscr();
move(NUM2INT(y), NUM2INT(x));
@@ -331,7 +352,8 @@ curses_setpos(VALUE obj, VALUE y, VALUE x)
/* def standout */
static VALUE
-curses_standout(VALUE obj)
+curses_standout(obj)
+ VALUE obj;
{
standout();
return Qnil;
@@ -339,7 +361,8 @@ curses_standout(VALUE obj)
/* def standend */
static VALUE
-curses_standend(VALUE obj)
+curses_standend(obj)
+ VALUE obj;
{
standend();
return Qnil;
@@ -347,7 +370,8 @@ curses_standend(VALUE obj)
/* def inch */
static VALUE
-curses_inch(VALUE obj)
+curses_inch(obj)
+ VALUE obj;
{
curses_stdscr();
return CH2FIX(inch());
@@ -355,7 +379,9 @@ curses_inch(VALUE obj)
/* def addch(ch) */
static VALUE
-curses_addch(VALUE obj, VALUE ch)
+curses_addch(obj, ch)
+ VALUE obj;
+ VALUE ch;
{
curses_stdscr();
addch(NUM2CH(ch));
@@ -364,7 +390,9 @@ curses_addch(VALUE obj, VALUE ch)
/* def insch(ch) */
static VALUE
-curses_insch(VALUE obj, VALUE ch)
+curses_insch(obj, ch)
+ VALUE obj;
+ VALUE ch;
{
curses_stdscr();
insch(NUM2CH(ch));
@@ -373,7 +401,9 @@ curses_insch(VALUE obj, VALUE ch)
/* def addstr(str) */
static VALUE
-curses_addstr(VALUE obj, VALUE str)
+curses_addstr(obj, str)
+ VALUE obj;
+ VALUE str;
{
curses_stdscr();
if (!NIL_P(str)) {
@@ -384,7 +414,8 @@ curses_addstr(VALUE obj, VALUE str)
/* def getch */
static VALUE
-curses_getch(VALUE obj)
+curses_getch(obj)
+ VALUE obj;
{
rb_read_check(stdin);
curses_stdscr();
@@ -393,7 +424,8 @@ curses_getch(VALUE obj)
/* def getstr */
static VALUE
-curses_getstr(VALUE obj)
+curses_getstr(obj)
+ VALUE obj;
{
char rtn[1024]; /* This should be big enough.. I hope */
@@ -408,7 +440,8 @@ curses_getstr(VALUE obj)
/* def delch */
static VALUE
-curses_delch(VALUE obj)
+curses_delch(obj)
+ VALUE obj;
{
delch();
return Qnil;
@@ -416,7 +449,8 @@ curses_delch(VALUE obj)
/* def delelteln */
static VALUE
-curses_deleteln(VALUE obj)
+curses_deleteln(obj)
+ VALUE obj;
{
#if defined(HAVE_DELETELN) || defined(deleteln)
deleteln();
@@ -426,7 +460,8 @@ curses_deleteln(VALUE obj)
/* def insertln */
static VALUE
-curses_insertln(VALUE obj)
+curses_insertln(obj)
+ VALUE obj;
{
#if defined(HAVE_INSERTLN) || defined(insertln)
insertln();
@@ -436,7 +471,9 @@ curses_insertln(VALUE obj)
/* def keyname */
static VALUE
-curses_keyname(VALUE obj, VALUE c)
+curses_keyname(obj, c)
+ VALUE obj;
+ VALUE c;
{
#ifdef HAVE_KEYNAME
const char *name;
@@ -453,13 +490,13 @@ curses_keyname(VALUE obj, VALUE c)
}
static VALUE
-curses_lines(void)
+curses_lines()
{
return INT2FIX(LINES);
}
static VALUE
-curses_cols(void)
+curses_cols()
{
return INT2FIX(COLS);
}
@@ -619,7 +656,7 @@ struct mousedata {
};
static void
-no_mevent(void)
+no_mevent()
{
rb_raise(rb_eRuntimeError, "no such mouse event");
}
@@ -731,7 +768,12 @@ window_s_allocate(VALUE class)
/* def initialize(h, w, top, left) */
static VALUE
-window_initialize(VALUE obj, VALUE h, VALUE w, VALUE top, VALUE left)
+window_initialize(obj, h, w, top, left)
+ VALUE obj;
+ VALUE h;
+ VALUE w;
+ VALUE top;
+ VALUE left;
{
struct windata *winp;
WINDOW *window;
@@ -749,7 +791,12 @@ window_initialize(VALUE obj, VALUE h, VALUE w, VALUE top, VALUE left)
/* def subwin(height, width, top, left) */
static VALUE
-window_subwin(VALUE obj, VALUE height, VALUE width, VALUE top, VALUE left)
+window_subwin(obj, height, width, top, left)
+ VALUE obj;
+ VALUE height;
+ VALUE width;
+ VALUE top;
+ VALUE left;
{
struct windata *winp;
WINDOW *window;
@@ -769,7 +816,8 @@ window_subwin(VALUE obj, VALUE height, VALUE width, VALUE top, VALUE left)
/* def close */
static VALUE
-window_close(VALUE obj)
+window_close(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -782,7 +830,8 @@ window_close(VALUE obj)
/* def clear */
static VALUE
-window_clear(VALUE obj)
+window_clear(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -794,7 +843,8 @@ window_clear(VALUE obj)
/* def clrtoeol */
static VALUE
-window_clrtoeol(VALUE obj)
+window_clrtoeol(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -806,7 +856,8 @@ window_clrtoeol(VALUE obj)
/* def refresh */
static VALUE
-window_refresh(VALUE obj)
+window_refresh(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -818,7 +869,8 @@ window_refresh(VALUE obj)
/* def noutrefresh */
static VALUE
-window_noutrefresh(VALUE obj)
+window_noutrefresh(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -834,7 +886,10 @@ window_noutrefresh(VALUE obj)
/* def move(y, x) */
static VALUE
-window_move(VALUE obj, VALUE y, VALUE x)
+window_move(obj, y, x)
+ VALUE obj;
+ VALUE y;
+ VALUE x;
{
struct windata *winp;
@@ -846,7 +901,10 @@ window_move(VALUE obj, VALUE y, VALUE x)
/* def setpos(y, x) */
static VALUE
-window_setpos(VALUE obj, VALUE y, VALUE x)
+window_setpos(obj, y, x)
+ VALUE obj;
+ VALUE y;
+ VALUE x;
{
struct windata *winp;
@@ -857,7 +915,8 @@ window_setpos(VALUE obj, VALUE y, VALUE x)
/* def cury */
static VALUE
-window_cury(VALUE obj)
+window_cury(obj)
+ VALUE obj;
{
struct windata *winp;
int x, y;
@@ -869,7 +928,8 @@ window_cury(VALUE obj)
/* def curx */
static VALUE
-window_curx(VALUE obj)
+window_curx(obj)
+ VALUE obj;
{
struct windata *winp;
int x, y;
@@ -881,7 +941,8 @@ window_curx(VALUE obj)
/* def maxy */
static VALUE
-window_maxy(VALUE obj)
+window_maxy(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -901,7 +962,8 @@ window_maxy(VALUE obj)
/* def maxx */
static VALUE
-window_maxx(VALUE obj)
+window_maxx(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -921,7 +983,8 @@ window_maxx(VALUE obj)
/* def begy */
static VALUE
-window_begy(VALUE obj)
+window_begy(obj)
+ VALUE obj;
{
struct windata *winp;
int x, y;
@@ -937,7 +1000,8 @@ window_begy(VALUE obj)
/* def begx */
static VALUE
-window_begx(VALUE obj)
+window_begx(obj)
+ VALUE obj;
{
struct windata *winp;
int x, y;
@@ -953,7 +1017,9 @@ window_begx(VALUE obj)
/* def box(vert, hor) */
static VALUE
-window_box(int argc, VALUE *argv, VALUE self)
+window_box(argc, argv, self)
+ int argc;
+ VALUE argv[], self;
{
struct windata *winp;
VALUE vert, hor, corn;
@@ -987,7 +1053,8 @@ window_box(int argc, VALUE *argv, VALUE self)
/* def standout */
static VALUE
-window_standout(VALUE obj)
+window_standout(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -998,7 +1065,8 @@ window_standout(VALUE obj)
/* def standend */
static VALUE
-window_standend(VALUE obj)
+window_standend(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -1009,7 +1077,8 @@ window_standend(VALUE obj)
/* def inch */
static VALUE
-window_inch(VALUE obj)
+window_inch(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -1019,7 +1088,9 @@ window_inch(VALUE obj)
/* def addch(ch) */
static VALUE
-window_addch(VALUE obj, VALUE ch)
+window_addch(obj, ch)
+ VALUE obj;
+ VALUE ch;
{
struct windata *winp;
@@ -1031,7 +1102,9 @@ window_addch(VALUE obj, VALUE ch)
/* def insch(ch) */
static VALUE
-window_insch(VALUE obj, VALUE ch)
+window_insch(obj, ch)
+ VALUE obj;
+ VALUE ch;
{
struct windata *winp;
@@ -1043,7 +1116,9 @@ window_insch(VALUE obj, VALUE ch)
/* def addstr(str) */
static VALUE
-window_addstr(VALUE obj, VALUE str)
+window_addstr(obj, str)
+ VALUE obj;
+ VALUE str;
{
if (!NIL_P(str)) {
struct windata *winp;
@@ -1056,7 +1131,9 @@ window_addstr(VALUE obj, VALUE str)
/* def <<(str) */
static VALUE
-window_addstr2(VALUE obj, VALUE str)
+window_addstr2(obj, str)
+ VALUE obj;
+ VALUE str;
{
window_addstr(obj, str);
return obj;
@@ -1064,7 +1141,8 @@ window_addstr2(VALUE obj, VALUE str)
/* def getch */
static VALUE
-window_getch(VALUE obj)
+window_getch(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -1075,7 +1153,8 @@ window_getch(VALUE obj)
/* def getstr */
static VALUE
-window_getstr(VALUE obj)
+window_getstr(obj)
+ VALUE obj;
{
struct windata *winp;
char rtn[1024]; /* This should be big enough.. I hope */
@@ -1092,7 +1171,8 @@ window_getstr(VALUE obj)
/* def delch */
static VALUE
-window_delch(VALUE obj)
+window_delch(obj)
+ VALUE obj;
{
struct windata *winp;
@@ -1103,7 +1183,8 @@ window_delch(VALUE obj)
/* def delelteln */
static VALUE
-window_deleteln(VALUE obj)
+window_deleteln(obj)
+ VALUE obj;
{
#if defined(HAVE_WDELETELN) || defined(wdeleteln)
struct windata *winp;
@@ -1116,7 +1197,8 @@ window_deleteln(VALUE obj)
/* def insertln */
static VALUE
-window_insertln(VALUE obj)
+window_insertln(obj)
+ VALUE obj;
{
#if defined(HAVE_WINSERTLN) || defined(winsertln)
struct windata *winp;
@@ -1174,7 +1256,7 @@ window_color_set(VALUE obj, VALUE col)
res = wcolor_set(winp->window, NUM2INT(col), NULL);
return (res == OK) ? Qtrue : Qfalse;
}
-#endif /* defined(USE_COLOR) && defined(HAVE_WCOLOR_SET) */
+#endif /* USE_COLOR */
static VALUE
window_scroll(VALUE obj)
@@ -1357,7 +1439,7 @@ window_timeout(VALUE obj, VALUE delay)
/*------------------------- Initialization -------------------------*/
void
-Init_curses(void)
+Init_curses()
{
mCurses = rb_define_module("Curses");
mKey = rb_define_module_under(mCurses, "Key");
diff --git a/ext/curses/extconf.rb b/ext/curses/extconf.rb
index 01fe971093..0124bbbf4a 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_func(f) || (have_macro(f, curses) && $defs.push(format("-DHAVE_%s", f.upcase)))
end
flag = "-D_XOPEN_SOURCE_EXTENDED"
src = "int test_var[(sizeof(char*)>sizeof(int))*2-1];"
diff --git a/ext/dbm/.cvsignore b/ext/dbm/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/dbm/.cvsignore
+++ b/ext/dbm/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index e89f8b1d74..69b7a6e7a7 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -32,7 +32,7 @@ struct dbmdata {
};
static void
-closed_dbm(void)
+closed_dbm()
{
rb_raise(rb_eDBMError, "closed DBM file");
}
@@ -49,7 +49,8 @@ closed_dbm(void)
}
static void
-free_dbm(struct dbmdata *dbmp)
+free_dbm(dbmp)
+ struct dbmdata *dbmp;
{
if (dbmp) {
if (dbmp->di_dbm) dbm_close(dbmp->di_dbm);
@@ -58,7 +59,8 @@ free_dbm(struct dbmdata *dbmp)
}
static VALUE
-fdbm_close(VALUE obj)
+fdbm_close(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
@@ -70,7 +72,8 @@ fdbm_close(VALUE obj)
}
static VALUE
-fdbm_closed(VALUE obj)
+fdbm_closed(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
@@ -83,14 +86,19 @@ fdbm_closed(VALUE obj)
return Qfalse;
}
+static VALUE fdbm_alloc _((VALUE));
static VALUE
-fdbm_alloc(VALUE klass)
+fdbm_alloc(klass)
+ VALUE klass;
{
return Data_Wrap_Struct(klass, 0, free_dbm, 0);
}
static VALUE
-fdbm_initialize(int argc, VALUE *argv, VALUE obj)
+fdbm_initialize(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE file, vmode, vflags;
DBM *dbm;
@@ -114,24 +122,24 @@ fdbm_initialize(int argc, VALUE *argv, VALUE obj)
if (flags & RUBY_DBM_RW_BIT) {
flags &= ~RUBY_DBM_RW_BIT;
- dbm = dbm_open(RSTRING_PTR(file), flags, mode);
+ dbm = dbm_open(RSTRING(file)->ptr, flags, mode);
}
else {
dbm = 0;
if (mode >= 0) {
- dbm = dbm_open(RSTRING_PTR(file), O_RDWR|O_CREAT, mode);
+ dbm = dbm_open(RSTRING(file)->ptr, O_RDWR|O_CREAT, mode);
}
if (!dbm) {
- dbm = dbm_open(RSTRING_PTR(file), O_RDWR, 0);
+ dbm = dbm_open(RSTRING(file)->ptr, O_RDWR, 0);
}
if (!dbm) {
- dbm = dbm_open(RSTRING_PTR(file), O_RDONLY, 0);
+ dbm = dbm_open(RSTRING(file)->ptr, O_RDONLY, 0);
}
}
if (!dbm) {
if (mode == -1) return Qnil;
- rb_sys_fail(RSTRING_PTR(file));
+ rb_sys_fail(RSTRING(file)->ptr);
}
dbmp = ALLOC(struct dbmdata);
@@ -143,7 +151,10 @@ fdbm_initialize(int argc, VALUE *argv, VALUE obj)
}
static VALUE
-fdbm_s_open(int argc, VALUE *argv, VALUE klass)
+fdbm_s_open(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE obj = Data_Wrap_Struct(klass, 0, free_dbm, 0);
@@ -159,15 +170,16 @@ fdbm_s_open(int argc, VALUE *argv, VALUE klass)
}
static VALUE
-fdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
+fdbm_fetch(obj, keystr, ifnone)
+ VALUE obj, keystr, ifnone;
{
datum key, value;
struct dbmdata *dbmp;
DBM *dbm;
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
GetDBM2(obj, dbmp, dbm);
value = dbm_fetch(dbm, key);
@@ -180,13 +192,17 @@ fdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
}
static VALUE
-fdbm_aref(VALUE obj, VALUE keystr)
+fdbm_aref(obj, keystr)
+ VALUE obj, keystr;
{
return fdbm_fetch(obj, keystr, Qnil);
}
static VALUE
-fdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
+fdbm_fetch_m(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE keystr, valstr, ifnone;
@@ -199,21 +215,22 @@ fdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
}
static VALUE
-fdbm_index(VALUE obj, VALUE valstr)
+fdbm_index(obj, valstr)
+ VALUE obj, valstr;
{
datum key, val;
struct dbmdata *dbmp;
DBM *dbm;
StringValue(valstr);
- val.dptr = RSTRING_PTR(valstr);
- val.dsize = RSTRING_LEN(valstr);
+ val.dptr = RSTRING(valstr)->ptr;
+ val.dsize = RSTRING(valstr)->len;
GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
- if (val.dsize == RSTRING_LEN(valstr) &&
- memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0) {
+ if (val.dsize == RSTRING(valstr)->len &&
+ memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0) {
return rb_tainted_str_new(key.dptr, key.dsize);
}
}
@@ -221,31 +238,68 @@ fdbm_index(VALUE obj, VALUE valstr)
}
static VALUE
-fdbm_select(VALUE obj)
+fdbm_indexes(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
- VALUE new = rb_ary_new();
- datum key, val;
- DBM *dbm;
- struct dbmdata *dbmp;
+ VALUE new;
+ int i;
- GetDBM2(obj, dbmp, dbm);
- for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
- VALUE assoc, v;
- val = dbm_fetch(dbm, key);
- assoc = rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
- rb_tainted_str_new(val.dptr, val.dsize));
- v = rb_yield(assoc);
- if (RTEST(v)) {
- rb_ary_push(new, assoc);
+ new = rb_ary_new2(argc);
+ for (i=0; i<argc; i++) {
+ rb_ary_push(new, fdbm_fetch(obj, argv[i], Qnil));
+ }
+
+ return new;
+}
+
+static VALUE
+fdbm_select(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
+ VALUE new = rb_ary_new2(argc);
+ int i;
+
+ if (rb_block_given_p()) {
+ datum key, val;
+ DBM *dbm;
+ struct dbmdata *dbmp;
+
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
}
- GetDBM2(obj, dbmp, dbm);
+ GetDBM2(obj, dbmp, dbm);
+ for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
+ VALUE assoc, v;
+ val = dbm_fetch(dbm, key);
+ assoc = rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
+ rb_tainted_str_new(val.dptr, val.dsize));
+ v = rb_yield(assoc);
+ if (RTEST(v)) {
+ rb_ary_push(new, assoc);
+ }
+ GetDBM2(obj, dbmp, dbm);
+ }
+ }
+ else {
+ rb_warn("DBM#select(index..) is deprecated; use DBM#values_at");
+
+ for (i=0; i<argc; i++) {
+ rb_ary_push(new, fdbm_fetch(obj, argv[i], Qnil));
+ }
}
return new;
}
static VALUE
-fdbm_values_at(int argc, VALUE *argv, VALUE obj)
+fdbm_values_at(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE new = rb_ary_new2(argc);
int i;
@@ -258,14 +312,16 @@ fdbm_values_at(int argc, VALUE *argv, VALUE obj)
}
static void
-fdbm_modify(VALUE obj)
+fdbm_modify(obj)
+ VALUE obj;
{
rb_secure(4);
if (OBJ_FROZEN(obj)) rb_error_frozen("DBM");
}
static VALUE
-fdbm_delete(VALUE obj, VALUE keystr)
+fdbm_delete(obj, keystr)
+ VALUE obj, keystr;
{
datum key, value;
struct dbmdata *dbmp;
@@ -274,11 +330,10 @@ fdbm_delete(VALUE obj, VALUE keystr)
fdbm_modify(obj);
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
GetDBM2(obj, dbmp, dbm);
-
value = dbm_fetch(dbm, key);
if (value.dptr == 0) {
if (rb_block_given_p()) return rb_yield(keystr);
@@ -299,7 +354,8 @@ fdbm_delete(VALUE obj, VALUE keystr)
}
static VALUE
-fdbm_shift(VALUE obj)
+fdbm_shift(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -321,7 +377,8 @@ fdbm_shift(VALUE obj)
}
static VALUE
-fdbm_delete_if(VALUE obj)
+fdbm_delete_if(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -345,23 +402,24 @@ fdbm_delete_if(VALUE obj)
GetDBM2(obj, dbmp, dbm);
}
- for (i = 0; i < RARRAY_LEN(ary); i++) {
- keystr = RARRAY_PTR(ary)[i];
+ for (i = 0; i < RARRAY(ary)->len; i++) {
+ keystr = RARRAY(ary)->ptr[i];
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
if (dbm_delete(dbm, key)) {
rb_raise(rb_eDBMError, "dbm_delete failed");
}
}
if (status) rb_jump_tag(status);
- if (n > 0) dbmp->di_size = n - RARRAY_LEN(ary);
+ if (n > 0) dbmp->di_size = n - RARRAY(ary)->len;
return obj;
}
static VALUE
-fdbm_clear(VALUE obj)
+fdbm_clear(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -381,7 +439,8 @@ fdbm_clear(VALUE obj)
}
static VALUE
-fdbm_invert(VALUE obj)
+fdbm_invert(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -399,36 +458,49 @@ fdbm_invert(VALUE obj)
return hash;
}
-static VALUE fdbm_store(VALUE,VALUE,VALUE);
+static VALUE each_pair _((VALUE));
+
+static VALUE
+each_pair(obj)
+ VALUE obj;
+{
+ return rb_funcall(obj, rb_intern("each_pair"), 0, 0);
+}
+
+static VALUE fdbm_store _((VALUE,VALUE,VALUE));
static VALUE
-update_i(VALUE pair, VALUE dbm)
+update_i(pair, dbm)
+ VALUE pair, dbm;
{
Check_Type(pair, T_ARRAY);
- if (RARRAY_LEN(pair) < 2) {
+ if (RARRAY(pair)->len < 2) {
rb_raise(rb_eArgError, "pair must be [key, value]");
}
- fdbm_store(dbm, RARRAY_PTR(pair)[0], RARRAY_PTR(pair)[1]);
+ fdbm_store(dbm, RARRAY(pair)->ptr[0], RARRAY(pair)->ptr[1]);
return Qnil;
}
static VALUE
-fdbm_update(VALUE obj, VALUE other)
+fdbm_update(obj, other)
+ VALUE obj, other;
{
- rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
+ rb_iterate(each_pair, other, update_i, obj);
return obj;
}
static VALUE
-fdbm_replace(VALUE obj, VALUE other)
+fdbm_replace(obj, other)
+ VALUE obj, other;
{
fdbm_clear(obj);
- rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
+ rb_iterate(each_pair, other, update_i, obj);
return obj;
}
static VALUE
-fdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
+fdbm_store(obj, keystr, valstr)
+ VALUE obj, keystr, valstr;
{
datum key, val;
struct dbmdata *dbmp;
@@ -438,11 +510,11 @@ fdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
keystr = rb_obj_as_string(keystr);
valstr = rb_obj_as_string(valstr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
- val.dptr = RSTRING_PTR(valstr);
- val.dsize = RSTRING_LEN(valstr);
+ val.dptr = RSTRING(valstr)->ptr;
+ val.dsize = RSTRING(valstr)->len;
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
@@ -458,7 +530,8 @@ fdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
}
static VALUE
-fdbm_length(VALUE obj)
+fdbm_length(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -477,7 +550,8 @@ fdbm_length(VALUE obj)
}
static VALUE
-fdbm_empty_p(VALUE obj)
+fdbm_empty_p(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -500,7 +574,8 @@ fdbm_empty_p(VALUE obj)
}
static VALUE
-fdbm_each_value(VALUE obj)
+fdbm_each_value(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -516,7 +591,8 @@ fdbm_each_value(VALUE obj)
}
static VALUE
-fdbm_each_key(VALUE obj)
+fdbm_each_key(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -531,7 +607,8 @@ fdbm_each_key(VALUE obj)
}
static VALUE
-fdbm_each_pair(VALUE obj)
+fdbm_each_pair(obj)
+ VALUE obj;
{
datum key, val;
DBM *dbm;
@@ -552,7 +629,8 @@ fdbm_each_pair(VALUE obj)
}
static VALUE
-fdbm_keys(VALUE obj)
+fdbm_keys(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -570,7 +648,8 @@ fdbm_keys(VALUE obj)
}
static VALUE
-fdbm_values(VALUE obj)
+fdbm_values(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -588,15 +667,16 @@ fdbm_values(VALUE obj)
}
static VALUE
-fdbm_has_key(VALUE obj, VALUE keystr)
+fdbm_has_key(obj, keystr)
+ VALUE obj, keystr;
{
datum key, val;
struct dbmdata *dbmp;
DBM *dbm;
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
GetDBM2(obj, dbmp, dbm);
val = dbm_fetch(dbm, key);
@@ -605,28 +685,30 @@ fdbm_has_key(VALUE obj, VALUE keystr)
}
static VALUE
-fdbm_has_value(VALUE obj, VALUE valstr)
+fdbm_has_value(obj, valstr)
+ VALUE obj, valstr;
{
datum key, val;
struct dbmdata *dbmp;
DBM *dbm;
StringValue(valstr);
- val.dptr = RSTRING_PTR(valstr);
- val.dsize = RSTRING_LEN(valstr);
+ val.dptr = RSTRING(valstr)->ptr;
+ val.dsize = RSTRING(valstr)->len;
GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
- if (val.dsize == RSTRING_LEN(valstr) &&
- memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0)
+ if (val.dsize == RSTRING(valstr)->len &&
+ memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0)
return Qtrue;
}
return Qfalse;
}
static VALUE
-fdbm_to_a(VALUE obj)
+fdbm_to_a(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -645,7 +727,8 @@ fdbm_to_a(VALUE obj)
}
static VALUE
-fdbm_to_hash(VALUE obj)
+fdbm_to_hash(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -664,13 +747,14 @@ fdbm_to_hash(VALUE obj)
}
static VALUE
-fdbm_reject(VALUE obj)
+fdbm_reject(obj)
+ VALUE obj;
{
return rb_hash_delete_if(fdbm_to_hash(obj));
}
void
-Init_dbm(void)
+Init_dbm()
{
rb_cDBM = rb_define_class("DBM", rb_cObject);
rb_eDBMError = rb_define_class("DBMError", rb_eStandardError);
@@ -687,7 +771,9 @@ Init_dbm(void)
rb_define_method(rb_cDBM, "[]=", fdbm_store, 2);
rb_define_method(rb_cDBM, "store", fdbm_store, 2);
rb_define_method(rb_cDBM, "index", fdbm_index, 1);
- rb_define_method(rb_cDBM, "select", fdbm_select, 0);
+ rb_define_method(rb_cDBM, "indexes", fdbm_indexes, -1);
+ rb_define_method(rb_cDBM, "indices", fdbm_indexes, -1);
+ rb_define_method(rb_cDBM, "select", fdbm_select, -1);
rb_define_method(rb_cDBM, "values_at", fdbm_values_at, -1);
rb_define_method(rb_cDBM, "length", fdbm_length, 0);
rb_define_method(rb_cDBM, "size", fdbm_length, 0);
@@ -726,7 +812,5 @@ Init_dbm(void)
#ifdef DB_VERSION_STRING
rb_define_const(rb_cDBM, "VERSION", rb_str_new2(DB_VERSION_STRING));
-#else
- rb_define_const(rb_cDBM, "VERSION", rb_str_new2("unknown"));
#endif
}
diff --git a/ext/digest/.cvsignore b/ext/digest/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/digest/.cvsignore
+++ b/ext/digest/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/digest/bubblebabble/.cvsignore b/ext/digest/bubblebabble/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/digest/bubblebabble/.cvsignore
+++ b/ext/digest/bubblebabble/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index c4a58cf3f6..0b910e8c47 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()", rb_inspect(self));
+ rb_raise(rb_eRuntimeError, "%s does not implement update()", RSTRING_PTR(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()", rb_inspect(self));
+ rb_raise(rb_eRuntimeError, "%s does not implement finish()", RSTRING_PTR(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()", rb_inspect(self));
+ rb_raise(rb_eRuntimeError, "%s does not implement reset()", RSTRING_PTR(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()", rb_inspect(self));
+ rb_raise(rb_eRuntimeError, "%s does not implement block_length()", RSTRING_PTR(rb_inspect(self)));
}
/*
@@ -381,7 +381,6 @@ static VALUE
rb_digest_class_s_digest(int argc, VALUE *argv, VALUE klass)
{
VALUE str;
- void *pctx;
volatile VALUE obj;
if (argc < 1) {
@@ -423,15 +422,19 @@ rb_digest_class_s_hexdigest(int argc, VALUE *argv, VALUE klass)
static rb_digest_metadata_t *
get_digest_base_metadata(VALUE klass)
{
+ VALUE p;
VALUE obj;
rb_digest_metadata_t *algo;
- if (rb_ivar_defined(klass, id_metadata) == Qfalse) {
- /* This class should not be subclassed in Ruby */
- rb_notimplement();
+ for (p = klass; p; p = RCLASS(p)->super) {
+ if (rb_ivar_defined(p, id_metadata)) {
+ obj = rb_ivar_get(p, id_metadata);
+ break;
+ }
}
- obj = rb_ivar_get(klass, id_metadata);
+ if (!p)
+ rb_raise(rb_eRuntimeError, "Digest::Base cannot be directly inherited in Ruby");
Data_Get_Struct(obj, rb_digest_metadata_t, algo);
@@ -519,7 +522,7 @@ rb_digest_base_update(VALUE self, VALUE str)
Data_Get_Struct(self, void, pctx);
StringValue(str);
- algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
+ algo->update_func(pctx, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
return self;
}
@@ -537,7 +540,7 @@ rb_digest_base_finish(VALUE self)
Data_Get_Struct(self, void, pctx);
str = rb_str_new(0, algo->digest_len);
- algo->finish_func(pctx, RSTRING_PTR(str));
+ algo->finish_func(pctx, (unsigned char *)RSTRING_PTR(str));
/* avoid potential coredump caused by use of a finished context */
algo->init_func(pctx);
diff --git a/ext/digest/lib/digest.rb b/ext/digest/lib/digest.rb
index a56d47551b..0c4ee3c2cc 100644
--- a/ext/digest/lib/digest.rb
+++ b/ext/digest/lib/digest.rb
@@ -1,19 +1,23 @@
require 'digest.so'
module Digest
- autoload "SHA256", "digest/sha2.so"
- autoload "SHA384", "digest/sha2.so"
- autoload "SHA512", "digest/sha2.so"
-
def self.const_missing(name)
- begin
- require File.join('digest', name.downcase)
+ case name
+ when :SHA256, :SHA384, :SHA512
+ lib = 'digest/sha2.so'
+ else
+ lib = File.join('digest', name.to_s.downcase)
+ end
- return Digest.const_get(name) if Digest.const_defined?(name)
+ begin
+ require lib
rescue LoadError => e
+ raise LoadError, "library not found for class Digest::#{name} -- #{lib}", caller(1)
end
-
- raise NameError, "Digest class not found: Digest::#{name}"
+ unless Digest.const_defined?(name)
+ raise NameError, "uninitialized constant Digest::#{name}", caller(1)
+ end
+ Digest.const_get(name)
end
class ::Digest::Class
diff --git a/ext/digest/lib/digest/hmac.rb b/ext/digest/lib/digest/hmac.rb
deleted file mode 100644
index 0aeb6a8b48..0000000000
--- a/ext/digest/lib/digest/hmac.rb
+++ /dev/null
@@ -1,269 +0,0 @@
-# = digest/hmac.rb
-#
-# An implementation of HMAC keyed-hashing algorithm
-#
-# == Overview
-#
-# This library adds a method named hmac() to Digest classes, which
-# creates a Digest class for calculating HMAC digests.
-#
-# == Examples
-#
-# require 'digest/hmac'
-#
-# # one-liner example
-# puts Digest::HMAC.hexdigest("data", "hash key", Digest::SHA1)
-#
-# # rather longer one
-# hmac = Digest::HMAC.new("foo", Digest::RMD160)
-#
-# buf = ""
-# while stream.read(16384, buf)
-# hmac.update(buf)
-# end
-#
-# puts hmac.bubblebabble
-#
-# == License
-#
-# Copyright (c) 2006 Akinori MUSHA <knu@iDaemons.org>
-#
-# Documentation by Akinori MUSHA
-#
-# All rights reserved. You can redistribute and/or modify it under
-# the same terms as Ruby.
-#
-# $Id$
-#
-
-require 'digest'
-
-module Digest
- class HMAC < Digest::Class
- def initialize(key, digester)
- @md = digester.new
-
- block_len = @md.block_length
-
- if key.length > block_len
- key = @md.digest(key)
- end
-
- ipad = Array.new(block_len).fill(0x36)
- opad = Array.new(block_len).fill(0x5c)
-
- key.bytes.each_with_index { |c, i|
- ipad[i] ^= c
- opad[i] ^= c
- }
-
- @key = key.freeze
- @ipad = ipad.inject('') { |s, c| s << c.chr }.freeze
- @opad = opad.inject('') { |s, c| s << c.chr }.freeze
- end
-
- def initialize_copy(other)
- @md = other.instance_eval { @md.clone }
- end
-
- def update(text)
- # @md is reset when digest() returns
- @md.update(@opad + @md.digest(@ipad + text))
- self
- end
-
- def reset
- @md.reset
- self
- end
-
- def finish
- @md.digest!
- end
- private :finish
-
- def digest_length
- @md.digest_length
- end
-
- def block_length
- @md.block_length
- end
-
- def inspect
- sprintf('#<%s: key=%s, digest=%s>', self.class.name, @key.inspect, @md.inspect.sub(/^\#<(.*)>$/) { $1 });
- end
- end
-end
-
-if $0 == __FILE__
- eval DATA.read, nil, $0, __LINE__+4
-end
-
-__END__
-
-require 'test/unit'
-
-module TM_HMAC
- def test_s_hexdigest
- cases.each { |h|
- digesters.each { |d|
- assert_equal(h[:hexdigest], Digest::HMAC.hexdigest(h[:data], h[:key], d))
- }
- }
- end
-
- def test_hexdigest
- cases.each { |h|
- digesters.each { |d|
- hmac = Digest::HMAC.new(h[:key], d)
-
- hmac.update(h[:data])
-
- assert_equal(h[:hexdigest], hmac.hexdigest)
- }
- }
- end
-
- def test_reset
- cases.each { |h|
- digesters.each { |d|
- hmac = Digest::HMAC.new(h[:key], d)
- hmac.update("test")
- hmac.reset
- hmac.update(h[:data])
-
- assert_equal(h[:hexdigest], hmac.hexdigest)
- }
- }
- end
-end
-
-class TC_HMAC_MD5 < Test::Unit::TestCase
- include TM_HMAC
-
- def digesters
- [Digest::MD5, Digest::MD5.new]
- end
-
- # Taken from RFC 2202: Test Cases for HMAC-MD5 and HMAC-SHA-1
- def cases
- [
- {
- :key => "\x0b" * 16,
- :data => "Hi There",
- :hexdigest => "9294727a3638bb1c13f48ef8158bfc9d",
- }, {
- :key => "Jefe",
- :data => "what do ya want for nothing?",
- :hexdigest => "750c783e6ab0b503eaa86e310a5db738",
- }, {
- :key => "\xaa" * 16,
- :data => "\xdd" * 50,
- :hexdigest => "56be34521d144c88dbb8c733f0e8b3f6",
- }, {
- :key => "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
- :data => "\xcd" * 50,
- :hexdigest => "697eaf0aca3a3aea3a75164746ffaa79",
- }, {
- :key => "\x0c" * 16,
- :data => "Test With Truncation",
- :hexdigest => "56461ef2342edc00f9bab995690efd4c",
- }, {
- :key => "\xaa" * 80,
- :data => "Test Using Larger Than Block-Size Key - Hash Key First",
- :hexdigest => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd",
- }, {
- :key => "\xaa" * 80,
- :data => "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
- :hexdigest => "6f630fad67cda0ee1fb1f562db3aa53e",
- }
- ]
- end
-end
-
-class TC_HMAC_SHA1 < Test::Unit::TestCase
- include TM_HMAC
-
- def digesters
- [Digest::SHA1, Digest::SHA1.new]
- end
-
- # Taken from RFC 2202: Test Cases for HMAC-MD5 and HMAC-SHA-1
- def cases
- [
- {
- :key => "\x0b" * 20,
- :data => "Hi There",
- :hexdigest => "b617318655057264e28bc0b6fb378c8ef146be00",
- }, {
- :key => "Jefe",
- :data => "what do ya want for nothing?",
- :hexdigest => "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79",
- }, {
- :key => "\xaa" * 20,
- :data => "\xdd" * 50,
- :hexdigest => "125d7342b9ac11cd91a39af48aa17b4f63f175d3",
- }, {
- :key => "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
- :data => "\xcd" * 50,
- :hexdigest => "4c9007f4026250c6bc8414f9bf50c86c2d7235da",
- }, {
- :key => "\x0c" * 20,
- :data => "Test With Truncation",
- :hexdigest => "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04",
- }, {
- :key => "\xaa" * 80,
- :data => "Test Using Larger Than Block-Size Key - Hash Key First",
- :hexdigest => "aa4ae5e15272d00e95705637ce8a3b55ed402112",
- }, {
- :key => "\xaa" * 80,
- :data => "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
- :hexdigest => "e8e99d0f45237d786d6bbaa7965c7808bbff1a91",
- }
- ]
- end
-end
-
-class TC_HMAC_RMD160 < Test::Unit::TestCase
- include TM_HMAC
-
- def digesters
- [Digest::RMD160, Digest::RMD160.new]
- end
-
- # Taken from RFC 2286: Test Cases for HMAC-RIPEMD160 and HMAC-RIPEMD128
- def cases
- [
- {
- :key => "\x0b" * 20,
- :data => "Hi There",
- :hexdigest => "24cb4bd67d20fc1a5d2ed7732dcc39377f0a5668",
- }, {
- :key => "Jefe",
- :data => "what do ya want for nothing?",
- :hexdigest => "dda6c0213a485a9e24f4742064a7f033b43c4069",
- }, {
- :key => "\xaa" * 20,
- :data => "\xdd" * 50,
- :hexdigest => "b0b105360de759960ab4f35298e116e295d8e7c1",
- }, {
- :key => "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
- :data => "\xcd" * 50,
- :hexdigest => "d5ca862f4d21d5e610e18b4cf1beb97a4365ecf4",
- }, {
- :key => "\x0c" * 20,
- :data => "Test With Truncation",
- :hexdigest => "7619693978f91d90539ae786500ff3d8e0518e39",
- }, {
- :key => "\xaa" * 80,
- :data => "Test Using Larger Than Block-Size Key - Hash Key First",
- :hexdigest => "6466ca07ac5eac29e1bd523e5ada7605b791fd8b",
- }, {
- :key => "\xaa" * 80,
- :data => "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
- :hexdigest => "69ea60798d71616cce5fd0871e23754cd75d5a0a",
- }
- ]
- end
-end
diff --git a/ext/digest/lib/md5.rb b/ext/digest/lib/md5.rb
new file mode 100644
index 0000000000..c399f2de1d
--- /dev/null
+++ b/ext/digest/lib/md5.rb
@@ -0,0 +1,23 @@
+# just for compatibility; requiring "md5" is obsoleted
+#
+# $RoughId: md5.rb,v 1.4 2001/07/13 15:38:27 knu Exp $
+# $Id$
+
+require 'digest/md5'
+
+class MD5 < Digest::MD5
+ class << self
+ alias orig_new new
+ def new(str = nil)
+ if str
+ orig_new.update(str)
+ else
+ orig_new
+ end
+ end
+
+ def md5(*args)
+ new(*args)
+ end
+ end
+end
diff --git a/ext/digest/lib/sha1.rb b/ext/digest/lib/sha1.rb
new file mode 100644
index 0000000000..4446e12e8d
--- /dev/null
+++ b/ext/digest/lib/sha1.rb
@@ -0,0 +1,23 @@
+# just for compatibility; requiring "sha1" is obsoleted
+#
+# $RoughId: sha1.rb,v 1.4 2001/07/13 15:38:27 knu Exp $
+# $Id$
+
+require 'digest/sha1'
+
+class SHA1 < Digest::SHA1
+ class << self
+ alias orig_new new
+ def new(str = nil)
+ if str
+ orig_new.update(str)
+ else
+ orig_new
+ end
+ end
+
+ def sha1(*args)
+ new(*args)
+ end
+ end
+end
diff --git a/ext/digest/md5/.cvsignore b/ext/digest/md5/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/digest/md5/.cvsignore
+++ b/ext/digest/md5/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/digest/rmd160/.cvsignore b/ext/digest/rmd160/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/digest/rmd160/.cvsignore
+++ b/ext/digest/rmd160/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/digest/rmd160/rmd160ossl.c b/ext/digest/rmd160/rmd160ossl.c
index 5d8c5ba470..f24e63e3d8 100644
--- a/ext/digest/rmd160/rmd160ossl.c
+++ b/ext/digest/rmd160/rmd160ossl.c
@@ -4,5 +4,5 @@
#include "rmd160ossl.h"
void RMD160_Finish(RMD160_CTX *ctx, char *buf) {
- RIPEMD160_Final(buf, ctx);
+ RIPEMD160_Final((unsigned char *)buf, ctx);
}
diff --git a/ext/digest/sha1/.cvsignore b/ext/digest/sha1/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/digest/sha1/.cvsignore
+++ b/ext/digest/sha1/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/digest/sha1/sha1ossl.c b/ext/digest/sha1/sha1ossl.c
index adf5cf267c..452cf35084 100644
--- a/ext/digest/sha1/sha1ossl.c
+++ b/ext/digest/sha1/sha1ossl.c
@@ -6,5 +6,5 @@
void
SHA1_Finish(SHA1_CTX *ctx, char *buf)
{
- SHA1_Final(buf, ctx);
+ SHA1_Final((unsigned char *)buf, ctx);
}
diff --git a/ext/digest/sha2/.cvsignore b/ext/digest/sha2/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/digest/sha2/.cvsignore
+++ b/ext/digest/sha2/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/digest/sha2/lib/digest/sha2.rb b/ext/digest/sha2/lib/sha2.rb
index 52dd639f9b..52dd639f9b 100644
--- a/ext/digest/sha2/lib/digest/sha2.rb
+++ b/ext/digest/sha2/lib/sha2.rb
diff --git a/ext/dl/.cvsignore b/ext/dl/.cvsignore
index 6c0b25a1c5..6d884b6cec 100644
--- a/ext/dl/.cvsignore
+++ b/ext/dl/.cvsignore
@@ -2,9 +2,7 @@ Makefile
mkmf.log
dlconfig.h
dlconfig.rb
-callback.h
*.func
*.o
*~
*.def
-extconf.h
diff --git a/ext/dl/cfunc.c b/ext/dl/cfunc.c
deleted file mode 100644
index 253c78f2b1..0000000000
--- a/ext/dl/cfunc.c
+++ /dev/null
@@ -1,509 +0,0 @@
-/* -*- C -*-
- * $Id$
- */
-
-#include <ruby.h>
-#include <errno.h>
-#include "dl.h"
-
-VALUE rb_cDLCFunc;
-
-static ID id_last_error;
-
-static VALUE
-rb_dl_get_last_error(VALUE self)
-{
- return rb_thread_local_aref(rb_thread_current(), id_last_error);
-}
-
-static VALUE
-rb_dl_set_last_error(VALUE self, VALUE val)
-{
- rb_thread_local_aset(rb_thread_current(), id_last_error, val);
- return Qnil;
-}
-
-#if defined(HAVE_WINDOWS_H)
-#include <windows.h>
-static ID id_win32_last_error;
-
-static VALUE
-rb_dl_get_win32_last_error(VALUE self)
-{
- return rb_thread_local_aref(rb_thread_current(), id_win32_last_error);
-}
-
-static VALUE
-rb_dl_set_win32_last_error(VALUE self, VALUE val)
-{
- rb_thread_local_aset(rb_thread_current(), id_win32_last_error, val);
- return Qnil;
-}
-#endif
-
-
-void
-dlcfunc_free(struct cfunc_data *data)
-{
- if( data->name ){
- xfree(data->name);
- }
- xfree(data);
-}
-
-VALUE
-rb_dlcfunc_new(void (*func)(), int type, const char *name, ID calltype)
-{
- VALUE val;
- struct cfunc_data *data;
-
- rb_secure(4);
- if( func ){
- val = Data_Make_Struct(rb_cDLCFunc, struct cfunc_data, 0, dlcfunc_free, data);
- data->ptr = func;
- data->name = name ? strdup(name) : NULL;
- data->type = type;
- data->calltype = calltype;
- }
- else{
- val = Qnil;
- }
-
- return val;
-}
-
-void *
-rb_dlcfunc2ptr(VALUE val)
-{
- struct cfunc_data *data;
- void * func;
-
- if( rb_obj_is_kind_of(val, rb_cDLCFunc) ){
- Data_Get_Struct(val, struct cfunc_data, data);
- func = data->ptr;
- }
- else if( val == Qnil ){
- func = NULL;
- }
- else{
- rb_raise(rb_eTypeError, "DL::CFunc was expected");
- }
-
- return func;
-}
-
-VALUE
-rb_dlcfunc_s_allocate(VALUE klass)
-{
- VALUE obj;
- struct cfunc_data *data;
-
- obj = Data_Make_Struct(klass, struct cfunc_data, 0, dlcfunc_free, data);
- data->ptr = 0;
- data->name = 0;
- data->type = 0;
- data->calltype = CFUNC_CDECL;
-
- return obj;
-}
-
-VALUE
-rb_dlcfunc_initialize(int argc, VALUE argv[], VALUE self)
-{
- VALUE addr, name, type, calltype;
- struct cfunc_data *data;
- void *saddr;
- const char *sname;
-
- rb_scan_args(argc, argv, "13", &addr, &type, &name, &calltype);
-
- saddr = (void*)(NUM2PTR(rb_Integer(addr)));
- sname = NIL_P(name) ? NULL : StringValuePtr(name);
-
- Data_Get_Struct(self, struct cfunc_data, data);
- if( data->name ) xfree(data->name);
- data->ptr = saddr;
- data->name = sname ? strdup(sname) : 0;
- data->type = (type == Qnil) ? DLTYPE_VOID : NUM2INT(type);
- data->calltype = (calltype == Qnil) ? CFUNC_CDECL : SYM2ID(calltype);
-
- return Qnil;
-}
-
-VALUE
-rb_dlcfunc_name(VALUE self)
-{
- struct cfunc_data *cfunc;
-
- Data_Get_Struct(self, struct cfunc_data, cfunc);
- return cfunc->name ? rb_tainted_str_new2(cfunc->name) : Qnil;
-}
-
-VALUE
-rb_dlcfunc_ctype(VALUE self)
-{
- struct cfunc_data *cfunc;
-
- Data_Get_Struct(self, struct cfunc_data, cfunc);
- return INT2NUM(cfunc->type);
-}
-
-VALUE
-rb_dlcfunc_set_ctype(VALUE self, VALUE ctype)
-{
- struct cfunc_data *cfunc;
-
- Data_Get_Struct(self, struct cfunc_data, cfunc);
- cfunc->type = NUM2INT(ctype);
- return ctype;
-}
-
-VALUE
-rb_dlcfunc_calltype(VALUE self)
-{
- struct cfunc_data *cfunc;
-
- Data_Get_Struct(self, struct cfunc_data, cfunc);
- return ID2SYM(cfunc->calltype);
-}
-
-VALUE
-rb_dlcfunc_set_calltype(VALUE self, VALUE sym)
-{
- struct cfunc_data *cfunc;
-
- Data_Get_Struct(self, struct cfunc_data, cfunc);
- cfunc->calltype = SYM2ID(sym);
- return sym;
-}
-
-
-VALUE
-rb_dlcfunc_ptr(VALUE self)
-{
- struct cfunc_data *cfunc;
-
- Data_Get_Struct(self, struct cfunc_data, cfunc);
- return PTR2NUM(cfunc->ptr);
-}
-
-VALUE
-rb_dlcfunc_set_ptr(VALUE self, VALUE addr)
-{
- struct cfunc_data *cfunc;
-
- Data_Get_Struct(self, struct cfunc_data, cfunc);
- cfunc->ptr = NUM2PTR(addr);
-
- return Qnil;
-}
-
-VALUE
-rb_dlcfunc_inspect(VALUE self)
-{
- VALUE val;
- char *str;
- int str_size;
- struct cfunc_data *cfunc;
-
- Data_Get_Struct(self, struct cfunc_data, cfunc);
-
- str_size = (cfunc->name ? strlen(cfunc->name) : 0) + 100;
- str = ruby_xmalloc(str_size);
- snprintf(str, str_size - 1,
- "#<DL::CFunc:%p ptr=%p type=%d name='%s'>",
- cfunc,
- cfunc->ptr,
- cfunc->type,
- cfunc->name ? cfunc->name : "");
- val = rb_tainted_str_new2(str);
- ruby_xfree(str);
-
- return val;
-}
-
-
-# define DECL_FUNC_CDECL(f,ret,args) ret (FUNC_CDECL(*f))(args)
-# define DECL_FUNC_STDCALL(f,ret,args) ret (FUNC_STDCALL(*f))(args)
-
-#define CALL_CASE switch( RARRAY_LEN(ary) ){ \
- CASE(0); break; \
- CASE(1); break; CASE(2); break; CASE(3); break; CASE(4); break; CASE(5); break; \
- CASE(6); break; CASE(7); break; CASE(8); break; CASE(9); break; CASE(10);break; \
- CASE(11);break; CASE(12);break; CASE(13);break; CASE(14);break; CASE(15);break; \
- CASE(16);break; CASE(17);break; CASE(18);break; CASE(19);break; CASE(20);break; \
- default: rb_raise(rb_eArgError, "too many arguments"); \
-}
-
-
-VALUE
-rb_dlcfunc_call(VALUE self, VALUE ary)
-{
- struct cfunc_data *cfunc;
- int i;
- DLSTACK_TYPE stack[DLSTACK_SIZE];
- VALUE result = Qnil;
-
- rb_secure_update(self);
-
- memset(stack, 0, sizeof(DLSTACK_TYPE) * DLSTACK_SIZE);
- Check_Type(ary, T_ARRAY);
-
- Data_Get_Struct(self, struct cfunc_data, cfunc);
-
- if( cfunc->ptr == 0 ){
- rb_raise(rb_eDLError, "can't call null-function");
- return Qnil;
- }
-
- for( i = 0; i < RARRAY_LEN(ary); i++ ){
- if( i >= DLSTACK_SIZE ){
- rb_raise(rb_eDLError, "too many arguments (stack overflow)");
- }
- stack[i] = NUM2LONG(RARRAY_PTR(ary)[i]);
- }
-
- /* calltype == CFUNC_CDECL */
- if( cfunc->calltype == CFUNC_CDECL ){
- switch( cfunc->type ){
- case DLTYPE_VOID:
-#define CASE(n) case n: { \
- DECL_FUNC_CDECL(f,void,DLSTACK_PROTO##n) = cfunc->ptr; \
- f(DLSTACK_ARGS##n(stack)); \
- result = Qnil; \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_VOIDP:
-#define CASE(n) case n: { \
- DECL_FUNC_CDECL(f,void*,DLSTACK_PROTO##n) = cfunc->ptr; \
- void * ret; \
- ret = f(DLSTACK_ARGS##n(stack)); \
- result = PTR2NUM(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_CHAR:
-#define CASE(n) case n: { \
- DECL_FUNC_CDECL(f,char,DLSTACK_PROTO##n) = cfunc->ptr; \
- char ret; \
- ret = f(DLSTACK_ARGS##n(stack)); \
- result = CHR2FIX(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_SHORT:
-#define CASE(n) case n: { \
- DECL_FUNC_CDECL(f,short,DLSTACK_PROTO##n) = cfunc->ptr; \
- short ret; \
- ret = f(DLSTACK_ARGS##n(stack)); \
- result = INT2NUM((int)ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_INT:
-#define CASE(n) case n: { \
- DECL_FUNC_CDECL(f,int,DLSTACK_PROTO##n) = cfunc->ptr; \
- int ret; \
- ret = f(DLSTACK_ARGS##n(stack)); \
- result = INT2NUM(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_LONG:
-#define CASE(n) case n: { \
- DECL_FUNC_CDECL(f,long,DLSTACK_PROTO##n) = cfunc->ptr; \
- long ret; \
- ret = f(DLSTACK_ARGS##n(stack)); \
- result = LONG2NUM(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
-#if HAVE_LONG_LONG /* used in ruby.h */
- case DLTYPE_LONG_LONG:
-#define CASE(n) case n: { \
- DECL_FUNC_CDECL(f,LONG_LONG,DLSTACK_PROTO) = cfunc->ptr; \
- LONG_LONG ret; \
- ret = f(DLSTACK_ARGS(stack)); \
- result = LL2NUM(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
-#endif
- case DLTYPE_FLOAT:
-#define CASE(n) case n: { \
- DECL_FUNC_CDECL(f,float,DLSTACK_PROTO) = cfunc->ptr; \
- float ret; \
- ret = f(DLSTACK_ARGS(stack)); \
- result = rb_float_new(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_DOUBLE:
-#define CASE(n) case n: { \
- DECL_FUNC_CDECL(f,double,DLSTACK_PROTO) = cfunc->ptr; \
- double ret; \
- ret = f(DLSTACK_ARGS(stack)); \
- result = rb_float_new(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- default:
- rb_raise(rb_eDLTypeError, "unknown type %d", cfunc->type);
- }
- }
- else if( cfunc->calltype == CFUNC_STDCALL ){
- /* calltype == CFUNC_STDCALL */
- switch( cfunc->type ){
- case DLTYPE_VOID:
-#define CASE(n) case n: { \
- DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n) = cfunc->ptr; \
- f(DLSTACK_ARGS##n(stack)); \
- result = Qnil; \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_VOIDP:
-#define CASE(n) case n: { \
- DECL_FUNC_STDCALL(f,void*,DLSTACK_PROTO##n) = cfunc->ptr; \
- void * ret; \
- ret = f(DLSTACK_ARGS##n(stack)); \
- result = PTR2NUM(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_CHAR:
-#define CASE(n) case n: { \
- DECL_FUNC_STDCALL(f,char,DLSTACK_PROTO##n) = cfunc->ptr; \
- char ret; \
- ret = f(DLSTACK_ARGS##n(stack)); \
- result = CHR2FIX(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_SHORT:
-#define CASE(n) case n: { \
- DECL_FUNC_STDCALL(f,short,DLSTACK_PROTO##n) = cfunc->ptr; \
- short ret; \
- ret = f(DLSTACK_ARGS##n(stack)); \
- result = INT2NUM((int)ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_INT:
-#define CASE(n) case n: { \
- DECL_FUNC_STDCALL(f,int,DLSTACK_PROTO##n) = cfunc->ptr; \
- int ret; \
- ret = f(DLSTACK_ARGS##n(stack)); \
- result = INT2NUM(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_LONG:
-#define CASE(n) case n: { \
- DECL_FUNC_STDCALL(f,long,DLSTACK_PROTO##n) = cfunc->ptr; \
- long ret; \
- ret = f(DLSTACK_ARGS##n(stack)); \
- result = LONG2NUM(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
-#if HAVE_LONG_LONG /* used in ruby.h */
- case DLTYPE_LONG_LONG:
-#define CASE(n) case n: { \
- DECL_FUNC_STDCALL(f,LONG_LONG,DLSTACK_PROTO) = cfunc->ptr; \
- LONG_LONG ret; \
- ret = f(DLSTACK_ARGS(stack)); \
- result = LL2NUM(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
-#endif
- case DLTYPE_FLOAT:
-#define CASE(n) case n: { \
- DECL_FUNC_STDCALL(f,float,DLSTACK_PROTO) = cfunc->ptr; \
- float ret; \
- ret = f(DLSTACK_ARGS(stack)); \
- result = rb_float_new(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- case DLTYPE_DOUBLE:
-#define CASE(n) case n: { \
- DECL_FUNC_STDCALL(f,double,DLSTACK_PROTO) = cfunc->ptr; \
- double ret; \
- ret = f(DLSTACK_ARGS(stack)); \
- result = rb_float_new(ret); \
-}
- CALL_CASE;
-#undef CASE
- break;
- default:
- rb_raise(rb_eDLTypeError, "unknown type %d", cfunc->type);
- }
- }
- else{
- rb_raise(rb_eDLError, "unsupported call type: %x", cfunc->calltype);
- }
-
- rb_dl_set_last_error(self, INT2NUM(errno));
-#if defined(HAVE_WINDOWS_H)
- rb_dl_set_win32_last_error(self, INT2NUM(GetLastError()));
-#endif
-
- return result;
-}
-
-VALUE
-rb_dlcfunc_to_i(VALUE self)
-{
- struct cfunc_data *cfunc;
-
- Data_Get_Struct(self, struct cfunc_data, cfunc);
- return PTR2NUM(cfunc->ptr);
-}
-
-void
-Init_dlcfunc()
-{
- id_last_error = rb_intern("__DL2_LAST_ERROR__");
-#if defined(HAVE_WINDOWS_H)
- id_win32_last_error = rb_intern("__DL2_WIN32_LAST_ERROR__");
-#endif
- rb_cDLCFunc = rb_define_class_under(rb_mDL, "CFunc", rb_cObject);
- rb_define_alloc_func(rb_cDLCFunc, rb_dlcfunc_s_allocate);
- rb_define_module_function(rb_cDLCFunc, "last_error", rb_dl_get_last_error, 0);
-#if defined(HAVE_WINDOWS_H)
- rb_define_module_function(rb_cDLCFunc, "win32_last_error", rb_dl_get_win32_last_error, 0);
-#endif
- rb_define_method(rb_cDLCFunc, "initialize", rb_dlcfunc_initialize, -1);
- rb_define_method(rb_cDLCFunc, "call", rb_dlcfunc_call, 1);
- rb_define_method(rb_cDLCFunc, "[]", rb_dlcfunc_call, 1);
- rb_define_method(rb_cDLCFunc, "name", rb_dlcfunc_name, 0);
- rb_define_method(rb_cDLCFunc, "ctype", rb_dlcfunc_ctype, 0);
- rb_define_method(rb_cDLCFunc, "ctype=", rb_dlcfunc_set_ctype, 1);
- rb_define_method(rb_cDLCFunc, "calltype", rb_dlcfunc_calltype, 0);
- rb_define_method(rb_cDLCFunc, "calltype=", rb_dlcfunc_set_calltype, 1);
- rb_define_method(rb_cDLCFunc, "ptr", rb_dlcfunc_ptr, 0);
- rb_define_method(rb_cDLCFunc, "ptr=", rb_dlcfunc_set_ptr, 1);
- rb_define_method(rb_cDLCFunc, "inspect", rb_dlcfunc_inspect, 0);
- rb_define_method(rb_cDLCFunc, "to_s", rb_dlcfunc_inspect, 0);
- rb_define_method(rb_cDLCFunc, "to_i", rb_dlcfunc_to_i, 0);
-}
diff --git a/ext/dl/cptr.c b/ext/dl/cptr.c
deleted file mode 100644
index b947ef27ef..0000000000
--- a/ext/dl/cptr.c
+++ /dev/null
@@ -1,483 +0,0 @@
-/* -*- C -*-
- * $Id$
- */
-
-#include <ruby.h>
-#include <rubyio.h>
-#include <ctype.h>
-#include <version.h> /* for ruby version code */
-#include "dl.h"
-
-VALUE rb_cDLCPtr;
-
-static ID id_to_ptr;
-
-static void
-dlptr_free(struct ptr_data *data)
-{
- if (data->ptr) {
- if (data->free) {
- (*(data->free))(data->ptr);
- }
- }
-}
-
-static void
-dlptr_mark(struct ptr_data *data)
-{
-}
-
-void
-dlptr_init(VALUE val)
-{
- struct ptr_data *data;
-
- Data_Get_Struct(val, struct ptr_data, data);
- OBJ_TAINT(val);
-}
-
-VALUE
-rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func)
-{
- struct ptr_data *data;
- VALUE val;
-
- rb_secure(4);
- val = Data_Make_Struct(klass, struct ptr_data,
- 0, dlptr_free, data);
- data->ptr = ptr;
- data->free = func;
- data->size = size;
- dlptr_init(val);
-
- return val;
-}
-
-VALUE
-rb_dlptr_new(void *ptr, long size, freefunc_t func)
-{
- return rb_dlptr_new2(rb_cDLCPtr, ptr, size, func);
-}
-
-VALUE
-rb_dlptr_malloc(long size, freefunc_t func)
-{
- void *ptr;
-
- rb_secure(4);
- ptr = ruby_xmalloc((size_t)size);
- memset(ptr,0,(size_t)size);
- return rb_dlptr_new(ptr, size, func);
-}
-
-void *
-rb_dlptr2cptr(VALUE val)
-{
- struct ptr_data *data;
- void *ptr;
-
- if (rb_obj_is_kind_of(val, rb_cDLCPtr)) {
- Data_Get_Struct(val, struct ptr_data, data);
- ptr = data->ptr;
- }
- else if (val == Qnil) {
- ptr = NULL;
- }
- else{
- rb_raise(rb_eTypeError, "DL::PtrData was expected");
- }
-
- return ptr;
-}
-
-static VALUE
-rb_dlptr_s_allocate(VALUE klass)
-{
- VALUE obj;
- struct ptr_data *data;
-
- rb_secure(4);
- obj = Data_Make_Struct(klass, struct ptr_data, dlptr_mark, dlptr_free, data);
- data->ptr = 0;
- data->size = 0;
- data->free = 0;
-
- return obj;
-}
-
-static VALUE
-rb_dlptr_initialize(int argc, VALUE argv[], VALUE self)
-{
- VALUE ptr, sym, size;
- struct ptr_data *data;
- void *p = NULL;
- freefunc_t f = NULL;
- long s = 0;
-
- switch (rb_scan_args(argc, argv, "12", &ptr, &size, &sym)) {
- case 1:
- p = (void*)(NUM2PTR(rb_Integer(ptr)));
- break;
- case 2:
- p = (void*)(NUM2PTR(rb_Integer(ptr)));
- s = NUM2LONG(size);
- break;
- case 3:
- p = (void*)(NUM2PTR(rb_Integer(ptr)));
- s = NUM2LONG(size);
- f = NIL_P(sym) ? NULL : RCFUNC_DATA(sym)->ptr;
- break;
- default:
- rb_bug("rb_dlptr_initialize");
- }
-
- if (p) {
- Data_Get_Struct(self, struct ptr_data, data);
- if (data->ptr && data->free) {
- /* Free previous memory. Use of inappropriate initialize may cause SEGV. */
- (*(data->free))(data->ptr);
- }
- data->ptr = p;
- data->size = s;
- data->free = f;
- }
-
- return Qnil;
-}
-
-static VALUE
-rb_dlptr_s_malloc(int argc, VALUE argv[], VALUE klass)
-{
- VALUE size, sym, obj;
- int s;
- freefunc_t f;
-
- switch (rb_scan_args(argc, argv, "11", &size, &sym)) {
- case 1:
- s = NUM2LONG(size);
- f = NULL;
- break;
- case 2:
- s = NUM2LONG(size);
- f = RCFUNC_DATA(sym)->ptr;
- break;
- default:
- rb_bug("rb_dlptr_s_malloc");
- }
-
- obj = rb_dlptr_malloc(s,f);
-
- return obj;
-}
-
-VALUE
-rb_dlptr_to_i(VALUE self)
-{
- struct ptr_data *data;
-
- Data_Get_Struct(self, struct ptr_data, data);
- return PTR2NUM(data->ptr);
-}
-
-VALUE
-rb_dlptr_to_value(VALUE self)
-{
- struct ptr_data *data;
- Data_Get_Struct(self, struct ptr_data, data);
- return (VALUE)(data->ptr);
-}
-
-VALUE
-rb_dlptr_ptr(VALUE self)
-{
- struct ptr_data *data;
-
- Data_Get_Struct(self, struct ptr_data, data);
- return rb_dlptr_new(*((void**)(data->ptr)),0,0);
-}
-
-VALUE
-rb_dlptr_ref(VALUE self)
-{
- struct ptr_data *data;
-
- Data_Get_Struct(self, struct ptr_data, data);
- return rb_dlptr_new(&(data->ptr),0,0);
-}
-
-VALUE
-rb_dlptr_null_p(VALUE self)
-{
- struct ptr_data *data;
-
- Data_Get_Struct(self, struct ptr_data, data);
- return data->ptr ? Qfalse : Qtrue;
-}
-
-VALUE
-rb_dlptr_free_set(VALUE self, VALUE val)
-{
- struct ptr_data *data;
- extern VALUE rb_cDLCFunc;
-
- Data_Get_Struct(self, struct ptr_data, data);
- if( rb_obj_is_kind_of(val, rb_cDLCFunc) == Qtrue ){
- data->free = RCFUNC_DATA(val)->ptr;
- }
- else{
- data->free = NUM2PTR(rb_Integer(val));
- }
-
- return Qnil;
-}
-
-VALUE
-rb_dlptr_free_get(VALUE self)
-{
- struct ptr_data *pdata;
-
- Data_Get_Struct(self, struct ptr_data, pdata);
-
- return rb_dlcfunc_new(pdata->free, DLTYPE_VOID, "free<anonymous>", CFUNC_CDECL);
-}
-
-VALUE
-rb_dlptr_to_s(int argc, VALUE argv[], VALUE self)
-{
- struct ptr_data *data;
- VALUE arg1, val;
- int len;
-
- Data_Get_Struct(self, struct ptr_data, data);
- switch (rb_scan_args(argc, argv, "01", &arg1)) {
- case 0:
- val = rb_tainted_str_new2((char*)(data->ptr));
- break;
- case 1:
- len = NUM2INT(arg1);
- val = rb_tainted_str_new((char*)(data->ptr), len);
- break;
- default:
- rb_bug("rb_dlptr_to_s");
- }
-
- return val;
-}
-
-VALUE
-rb_dlptr_to_str(int argc, VALUE argv[], VALUE self)
-{
- struct ptr_data *data;
- VALUE arg1, val;
- int len;
-
- Data_Get_Struct(self, struct ptr_data, data);
- switch (rb_scan_args(argc, argv, "01", &arg1)) {
- case 0:
- val = rb_tainted_str_new((char*)(data->ptr),data->size);
- break;
- case 1:
- len = NUM2INT(arg1);
- val = rb_tainted_str_new((char*)(data->ptr), len);
- break;
- default:
- rb_bug("rb_dlptr_to_str");
- }
-
- return val;
-}
-
-VALUE
-rb_dlptr_inspect(VALUE self)
-{
- struct ptr_data *data;
- char str[1024];
-
- Data_Get_Struct(self, struct ptr_data, data);
- snprintf(str, 1023, "#<%s:%p ptr=%p size=%ld free=%p>",
- rb_class2name(CLASS_OF(self)), data, data->ptr, data->size, data->free);
- return rb_str_new2(str);
-}
-
-VALUE
-rb_dlptr_eql(VALUE self, VALUE other)
-{
- void *ptr1, *ptr2;
- ptr1 = rb_dlptr2cptr(self);
- ptr2 = rb_dlptr2cptr(other);
-
- return ptr1 == ptr2 ? Qtrue : Qfalse;
-}
-
-VALUE
-rb_dlptr_cmp(VALUE self, VALUE other)
-{
- void *ptr1, *ptr2;
- ptr1 = rb_dlptr2cptr(self);
- ptr2 = rb_dlptr2cptr(other);
- return PTR2NUM((long)ptr1 - (long)ptr2);
-}
-
-VALUE
-rb_dlptr_plus(VALUE self, VALUE other)
-{
- void *ptr;
- long num, size;
-
- ptr = rb_dlptr2cptr(self);
- size = RPTR_DATA(self)->size;
- num = NUM2LONG(other);
- return rb_dlptr_new((char *)ptr + num, size - num, 0);
-}
-
-VALUE
-rb_dlptr_minus(VALUE self, VALUE other)
-{
- void *ptr;
- long num, size;
-
- ptr = rb_dlptr2cptr(self);
- size = RPTR_DATA(self)->size;
- num = NUM2LONG(other);
- return rb_dlptr_new((char *)ptr - num, size + num, 0);
-}
-
-VALUE
-rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
-{
- VALUE arg0, arg1;
- VALUE retval = Qnil;
- size_t offset, len;
-
- switch( rb_scan_args(argc, argv, "11", &arg0, &arg1) ){
- case 1:
- offset = NUM2ULONG(arg0);
- retval = INT2NUM(*((char*)RPTR_DATA(self)->ptr + offset));
- break;
- case 2:
- offset = NUM2ULONG(arg0);
- len = NUM2ULONG(arg1);
- retval = rb_tainted_str_new((char *)RPTR_DATA(self)->ptr + offset, len);
- break;
- default:
- rb_bug("rb_dlptr_aref()");
- }
- return retval;
-}
-
-VALUE
-rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
-{
- VALUE arg0, arg1, arg2;
- VALUE retval = Qnil;
- size_t offset, len;
- void *mem;
-
- switch( rb_scan_args(argc, argv, "21", &arg0, &arg1, &arg2) ){
- case 2:
- offset = NUM2ULONG(arg0);
- ((char*)RPTR_DATA(self)->ptr)[offset] = NUM2UINT(arg1);
- retval = arg1;
- break;
- case 3:
- offset = NUM2ULONG(arg0);
- len = NUM2ULONG(arg1);
- if( TYPE(arg2) == T_STRING ){
- mem = StringValuePtr(arg2);
- }
- else if( rb_obj_is_kind_of(arg2, rb_cDLCPtr) ){
- mem = rb_dlptr2cptr(arg2);
- }
- else{
- mem = NUM2PTR(arg2);
- }
- memcpy((char *)RPTR_DATA(self)->ptr + offset, mem, len);
- retval = arg2;
- break;
- default:
- rb_bug("rb_dlptr_aset()");
- }
- return retval;
-}
-
-VALUE
-rb_dlptr_size(int argc, VALUE argv[], VALUE self)
-{
- VALUE size;
-
- if (rb_scan_args(argc, argv, "01", &size) == 0){
- return LONG2NUM(RPTR_DATA(self)->size);
- }
- else{
- RPTR_DATA(self)->size = NUM2LONG(size);
- return size;
- }
-}
-
-VALUE
-rb_dlptr_s_to_ptr(VALUE self, VALUE val)
-{
- if( rb_obj_is_kind_of(val, rb_cIO) == Qtrue ){
- OpenFile *fptr;
- FILE *fp;
- GetOpenFile(val, fptr);
-#if RUBY_VERSION_CODE >= 190
- fp = rb_io_stdio_file(fptr);
-#else
- fp = fptr->f;
-#endif
- return rb_dlptr_new(fp, 0, NULL);
- }
- else if( rb_obj_is_kind_of(val, rb_cString) == Qtrue ){
- char *ptr = StringValuePtr(val);
- return rb_dlptr_new(ptr, RSTRING_LEN(val), NULL);
- }
- else if( rb_respond_to(val, id_to_ptr) ){
- VALUE vptr = rb_funcall(val, id_to_ptr, 0);
- if( rb_obj_is_kind_of(vptr, rb_cDLCPtr) ){
- return vptr;
- }
- else{
- rb_raise(rb_eDLError, "to_ptr should return a CPtr object");
- }
- }
- else{
- return rb_dlptr_new(NUM2PTR(rb_Integer(val)), 0, NULL);
- }
-}
-
-void
-Init_dlptr()
-{
- id_to_ptr = rb_intern("to_ptr");
-
- rb_cDLCPtr = rb_define_class_under(rb_mDL, "CPtr", rb_cObject);
- rb_define_alloc_func(rb_cDLCPtr, rb_dlptr_s_allocate);
- rb_define_singleton_method(rb_cDLCPtr, "malloc", rb_dlptr_s_malloc, -1);
- rb_define_singleton_method(rb_cDLCPtr, "to_ptr", rb_dlptr_s_to_ptr, 1);
- rb_define_singleton_method(rb_cDLCPtr, "[]", rb_dlptr_s_to_ptr, 1);
- rb_define_method(rb_cDLCPtr, "initialize", rb_dlptr_initialize, -1);
- rb_define_method(rb_cDLCPtr, "free=", rb_dlptr_free_set, 1);
- rb_define_method(rb_cDLCPtr, "free", rb_dlptr_free_get, 0);
- rb_define_method(rb_cDLCPtr, "to_i", rb_dlptr_to_i, 0);
- rb_define_method(rb_cDLCPtr, "to_value", rb_dlptr_to_value, 0);
- rb_define_method(rb_cDLCPtr, "ptr", rb_dlptr_ptr, 0);
- rb_define_method(rb_cDLCPtr, "+@", rb_dlptr_ptr, 0);
- rb_define_method(rb_cDLCPtr, "ref", rb_dlptr_ref, 0);
- rb_define_method(rb_cDLCPtr, "-@", rb_dlptr_ref, 0);
- rb_define_method(rb_cDLCPtr, "null?", rb_dlptr_null_p, 0);
- rb_define_method(rb_cDLCPtr, "to_s", rb_dlptr_to_s, -1);
- rb_define_method(rb_cDLCPtr, "to_str", rb_dlptr_to_str, -1);
- rb_define_method(rb_cDLCPtr, "inspect", rb_dlptr_inspect, 0);
- rb_define_method(rb_cDLCPtr, "<=>", rb_dlptr_cmp, 1);
- rb_define_method(rb_cDLCPtr, "==", rb_dlptr_eql, 1);
- rb_define_method(rb_cDLCPtr, "eql?", rb_dlptr_eql, 1);
- rb_define_method(rb_cDLCPtr, "+", rb_dlptr_plus, 1);
- rb_define_method(rb_cDLCPtr, "-", rb_dlptr_minus, 1);
- rb_define_method(rb_cDLCPtr, "[]", rb_dlptr_aref, -1);
- rb_define_method(rb_cDLCPtr, "[]=", rb_dlptr_aset, -1);
- rb_define_method(rb_cDLCPtr, "size", rb_dlptr_size, -1);
- rb_define_method(rb_cDLCPtr, "size=", rb_dlptr_size, -1);
-
- rb_define_const(rb_mDL, "NULL", rb_dlptr_new(0, 0, 0));
-}
diff --git a/ext/dl/depend b/ext/dl/depend
index 3f05a2f802..fba3df7a3d 100644
--- a/ext/dl/depend
+++ b/ext/dl/depend
@@ -1,11 +1,46 @@
-cfunc.o: cfunc.c dl.h
+LDSHARED_TEST = $(LDSHARED) $(LDFLAGS) test/test.o -o test/libtest.so $(LOCAL_LIBS)
-cptr.o: cptr.c dl.h
+libtest.so: test/libtest.so
-handle.o: handle.c dl.h
+test/libtest.so: test/test.o $(srcdir)/test/libtest.def
+ $(RUBY) -rftools -e 'ARGV.each do|d|File.mkpath(File.dirname(d))end' $@
+ $(LDSHARED_TEST:dl.def=test/libtest.def)
-dl.o: dl.c dl.h callback.h
+test/test.o: $(srcdir)/test/test.c
+ @$(RUBY) -rftools -e 'File.mkpath(*ARGV)' test
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/test/test.c -o $@
-callback.h: $(srcdir)/mkcallback.rb dl.h
- @echo "generating callback.h"
- @$(RUBY) $(srcdir)/mkcallback.rb $(srcdir)/dl.h > $@
+test:: dl.so libtest.so force
+ $(RUBY) -I. -I$(srcdir)/lib $(srcdir)/test/test.rb
+
+force:
+
+.PHONY: force test
+
+allclean: distclean
+ @rm -f $(CLEANFILES) $(DISTCLEANFILES)
+
+$(OBJS): ./dlconfig.h
+
+sym.o: dl.h call.func
+
+dl.o: dl.h callback.func cbtable.func
+
+ptr.o: dl.h
+
+handle.o: dl.h
+
+call.func: $(srcdir)/mkcall.rb ./dlconfig.rb
+ @echo "Generating call.func"
+ @$(RUBY) $(srcdir)/mkcall.rb > $@
+
+callback.func: $(srcdir)/mkcallback.rb ./dlconfig.rb
+ @echo "Generating callback.func"
+ @$(RUBY) $(srcdir)/mkcallback.rb > $@
+
+cbtable.func: $(srcdir)/mkcbtable.rb ./dlconfig.rb
+ @echo "Generating cbtable.func"
+ @$(RUBY) $(srcdir)/mkcbtable.rb > $@
+
+debug:
+ $(MAKE) CPPFLAGS="$(CPPFLAGS) -DDEBUG"
diff --git a/ext/dl/dl.c b/ext/dl/dl.c
index 015e76f09e..88e954c668 100644
--- a/ext/dl/dl.c
+++ b/ext/dl/dl.c
@@ -1,6 +1,9 @@
+/*
+ * $Id$
+ */
+
#include <ruby.h>
#include <rubyio.h>
-#include <version.h>
#include <ctype.h>
#include "dl.h"
@@ -8,126 +11,726 @@ VALUE rb_mDL;
VALUE rb_eDLError;
VALUE rb_eDLTypeError;
-ID rbdl_id_cdecl;
-ID rbdl_id_stdcall;
+static VALUE DLFuncTable;
+static void *rb_dl_callback_table[CALLBACK_TYPES][MAX_CALLBACK];
+static ID id_call;
+
+static int
+rb_dl_scan_callback_args(long stack[], const char *proto,
+ int *argc, VALUE argv[])
+{
+ int i;
+ long *sp;
+ VALUE val;
+
+ sp = stack;
+ for (i=1; proto[i]; i++) {
+ switch (proto[i]) {
+ case 'C':
+ {
+ char v;
+ v = (char)(*sp);
+ sp++;
+ val = INT2NUM(v);
+ }
+ break;
+ case 'H':
+ {
+ short v;
+ v = (short)(*sp);
+ sp++;
+ val = INT2NUM(v);
+ }
+ break;
+ case 'I':
+ {
+ int v;
+ v = (int)(*sp);
+ sp++;
+ val = INT2NUM(v);
+ }
+ break;
+ case 'L':
+ {
+ long v;
+ v = (long)(*sp);
+ sp++;
+ val = INT2NUM(v);
+ }
+ break;
+ case 'F':
+ {
+ float v;
+ memcpy(&v, sp, sizeof(float));
+ sp += sizeof(float)/sizeof(long);
+ val = rb_float_new(v);
+ }
+ break;
+ case 'D':
+ {
+ double v;
+ memcpy(&v, sp, sizeof(double));
+ sp += sizeof(double)/sizeof(long);
+ val = rb_float_new(v);
+ }
+ break;
+ case 'P':
+ {
+ void *v;
+ memcpy(&v, sp, sizeof(void*));
+ sp++;
+ val = rb_dlptr_new(v, 0, 0);
+ }
+ break;
+ case 'S':
+ {
+ char *v;
+ memcpy(&v, sp, sizeof(void*));
+ sp++;
+ val = rb_tainted_str_new2(v);
+ }
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unsupported type `%c'", proto[i]);
+ break;
+ }
+ argv[i-1] = val;
+ }
+ *argc = (i - 1);
+
+ return (*argc);
+}
+
+#include "callback.func"
+
+static void
+init_dl_func_table(){
+#include "cbtable.func"
+}
+
+void *
+dlmalloc(size_t size)
+{
+ DEBUG_CODE2({
+ void *ptr;
+
+ printf("dlmalloc(%d)",size);
+ ptr = xmalloc(size);
+ printf(":0x%x\n",ptr);
+ return ptr;
+ },
+ {
+ return xmalloc(size);
+ });
+}
+
+void *
+dlrealloc(void *ptr, size_t size)
+{
+ DEBUG_CODE({
+ printf("dlrealloc(0x%x,%d)\n",ptr,size);
+ });
+ return xrealloc(ptr, size);
+}
+
+void
+dlfree(void *ptr)
+{
+ DEBUG_CODE({
+ printf("dlfree(0x%x)\n",ptr);
+ });
+ xfree(ptr);
+}
+
+char*
+dlstrdup(const char *str)
+{
+ char *newstr;
+
+ newstr = (char*)dlmalloc(strlen(str)+1);
+ strcpy(newstr,str);
+
+ return newstr;
+}
+
+size_t
+dlsizeof(const char *cstr)
+{
+ size_t size;
+ int i, len, n, dlen;
+ char *d;
+
+ len = strlen(cstr);
+ size = 0;
+ for (i=0; i<len; i++) {
+ n = 1;
+ if (isdigit(cstr[i+1])) {
+ dlen = 1;
+ while (isdigit(cstr[i+dlen])) { dlen ++; };
+ dlen --;
+ d = ALLOCA_N(char, dlen + 1);
+ strncpy(d, cstr + i + 1, dlen);
+ d[dlen] = '\0';
+ n = atoi(d);
+ }
+ else{
+ dlen = 0;
+ }
+
+ switch (cstr[i]) {
+ case 'I':
+ DLALIGN(0,size,INT_ALIGN);
+ case 'i':
+ size += sizeof(int) * n;
+ break;
+ case 'L':
+ DLALIGN(0,size,LONG_ALIGN);
+ case 'l':
+ size += sizeof(long) * n;
+ break;
+ case 'F':
+ DLALIGN(0,size,FLOAT_ALIGN);
+ case 'f':
+ size += sizeof(float) * n;
+ break;
+ case 'D':
+ DLALIGN(0,size,DOUBLE_ALIGN);
+ case 'd':
+ size += sizeof(double) * n;
+ break;
+ case 'C':
+ case 'c':
+ size += sizeof(char) * n;
+ break;
+ case 'H':
+ DLALIGN(0,size,SHORT_ALIGN);
+ case 'h':
+ size += sizeof(short) * n;
+ break;
+ case 'P':
+ case 'S':
+ DLALIGN(0,size,VOIDP_ALIGN);
+ case 'p':
+ case 's':
+ size += sizeof(void*) * n;
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unexpected type '%c'", cstr[i]);
+ break;
+ }
+ i += dlen;
+ }
+
+ return size;
+}
+
+static float *
+c_farray(VALUE v, long *size)
+{
+ int i, len;
+ float *ary;
+ VALUE e;
+
+ len = RARRAY(v)->len;
+ *size = sizeof(float) * len;
+ ary = dlmalloc(*size);
+ for (i=0; i < len; i++) {
+ e = rb_ary_entry(v, i);
+ switch (TYPE(e)) {
+ case T_FLOAT:
+ ary[i] = (float)(RFLOAT(e)->value);
+ break;
+ case T_NIL:
+ ary[i] = 0.0;
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
+ break;
+ }
+ }
+
+ return ary;
+}
+
+static double *
+c_darray(VALUE v, long *size)
+{
+ int i, len;
+ double *ary;
+ VALUE e;
+
+ len = RARRAY(v)->len;
+ *size = sizeof(double) * len;
+ ary = dlmalloc(*size);
+ for (i=0; i < len; i++) {
+ e = rb_ary_entry(v, i);
+ switch (TYPE(e)) {
+ case T_FLOAT:
+ ary[i] = (double)(RFLOAT(e)->value);
+ break;
+ case T_NIL:
+ ary[i] = 0.0;
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
+ break;
+ }
+ }
+
+ return ary;
+}
+
+static long *
+c_larray(VALUE v, long *size)
+{
+ int i, len;
+ long *ary;
+ VALUE e;
+
+ len = RARRAY(v)->len;
+ *size = sizeof(long) * len;
+ ary = dlmalloc(*size);
+ for (i=0; i < len; i++) {
+ e = rb_ary_entry(v, i);
+ switch (TYPE(e)) {
+ case T_FIXNUM:
+ case T_BIGNUM:
+ ary[i] = (long)(NUM2INT(e));
+ break;
+ case T_NIL:
+ ary[i] = 0;
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
+ break;
+ }
+ }
+
+ return ary;
+}
+
+static int *
+c_iarray(VALUE v, long *size)
+{
+ int i, len;
+ int *ary;
+ VALUE e;
+
+ len = RARRAY(v)->len;
+ *size = sizeof(int) * len;
+ ary = dlmalloc(*size);
+ for (i=0; i < len; i++) {
+ e = rb_ary_entry(v, i);
+ switch (TYPE(e)) {
+ case T_FIXNUM:
+ case T_BIGNUM:
+ ary[i] = (int)(NUM2INT(e));
+ break;
+ case T_NIL:
+ ary[i] = 0;
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
+ break;
+ }
+ }
+
+ return ary;
+}
+
+static short *
+c_harray(VALUE v, long *size)
+{
+ int i, len;
+ short *ary;
+ VALUE e;
+
+ len = RARRAY(v)->len;
+ *size = sizeof(short) * len;
+ ary = dlmalloc(*size);
+ for (i=0; i < len; i++) {
+ e = rb_ary_entry(v, i);
+ switch (TYPE(e)) {
+ case T_FIXNUM:
+ case T_BIGNUM:
+ ary[i] = (short)(NUM2INT(e));
+ break;
+ case T_NIL:
+ ary[i] = 0;
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
+ break;
+ }
+ }
+
+ return ary;
+}
+
+static char *
+c_carray(VALUE v, long *size)
+{
+ int i, len;
+ char *ary;
+ VALUE e;
+
+ len = RARRAY(v)->len;
+ *size = sizeof(char) * len;
+ ary = dlmalloc(*size);
+ for (i=0; i < len; i++) {
+ e = rb_ary_entry(v, i);
+ switch (TYPE(e)) {
+ case T_FIXNUM:
+ case T_BIGNUM:
+ ary[i] = (char)(NUM2INT(e));
+ break;
+ case T_NIL:
+ ary[i] = 0;
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
+ break;
+ }
+ }
+
+ return ary;
+}
+
+static void *
+c_parray(VALUE v, long *size)
+{
+ int i, len;
+ void **ary;
+ VALUE e, tmp;
+
+ len = RARRAY(v)->len;
+ *size = sizeof(void*) * len;
+ ary = dlmalloc(*size);
+ for (i=0; i < len; i++) {
+ e = rb_ary_entry(v, i);
+ switch (TYPE(e)) {
+ default:
+ tmp = rb_check_string_type(e);
+ if (NIL_P(tmp)) {
+ rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
+ }
+ e = tmp;
+ /* fall through */
+ case T_STRING:
+ rb_check_safe_str(e);
+ {
+ char *str, *src;
+ src = RSTRING(e)->ptr;
+ str = dlstrdup(src);
+ ary[i] = (void*)str;
+ }
+ break;
+ case T_NIL:
+ ary[i] = NULL;
+ break;
+ case T_DATA:
+ if (rb_obj_is_kind_of(e, rb_cDLPtrData)) {
+ struct ptr_data *pdata;
+ Data_Get_Struct(e, struct ptr_data, pdata);
+ ary[i] = (void*)(pdata->ptr);
+ }
+ else{
+ e = rb_funcall(e, rb_intern("to_ptr"), 0);
+ if (rb_obj_is_kind_of(e, rb_cDLPtrData)) {
+ struct ptr_data *pdata;
+ Data_Get_Struct(e, struct ptr_data, pdata);
+ ary[i] = (void*)(pdata->ptr);
+ }
+ else{
+ rb_raise(rb_eDLTypeError, "unexpected type of the element #%d", i);
+ }
+ }
+ break;
+ }
+ }
+
+ return ary;
+}
+
+void *
+rb_ary2cary(char t, VALUE v, long *size)
+{
+ int len;
+ VALUE val0;
+
+ val0 = rb_check_array_type(v);
+ if(NIL_P(val0)) {
+ rb_raise(rb_eDLTypeError, "an array is expected.");
+ }
+ v = val0;
+
+ len = RARRAY(v)->len;
+ if (len == 0) {
+ return NULL;
+ }
+
+ if (!size) {
+ size = ALLOCA_N(long,1);
+ }
+
+ val0 = rb_ary_entry(v,0);
+ switch (TYPE(val0)) {
+ case T_FIXNUM:
+ case T_BIGNUM:
+ switch (t) {
+ case 'C': case 'c':
+ return (void*)c_carray(v,size);
+ case 'H': case 'h':
+ return (void*)c_harray(v,size);
+ case 'I': case 'i':
+ return (void*)c_iarray(v,size);
+ case 'L': case 'l': case 0:
+ return (void*)c_larray(v,size);
+ default:
+ rb_raise(rb_eDLTypeError, "type mismatch");
+ }
+ case T_STRING:
+ return (void*)c_parray(v,size);
+ case T_FLOAT:
+ switch (t) {
+ case 'F': case 'f':
+ return (void*)c_farray(v,size);
+ case 'D': case 'd': case 0:
+ return (void*)c_darray(v,size);
+ }
+ rb_raise(rb_eDLTypeError, "type mismatch");
+ case T_DATA:
+ if (rb_obj_is_kind_of(val0, rb_cDLPtrData)) {
+ return (void*)c_parray(v,size);
+ }
+ else{
+ val0 = rb_funcall(val0, rb_intern("to_ptr"), 0);
+ if (rb_obj_is_kind_of(val0, rb_cDLPtrData)) {
+ return (void*)c_parray(v,size);
+ }
+ }
+ rb_raise(rb_eDLTypeError, "type mismatch");
+ case T_NIL:
+ return (void*)c_parray(v, size);
+ default:
+ rb_raise(rb_eDLTypeError, "unsupported type");
+ }
+}
VALUE
-rb_dl_dlopen(int argc, VALUE argv[], VALUE self)
+rb_str_to_ptr(VALUE self)
{
- rb_secure(2);
- return rb_class_new_instance(argc, argv, rb_cDLHandle);
+ 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;
}
VALUE
-rb_dl_malloc(VALUE self, VALUE size)
+rb_ary_to_ptr(int argc, VALUE argv[], VALUE self)
{
- void *ptr;
+ void *ptr;
+ VALUE t;
+ long size;
- ptr = (void*)ruby_xmalloc(NUM2INT(size));
- return PTR2NUM(ptr);
+ switch (rb_scan_args(argc, argv, "01", &t)) {
+ case 1:
+ ptr = rb_ary2cary(StringValuePtr(t)[0], self, &size);
+ break;
+ case 0:
+ 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;
}
VALUE
-rb_dl_realloc(VALUE self, VALUE addr, VALUE size)
+rb_io_to_ptr(VALUE self)
{
- void *ptr = NUM2PTR(addr);
+ OpenFile *fptr;
+ FILE *fp;
+
+ GetOpenFile(self, fptr);
+ fp = fptr->f;
- ptr = (void*)ruby_xrealloc(ptr, NUM2INT(size));
- return PTR2NUM(ptr);
+ return fp ? rb_dlptr_new(fp, 0, 0) : Qnil;
}
VALUE
-rb_dl_free(VALUE self, VALUE addr)
+rb_dl_dlopen(int argc, VALUE argv[], VALUE self)
{
- void *ptr = NUM2PTR(addr);
- ruby_xfree(ptr);
- return Qnil;
+ rb_secure(2);
+ return rb_class_new_instance(argc, argv, rb_cDLHandle);
}
VALUE
-rb_dl_ptr2value(VALUE self, VALUE addr)
+rb_dl_malloc(VALUE self, VALUE size)
{
- return (VALUE)NUM2PTR(addr);
+ rb_secure(4);
+ return rb_dlptr_malloc(DLNUM2LONG(size), dlfree);
}
VALUE
-rb_dl_value2ptr(VALUE self, VALUE val)
+rb_dl_strdup(VALUE self, VALUE str)
{
- return PTR2NUM((void*)val);
+ SafeStringValue(str);
+ return rb_dlptr_new(strdup(RSTRING(str)->ptr), RSTRING(str)->len, dlfree);
}
-#include "callback.h"
+static VALUE
+rb_dl_sizeof(VALUE self, VALUE str)
+{
+ return INT2NUM(dlsizeof(StringValuePtr(str)));
+}
+
+static VALUE
+rb_dl_callback(int argc, VALUE argv[], VALUE self)
+{
+ VALUE type, proc;
+ int rettype, entry, i;
+ char fname[127];
+
+ rb_secure(4);
+ proc = Qnil;
+ switch (rb_scan_args(argc, argv, "11", &type, &proc)) {
+ case 1:
+ if (rb_block_given_p()) {
+ proc = rb_block_proc();
+ }
+ else{
+ proc = Qnil;
+ }
+ default:
+ break;
+ }
+
+ StringValue(type);
+ switch (RSTRING(type)->ptr[0]) {
+ case '0':
+ rettype = 0x00;
+ break;
+ case 'C':
+ rettype = 0x01;
+ break;
+ case 'H':
+ rettype = 0x02;
+ break;
+ case 'I':
+ rettype = 0x03;
+ break;
+ case 'L':
+ rettype = 0x04;
+ break;
+ case 'F':
+ rettype = 0x05;
+ break;
+ case 'D':
+ rettype = 0x06;
+ break;
+ case 'P':
+ rettype = 0x07;
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unsupported type `%c'", RSTRING(type)->ptr[0]);
+ }
+
+ entry = -1;
+ for (i=0; i < MAX_CALLBACK; i++) {
+ if (rb_hash_aref(DLFuncTable, rb_assoc_new(INT2NUM(rettype), INT2NUM(i))) == Qnil) {
+ entry = i;
+ break;
+ }
+ }
+ if (entry < 0) {
+ rb_raise(rb_eDLError, "too many callbacks are defined.");
+ }
+
+ rb_hash_aset(DLFuncTable,
+ rb_assoc_new(INT2NUM(rettype),INT2NUM(entry)),
+ rb_assoc_new(type,proc));
+ sprintf(fname, "rb_dl_callback_func_%d_%d", rettype, entry);
+ return rb_dlsym_new((void (*)())rb_dl_callback_table[rettype][entry],
+ fname, RSTRING(type)->ptr);
+}
+
+static VALUE
+rb_dl_remove_callback(VALUE mod, VALUE sym)
+{
+ freefunc_t f;
+ int i, j;
+
+ rb_secure(4);
+ f = rb_dlsym2csym(sym);
+ for (i=0; i < CALLBACK_TYPES; i++) {
+ for (j=0; j < MAX_CALLBACK; j++) {
+ if (rb_dl_callback_table[i][j] == f) {
+ rb_hash_aset(DLFuncTable, rb_assoc_new(INT2NUM(i),INT2NUM(j)),Qnil);
+ break;
+ }
+ }
+ }
+ return Qnil;
+}
void
Init_dl()
{
- void Init_dlhandle();
- void Init_dlcfunc();
- void Init_dlptr();
-
- rbdl_id_cdecl = rb_intern("cdecl");
- rbdl_id_stdcall = rb_intern("stdcall");
-
- rb_mDL = rb_define_module("DL");
- rb_eDLError = rb_define_class_under(rb_mDL, "DLError", rb_eStandardError);
- rb_eDLTypeError = rb_define_class_under(rb_mDL, "DLTypeError", rb_eDLError);
-
- rb_define_const(rb_mDL, "MAX_CALLBACK", INT2NUM(MAX_CALLBACK));
- rb_define_const(rb_mDL, "DLSTACK_SIZE", INT2NUM(DLSTACK_SIZE));
-
- rb_dl_init_callbacks();
-
- rb_define_const(rb_mDL, "RTLD_GLOBAL", INT2NUM(RTLD_GLOBAL));
- rb_define_const(rb_mDL, "RTLD_LAZY", INT2NUM(RTLD_LAZY));
- rb_define_const(rb_mDL, "RTLD_NOW", INT2NUM(RTLD_NOW));
-
- rb_define_const(rb_mDL, "TYPE_VOID", INT2NUM(DLTYPE_VOID));
- rb_define_const(rb_mDL, "TYPE_VOIDP", INT2NUM(DLTYPE_VOIDP));
- rb_define_const(rb_mDL, "TYPE_CHAR", INT2NUM(DLTYPE_CHAR));
- rb_define_const(rb_mDL, "TYPE_SHORT", INT2NUM(DLTYPE_SHORT));
- rb_define_const(rb_mDL, "TYPE_INT", INT2NUM(DLTYPE_INT));
- rb_define_const(rb_mDL, "TYPE_LONG", INT2NUM(DLTYPE_LONG));
-#if HAVE_LONG_LONG
- rb_define_const(rb_mDL, "TYPE_LONG_LONG", INT2NUM(DLTYPE_LONG_LONG));
-#endif
- rb_define_const(rb_mDL, "TYPE_FLOAT", INT2NUM(DLTYPE_FLOAT));
- rb_define_const(rb_mDL, "TYPE_DOUBLE", INT2NUM(DLTYPE_DOUBLE));
-
- rb_define_const(rb_mDL, "ALIGN_VOIDP", INT2NUM(ALIGN_VOIDP));
- rb_define_const(rb_mDL, "ALIGN_CHAR", INT2NUM(ALIGN_CHAR));
- rb_define_const(rb_mDL, "ALIGN_SHORT", INT2NUM(ALIGN_SHORT));
- rb_define_const(rb_mDL, "ALIGN_INT", INT2NUM(ALIGN_INT));
- rb_define_const(rb_mDL, "ALIGN_LONG", INT2NUM(ALIGN_LONG));
-#if HAVE_LONG_LONG
- rb_define_const(rb_mDL, "ALIGN_LONG_LONG", INT2NUM(ALIGN_LONG_LONG));
-#endif
- rb_define_const(rb_mDL, "ALIGN_FLOAT", INT2NUM(ALIGN_FLOAT));
- rb_define_const(rb_mDL, "ALIGN_DOUBLE",INT2NUM(ALIGN_DOUBLE));
-
- rb_define_const(rb_mDL, "SIZEOF_VOIDP", INT2NUM(sizeof(void*)));
- rb_define_const(rb_mDL, "SIZEOF_CHAR", INT2NUM(sizeof(char)));
- rb_define_const(rb_mDL, "SIZEOF_SHORT", INT2NUM(sizeof(short)));
- rb_define_const(rb_mDL, "SIZEOF_INT", INT2NUM(sizeof(int)));
- rb_define_const(rb_mDL, "SIZEOF_LONG", INT2NUM(sizeof(long)));
-#if HAVE_LONG_LONG
- rb_define_const(rb_mDL, "SIZEOF_LONG_LONG", INT2NUM(sizeof(LONG_LONG)));
-#endif
- rb_define_const(rb_mDL, "SIZEOF_FLOAT", INT2NUM(sizeof(float)));
- rb_define_const(rb_mDL, "SIZEOF_DOUBLE",INT2NUM(sizeof(double)));
-
- rb_define_module_function(rb_mDL, "dlwrap", rb_dl_value2ptr, 1);
- rb_define_module_function(rb_mDL, "dlunwrap", rb_dl_ptr2value, 1);
-
- rb_define_module_function(rb_mDL, "dlopen", rb_dl_dlopen, -1);
- rb_define_module_function(rb_mDL, "malloc", rb_dl_malloc, 1);
- rb_define_module_function(rb_mDL, "realloc", rb_dl_realloc, 2);
- rb_define_module_function(rb_mDL, "free", rb_dl_free, 1);
-
- rb_define_const(rb_mDL, "RUBY_FREE", PTR2NUM(ruby_xfree));
- rb_define_const(rb_mDL, "BUILD_RUBY_PLATFORM", rb_str_new2(RUBY_PLATFORM));
- rb_define_const(rb_mDL, "BUILD_RUBY_VERSION", rb_str_new2(RUBY_VERSION));
-
- Init_dlhandle();
- Init_dlcfunc();
- Init_dlptr();
+ void Init_dlptr();
+ void Init_dlsym();
+ void Init_dlhandle();
+
+ id_call = rb_intern("call");
+
+ rb_mDL = rb_define_module("DL");
+
+ rb_eDLError = rb_define_class_under(rb_mDL, "DLError", rb_eStandardError);
+ rb_eDLTypeError = rb_define_class_under(rb_mDL, "DLTypeError", rb_eDLError);
+
+ DLFuncTable = rb_hash_new();
+ init_dl_func_table();
+ rb_define_const(rb_mDL, "FuncTable", DLFuncTable);
+
+ rb_define_const(rb_mDL, "RTLD_GLOBAL", INT2NUM(RTLD_GLOBAL));
+ rb_define_const(rb_mDL, "RTLD_LAZY", INT2NUM(RTLD_LAZY));
+ rb_define_const(rb_mDL, "RTLD_NOW", INT2NUM(RTLD_NOW));
+
+ rb_define_const(rb_mDL, "ALIGN_INT", INT2NUM(ALIGN_INT));
+ rb_define_const(rb_mDL, "ALIGN_LONG", INT2NUM(ALIGN_LONG));
+ rb_define_const(rb_mDL, "ALIGN_FLOAT", INT2NUM(ALIGN_FLOAT));
+ rb_define_const(rb_mDL, "ALIGN_SHORT", INT2NUM(ALIGN_SHORT));
+ rb_define_const(rb_mDL, "ALIGN_DOUBLE",INT2NUM(ALIGN_DOUBLE));
+ rb_define_const(rb_mDL, "ALIGN_VOIDP", INT2NUM(ALIGN_VOIDP));
+
+ rb_define_const(rb_mDL, "MAX_ARG", INT2NUM(MAX_ARG));
+ rb_define_const(rb_mDL, "DLSTACK", rb_tainted_str_new2(DLSTACK_METHOD));
+
+ rb_define_module_function(rb_mDL, "dlopen", rb_dl_dlopen, -1);
+ rb_define_module_function(rb_mDL, "callback", rb_dl_callback, -1);
+ rb_define_module_function(rb_mDL, "define_callback", rb_dl_callback, -1);
+ rb_define_module_function(rb_mDL, "remove_callback", rb_dl_remove_callback, 1);
+ rb_define_module_function(rb_mDL, "malloc", rb_dl_malloc, 1);
+ rb_define_module_function(rb_mDL, "strdup", rb_dl_strdup, 1);
+ rb_define_module_function(rb_mDL, "sizeof", rb_dl_sizeof, 1);
+
+ Init_dlptr();
+ Init_dlsym();
+ Init_dlhandle();
+
+ rb_define_const(rb_mDL, "FREE", rb_dlsym_new(dlfree, "free", "0P"));
+
+ rb_define_method(rb_cString, "to_ptr", rb_str_to_ptr, 0);
+ rb_define_method(rb_cArray, "to_ptr", rb_ary_to_ptr, -1);
+ rb_define_method(rb_cIO, "to_ptr", rb_io_to_ptr, 0);
}
diff --git a/ext/dl/dl.def b/ext/dl/dl.def
new file mode 100644
index 0000000000..cdab4af90d
--- /dev/null
+++ b/ext/dl/dl.def
@@ -0,0 +1,59 @@
+EXPORTS
+Init_dl
+dlfree
+dlmalloc
+dlrealloc
+dlstrdup
+rb_ary_to_ptr
+rb_dl_dlopen
+rb_dl_malloc
+rb_dl_strdup
+rb_eDLError
+rb_eDLTypeError
+rb_io_to_ptr
+rb_mDL
+rb_str_to_ptr
+Init_dlhandle
+rb_cDLHandle
+rb_dlhandle_close
+rb_dlhandle_disable_close
+rb_dlhandle_enable_close
+rb_dlhandle_sym
+Init_dlptr
+rb_cDLPtrData
+rb_dlmem_each
+rb_dlptr2cptr
+rb_dlptr_malloc
+rb_dlptr_aref
+rb_dlptr_aset
+rb_dlptr_cmp
+rb_dlptr_define_data_type
+rb_dlptr_define_struct
+rb_dlptr_define_union
+rb_dlptr_eql
+rb_dlptr_free_get
+rb_dlptr_free_set
+rb_dlptr_get_data_type
+rb_dlptr_inspect
+rb_dlptr_minus
+rb_dlptr_new
+rb_dlptr_new2
+rb_dlptr_null_p
+rb_dlptr_plus
+rb_dlptr_ptr
+rb_dlptr_ref
+rb_dlptr_to_array
+rb_dlptr_to_i
+rb_dlptr_to_s
+rb_dlptr_to_str
+rb_mDLMemorySpace
+Init_dlsym
+rb_cDLSymbol
+rb_dlsym2csym
+rb_dlsym_call
+rb_dlsym_cproto
+rb_dlsym_inspect
+rb_dlsym_name
+rb_dlsym_new
+rb_dlsym_proto
+rb_dlsym_to_ptr
diff --git a/ext/dl/dl.h b/ext/dl/dl.h
index 7b8ad077ae..1faa316cf1 100644
--- a/ext/dl/dl.h
+++ b/ext/dl/dl.h
@@ -1,14 +1,12 @@
+/* -*- C -*-
+ * $Id$
+ */
+
#ifndef RUBY_DL_H
#define RUBY_DL_H
#include <ruby.h>
-
-#if !defined(FUNC_CDECL)
-# define FUNC_CDECL(x) x
-#endif
-#if !defined(FUNC_STDCALL)
-# define FUNC_STDCALL(x) x
-#endif
+#include <dlconfig.h>
#if defined(HAVE_DLFCN_H)
# include <dlfcn.h>
@@ -35,156 +33,281 @@
# endif
#endif
-#define MAX_CALLBACK 5
-#define DLSTACK_TYPE long
-#define DLSTACK_SIZE (20)
-#define DLSTACK_PROTO \
- DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,\
- DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,\
- DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,\
- DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE
-#define DLSTACK_ARGS(stack) \
- stack[0],stack[1],stack[2],stack[3],stack[4],\
- stack[5],stack[6],stack[7],stack[8],stack[9],\
- stack[10],stack[11],stack[12],stack[13],stack[14],\
- stack[15],stack[16],stack[17],stack[18],stack[19]
-
-#define DLSTACK_PROTO0
-#define DLSTACK_PROTO1 DLSTACK_TYPE
-#define DLSTACK_PROTO2 DLSTACK_PROTO1, DLSTACK_TYPE
-#define DLSTACK_PROTO3 DLSTACK_PROTO2, DLSTACK_TYPE
-#define DLSTACK_PROTO4 DLSTACK_PROTO3, DLSTACK_TYPE
-#define DLSTACK_PROTO4 DLSTACK_PROTO3, DLSTACK_TYPE
-#define DLSTACK_PROTO5 DLSTACK_PROTO4, DLSTACK_TYPE
-#define DLSTACK_PROTO6 DLSTACK_PROTO5, DLSTACK_TYPE
-#define DLSTACK_PROTO7 DLSTACK_PROTO6, DLSTACK_TYPE
-#define DLSTACK_PROTO8 DLSTACK_PROTO7, DLSTACK_TYPE
-#define DLSTACK_PROTO9 DLSTACK_PROTO8, DLSTACK_TYPE
-#define DLSTACK_PROTO10 DLSTACK_PROTO9, DLSTACK_TYPE
-#define DLSTACK_PROTO11 DLSTACK_PROTO10, DLSTACK_TYPE
-#define DLSTACK_PROTO12 DLSTACK_PROTO11, DLSTACK_TYPE
-#define DLSTACK_PROTO13 DLSTACK_PROTO12, DLSTACK_TYPE
-#define DLSTACK_PROTO14 DLSTACK_PROTO13, DLSTACK_TYPE
-#define DLSTACK_PROTO14 DLSTACK_PROTO13, DLSTACK_TYPE
-#define DLSTACK_PROTO15 DLSTACK_PROTO14, DLSTACK_TYPE
-#define DLSTACK_PROTO16 DLSTACK_PROTO15, DLSTACK_TYPE
-#define DLSTACK_PROTO17 DLSTACK_PROTO16, DLSTACK_TYPE
-#define DLSTACK_PROTO18 DLSTACK_PROTO17, DLSTACK_TYPE
-#define DLSTACK_PROTO19 DLSTACK_PROTO18, DLSTACK_TYPE
-#define DLSTACK_PROTO20 DLSTACK_PROTO19, DLSTACK_TYPE
-
-#define DLSTACK_ARGS0(stack)
-#define DLSTACK_ARGS1(stack) stack[0]
-#define DLSTACK_ARGS2(stack) DLSTACK_ARGS1(stack), stack[1]
-#define DLSTACK_ARGS3(stack) DLSTACK_ARGS2(stack), stack[2]
-#define DLSTACK_ARGS4(stack) DLSTACK_ARGS3(stack), stack[3]
-#define DLSTACK_ARGS5(stack) DLSTACK_ARGS4(stack), stack[4]
-#define DLSTACK_ARGS6(stack) DLSTACK_ARGS5(stack), stack[5]
-#define DLSTACK_ARGS7(stack) DLSTACK_ARGS6(stack), stack[6]
-#define DLSTACK_ARGS8(stack) DLSTACK_ARGS7(stack), stack[7]
-#define DLSTACK_ARGS9(stack) DLSTACK_ARGS8(stack), stack[8]
-#define DLSTACK_ARGS10(stack) DLSTACK_ARGS9(stack), stack[9]
-#define DLSTACK_ARGS11(stack) DLSTACK_ARGS10(stack), stack[10]
-#define DLSTACK_ARGS12(stack) DLSTACK_ARGS11(stack), stack[11]
-#define DLSTACK_ARGS13(stack) DLSTACK_ARGS12(stack), stack[12]
-#define DLSTACK_ARGS14(stack) DLSTACK_ARGS13(stack), stack[13]
-#define DLSTACK_ARGS15(stack) DLSTACK_ARGS14(stack), stack[14]
-#define DLSTACK_ARGS16(stack) DLSTACK_ARGS15(stack), stack[15]
-#define DLSTACK_ARGS17(stack) DLSTACK_ARGS16(stack), stack[16]
-#define DLSTACK_ARGS18(stack) DLSTACK_ARGS17(stack), stack[17]
-#define DLSTACK_ARGS19(stack) DLSTACK_ARGS18(stack), stack[18]
-#define DLSTACK_ARGS20(stack) DLSTACK_ARGS19(stack), stack[19]
+#if !defined(StringValue)
+# define StringValue(v) if(TYPE(v) != T_STRING) v = rb_str_to_str(v)
+#endif
+#if !defined(StringValuePtr)
+# define StringValuePtr(v) RSTRING((TYPE(v) == T_STRING) ? (v) : rb_str_to_str(v))->ptr
+#endif
+
+#ifdef DEBUG
+#define DEBUG_CODE(b) {printf("DEBUG:%d\n",__LINE__);b;}
+#define DEBUG_CODE2(b1,b2) {printf("DEBUG:%d\n",__LINE__);b1;}
+#else
+#define DEBUG_CODE(b)
+#define DEBUG_CODE2(b1,b2) b2
+#endif
+
+#define VOID_DLTYPE 0x00
+#define CHAR_DLTYPE 0x01
+#define SHORT_DLTYPE 0x02
+#define INT_DLTYPE 0x03
+#define LONG_DLTYPE 0x04
+#define FLOAT_DLTYPE 0x05
+#define DOUBLE_DLTYPE 0x06
+#define VOIDP_DLTYPE 0x07
+
+#define ARG_TYPE(x,i) (((x) & (0x07 << ((i)*3))) >> ((i)*3))
+#define PUSH_ARG(x,t) do{x <<= 3; x |= t;}while(0)
+#define PUSH_0(x) PUSH_ARG(x,VOID_DLTYPE)
+
+#if SIZEOF_INT == SIZEOF_LONG
+# define PUSH_I(x) PUSH_ARG(x,LONG_DLTYPE)
+# define ANY2I(x) x.l
+# define DLINT(x) (long)x
+#else
+# define PUSH_I(x) PUSH_ARG(x,INT_DLTYPE)
+# define ANY2I(x) x.i
+# define DLINT(x) (int)x
+#endif
+#define PUSH_L(x) PUSH_ARG(x,LONG_DLTYPE)
+#define ANY2L(x) x.l
+#define DLLONG(x) (long)x
+
+#if defined(WITH_TYPE_FLOAT)
+# if SIZEOF_FLOAT == SIZEOF_DOUBLE
+# define PUSH_F(x) PUSH_ARG(x,DOUBLE_DLTYPE)
+# define ANY2F(x) (x.d)
+# define DLFLOAT(x) ((double)x)
+# else
+# define PUSH_F(x) PUSH_ARG(x,FLOAT_DLTYPE)
+# define ANY2F(x) (x.f)
+# define DLFLOAT(x) ((float)x)
+# endif
+#else
+# define PUSH_F(x) PUSH_ARG(x,DOUBLE_DLTYPE)
+# define ANY2F(x) (x.d)
+# define DLFLOAT(x) ((double)x)
+#endif
+#define PUSH_D(x) PUSH_ARG(x,DOUBLE_DLTYPE)
+#define ANY2D(x) (x.d)
+#define DLDOUBLE(x) ((double)x)
+
+#if SIZEOF_INT == SIZEOF_VOIDP && SIZEOF_INT != SIZEOF_LONG
+# define PUSH_P(x) PUSH_ARG(x,INT_DLTYPE)
+# define ANY2P(x) (x.i)
+# define DLVOIDP(x) ((int)x)
+#elif SIZEOF_LONG == SIZEOF_VOIDP
+# define PUSH_P(x) PUSH_ARG(x,LONG_DLTYPE)
+# define ANY2P(x) (x.l)
+# define DLVOIDP(x) ((long)x)
+#else
+# define PUSH_P(x) PUSH_ARG(x,VOIDP_DLTYPE)
+# define ANY2P(x) (x.p)
+# define DLVOIDP(x) ((void*)p)
+#endif
+
+#if defined(WITH_TYPE_CHAR)
+# define PUSH_C(x) PUSH_ARG(x,CHAR_DLTYPE)
+# define ANY2C(x) (x.c)
+# define DLCHAR(x) ((char)x)
+#else
+# define PUSH_C(x) PUSH_I(x)
+# define ANY2C(x) ANY2I(x)
+# define DLCHAR(x) DLINT(x)
+#endif
+
+#if defined(WITH_TYPE_SHORT)
+# define PUSH_H(x) PUSH_ARG(x,SHORT_DLTYPE)
+# define ANY2H(x) (x.h)
+# define DLSHORT(x) ((short)x)
+#else
+# define PUSH_H(x) PUSH_I(x)
+# define ANY2H(x) ANY2I(x)
+# define DLSHORT(x) DLINT(x)
+#endif
+
+#define PUSH_S(x) PUSH_P(x)
+#define ANY2S(x) ANY2P(x)
+#define DLSTR(x) DLVOIDP(x)
+
+#define CBPUSH_0(x) PUSH_0(x)
+#define CBPUSH_C(x) PUSH_C(x)
+#define CBPUSH_H(x) PUSH_H(x)
+#define CBPUSH_I(x) PUSH_I(x)
+#define CBPUSH_L(x) PUSH_L(x)
+#define CBPUSH_F(x) PUSH_F(x)
+#define CBPUSH_D(x) PUSH_D(x)
+#if defined(WITH_CBTYPE_VOIDP)
+# define CBPUSH_P(x) PUSH_ARG(x,VOIDP_DLTYPE)
+#else
+# define CBPUSH_P(x) PUSH_P(x)
+#endif
+
+
+#if defined(USE_INLINE_ASM)
+# if defined(__i386__) && defined(__GNUC__)
+# define DLSTACK
+# define DLSTACK_METHOD "asm"
+# define DLSTACK_REVERSE
+# define DLSTACK_PROTO
+# define DLSTACK_ARGS
+# define DLSTACK_START(sym)
+# define DLSTACK_END(sym)
+# define DLSTACK_PUSH_C(x) asm volatile ("pushl %0" :: "g" (x));
+# define DLSTACK_PUSH_H(x) asm volatile ("pushl %0" :: "g" (x));
+# define DLSTACK_PUSH_I(x) asm volatile ("pushl %0" :: "g" (x));
+# define DLSTACK_PUSH_L(x) asm volatile ("pushl %0" :: "g" (x));
+# define DLSTACK_PUSH_P(x) asm volatile ("pushl %0" :: "g" (x));
+# define DLSTACK_PUSH_F(x) asm volatile ("flds %0"::"g"(x));\
+ asm volatile ("subl $4,%esp");\
+ asm volatile ("fstps (%esp)");
+# define DLSTACK_PUSH_D(x) asm volatile ("fldl %0"::"g"(x));\
+ asm volatile ("subl $8,%esp");\
+ asm volatile ("fstpl (%esp)")
+# else
+# error --with-asm is not supported on this machine
+# endif
+#elif defined(USE_DLSTACK)
+# define DLSTACK
+# define DLSTACK_GUARD
+# define DLSTACK_METHOD "dl"
+# define DLSTACK_PROTO long,long,long,long,long,\
+ long,long,long,long,long,\
+ long,long,long,long,long
+# define DLSTACK_ARGS stack[0],stack[1],stack[2],stack[3],stack[4],\
+ stack[5],stack[6],stack[7],stack[8],stack[9],\
+ stack[10],stack[11],stack[12],stack[13],stack[14]
+# define DLSTACK_SIZE (sizeof(long)*15)
+# define DLSTACK_START(sym)
+# define DLSTACK_END(sym)
+# define DLSTACK_PUSH_C(x) {long v=(long)x; memcpy(sp,&v,sizeof(long)); sp++;}
+# define DLSTACK_PUSH_H(x) {long v=(long)x; memcpy(sp,&v,sizeof(long)); sp++;}
+# define DLSTACK_PUSH_I(x) {long v=(long)x; memcpy(sp,&v,sizeof(long)); sp++;}
+# define DLSTACK_PUSH_L(x) memcpy(sp,&x,sizeof(long)); sp++;
+# define DLSTACK_PUSH_P(x) memcpy(sp,&x,sizeof(void*)); sp++;
+# define DLSTACK_PUSH_F(x) memcpy(sp,&x,sizeof(float)); sp+=sizeof(float)/sizeof(long);
+# define DLSTACK_PUSH_D(x) memcpy(sp,&x,sizeof(double)); sp+=sizeof(double)/sizeof(long);
+#else
+# define DLSTACK_METHOD "none"
+#endif
extern VALUE rb_mDL;
+extern VALUE rb_mDLMemorySpace;
extern VALUE rb_cDLHandle;
extern VALUE rb_cDLSymbol;
+extern VALUE rb_cDLPtrData;
+extern VALUE rb_cDLStructData;
+
extern VALUE rb_eDLError;
extern VALUE rb_eDLTypeError;
+#if defined(LONG2NUM) && (SIZEOF_LONG == SIZEOF_VOIDP)
+# define DLLONG2NUM(x) LONG2NUM((long)x)
+# define DLNUM2LONG(x) (long)(NUM2LONG(x))
+#else
+# define DLLONG2NUM(x) INT2NUM((long)x)
+# define DLNUM2LONG(x) (long)(NUM2INT(x))
+#endif
+
typedef struct { char c; void *x; } s_voidp;
typedef struct { char c; short x; } s_short;
typedef struct { char c; int x; } s_int;
typedef struct { char c; long x; } s_long;
typedef struct { char c; float x; } s_float;
typedef struct { char c; double x; } s_double;
-#if HAVE_LONG_LONG
-typedef struct { char c; LONG_LONG x; } s_long_long;
-#endif
#define ALIGN_VOIDP (sizeof(s_voidp) - sizeof(void *))
#define ALIGN_SHORT (sizeof(s_short) - sizeof(short))
-#define ALIGN_CHAR (1)
#define ALIGN_INT (sizeof(s_int) - sizeof(int))
#define ALIGN_LONG (sizeof(s_long) - sizeof(long))
-#if HAVE_LONG_LONG
-#define ALIGN_LONG_LONG (sizeof(s_long_long) - sizeof(LONG_LONG))
-#endif
#define ALIGN_FLOAT (sizeof(s_float) - sizeof(float))
#define ALIGN_DOUBLE (sizeof(s_double) - sizeof(double))
+/* for compatibility */
+#define VOIDP_ALIGN ALIGN_VOIDP
+#define SHORT_ALIGN ALIGN_SHORT
+#define INT_ALIGN ALIGN_INT
+#define LONG_ALIGN ALIGN_LONG
+#define FLOAT_ALIGN ALIGN_FLOAT
+#define DOUBLE_ALIGN ALIGN_DOUBLE
+
#define DLALIGN(ptr,offset,align) {\
while( (((unsigned long)((char *)ptr + offset)) % align) != 0 ) offset++;\
}
+typedef void (*freefunc_t)(void *);
+#define DLFREEFUNC(func) ((freefunc_t)(func))
-#define DLTYPE_VOID 0
-#define DLTYPE_VOIDP 1
-#define DLTYPE_CHAR 2
-#define DLTYPE_SHORT 3
-#define DLTYPE_INT 4
-#define DLTYPE_LONG 5
-#if HAVE_LONG_LONG
-#define DLTYPE_LONG_LONG 6
-#endif
-#define DLTYPE_FLOAT 7
-#define DLTYPE_DOUBLE 8
-#define MAX_DLTYPE 9
-
-#if SIZEOF_VOIDP == SIZEOF_LONG
-# define PTR2NUM(x) (ULONG2NUM((unsigned long)(x)))
-# define NUM2PTR(x) ((void*)(NUM2ULONG(x)))
-#else
-/* # error --->> Ruby/DL2 requires sizeof(void*) == sizeof(long) to be compiled. <<--- */
-# define PTR2NUM(x) (ULL2NUM((unsigned long long)(x)))
-# define NUM2PTR(x) ((void*)(NUM2ULL(x)))
-#endif
-
-#define BOOL2INT(x) ((x == Qtrue)?1:0)
-#define INT2BOOL(x) (x?Qtrue:Qfalse)
-
-typedef void (*freefunc_t)(void*);
+typedef union {
+ void* p;
+ char c;
+ short h;
+ int i;
+ long l;
+ float f;
+ double d;
+ char *s;
+} ANY_TYPE;
struct dl_handle {
- void *ptr;
- int open;
- int enable_close;
+ void *ptr;
+ int open;
+ int enable_close;
};
+struct sym_data {
+ void *func;
+ char *name;
+ char *type;
+ int len;
+};
-struct cfunc_data {
- void *ptr;
- char *name;
- int type;
- ID calltype;
+enum DLPTR_CTYPE {
+ DLPTR_CTYPE_UNKNOWN,
+ DLPTR_CTYPE_STRUCT,
+ DLPTR_CTYPE_UNION
};
-extern ID rbdl_id_cdecl;
-extern ID rbdl_id_stdcall;
-#define CFUNC_CDECL (rbdl_id_cdecl)
-#define CFUNC_STDCALL (rbdl_id_stdcall)
struct ptr_data {
- void *ptr;
- long size;
- freefunc_t free;
+ void *ptr; /* a pointer to the data */
+ freefunc_t free; /* free() */
+ char *stype; /* array of type specifiers */
+ int *ssize; /* size[i] = sizeof(type[i]) > 0 */
+ int slen; /* the number of type specifiers */
+ ID *ids;
+ int ids_num;
+ int ctype; /* DLPTR_CTYPE_UNKNOWN, DLPTR_CTYPE_STRUCT, DLPTR_CTYPE_UNION */
+ long size;
};
-#define RDL_HANDLE(obj) ((struct dl_handle *)(DATA_PTR(obj)))
-#define RCFUNC_DATA(obj) ((struct cfunc_data *)(DATA_PTR(obj)))
-#define RPTR_DATA(obj) ((struct ptr_data *)(DATA_PTR(obj)))
+#define RDLPTR(obj) ((struct ptr_data *)(DATA_PTR(obj)))
+#define RDLSYM(obj) ((struct sym_data *)(DATA_PTR(obj)))
+
+void dlfree(void*);
+void *dlmalloc(size_t);
+void *dlrealloc(void*,size_t);
+char *dlstrdup(const char *);
+size_t dlsizeof(const char *);
+
+void *rb_ary2cary(char t, VALUE ary, long *size);
+
+/*
+void rb_dlmem_delete(void *ptr);
+void rb_dlmem_aset(void *ptr, VALUE obj);
+VALUE rb_dlmem_aref(void *ptr);
+*/
+
+void dlptr_free(struct ptr_data *data);
+void dlptr_init(VALUE val);
-VALUE rb_dlcfunc_new(void (*func)(), int dltype, const char * name, ID calltype);
VALUE rb_dlptr_new(void *ptr, long size, freefunc_t func);
VALUE rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func);
VALUE rb_dlptr_malloc(long size, freefunc_t func);
+void *rb_dlptr2cptr(VALUE val);
-#endif
+VALUE rb_dlsym_new(void (*func)(), const char *name, const char *type);
+freefunc_t rb_dlsym2csym(VALUE val);
+
+
+#endif /* RUBY_DL_H */
diff --git a/ext/dl/doc/dl.txt b/ext/dl/doc/dl.txt
new file mode 100644
index 0000000000..893bd21d79
--- /dev/null
+++ b/ext/dl/doc/dl.txt
@@ -0,0 +1,266 @@
+=begin
+
+= Ruby/DL
+
+Ruby/DL provides an interface to the dynamic linker such as dlopen() on UNIX
+and LoadLibrary() on Windows.
+
+= Building and Installing
+
+ $ ruby extconf.rb # to create the Makefile
+ $ make # to build the library 'dl.so'
+ $ make libtest.so # to build the C library 'libtest.so' for the test script
+ $ make test # to run the test script
+ $ make install # to install the library
+ $ make clean # to remove the created files without Makefile
+ $ make distclean # to remove the all created files
+
+= Using Ruby/DL
+
+We should usually use DL::Importable module provided by "dl/import.rb".
+It has high-level functions to access library functions. We use
+DL::Importable module to extend a module as follows:
+
+ require "dl/import"
+ module LIBC
+ extend DL::Importable
+ end
+
+Now we can use methods dlload and extern in this module. We load the
+libraries using dlload, and define wrapper methods to library functions
+using extern respectively as follows:
+
+ module LIBC
+ extend DL::Importable
+ dlload "libc.so.6","libm.so.6"
+ extern "int strlen(char*)"
+ end
+ # Note that we should not include the module LIBC from some reason.
+
+We can call the library function strlen() using LIBC.strlen. If the first
+character of given function name is an uppercase, the first character of the
+defined method name becomes lowercase.
+We can also construct memory images of structures and unions using functions
+struct and union which are defined in "dl/struct.rb" as follows:
+
+ require "dl/import"
+ require "dl/struct"
+ module LIBC
+ extend DL::Importable
+ Timeval = struct [ # define timeval structure.
+ "long tv_sec",
+ "long tv_uses",
+ ]
+ end
+ val = LIBC::Timeval.malloc # allocate memory.
+
+Notice that the above example takes LIBC::Timeval.malloc to allocate memory,
+rather than LIBC::Timeval.new. It is because DL::Timeval.new is for wrapping
+an object, PtrData, which has already been created.
+
+We can define a callback using the module function "callback" as follows:
+
+ module Foo
+ extend DL::Importable
+ def my_comp(str1,str2)
+ str1 <=> str2
+ end
+ COMPARE = callback "int my_comp(char*,char*)"
+ end
+
+where Foo::COMPARE is a Symbol object which invokes the method "my_comp".
+
+DL::Importable module is very useful. However, we sometimes encounter a case
+that we must directly use low-level functions such as dlsym(). In such case,
+we would use DL module functions. They are described in next section.
+
+= DL module
+
+Module DL consists of three classes, a few module functions and constants.
+The class Symbol represents the symbol we can call. The class PtrData
+indicates a memory block such as a pointer in C. An object instantiated from
+the class Handle keeps a handle to opened library.
+
+== Constants
+
+* VERSION
+* MAJOR_VERSION
+* MINOR_VERSION
+* PATCH_VERSION
+* RTLD_GLOBAL
+* RTLD_LAZY
+* RTLD_NOW
+* MAX_ARG
+* MAX_CBARG
+* MAX_CBENT
+
+== Functions
+
+* handle = dlopen(lib){|handle| ... }
+ * is quite equal to `Handle.new(lib)'
+
+* sym = set_callback(cbtype, entry){|args| ... }
+* sym = set_callback(cbtype, entry, proc)
+ * makes entry-th pre-defined function to call the proc or given block. the
+ entry-th pre-defined function is specified by cbtype and entry. cbtype is a
+ prototype of the callback. see also the section `Type specifiers' about
+ cbtype.
+
+* sym = get_callback(cbtype, entry)
+ * returns the Proc object which is given by the above function
+ `set_callback'.
+
+* ptr = malloc(size, [free = nil])
+ * allocates the size bytes, and returns the pointer as a PtrData object ptr.
+
+* ptr = strdup(str)
+ * returns a PtrData object ptr which represents the pointer to a new string
+ which is a duplicate of the string str.
+
+* size = sizeof(type)
+ * returns the size of type. `sizeof("C") + sizeof("L")' is not equal to
+ `sizeof("CL")'. the latter is assumed to returns the enough size of the
+ structure `struct foo { char c; long l; }', but the size may not equal to
+ `sizeof(foo)' of C.
+
+== Handle class
+
+* handle = Handle.new(lib){|handle| ... }
+ * opens a library lib and returns a Handle object handle. if a block is
+ given, the handle is automatically closed as the block ends.
+
+* Handle#close
+ * closes the handle opened by the above Handle.new(lib).
+
+* sym = Handle#sym(func, prototype = "0"),
+ sym = Handle#[func, prototype = nil]
+
+ * obtains the pointer to a function called func and returns a Symbol object
+ or a DataPtr object. prototype is a string which consists of type
+ specifiers, it indicates the function's prototype. see also the section
+ `Type specifiers'.
+
+== Symbol class
+
+* sym = Symbol.new(addr, type = nil, name = nil)
+ * creates the Symbol object sym with the type type if type is not nil. addr
+ is the address where the function is allocated. If type is nil, it returns
+ a DataPtr object.
+
+* Symbol::char2type(char)
+ * takes a character char that represents a type and returns the type
+ specifier of the C language.
+
+* str = Symbol#proto()
+ * returns the function prototype.
+
+* str = Symbol#name()
+ * Returns the function name.
+
+* str = Symbol#cproto(),
+ str = Symbol#to_s()
+ * returns the prototype of the C language.
+
+* str = Symbol#inspect()
+ * returns the inspectable string.
+
+* r,rs = Symbol#call(arg1,arg2,...,argN),
+ r,rs = Symbol#[](arg1,arg2,...,argN)
+ * calls the function with parameters arg1, arg2, ..., argN. and the result
+ consists of the return value r and parameters rs. rs is an array.
+
+* ptr = Symbol#to_ptr
+ * returns the corresponding PtrData object ptr.
+
+== PtrData class
+
+* ptr = PtrData.new(addr, [size = 0, free = nil])
+ * returns the PtrData object representing the pointer which indicates the
+ address addr. GC frees the memory using the free function.
+
+* PtrData#free=(sym)
+ * If you specify a symbol object sym, GC frees the memory using the function
+ represented by sym.
+
+* sym = PtrData#free
+ * returns a symbol object sym which is used when GC frees the memory. it
+ usually configured by `PtrData#free=' or `PtrData.new'.
+
+* size = PtrData#size, PtrData#size=(size)
+ * gets and sets allocated size of the memory.
+
+* ary = PtrData#to_a(type, [size])
+ * returns an array of the type which specified with type. type must be one of
+ 'S','P','I','L','D' and 'F'.
+
+* str = PtrData#to_s([len])
+ * returns a string which length is len. if len is omitted, the end of the
+ string is '\0'.
+
+* ptr = PtrData#ptr,+@
+ * returns the pointed value as a PtrData object ptr.
+
+* ptr = PtrData#ref,-@
+ * returns the reference as a PtrData object ptr.
+
+* ptr = PtrData#+
+ * returns the PtrData object
+
+* ptr = PtrData#-
+ * returns the PtrData object
+
+* PtrData#struct!(type, *members)
+ * defines the data type to get access to a structure member with a symbol.
+ (see also PtrData#[])
+
+* PtrData#union!(type, *members)
+ * defines the data type to get access to a union member with a symbol. (see
+ also PtrData#[])
+
+* val = PtrData#[key], PtrData#[key, num = 0]
+ * if the key is a string or symbol, this method returns the value of the
+ structure/union member which has the type defined by PtrData#
+ {struct!,union!}. if the key is a integer value and this object represents
+ the pointer ptr, it returns the value of `(ptr + key).to_s(num)'
+
+* PtrData#[key,num]=val, PtrData#[key]=val
+ * if the key is a string or symbol, this method substitute the value of the
+ structure/union member with val. if the key is a integer value and val is a
+ string, this method copies num bytes of val to the memory area ptr using
+ memcpy(3).
+
+== Type specifiers
+
+the prototype consists of the following type specifiers, first element of
+prototype represents the type of return value, and remaining elements represent
+the type of each argument.
+
+ C : char
+ c : char *
+ H : short
+ h : short *
+ I : int
+ i : int *
+ L : long
+ l : long *
+ F : float
+ f : float *
+ D : double
+ d : double *
+ S : const char *
+ s : char *
+ A : const type[]
+ a : type[] (allocates new memory space)
+ P : void * (same as 'p')
+ p : void * (same as 'P')
+ 0 : void function (this must be a first character of the prototype)
+
+the cbtype consists of type specifiers 0, C, I, H, L, F, D, S and P.
+for example:
+
+ DL.callback('IPP'){|ptr1,ptr2|
+ str1 = ptr1.ptr.to_s
+ str2 = ptr2.ptr.to_s
+ str1 <=> str2
+ }
+=end
diff --git a/ext/dl/extconf.rb b/ext/dl/extconf.rb
index 99419b2d7d..beb15ab04c 100644
--- a/ext/dl/extconf.rb
+++ b/ext/dl/extconf.rb
@@ -1,30 +1,193 @@
require 'mkmf'
-if( RbConfig::CONFIG['CC'] =~ /gcc/ )
+begin # for the exception SystemExit
+
+$:.unshift File.dirname(__FILE__)
+require 'type'
+
+if( ARGV.include?("--help") )
+ print <<EOF
+ --help print this messages
+ --with-type-char strictly use type 'char'
+ --with-type-short strictly use type 'short'
+ --with-type-float strictly use type 'float'
+ --with-args=<max_arg>
+ --with-callback=<max_callback>
+ --enable-asm use the embedded assembler for passing arguments.
+ (this option is available for i386 machine now.)
+ --enable-dlstack use a stack emulation for constructing function call.
+EOF
+ exit(0)
+end
+
+($CPPFLAGS || $CFLAGS) << " -I."
+
+if (Config::CONFIG['CC'] =~ /gcc/) # from Win32API
$CFLAGS << " -fno-defer-pop -fno-omit-frame-pointer"
end
-$INSTALLFILES = [
- ["dl.h", "$(archdir)$(target_prefix)", ""],
-]
-$distcleanfiles << "callback.h"
+$with_dlstack ||= true
+$with_asm = ! $with_dlstack
+
+$with_type_int = try_cpp(<<EOF)
+#include "config.h"
+#if SIZEOF_INT == SIZEOF_LONG
+#error int not needed
+#endif
+EOF
+
+$with_type_float = try_cpp(<<EOF)
+#include "config.h"
+#if SIZEOF_FLOAT == SIZEOF_DOUBLE
+#error float not needed
+#endif
+EOF
+
+$with_type_voidp = try_cpp(<<EOF)
+#include "config.h"
+#if SIZEOF_VOIDP == SIZEOF_INT || SIZEOF_VOIDP == SIZEOF_LONG
+#error void* not needed
+#endif
+EOF
+$with_type_char = DLTYPE[CHAR][:sym]
+$with_type_short = DLTYPE[SHORT][:sym]
+$with_type_long = DLTYPE[LONG][:sym]
+$with_type_double= DLTYPE[DOUBLE][:sym]
+$with_type_int &= DLTYPE[INT][:sym]
+$with_type_float &= DLTYPE[FLOAT][:sym]
+$with_type_voidp &= DLTYPE[VOIDP][:sym]
+
+$with_type_char = enable_config("type-char", $with_type_char)
+$with_type_short = enable_config("type-short", $with_type_short)
+$with_type_float = enable_config("type-float", $with_type_float)
+
+$with_asm = enable_config("asm", $with_asm)
+$with_dlstack = enable_config("dlstack", $with_dlstack)
+
+args = with_config("args")
+max_arg = nil
+if( $with_asm || $with_dlstack )
+ $with_type_char = true
+ $with_type_short = true
+ $with_type_float = true
+ max_arg = 0
+end
+if( args )
+ max_arg = args.to_i
+ if( !max_arg )
+ print("--with-args=<max_arg>\n")
+ exit(1)
+ end
+end
+max_arg ||= 6
+
+max_callback = with_config("callback","10").to_i
+callback_types = DLTYPE.keys.length
+
+
+$dlconfig_h = <<EOF
+#define MAX_ARG #{max_arg}
+EOF
+
+def dlc_define(const)
+ $dlconfig_h << "#if !defined(#{const})\n" +
+ "# define #{const}\n" +
+ "#endif\n"
+end
+
+$dlconfig_h << "#define MAX_CALLBACK #{max_callback}\n"
+$dlconfig_h << "#define CALLBACK_TYPES #{callback_types}\n"
+if( $with_dlstack )
+ $dlconfig_h << "#define USE_DLSTACK\n"
+else
+ if( $with_asm )
+ $dlconfig_h << "#define USE_INLINE_ASM\n"
+ end
+end
+if( $with_type_char )
+ $dlconfig_h << "#define WITH_TYPE_CHAR\n"
+end
+if( $with_type_short )
+ $dlconfig_h << "#define WITH_TYPE_SHORT\n"
+end
+if( $with_type_long )
+ $dlconfig_h << "#define WITH_TYPE_LONG\n"
+end
+if( $with_type_double )
+ $dlconfig_h << "#define WITH_TYPE_DOUBLE\n"
+end
+if( $with_type_float )
+ $dlconfig_h << "#define WITH_TYPE_FLOAT\n"
+end
+if( $with_type_int )
+ $dlconfig_h << "#define WITH_TYPE_INT\n"
+end
+if( $with_type_voidp )
+ $dlconfig_h << "#define WITH_TYPE_VOIDP\n"
+end
+
+if( have_header("windows.h") )
+ have_library("kernel32")
+ have_func("GetLastError", "windows.h")
+ dlc_define("HAVE_WINDOWS_H")
+ have_windows_h = true
+end
-check = true
if( have_header("dlfcn.h") )
+ dlc_define("HAVE_DLFCN_H")
have_library("dl")
- check &&= have_func("dlopen")
- check &&= have_func("dlclose")
- check &&= have_func("dlsym")
- have_func("dlerror")
-elsif( have_header("windows.h") )
- check &&= have_func("LoadLibrary")
- check &&= have_func("FreeLibrary")
- check &&= have_func("GetProcAddress")
+ have_func("dlopen")
+ have_func("dlclose")
+ have_func("dlsym")
+ if( have_func("dlerror") )
+ dlc_define("HAVE_DLERROR")
+ end
+elsif ( have_windows_h )
+ have_func("LoadLibrary")
+ have_func("FreeLibrary")
+ have_func("GetProcAddress")
else
- check = false
+ exit(0)
end
-if( check )
- create_makefile("dl")
+def File.update(file, str)
+ begin
+ open(file){|f|f.read} == str
+ rescue Errno::ENOENT
+ false
+ end or open(file, "w"){|f|f.print(str)}
+end
+
+File.update("dlconfig.h", <<EOF)
+#ifndef DLCONFIG_H
+#define DLCONFIG_H
+#{$dlconfig_h}
+#endif /* DLCONFIG_H */
+EOF
+
+File.update("dlconfig.rb", <<EOF)
+MAX_ARG = #{max_arg}
+MAX_CALLBACK = #{max_callback}
+CALLBACK_TYPES = #{callback_types}
+DLTYPE[CHAR][:sym] = #{$with_type_char}
+DLTYPE[SHORT][:sym] = #{$with_type_short}
+DLTYPE[INT][:sym] = #{$with_type_int}
+DLTYPE[LONG][:sym] = #{$with_type_long}
+DLTYPE[FLOAT][:sym] = #{$with_type_float}
+DLTYPE[DOUBLE][:sym]= #{$with_type_double}
+DLTYPE[VOIDP][:sym] = #{$with_type_voidp}
+EOF
+
+$INSTALLFILES = [
+ ["./dlconfig.h", "$(archdir)$(target_prefix)", "."],
+ ["dl.h", "$(archdir)$(target_prefix)", ""],
+]
+$cleanfiles = %w[test/test.o]
+$distcleanfiles = %w[call.func callback.func cbtable.func dlconfig.rb
+./dlconfig.h test/libtest.so test/*~ *~ mkmf.log]
+
+create_makefile('dl')
+rescue SystemExit
+ # do nothing
end
diff --git a/ext/dl/h2rb b/ext/dl/h2rb
new file mode 100644
index 0000000000..00fbd60c82
--- /dev/null
+++ b/ext/dl/h2rb
@@ -0,0 +1,500 @@
+#!/usr/bin/env ruby
+# -*- ruby -*-
+# $Id$
+
+require 'mkmf'
+require 'ftools'
+
+$recursive = false
+$force = false
+$conly = true
+$inc_path = []
+$infilename= nil
+$insert_require = true
+
+def valid_ruby_code?(code)
+ begin
+ eval("BEGIN {return true}; #{code}")
+ rescue SyntaxError
+ return false
+ end
+ return false
+end
+
+def print_usage
+ print <<EOF
+h2rb [-r] [-I <path>] [-d] [<filename>]
+EOF
+end
+
+while( ARGV[0] )
+ case( ARGV[0] )
+ when "-r"
+ ARGV.shift
+ $recursive = true
+ when "-R"
+ ARGV.shift
+ $recursive = false
+ when "-l"
+ ARGV.shift
+ $insert_require = true
+ when "-L"
+ ARGV.shift
+ $insert_require = false
+ when "-c"
+ ARGV.shift
+ $conly = true
+ when "-C"
+ ARGV.shift
+ $conly = false
+ when "-f"
+ ARGV.shift
+ $force = true
+ when "-F"
+ ARGV.shift
+ $force = false
+ when "-I"
+ ARGV.shift
+ $inc_path << ARGV.shift
+ when "-d"
+ ARGV.shift
+ $DEBUG = true
+ when "-h","--help"
+ print_usage()
+ exit 0
+ when /-.*/
+ $stderr.print("unknown option '#{ARGV[0]}'.\n")
+ print_usage()
+ exit 0
+ else
+ $infilename = ARGV.shift
+ end
+end
+
+$inc_dir = File.join(CONFIG["prefix"], "lib", "ruby",
+ CONFIG["MAJOR"] + "." + CONFIG["MINOR"],
+ "dl")
+
+class H2RBError < StandardError; end
+
+
+class H2RB
+ def initialize(inc_dir = nil, inc_path = nil, insert_require = nil)
+ @inc_path = inc_path || []
+ @inc_dir = inc_dir || '.'
+ @indent = 0
+ @parsed_files = []
+ @insert_require = insert_require || false
+ end
+
+ def find_path(file)
+ if( ! file )
+ return nil
+ end
+ if( File.exist?(file) )
+ if( file[0] == ?/ )
+ return file
+ else
+ return file
+ end
+ end
+ @inc_path.each{|path|
+ full = File.join(path, file)
+ if( File.exist?(full) )
+ return full
+ end
+ }
+ return nil
+ end
+
+ def strip_comment(line)
+ if( @commented )
+ if( e = line.index("*/") )
+ line[0..(e+1)] = ""
+ @commented = false
+ else
+ line = ""
+ end
+ else
+ if( s = line.index("/*") )
+ if( e = line.index("*/") )
+ line[s..(e+1)] = ""
+ else
+ line[s..-1] = ""
+ @commented = true
+ end
+ elsif( s = line.index("//") )
+ line[s..(-1)] = ""
+ end
+ end
+
+ line.gsub!(/\s+$/,"")
+ return line
+ end
+
+ def up_indent
+ @indent += 1
+ end
+
+ def down_indent
+ @indent -= 1
+ if( @indent < 0 )
+ raise
+ end
+ end
+
+ def indent
+ " " * @indent
+ end
+
+ def rescue_begin
+ line = "#{indent}begin"
+ up_indent
+ return line
+ end
+
+ def rescue_nameerror
+ down_indent
+ line = [
+ "#{indent}rescue NameError => e",
+ "#{indent} raise e if( $DEBUG )",
+ "#{indent}end"].join($/)
+ return line
+ end
+
+ def parse_enum(line)
+ if( line =~ /enum\s+(\S+\s+)?\{(.+)\}/ )
+ enum_name = $1
+ enum_block = $2
+ if( enum_name )
+ line = "#{indent}# -- enum #{enum_name}\n"
+ else
+ line = "#{indent}# -- enum\n"
+ end
+ enums = enum_block.split(/,/).collect{|e| e.strip}
+ i = 0
+ enums.each{|elem|
+ var,val = elem.split(/=/).collect{|e| e.strip}
+ if( val )
+ i = val.to_i
+ end
+ line += "#{indent}#{var} = #{i.to_s}\n"
+ i += 1
+ }
+ line += "#{indent}# -- end of enum"
+ return line
+ else
+ return nil
+ end
+ end
+
+ def parse_define(line)
+ case line
+ when /^#\s*define\s+(\S+)\(\)/
+ line = nil
+ when /^#\s*define\s+(\S+)\((.+)\)\s+(.+)$/
+ if( @conly )
+ line = nil
+ else
+ defname = $1
+ defargs = $2
+ defval = $3
+ if( !valid_ruby_code?(defval) )
+ defval = "nil # #{defval}"
+ end
+ if( defname[0,1] =~ /^[A-Z]$/ )
+ line = "#{indent}#{defname} = proc{|#{defargs}| #{defval}}"
+ else
+ line = [
+ "#{indent}def #{defname}(#{defargs})",
+ "#{indent} #{defval}",
+ "#{indent}end"
+ ].join("\n")
+ end
+ end
+ when /^#\s*define\s+(\S+)\((.+)\)$/
+ if( @conly )
+ line = nil
+ else
+ defname = $1
+ defargs = $2
+ defval = nil
+ if( !valid_ruby_code?(defval) )
+ defval = "nil # #{defval}"
+ end
+ if( defname[0,1] =~ /^[A-Z]$/ )
+ line = "#{indent}#{defname} = proc{|#{defargs}| #{defval}}"
+ else
+ line = [
+ "#{indent}def #{defname}(#{defargs})",
+ "#{indent} #{defval}",
+ "#{indent}end"
+ ].join("\n")
+ end
+ end
+ when /^#\s*define\s+(\S+)\s+(.+)$/
+ defname = $1
+ defval = $2
+ if( !valid_ruby_code?(defval) )
+ defval = "nil # #{defval}"
+ end
+ line = [rescue_begin, "#{indent}#{defname} = #{defval}", rescue_nameerror].join($/)
+ when /^#\s*define\s+(\S+)$/
+ defname = $1
+ line = "#{indent}#{defname} = nil"
+ else
+ line = nil
+ end
+ return line
+ end
+
+ def parse_undef(line)
+ case line
+ when /^#\s*undef\s+([A-Z]\S+)$/
+ defname = $1
+ line = "#{indent}remove_const(:#{defname})"
+ when /^#\s*undef\s+(\S+)$/
+ defname = $1
+ line = "#{indent}#{defname} = nil"
+ else
+ line = nil
+ end
+ return line
+ end
+
+ def parse_ifdef(line)
+ case line
+ when /^#\s*ifdef\s+(\S+)$/
+ defname = $1
+ line = [
+ rescue_begin,
+ "#{indent}if( defined?(#{defname}) && ! #{defname}.nil? )"].join($/)
+ else
+ line = nil
+ end
+ return line
+ end
+
+ def parse_ifndef(line)
+ case line
+ when /^#\s*ifndef\s+(\S+)$/
+ defname = $1
+ line = [
+ rescue_begin,
+ "#{indent}if( ! defined?(#{defname}) || #{defname}.nil? )"].join($/)
+ else
+ line = nil
+ end
+ return line
+ end
+
+ def parse_if(line)
+ case line
+ when /^#\s*if\s+(.+)$/
+ cond = $1
+ cond.gsub!(/defined(.+)/){ "defined?(#{$1}) && ! #{$1}.nil?" }
+ if( valid_ruby_code?(cond) )
+ line = "#{indent}if( #{cond} )"
+ else
+ line = "#{indent}if( false ) # #{cond}"
+ end
+ line = [rescue_begin, line].join($/)
+ else
+ line = nil
+ end
+ return line
+ end
+
+ def parse_elif(line)
+ case line
+ when /^#\s*elif\s+(.+)$/
+ cond = $1
+ cond.gsub!("defined","defined?")
+ line = "#{indent}elsif( #{cond} )"
+ else
+ line = nil
+ end
+ return line
+ end
+
+ def parse_else(line)
+ case line
+ when /^#\s*else\s*/
+ line = "#{indent}else"
+ else
+ line = nil
+ end
+ return line
+ end
+
+ def parse_endif(line)
+ case line
+ when /^#\s*endif\s*$/
+ line = ["#{indent}end", rescue_nameerror].join($/)
+ else
+ line = nil
+ end
+ return line
+ end
+
+ def parse_include(line)
+ if( ! @insert_require )
+ return nil
+ end
+
+ file = nil
+ case line
+ when /^#\s*include "(.+)"$/
+ file = $1
+ line = "#{indent}require '#{file}'"
+ when /^#\s*include \<(.+)\>$/
+ file = $1
+ line = "#{indent}require '#{file}'"
+ else
+ line = nil
+ end
+ if( @recursive && file && (!@parsed_files.include?(file)) )
+ parse(file, @recursive, @force, @conly)
+ end
+ return line
+ end
+
+
+ def open_files(infilename)
+ if( ! infilename )
+ return [$stdin, $stdout]
+ end
+
+ old_infilename = infilename
+ infilename = find_path(infilename)
+ if( ! infilename )
+ $stderr.print("'#{old_infilename}' was not found.\n")
+ return [nil,nil]
+ end
+
+ if( infilename )
+ if( infilename[0,1] == '/' )
+ outfilename = File.join(@inc_dir, infilename[1..-1] + ".rb")
+ else
+ outfilename = infilename + ".rb"
+ end
+ File.mkpath(File.dirname(outfilename))
+ else
+ outfilename = nil
+ end
+
+ if( infilename )
+ fin = File.open(infilename,"r")
+ else
+ fin = $stdin
+ end
+ if( outfilename )
+ if( File.exist?(outfilename) && (!@force) )
+ $stderr.print("'#{outfilename}' have already existed.\n")
+ return [fin, nil]
+ end
+ fout = File.open(outfilename,"w")
+ else
+ fout = $stdout
+ end
+
+ $stderr.print("#{infilename} -> #{outfilename}\n")
+ if( fout )
+ dir = File.dirname(outfilename)
+ if( dir[0,1] != "." && dir != "" )
+ fout.print("if( ! $LOAD_PATH.include?('#{dir}') )\n",
+ " $LOAD_PATH.push('#{dir}')\n",
+ "end\n")
+ end
+ end
+ return [fin,fout]
+ end
+
+ def parse(infilename = nil, recursive = false, force = false, conly = false)
+ @commented = false
+ @recursive = recursive
+ @force = force
+ @conly = conly
+ @parsed_files << infilename
+
+ fin,fout = open_files(infilename)
+ if( !fin )
+ return
+ end
+
+ begin
+ line_number = 0
+ pre_line = nil
+ fin.each_line{|line|
+ line_number += 1
+ line.chop!
+ if( $DEBUG )
+ $stderr.print("#{line_number}:(#{@indent}):", line, "\n")
+ end
+
+ if( pre_line )
+ line = pre_line + line
+ pre_line = nil
+ end
+
+ if( line[-1,1] == "\\" )
+ pre_line = line[0..-2]
+ next
+ end
+
+ if( eidx = line.index("enum ") )
+ pre_line = line[eidx .. -1]
+ if( i = line.index("{") && j = line.index("}") )
+ line = line[0..j]
+ pre_line = nil
+ else
+ next
+ end
+ end
+
+ line = strip_comment(line)
+ case line
+ when /^enum\s/
+ line = parse_enum(line)
+ when /^#\s*define\s/
+ line = parse_define(line)
+ when /^#\s*undef\s/
+ line = parse_undef(line)
+ when /^#\s*ifdef\s/
+ line = parse_ifdef(line)
+ up_indent
+ when /^#\s*ifndef\s/
+ line = parse_ifndef(line)
+ up_indent
+ when /^#\s*if\s/
+ line = parse_if(line)
+ up_indent
+ when /^#\s*elif\s/
+ down_indent
+ line = parse_elif(line)
+ up_indent
+ when /^#\s*else/
+ down_indent
+ line = parse_else(line)
+ up_indent
+ when /^#\s*endif/
+ down_indent
+ line = parse_endif(line)
+ when /^#\s*include\s/
+ line = parse_include(line)
+ else
+ line = nil
+ end
+ if( line && fout )
+ fout.print(line, " # #{line_number}",$/)
+ end
+ }
+ ensure
+ fin.close if fin
+ fout.close if fout
+ end
+ end
+end
+
+h2rb = H2RB.new($inc_dir, $inc_path, $insert_require)
+h2rb.parse($infilename, $recursive, $force, $conly)
diff --git a/ext/dl/handle.c b/ext/dl/handle.c
index 24269dfd78..69d47caac0 100644
--- a/ext/dl/handle.c
+++ b/ext/dl/handle.c
@@ -10,7 +10,7 @@ VALUE rb_cDLHandle;
void
dlhandle_free(struct dl_handle *dlhandle)
{
- if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
+ if (dlhandle->ptr && dlhandle->open && dlhandle->enable_close) {
dlclose(dlhandle->ptr);
}
}
@@ -50,11 +50,7 @@ rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
int cflag;
const char *err;
- switch( rb_scan_args(argc, argv, "02", &lib, &flag) ){
- case 0:
- clib = NULL;
- cflag = RTLD_LAZY | RTLD_GLOBAL;
- break;
+ switch (rb_scan_args(argc, argv, "11", &lib, &flag)) {
case 1:
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
cflag = RTLD_LAZY | RTLD_GLOBAL;
@@ -69,24 +65,24 @@ rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
ptr = dlopen(clib, cflag);
#if defined(HAVE_DLERROR)
- if( !ptr && (err = dlerror()) ){
- rb_raise(rb_eDLError, "%s", err);
+ if (!ptr && (err = dlerror())) {
+ rb_raise(rb_eRuntimeError, "%s", err);
}
#else
- if( !ptr ){
+ if (!ptr) {
err = dlerror();
- rb_raise(rb_eDLError, "%s", err);
+ rb_raise(rb_eRuntimeError, "%s", err);
}
#endif
Data_Get_Struct(self, struct dl_handle, dlhandle);
- if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
+ if (dlhandle->ptr && dlhandle->open && dlhandle->enable_close) {
dlclose(dlhandle->ptr);
}
dlhandle->ptr = ptr;
dlhandle->open = 1;
dlhandle->enable_close = 0;
- if( rb_block_given_p() ){
+ if (rb_block_given_p()) {
rb_ensure(rb_yield, self, rb_dlhandle_close, self);
}
@@ -119,109 +115,101 @@ rb_dlhandle_to_i(VALUE self)
struct dl_handle *dlhandle;
Data_Get_Struct(self, struct dl_handle, dlhandle);
- return PTR2NUM(dlhandle);
+ return DLLONG2NUM(dlhandle);
}
VALUE
-rb_dlhandle_sym(VALUE self, VALUE sym)
+rb_dlhandle_to_ptr(VALUE self)
{
- void (*func)();
- struct dl_handle *dlhandle;
- void *handle;
- const char *name;
- const char *err;
- int i;
+ struct dl_handle *dlhandle;
-#if defined(HAVE_DLERROR)
-# define CHECK_DLERROR if( err = dlerror() ){ func = 0; }
-#else
-# define CHECK_DLERROR
-#endif
+ Data_Get_Struct(self, struct dl_handle, dlhandle);
+ return rb_dlptr_new(dlhandle, sizeof(dlhandle), 0);
+}
- rb_secure(2);
+VALUE
+rb_dlhandle_sym(int argc, VALUE argv[], VALUE self)
+{
+ VALUE sym, type;
+ void (*func)();
+ VALUE val;
+ struct dl_handle *dlhandle;
+ void *handle;
+ const char *name, *stype;
+ const char *err;
+
+ rb_secure(2);
+ if (rb_scan_args(argc, argv, "11", &sym, &type) == 2) {
+ SafeStringValue(type);
+ stype = StringValuePtr(type);
+ }
+ else{
+ stype = NULL;
+ }
- if( sym == Qnil ){
+ if (sym == Qnil) {
#if defined(RTLD_NEXT)
- name = RTLD_NEXT;
+ name = RTLD_NEXT;
#else
- name = NULL;
+ name = NULL;
#endif
- }
- else{
- name = StringValuePtr(sym);
- }
-
+ }
+ else{
+ SafeStringValue(sym);
+ name = StringValuePtr(sym);
+ }
- Data_Get_Struct(self, struct dl_handle, dlhandle);
- if( ! dlhandle->open ){
- rb_raise(rb_eDLError, "closed handle");
- }
- handle = dlhandle->ptr;
+ Data_Get_Struct(self, struct dl_handle, dlhandle);
+ if (!dlhandle->open) {
+ rb_raise(rb_eRuntimeError, "closed handle");
+ }
+ handle = dlhandle->ptr;
- func = dlsym(handle, name);
- CHECK_DLERROR;
- if( !func ){
+ func = dlsym(handle, name);
+#if defined(HAVE_DLERROR)
+ if (!func && (err = dlerror()))
+#else
+ if (!func)
+#endif
+ {
#if defined(__CYGWIN__) || defined(WIN32) || defined(__MINGW32__)
- {
- int len = strlen(name);
- char *name_a = (char*)xmalloc(len+2);
- strcpy(name_a, name);
- name_a[len] = 'A';
- name_a[len+1] = '\0';
- func = dlsym(handle, name_a);
- xfree(name_a);
- CHECK_DLERROR;
- if( !func ){
- for( i = 0; i < 256; i += 4 ){
- int len = strlen(name);
- char *name_n = (char*)xmalloc(len+5);
- sprintf(name_n, "%s@%d%c", name, i, 0);
- func = dlsym(handle, name_n);
- xfree(name_n);
- CHECK_DLERROR;
- if( func )
- {
- break;
- }
- }
- CHECK_DLERROR;
- if( !func ){
- rb_raise(rb_eDLError, "unknown symbol \"%s\"", name);
- }
- }
- }
+ {
+ int len = strlen(name);
+ char *name_a = (char*)dlmalloc(len+2);
+ strcpy(name_a, name);
+ name_a[len] = 'A';
+ name_a[len+1] = '\0';
+ func = dlsym(handle, name_a);
+ dlfree(name_a);
+#if defined(HAVE_DLERROR)
+ if (!func && (err = dlerror()))
#else
- for( i = 0; i < 256; i += 4 ){
- int len = strlen(name);
- char *name_n = (char*)xmalloc(len+4);
- sprintf(name_n, "%s@%d", name, i);
- func = dlsym(handle, name_n);
- xfree(name_n);
- CHECK_DLERROR;
- if( func ){
- break;
- }
- }
- CHECK_DLERROR;
- if( !func ){
- rb_raise(rb_eDLError, "unknown symbol \"%s\"", name);
- }
+ if (!func)
#endif
+ {
+ rb_raise(rb_eRuntimeError, "unknown symbol \"%sA\"", name);
+ }
}
+#else
+ rb_raise(rb_eRuntimeError, "unknown symbol \"%s\"", name);
+#endif
+ }
+ val = rb_dlsym_new(func, name, stype);
- return PTR2NUM(func);
+ return val;
}
void
Init_dlhandle()
{
- rb_cDLHandle = rb_define_class_under(rb_mDL, "Handle", rb_cObject);
- rb_define_alloc_func(rb_cDLHandle, rb_dlhandle_s_allocate);
- rb_define_method(rb_cDLHandle, "initialize", rb_dlhandle_initialize, -1);
- rb_define_method(rb_cDLHandle, "to_i", rb_dlhandle_to_i, 0);
- rb_define_method(rb_cDLHandle, "close", rb_dlhandle_close, 0);
- rb_define_method(rb_cDLHandle, "sym", rb_dlhandle_sym, 1);
- rb_define_method(rb_cDLHandle, "[]", rb_dlhandle_sym, 1);
- rb_define_method(rb_cDLHandle, "disable_close", rb_dlhandle_disable_close, 0);
- rb_define_method(rb_cDLHandle, "enable_close", rb_dlhandle_enable_close, 0);
+ rb_cDLHandle = rb_define_class_under(rb_mDL, "Handle", rb_cObject);
+ rb_define_alloc_func(rb_cDLHandle, rb_dlhandle_s_allocate);
+ rb_define_method(rb_cDLHandle, "initialize", rb_dlhandle_initialize, -1);
+ rb_define_method(rb_cDLHandle, "to_i", rb_dlhandle_to_i, 0);
+ rb_define_method(rb_cDLHandle, "to_ptr", rb_dlhandle_to_ptr, 0);
+ rb_define_method(rb_cDLHandle, "close", rb_dlhandle_close, 0);
+ rb_define_method(rb_cDLHandle, "sym", rb_dlhandle_sym, -1);
+ rb_define_method(rb_cDLHandle, "[]", rb_dlhandle_sym, -1);
+ rb_define_method(rb_cDLHandle, "disable_close", rb_dlhandle_disable_close, 0);
+ rb_define_method(rb_cDLHandle, "enable_close", rb_dlhandle_enable_close, 0);
}
diff --git a/ext/dl/install.rb b/ext/dl/install.rb
new file mode 100644
index 0000000000..69b1834301
--- /dev/null
+++ b/ext/dl/install.rb
@@ -0,0 +1,49 @@
+require 'mkmf'
+require 'ftools'
+
+SO_LIBS = ["dl.so"]
+
+$ruby_version = CONFIG['MAJOR'] + "." + CONFIG['MINOR']
+$prefix = CONFIG['prefix']
+$libdir = File.join($prefix,'lib')
+$rubylibdir = File.join($libdir, 'ruby', $ruby_version)
+$arch = CONFIG['arch']
+$archdir = File.join($rubylibdir, $arch)
+
+def find(dir, match = /./)
+ Dir.chdir(dir)
+ files = []
+ Dir.new(".").each{|file|
+ if( file != "." && file != ".." )
+ case File.ftype(file)
+ when "file"
+ if( file =~ match )
+ files.push(File.join(dir,file))
+ end
+ when "directory"
+ files += find(file, match).collect{|f| File.join(dir,f)}
+ end
+ end
+ }
+ Dir.chdir("..")
+ return files
+end
+
+def install()
+ rb_files = find(File.join(".","lib"), /.rb$/)
+
+ SO_LIBS.each{|f|
+ File.makedirs($rubylibdir, "#{$archdir}")
+ File.install(f, File.join($archdir,f), 0555, true)
+ }
+
+ rb_files.each{|f|
+ origfile = f
+ instfile = File.join($rubylibdir, origfile.sub("./lib/",""))
+ instdir = File.dirname(instfile)
+ File.makedirs(instdir)
+ File.install(origfile, instfile, 0644, true)
+ }
+end
+
+install()
diff --git a/ext/dl/lib/dl/callback.rb b/ext/dl/lib/dl/callback.rb
deleted file mode 100644
index d0b2c7a819..0000000000
--- a/ext/dl/lib/dl/callback.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-require 'dl'
-require 'thread'
-
-module DL
- SEM = Mutex.new
-
- def set_callback_internal(proc_entry, addr_entry, argc, ty, &cbp)
- if( argc < 0 )
- raise(ArgumentError, "arity should not be less than 0.")
- end
- addr = nil
- SEM.synchronize{
- ary = proc_entry[ty]
- (0...MAX_CALLBACK).each{|n|
- idx = (n * DLSTACK_SIZE) + argc
- if( ary[idx].nil? )
- ary[idx] = cbp
- addr = addr_entry[ty][idx]
- break
- end
- }
- }
- addr
- end
-
- def set_cdecl_callback(ty, argc, &cbp)
- set_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, argc, ty, &cbp)
- end
-
- def set_stdcall_callback(ty, argc, &cbp)
- set_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, argc, ty, &cbp)
- end
-
- def remove_callback_internal(proc_entry, addr_entry, addr, ctype = nil)
- index = nil
- if( ctype )
- addr_entry[ctype].each_with_index{|xaddr, idx|
- if( xaddr == addr )
- index = idx
- end
- }
- else
- addr_entry.each{|ty,entry|
- entry.each_with_index{|xaddr, idx|
- if( xaddr == addr )
- index = idx
- end
- }
- }
- end
- if( proc_entry[ctype][index] )
- proc_entry[ctype][index] = nil
- return true
- else
- return false
- end
- end
-
- def remove_cdecl_callback(addr, ctype = nil)
- remove_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, addr, ctype)
- end
-
- def remove_stdcall_callback(addr, ctype = nil)
- remove_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, addr, ctype)
- end
-
- alias set_callback set_cdecl_callback
- alias remove_callback remove_cdecl_callback
-end
diff --git a/ext/dl/lib/dl/cparser.rb b/ext/dl/lib/dl/cparser.rb
deleted file mode 100644
index c897d1b69f..0000000000
--- a/ext/dl/lib/dl/cparser.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-module DL
- module CParser
- def parse_struct_signature(signature, tymap=nil)
- if( signature.is_a?(String) )
- signature = signature.split("\s*,\s*")
- end
- mems = []
- tys = []
- signature.each{|msig|
- tks = msig.split(/\s+(\*)?/)
- ty = tks[0..-2].join(" ")
- member = tks[-1]
-
- case ty
- when /\[(\d+)\]/
- n = $1.to_i
- ty.gsub!(/\s*\[\d+\]/,"")
- ty = [ty, n]
- when /\[\]/
- ty.gsub!(/\s*\[\]/, "*")
- end
-
- case member
- when /\[(\d+)\]/
- ty = [ty, $1.to_i]
- member.gsub!(/\s*\[\d+\]/,"")
- when /\[\]/
- ty = ty + "*"
- member.gsub!(/\s*\[\]/, "")
- end
-
- mems.push(member)
- tys.push(parse_ctype(ty,tymap))
- }
- return tys, mems
- end
-
- def parse_signature(signature, tymap=nil)
- tymap ||= {}
- signature = signature.gsub(/\s+/, " ").strip
- case signature
- when /^([\d\w@\*_\s]+)\(([\d\w\*_\s\,\[\]]*)\)$/
- ret = $1
- args = $2
- ret = ret.split(/\s+/)
- args = args.split(/\s*,\s*/)
- func = ret.pop
- if( func =~ /^\*/ )
- func.gsub!(/^\*+/,"")
- ret.push("*")
- end
- ret = ret.join(" ")
- return [func, parse_ctype(ret, tymap), args.collect{|arg| parse_ctype(arg, tymap)}]
- else
- raise(RuntimeError,"can't parse the function prototype: #{proto}")
- end
- end
-
- def parse_ctype(ty, tymap=nil)
- tymap ||= {}
- case ty
- when Array
- return [parse_ctype(ty[0], tymap), ty[1]]
- when "void"
- return TYPE_VOID
- when "char"
- return TYPE_CHAR
- when "unsigned char"
- return -TYPE_CHAR
- when "short"
- return TYPE_SHORT
- when "unsigned short"
- return -TYPE_SHORT
- when "int"
- return TYPE_INT
- when "unsigned int"
- return -TYPE_INT
- when "long"
- return TYPE_LONG
- when "unsigned long"
- return -TYPE_LONG
- when "long long"
- if( defined?(TYPE_LONG_LONG) )
- return TYPE_LONG_LONG
- else
- raise(RuntimeError, "unsupported type: #{ty}")
- end
- when "unsigned long long"
- if( defined?(TYPE_LONG_LONG) )
- return -TYPE_LONG_LONG
- else
- raise(RuntimeError, "unsupported type: #{ty}")
- end
- when "float"
- return TYPE_FLOAT
- when "double"
- return TYPE_DOUBLE
- when /\*/, /\[\s*\]/
- return TYPE_VOIDP
- else
- if( tymap[ty] )
- return parse_ctype(tymap[ty], tymap)
- else
- raise(DLError, "unknown type: #{ty}")
- end
- end
- end
- end
-end
diff --git a/ext/dl/lib/dl/func.rb b/ext/dl/lib/dl/func.rb
deleted file mode 100644
index b29aebcc8b..0000000000
--- a/ext/dl/lib/dl/func.rb
+++ /dev/null
@@ -1,141 +0,0 @@
-require 'dl'
-require 'dl/callback'
-require 'dl/stack'
-require 'dl/value'
-require 'thread'
-
-module DL
- class Function
- include DL
- include ValueUtil
-
- def initialize(cfunc, argtypes, &proc)
- @cfunc = cfunc
- @stack = Stack.new(argtypes.collect{|ty| ty.abs})
- if( @cfunc.ctype < 0 )
- @cfunc.ctype = @cfunc.ctype.abs
- @unsigned = true
- end
- if( proc )
- bind(&proc)
- end
- end
-
- def to_i()
- @cfunc.to_i
- end
-
- def call(*args, &block)
- funcs = []
- args = wrap_args(args, @stack.types, funcs, &block)
- r = @cfunc.call(@stack.pack(args))
- funcs.each{|f| f.unbind_at_call()}
- return wrap_result(r)
- end
-
- def wrap_result(r)
- case @cfunc.ctype
- when TYPE_VOIDP
- r = CPtr.new(r)
- else
- if( @unsigned )
- r = unsigned_value(r, @cfunc.ctype)
- end
- end
- r
- end
-
- def bind(&block)
- if( !block )
- raise(RuntimeError, "block must be given.")
- end
- if( @cfunc.ptr == 0 )
- cb = Proc.new{|*args|
- ary = @stack.unpack(args)
- @stack.types.each_with_index{|ty, idx|
- case ty
- when TYPE_VOIDP
- ary[idx] = CPtr.new(ary[idx])
- end
- }
- r = block.call(*ary)
- wrap_arg(r, @cfunc.ctype, [])
- }
- case @cfunc.calltype
- when :cdecl
- @cfunc.ptr = set_cdecl_callback(@cfunc.ctype, @stack.size, &cb)
- when :stdcall
- @cfunc.ptr = set_stdcall_callback(@cfunc.ctype, @stack.size, &cb)
- else
- raise(RuntimeError, "unsupported calltype: #{@cfunc.calltype}")
- end
- if( @cfunc.ptr == 0 )
- raise(RuntimeException, "can't bind C function.")
- end
- end
- end
-
- def unbind()
- if( @cfunc.ptr != 0 )
- case @cfunc.calltype
- when :cdecl
- remove_cdecl_callback(@cfunc.ptr, @cfunc.ctype)
- when :stdcall
- remove_stdcall_callback(@cfunc.ptr, @cfunc.ctype)
- else
- raise(RuntimeError, "unsupported calltype: #{@cfunc.calltype}")
- end
- @cfunc.ptr = 0
- end
- end
-
- def bind_at_call(&block)
- bind(&block)
- end
-
- def unbind_at_call()
- end
- end
-
- class TempFunction < Function
- def bind_at_call(&block)
- bind(&block)
- end
-
- def unbind_at_call()
- unbind()
- end
- end
-
- class CarriedFunction < Function
- def initialize(cfunc, argtypes, n)
- super(cfunc, argtypes)
- @carrier = []
- @index = n
- @mutex = Mutex.new
- end
-
- def create_carrier(data)
- ary = []
- userdata = [ary, data]
- @mutex.lock()
- @carrier.push(userdata)
- return dlwrap(userdata)
- end
-
- def bind_at_call(&block)
- userdata = @carrier[-1]
- userdata[0].push(block)
- bind{|*args|
- ptr = args[@index]
- if( !ptr )
- raise(RuntimeError, "The index of userdata should be lower than #{args.size}.")
- end
- userdata = dlunwrap(Integer(ptr))
- args[@index] = userdata[1]
- userdata[0][0].call(*args)
- }
- @mutex.unlock()
- end
- end
-end
diff --git a/ext/dl/lib/dl/import.rb b/ext/dl/lib/dl/import.rb
index f04b0f9142..01ee2490e8 100644
--- a/ext/dl/lib/dl/import.rb
+++ b/ext/dl/lib/dl/import.rb
@@ -1,215 +1,225 @@
+# -*- ruby -*-
+
require 'dl'
-require 'dl/func.rb'
-require 'dl/struct.rb'
-require 'dl/cparser.rb'
+require 'dl/types'
module DL
- class CompositeHandler
- def initialize(handlers)
- @handlers = handlers
- end
-
- def handlers()
- @handlers
- end
-
- def sym(symbol)
- @handlers.each{|handle|
- if( handle )
- begin
- addr = handle.sym(symbol)
- return addr
- rescue DLError
- end
- end
- }
- return nil
- end
-
- def [](symbol)
- sym(symbol)
- end
- end
-
- module Importer
- include DL
- include CParser
- extend Importer
-
- def dlload(*libs)
- handles = libs.collect{|lib|
- case lib
- when nil
- nil
- when Handle
- lib
- when Importer
- lib.handlers
- else
- begin
- DL.dlopen(lib)
- rescue DLError
- raise(DLError, "can't load #{lib}")
- end
- end
- }.flatten()
- @handler = CompositeHandler.new(handles)
- @func_map = {}
- @type_alias = {}
- end
-
- def typealias(alias_type, orig_type)
- @type_alias[alias_type] = orig_type
- end
-
- def sizeof(ty)
- case ty
- when String
- ty = parse_ctype(ty, @type_alias).abs()
- case ty
- when TYPE_CHAR
- return SIZEOF_CHAR
- when TYPE_SHORT
- return SIZEOF_SHORT
- when TYPE_INT
- return SIZEOF_INT
- when TYPE_LONG
- return SIZEOF_LONG
- when TYPE_LONG_LONG
- return SIZEOF_LONG_LON
- when TYPE_FLOAT
- return SIZEOF_FLOAT
- when TYPE_DOUBLE
- return SIZEOF_DOUBLE
- when TYPE_VOIDP
- return SIZEOF_VOIDP
- else
- raise(DLError, "unknown type: #{ty}")
- end
- when Class
- if( ty.instance_methods().include?("to_ptr") )
- return ty.size()
- end
+ module Importable
+ LIB_MAP = {}
+
+ module Internal
+ def init_types()
+ @types ||= ::DL::Types.new
+ end
+
+ def init_sym()
+ @SYM ||= {}
+ end
+
+ def [](name)
+ return @SYM[name.to_s][0]
+ end
+
+ def dlload(*libnames)
+ if( !defined?(@LIBS) )
+ @LIBS = []
+ end
+ libnames.each{|libname|
+ if( !LIB_MAP[libname] )
+ LIB_MAP[libname] = DL.dlopen(libname)
+ end
+ @LIBS.push(LIB_MAP[libname])
+ }
+ end
+ alias dllink :dlload
+
+ def parse_cproto(proto)
+ proto = proto.gsub(/\s+/, " ").strip
+ case proto
+ when /^([\d\w\*_\s]+)\(([\d\w\*_\s\,\[\]]*)\)$/
+ ret = $1
+ args = $2.strip()
+ ret = ret.split(/\s+/)
+ args = args.split(/\s*,\s*/)
+ func = ret.pop()
+ if( func =~ /^\*/ )
+ func.gsub!(/^\*+/,"")
+ ret.push("*")
+ end
+ ret = ret.join(" ")
+ return [func, ret, args]
+ else
+ raise(RuntimeError,"can't parse the function prototype: #{proto}")
+ end
end
- return CPtr[ty].size()
- end
-
- def parse_bind_options(opts)
- h = {}
- prekey = nil
- while( opt = opts.shift() )
- case opt
- when :stdcall, :cdecl
- h[:call_type] = opt
- when :carried, :temp, :temporal, :bind
- h[:callback_type] = opt
- h[:carrier] = opts.shift()
- else
- h[opt] = true
+
+ # example:
+ # extern "int strlen(char*)"
+ #
+ def extern(proto)
+ func,ret,args = parse_cproto(proto)
+ return import(func, ret, args)
+ end
+
+ # example:
+ # callback "int method_name(int, char*)"
+ #
+ def callback(proto)
+ func,ret,args = parse_cproto(proto)
+
+ init_types()
+ init_sym()
+
+ rty,renc,rdec = @types.encode_return_type(ret)
+ if( !rty )
+ raise(TypeError, "unsupported type: #{ret}")
end
+ ty,enc,dec = encode_argument_types(args)
+ symty = rty + ty
+
+ module_eval("module_function :#{func}")
+ sym = module_eval([
+ "DL::callback(\"#{symty}\"){|*args|",
+ " sym,rdec,enc,dec = @SYM['#{func}']",
+ " args = enc.call(args) if enc",
+ " r,rs = #{func}(*args)",
+ " r = renc.call(r) if rdec",
+ " rs = dec.call(rs) if (dec && rs)",
+ " @retval = r",
+ " @args = rs",
+ " r",
+ "}",
+ ].join("\n"))
+
+ @SYM[func] = [sym,rdec,enc,dec]
+
+ return sym
end
- h
- end
- private :parse_bind_options
-
- def extern(signature, *opts)
- symname, ctype, argtype = parse_signature(signature, @type_alias)
- opt = parse_bind_options(opts)
- f = import_function(symname, ctype, argtype, opt[:call_type])
- name = symname.gsub(/@.+/,'')
- @func_map[name] = f
- define_method(name){|*args,&block| f.call(*args,&block)}
- #module_eval(<<-EOS)
- # def #{name}(*args, &block)
- # @func_map['#{name}'].call(*args,&block)
- # end
- #EOS
- module_function(name)
- f
- end
-
- def bind(signature, *opts, &blk)
- name, ctype, argtype = parse_signature(signature, @type_alias)
- h = parse_bind_options(opts)
- case h[:callback_type]
- when :bind, nil
- f = bind_function(name, ctype, argtype, h[:call_type], &blk)
- when :temp, :temporal
- f = create_temp_function(name, ctype, argtype, h[:call_type])
- when :carried
- f = create_carried_function(name, ctype, argtype, h[:call_type], h[:carrier])
- else
- raise(RuntimeError, "unknown callback type: #{h[:callback_type]}")
+
+ # example:
+ # typealias("uint", "unsigned int")
+ #
+ def typealias(alias_type, ty1, enc1=nil, dec1=nil, ty2=nil, enc2=nil, dec2=nil)
+ init_types()
+ @types.typealias(alias_type, ty1, enc1, dec1,
+ ty2||ty1, enc2, dec2)
end
- @func_map[name] = f
- define_method(name){|*args,&block| f.call(*args,&block)}
- #module_eval(<<-EOS)
- # def #{name}(*args,&block)
- # @func_map['#{name}'].call(*args,&block)
- # end
- #EOS
- module_function(name)
- f
- end
-
- def struct(signature)
- tys, mems = parse_struct_signature(signature, @type_alias)
- DL::CStructBuilder.create(CStruct, tys, mems)
- end
-
- def union(signature)
- tys, mems = parse_struct_signature(signature, @type_alias)
- DL::CStructBuilder.create(CUnion, tys, mems)
- end
-
- def [](name)
- @func_map[name]
- end
-
- def create_value(ty, val=nil)
- s = struct([ty + " value"])
- ptr = s.malloc()
- if( val )
- ptr.value = val
+
+ # example:
+ # symbol "foo_value"
+ # symbol "foo_func", "IIP"
+ #
+ def symbol(name, ty = nil)
+ sym = nil
+ @LIBS.each{|lib|
+ begin
+ if( ty )
+ sym = lib[name, ty]
+ else
+ sym = lib[name]
+ end
+ rescue
+ next
+ end
+ }
+ if( !sym )
+ raise(RuntimeError, "can't find the symbol `#{name}'")
+ end
+ return sym
end
- return ptr
- end
- alias value create_value
-
- def import_value(ty, addr)
- s = struct([ty + " value"])
- ptr = s.new(addr)
- return ptr
- end
-
- def import_symbol(name)
- addr = @handler.sym(name)
- if( !addr )
- raise(DLError, "cannot find the symbol: #{name}")
+
+ # example:
+ # import("get_length", "int", ["void*", "int"])
+ #
+ def import(name, rettype, argtypes = nil)
+ init_types()
+ init_sym()
+
+ rty,_,rdec = @types.encode_return_type(rettype)
+ if( !rty )
+ raise(TypeError, "unsupported type: #{rettype}")
+ end
+ ty,enc,dec = encode_argument_types(argtypes)
+ symty = rty + ty
+
+ sym = symbol(name, symty)
+
+ mname = name.dup
+ if( ?A <= mname[0] && mname[0] <= ?Z )
+ mname[0,1] = mname[0,1].downcase
+ end
+ @SYM[mname] = [sym,rdec,enc,dec]
+
+ module_eval [
+ "def #{mname}(*args)",
+ " sym,rdec,enc,dec = @SYM['#{mname}']",
+ " args = enc.call(args) if enc",
+ if( $DEBUG )
+ " p \"[DL] call #{mname} with \#{args.inspect}\""
+ else
+ ""
+ end,
+ " r,rs = sym.call(*args)",
+ if( $DEBUG )
+ " p \"[DL] retval=\#{r.inspect} args=\#{rs.inspect}\""
+ else
+ ""
+ end,
+ " r = rdec.call(r) if rdec",
+ " rs = dec.call(rs) if dec",
+ " @retval = r",
+ " @args = rs",
+ " return r",
+ "end",
+ "module_function :#{mname}",
+ ].join("\n")
+
+ return sym
+ end
+
+ def _args_
+ return @args
end
- CPtr.new(addr)
- end
- def import_function(name, ctype, argtype, call_type = nil)
- addr = @handler.sym(name)
- if( !addr )
- raise(DLError, "cannot find the function: #{name}()")
+ def _retval_
+ return @retval
+ end
+
+ def encode_argument_types(tys)
+ init_types()
+ encty = []
+ enc = nil
+ dec = nil
+ tys.each_with_index{|ty,idx|
+ ty,c1,c2 = @types.encode_argument_type(ty)
+ if( !ty )
+ raise(TypeError, "unsupported type: #{ty}")
+ end
+ encty.push(ty)
+ if( enc )
+ if( c1 )
+ conv1 = enc
+ enc = proc{|v| v = conv1.call(v); v[idx] = c1.call(v[idx]); v}
+ end
+ else
+ if( c1 )
+ enc = proc{|v| v[idx] = c1.call(v[idx]); v}
+ end
+ end
+ if( dec )
+ if( c2 )
+ conv2 = dec
+ dec = proc{|v| v = conv2.call(v); v[idx] = c2.call(v[idx]); v}
+ end
+ else
+ if( c2 )
+ dec = proc{|v| v[idx] = c2.call(v[idx]); v}
+ end
+ end
+ }
+ return [encty.join, enc, dec]
end
- Function.new(CFunc.new(addr, ctype, name, call_type || :cdecl), argtype)
- end
-
- def bind_function(name, ctype, argtype, call_type = nil, &block)
- f = Function.new(CFunc.new(0, ctype, name, call_type || :cdecl), argtype)
- f.bind(&block)
- f
- end
-
- def create_temp_function(name, ctype, argtype, call_type = nil)
- TempFunction.new(CFunc.new(0, ctype, name, call_type || :cdecl), argtype)
- end
-
- def create_carried_function(name, ctype, argtype, call_type = nil, n = 0)
- CarriedFunction.new(CFunc.new(0, ctype, name, call_type || :cdecl), argtype, n)
- end
- end
+ end # end of Internal
+ include Internal
+ end # end of Importable
end
diff --git a/ext/dl/lib/dl/pack.rb b/ext/dl/lib/dl/pack.rb
deleted file mode 100644
index ad91833b3a..0000000000
--- a/ext/dl/lib/dl/pack.rb
+++ /dev/null
@@ -1,173 +0,0 @@
-require 'dl'
-
-module DL
- module PackInfo
- if( defined?(TYPE_LONG_LONG) )
- ALIGN_MAP = {
- TYPE_VOIDP => ALIGN_VOIDP,
- TYPE_CHAR => ALIGN_CHAR,
- TYPE_SHORT => ALIGN_SHORT,
- TYPE_INT => ALIGN_INT,
- TYPE_LONG => ALIGN_LONG,
- TYPE_LONG_LONG => ALIGN_LONG_LONG,
- TYPE_FLOAT => ALIGN_FLOAT,
- TYPE_DOUBLE => ALIGN_DOUBLE,
- -TYPE_CHAR => ALIGN_CHAR,
- -TYPE_SHORT => ALIGN_SHORT,
- -TYPE_INT => ALIGN_INT,
- -TYPE_LONG => ALIGN_LONG,
- -TYPE_LONG_LONG => ALIGN_LONG_LONG,
- }
-
- PACK_MAP = {
- TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG) ? "q" : "l!"),
- TYPE_CHAR => "c",
- TYPE_SHORT => "s!",
- TYPE_INT => "i!",
- TYPE_LONG => "l!",
- TYPE_LONG_LONG => "q",
- TYPE_FLOAT => "f",
- TYPE_DOUBLE => "d",
- -TYPE_CHAR => "c",
- -TYPE_SHORT => "s!",
- -TYPE_INT => "i!",
- -TYPE_LONG => "l!",
- -TYPE_LONG_LONG => "q",
- }
-
- SIZE_MAP = {
- TYPE_VOIDP => SIZEOF_VOIDP,
- TYPE_CHAR => SIZEOF_CHAR,
- TYPE_SHORT => SIZEOF_SHORT,
- TYPE_INT => SIZEOF_INT,
- TYPE_LONG => SIZEOF_LONG,
- TYPE_LONG_LONG => SIZEOF_LONG_LONG,
- TYPE_FLOAT => SIZEOF_FLOAT,
- TYPE_DOUBLE => SIZEOF_DOUBLE,
- -TYPE_CHAR => SIZEOF_CHAR,
- -TYPE_SHORT => SIZEOF_SHORT,
- -TYPE_INT => SIZEOF_INT,
- -TYPE_LONG => SIZEOF_LONG,
- -TYPE_LONG_LONG => SIZEOF_LONG_LONG,
- }
- else
- ALIGN_MAP = {
- TYPE_VOIDP => ALIGN_VOIDP,
- TYPE_CHAR => ALIGN_CHAR,
- TYPE_SHORT => ALIGN_SHORT,
- TYPE_INT => ALIGN_INT,
- TYPE_LONG => ALIGN_LONG,
- TYPE_FLOAT => ALIGN_FLOAT,
- TYPE_DOUBLE => ALIGN_DOUBLE,
- -TYPE_CHAR => ALIGN_CHAR,
- -TYPE_SHORT => ALIGN_SHORT,
- -TYPE_INT => ALIGN_INT,
- -TYPE_LONG => ALIGN_LONG,
- }
-
- PACK_MAP = {
- TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG) ? "q" : "l!"),
- TYPE_CHAR => "c",
- TYPE_SHORT => "s!",
- TYPE_INT => "i!",
- TYPE_LONG => "l!",
- TYPE_FLOAT => "f",
- TYPE_DOUBLE => "d",
- -TYPE_CHAR => "c",
- -TYPE_SHORT => "s!",
- -TYPE_INT => "i!",
- -TYPE_LONG => "l!",
- }
-
- SIZE_MAP = {
- TYPE_VOIDP => SIZEOF_VOIDP,
- TYPE_CHAR => SIZEOF_CHAR,
- TYPE_SHORT => SIZEOF_SHORT,
- TYPE_INT => SIZEOF_INT,
- TYPE_LONG => SIZEOF_LONG,
- TYPE_FLOAT => SIZEOF_FLOAT,
- TYPE_DOUBLE => SIZEOF_DOUBLE,
- -TYPE_CHAR => SIZEOF_CHAR,
- -TYPE_SHORT => SIZEOF_SHORT,
- -TYPE_INT => SIZEOF_INT,
- -TYPE_LONG => SIZEOF_LONG,
- }
- end
-
- def align(addr, align)
- d = addr % align
- if( d == 0 )
- addr
- else
- addr + (align - d)
- end
- end
- module_function :align
- end
-
- class Packer
- include PackInfo
-
- def Packer.[](*types)
- Packer.new(types)
- end
-
- def initialize(types)
- parse_types(types)
- end
-
- def size()
- @size
- end
-
- def pack(ary)
- case SIZEOF_VOIDP
- when SIZEOF_LONG
- ary.pack(@template)
- when SIZEOF_LONG
- ary.pack(@template)
- else
- raise(RuntimeError, "sizeof(void*)?")
- end
- end
-
- def unpack(ary)
- case SIZEOF_VOIDP
- when SIZEOF_LONG
- ary.join().unpack(@template)
- when SIZEOF_LONG_LONG
- ary.join().unpack(@template)
- else
- raise(RuntimeError, "sizeof(void*)?")
- end
- end
-
- private
-
- def parse_types(types)
- @template = ""
- addr = 0
- types.each{|t|
- orig_addr = addr
- if( t.is_a?(Array) )
- addr = align(orig_addr, ALIGN_MAP[TYPE_VOIDP])
- else
- addr = align(orig_addr, ALIGN_MAP[t])
- end
- d = addr - orig_addr
- if( d > 0 )
- @template << "x#{d}"
- end
- if( t.is_a?(Array) )
- @template << (PACK_MAP[t[0]] * t[1])
- addr += (SIZE_MAP[t[0]] * t[1])
- else
- @template << PACK_MAP[t]
- addr += SIZE_MAP[t]
- end
- }
- addr = align(addr, ALIGN_MAP[TYPE_VOIDP])
- @size = addr
- end
- end
-end
diff --git a/ext/dl/lib/dl/stack.rb b/ext/dl/lib/dl/stack.rb
deleted file mode 100644
index 9daf089775..0000000000
--- a/ext/dl/lib/dl/stack.rb
+++ /dev/null
@@ -1,140 +0,0 @@
-require 'dl'
-
-module DL
- class Stack
- def Stack.[](*types)
- Stack.new(types)
- end
-
- def initialize(types)
- parse_types(types)
- end
-
- def size()
- @size
- end
-
- def types()
- @types
- end
-
- def pack(ary)
- case SIZEOF_VOIDP
- when SIZEOF_LONG
- ary.pack(@template).unpack('l!*')
- when SIZEOF_LONG_LONG
- ary.pack(@template).unpack('q*')
- else
- raise(RuntimeError, "sizeof(void*)?")
- end
- end
-
- def unpack(ary)
- case SIZEOF_VOIDP
- when SIZEOF_LONG
- ary.pack('l!*').unpack(@template)
- when SIZEOF_LONG_LONG
- ary.pack('q*').unpack(@template)
- else
- raise(RuntimeError, "sizeof(void*)?")
- end
- end
-
- private
-
- def align(addr, align)
- d = addr % align
- if( d == 0 )
- addr
- else
- addr + (align - d)
- end
- end
-
-if( defined?(TYPE_LONG_LONG) )
- ALIGN_MAP = {
- TYPE_VOIDP => ALIGN_VOIDP,
- TYPE_CHAR => ALIGN_VOIDP,
- TYPE_SHORT => ALIGN_VOIDP,
- TYPE_INT => ALIGN_VOIDP,
- TYPE_LONG => ALIGN_VOIDP,
- TYPE_LONG_LONG => ALIGN_LONG_LONG,
- TYPE_FLOAT => ALIGN_FLOAT,
- TYPE_DOUBLE => ALIGN_DOUBLE,
- }
-
- PACK_MAP = {
- TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG)? "q" : "l!"),
- TYPE_CHAR => "c",
- TYPE_SHORT => "s!",
- TYPE_INT => "i!",
- TYPE_LONG => "l!",
- TYPE_LONG_LONG => "q",
- TYPE_FLOAT => "f",
- TYPE_DOUBLE => "d",
- }
-
- SIZE_MAP = {
- TYPE_VOIDP => SIZEOF_VOIDP,
- TYPE_CHAR => SIZEOF_CHAR,
- TYPE_SHORT => SIZEOF_SHORT,
- TYPE_INT => SIZEOF_INT,
- TYPE_LONG => SIZEOF_LONG,
- TYPE_LONG_LONG => SIZEOF_LONG_LONG,
- TYPE_FLOAT => SIZEOF_FLOAT,
- TYPE_DOUBLE => SIZEOF_DOUBLE,
- }
-else
- ALIGN_MAP = {
- TYPE_VOIDP => ALIGN_VOIDP,
- TYPE_CHAR => ALIGN_VOIDP,
- TYPE_SHORT => ALIGN_VOIDP,
- TYPE_INT => ALIGN_VOIDP,
- TYPE_LONG => ALIGN_VOIDP,
- TYPE_FLOAT => ALIGN_FLOAT,
- TYPE_DOUBLE => ALIGN_DOUBLE,
- }
-
- PACK_MAP = {
- TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG)? "q" : "l!"),
- TYPE_CHAR => "c",
- TYPE_SHORT => "s!",
- TYPE_INT => "i!",
- TYPE_LONG => "l!",
- TYPE_FLOAT => "f",
- TYPE_DOUBLE => "d",
- }
-
- SIZE_MAP = {
- TYPE_VOIDP => SIZEOF_VOIDP,
- TYPE_CHAR => SIZEOF_CHAR,
- TYPE_SHORT => SIZEOF_SHORT,
- TYPE_INT => SIZEOF_INT,
- TYPE_LONG => SIZEOF_LONG,
- TYPE_FLOAT => SIZEOF_FLOAT,
- TYPE_DOUBLE => SIZEOF_DOUBLE,
- }
-end
-
- def parse_types(types)
- @types = types
- @template = ""
- addr = 0
- types.each{|t|
- orig_addr = addr
- addr = align(orig_addr, ALIGN_MAP[t])
- d = addr - orig_addr
- if( d > 0 )
- @template << "x#{d}"
- end
- @template << PACK_MAP[t]
- addr += SIZE_MAP[t]
- }
- if( addr % SIZEOF_VOIDP == 0 )
- @size = addr / SIZEOF_VOIDP
- else
- @size = (addr / SIZEOF_VOIDP) + 1
- end
- end
- end
-end
diff --git a/ext/dl/lib/dl/struct.rb b/ext/dl/lib/dl/struct.rb
index 4272b3960c..33f303fe22 100644
--- a/ext/dl/lib/dl/struct.rb
+++ b/ext/dl/lib/dl/struct.rb
@@ -1,213 +1,149 @@
+# -*- ruby -*-
+
require 'dl'
-require 'dl/pack.rb'
+require 'dl/import'
module DL
- class CStruct
- def CStruct.entity_class()
- CStructEntity
- end
- end
-
- class CUnion
- def CUnion.entity_class()
- CUnionEntity
- end
- end
-
- module CStructBuilder
- def create(klass, types, members)
- new_class = Class.new(klass){
- define_method(:initialize){|addr|
- @entity = klass.entity_class.new(addr, types)
- @entity.assign_names(members)
- }
- define_method(:to_ptr){ @entity }
- define_method(:to_i){ @entity.to_i }
- members.each{|name|
- define_method(name){ @entity[name] }
- define_method(name + "="){|val| @entity[name] = val }
- }
- }
- size = klass.entity_class.size(types)
- new_class.module_eval(<<-EOS)
- def new_class.size()
- #{size}
- end
- def new_class.malloc()
- addr = DL.malloc(#{size})
- new(addr)
- end
- EOS
- return new_class
- end
- module_function :create
- end
-
- class CStructEntity < CPtr
- include PackInfo
- include ValueUtil
-
- def CStructEntity.malloc(types, func = nil)
- addr = DL.malloc(CStructEntity.size(types))
- CStructEntity.new(addr, types, func)
- end
-
- def CStructEntity.size(types)
- offset = 0
- max_align = 0
- types.each_with_index{|t,i|
- orig_offset = offset
- if( t.is_a?(Array) )
- align = PackInfo::ALIGN_MAP[t[0]]
- offset = PackInfo.align(orig_offset, align)
- size = offset - orig_offset
- offset += (PackInfo::SIZE_MAP[t[0]] * t[1])
- else
- align = PackInfo::ALIGN_MAP[t]
- offset = PackInfo.align(orig_offset, align)
- size = offset - orig_offset
- offset += PackInfo::SIZE_MAP[t]
- end
- if (max_align < align)
- max_align = align
- end
- }
- offset = PackInfo.align(offset, max_align)
- offset
- end
-
- def initialize(addr, types, func = nil)
- set_ctypes(types)
- super(addr, @size, func)
- end
-
- def assign_names(members)
- @members = members
- end
-
- def set_ctypes(types)
- @ctypes = types
- @offset = []
- offset = 0
- max_align = 0
- types.each_with_index{|t,i|
- orig_offset = offset
- if( t.is_a?(Array) )
- align = ALIGN_MAP[t[0]]
- else
- align = ALIGN_MAP[t]
- end
- offset = PackInfo.align(orig_offset, align)
- size = offset - orig_offset
- @offset[i] = offset
- if( t.is_a?(Array) )
- offset += (SIZE_MAP[t[0]] * t[1])
- else
- offset += SIZE_MAP[t]
- end
- if (max_align < align)
- max_align = align
- end
- }
- offset = PackInfo.align(offset, max_align)
- @size = offset
- end
-
- def [](name)
- idx = @members.index(name)
- if( idx.nil? )
- raise(ArgumentError, "no such member: #{name}")
+ module Importable
+ module Internal
+ def define_struct(contents)
+ init_types()
+ Struct.new(@types, contents)
end
- ty = @ctypes[idx]
- if( ty.is_a?(Array) )
- r = super(@offset[idx], SIZE_MAP[ty[0]] * ty[1])
- else
- r = super(@offset[idx], SIZE_MAP[ty.abs])
- end
- packer = Packer.new([ty])
- val = packer.unpack([r])
- case ty
- when Array
- case ty[0]
- when TYPE_VOIDP
- val = val.collect{|v| CPtr.new(v)}
- end
- when TYPE_VOIDP
- val = CPtr.new(val[0])
- else
- val = val[0]
- end
- if( ty.is_a?(Integer) && (ty < 0) )
- return unsigned_value(val, ty)
- elsif( ty.is_a?(Array) && (ty[0] < 0) )
- return val.collect{|v| unsigned_value(v,ty[0])}
- else
- return val
- end
- end
+ alias struct define_struct
- def []=(name, val)
- idx = @members.index(name)
- if( idx.nil? )
- raise(ArgumentError, "no such member: #{name}")
+ def define_union(contents)
+ init_types()
+ Union.new(@types, contents)
end
- ty = @ctypes[idx]
- packer = Packer.new([ty])
- val = wrap_arg(val, ty, [])
- buff = packer.pack([val].flatten())
- super(@offset[idx], buff.size, buff)
- if( ty.is_a?(Integer) && (ty < 0) )
- return unsigned_value(val, ty)
- elsif( ty.is_a?(Array) && (ty[0] < 0) )
- return val.collect{|v| unsigned_value(v,ty[0])}
- else
- return val
+ alias union define_union
+
+ class Memory
+ def initialize(ptr, names, ty, len, enc, dec)
+ @ptr = ptr
+ @names = names
+ @ty = ty
+ @len = len
+ @enc = enc
+ @dec = dec
+
+ # define methods
+ @names.each{|name|
+ instance_eval [
+ "def #{name}",
+ " v = @ptr[\"#{name}\"]",
+ " if( @len[\"#{name}\"] )",
+ " v = v.collect{|x| @dec[\"#{name}\"] ? @dec[\"#{name}\"].call(x) : x }",
+ " else",
+ " v = @dec[\"#{name}\"].call(v) if @dec[\"#{name}\"]",
+ " end",
+ " return v",
+ "end",
+ "def #{name}=(v)",
+ " if( @len[\"#{name}\"] )",
+ " v = v.collect{|x| @enc[\"#{name}\"] ? @enc[\"#{name}\"].call(x) : x }",
+ " else",
+ " v = @enc[\"#{name}\"].call(v) if @enc[\"#{name}\"]",
+ " end",
+ " @ptr[\"#{name}\"] = v",
+ " return v",
+ "end",
+ ].join("\n")
+ }
+ end
+
+ def to_ptr
+ return @ptr
+ end
+
+ def size
+ return @ptr.size
+ end
end
- end
-
- def to_s()
- super(@size)
- end
- end
-
- class CUnionEntity < CStructEntity
- include PackInfo
-
- def CUnionEntity.malloc(types, func=nil)
- addr = DL.malloc(CUnionEntity.size(types))
- CUnionEntity.new(addr, types, func)
- end
-
- def CUnionEntity.size(types)
- size = 0
- types.each_with_index{|t,i|
- if( t.is_a?(Array) )
- tsize = PackInfo::SIZE_MAP[t[0]] * t[1]
- else
- tsize = PackInfo::SIZE_MAP[t]
- end
- if( tsize > size )
- size = tsize
- end
- }
- end
-
- def set_ctypes(types)
- @ctypes = types
- @offset = []
- @size = 0
- types.each_with_index{|t,i|
- @offset[i] = 0
- if( t.is_a?(Array) )
- size = SIZE_MAP[t[0]] * t[1]
- else
- size = SIZE_MAP[t]
- end
- if( size > @size )
- @size = size
- end
- }
- end
- end
-end
+ class Struct
+ def initialize(types, contents)
+ @names = []
+ @ty = {}
+ @len = {}
+ @enc = {}
+ @dec = {}
+ @size = 0
+ @tys = ""
+ @types = types
+ parse(contents)
+ end
+
+ def size
+ return @size
+ end
+
+ def members
+ return @names
+ end
+
+ # ptr must be a PtrData object.
+ def new(ptr)
+ ptr.struct!(@tys, *@names)
+ mem = Memory.new(ptr, @names, @ty, @len, @enc, @dec)
+ return mem
+ end
+
+ def malloc(size = nil)
+ if( !size )
+ size = @size
+ end
+ ptr = DL::malloc(size)
+ return new(ptr)
+ end
+
+ def parse(contents)
+ contents.each{|elem|
+ name,ty,num,enc,dec = parse_elem(elem)
+ @names.push(name)
+ @ty[name] = ty
+ @len[name] = num
+ @enc[name] = enc
+ @dec[name] = dec
+ if( num )
+ @tys += "#{ty}#{num}"
+ else
+ @tys += ty
+ end
+ }
+ @size = DL.sizeof(@tys)
+ end
+
+ def parse_elem(elem)
+ elem.strip!
+ case elem
+ when /^([\w\d_\*]+)([\*\s]+)([\w\d_]+)$/
+ ty = ($1 + $2).strip
+ name = $3
+ num = nil;
+ when /^([\w\d_\*]+)([\*\s]+)([\w\d_]+)\[(\d+)\]$/
+ ty = ($1 + $2).strip
+ name = $3
+ num = $4.to_i
+ else
+ raise(RuntimeError, "invalid element: #{elem}")
+ end
+ ty,enc,dec = @types.encode_struct_type(ty)
+ if( !ty )
+ raise(TypeError, "unsupported type: #{ty}")
+ end
+ return [name,ty,num,enc,dec]
+ end
+ end # class Struct
+
+ class Union < Struct
+ def new
+ ptr = DL::malloc(@size)
+ ptr.union!(@tys, *@names)
+ mem = Memory.new(ptr, @names, @ty, @len, @enc, @dec)
+ return mem
+ end
+ end
+ end # module Internal
+ end # module Importable
+end # module DL
diff --git a/ext/dl/lib/dl/types.rb b/ext/dl/lib/dl/types.rb
index b85ac890cd..1144917dae 100644
--- a/ext/dl/lib/dl/types.rb
+++ b/ext/dl/lib/dl/types.rb
@@ -1,40 +1,245 @@
+# -*- ruby -*-
+
+require 'dl'
+
module DL
- module Win32Types
- def included(m)
- m.module_eval{
- typealias "DWORD", "unsigned long"
- typealias "PDWORD", "unsigned long *"
- typealias "WORD", "unsigned short"
- typealias "PWORD", "unsigned short *"
- typealias "BOOL", "int"
- typealias "ATOM", "int"
- typealias "BYTE", "unsigned char"
- typealias "PBYTE", "unsigned char *"
- typealias "UINT", "unsigned int"
- typealias "ULONG", "unsigned long"
- typealias "UCHAR", "unsigned char"
- typealias "HANDLE", "unsigned long"
- typealias "PHANDLE", "void*"
- typealias "PVOID", "void*"
- typealias "LPCSTR", "char*"
- typealias "LPSTR", "char*"
- typealias "HINSTANCE", "unsigned int"
- typealias "HDC", "unsigned int"
- typealias "HWND", "unsigned int"
+ class Types
+ TYPES = [
+ # FORMAT:
+ # ["alias name",
+ # "type name", encoding_method, decoding_method, for function prototypes
+ # "type name", encoding_method, decoding_method] for structures (not implemented)
+
+ # for Windows
+ ["DWORD", "unsigned long", nil, nil,
+ "unsigned long", nil, nil],
+ ["PDWORD", "unsigned long *", nil, nil,
+ "unsigned long *", nil, nil],
+ ["WORD", "unsigned short", nil, nil,
+ "unsigned short", nil, nil],
+ ["PWORD", "unsigned int *", nil, nil,
+ "unsigned int *", nil, nil],
+ ["BYTE", "unsigned char", nil, nil,
+ "unsigned char", nil, nil],
+ ["PBYTE", "unsigned char *", nil, nil,
+ "unsigned char *", nil, nil],
+ ["BOOL", "ibool", nil, nil,
+ "ibool", nil, nil],
+ ["ATOM", "int", nil, nil,
+ "int", nil, nil],
+ ["BYTE", "unsigned char", nil, nil,
+ "unsigned char", nil, nil],
+ ["PBYTE", "unsigned char *", nil, nil,
+ "unsigned char *", nil, nil],
+ ["UINT", "unsigned int", nil, nil,
+ "unsigned int", nil, nil],
+ ["ULONG", "unsigned long", nil, nil,
+ "unsigned long", nil, nil],
+ ["UCHAR", "unsigned char", nil, nil,
+ "unsigned char", nil, nil],
+ ["HANDLE", "unsigned long", nil, nil,
+ "unsigned long", nil, nil],
+ ["PHANDLE","void*", nil, nil,
+ "void*", nil, nil],
+ ["PVOID", "void*", nil, nil,
+ "void*", nil, nil],
+ ["LPCSTR", "char*", nil, nil,
+ "char*", nil, nil],
+ ["HDC", "unsigned int", nil, nil,
+ "unsigned int", nil, nil],
+ ["HWND", "unsigned int", nil, nil,
+ "unsigned int", nil, nil],
+
+ # Others
+ ["uint", "unsigned int", nil, nil,
+ "unsigned int", nil, nil],
+ ["u_int", "unsigned int", nil, nil,
+ "unsigned int", nil, nil],
+ ["ulong", "unsigned long", nil, nil,
+ "unsigned long", nil, nil],
+ ["u_long", "unsigned long", nil, nil,
+ "unsigned long", nil, nil],
+
+ # DL::Importable primitive types
+ ["ibool",
+ "I",
+ proc{|v| v ? 1 : 0},
+ proc{|v| (v != 0) ? true : false},
+ "I",
+ proc{|v| v ? 1 : 0 },
+ proc{|v| (v != 0) ? true : false} ],
+ ["cbool",
+ "C",
+ proc{|v| v ? 1 : 0},
+ proc{|v| (v != 0) ? true : false},
+ "C",
+ proc{|v,len| v ? 1 : 0},
+ proc{|v,len| (v != 0) ? true : false}],
+ ["lbool",
+ "L",
+ proc{|v| v ? 1 : 0},
+ proc{|v| (v != 0) ? true : false},
+ "L",
+ proc{|v,len| v ? 1 : 0},
+ proc{|v,len| (v != 0) ? true : false}],
+ ["unsigned char",
+ "C",
+ proc{|v| [v].pack("C").unpack("c")[0]},
+ proc{|v| [v].pack("c").unpack("C")[0]},
+ "C",
+ proc{|v| [v].pack("C").unpack("c")[0]},
+ proc{|v| [v].pack("c").unpack("C")[0]}],
+ ["unsigned short",
+ "H",
+ proc{|v| [v].pack("S").unpack("s")[0]},
+ proc{|v| [v].pack("s").unpack("S")[0]},
+ "H",
+ proc{|v| [v].pack("S").unpack("s")[0]},
+ proc{|v| [v].pack("s").unpack("S")[0]}],
+ ["unsigned int",
+ "I",
+ proc{|v| [v].pack("I").unpack("i")[0]},
+ proc{|v| [v].pack("i").unpack("I")[0]},
+ "I",
+ proc{|v| [v].pack("I").unpack("i")[0]},
+ proc{|v| [v].pack("i").unpack("I")[0]}],
+ ["unsigned long",
+ "L",
+ proc{|v| [v].pack("L").unpack("l")[0]},
+ proc{|v| [v].pack("l").unpack("L")[0]},
+ "L",
+ proc{|v| [v].pack("L").unpack("l")[0]},
+ proc{|v| [v].pack("l").unpack("L")[0]}],
+ ["unsigned char ref",
+ "c",
+ proc{|v| [v].pack("C").unpack("c")[0]},
+ proc{|v| [v].pack("c").unpack("C")[0]},
+ nil, nil, nil],
+ ["unsigned int ref",
+ "i",
+ proc{|v| [v].pack("I").unpack("i")[0]},
+ proc{|v| [v].pack("i").unpack("I")[0]},
+ nil, nil, nil],
+ ["unsigned long ref",
+ "l",
+ proc{|v| [v].pack("L").unpack("l")[0]},
+ proc{|v| [v].pack("l").unpack("L")[0]},
+ nil, nil, nil],
+ ["char ref", "c", nil, nil,
+ nil, nil, nil],
+ ["short ref", "h", nil, nil,
+ nil, nil, nil],
+ ["int ref", "i", nil, nil,
+ nil, nil, nil],
+ ["long ref", "l", nil, nil,
+ nil, nil, nil],
+ ["float ref", "f", nil, nil,
+ nil, nil, nil],
+ ["double ref","d", nil, nil,
+ nil, nil, nil],
+ ["char", "C", nil, nil,
+ "C", nil, nil],
+ ["short", "H", nil, nil,
+ "H", nil, nil],
+ ["int", "I", nil, nil,
+ "I", nil, nil],
+ ["long", "L", nil, nil,
+ "L", nil, nil],
+ ["float", "F", nil, nil,
+ "F", nil, nil],
+ ["double", "D", nil, nil,
+ "D", nil, nil],
+ [/^char\s*\*$/,"s",nil, nil,
+ "S",nil, nil],
+ [/^const char\s*\*$/,"S",nil, nil,
+ "S",nil, nil],
+ [/^.+\*$/, "P", nil, nil,
+ "P", nil, nil],
+ [/^.+\[\]$/, "a", nil, nil,
+ "a", nil, nil],
+ ["void", "0", nil, nil,
+ nil, nil, nil],
+ ]
+
+ def initialize
+ init_types()
+ end
+
+ def typealias(ty1, ty2, enc=nil, dec=nil, ty3=nil, senc=nil, sdec=nil)
+ @TYDEFS.unshift([ty1, ty2, enc, dec, ty3, senc, sdec])
+ end
+
+ def init_types
+ @TYDEFS = TYPES.dup
+ end
+
+ def encode_argument_type(alias_type)
+ proc_encode = nil
+ proc_decode = nil
+ @TYDEFS.each{|aty,ty,enc,dec,_,_,_|
+ if( (aty.is_a?(Regexp) && (aty =~ alias_type)) || (aty == alias_type) )
+ alias_type = alias_type.gsub(aty,ty) if ty
+ alias_type.strip! if alias_type
+ if( proc_encode )
+ if( enc )
+ conv1 = proc_encode
+ proc_encode = proc{|v| enc.call(conv1.call(v))}
+ end
+ else
+ if( enc )
+ proc_encode = enc
+ end
+ end
+ if( proc_decode )
+ if( dec )
+ conv2 = proc_decode
+ proc_decode = proc{|v| dec.call(conv2.call(v))}
+ end
+ else
+ if( dec )
+ proc_decode = dec
+ end
+ end
+ end
}
+ return [alias_type, proc_encode, proc_decode]
end
- module_function :included
- end
-
- module BasicTypes
- def included(m)
- m.module_eval{
- typealias "uint", "unsigned int"
- typealias "u_int", "unsigned int"
- typealias "ulong", "unsigned long"
- typealias "u_long", "unsigned long"
+
+ def encode_return_type(ty)
+ ty, enc, dec = encode_argument_type(ty)
+ return [ty, enc, dec]
+ end
+
+ def encode_struct_type(alias_type)
+ proc_encode = nil
+ proc_decode = nil
+ @TYDEFS.each{|aty,_,_,_,ty,enc,dec|
+ if( (aty.is_a?(Regexp) && (aty =~ alias_type)) || (aty == alias_type) )
+ alias_type = alias_type.gsub(aty,ty) if ty
+ alias_type.strip! if alias_type
+ if( proc_encode )
+ if( enc )
+ conv1 = proc_encode
+ proc_encode = proc{|v| enc.call(conv1.call(v))}
+ end
+ else
+ if( enc )
+ proc_encode = enc
+ end
+ end
+ if( proc_decode )
+ if( dec )
+ conv2 = proc_decode
+ proc_decode = proc{|v| dec.call(conv2.call(v))}
+ end
+ else
+ if( dec )
+ proc_decode = dec
+ end
+ end
+ end
}
+ return [alias_type, proc_encode, proc_decode]
end
- module_function :included
- end
+ end # end of Types
end
diff --git a/ext/dl/lib/dl/value.rb b/ext/dl/lib/dl/value.rb
deleted file mode 100644
index aa7e0dd325..0000000000
--- a/ext/dl/lib/dl/value.rb
+++ /dev/null
@@ -1,108 +0,0 @@
-require 'dl'
-
-module DL
- module ValueUtil
- def unsigned_value(val, ty)
- case ty.abs
- when TYPE_CHAR
- [val].pack("c").unpack("C")[0]
- when TYPE_SHORT
- [val].pack("s!").unpack("S!")[0]
- when TYPE_INT
- [val].pack("i!").unpack("I!")[0]
- when TYPE_LONG
- [val].pack("l!").unpack("L!")[0]
- when TYPE_LONG_LONG
- [val].pack("q!").unpack("Q!")[0]
- else
- val
- end
- end
-
- def signed_value(val, ty)
- case ty.abs
- when TYPE_CHAR
- [val].pack("C").unpack("c")[0]
- when TYPE_SHORT
- [val].pack("S!").unpack("s!")[0]
- when TYPE_INT
- [val].pack("I!").unpack("i!")[0]
- when TYPE_LONG
- [val].pack("L!").unpack("l!")[0]
- when TYPE_LONG_LONG
- [val].pack("Q!").unpack("q!")[0]
- else
- val
- end
- end
-
- def wrap_args(args, tys, funcs, &block)
- result = []
- tys ||= []
- args.each_with_index{|arg, idx|
- result.push(wrap_arg(arg, tys[idx], funcs, &block))
- }
- result
- end
-
- def wrap_arg(arg, ty, funcs, &block)
- funcs ||= []
- case arg
- when CPtr
- return arg.to_i
- when IO
- case ty
- when TYPE_VOIDP
- return CPtr[arg].to_i
- else
- return arg.to_i
- end
- when Function
- if( block )
- arg.bind_at_call(&block)
- funcs.push(arg)
- end
- return arg.to_i
- when String
- if( ty.is_a?(Array) )
- return arg.unpack('C*')
- else
- case SIZEOF_VOIDP
- when SIZEOF_LONG
- return [arg].pack("p").unpack("l!")[0]
- when SIZEOF_LONG_LONG
- return [arg].pack("p").unpack("q")[0]
- else
- raise(RuntimeError, "sizeof(void*)?")
- end
- end
- when Float, Integer
- return arg
- when Array
- if( ty.is_a?(Array) ) # used only by struct
- case ty[0]
- when TYPE_VOIDP
- return arg.collect{|v| Integer(v)}
- when TYPE_CHAR
- if( arg.is_a?(String) )
- return val.unpack('C*')
- end
- end
- return arg
- else
- return arg
- end
- else
- if( arg.respond_to?(:to_ptr) )
- return arg.to_ptr.to_i
- else
- begin
- return Integer(arg)
- rescue
- raise(ArgumentError, "unknown argument type: #{arg.class}")
- end
- end
- end
- end
- end
-end
diff --git a/ext/dl/lib/dl/win32.rb b/ext/dl/lib/dl/win32.rb
new file mode 100644
index 0000000000..0fed47c324
--- /dev/null
+++ b/ext/dl/lib/dl/win32.rb
@@ -0,0 +1,25 @@
+# -*- ruby -*-
+
+require 'dl'
+
+class Win32API
+ DLL = {}
+
+ def initialize(dllname, func, import, export = "0")
+ prototype = (export + import.to_s).tr("VPpNnLlIi", "0SSI").sub(/^(.)0*$/, '\1')
+ handle = DLL[dllname] ||= DL::Handle.new(dllname)
+ @sym = handle.sym(func, prototype)
+ end
+
+ def call(*args)
+ import = @sym.proto.split("", 2)[1]
+ args.each_with_index do |x, i|
+ args[i] = nil if x == 0 and import[i] == ?S
+ args[i], = [x].pack("I").unpack("i") if import[i] == ?I
+ end
+ ret, = @sym.call(*args)
+ return ret || 0
+ end
+
+ alias Call call
+end
diff --git a/ext/dl/mkcall.rb b/ext/dl/mkcall.rb
new file mode 100644
index 0000000000..6a85570152
--- /dev/null
+++ b/ext/dl/mkcall.rb
@@ -0,0 +1,62 @@
+# -*- ruby -*-
+
+require 'mkmf'
+$:.unshift File.dirname(__FILE__)
+require 'type'
+require 'dlconfig'
+
+def output_arg(x,i)
+ "args[#{i}].#{DLTYPE[x][:stmem]}"
+end
+
+def output_args(types)
+ t = []
+ types[1..-1].each_with_index{|x,i| t.push(output_arg(x,i))}
+ t.join(",")
+end
+
+def output_callfunc(types)
+ t = types[0]
+ stmem = DLTYPE[t][:stmem]
+ ctypes = types2ctypes(types)
+ if( t == VOID )
+ callstm = "(*f)(#{output_args(types)})"
+ else
+ callstm = "ret.#{stmem} = (*f)(#{output_args(types)})"
+ end
+ [ "{",
+ "#{ctypes[0]} (*f)(#{ctypes[1..-1].join(',')}) = func;",
+ "#{callstm};",
+ "}"].join(" ")
+end
+
+def output_case(types)
+ num = types2num(types)
+ callfunc_stm = output_callfunc(types)
+<<EOF
+ case #{num}:
+#ifdef DEBUG
+ printf("#{callfunc_stm}\\n");
+#endif
+ #{callfunc_stm};
+ break;
+EOF
+end
+
+def rec_output(types = [VOID])
+ print output_case(types)
+ if( types.length <= MAX_ARG )
+ DLTYPE.keys.sort.each{|t|
+ if( t != VOID && DLTYPE[t][:sym] )
+ rec_output(types + [t])
+ end
+ }
+ end
+end
+
+DLTYPE.keys.sort.each{|t|
+ if( DLTYPE[t][:sym] )
+ $stderr.printf(" #{DLTYPE[t][:ctype]}\n")
+ rec_output([t])
+ end
+}
diff --git a/ext/dl/mkcallback.rb b/ext/dl/mkcallback.rb
index 8526353bf3..c9f92e4a0d 100644
--- a/ext/dl/mkcallback.rb
+++ b/ext/dl/mkcallback.rb
@@ -1,189 +1,56 @@
-$out ||= $stdout
-$dl_h = ARGV[0] || "dl.h"
+# -*- ruby -*-
-# import DLSTACK_SIZE, DLSTACK_ARGS and so on
-File.open($dl_h){|f|
- pre = ""
- f.each{|line|
- line.chop!
- if( line[-1] == ?\ )
- line.chop!
- line.concat(" ")
- pre += line
- next
- end
- if( pre.size > 0 )
- line = pre + line
- pre = ""
- end
- case line
- when /#define\s+DLSTACK_SIZE\s+\(?(\d+)\)?/
- DLSTACK_SIZE = $1.to_i
- when /#define\s+DLSTACK_ARGS\s+(.+)/
- DLSTACK_ARGS = $1.to_i
- when /#define\s+DLTYPE_([A-Z_]+)\s+\(?(\d+)\)?/
- eval("#{$1} = #{$2}")
- when /#define\s+MAX_DLTYPE\s+\(?(\d+)\)?/
- MAX_DLTYPE = $1.to_i
- when /#define\s+MAX_CALLBACK\s+\(?(\d+)\)?/
- MAX_CALLBACK = $1.to_i
- end
- }
-}
-
-CDECL = "cdecl"
-STDCALL = "stdcall"
+require 'mkmf'
+$:.unshift File.dirname(__FILE__)
+require 'type'
+require 'dlconfig'
-CALLTYPES = [CDECL, STDCALL]
+def mkfunc(rettype, fnum, argc)
+ args = (0..(argc-1)).collect{|i| "long arg#{i}"}.join(", ")
-DLTYPE = {
- VOID => {
- :name => 'void',
- :type => 'void',
- :conv => nil,
- },
- CHAR => {
- :name => 'char',
- :type => 'char',
- :conv => 'NUM2CHR(%s)'
- },
- SHORT => {
- :name => 'short',
- :type => 'short',
- :conv => 'NUM2INT(%s)',
- },
- INT => {
- :name => 'int',
- :type => 'int',
- :conv => 'NUM2INT(%s)',
- },
- LONG => {
- :name => 'long',
- :type => 'long',
- :conv => 'NUM2LONG(%s)',
- },
- LONG_LONG => {
- :name => 'long_long',
- :type => 'LONG_LONG',
- :conv => 'NUM2LL(%s)',
- },
- FLOAT => {
- :name => 'float',
- :type => 'float',
- :conv => 'RFLOAT(%s)->value',
- },
- DOUBLE => {
- :name => 'double',
- :type => 'double',
- :conv => 'RFLOAT(%s)->value',
- },
- VOIDP => {
- :name => 'ptr',
- :type => 'void *',
- :conv => 'NUM2PTR(%s)',
- },
-}
+ subst_code = (0..(argc-1)).collect{|i|
+ " buff[#{i.to_s}] = arg#{i.to_s};"
+ }.join("\n")
+ ret_code =
+ if( DLTYPE[rettype][:c2rb] )
+ " return #{DLTYPE[rettype][:rb2c]['retval']};"
+ else
+ " /* no return value */"
+ end
-def func_name(ty, argc, n, calltype)
- "rb_dl_callback_#{DLTYPE[ty][:name]}_#{argc}_#{n}_#{calltype}"
+ code = [
+ "static #{DLTYPE[rettype][:ctype]}",
+ "rb_dl_callback_func_#{rettype.to_s}_#{fnum.to_s}(#{args})",
+ "{",
+ " VALUE retval, proto, proc, obj;",
+ " VALUE argv[#{argc.to_s}];",
+ " int argc;",
+ " long buff[#{argc.to_s}];",
+ "",
+ subst_code,
+ "",
+ " obj = rb_hash_aref(DLFuncTable, rb_assoc_new(INT2NUM(#{rettype.to_s}),INT2NUM(#{fnum.to_s})));",
+ " if(NIL_P(obj))",
+ " rb_raise(rb_eDLError, \"callback function does not exist in DL::FuncTable\");",
+ " Check_Type(obj, T_ARRAY);",
+ " proto = rb_ary_entry(obj, 0);",
+ " proc = rb_ary_entry(obj, 1);",
+ " Check_Type(proto, T_STRING);",
+ " if( RSTRING(proto)->len >= #{argc.to_s} )",
+ " rb_raise(rb_eArgError, \"too many arguments\");",
+ " rb_dl_scan_callback_args(buff, RSTRING(proto)->ptr, &argc, argv);",
+ " retval = rb_funcall2(proc, id_call, argc, argv);",
+ "",
+ ret_code,
+ "}",
+ ].join("\n")
+
+ return code
end
-$out << (<<EOS)
-VALUE rb_DLCdeclCallbackAddrs, rb_DLCdeclCallbackProcs;
-VALUE rb_DLStdcallCallbackAddrs, rb_DLStdcallCallbackProcs;
-/*static void *cdecl_callbacks[MAX_DLTYPE][MAX_CALLBACK];*/
-/*static void *stdcall_callbacks[MAX_DLTYPE][MAX_CALLBACK];*/
-static ID cb_call;
-EOS
-
-for calltype in CALLTYPES
- case calltype
- when CDECL
- proc_entry = "rb_DLCdeclCallbackProcs"
- when STDCALL
- proc_entry = "rb_DLStdcallCallbackProcs"
- else
- raise "unknown calltype: #{calltype}"
+DLTYPE.keys.sort.each{|t|
+ for n in 0..(MAX_CALLBACK - 1)
+ print(mkfunc(t, n, 15), "\n\n")
end
- for ty in 0..(MAX_DLTYPE-1)
- for argc in 0..(DLSTACK_SIZE-1)
- for n in 0..(MAX_CALLBACK-1)
- $out << (<<-EOS)
-
-static #{DLTYPE[ty][:type]}
-FUNC_#{calltype.upcase}(#{func_name(ty,argc,n,calltype)})(#{(0...argc).collect{|i| "DLSTACK_TYPE stack" + i.to_s}.join(", ")})
-{
- VALUE ret, cb#{argc > 0 ? ", args[#{argc}]" : ""};
-#{
- (0...argc).collect{|i|
- " args[%d] = LONG2NUM(stack%d);" % [i,i]
- }.join("\n")
-}
- cb = rb_ary_entry(rb_ary_entry(#{proc_entry}, #{ty}), #{(n * DLSTACK_SIZE) + argc});
- ret = rb_funcall2(cb, cb_call, #{argc}, #{argc > 0 ? 'args' : 'NULL'});
- return #{DLTYPE[ty][:conv] ? DLTYPE[ty][:conv] % "ret" : ""};
-}
-
- EOS
- end
- end
- end
-end
-
-$out << (<<EOS)
-static void
-rb_dl_init_callbacks()
-{
- cb_call = rb_intern("call");
-
- rb_DLCdeclCallbackProcs = rb_ary_new();
- rb_DLCdeclCallbackAddrs = rb_ary_new();
- rb_DLStdcallCallbackProcs = rb_ary_new();
- rb_DLStdcallCallbackAddrs = rb_ary_new();
- rb_define_const(rb_mDL, "CdeclCallbackProcs", rb_DLCdeclCallbackProcs);
- rb_define_const(rb_mDL, "CdeclCallbackAddrs", rb_DLCdeclCallbackAddrs);
- rb_define_const(rb_mDL, "StdcallCallbackProcs", rb_DLStdcallCallbackProcs);
- rb_define_const(rb_mDL, "StdcallCallbackAddrs", rb_DLStdcallCallbackAddrs);
-#{
- (0...MAX_DLTYPE).collect{|ty|
- sprintf(" rb_ary_push(rb_DLCdeclCallbackProcs, rb_ary_new3(%d,%s));",
- MAX_CALLBACK * DLSTACK_SIZE,
- (0...MAX_CALLBACK).collect{
- (0...DLSTACK_SIZE).collect{ "Qnil" }.join(",")
- }.join(","))
- }.join("\n")
-}
-#{
- (0...MAX_DLTYPE).collect{|ty|
- sprintf(" rb_ary_push(rb_DLCdeclCallbackAddrs, rb_ary_new3(%d,%s));",
- MAX_CALLBACK * DLSTACK_SIZE,
- (0...MAX_CALLBACK).collect{|i|
- (0...DLSTACK_SIZE).collect{|argc|
- "PTR2NUM(%s)" % func_name(ty,argc,i,CDECL)
- }.join(",")
- }.join(","))
- }.join("\n")
-}
-#{
- (0...MAX_DLTYPE).collect{|ty|
- sprintf(" rb_ary_push(rb_DLStdcallCallbackProcs, rb_ary_new3(%d,%s));",
- MAX_CALLBACK * DLSTACK_SIZE,
- (0...MAX_CALLBACK).collect{
- (0...DLSTACK_SIZE).collect{ "Qnil" }.join(",")
- }.join(","))
- }.join("\n")
-}
-#{
- (0...MAX_DLTYPE).collect{|ty|
- sprintf(" rb_ary_push(rb_DLStdcallCallbackAddrs, rb_ary_new3(%d,%s));",
- MAX_CALLBACK * DLSTACK_SIZE,
- (0...MAX_CALLBACK).collect{|i|
- (0...DLSTACK_SIZE).collect{|argc|
- "PTR2NUM(%s)" % func_name(ty,argc,i,STDCALL)
- }.join(",")
- }.join(","))
- }.join("\n")
-}
}
-EOS
diff --git a/ext/dl/mkcbtable.rb b/ext/dl/mkcbtable.rb
new file mode 100644
index 0000000000..165c4bdc88
--- /dev/null
+++ b/ext/dl/mkcbtable.rb
@@ -0,0 +1,18 @@
+# -*- ruby -*-
+
+require 'mkmf'
+$:.unshift File.dirname(__FILE__)
+require 'type'
+require 'dlconfig'
+
+def mktable(rettype, fnum, argc)
+ code =
+ "rb_dl_callback_table[#{rettype}][#{fnum}] = &rb_dl_callback_func_#{rettype.to_s}_#{fnum};"
+ return code
+end
+
+DLTYPE.keys.sort.each{|t|
+ for n in 0..(MAX_CALLBACK - 1)
+ print(mktable(t, n, 15), "\n")
+ end
+}
diff --git a/ext/dl/ptr.c b/ext/dl/ptr.c
new file mode 100644
index 0000000000..7e3d3549d3
--- /dev/null
+++ b/ext/dl/ptr.c
@@ -0,0 +1,1058 @@
+/* -*- C -*-
+ * $Id$
+ */
+
+#include <ruby.h>
+#include <ctype.h>
+#include "st.h"
+#include "dl.h"
+
+VALUE rb_cDLPtrData;
+VALUE rb_mDLMemorySpace;
+static st_table* st_memory_table;
+
+#ifndef T_SYMBOL
+# define T_SYMBOL T_FIXNUM
+#endif
+
+static void
+rb_dlmem_delete(void *ptr)
+{
+ rb_secure(4);
+ st_delete(st_memory_table, (st_data_t*)&ptr, NULL);
+}
+
+static void
+rb_dlmem_aset(void *ptr, VALUE obj)
+{
+ if (obj == Qnil) {
+ rb_dlmem_delete(ptr);
+ }
+ else{
+ st_insert(st_memory_table, (st_data_t)ptr, (st_data_t)obj);
+ }
+}
+
+static VALUE
+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;
+}
+
+void
+dlptr_free(struct ptr_data *data)
+{
+ if (data->ptr) {
+ DEBUG_CODE({
+ printf("dlptr_free(): removing the pointer `0x%x' from the MemorySpace\n",
+ data->ptr);
+ });
+ rb_dlmem_delete(data->ptr);
+ if (data->free) {
+ DEBUG_CODE({
+ printf("dlptr_free(): 0x%x(data->ptr:0x%x)\n",data->free,data->ptr);
+ });
+ (*(data->free))(data->ptr);
+ }
+ }
+ if (data->stype) dlfree(data->stype);
+ if (data->ssize) dlfree(data->ssize);
+ if (data->ids) dlfree(data->ids);
+}
+
+void
+dlptr_init(VALUE val)
+{
+ struct ptr_data *data;
+
+ Data_Get_Struct(val, struct ptr_data, data);
+ DEBUG_CODE({
+ printf("dlptr_init(): add the pointer `0x%x' to the MemorySpace\n",
+ data->ptr);
+ });
+ rb_dlmem_aset(data->ptr, val);
+ OBJ_TAINT(val);
+}
+
+VALUE
+rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func)
+{
+ struct ptr_data *data;
+ VALUE val;
+
+ rb_secure(4);
+ if (ptr) {
+ val = rb_dlmem_aref(ptr);
+ if (val == Qnil) {
+ val = Data_Make_Struct(klass, struct ptr_data,
+ 0, dlptr_free, data);
+ data->ptr = ptr;
+ data->free = func;
+ data->ctype = DLPTR_CTYPE_UNKNOWN;
+ data->stype = NULL;
+ data->ssize = NULL;
+ data->slen = 0;
+ data->size = size;
+ data->ids = NULL;
+ data->ids_num = 0;
+ dlptr_init(val);
+ }
+ else{
+ if (func) {
+ Data_Get_Struct(val, struct ptr_data, data);
+ data->free = func;
+ }
+ }
+ }
+ else{
+ val = Qnil;
+ }
+
+ return val;
+}
+
+VALUE
+rb_dlptr_new(void *ptr, long size, freefunc_t func)
+{
+ return rb_dlptr_new2(rb_cDLPtrData, ptr, size, func);
+}
+
+VALUE
+rb_dlptr_malloc(long size, freefunc_t func)
+{
+ void *ptr;
+
+ rb_secure(4);
+ ptr = dlmalloc((size_t)size);
+ memset(ptr,0,(size_t)size);
+ return rb_dlptr_new(ptr, size, func);
+}
+
+void *
+rb_dlptr2cptr(VALUE val)
+{
+ struct ptr_data *data;
+ void *ptr;
+
+ if (rb_obj_is_kind_of(val, rb_cDLPtrData)) {
+ Data_Get_Struct(val, struct ptr_data, data);
+ ptr = data->ptr;
+ }
+ else if (val == Qnil) {
+ ptr = NULL;
+ }
+ else{
+ rb_raise(rb_eTypeError, "DL::PtrData was expected");
+ }
+
+ return ptr;
+}
+
+static VALUE
+rb_dlptr_s_allocate(VALUE klass)
+{
+ VALUE obj;
+ struct ptr_data *data;
+
+ rb_secure(4);
+ obj = Data_Make_Struct(klass, struct ptr_data, 0, dlptr_free, data);
+ data->ptr = 0;
+ data->free = 0;
+ data->ctype = DLPTR_CTYPE_UNKNOWN;
+ data->stype = NULL;
+ data->ssize = NULL;
+ data->slen = 0;
+ data->size = 0;
+ data->ids = NULL;
+ data->ids_num = 0;
+
+ return obj;
+}
+
+static VALUE
+rb_dlptr_initialize(int argc, VALUE argv[], VALUE self)
+{
+ VALUE ptr, sym, size;
+ struct ptr_data *data;
+ void *p = NULL;
+ freefunc_t f = NULL;
+ long s = 0;
+
+ switch (rb_scan_args(argc, argv, "12", &ptr, &size, &sym)) {
+ case 1:
+ p = (void*)(DLNUM2LONG(rb_Integer(ptr)));
+ break;
+ case 2:
+ p = (void*)(DLNUM2LONG(rb_Integer(ptr)));
+ s = DLNUM2LONG(size);
+ break;
+ case 3:
+ p = (void*)(DLNUM2LONG(rb_Integer(ptr)));
+ s = DLNUM2LONG(size);
+ f = rb_dlsym2csym(sym);
+ break;
+ default:
+ rb_bug("rb_dlptr_initialize");
+ }
+
+ if (p) {
+ Data_Get_Struct(self, struct ptr_data, data);
+ if (data->ptr && data->free) {
+ /* Free previous memory. Use of inappropriate initialize may cause SEGV. */
+ (*(data->free))(data->ptr);
+ }
+ data->ptr = p;
+ data->size = s;
+ data->free = f;
+ }
+
+ return Qnil;
+}
+
+static VALUE
+rb_dlptr_s_malloc(int argc, VALUE argv[], VALUE klass)
+{
+ VALUE size, sym, obj;
+ int s;
+ freefunc_t f = NULL;
+
+ switch (rb_scan_args(argc, argv, "11", &size, &sym)) {
+ case 1:
+ s = NUM2INT(size);
+ break;
+ case 2:
+ s = NUM2INT(size);
+ f = rb_dlsym2csym(sym);
+ break;
+ default:
+ rb_bug("rb_dlptr_s_malloc");
+ }
+
+ obj = rb_dlptr_malloc(s,f);
+
+ return obj;
+}
+
+VALUE
+rb_dlptr_to_i(VALUE self)
+{
+ struct ptr_data *data;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+ return DLLONG2NUM(data->ptr);
+}
+
+VALUE
+rb_dlptr_ptr(VALUE self)
+{
+ struct ptr_data *data;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+ return rb_dlptr_new(*((void**)(data->ptr)),0,0);
+}
+
+VALUE
+rb_dlptr_ref(VALUE self)
+{
+ struct ptr_data *data;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+ return rb_dlptr_new(&(data->ptr),0,0);
+}
+
+VALUE
+rb_dlptr_null_p(VALUE self)
+{
+ struct ptr_data *data;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+ return data->ptr ? Qfalse : Qtrue;
+}
+
+VALUE
+rb_dlptr_free_set(VALUE self, VALUE val)
+{
+ struct ptr_data *data;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+
+ data->free = DLFREEFUNC(rb_dlsym2csym(val));
+
+ return Qnil;
+}
+
+VALUE
+rb_dlptr_free_get(VALUE self)
+{
+ struct ptr_data *pdata;
+
+ Data_Get_Struct(self, struct ptr_data, pdata);
+
+ return rb_dlsym_new(pdata->free,"(free)","0P");
+}
+
+VALUE
+rb_dlptr_to_array(int argc, VALUE argv[], VALUE self)
+{
+ struct ptr_data *data;
+ int n;
+ int i;
+ int t;
+ VALUE ary;
+ VALUE type, size;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+
+ switch (rb_scan_args(argc, argv, "11", &type, &size)) {
+ case 2:
+ t = StringValuePtr(type)[0];
+ n = NUM2INT(size);
+ break;
+ case 1:
+ t = StringValuePtr(type)[0];
+ switch (t) {
+ case 'C':
+ n = data->size;
+ break;
+ case 'H':
+ n = data->size / sizeof(short);
+ break;
+ case 'I':
+ n = data->size / sizeof(int);
+ break;
+ case 'L':
+ n = data->size / sizeof(long);
+ break;
+ case 'F':
+ n = data->size / sizeof(float);
+ break;
+ case 'D':
+ n = data->size / sizeof(double);
+ break;
+ case 'P': case 'p':
+ n = data->size / sizeof(void*);
+ break;
+ case 'S': case 's':
+ for (n=0; ((void**)(data->ptr))[n]; n++) {};
+ break;
+ default:
+ n = 0;
+ }
+ break;
+ default:
+ rb_bug("rb_dlptr_to_array");
+ }
+
+ ary = rb_ary_new();
+
+ for (i=0; i < n; i++) {
+ switch (t) {
+ case 'C':
+ rb_ary_push(ary, INT2NUM(((char*)(data->ptr))[i]));
+ break;
+ case 'H':
+ rb_ary_push(ary, INT2NUM(((short*)(data->ptr))[i]));
+ break;
+ case 'I':
+ rb_ary_push(ary, INT2NUM(((int*)(data->ptr))[i]));
+ break;
+ case 'L':
+ rb_ary_push(ary, DLLONG2NUM(((long*)(data->ptr))[i]));
+ break;
+ case 'D':
+ rb_ary_push(ary, rb_float_new(((double*)(data->ptr))[i]));
+ break;
+ case 'F':
+ rb_ary_push(ary, rb_float_new(((float*)(data->ptr))[i]));
+ break;
+ case 'S':
+ {
+ char *str = ((char**)(data->ptr))[i];
+ if (str) {
+ rb_ary_push(ary, rb_tainted_str_new2(str));
+ }
+ else{
+ rb_ary_push(ary, Qnil);
+ }
+ }
+ break;
+ case 's':
+ {
+ char *str = ((char**)(data->ptr))[i];
+ if (str) {
+ rb_ary_push(ary, rb_tainted_str_new2(str));
+ xfree(str);
+ }
+ else{
+ rb_ary_push(ary, Qnil);
+ }
+ }
+ break;
+ case 'P':
+ rb_ary_push(ary, rb_dlptr_new(((void**)(data->ptr))[i],0,0));
+ break;
+ case 'p':
+ rb_ary_push(ary,
+ rb_dlptr_new(((void**)(data->ptr))[i],0,dlfree));
+ break;
+ }
+ }
+
+ return ary;
+}
+
+
+VALUE
+rb_dlptr_to_s(int argc, VALUE argv[], VALUE self)
+{
+ struct ptr_data *data;
+ VALUE arg1, val;
+ int len;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+ switch (rb_scan_args(argc, argv, "01", &arg1)) {
+ case 0:
+ val = rb_tainted_str_new2((char*)(data->ptr));
+ break;
+ case 1:
+ len = NUM2INT(arg1);
+ val = rb_tainted_str_new((char*)(data->ptr), len);
+ break;
+ default:
+ rb_bug("rb_dlptr_to_s");
+ }
+
+ return val;
+}
+
+VALUE
+rb_dlptr_to_str(int argc, VALUE argv[], VALUE self)
+{
+ struct ptr_data *data;
+ VALUE arg1, val;
+ int len;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+ switch (rb_scan_args(argc, argv, "01", &arg1)) {
+ case 0:
+ val = rb_tainted_str_new((char*)(data->ptr),data->size);
+ break;
+ case 1:
+ len = NUM2INT(arg1);
+ val = rb_tainted_str_new((char*)(data->ptr), len);
+ break;
+ default:
+ rb_bug("rb_dlptr_to_str");
+ }
+
+ return val;
+}
+
+VALUE
+rb_dlptr_inspect(VALUE self)
+{
+ struct ptr_data *data;
+ 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);
+ return rb_str_new2(str);
+}
+
+VALUE
+rb_dlptr_eql(VALUE self, VALUE other)
+{
+ void *ptr1, *ptr2;
+ ptr1 = rb_dlptr2cptr(self);
+ ptr2 = rb_dlptr2cptr(other);
+
+ return ptr1 == ptr2 ? Qtrue : Qfalse;
+}
+
+VALUE
+rb_dlptr_cmp(VALUE self, VALUE other)
+{
+ void *ptr1, *ptr2;
+ ptr1 = rb_dlptr2cptr(self);
+ ptr2 = rb_dlptr2cptr(other);
+ return DLLONG2NUM((long)ptr1 - (long)ptr2);
+}
+
+VALUE
+rb_dlptr_plus(VALUE self, VALUE other)
+{
+ void *ptr;
+ long num, size;
+
+ ptr = rb_dlptr2cptr(self);
+ size = RDLPTR(self)->size;
+ num = DLNUM2LONG(other);
+ return rb_dlptr_new((char *)ptr + num, size - num, 0);
+}
+
+VALUE
+rb_dlptr_minus(VALUE self, VALUE other)
+{
+ void *ptr;
+ long num, size;
+
+ ptr = rb_dlptr2cptr(self);
+ size = RDLPTR(self)->size;
+ num = DLNUM2LONG(other);
+ return rb_dlptr_new((char *)ptr - num, size + num, 0);
+}
+
+VALUE
+rb_dlptr_define_data_type(int argc, VALUE argv[], VALUE self)
+{
+ VALUE data_type, type, rest, vid;
+ struct ptr_data *data;
+ int i, t, num;
+ char *ctype;
+
+ rb_scan_args(argc, argv, "11*", &data_type, &type, &rest);
+ Data_Get_Struct(self, struct ptr_data, data);
+
+ if (argc == 1 || (argc == 2 && type == Qnil)) {
+ if (NUM2INT(data_type) == DLPTR_CTYPE_UNKNOWN) {
+ data->ctype = DLPTR_CTYPE_UNKNOWN;
+ data->slen = 0;
+ data->ids_num = 0;
+ if (data->stype) {
+ dlfree(data->stype);
+ data->stype = NULL;
+ }
+ if (data->ids) {
+ dlfree(data->ids);
+ data->ids = NULL;
+ }
+ return Qnil;
+ }
+ else{
+ rb_raise(rb_eArgError, "wrong arguments");
+ }
+ }
+
+ t = NUM2INT(data_type);
+ StringValue(type);
+ Check_Type(rest, T_ARRAY);
+ num = RARRAY(rest)->len;
+ for (i=0; i<num; i++) {
+ rb_to_id(rb_ary_entry(rest,i));
+ }
+
+ data->ctype = t;
+ data->slen = num;
+ data->ids_num = num;
+ if (data->stype) dlfree(data->stype);
+ data->stype = (char*)dlmalloc(sizeof(char) * num);
+ if (data->ssize) dlfree(data->ssize);
+ data->ssize = (int*)dlmalloc(sizeof(int) * num);
+ if (data->ids) dlfree(data->ids);
+ data->ids = (ID*)dlmalloc(sizeof(ID) * data->ids_num);
+
+ ctype = StringValuePtr(type);
+ for (i=0; i<num; i++) {
+ vid = rb_ary_entry(rest,i);
+ data->ids[i] = rb_to_id(vid);
+ data->stype[i] = *ctype;
+ ctype ++;
+ if (isdigit(*ctype)) {
+ char *p, *d;
+ for (p=ctype; isdigit(*p); p++) ;
+ d = ALLOCA_N(char, p - ctype + 1);
+ strncpy(d, ctype, p - ctype);
+ d[p - ctype] = '\0';
+ data->ssize[i] = atoi(d);
+ ctype = p;
+ }
+ else{
+ data->ssize[i] = 1;
+ }
+ }
+
+ if (*ctype) {
+ rb_raise(rb_eArgError, "too few/many arguments");
+ }
+
+ if (!data->size)
+ data->size = dlsizeof(RSTRING(type)->ptr);
+
+ return Qnil;
+}
+
+VALUE
+rb_dlptr_define_struct(int argc, VALUE argv[], VALUE self)
+{
+ VALUE *pass_argv;
+ int pass_argc, i;
+
+ pass_argc = argc + 1;
+ pass_argv = ALLOCA_N(VALUE, pass_argc);
+ pass_argv[0] = INT2FIX(DLPTR_CTYPE_STRUCT);
+ for (i=1; i<pass_argc; i++) {
+ pass_argv[i] = argv[i-1];
+ }
+ return rb_dlptr_define_data_type(pass_argc, pass_argv, self);
+}
+
+VALUE
+rb_dlptr_define_union(int argc, VALUE argv[], VALUE self)
+{
+ VALUE *pass_argv;
+ int pass_argc, i;
+
+ pass_argc = argc + 1;
+ pass_argv = ALLOCA_N(VALUE, pass_argc);
+ pass_argv[0] = INT2FIX(DLPTR_CTYPE_UNION);
+ for (i=1; i<pass_argc; i++) {
+ pass_argv[i] = argv[i-1];
+ }
+ return rb_dlptr_define_data_type(pass_argc, pass_argv, self);
+}
+
+VALUE
+rb_dlptr_get_data_type(VALUE self)
+{
+ struct ptr_data *data;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+ if (data->stype)
+ return rb_assoc_new(INT2FIX(data->ctype),
+ rb_tainted_str_new(data->stype, data->slen));
+ else
+ return rb_assoc_new(INT2FIX(data->ctype), Qnil);
+}
+
+static VALUE
+cary2ary(void *ptr, char t, int len)
+{
+ VALUE ary;
+ VALUE elem;
+ int i;
+
+ if (len < 1)
+ return Qnil;
+
+ if (len == 1) {
+ switch (t) {
+ case 'I':
+ elem = INT2NUM(*((int*)ptr));
+ ptr = (char *)ptr + sizeof(int);
+ break;
+ case 'L':
+ elem = DLLONG2NUM(*((long*)ptr));
+ ptr = (char *)ptr + sizeof(long);
+ break;
+ case 'P':
+ case 'S':
+ elem = rb_dlptr_new(*((void**)ptr),0, 0);
+ ptr = (char *)ptr + sizeof(void*);
+ break;
+ case 'F':
+ elem = rb_float_new(*((float*)ptr));
+ ptr = (char *)ptr + sizeof(float);
+ break;
+ case 'D':
+ elem = rb_float_new(*((double*)ptr));
+ ptr = (char *)ptr + sizeof(double);
+ break;
+ case 'C':
+ elem = INT2NUM(*((char*)ptr));
+ ptr = (char *)ptr + sizeof(char);
+ break;
+ case 'H':
+ elem = INT2NUM(*((short*)ptr));
+ ptr = (char *)ptr + sizeof(short);
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unsupported type '%c'", t);
+ }
+ return elem;
+ }
+
+ ary = rb_ary_new();
+ for (i=0; i < len; i++) {
+ switch (t) {
+ case 'I':
+ elem = INT2NUM(*((int*)ptr));
+ ptr = (char *)ptr + sizeof(int);
+ break;
+ case 'L':
+ elem = DLLONG2NUM(*((long*)ptr));
+ ptr = (char *)ptr + sizeof(long);
+ break;
+ case 'P':
+ case 'S':
+ elem = rb_dlptr_new(*((void**)ptr), 0, 0);
+ ptr = (char *)ptr + sizeof(void*);
+ break;
+ case 'F':
+ elem = rb_float_new(*((float*)ptr));
+ ptr = (char *)ptr + sizeof(float);
+ break;
+ case 'D':
+ elem = rb_float_new(*((float*)ptr));
+ ptr = (char *)ptr + sizeof(double);
+ break;
+ case 'C':
+ elem = INT2NUM(*((char*)ptr));
+ ptr = (char *)ptr + sizeof(char);
+ break;
+ case 'H':
+ elem = INT2NUM(*((short*)ptr));
+ ptr = (char *)ptr + sizeof(short);
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unsupported type '%c'", t);
+ }
+ rb_ary_push(ary, elem);
+ }
+
+ return ary;
+}
+
+VALUE
+rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
+{
+ VALUE key = Qnil, num = Qnil;
+ ID id;
+ struct ptr_data *data;
+ int i;
+ int offset;
+
+ if (rb_scan_args(argc, argv, "11", &key, &num) == 1) {
+ num = INT2NUM(0);
+ }
+
+ if (TYPE(key) == T_FIXNUM || TYPE(key) == T_BIGNUM) {
+ VALUE pass[1];
+ pass[0] = num;
+ return rb_dlptr_to_str(1, pass, rb_dlptr_plus(self, key));
+ }
+ rb_to_id(key);
+ if (! (TYPE(key) == T_STRING || TYPE(key) == T_SYMBOL)) {
+ rb_raise(rb_eTypeError, "the key must be a string or symbol");
+ }
+
+ id = rb_to_id(key);
+ Data_Get_Struct(self, struct ptr_data, data);
+ offset = 0;
+ switch (data->ctype) {
+ case DLPTR_CTYPE_STRUCT:
+ for (i=0; i < data->ids_num; i++) {
+ switch (data->stype[i]) {
+ case 'I':
+ DLALIGN(data->ptr,offset,INT_ALIGN);
+ break;
+ case 'L':
+ DLALIGN(data->ptr,offset,LONG_ALIGN);
+ break;
+ case 'P':
+ case 'S':
+ DLALIGN(data->ptr,offset,VOIDP_ALIGN);
+ break;
+ case 'F':
+ DLALIGN(data->ptr,offset,FLOAT_ALIGN);
+ break;
+ case 'D':
+ DLALIGN(data->ptr,offset,DOUBLE_ALIGN);
+ break;
+ case 'C':
+ break;
+ case 'H':
+ DLALIGN(data->ptr,offset,SHORT_ALIGN);
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]);
+ }
+ if (data->ids[i] == id) {
+ return cary2ary((char *)data->ptr + offset, data->stype[i], data->ssize[i]);
+ }
+ switch (data->stype[i]) {
+ case 'I':
+ offset += sizeof(int) * data->ssize[i];
+ break;
+ case 'L':
+ offset += sizeof(long) * data->ssize[i];
+ break;
+ case 'P':
+ case 'S':
+ offset += sizeof(void*) * data->ssize[i];
+ break;
+ case 'F':
+ offset += sizeof(float) * data->ssize[i];
+ break;
+ case 'D':
+ offset += sizeof(double) * data->ssize[i];
+ break;
+ case 'C':
+ offset += sizeof(char) * data->ssize[i];
+ break;
+ case 'H':
+ offset += sizeof(short) * data->ssize[i];
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]);
+ }
+ }
+ break;
+ case DLPTR_CTYPE_UNION:
+ for (i=0; i < data->ids_num; i++) {
+ if (data->ids[i] == id) {
+ return cary2ary((char *)data->ptr + offset, data->stype[i], data->ssize[i]);
+ }
+ }
+ break;
+ } /* end of switch */
+
+ rb_raise(rb_eNameError, "undefined key `%s' for %s",
+ rb_id2name(id), rb_class2name(CLASS_OF(self)));
+
+ return Qnil;
+}
+
+static void *
+ary2cary(char t, VALUE val, long *size)
+{
+ void *ptr;
+
+ if (TYPE(val) == T_ARRAY) {
+ ptr = rb_ary2cary(t, val, size);
+ }
+ else{
+ ptr = rb_ary2cary(t, rb_ary_new3(1, val), size);
+ }
+ return ptr;
+}
+
+VALUE
+rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
+{
+ VALUE key = Qnil, num = Qnil, val = Qnil;
+ ID id;
+ struct ptr_data *data;
+ int i;
+ int offset;
+ long memsize;
+ void *memimg;
+
+ rb_secure(4);
+ switch (rb_scan_args(argc, argv, "21", &key, &num, &val)) {
+ case 2:
+ val = num;
+ num = Qnil;
+ break;
+ }
+
+ if (TYPE(key) == T_FIXNUM || TYPE(key) == T_BIGNUM) {
+ void *dst, *src;
+ long len;
+
+ StringValue(val);
+ Data_Get_Struct(self, struct ptr_data, data);
+ dst = (void*)((long)(data->ptr) + DLNUM2LONG(key));
+ src = RSTRING(val)->ptr;
+ len = RSTRING(val)->len;
+ if (num == Qnil) {
+ memcpy(dst, src, len);
+ }
+ else{
+ long n = NUM2INT(num);
+ memcpy(dst, src, n < len ? n : len);
+ if (n > len) MEMZERO((char*)dst + len, char, n - len);
+ }
+ return val;
+ }
+
+ id = rb_to_id(key);
+ Data_Get_Struct(self, struct ptr_data, data);
+ switch (data->ctype) {
+ case DLPTR_CTYPE_STRUCT:
+ offset = 0;
+ for (i=0; i < data->ids_num; i++) {
+ switch (data->stype[i]) {
+ case 'I':
+ DLALIGN(data->ptr,offset,INT_ALIGN);
+ break;
+ case 'L':
+ DLALIGN(data->ptr,offset,LONG_ALIGN);
+ break;
+ case 'P':
+ case 'S':
+ DLALIGN(data->ptr,offset,VOIDP_ALIGN);
+ break;
+ case 'D':
+ DLALIGN(data->ptr,offset,DOUBLE_ALIGN);
+ break;
+ case 'F':
+ DLALIGN(data->ptr,offset,FLOAT_ALIGN);
+ break;
+ case 'C':
+ break;
+ case 'H':
+ DLALIGN(data->ptr,offset,SHORT_ALIGN);
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]);
+ }
+ if (data->ids[i] == id) {
+ memimg = ary2cary(data->stype[i], val, &memsize);
+ memcpy((char *)data->ptr + offset, memimg, memsize);
+ dlfree(memimg);
+ return val;
+ }
+ switch (data->stype[i]) {
+ case 'I':
+ case 'i':
+ offset += sizeof(int) * data->ssize[i];
+ break;
+ case 'L':
+ case 'l':
+ offset += sizeof(long) * data->ssize[i];
+ break;
+ case 'P':
+ case 'p':
+ case 'S':
+ case 's':
+ offset += sizeof(void*) * data->ssize[i];
+ break;
+ case 'D':
+ case 'd':
+ offset += sizeof(double) * data->ssize[i];
+ break;
+ case 'F':
+ case 'f':
+ offset += sizeof(float) * data->ssize[i];
+ break;
+ case 'C':
+ case 'c':
+ offset += sizeof(char) * data->ssize[i];
+ break;
+ case 'H':
+ case 'h':
+ offset += sizeof(short) * data->ssize[i];
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]);
+ }
+ }
+ return val;
+ /* break; */
+ case DLPTR_CTYPE_UNION:
+ for (i=0; i < data->ids_num; i++) {
+ if (data->ids[i] == id) {
+ switch (data->stype[i]) {
+ case 'I': case 'i':
+ memsize = sizeof(int) * data->ssize[i];
+ break;
+ case 'L': case 'l':
+ memsize = sizeof(long) * data->ssize[i];
+ break;
+ case 'P': case 'p':
+ case 'S': case 's':
+ memsize = sizeof(void*) * data->ssize[i];
+ break;
+ case 'F': case 'f':
+ memsize = sizeof(float) * data->ssize[i];
+ break;
+ case 'D': case 'd':
+ memsize = sizeof(double) * data->ssize[i];
+ break;
+ case 'C': case 'c':
+ memsize = sizeof(char) * data->ssize[i];
+ break;
+ case 'H': case 'h':
+ memsize = sizeof(short) * data->ssize[i];
+ break;
+ default:
+ rb_raise(rb_eDLTypeError, "unsupported type '%c'", data->stype[i]);
+ }
+ memimg = ary2cary(data->stype[i], val, NULL);
+ memcpy(data->ptr, memimg, memsize);
+ dlfree(memimg);
+ }
+ }
+ return val;
+ /* break; */
+ }
+
+ rb_raise(rb_eNameError, "undefined key `%s' for %s",
+ rb_id2name(id), rb_class2name(CLASS_OF(self)));
+
+ return Qnil;
+}
+
+VALUE
+rb_dlptr_size(int argc, VALUE argv[], VALUE self)
+{
+ VALUE size;
+
+ if (rb_scan_args(argc, argv, "01", &size) == 0){
+ return DLLONG2NUM(RDLPTR(self)->size);
+ }
+ else{
+ RDLPTR(self)->size = DLNUM2LONG(size);
+ return size;
+ }
+}
+
+static int
+dlmem_each_i(void* key, VALUE value, void* arg)
+{
+ VALUE vkey = DLLONG2NUM(key);
+ rb_yield(rb_assoc_new(vkey, value));
+ return Qnil;
+}
+
+VALUE
+rb_dlmem_each(VALUE self)
+{
+ st_foreach(st_memory_table, dlmem_each_i, 0);
+ return Qnil;
+}
+
+void
+Init_dlptr()
+{
+ rb_cDLPtrData = rb_define_class_under(rb_mDL, "PtrData", rb_cObject);
+ rb_define_alloc_func(rb_cDLPtrData, rb_dlptr_s_allocate);
+ rb_define_singleton_method(rb_cDLPtrData, "malloc", rb_dlptr_s_malloc, -1);
+ rb_define_method(rb_cDLPtrData, "initialize", rb_dlptr_initialize, -1);
+ rb_define_method(rb_cDLPtrData, "free=", rb_dlptr_free_set, 1);
+ rb_define_method(rb_cDLPtrData, "free", rb_dlptr_free_get, 0);
+ rb_define_method(rb_cDLPtrData, "to_i", rb_dlptr_to_i, 0);
+ rb_define_method(rb_cDLPtrData, "ptr", rb_dlptr_ptr, 0);
+ rb_define_method(rb_cDLPtrData, "+@", rb_dlptr_ptr, 0);
+ rb_define_method(rb_cDLPtrData, "ref", rb_dlptr_ref, 0);
+ rb_define_method(rb_cDLPtrData, "-@", rb_dlptr_ref, 0);
+ rb_define_method(rb_cDLPtrData, "null?", rb_dlptr_null_p, 0);
+ rb_define_method(rb_cDLPtrData, "to_a", rb_dlptr_to_array, -1);
+ rb_define_method(rb_cDLPtrData, "to_s", rb_dlptr_to_s, -1);
+ rb_define_method(rb_cDLPtrData, "to_str", rb_dlptr_to_str, -1);
+ rb_define_method(rb_cDLPtrData, "inspect", rb_dlptr_inspect, 0);
+ rb_define_method(rb_cDLPtrData, "<=>", rb_dlptr_cmp, 1);
+ rb_define_method(rb_cDLPtrData, "==", rb_dlptr_eql, 1);
+ rb_define_method(rb_cDLPtrData, "eql?", rb_dlptr_eql, 1);
+ rb_define_method(rb_cDLPtrData, "+", rb_dlptr_plus, 1);
+ rb_define_method(rb_cDLPtrData, "-", rb_dlptr_minus, 1);
+ rb_define_method(rb_cDLPtrData, "define_data_type",
+ rb_dlptr_define_data_type, -1);
+ rb_define_method(rb_cDLPtrData, "struct!", rb_dlptr_define_struct, -1);
+ rb_define_method(rb_cDLPtrData, "union!", rb_dlptr_define_union, -1);
+ rb_define_method(rb_cDLPtrData, "data_type", rb_dlptr_get_data_type, 0);
+ rb_define_method(rb_cDLPtrData, "[]", rb_dlptr_aref, -1);
+ rb_define_method(rb_cDLPtrData, "[]=", rb_dlptr_aset, -1);
+ rb_define_method(rb_cDLPtrData, "size", rb_dlptr_size, -1);
+ 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 */
+ rb_define_module_function(rb_mDLMemorySpace, "each", rb_dlmem_each, 0);
+}
diff --git a/ext/dl/sample/c++sample.C b/ext/dl/sample/c++sample.C
new file mode 100644
index 0000000000..d083d337a7
--- /dev/null
+++ b/ext/dl/sample/c++sample.C
@@ -0,0 +1,35 @@
+#include <stdio.h>
+
+class Person {
+private:
+ const char *name;
+ int age;
+
+public:
+ Person(const char *name, int age);
+ const char * get_name();
+ int get_age();
+ void set_age(int i);
+};
+
+Person::Person(const char *name, int age)
+ : name(name), age(age)
+{
+ /* empty */
+}
+
+const char *
+Person::get_name()
+{
+ return name;
+}
+
+int
+Person::get_age(){
+ return age;
+}
+
+void
+Person::set_age(int i){
+ age = i;
+}
diff --git a/ext/dl/sample/c++sample.rb b/ext/dl/sample/c++sample.rb
new file mode 100644
index 0000000000..29887df845
--- /dev/null
+++ b/ext/dl/sample/c++sample.rb
@@ -0,0 +1,60 @@
+=begin
+ This script shows how to deal with C++ classes using Ruby/DL.
+ You must build a dynamic loadable library using "c++sample.C"
+ to run this script as follows:
+ $ g++ -o libsample.so -shared c++sample.C
+=end
+
+require 'dl'
+require 'dl/import'
+require 'dl/struct'
+
+# Give a name of dynamic loadable library
+LIBNAME = ARGV[0] || "libsample.so"
+
+class Person
+ module Core
+ extend DL::Importable
+
+ dlload LIBNAME
+
+ # mangled symbol names
+ extern "void __6PersonPCci(void *, const char *, int)"
+ extern "const char *get_name__6Person(void *)"
+ extern "int get_age__6Person(void *)"
+ extern "void set_age__6Personi(void *, int)"
+
+ Data = struct [
+ "char *name",
+ "int age",
+ ]
+ end
+
+ def initialize(name, age)
+ @ptr = Core::Data.alloc
+ Core::__6PersonPCci(@ptr, name, age)
+ end
+
+ def get_name()
+ str = Core::get_name__6Person(@ptr)
+ if( str )
+ str.to_s
+ else
+ nil
+ end
+ end
+
+ def get_age()
+ Core::get_age__6Person(@ptr)
+ end
+
+ def set_age(age)
+ Core::set_age__6Personi(@ptr, age)
+ end
+end
+
+obj = Person.new("ttate", 1)
+p obj.get_name()
+p obj.get_age()
+obj.set_age(10)
+p obj.get_age()
diff --git a/ext/dl/sample/drives.rb b/ext/dl/sample/drives.rb
new file mode 100644
index 0000000000..8a590404b1
--- /dev/null
+++ b/ext/dl/sample/drives.rb
@@ -0,0 +1,70 @@
+# -*- ruby -*-
+# drives.rb -- find existing drives and show the drive type.
+
+require 'dl'
+require 'dl/import'
+
+module Kernel32
+ extend DL::Importable
+
+ dlload "kernel32"
+
+ extern "long GetLogicalDrives()"
+ extern "int GetDriveType(char*)"
+ extern "long GetDiskFreeSpace(char*, long ref, long ref, long ref, long ref)"
+end
+
+include Kernel32
+
+buff = Kernel32.getLogicalDrives()
+
+i = 0
+ds = []
+while( i < 26 )
+ mask = (1 << i)
+ if( buff & mask > 0 )
+ ds.push((65+i).chr)
+ end
+ i += 1
+end
+
+=begin
+From the cygwin's /usr/include/w32api/winbase.h:
+#define DRIVE_UNKNOWN 0
+#define DRIVE_NO_ROOT_DIR 1
+#define DRIVE_REMOVABLE 2
+#define DRIVE_FIXED 3
+#define DRIVE_REMOTE 4
+#define DRIVE_CDROM 5
+#define DRIVE_RAMDISK 6
+=end
+
+types = [
+ "unknown",
+ "no root dir",
+ "Removable",
+ "Fixed",
+ "Remote",
+ "CDROM",
+ "RAM",
+]
+print("Drive : Type (Free Space/Available Space)\n")
+ds.each{|d|
+ t = Kernel32.getDriveType(d + ":\\")
+ Kernel32.getDiskFreeSpace(d + ":\\", 0, 0, 0, 0)
+ _,sec_per_clus,byte_per_sec,free_clus,total_clus = Kernel32._args_
+ fbytes = sec_per_clus * byte_per_sec * free_clus
+ tbytes = sec_per_clus * byte_per_sec * total_clus
+ unit = "B"
+ if( fbytes > 1024 && tbytes > 1024 )
+ fbytes = fbytes / 1024
+ tbytes = tbytes / 1024
+ unit = "K"
+ end
+ if( fbytes > 1024 && tbytes > 1024 )
+ fbytes = fbytes / 1024
+ tbytes = tbytes / 1024
+ unit = "M"
+ end
+ print("#{d} : #{types[t]} (#{fbytes} #{unit}/#{tbytes} #{unit})\n")
+}
diff --git a/ext/dl/sample/getch.rb b/ext/dl/sample/getch.rb
new file mode 100644
index 0000000000..3f7261c979
--- /dev/null
+++ b/ext/dl/sample/getch.rb
@@ -0,0 +1,5 @@
+require 'dl'
+
+crtdll = DL::dlopen("crtdll")
+getch = crtdll['_getch', 'L']
+print(getch.call, "\n")
diff --git a/ext/dl/sample/libc.rb b/ext/dl/sample/libc.rb
new file mode 100644
index 0000000000..a1f6fbe543
--- /dev/null
+++ b/ext/dl/sample/libc.rb
@@ -0,0 +1,69 @@
+require "dl/import"
+require "dl/struct"
+
+module LIBC
+ extend DL::Importable
+
+ begin
+ dlload "libc.so.6"
+ rescue
+ dlload "libc.so.5"
+ end
+
+ extern "int atoi(char*)"
+ extern "ibool isdigit(int)"
+ extern "int gettimeofday(struct timeval *, struct timezone *)"
+ extern "char* strcat(char*, char*)"
+ extern "FILE* fopen(char*, char*)"
+ extern "int fclose(FILE*)"
+ extern "int fgetc(FILE*)"
+ extern "int strlen(char*)"
+ extern "void qsort(void*, int, int, void*)"
+
+ def str_qsort(ary, comp)
+ len = ary.length
+ r,rs = qsort(ary, len, DL.sizeof('P'), comp)
+ return rs[0].to_a('S', len)
+ end
+
+ Timeval = struct [
+ "long tv_sec",
+ "long tv_usec",
+ ]
+
+ Timezone = struct [
+ "int tz_minuteswest",
+ "int tz_dsttime",
+ ]
+
+ def my_compare(ptr1, ptr2)
+ ptr1.ptr.to_s <=> ptr2.ptr.to_s
+ end
+ COMPARE = callback("int my_compare(char**, char**)")
+end
+
+
+$cb1 = DL.callback('IPP'){|ptr1, ptr2|
+ str1 = ptr1.ptr.to_s
+ str2 = ptr2.ptr.to_s
+ str1 <=> str2
+}
+
+p LIBC.atoi("10")
+
+p LIBC.isdigit(?1)
+
+p LIBC.isdigit(?a)
+
+p LIBC.strcat("a", "b")
+
+ary = ["a","c","b"]
+ptr = ary.to_ptr
+LIBC.qsort(ptr, ary.length, DL.sizeof('P'), LIBC::COMPARE)
+p ptr.to_a('S', ary.length)
+
+tv = LIBC::Timeval.malloc
+tz = LIBC::Timezone.malloc
+LIBC.gettimeofday(tv, tz)
+
+p Time.at(tv.tv_sec)
diff --git a/ext/dl/sample/msgbox.rb b/ext/dl/sample/msgbox.rb
new file mode 100644
index 0000000000..091e646091
--- /dev/null
+++ b/ext/dl/sample/msgbox.rb
@@ -0,0 +1,19 @@
+# This script works on Windows.
+
+require 'dl'
+
+User32 = DL.dlopen("user32")
+Kernel32 = DL.dlopen("kernel32")
+
+MB_OK = 0
+MB_OKCANCEL = 1
+
+message_box = User32['MessageBoxA', 'ILSSI']
+r,rs = message_box.call(0, 'ok?', 'error', MB_OKCANCEL)
+
+case r
+when 1
+ print("OK!\n")
+when 2
+ print("Cancel!\n")
+end
diff --git a/ext/dl/sample/msgbox2.rb b/ext/dl/sample/msgbox2.rb
new file mode 100644
index 0000000000..e49846cc5e
--- /dev/null
+++ b/ext/dl/sample/msgbox2.rb
@@ -0,0 +1,18 @@
+# This script works on Windows.
+
+require 'dl/win32'
+
+MB_OK = 0
+MB_OKCANCEL = 1
+
+message_box = Win32API.new("user32",'MessageBoxA', 'ISSI', 'I')
+r = message_box.call(0, 'ok?', 'error', MB_OKCANCEL)
+
+case r
+when 1
+ print("OK!\n")
+when 2
+ print("Cancel!\n")
+else
+ p r
+end
diff --git a/ext/dl/sample/stream.rb b/ext/dl/sample/stream.rb
new file mode 100644
index 0000000000..179836999d
--- /dev/null
+++ b/ext/dl/sample/stream.rb
@@ -0,0 +1,87 @@
+# -*- ruby -*-
+# Display a file name and stream names of a file with those size.
+
+require 'dl'
+require 'dl/import'
+
+module NTFS
+ extend DL::Importable
+
+ dlload "kernel32.dll"
+
+ OPEN_EXISTING = 3
+ GENERIC_READ = 0x80000000
+ BACKUP_DATA = 0x00000001
+ BACKUP_ALTERNATE_DATA = 0x00000004
+ FILE_SHARE_READ = 0x00000001
+ FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
+
+ typealias "LPSECURITY_ATTRIBUTES", "void*"
+
+ extern "BOOL BackupRead(HANDLE, PBYTE, DWORD, PDWORD, BOOL, BOOL, PVOID)"
+ extern "BOOL BackupSeek(HANDLE, DWORD, DWORD, PDWORD, PDWORD, PVOID)"
+ extern "BOOL CloseHandle(HANDLE)"
+ extern "HANDLE CreateFile(LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES,
+ DWORD, DWORD, HANDLE)"
+
+ module_function
+
+ def streams(filename)
+ status = []
+ h = createFile(filename,GENERIC_READ,FILE_SHARE_READ,nil,
+ OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,0)
+ if( h != 0 )
+ begin
+ # allocate the memory for backup data used in backupRead().
+ data = DL.malloc(DL.sizeof("L5"))
+ data.struct!("LLLLL", :id, :attrs, :size_low, :size_high, :name_size)
+
+ # allocate memories for references to long values used in backupRead().
+ context = DL.malloc(DL.sizeof("L"))
+ lval = DL.malloc(DL.sizeof("L"))
+
+ while( backupRead(h, data, data.size, lval, false, false, context) )
+ size = data[:size_low] + (data[:size_high] << (DL.sizeof("I") * 8))
+ case data[:id]
+ when BACKUP_ALTERNATE_DATA
+ stream_name = DL.malloc(data[:name_size])
+ backupRead(h, stream_name, stream_name.size,
+ lval, false, false, context)
+ name = stream_name[0, stream_name.size]
+ name.tr!("\000","")
+ if( name =~ /^:(.*?):.*$/ )
+ status.push([$1,size])
+ end
+ when BACKUP_DATA
+ status.push([nil,size])
+ else
+ raise(RuntimeError, "unknown data type #{data[:id]}.")
+ end
+ l1 = DL.malloc(DL.sizeof("L"))
+ l2 = DL.malloc(DL.sizeof("L"))
+ if( !backupSeek(h, data[:size_low], data[:size_high], l1, l2, context) )
+ break
+ end
+ end
+ ensure
+ backupRead(h, nil, 0, lval, true, false, context)
+ closeHandle(h)
+ end
+ return status
+ else
+ raise(RuntimeError, "can't open #{filename}.\n")
+ end
+ end
+end
+
+ARGV.each{|filename|
+ if( File.exist?(filename) )
+ NTFS.streams(filename).each{|name,size|
+ if( name )
+ print("#{filename}:#{name}\t#{size}bytes\n")
+ else
+ print("#{filename}\t#{size}bytes\n")
+ end
+ }
+ end
+}
diff --git a/ext/dl/sym.c b/ext/dl/sym.c
new file mode 100644
index 0000000000..933fb7f4f0
--- /dev/null
+++ b/ext/dl/sym.c
@@ -0,0 +1,993 @@
+/* -*- C -*-
+ * $Id$
+ */
+
+#include <ruby.h>
+#include <errno.h>
+#include "dl.h"
+
+VALUE rb_cDLSymbol;
+
+static const char *
+char2type(int ch)
+{
+ switch (ch) {
+ case '0':
+ return "void";
+ case 'P':
+ return "void *";
+ case 'p':
+ return "void *";
+ case 'C':
+ return "char";
+ case 'c':
+ return "char *";
+ case 'H':
+ return "short";
+ case 'h':
+ return "short *";
+ case 'I':
+ return "int";
+ case 'i':
+ return "int *";
+ case 'L':
+ return "long";
+ case 'l':
+ return "long *";
+ case 'F':
+ return "double";
+ case 'f':
+ return "double *";
+ case 'D':
+ return "double";
+ case 'd':
+ return "double *";
+ case 'S':
+ return "const char *";
+ case 's':
+ return "char *";
+ case 'A':
+ return "[]";
+ case 'a':
+ return "[]"; /* ?? */
+ }
+ return NULL;
+}
+
+void
+dlsym_free(struct sym_data *data)
+{
+ if( data->name ){
+ DEBUG_CODE({
+ printf("dlsym_free(): free(data->name:%s)\n",data->name);
+ });
+ free(data->name);
+ }
+ if( data->type ){
+ DEBUG_CODE({
+ printf("dlsym_free(): free(data->type:%s)\n",data->type);
+ });
+ free(data->type);
+ }
+}
+
+VALUE
+rb_dlsym_new(void (*func)(), const char *name, const char *type)
+{
+ VALUE val;
+ struct sym_data *data;
+ const char *ptype;
+
+ rb_secure(4);
+ if( !type || !type[0] ){
+ return rb_dlptr_new((void*)func, 0, 0);
+ }
+
+ for( ptype = type; *ptype; ptype ++ ){
+ if( ! char2type(*ptype) ){
+ rb_raise(rb_eDLTypeError, "unknown type specifier '%c'", *ptype);
+ }
+ }
+
+ if( func ){
+ val = Data_Make_Struct(rb_cDLSymbol, struct sym_data, 0, dlsym_free, data);
+ data->func = func;
+ data->name = name ? strdup(name) : NULL;
+ data->type = type ? strdup(type) : NULL;
+ data->len = type ? strlen(type) : 0;
+#if !(defined(DLSTACK))
+ if( data->len - 1 > MAX_ARG ){
+ rb_raise(rb_eDLError, "maximum number of arguments is %d.", MAX_ARG);
+ }
+#endif
+ }
+ else{
+ val = Qnil;
+ }
+
+ return val;
+}
+
+freefunc_t
+rb_dlsym2csym(VALUE val)
+{
+ struct sym_data *data;
+ freefunc_t func;
+
+ if( rb_obj_is_kind_of(val, rb_cDLSymbol) ){
+ Data_Get_Struct(val, struct sym_data, data);
+ func = data->func;
+ }
+ else if( val == Qnil ){
+ func = NULL;
+ }
+ else{
+ rb_raise(rb_eTypeError, "DL::Symbol was expected");
+ }
+
+ return func;
+}
+
+VALUE
+rb_dlsym_s_allocate(VALUE klass)
+{
+ VALUE obj;
+ struct sym_data *data;
+
+ obj = Data_Make_Struct(klass, struct sym_data, 0, dlsym_free, data);
+ data->func = 0;
+ data->name = 0;
+ data->type = 0;
+ data->len = 0;
+
+ return obj;
+}
+
+VALUE
+rb_dlsym_initialize(int argc, VALUE argv[], VALUE self)
+{
+ VALUE addr, name, type;
+ struct sym_data *data;
+ void *saddr;
+ const char *sname, *stype;
+
+ rb_scan_args(argc, argv, "12", &addr, &name, &type);
+
+ saddr = (void*)(DLNUM2LONG(rb_Integer(addr)));
+ if (!NIL_P(name)) StringValue(name);
+ stype = NIL_P(type) ? NULL : StringValuePtr(type);
+ sname = NIL_P(name) ? NULL : RSTRING(name)->ptr;
+
+ if( saddr ){
+ Data_Get_Struct(self, struct sym_data, data);
+ if( data->name ) free(data->name);
+ if( data->type ) free(data->type);
+ data->func = saddr;
+ data->name = sname ? strdup(sname) : 0;
+ data->type = stype ? strdup(stype) : 0;
+ data->len = stype ? strlen(stype) : 0;
+ }
+
+ return Qnil;
+}
+
+VALUE
+rb_s_dlsym_char2type(VALUE self, VALUE ch)
+{
+ const char *type;
+
+ type = char2type(StringValuePtr(ch)[0]);
+
+ if (type == NULL)
+ return Qnil;
+ else
+ return rb_str_new2(type);
+}
+
+VALUE
+rb_dlsym_name(VALUE self)
+{
+ struct sym_data *sym;
+
+ Data_Get_Struct(self, struct sym_data, sym);
+ return sym->name ? rb_tainted_str_new2(sym->name) : Qnil;
+}
+
+VALUE
+rb_dlsym_proto(VALUE self)
+{
+ struct sym_data *sym;
+
+ Data_Get_Struct(self, struct sym_data, sym);
+ return sym->type ? rb_tainted_str_new2(sym->type) : Qnil;
+}
+
+VALUE
+rb_dlsym_cproto(VALUE self)
+{
+ struct sym_data *sym;
+ const char *ptype, *typestr;
+ size_t len;
+ VALUE val;
+
+ Data_Get_Struct(self, struct sym_data, sym);
+
+ ptype = sym->type;
+
+ if( ptype ){
+ typestr = char2type(*ptype++);
+ len = strlen(typestr);
+
+ val = rb_tainted_str_new(typestr, len);
+ if (typestr[len - 1] != '*')
+ rb_str_cat(val, " ", 1);
+
+ if( sym->name ){
+ rb_str_cat2(val, sym->name);
+ }
+ else{
+ rb_str_cat2(val, "(null)");
+ }
+ rb_str_cat(val, "(", 1);
+
+ while (*ptype) {
+ const char *ty = char2type(*ptype++);
+ rb_str_cat2(val, ty);
+ if (*ptype)
+ rb_str_cat(val, ", ", 2);
+ }
+
+ rb_str_cat(val, ");", 2);
+ }
+ else{
+ val = rb_tainted_str_new2("void (");
+ if( sym->name ){
+ rb_str_cat2(val, sym->name);
+ }
+ else{
+ rb_str_cat2(val, "(null)");
+ }
+ rb_str_cat2(val, ")()");
+ }
+
+ return val;
+}
+
+VALUE
+rb_dlsym_inspect(VALUE self)
+{
+ VALUE proto;
+ VALUE val;
+ char *str;
+ int str_size;
+ struct sym_data *sym;
+
+ Data_Get_Struct(self, struct sym_data, sym);
+ proto = rb_dlsym_cproto(self);
+
+ str_size = RSTRING(proto)->len + 100;
+ str = dlmalloc(str_size);
+ snprintf(str, str_size - 1,
+ "#<DL::Symbol:0x%lx func=0x%lx '%s'>",
+ sym, sym->func, RSTRING(proto)->ptr);
+ val = rb_tainted_str_new2(str);
+ dlfree(str);
+
+ return val;
+}
+
+static int
+stack_size(struct sym_data *sym)
+{
+ int i;
+ int size;
+
+ size = 0;
+ for( i=1; i < sym->len; i++ ){
+ switch(sym->type[i]){
+ case 'C':
+ case 'H':
+ case 'I':
+ case 'L':
+ size += sizeof(long);
+ break;
+ case 'F':
+ size += sizeof(float);
+ break;
+ case 'D':
+ size += sizeof(double);
+ break;
+ case 'c':
+ case 'h':
+ case 'i':
+ case 'l':
+ case 'f':
+ case 'd':
+ case 'p':
+ case 'P':
+ case 's':
+ case 'S':
+ case 'a':
+ case 'A':
+ size += sizeof(void*);
+ break;
+ default:
+ return -(sym->type[i]);
+ }
+ }
+ return size;
+}
+
+static ID rb_dl_id_DLErrno;
+
+static VALUE
+rb_dl_get_last_error(VALUE self)
+{
+ return rb_thread_local_aref(rb_thread_current(), rb_dl_id_DLErrno);
+}
+
+static VALUE
+rb_dl_set_last_error(VALUE self, VALUE val)
+{
+ errno = NUM2INT(val);
+ rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLErrno, val);
+ return Qnil;
+}
+
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+static ID rb_dl_id_DLW32Error;
+
+static VALUE
+rb_dl_win32_get_last_error(VALUE self)
+{
+ return rb_thread_local_aref(rb_thread_current(), rb_dl_id_DLW32Error);
+}
+
+static VALUE
+rb_dl_win32_set_last_error(VALUE self, VALUE val)
+{
+ SetLastError(NUM2INT(val));
+ rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLW32Error, val);
+ return Qnil;
+}
+#endif
+
+#ifdef DLSTACK_GUARD
+# ifdef __MSVC_RUNTIME_CHECKS
+# pragma runtime_checks("s", off)
+# endif
+# if _MSC_VER >= 1300
+__declspec(noinline)
+# endif
+static int
+rb_dlsym_guardcall(char type, ANY_TYPE *ret, long *stack, void *func)
+{
+ char *volatile guard = ALLOCA_N(char, 1); /* guard stack pointer */
+ switch(type){
+ case '0':
+ {
+ void (*f)(DLSTACK_PROTO) = func;
+ f(DLSTACK_ARGS);
+ }
+ break;
+ case 'P':
+ case 'p':
+ {
+ void * (*f)(DLSTACK_PROTO) = func;
+ ret->p = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'C':
+ case 'c':
+ {
+ char (*f)(DLSTACK_PROTO) = func;
+ ret->c = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'H':
+ case 'h':
+ {
+ short (*f)(DLSTACK_PROTO) = func;
+ ret->h = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'I':
+ case 'i':
+ {
+ int (*f)(DLSTACK_PROTO) = func;
+ ret->i = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'L':
+ case 'l':
+ {
+ long (*f)(DLSTACK_PROTO) = func;
+ ret->l = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'F':
+ case 'f':
+ {
+ float (*f)(DLSTACK_PROTO) = func;
+ ret->f = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'D':
+ case 'd':
+ {
+ double (*f)(DLSTACK_PROTO) = func;
+ ret->d = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'S':
+ case 's':
+ {
+ char * (*f)(DLSTACK_PROTO) = func;
+ ret->s = f(DLSTACK_ARGS);
+ }
+ break;
+ default:
+ return 0;
+ }
+ return 1;
+}
+# ifdef __MSVC_RUNTIME_CHECKS
+# pragma runtime_checks("s", restore)
+# endif
+#endif /* defined(DLSTACK_GUARD) */
+
+VALUE
+rb_dlsym_call(int argc, VALUE argv[], VALUE self)
+{
+ struct sym_data *sym;
+ ANY_TYPE *args;
+ ANY_TYPE *dargs;
+ ANY_TYPE ret;
+ int *dtypes;
+ VALUE val;
+ VALUE dvals;
+ int i;
+ long ftype;
+ void *func;
+
+ rb_secure_update(self);
+ Data_Get_Struct(self, struct sym_data, sym);
+ DEBUG_CODE({
+ printf("rb_dlsym_call(): type = '%s', func = 0x%x\n", sym->type, sym->func);
+ });
+ if( (sym->len - 1) != argc ){
+ rb_raise(rb_eArgError, "%d arguments are needed", sym->len - 1);
+ }
+
+ ftype = 0;
+ dvals = Qnil;
+
+ args = ALLOC_N(ANY_TYPE, sym->len - 1);
+ dargs = ALLOC_N(ANY_TYPE, sym->len - 1);
+ dtypes = ALLOC_N(int, sym->len - 1);
+#define FREE_ARGS {xfree(args); xfree(dargs); xfree(dtypes);}
+
+ for( i = sym->len - 2; i >= 0; i-- ){
+ dtypes[i] = 0;
+
+ switch( sym->type[i+1] ){
+ case 'p':
+ dtypes[i] = 'p';
+ case 'P':
+ {
+ struct ptr_data *data;
+ VALUE pval;
+
+ if( argv[i] == Qnil ){
+ ANY2P(args[i]) = DLVOIDP(0);
+ }
+ else{
+ if( rb_obj_is_kind_of(argv[i], rb_cDLPtrData) ){
+ pval = argv[i];
+ }
+ else{
+ pval = rb_funcall(argv[i], rb_intern("to_ptr"), 0);
+ if( !rb_obj_is_kind_of(pval, rb_cDLPtrData) ){
+ 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);
+ }
+ }
+ PUSH_P(ftype);
+ break;
+ case 'a':
+ dtypes[i] = 'a';
+ case 'A':
+ if( argv[i] == Qnil ){
+ ANY2P(args[i]) = DLVOIDP(0);
+ }
+ else{
+ ANY2P(args[i]) = DLVOIDP(rb_ary2cary(0, argv[i], NULL));
+ }
+ PUSH_P(ftype);
+ break;
+ case 'C':
+ ANY2C(args[i]) = DLCHAR(NUM2CHR(argv[i]));
+ PUSH_C(ftype);
+ break;
+ case 'c':
+ ANY2C(dargs[i]) = DLCHAR(NUM2CHR(argv[i]));
+ ANY2P(args[i]) = DLVOIDP(&(ANY2C(dargs[i])));
+ dtypes[i] = 'c';
+ PUSH_P(ftype);
+ break;
+ case 'H':
+ ANY2H(args[i]) = DLSHORT(NUM2INT(argv[i]));
+ PUSH_C(ftype);
+ break;
+ case 'h':
+ ANY2H(dargs[i]) = DLSHORT(NUM2INT(argv[i]));
+ ANY2P(args[i]) = DLVOIDP(&(ANY2H(dargs[i])));
+ dtypes[i] = 'h';
+ PUSH_P(ftype);
+ break;
+ case 'I':
+ ANY2I(args[i]) = DLINT(NUM2INT(argv[i]));
+ PUSH_I(ftype);
+ break;
+ case 'i':
+ ANY2I(dargs[i]) = DLINT(NUM2INT(argv[i]));
+ ANY2P(args[i]) = DLVOIDP(&(ANY2I(dargs[i])));
+ dtypes[i] = 'i';
+ PUSH_P(ftype);
+ break;
+ case 'L':
+ ANY2L(args[i]) = DLNUM2LONG(argv[i]);
+ PUSH_L(ftype);
+ break;
+ case 'l':
+ ANY2L(dargs[i]) = DLNUM2LONG(argv[i]);
+ ANY2P(args[i]) = DLVOIDP(&(ANY2L(dargs[i])));
+ dtypes[i] = 'l';
+ PUSH_P(ftype);
+ break;
+ case 'F':
+ Check_Type(argv[i], T_FLOAT);
+ ANY2F(args[i]) = DLFLOAT(RFLOAT(argv[i])->value);
+ PUSH_F(ftype);
+ break;
+ case 'f':
+ Check_Type(argv[i], T_FLOAT);
+ ANY2F(dargs[i]) = DLFLOAT(RFLOAT(argv[i])->value);
+ ANY2P(args[i]) = DLVOIDP(&(ANY2F(dargs[i])));
+ dtypes[i] = 'f';
+ PUSH_P(ftype);
+ break;
+ case 'D':
+ Check_Type(argv[i], T_FLOAT);
+ ANY2D(args[i]) = RFLOAT(argv[i])->value;
+ PUSH_D(ftype);
+ break;
+ case 'd':
+ Check_Type(argv[i], T_FLOAT);
+ ANY2D(dargs[i]) = RFLOAT(argv[i])->value;
+ ANY2P(args[i]) = DLVOIDP(&(ANY2D(dargs[i])));
+ dtypes[i] = 'd';
+ PUSH_P(ftype);
+ break;
+ case 'S':
+ if( argv[i] == Qnil ){
+ ANY2S(args[i]) = DLSTR(0);
+ }
+ else{
+ VALUE str = argv[i];
+ SafeStringValue(str);
+ ANY2S(args[i]) = DLSTR(RSTRING(str)->ptr);
+ }
+ PUSH_P(ftype);
+ break;
+ case 's':
+ {
+ VALUE str = argv[i];
+ SafeStringValue(str);
+ ANY2S(args[i]) = DLSTR(dlmalloc(RSTRING(str)->len + 1));
+ memcpy((char*)(ANY2S(args[i])), RSTRING(str)->ptr, RSTRING(str)->len + 1);
+ dtypes[i] = 's';
+ }
+ PUSH_P(ftype);
+ break;
+ default:
+ FREE_ARGS;
+ rb_raise(rb_eDLTypeError,
+ "unknown type '%c' of the return value.",
+ sym->type[i+1]);
+ }
+ }
+
+ switch( sym->type[0] ){
+ case '0':
+ PUSH_0(ftype);
+ break;
+ case 'P':
+ case 'p':
+ case 'S':
+ case 's':
+ case 'A':
+ case 'a':
+ PUSH_P(ftype);
+ break;
+ case 'C':
+ case 'c':
+ PUSH_C(ftype);
+ break;
+ case 'H':
+ case 'h':
+ PUSH_H(ftype);
+ break;
+ case 'I':
+ case 'i':
+ PUSH_I(ftype);
+ break;
+ case 'L':
+ case 'l':
+ PUSH_L(ftype);
+ break;
+ case 'F':
+ case 'f':
+ PUSH_F(ftype);
+ break;
+ case 'D':
+ case 'd':
+ PUSH_D(ftype);
+ break;
+ default:
+ FREE_ARGS;
+ rb_raise(rb_eDLTypeError,
+ "unknown type `%c' of the return value.",
+ sym->type[0]);
+ }
+
+ func = sym->func;
+
+#if defined(DLSTACK)
+ {
+#if defined(DLSTACK_SIZE)
+ int stk_size;
+ long stack[DLSTACK_SIZE];
+ long *sp;
+
+ sp = stack;
+ stk_size = stack_size(sym);
+ if( stk_size < 0 ){
+ FREE_ARGS;
+ rb_raise(rb_eDLTypeError, "unknown type '%c'.", -stk_size);
+ }
+ else if( stk_size > (int)(DLSTACK_SIZE) ){
+ FREE_ARGS;
+ rb_raise(rb_eArgError, "too many arguments.");
+ }
+#endif
+
+ DLSTACK_START(sym);
+
+#if defined(DLSTACK_REVERSE)
+ for( i = sym->len - 2; i >= 0; i-- )
+#else
+ for( i = 0; i <= sym->len -2; i++ )
+#endif
+ {
+ switch( sym->type[i+1] ){
+ case 'p':
+ case 'P':
+ DLSTACK_PUSH_P(ANY2P(args[i]));
+ break;
+ case 'a':
+ case 'A':
+ DLSTACK_PUSH_P(ANY2P(args[i]));
+ break;
+ case 'C':
+ DLSTACK_PUSH_C(ANY2C(args[i]));
+ break;
+ case 'c':
+ DLSTACK_PUSH_P(ANY2P(args[i]));
+ break;
+ case 'H':
+ DLSTACK_PUSH_H(ANY2H(args[i]));
+ break;
+ case 'h':
+ DLSTACK_PUSH_P(ANY2P(args[i]));
+ break;
+ case 'I':
+ DLSTACK_PUSH_I(ANY2I(args[i]));
+ break;
+ case 'i':
+ DLSTACK_PUSH_P(ANY2P(args[i]));
+ break;
+ case 'L':
+ DLSTACK_PUSH_L(ANY2L(args[i]));
+ break;
+ case 'l':
+ DLSTACK_PUSH_P(ANY2P(args[i]));
+ break;
+ case 'F':
+ DLSTACK_PUSH_F(ANY2F(args[i]));
+ break;
+ case 'f':
+ DLSTACK_PUSH_P(ANY2P(args[i]));
+ break;
+ case 'D':
+ DLSTACK_PUSH_D(ANY2D(args[i]));
+ break;
+ case 'd':
+ DLSTACK_PUSH_P(ANY2P(args[i]));
+ break;
+ case 'S':
+ case 's':
+ DLSTACK_PUSH_P(ANY2S(args[i]));
+ break;
+ }
+ }
+ DLSTACK_END(sym->type);
+
+#ifdef DLSTACK_GUARD
+ if(!rb_dlsym_guardcall(sym->type[0], &ret, stack, func)) {
+ FREE_ARGS;
+ rb_raise(rb_eDLTypeError, "unknown type `%c'", sym->type[0]);
+ }
+#else /* defined(DLSTACK_GUARD) */
+ {
+ switch( sym->type[0] ){
+ case '0':
+ {
+ void (*f)(DLSTACK_PROTO) = func;
+ f(DLSTACK_ARGS);
+ }
+ break;
+ case 'P':
+ case 'p':
+ {
+ void * (*f)(DLSTACK_PROTO) = func;
+ ret.p = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'C':
+ case 'c':
+ {
+ char (*f)(DLSTACK_PROTO) = func;
+ ret.c = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'H':
+ case 'h':
+ {
+ short (*f)(DLSTACK_PROTO) = func;
+ ret.h = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'I':
+ case 'i':
+ {
+ int (*f)(DLSTACK_PROTO) = func;
+ ret.i = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'L':
+ case 'l':
+ {
+ long (*f)(DLSTACK_PROTO) = func;
+ ret.l = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'F':
+ case 'f':
+ {
+ float (*f)(DLSTACK_PROTO) = func;
+ ret.f = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'D':
+ case 'd':
+ {
+ double (*f)(DLSTACK_PROTO) = func;
+ ret.d = f(DLSTACK_ARGS);
+ }
+ break;
+ case 'S':
+ case 's':
+ {
+ char * (*f)(DLSTACK_PROTO) = func;
+ ret.s = f(DLSTACK_ARGS);
+ }
+ break;
+ default:
+ FREE_ARGS;
+ rb_raise(rb_eDLTypeError, "unknown type `%c'", sym->type[0]);
+ }
+ }
+#endif /* defubed(DLSTACK_GUARD) */
+
+ {
+ /*
+ * We should get the value of errno/GetLastError() before calling another functions.
+ */
+ int last_errno = errno;
+#ifdef _WIN32
+ DWORD win32_last_err = GetLastError();
+#endif
+
+ rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLErrno, INT2NUM(last_errno));
+#ifdef _WIN32
+ rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLW32Error, INT2NUM(win32_last_err));
+#endif
+ }
+
+ }
+#else /* defined(DLSTACK) */
+ switch(ftype){
+#include "call.func"
+ default:
+ FREE_ARGS;
+ rb_raise(rb_eDLTypeError, "unsupported function type `%s'", sym->type);
+ }
+#endif /* defined(DLSTACK) */
+
+ switch( sym->type[0] ){
+ case '0':
+ val = Qnil;
+ break;
+ case 'P':
+ val = rb_dlptr_new((void*)(ANY2P(ret)), 0, 0);
+ break;
+ case 'p':
+ val = rb_dlptr_new((void*)(ANY2P(ret)), 0, dlfree);
+ break;
+ case 'C':
+ case 'c':
+ val = CHR2FIX((char)(ANY2C(ret)));
+ break;
+ case 'H':
+ case 'h':
+ val = INT2NUM((short)(ANY2H(ret)));
+ break;
+ case 'I':
+ case 'i':
+ val = INT2NUM((int)(ANY2I(ret)));
+ break;
+ case 'L':
+ case 'l':
+ val = DLLONG2NUM((long)(ANY2L(ret)));
+ break;
+ case 'F':
+ case 'f':
+ val = rb_float_new((double)(ANY2F(ret)));
+ break;
+ case 'D':
+ case 'd':
+ val = rb_float_new((double)(ANY2D(ret)));
+ break;
+ case 'S':
+ if( ANY2S(ret) ){
+ val = rb_tainted_str_new2((char*)(ANY2S(ret)));
+ }
+ else{
+ val = Qnil;
+ }
+ break;
+ case 's':
+ if( ANY2S(ret) ){
+ val = rb_tainted_str_new2((char*)(ANY2S(ret)));
+ DEBUG_CODE({
+ printf("dlfree(%s)\n",(char*)(ANY2S(ret)));
+ });
+ dlfree((void*)(ANY2S(ret)));
+ }
+ else{
+ val = Qnil;
+ }
+ break;
+ default:
+ FREE_ARGS;
+ rb_raise(rb_eDLTypeError, "unknown type `%c'", sym->type[0]);
+ }
+
+ dvals = rb_ary_new();
+ for( i = 0; i <= sym->len - 2; i++ ){
+ if( dtypes[i] ){
+ switch( dtypes[i] ){
+ case 'c':
+ rb_ary_push(dvals, CHR2FIX(*((char*)(ANY2P(args[i])))));
+ break;
+ case 'h':
+ rb_ary_push(dvals, INT2NUM(*((short*)(ANY2P(args[i])))));
+ break;
+ case 'i':
+ rb_ary_push(dvals, INT2NUM(*((int*)(ANY2P(args[i])))));
+ break;
+ case 'l':
+ rb_ary_push(dvals, DLLONG2NUM(*((long*)(ANY2P(args[i])))));
+ break;
+ case 'f':
+ rb_ary_push(dvals, rb_float_new(*((float*)(ANY2P(args[i])))));
+ break;
+ case 'd':
+ rb_ary_push(dvals, rb_float_new(*((double*)(ANY2P(args[i])))));
+ break;
+ case 'p':
+ rb_ary_push(dvals, rb_dlptr_new((void*)(ANY2P(args[i])), 0, 0));
+ break;
+ case 'a':
+ rb_ary_push(dvals, rb_dlptr_new((void*)ANY2P(args[i]), 0, 0));
+ break;
+ case 's':
+ rb_ary_push(dvals, rb_tainted_str_new2((char*)ANY2S(args[i])));
+ DEBUG_CODE({
+ printf("dlfree(%s)\n",(char*)ANY2S(args[i]));
+ });
+ dlfree((void*)ANY2S(args[i]));
+ break;
+ default:
+ {
+ char c = dtypes[i];
+ FREE_ARGS;
+ rb_raise(rb_eRuntimeError, "unknown argument type '%c'", i, c);
+ }
+ }
+ }
+ else{
+ switch( sym->type[i+1] ){
+ case 'A':
+ dlfree((void*)ANY2P(args[i]));
+ break;
+ }
+ rb_ary_push(dvals, argv[i]);
+ }
+ }
+
+ FREE_ARGS;
+#undef FREE_ARGS
+ return rb_assoc_new(val,dvals);
+}
+
+VALUE
+rb_dlsym_to_i(VALUE self)
+{
+ struct sym_data *sym;
+
+ Data_Get_Struct(self, struct sym_data, sym);
+ return DLLONG2NUM(sym);
+}
+
+VALUE
+rb_dlsym_to_ptr(VALUE self)
+{
+ struct sym_data *sym;
+
+ Data_Get_Struct(self, struct sym_data, sym);
+ return rb_dlptr_new(sym->func, sizeof(freefunc_t), 0);
+}
+
+void
+Init_dlsym()
+{
+ rb_cDLSymbol = rb_define_class_under(rb_mDL, "Symbol", rb_cObject);
+ rb_define_alloc_func(rb_cDLSymbol, rb_dlsym_s_allocate);
+ rb_define_singleton_method(rb_cDLSymbol, "char2type", rb_s_dlsym_char2type, 1);
+ rb_define_method(rb_cDLSymbol, "initialize", rb_dlsym_initialize, -1);
+ rb_define_method(rb_cDLSymbol, "call", rb_dlsym_call, -1);
+ rb_define_method(rb_cDLSymbol, "[]", rb_dlsym_call, -1);
+ rb_define_method(rb_cDLSymbol, "name", rb_dlsym_name, 0);
+ rb_define_method(rb_cDLSymbol, "proto", rb_dlsym_proto, 0);
+ rb_define_method(rb_cDLSymbol, "cproto", rb_dlsym_cproto, 0);
+ rb_define_method(rb_cDLSymbol, "inspect", rb_dlsym_inspect, 0);
+ rb_define_method(rb_cDLSymbol, "to_s", rb_dlsym_cproto, 0);
+ rb_define_method(rb_cDLSymbol, "to_ptr", rb_dlsym_to_ptr, 0);
+ rb_define_method(rb_cDLSymbol, "to_i", rb_dlsym_to_i, 0);
+
+ rb_dl_id_DLErrno = rb_intern("DLErrno");
+ rb_define_singleton_method(rb_mDL, "last_error", rb_dl_get_last_error, 0);
+ rb_define_singleton_method(rb_mDL, "last_error=", rb_dl_set_last_error, 1);
+#ifdef _WIN32
+ rb_dl_id_DLW32Error = rb_intern("DLW32Error");
+ rb_define_singleton_method(rb_mDL, "win32_last_error", rb_dl_win32_get_last_error, 0);
+ rb_define_singleton_method(rb_mDL, "win32_last_error=", rb_dl_win32_set_last_error, 1);
+#endif
+}
diff --git a/ext/dl/test/libtest.def b/ext/dl/test/libtest.def
new file mode 100644
index 0000000000..8ecefc917b
--- /dev/null
+++ b/ext/dl/test/libtest.def
@@ -0,0 +1,28 @@
+EXPORTS
+test_alloc_test_struct
+test_append
+test_arylen
+test_c2i
+test_call_func1
+test_callback1
+test_close
+test_d2f
+test_f2d
+test_fill_test_struct
+test_fill_test_union
+test_gets
+test_i2c
+test_init
+test_isucc
+test_lcc
+test_lsucc
+test_open
+test_strcat
+test_strlen
+test_succ
+test_data_init
+test_data_add
+test_data_aref
+test_set_long_value
+test_get_long_value
+internal_long_value
diff --git a/ext/dl/test/test.c b/ext/dl/test/test.c
new file mode 100644
index 0000000000..7321379390
--- /dev/null
+++ b/ext/dl/test/test.c
@@ -0,0 +1,247 @@
+#include <stdio.h>
+#include <string.h>
+
+static char internal_string[] = "internal_string";
+long internal_long_value = 100;
+
+struct test_struct {
+ char c;
+ long l;
+};
+
+union test_union {
+ char c;
+ int i;
+ long l;
+ void *p;
+};
+
+struct test_data {
+ char name[1024];
+ struct test_data *next;
+};
+
+long
+test_get_long_value()
+{
+ return internal_long_value;
+};
+
+void
+test_set_long_value(long l)
+{
+ internal_long_value = l;
+};
+
+void
+test_fill_test_struct(struct test_struct *ptr, char c, long l)
+{
+ ptr->c = c;
+ ptr->l = l;
+};
+
+void
+test_fill_test_union(union test_union *ptr, long l)
+{
+ ptr->l = l;
+};
+
+struct test_struct *
+test_alloc_test_struct(char c, long l)
+{
+ struct test_struct *data;
+
+ data = (struct test_struct *)malloc(sizeof(struct test_struct));
+ data->c = c;
+ data->l = l;
+
+ return data;
+};
+
+int
+test_c2i(char c)
+{
+ return (int)c;
+};
+
+char
+test_i2c(int i)
+{
+ return (char)i;
+};
+
+long
+test_lcc(char c1, char c2)
+{
+ return (long)(c1 + c2);
+};
+
+double
+test_f2d(float f)
+{
+ double d;
+ d = f;
+ return d;
+};
+
+float
+test_d2f(double d)
+{
+ float f;
+ f = d;
+ return f;
+};
+
+int
+test_strlen(const char *str)
+{
+ return strlen(str);
+};
+
+int
+test_isucc(int i)
+{
+ return (i+1);
+};
+
+long
+test_lsucc(long l)
+{
+ return (l+1);
+};
+
+void
+test_succ(long *l)
+{
+ (*l)++;
+};
+
+char *
+test_strcat(char *str1, const char *str2)
+{
+ return strcat(str1, str2);
+};
+
+int
+test_arylen(char *ary[])
+{
+ int i;
+ for( i=0; ary[i]; i++ ){};
+ return i;
+};
+
+void
+test_append(char *ary[], int len, char *astr)
+{
+ int i;
+ int size1,size2;
+ char *str;
+
+ size2 = strlen(astr);
+
+ for( i=0; i <= len - 1; i++ ){
+ size1 = strlen(ary[i]);
+ str = (char*)malloc(size1 + size2 + 1);
+ strcpy(str, ary[i]);
+ strcat(str, astr);
+ ary[i] = str;
+ };
+};
+
+int
+test_init(int *argc, char **argv[])
+{
+ int i;
+ char s[256];
+
+ for( i=0; i < (*argc); i++ ){
+ sprintf(s, "arg%d", i);
+ if( strcmp((*argv)[i], s) != 0 ){
+ return 1;
+ }
+ }
+ return 0;
+}
+
+FILE *
+test_open(const char *filename, const char *mode)
+{
+ FILE *file;
+ file = fopen(filename,mode);
+ return file;
+};
+
+void
+test_close(FILE *file)
+{
+ fclose(file);
+};
+
+char *
+test_gets(char *s, int size, FILE *f)
+{
+ return fgets(s,size,f);
+};
+
+typedef int callback1_t(int, char *);
+#define CALLBACK_MSG "callback message"
+
+int
+test_callback1(int err, const char *msg)
+{
+ if( strcmp(msg, CALLBACK_MSG) == 0 ){
+ return 1;
+ }
+ else{
+ return 0;
+ }
+}
+
+int
+test_call_func1(callback1_t *func)
+{
+ if( func ){
+ return (*func)(0, CALLBACK_MSG);
+ }
+ else{
+ return 0;
+ }
+}
+
+struct test_data *
+test_data_init()
+{
+ struct test_data *data;
+
+ data = (struct test_data *)malloc(sizeof(struct test_data));
+ data->next = NULL;
+ memset(data->name, 0, 1024);
+
+ return data;
+};
+
+void
+test_data_add(struct test_data *list, const char *name)
+{
+ struct test_data *data;
+
+ data = (struct test_data *)malloc(sizeof(struct test_data));
+ memset(data->name, 0, 1024);
+ strncpy(data->name, name, 1024);
+ data->next = list->next;
+ list->next = data;
+};
+
+struct test_data *
+test_data_aref(struct test_data *list, int i)
+{
+ struct test_data *data;
+ int j;
+
+ for( data = list->next, j=0; data; data = data->next, j++ ){
+ if( i == j ){
+ return data;
+ };
+ };
+ return NULL;
+};
diff --git a/ext/dl/test/test.rb b/ext/dl/test/test.rb
new file mode 100644
index 0000000000..bf8dfc18e3
--- /dev/null
+++ b/ext/dl/test/test.rb
@@ -0,0 +1,306 @@
+# -*- ruby -*-
+
+require 'dl'
+require 'dl/import'
+
+$FAIL = 0
+$TOTAL = 0
+
+def assert(label, ty, *conds)
+ $TOTAL += 1
+ cond = !conds.include?(false)
+ if( cond )
+ printf("succeed in `#{label}'\n")
+ else
+ $FAIL += 1
+ case ty
+ when :may
+ printf("fail in `#{label}' ... expected\n")
+ when :must
+ printf("fail in `#{label}' ... unexpected\n")
+ when :raise
+ raise(RuntimeError, "fail in `#{label}'")
+ end
+ end
+end
+
+def debug(*xs)
+ if( $DEBUG )
+ xs.each{|x|
+ p x
+ }
+ end
+end
+
+print("DLSTACK = #{DL::DLSTACK}\n")
+print("MAX_ARG = #{DL::MAX_ARG}\n")
+print("\n")
+print("DL::FREE = #{DL::FREE.inspect}\n")
+print("\n")
+
+$LIB = nil
+if( !$LIB && File.exist?("libtest.so") )
+ $LIB = "./libtest.so"
+end
+if( !$LIB && File.exist?("test/libtest.so") )
+ $LIB = "./test/libtest.so"
+end
+
+module LIBTest
+ extend DL::Importable
+
+ dlload($LIB)
+ extern "int test_c2i(char)"
+ extern "char test_i2c(int)"
+ extern "long test_lcc(char, char)"
+ extern "double test_f2d(float)"
+ extern "float test_d2f(double)"
+ extern "int test_strlen(char*)"
+ extern "int test_isucc(int)"
+ extern "long test_lsucc(long)"
+ extern "void test_succ(long *)"
+ extern "int test_arylen(int [])"
+ extern "void test_append(char*[], int, char *)"
+end
+
+DL.dlopen($LIB){|h|
+ c2i = h["test_c2i","IC"]
+ debug c2i
+ r,rs = c2i[?a]
+ debug r,rs
+ assert("c2i", :may, r == ?a)
+ assert("extern c2i", :must, r == LIBTest.test_c2i(?a))
+
+ i2c = h["test_i2c","CI"]
+ debug i2c
+ r,rs = i2c[?a]
+ debug r,rs
+ assert("i2c", :may, r == ?a)
+ assert("exern i2c", :must, r == LIBTest.test_i2c(?a))
+
+ lcc = h["test_lcc","LCC"]
+ debug lcc
+ r,rs = lcc[1,2]
+ assert("lcc", :may, r == 3)
+ assert("extern lcc", :must, r == LIBTest.test_lcc(1,2))
+
+ f2d = h["test_f2d","DF"]
+ debug f2d
+ r,rs = f2d[20.001]
+ debug r,rs
+ assert("f2d", :may, r.to_i == 20)
+ assert("extern f2d", :must, r = LIBTest.test_f2d(20.001))
+
+ d2f = h["test_d2f","FD"]
+ debug d2f
+ r,rs = d2f[20.001]
+ debug r,rs
+ assert("d2f", :may, r.to_i == 20)
+ assert("extern d2f", :must, r == LIBTest.test_d2f(20.001))
+
+ strlen = h["test_strlen","IS"]
+ debug strlen
+ r,rs = strlen["0123456789"]
+ debug r,rs
+ assert("strlen", :must, r == 10)
+ assert("extern strlen", :must, r == LIBTest.test_strlen("0123456789"))
+
+ isucc = h["test_isucc","II"]
+ debug isucc
+ r,rs = isucc[2]
+ debug r,rs
+ assert("isucc", :must, r == 3)
+ assert("extern isucc", :must, r == LIBTest.test_isucc(2))
+
+ lsucc = h["test_lsucc","LL"]
+ debug lsucc
+ r,rs = lsucc[10000000]
+ debug r,rs
+ assert("lsucc", :must, r == 10000001)
+ assert("extern lsucc", :must, r == LIBTest.test_lsucc(10000000))
+
+ succ = h["test_succ","0l"]
+ debug succ
+ r,rs = succ[0]
+ debug r,rs
+ assert("succ", :must, rs[0] == 1)
+ l = DL.malloc(DL.sizeof("L"))
+ l.struct!("L",:lval)
+ LIBTest.test_succ(l)
+ assert("extern succ", :must, rs[0] == l[:lval])
+
+ arylen = h["test_arylen","IA"]
+ debug arylen
+ r,rs = arylen[["a","b","c","d",nil]]
+ debug r,rs
+ assert("arylen", :must, r == 4)
+
+ arylen = h["test_arylen","IP"]
+ debug arylen
+ r,rs = arylen[["a","b","c","d",nil]]
+ debug r,rs
+ assert("arylen", :must, r == 4)
+ assert("extern arylen", :must, r == LIBTest.test_arylen(["a","b","c","d",nil]))
+
+ append = h["test_append","0aIS"]
+ debug append
+ r,rs = append[["a","b","c"],3,"x"]
+ debug r,rs
+ assert("append", :must, rs[0].to_a('S',3) == ["ax","bx","cx"])
+
+ LIBTest.test_append(["a","b","c"],3,"x")
+ assert("extern append", :must, rs[0].to_a('S',3) == LIBTest._args_[0].to_a('S',3))
+
+ strcat = h["test_strcat","SsS"]
+ debug strcat
+ r,rs = strcat["abc\0","x"]
+ debug r,rs
+ assert("strcat", :must, rs[0].to_s == "abcx")
+
+ init = h["test_init","IiP"]
+ debug init
+ argc = 3
+ argv = ["arg0","arg1","arg2"].to_ptr
+ r,rs = init[argc, argv.ref]
+ assert("init", :must, r == 0)
+}
+
+
+h = DL.dlopen($LIB)
+
+sym_open = h["test_open", "PSS"]
+sym_gets = h["test_gets", "SsIP"]
+sym_close = h["test_close", "0P"]
+debug sym_open,sym_gets,sym_close
+
+line = "Hello world!\n"
+File.open("tmp.txt", "w"){|f|
+ f.print(line)
+}
+
+fp,rs = sym_open["tmp.txt", "r"]
+if( fp )
+ fp.free = sym_close
+ r,rs = sym_gets[" " * 256, 256, fp]
+ debug r,rs
+ assert("open,gets", :must, rs[0] == line)
+ ObjectSpace.define_finalizer(fp) {File.unlink("tmp.txt")}
+ fp = nil
+else
+ assert("open,gets", :must, line == nil)
+ File.unlink("tmp.txt")
+end
+
+
+callback1 = h["test_callback1"]
+debug callback1
+r,rs = h["test_call_func1", "IP"][callback1]
+debug r,rs
+assert("callback1", :must, r == 1)
+
+
+callback2 = DL.callback("LLP"){|num,ptr|
+ msg = ptr.to_s
+ if( msg == "callback message" )
+ 2
+ else
+ 0
+ end
+}
+debug callback2
+r,rs = h["test_call_func1", "IP"][callback2]
+debug r,rs
+assert("callback2", :must, r == 2)
+DL.remove_callback(callback2)
+
+ptr = DL.malloc(DL.sizeof('CL'))
+ptr.struct!("CL", :c, :l)
+ptr["c"] = 0
+ptr["l"] = 0
+r,rs = h["test_fill_test_struct","0PIL"][ptr,100,1000]
+debug r,rs
+assert("fill_test_struct", :must, ptr["c"] == 100, ptr["l"] == 1000)
+assert("fill_test_struct", :must, ptr[:c] == 100, ptr[:l] == 1000) unless (Fixnum === :-)
+
+
+r,rs = h["test_alloc_test_struct", "PIL"][100,200]
+r.free = DL::FREE
+r.struct!("CL", :c, :l)
+assert("alloc_test_struct", :must, r["c"] == 100, r["l"] == 200)
+assert("alloc_test_struct", :must, r[:c] == 100, r[:l] == 200) unless (Fixnum === :-)
+
+ptr = h["test_strlen"]
+sym1 = DL::Symbol.new(ptr,"foo","0")
+sym2 = h["test_strlen","LS"]
+assert("Symbol.new", :must, ptr == sym1.to_ptr, sym1.to_ptr == sym2.to_ptr)
+
+set_val = h["test_set_long_value","0"]
+get_val = h["test_get_long_value","L"]
+lval = get_val[][0]
+ptr = h["internal_long_value"]
+ptr.struct!("L", :l)
+assert("get value", :must, ptr["l"] == lval)
+assert("get value", :must, ptr[:l] == lval) unless (Fixnum === :-)
+ptr["l"] = 200
+lval = get_val[][0]
+assert("set value", :must, ptr["l"] == lval)
+assert("set value", :must, ptr[:l] == lval) unless (Fixnum === :-)
+
+
+data_init = h["test_data_init", "P"]
+data_add = h["test_data_add", "0PS"]
+data_aref = h["test_data_aref", "PPI"]
+r,rs = data_init[]
+ptr = r
+data_add[ptr, "name1"]
+data_add[ptr, "name2"]
+data_add[ptr, "name3"]
+
+r,rs = data_aref[ptr, 1]
+ptr = r
+ptr.struct!("C1024P", :name, :next)
+assert("data_aref", :must,
+ ptr["name"].collect{|c| c.chr}.join.split("\0")[0] == "name2")
+assert("data_aref", :must,
+ ptr["name"].collect{|c| c.chr}.join.split("\0")[0] == "name2") unless (Fixnum === :-)
+
+ptr = ptr["next"]
+ptr.struct!("C1024P", :name, :next)
+assert("data_aref", :must,
+ ptr["name"].collect{|c| c.chr}.join.split("\0")[0] == "name1")
+assert("data_aref", :must,
+ ptr["name"].collect{|c| c.chr}.join.split("\0")[0] == "name1") unless (Fixnum === :-)
+
+GC.start
+
+ptr = DL::malloc(32)
+ptr.struct!("CHIL", "c", "h", "i", "l")
+ptr["c"] = 1
+ptr["h"] = 2
+ptr["i"] = 3
+ptr["l"] = 4
+assert("struct!", :must,
+ ptr["c"] == 1 &&
+ ptr["h"] == 2 &&
+ ptr["i"] == 3 &&
+ ptr["l"] == 4)
+
+ptr = DL::malloc(DL::sizeof("IP"))
+ptr.struct!("IP", "n", "ptr")
+ptr["n"] = 10
+ptr["ptr"] = nil
+assert("struct!", :must, ptr["n"] == 10 && ptr["ptr"] == nil)
+
+ptr = DL::malloc(16)
+ptr.struct!("CICI", "c1", "i1", "c2", "i2")
+ptr["c1"] = 0xf1
+ptr["c2"] = 0xf2
+c1 = [ptr["c1"]].pack("c").unpack("C")[0]
+c2 = [ptr["c2"]].pack("c").unpack("C")[0]
+assert("struct!", :must,
+ c1 == 0xf1 &&
+ c2 == 0xf2)
+
+
+GC.start
+printf("fail/total = #{$FAIL}/#{$TOTAL}\n")
diff --git a/ext/dl/test/test_all.rb b/ext/dl/test/test_all.rb
deleted file mode 100644
index fb1f4939f9..0000000000
--- a/ext/dl/test/test_all.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require 'test_base'
-require 'dl/import'
-
-require 'test_dl2'
-require 'test_func'
-require 'test_import'
-
-case RUBY_PLATFORM
-when /cygwin/, /mingw32/, /mswin32/, /bccwin32/
- require 'test_win32'
-end
diff --git a/ext/dl/test/test_base.rb b/ext/dl/test/test_base.rb
deleted file mode 100644
index fc72db4e5e..0000000000
--- a/ext/dl/test/test_base.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-require 'test/unit'
-require 'dl'
-
-case RUBY_PLATFORM
-when /cygwin/
- LIBC_SO = "cygwin1.dll"
- LIBM_SO = "cygwin1.dll"
-when /linux/
- LIBC_SO = "/lib/libc.so.6"
- LIBM_SO = "/lib/libm.so.6"
-when /mingw/, /mswin32/
- LIBC_SO = "msvcrt.dll"
- LIBM_SO = "msvcrt.dll"
-else
- LIBC_SO = ARGV[0]
- LIBM_SO = ARGV[1]
- if( !(LIBC_SO && LIBM_SO) )
- $stderr.puts("#{$0} <libc> <libm>")
- exit
- end
-end
-
-module DL
- class TestBase < Test::Unit::TestCase
- include Math
- include DL
-
- def setup
- @libc = dlopen(LIBC_SO)
- @libm = dlopen(LIBM_SO)
- end
-
- def assert_match(expected, actual, message="")
- assert(expected === actual, message)
- end
-
- def assert_positive(actual)
- assert(actual > 0)
- end
-
- def assert_zero(actual)
- assert(actual == 0)
- end
-
- def assert_negative(actual)
- assert(actual < 0)
- end
-
- def test_empty()
- end
- end
-end
diff --git a/ext/dl/test/test_dl2.rb b/ext/dl/test/test_dl2.rb
deleted file mode 100644
index 8c1f3e71b4..0000000000
--- a/ext/dl/test/test_dl2.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-require 'test_base.rb'
-require 'dl/callback'
-
-module DL
-class TestDL < TestBase
- def test_call_int()
- cfunc = CFunc.new(@libc['atoi'], TYPE_INT, 'atoi')
- x = cfunc.call(["100"].pack("p").unpack("l!*"))
- assert_equal(100, x)
-
- cfunc = CFunc.new(@libc['atoi'], TYPE_INT, 'atoi')
- x = cfunc.call(["-100"].pack("p").unpack("l!*"))
- assert_equal(-100, x)
- end
-
- def test_call_long()
- cfunc = CFunc.new(@libc['atol'], TYPE_LONG, 'atol')
- x = cfunc.call(["100"].pack("p").unpack("l!*"))
- assert_equal(100, x)
- cfunc = CFunc.new(@libc['atol'], TYPE_LONG, 'atol')
- x = cfunc.call(["-100"].pack("p").unpack("l!*"))
- assert_equal(-100, x)
- end
-
- def test_call_double()
- cfunc = CFunc.new(@libc['atof'], TYPE_DOUBLE, 'atof')
- x = cfunc.call(["0.1"].pack("p").unpack("l!*"))
- assert_match(0.09..0.11, x)
-
- cfunc = CFunc.new(@libc['atof'], TYPE_DOUBLE, 'atof')
- x = cfunc.call(["-0.1"].pack("p").unpack("l!*"))
- assert_match(-0.11 .. -0.09, x)
- end
-
- def test_sin()
- cfunc = CFunc.new(@libm['sin'], TYPE_DOUBLE, 'sin')
- x = cfunc.call([3.14/2].pack("d").unpack("l!*"))
- assert_equal(x, Math.sin(3.14/2))
-
- cfunc = CFunc.new(@libm['sin'], TYPE_DOUBLE, 'sin')
- x = cfunc.call([-3.14/2].pack("d").unpack("l!*"))
- assert_equal(Math.sin(-3.14/2), x)
- end
-
- def test_strlen()
- cfunc = CFunc.new(@libc['strlen'], TYPE_INT, 'strlen')
- x = cfunc.call(["abc"].pack("p").unpack("l!*"))
- assert_equal("abc".size, x)
- end
-
- def test_strcpy()
- buff = "xxxx"
- str = "abc"
- cfunc = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy')
- x = cfunc.call([buff,str].pack("pp").unpack("l!*"))
- assert_equal("abc\0", buff)
- assert_equal("abc\0", CPtr.new(x).to_s(4))
-
- buff = "xxxx"
- str = "abc"
- cfunc = CFunc.new(@libc['strncpy'], TYPE_VOIDP, 'strncpy')
- x = cfunc.call([buff,str,3].pack("ppi").unpack("l!*"))
- assert_equal("abcx", buff)
- assert_equal("abcx", CPtr.new(x).to_s(4))
-
- ptr = CPtr.malloc(4)
- str = "abc"
- cfunc = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy')
- x = cfunc.call([ptr.to_i,str].pack("lp").unpack("l!*"))
- assert_equal("abc\0", ptr[0,4])
- assert_equal("abc\0", CPtr.new(x).to_s(4))
- end
-
- def test_callback()
- buff = "foobarbaz"
- cb = set_callback(TYPE_INT,2){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
- cfunc = CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort')
- cfunc.call([buff, buff.size, 1, cb].pack("pI!I!L!").unpack("l!*"))
- assert_equal('aabbfoorz', buff)
- end
-
- def test_dlwrap()
- ary = [0,1,2,4,5]
- addr = dlwrap(ary)
- ary2 = dlunwrap(addr)
- assert_equal(ary, ary2)
- end
-
- def test_cptr()
- check = Proc.new{|str,ptr|
- assert_equal(str.size(), ptr.size())
- assert_equal(str, ptr.to_s())
- assert_equal(str[0,2], ptr.to_s(2))
- assert_equal(str[0,2], ptr[0,2])
- assert_equal(str[1,2], ptr[1,2])
- assert_equal(str[1,0], ptr[1,0])
- assert_equal(str[0].ord, ptr[0])
- assert_equal(str[1].ord, ptr[1])
- }
- str = 'abc'
- ptr = CPtr[str]
- check.call(str, ptr)
- str[0] = "c"
- ptr[0] = "c".ord
- check.call(str, ptr)
- str[0,2] = "aa"
- ptr[0,2] = "aa"
- check.call(str, ptr)
- end
-end
-end # module DL
diff --git a/ext/dl/test/test_func.rb b/ext/dl/test/test_func.rb
deleted file mode 100644
index 64a32d9565..0000000000
--- a/ext/dl/test/test_func.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-require 'test_base'
-require 'dl/func'
-
-module DL
- class TestFunc < TestBase
- def test_strcpy()
- f = Function.new(CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy'),
- [TYPE_VOIDP, TYPE_VOIDP])
- buff = "000"
- str = f.call(buff, "123")
- assert_equal("123", buff)
- assert_equal("123", str.to_s)
- end
-
- def test_isdigit()
- f = Function.new(CFunc.new(@libc['isdigit'], TYPE_INT, 'isdigit'),
- [TYPE_INT])
- r1 = f.call(?1)
- r2 = f.call(?2)
- rr = f.call(?r)
- assert_positive(r1)
- assert_positive(r2)
- assert_zero(rr)
- end
-
- def test_atof()
- f = Function.new(CFunc.new(@libc['atof'], TYPE_FLOAT, 'atof'),
- [TYPE_VOIDP])
- r = f.call("12.34")
- assert_match(12.00..13.00, r)
- end
-
- def test_strtod()
- f = Function.new(CFunc.new(@libc['strtod'], TYPE_DOUBLE, 'strtod'),
- [TYPE_VOIDP, TYPE_VOIDP])
- buff1 = "12.34"
- buff2 = " "
- r = f.call(buff1, buff2)
- assert_match(12.00..13.00, r)
- end
-
- def test_qsort1()
- cb = Function.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
- [TYPE_VOIDP, TYPE_VOIDP]){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
- qsort = Function.new(CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort'),
- [TYPE_VOIDP, TYPE_INT, TYPE_INT, TYPE_VOIDP])
- buff = "9341"
- qsort.call(buff, buff.size, 1, cb)
- assert_equal("1349", buff)
- end
-
- def test_qsort2()
- cb = TempFunction.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
- [TYPE_VOIDP, TYPE_VOIDP])
- qsort = Function.new(CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort'),
- [TYPE_VOIDP, TYPE_INT, TYPE_INT, TYPE_VOIDP])
- buff = "9341"
- qsort.call(buff, buff.size, 1, cb){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
- assert_equal("1349", buff)
- end
- end
-end
diff --git a/ext/dl/test/test_import.rb b/ext/dl/test/test_import.rb
deleted file mode 100644
index f0694637eb..0000000000
--- a/ext/dl/test/test_import.rb
+++ /dev/null
@@ -1,154 +0,0 @@
-require 'test_base'
-require 'dl/import'
-
-module DL
- module LIBC
- extend Importer
- dlload LIBC_SO, LIBM_SO
-
- typealias 'string', 'char*'
- typealias 'FILE*', 'void*'
-
- extern "void *strcpy(char*, char*)"
- extern "int isdigit(int)"
- extern "float atof(string)"
- extern "unsigned long strtoul(char*, char **, int)"
- extern "int qsort(void*, int, int, void*)"
- extern "void fprintf(FILE*, char*)"
- extern "int gettimeofday(timeval*, timezone*)" rescue nil
-
- QsortCallback = bind("void *qsort_callback(void*, void*)", :temp)
- BoundQsortCallback = bind("void *qsort_callback(void*, void*)"){|ptr1,ptr2| ptr1[0] <=> ptr2[0]}
- Timeval = struct [
- "long tv_sec",
- "long tv_usec",
- ]
- Timezone = struct [
- "int tz_minuteswest",
- "int tz_dsttime",
- ]
- MyStruct = struct [
- "short num[5]",
- "char c",
- "unsigned char buff[7]",
- ]
-
- CallCallback = bind("void call_callback(void*, void*)"){|ptr1, ptr2|
- f = Function.new(CFunc.new(ptr1.to_i, DL::TYPE_VOID, "<anonymous>"), [TYPE_VOIDP])
- f.call(ptr2)
- }
- CarriedFunction = bind("void callback_function(void*)", :carried, 0)
- end
-
- class TestImport < TestBase
- def test_malloc()
- s1 = LIBC::Timeval.malloc()
- s2 = LIBC::Timeval.malloc()
- assert_not_equal(s1.to_ptr.to_i, s2.to_ptr.to_i)
- end
-
- def test_sizeof()
- assert_equal(DL::SIZEOF_VOIDP, LIBC.sizeof("FILE*"))
- assert_equal(LIBC::MyStruct.size(), LIBC.sizeof(LIBC::MyStruct))
- end
-
- def test_unsigned_result()
- d = (2 ** 31) + 1
-
- r = LIBC.strtoul(d.to_s, 0, 0)
- assert_equal(d, r)
- end
-
- def test_io()
- if( RUBY_PLATFORM != DL::BUILD_RUBY_PLATFORM )
- return
- end
- io_in,io_out = IO.pipe()
- LIBC.fprintf(io_out, "hello")
- io_out.flush()
- io_out.close()
- str = io_in.read()
- io_in.close()
- assert_equal("hello", str)
- end
-
- def test_value()
- i = LIBC.value('int', 2)
- assert_equal(2, i.value)
-
- d = LIBC.value('double', 2.0)
- assert_equal(2.0, d.value)
-
- ary = LIBC.value('int[3]', [0,1,2])
- assert_equal([0,1,2], ary.value)
- end
-
- def test_carried_function()
- data1 = "data"
- data2 = nil
- LIBC.call_callback(LIBC::CarriedFunction, LIBC::CarriedFunction.create_carrier(data1)){|d|
- data2 = d
- }
- assert_equal(data1, data2)
- end
-
- def test_struct()
- s = LIBC::MyStruct.malloc()
- s.num = [0,1,2,3,4]
- s.c = ?a
- s.buff = "012345\377"
- assert_equal([0,1,2,3,4], s.num)
- assert_equal(?a, s.c)
- assert_equal([?0,?1,?2,?3,?4,?5,?\377], s.buff)
- end
-
- def test_gettimeofday()
- if( defined?(LIBC.gettimeofday) )
- timeval = LIBC::Timeval.malloc()
- timezone = LIBC::Timezone.malloc()
- LIBC.gettimeofday(timeval, timezone)
- cur = Time.now()
- assert(cur.to_i - 2 <= timeval.tv_sec && timeval.tv_sec <= cur.to_i)
- end
- end
-
- def test_strcpy()
- buff = "000"
- str = LIBC.strcpy(buff, "123")
- assert_equal("123", buff)
- assert_equal("123", str.to_s)
- end
-
- def test_isdigit()
- r1 = LIBC.isdigit(?1)
- r2 = LIBC.isdigit(?2)
- rr = LIBC.isdigit(?r)
- assert_positive(r1)
- assert_positive(r2)
- assert_zero(rr)
- end
-
- def test_atof()
- r = LIBC.atof("12.34")
- assert_match(12.00..13.00, r)
- end
-
- def test_strtod()
- f = Function.new(CFunc.new(@libc['strtod'], TYPE_DOUBLE, 'strtod'),
- [TYPE_VOIDP, TYPE_VOIDP])
- buff1 = "12.34"
- buff2 = " "
- r = f.call(buff1, buff2)
- assert_match(12.00..13.00, r)
- end
-
- def test_qsort()
- buff = "9341"
- LIBC.qsort(buff, buff.size, 1, LIBC::QsortCallback){|ptr1,ptr2| ptr1[0] <=> ptr2[0]}
- assert_equal("1349", buff)
- buff = "9341"
- LIBC.qsort(buff, buff.size, 1, LIBC::BoundQsortCallback)
- assert_equal("1349", buff)
- end
- end
-end
diff --git a/ext/dl/test/test_win32.rb b/ext/dl/test/test_win32.rb
deleted file mode 100644
index b2210287a1..0000000000
--- a/ext/dl/test/test_win32.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require 'test_base'
-require 'dl/import'
-require 'dl/types'
-
-module Win32API
- extend DL::Importer
-
- dlload "kernel32.dll"
-
- include DL::Win32Types
-
- OSVERSIONINFO = struct [
- "DWORD dwOSVersionInfoSize",
- "DWORD dwMajorVersion",
- "DWORD dwMinorVersion",
- "DWORD dwBuildNumber",
- "DWORD dwPlatformId",
- "UCHAR szCSDVersion[128]",
- ]
-
- typealias "POSVERSIONINFO", "OSVERSIONINFO*"
-
- extern "BOOL GetVersionEx(POSVERSIONINFO)", :stdcall
-
- def get_version_ex()
- ptr = OSVERSIONINFO.malloc()
- ptr.dwOSVersionInfoSize = OSVERSIONINFO.size
- ret = GetVersionEx(ptr)
- if( ret )
- ptr
- else
- nil
- end
- end
- module_function :get_version_ex
-end
-
-module DL
-class TestWin32 < TestBase
- def test_version()
- platform = Win32API.get_version_ex().dwPlatformId
- case ENV['OS']
- when 'Windows_NT'
- expect = 2
- when /Windows.+/
- expect = 1
- else
- expect = 0
- end
- assert_equal(expect, platform)
- end
-end
-end
diff --git a/ext/dl/type.rb b/ext/dl/type.rb
new file mode 100644
index 0000000000..804420c395
--- /dev/null
+++ b/ext/dl/type.rb
@@ -0,0 +1,115 @@
+# example:
+# DLTYPE[INT][:rb2c]["arg0"] => "NUM2INT(arg0)"
+# DLTYPE[DOUBLE][:c2rb]["r"] => "rb_float_new(r)"
+
+DLTYPE = {
+ VOID = 0x00 => {
+ :name => 'VOID',
+ :rb2c => nil,
+ :c2rb => nil,
+ :ctype => "void",
+ :stmem => "v",
+ :sym => true,
+ :cb => true,
+ },
+ CHAR = 0x01 => {
+ :name => 'CHAR',
+ :rb2c => proc{|x| "NUM2CHR(#{x})"},
+ :c2rb => proc{|x| "CHR2FIX(#{x})"},
+ :ctype => "char",
+ :stmem => "c",
+ :sym => false,
+ :cb => false,
+ },
+ SHORT = 0x02 => {
+ :name => 'SHORT',
+ :rb2c => proc{|x| "FIX2INT(#{x})"},
+ :c2rb => proc{|x| "INT2FIX(#{x})"},
+ :ctype => "short",
+ :stmem => "h",
+ :sym => false,
+ :cb => false,
+ },
+ INT = 0x03 => {
+ :name => 'INT',
+ :rb2c => proc{|x| "NUM2INT(#{x})"},
+ :c2rb => proc{|x| "INT2NUM(#{x})"},
+ :ctype => "int",
+ :stmem => "i",
+ :sym => true,
+ :cb => false,
+ },
+ LONG = 0x04 => {
+ :name => 'LONG',
+ :rb2c => proc{|x| "NUM2INT(#{x})"},
+ :c2rb => proc{|x| "INT2NUM(#{x})"},
+ :ctype => "long",
+ :stmem => "l",
+ :sym => true,
+ :cb => true,
+ },
+ FLOAT = 0x05 => {
+ :name => 'FLOAT',
+ :rb2c => proc{|x| "(float)(RFLOAT(#{x})->value)"},
+ :c2rb => proc{|x| "rb_float_new((double)#{x})"},
+ :ctype => "float",
+ :stmem => "f",
+ :sym => false,
+ :cb => false,
+ },
+ DOUBLE = 0x06 => {
+ :name => 'DOUBLE',
+ :rb2c => proc{|x| "RFLOAT(#{x})->value"},
+ :c2rb => proc{|x| "rb_float_new(#{x})"},
+ :ctype => "double",
+ :stmem => "d",
+ :sym => true,
+ :cb => true,
+ },
+ VOIDP = 0x07 => {
+ :name => 'VOIDP',
+ :rb2c => proc{|x| "rb_dlptr2cptr(#{x})"},
+ :c2rb => proc{|x| "rb_dlptr_new(#{x},sizeof(void*),0)"},
+ :ctype => "void *",
+ :stmem => "p",
+ :sym => true,
+ :cb => true,
+ },
+}
+
+def tpush(t, x)
+ (t << 3)|x
+end
+
+def tget(t, i)
+ (t & (0x07 << (i * 3))) >> (i * 3)
+end
+
+def types2num(types)
+ res = 0x00
+ r = types.reverse
+ r.each{|t|
+ res = tpush(res,t)
+ }
+ res
+end
+
+def num2types(num)
+ ts = []
+ i = 0
+ t = tget(num,i)
+ while( (t != VOID && i > 0) || (i == 0) )
+ ts.push(DLTYPE[t][:ctype])
+ i += 1
+ t = tget(num,i)
+ end
+ ts
+end
+
+def types2ctypes(types)
+ res = []
+ types.each{|t|
+ res.push(DLTYPE[t][:ctype])
+ }
+ res
+end
diff --git a/ext/enumerator/.cvsignore b/ext/enumerator/.cvsignore
new file mode 100644
index 0000000000..fc802ff1c2
--- /dev/null
+++ b/ext/enumerator/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+mkmf.log
diff --git a/ext/enumerator/enumerator.c b/ext/enumerator/enumerator.c
new file mode 100644
index 0000000000..1c6e1d1ace
--- /dev/null
+++ b/ext/enumerator/enumerator.c
@@ -0,0 +1,298 @@
+/************************************************
+
+ enumerator.c - provides Enumerator class
+
+ $Author$
+
+ Copyright (C) 2001-2003 Akinori MUSHA
+
+ $Idaemons: /home/cvs/rb/enumerator/enumerator.c,v 1.1.1.1 2001/07/15 10:12:48 knu Exp $
+ $RoughId: enumerator.c,v 1.6 2003/07/27 11:03:24 nobu Exp $
+ $Id$
+
+************************************************/
+
+#include "ruby.h"
+#include "node.h"
+
+/*
+ * Document-class: Enumerable::Enumerator
+ *
+ * A class which provides a method `each' to be used as an Enumerable
+ * object.
+ */
+static VALUE rb_cEnumerator;
+static ID sym_each, sym_each_with_index, sym_each_slice, sym_each_cons;
+static ID id_new, id_enum_obj, id_enum_method, id_enum_args;
+
+/*
+ * call-seq:
+ * obj.to_enum(method = :each, *args)
+ * obj.enum_for(method = :each, *args)
+ *
+ * Returns Enumerable::Enumerator.new(self, method, *args).
+ *
+ * e.g.:
+ * str = "xyz"
+ *
+ * enum = str.enum_for(:each_byte)
+ * a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
+ *
+ * # protects an array from being modified
+ * a = [1, 2, 3]
+ * some_method(a.to_enum)
+ *
+ */
+static VALUE
+obj_to_enum(obj, enum_args)
+ VALUE obj, enum_args;
+{
+ rb_ary_unshift(enum_args, obj);
+
+ return rb_apply(rb_cEnumerator, id_new, enum_args);
+}
+
+/*
+ * call-seq:
+ * enum_with_index
+ *
+ * Returns Enumerable::Enumerator.new(self, :each_with_index).
+ *
+ */
+static VALUE
+enumerator_enum_with_index(obj)
+ VALUE obj;
+{
+ return rb_funcall(rb_cEnumerator, id_new, 2, obj, sym_each_with_index);
+}
+
+static VALUE
+each_slice_i(val, memo)
+ VALUE val;
+ NODE *memo;
+{
+ VALUE ary = memo->u1.value;
+ long size = memo->u3.cnt;
+
+ rb_ary_push(ary, val);
+
+ if (RARRAY(ary)->len == size) {
+ rb_yield(ary);
+ memo->u1.value = rb_ary_new2(size);
+ }
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * e.each_slice(n) {...}
+ *
+ * Iterates the given block for each slice of <n> elements.
+ *
+ * e.g.:
+ * (1..10).each_slice(3) {|a| p a}
+ * # outputs below
+ * [1, 2, 3]
+ * [4, 5, 6]
+ * [7, 8, 9]
+ * [10]
+ *
+ */
+static VALUE
+enum_each_slice(obj, n)
+ VALUE obj, n;
+{
+ long size = NUM2LONG(n);
+ NODE *memo;
+ VALUE ary;
+
+ if (size <= 0) rb_raise(rb_eArgError, "invalid slice size");
+
+ memo = rb_node_newnode(NODE_MEMO, rb_ary_new2(size), 0, size);
+
+ rb_iterate(rb_each, obj, each_slice_i, (VALUE)memo);
+
+ ary = memo->u1.value;
+ if (RARRAY(ary)->len > 0) rb_yield(ary);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * e.enum_slice(n)
+ *
+ * Returns Enumerable::Enumerator.new(self, :each_slice, n).
+ *
+ */
+static VALUE
+enumerator_enum_slice(obj, n)
+ VALUE obj, n;
+{
+ return rb_funcall(rb_cEnumerator, id_new, 3, obj, sym_each_slice, n);
+}
+
+static VALUE
+each_cons_i(val, memo)
+ VALUE val;
+ NODE *memo;
+{
+ VALUE ary = memo->u1.value;
+ long size = memo->u3.cnt;
+
+ if (RARRAY(ary)->len == size) {
+ rb_ary_shift(ary);
+ }
+ rb_ary_push(ary, val);
+ if (RARRAY(ary)->len == size) {
+ rb_yield(rb_ary_dup(ary));
+ }
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * each_cons(n) {...}
+ *
+ * Iterates the given block for each array of consecutive <n>
+ * elements.
+ *
+ * e.g.:
+ * (1..10).each_cons(3) {|a| p a}
+ * # outputs below
+ * [1, 2, 3]
+ * [2, 3, 4]
+ * [3, 4, 5]
+ * [4, 5, 6]
+ * [5, 6, 7]
+ * [6, 7, 8]
+ * [7, 8, 9]
+ * [8, 9, 10]
+ *
+ */
+static VALUE
+enum_each_cons(obj, n)
+ VALUE obj, n;
+{
+ long size = NUM2LONG(n);
+ NODE *memo;
+
+ if (size <= 0) rb_raise(rb_eArgError, "invalid size");
+ memo = rb_node_newnode(NODE_MEMO, rb_ary_new2(size), 0, size);
+
+ rb_iterate(rb_each, obj, each_cons_i, (VALUE)memo);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * e.enum_cons(n)
+ *
+ * Returns Enumerable::Enumerator.new(self, :each_cons, n).
+ *
+ */
+static VALUE
+enumerator_enum_cons(obj, n)
+ VALUE obj, n;
+{
+ return rb_funcall(rb_cEnumerator, id_new, 3, obj, sym_each_cons, n);
+}
+
+/*
+ * call-seq:
+ * Enumerable::Enumerator.new(obj, method = :each, *args)
+ *
+ * Creates a new Enumerable::Enumerator object, which is to be
+ * used as an Enumerable object using the given object's given
+ * method with the given arguments.
+ *
+ * e.g.:
+ * str = "xyz"
+ *
+ * enum = Enumerable::Enumerator.new(str, :each_byte)
+ * a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
+ *
+ */
+static VALUE
+enumerator_initialize(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
+ VALUE enum_obj, enum_method, enum_args;
+
+ rb_scan_args(argc, argv, "11*", &enum_obj, &enum_method, &enum_args);
+
+ if (enum_method == Qnil)
+ enum_method = sym_each;
+
+ rb_ivar_set(obj, id_enum_obj, enum_obj);
+ rb_ivar_set(obj, id_enum_method, enum_method);
+ rb_ivar_set(obj, id_enum_args, enum_args);
+
+ return Qnil;
+}
+
+static VALUE
+enumerator_iter(memo)
+ NODE *memo;
+{
+ return rb_apply(memo->u1.value, memo->u2.id, memo->u3.value);
+}
+
+/*
+ * call-seq:
+ * enum.each {...}
+ *
+ * Iterates the given block using the object and the method specified
+ * in the first place.
+ *
+ */
+static VALUE
+enumerator_each(obj)
+ VALUE obj;
+{
+ VALUE val;
+
+ obj = (VALUE)rb_node_newnode(NODE_MEMO,
+ rb_ivar_get(obj, id_enum_obj),
+ rb_to_id(rb_ivar_get(obj, id_enum_method)),
+ rb_ivar_get(obj, id_enum_args));
+ val = rb_iterate((VALUE (*)_((VALUE)))enumerator_iter, obj, rb_yield, 0);
+ return val;
+}
+
+void
+Init_enumerator()
+{
+ VALUE rb_mEnumerable;
+
+ rb_define_method(rb_mKernel, "to_enum", obj_to_enum, -2);
+ rb_define_method(rb_mKernel, "enum_for", obj_to_enum, -2);
+
+ rb_mEnumerable = rb_path2class("Enumerable");
+
+ rb_define_method(rb_mEnumerable, "enum_with_index", enumerator_enum_with_index, 0);
+ rb_define_method(rb_mEnumerable, "each_slice", enum_each_slice, 1);
+ rb_define_method(rb_mEnumerable, "enum_slice", enumerator_enum_slice, 1);
+ rb_define_method(rb_mEnumerable, "each_cons", enum_each_cons, 1);
+ rb_define_method(rb_mEnumerable, "enum_cons", enumerator_enum_cons, 1);
+
+ rb_cEnumerator = rb_define_class_under(rb_mEnumerable, "Enumerator", rb_cObject);
+ rb_include_module(rb_cEnumerator, rb_mEnumerable);
+
+ rb_define_method(rb_cEnumerator, "initialize", enumerator_initialize, -1);
+ rb_define_method(rb_cEnumerator, "each", enumerator_each, 0);
+
+ sym_each = ID2SYM(rb_intern("each"));
+ sym_each_with_index = ID2SYM(rb_intern("each_with_index"));
+ sym_each_slice = ID2SYM(rb_intern("each_slice"));
+ sym_each_cons = ID2SYM(rb_intern("each_cons"));
+
+ id_new = rb_intern("new");
+ id_enum_obj = rb_intern("enum_obj");
+ id_enum_method = rb_intern("enum_method");
+ id_enum_args = rb_intern("enum_args");
+}
diff --git a/ext/enumerator/enumerator.txt b/ext/enumerator/enumerator.txt
new file mode 100644
index 0000000000..64c7d50226
--- /dev/null
+++ b/ext/enumerator/enumerator.txt
@@ -0,0 +1,102 @@
+.\" enumerator.txt - -*- Indented-Text -*-
+$Idaemons: /home/cvs/rb/enumerator/enumerator.txt,v 1.2 2001/07/15 10:19:24 knu Exp $
+$RoughId: enumerator.txt,v 1.5 2003/02/20 12:24:51 knu Exp $
+$Id$
+
+** Enumerable::Enumerator(Class)
+
+A class which provides a method `each' to be used as an Enumerable
+object.
+
+Superclass: Object
+
+Mix-ins: Enumerable
+
+require 'enumerator'
+
+Class Methods:
+
+ new(obj, method = :each, *args)
+
+ Creates a new Enumerable::Enumerator object, which is to be
+ used as an Enumerable object using the given object's given
+ method with the given arguments.
+
+ e.g.:
+ str = "xyz"
+
+ enum = Enumerable::Enumerator.new(str, :each_byte)
+ a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
+
+Methods:
+
+ each {...}
+
+ Iterates the given block using the object and the method
+ specified in the first place.
+
+
+Requiring this module also adds some methods to the Object class:
+
+ to_enum(method = :each, *args)
+ enum_for(method = :each, *args)
+
+ Returns Enumerable::Enumerator.new(self, method, *args).
+
+ e.g.:
+ str = "xyz"
+
+ enum = str.enum_for(:each_byte)
+ a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
+
+ # protects an array from being modified
+ a = [1, 2, 3]
+ some_method(a.to_enum)
+
+And the Enumerable module.
+
+ each_slice(n) {...}
+
+ Iterates the given block for each slice of <n> elements.
+
+ e.g.:
+ (1..10).each_slice(3) {|a| p a}
+ # outputs below
+ [1, 2, 3]
+ [4, 5, 6]
+ [7, 8, 9]
+ [10]
+
+ enum_slice(n)
+
+ Returns Enumerable::Enumerator.new(self, :each_slice, n).
+
+ each_cons(n) {...}
+
+ Iterates the given block for each array of consecutive <n>
+ elements.
+
+ e.g.:
+ (1..10).each_cons(3) {|a| p a}
+ # outputs below
+ [1, 2, 3]
+ [2, 3, 4]
+ [3, 4, 5]
+ [4, 5, 6]
+ [5, 6, 7]
+ [6, 7, 8]
+ [7, 8, 9]
+ [8, 9, 10]
+
+ enum_cons(n)
+
+ Returns Enumerable::Enumerator.new(self, :each_cons, n).
+
+ enum_with_index
+
+ Returns Enumerable::Enumerator.new(self, :each_with_index).
+
+-------------------------------------------------------
+Local variables:
+fill-column: 70
+end:
diff --git a/ext/enumerator/extconf.rb b/ext/enumerator/extconf.rb
new file mode 100644
index 0000000000..94e2ee38b2
--- /dev/null
+++ b/ext/enumerator/extconf.rb
@@ -0,0 +1,2 @@
+require 'mkmf'
+create_makefile('enumerator')
diff --git a/ext/etc/.cvsignore b/ext/etc/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/etc/.cvsignore
+++ b/ext/etc/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/etc/etc.c b/ext/etc/etc.c
index 1bd767d09c..486963378b 100644
--- a/ext/etc/etc.c
+++ b/ext/etc/etc.c
@@ -40,7 +40,8 @@ char *getlogin();
* Etc.getlogin -> 'guest'
*/
static VALUE
-etc_getlogin(VALUE obj)
+etc_getlogin(obj)
+ VALUE obj;
{
char *login;
@@ -59,7 +60,8 @@ etc_getlogin(VALUE obj)
#if defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT)
static VALUE
-safe_setup_str(const char *str)
+safe_setup_str(str)
+ const char *str;
{
if (str == 0) str = "";
return rb_tainted_str_new2(str);
@@ -68,7 +70,8 @@ safe_setup_str(const char *str)
#ifdef HAVE_GETPWENT
static VALUE
-setup_passwd(struct passwd *pwd)
+setup_passwd(pwd)
+ struct passwd *pwd;
{
if (pwd == 0) rb_sys_fail("/etc/passwd");
return rb_struct_new(sPasswd,
@@ -116,7 +119,10 @@ setup_passwd(struct passwd *pwd)
* passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">
*/
static VALUE
-etc_getpwuid(int argc, VALUE *argv, VALUE obj)
+etc_getpwuid(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
#if defined(HAVE_GETPWENT)
VALUE id;
@@ -125,16 +131,7 @@ etc_getpwuid(int argc, VALUE *argv, VALUE obj)
rb_secure(4);
if (rb_scan_args(argc, argv, "01", &id) == 1) {
-#if HAVE_LONG_LONG && HAVE_TYPE_UID_T
- if (sizeof(uid_t) > sizeof(int)) {
- uid = NUM2ULL(id);
- }
- else {
- uid = NUM2UINT(id);
- }
-#else
- uid = NUM2UINT(id);
-#endif
+ uid = PW_VAL2UID(id);
}
else {
uid = getuid();
@@ -156,14 +153,15 @@ etc_getpwuid(int argc, VALUE *argv, VALUE obj)
* passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">
*/
static VALUE
-etc_getpwnam(VALUE obj, VALUE nam)
+etc_getpwnam(obj, nam)
+ VALUE obj, nam;
{
#ifdef HAVE_GETPWENT
struct passwd *pwd;
SafeStringValue(nam);
- pwd = getpwnam(RSTRING_PTR(nam));
- if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %s", RSTRING_PTR(nam));
+ pwd = getpwnam(RSTRING(nam)->ptr);
+ if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %s", RSTRING(nam)->ptr);
return setup_passwd(pwd);
#else
return Qnil;
@@ -209,7 +207,8 @@ passwd_iterate()
*
*/
static VALUE
-etc_passwd(VALUE obj)
+etc_passwd(obj)
+ VALUE obj;
{
#ifdef HAVE_GETPWENT
struct passwd *pw;
@@ -233,7 +232,8 @@ etc_passwd(VALUE obj)
* to getpwent will return the first entry again.
*/
static VALUE
-etc_setpwent(VALUE obj)
+etc_setpwent(obj)
+ VALUE obj;
{
#ifdef HAVE_GETPWENT
setpwent();
@@ -245,7 +245,8 @@ etc_setpwent(VALUE obj)
* getpwent, and closes the file.
*/
static VALUE
-etc_endpwent(VALUE obj)
+etc_endpwent(obj)
+ VALUE obj;
{
#ifdef HAVE_GETPWENT
endpwent();
@@ -280,7 +281,8 @@ etc_endpwent(VALUE obj)
* - Passwd#shell contains the path to the login shell of the user as a String.
*/
static VALUE
-etc_getpwent(VALUE obj)
+etc_getpwent(obj)
+ VALUE obj;
{
#ifdef HAVE_GETPWENT
struct passwd *pw;
@@ -294,7 +296,8 @@ etc_getpwent(VALUE obj)
#ifdef HAVE_GETGRENT
static VALUE
-setup_group(struct group *grp)
+setup_group(grp)
+ struct group *grp;
{
VALUE mem;
char **tbl;
@@ -326,14 +329,15 @@ setup_group(struct group *grp)
*
*/
static VALUE
-etc_getgrgid(VALUE obj, VALUE id)
+etc_getgrgid(obj, id)
+ VALUE obj, id;
{
#ifdef HAVE_GETGRENT
- int gid;
+ gid_t gid;
struct group *grp;
rb_secure(4);
- gid = NUM2INT(id);
+ gid = PW_VAL2GID(id);
grp = getgrgid(gid);
if (grp == 0) rb_raise(rb_eArgError, "can't find group for %d", gid);
return setup_group(grp);
@@ -353,15 +357,16 @@ etc_getgrgid(VALUE obj, VALUE id)
*
*/
static VALUE
-etc_getgrnam(VALUE obj, VALUE nam)
+etc_getgrnam(obj, nam)
+ VALUE obj, nam;
{
#ifdef HAVE_GETGRENT
struct group *grp;
rb_secure(4);
SafeStringValue(nam);
- grp = getgrnam(RSTRING_PTR(nam));
- if (grp == 0) rb_raise(rb_eArgError, "can't find group for %s", RSTRING_PTR(nam));
+ grp = getgrnam(RSTRING(nam)->ptr);
+ if (grp == 0) rb_raise(rb_eArgError, "can't find group for %s", RSTRING(nam)->ptr);
return setup_group(grp);
#else
return Qnil;
@@ -407,7 +412,8 @@ group_iterate()
*
*/
static VALUE
-etc_group(VALUE obj)
+etc_group(obj)
+ VALUE obj;
{
#ifdef HAVE_GETGRENT
struct group *grp;
@@ -431,7 +437,8 @@ etc_group(VALUE obj)
* to getgrent will return the first entry again.
*/
static VALUE
-etc_setgrent(VALUE obj)
+etc_setgrent(obj)
+ VALUE obj;
{
#ifdef HAVE_GETGRENT
setgrent();
@@ -443,7 +450,8 @@ etc_setgrent(VALUE obj)
* getgrent, and closes the file.
*/
static VALUE
-etc_endgrent(VALUE obj)
+etc_endgrent(obj)
+ VALUE obj;
{
#ifdef HAVE_GETGRENT
endgrent();
@@ -472,7 +480,8 @@ etc_endgrent(VALUE obj)
* members of the group.
*/
static VALUE
-etc_getgrent(VALUE obj)
+etc_getgrent(obj)
+ VALUE obj;
{
#ifdef HAVE_GETGRENT
struct group *gr;
@@ -492,7 +501,7 @@ static VALUE mEtc;
* Documented by mathew <meta@pobox.com>.
*/
void
-Init_etc(void)
+Init_etc()
{
mEtc = rb_define_module("Etc");
diff --git a/ext/etc/extconf.rb b/ext/etc/extconf.rb
index 2496d36aa1..dbd0672545 100644
--- a/ext/etc/extconf.rb
+++ b/ext/etc/extconf.rb
@@ -35,7 +35,9 @@ if a or b or c
f = "U#{f}"
end
end
- $defs.push("-DPW_#{t.chomp('_t').upcase}2VAL=#{f}")
+ t = t.chomp('_t').upcase
+ $defs.push("-DPW_#{t}2VAL=#{f}")
+ $defs.push("-DPW_VAL2#{t}=#{f.sub(/([A-Z]+)2(NUM)/, '\22\1')}")
end
create_makefile("etc")
end
diff --git a/ext/extmk.rb b/ext/extmk.rb
index 290fef9d56..cf7944679c 100644
--- a/ext/extmk.rb
+++ b/ext/extmk.rb
@@ -69,7 +69,7 @@ def extract_makefile(makefile, keep = true)
unless installrb.empty?
config = CONFIG.dup
install_dirs(target_prefix).each {|var, val| config[var] = val}
- FileUtils.rm_f(installrb.values.collect {|f| RbConfig.expand(f, config)}, verbose: true)
+ FileUtils.rm_f(installrb.values.collect {|f| Config.expand(f, config)}, :verbose => true)
end
end
return false
@@ -112,10 +112,10 @@ def extmake(target)
Dir.chdir target
top_srcdir = $top_srcdir
topdir = $topdir
- mk_srcdir = CONFIG["srcdir"]
- mk_topdir = CONFIG["topdir"]
+ hdrdir = $hdrdir
prefix = "../" * (target.count("/")+1)
- $hdrdir = $top_srcdir = relative_from(top_srcdir, prefix)
+ $top_srcdir = relative_from(top_srcdir, prefix)
+ $hdrdir = relative_from(hdrdir, prefix)
$topdir = prefix + $topdir
$target = target
$mdir = target
@@ -127,12 +127,31 @@ def extmake(target)
makefile = "./Makefile"
ok = File.exist?(makefile)
unless $ignore
- RbConfig::CONFIG["hdrdir"] = $hdrdir
- RbConfig::CONFIG["srcdir"] = $srcdir
- RbConfig::CONFIG["topdir"] = $topdir
- CONFIG["hdrdir"] = ($hdrdir == top_srcdir) ? top_srcdir : "$(topdir)"+top_srcdir[2..-1]
- CONFIG["srcdir"] = "$(hdrdir)/ext/#{$mdir}"
- CONFIG["topdir"] = $topdir
+ 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)
+ }
begin
$extconf_h = nil
ok &&= extract_makefile(makefile)
@@ -165,7 +184,7 @@ def extmake(target)
ok = yield(ok) if block_given?
unless ok
open(makefile, "w") do |f|
- f.print(*dummy_makefile(CONFIG["srcdir"]))
+ f.print dummy_makefile(CONFIG["srcdir"])
end
return true
end
@@ -181,7 +200,11 @@ def extmake(target)
$ignore or $continue or return false
end
$compiled[target] = true
- if $clean and $clean != true
+ if $clean
+ FileUtils.rm_f("mkmf.log")
+ if $clean != true
+ FileUtils.rm_f([makefile, $extconf_h || "extconf.h"])
+ end
File.unlink(makefile) rescue nil
end
if $static
@@ -195,13 +218,21 @@ def extmake(target)
$extpath |= $LIBPATH
end
ensure
- RbConfig::CONFIG["srcdir"] = $top_srcdir
- RbConfig::CONFIG["topdir"] = topdir
- CONFIG["srcdir"] = mk_srcdir
- CONFIG["topdir"] = mk_topdir
- CONFIG.delete("hdrdir")
- $hdrdir = $top_srcdir = top_srcdir
+ 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
$topdir = topdir
+ $hdrdir = hdrdir
Dir.chdir dir
end
begin
@@ -220,6 +251,7 @@ end
def parse_args()
$mflags = []
+ opts = nil
$optparser ||= OptionParser.new do |opts|
opts.on('-n') {$dryrun = true}
opts.on('--[no-]extension [EXTS]', Array) do |v|
@@ -258,7 +290,7 @@ def parse_args()
rescue OptionParser::InvalidOption => e
retry if /^--/ =~ e.args[0]
$optparser.warn(e)
- abort $optparser.to_s
+ abort opts.to_s
end
$destdir ||= ''
@@ -267,7 +299,7 @@ def parse_args()
$mflags.unshift(*rest) unless rest.empty?
def $mflags.set?(flag)
- grep(/\A-(?!-).*#{'%s' % flag}/i) { return true }
+ grep(/\A-(?!-).*#{'%c' % flag}/i) { return true }
false
end
def $mflags.defined?(var)
@@ -284,6 +316,7 @@ 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
@@ -322,16 +355,19 @@ elsif sep = config_string('BUILD_FILE_SEPARATOR')
else
$ruby = '$(topdir)/miniruby' + EXEEXT
end
-$ruby << " -I'$(topdir)' -I'$(hdrdir)/lib'"
+$ruby << " -I'$(topdir)' -I'$(top_srcdir)/lib'"
+$ruby << " -I'$(extout)/$(arch)' -I'$(extout)/common'" if $extout
+$ruby << " -I'$(hdrdir)/ext' -rpurelib.rb"
$config_h = '$(topdir)/config.h'
+ENV["RUBYLIB"] = "-"
+ENV["RUBYOPT"] = "-rpurelib.rb"
MTIMES = [__FILE__, 'rbconfig.rb', srcdir+'/lib/mkmf.rb'].collect {|f| File.mtime(f)}
# get static-link modules
$static_ext = {}
if $extstatic
- $extstatic.each do |t|
- target = t
+ $extstatic.each do |target|
target = target.downcase if /mswin32|bccwin32/ =~ RUBY_PLATFORM
$static_ext[target] = $static_ext.size
end
@@ -368,17 +404,17 @@ if $extension
exts |= $extension.select {|d| File.directory?("#{ext_prefix}/#{d}")}
else
withes, withouts = %w[--with --without].collect {|w|
- if not (w = %w[-extensions -ext].collect {|o|arg_config(w+o)}).any?
+ if not (w = %w[-extensions -ext].collect {|opt|arg_config(w+opt)}).any?
proc {false}
elsif (w = w.grep(String)).empty?
proc {true}
else
- w.collect {|o| o.split(/,/)}.flatten.method(:any?)
+ proc {|c1| w.collect {|opt| opt.split(/,/)}.flatten.any?(&c1)}
end
}
cond = proc {|ext|
cond1 = proc {|n| File.fnmatch(n, ext, File::FNM_PATHNAME)}
- withes.call(&cond1) or !withouts.call(&cond1)
+ withes.call(cond1) or !withouts.call(cond1)
}
exts |= Dir.glob("#{ext_prefix}/*/**/extconf.rb").collect {|d|
d = File.dirname(d)
@@ -390,7 +426,7 @@ else
end
if $extout
- extout = RbConfig.expand("#{$extout}", RbConfig::CONFIG.merge("topdir"=>$topdir))
+ extout = Config.expand("#{$extout}", Config::CONFIG.merge("topdir"=>$topdir))
unless $ignore
FileUtils.mkpath(extout)
end
@@ -400,12 +436,14 @@ 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
-$hdrdir = $top_srcdir = srcdir
+$top_srcdir = srcdir
$topdir = "."
+$hdrdir = hdrdir
extinit = Struct.new(:c, :o) {
def initialize(src)
@@ -451,17 +489,14 @@ unless $extlist.empty?
src = %{\
#include "ruby.h"
-#define init(func, name) { \
- void func _((void)); \
- ruby_sourcefile = src = rb_source_filename(name); \
- func(); \
- rb_provide(src); \
-}
+#define init(func, name) {void func _((void)); ruby_init_ext(name, func);}
+
+void ruby_init_ext _((const char *name, void (*init)(void)));
-void Init_ext _((void))\n{\n char *src;#$extinit}
+void Init_ext _((void))\n{\n#$extinit}
}
if !modified?(extinit.c, MTIMES) || IO.read(extinit.c) != src
- open(extinit.c, "w") {|fe| fe.print src}
+ open(extinit.c, "w") {|f| f.print src}
end
$extobjs = "ext/#{extinit.o} #{$extobjs}"
@@ -478,15 +513,15 @@ void Init_ext _((void))\n{\n char *src;#$extinit}
].map {|n, v|
"#{n}=#{v}" if v and !(v = v.strip).empty?
}.compact
- puts(*conf)
+ puts conf
$stdout.flush
$mflags.concat(conf)
else
FileUtils.rm_f(extinit.to_a)
end
rubies = []
-%w[RUBY RUBYW STATIC_RUBY].each {|n|
- r = n
+%w[RUBY RUBYW STATIC_RUBY].each {|r|
+ n = r
if r = arg_config("--"+r.downcase) || config_string(r+"_INSTALL_NAME")
rubies << Config.expand(r+=EXEEXT)
$mflags << "#{n}=#{r}"
diff --git a/ext/fcntl/.cvsignore b/ext/fcntl/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/fcntl/.cvsignore
+++ b/ext/fcntl/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/gdbm/.cvsignore b/ext/gdbm/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/gdbm/.cvsignore
+++ b/ext/gdbm/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index 7beffd2bdc..82109fda90 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -79,7 +79,8 @@ static VALUE rb_cGDBM, rb_eGDBMError, rb_eGDBMFatalError;
#define MY_BLOCK_SIZE (2048)
#define MY_FATAL_FUNC rb_gdbm_fatal
static void
-rb_gdbm_fatal(char *msg)
+rb_gdbm_fatal(msg)
+ char *msg;
{
rb_raise(rb_eGDBMFatalError, "%s", msg);
}
@@ -90,7 +91,7 @@ struct dbmdata {
};
static void
-closed_dbm(void)
+closed_dbm()
{
rb_raise(rb_eRuntimeError, "closed GDBM file");
}
@@ -107,7 +108,8 @@ closed_dbm(void)
}
static void
-free_dbm(struct dbmdata *dbmp)
+free_dbm(dbmp)
+ struct dbmdata *dbmp;
{
if (dbmp) {
if (dbmp->di_dbm) gdbm_close(dbmp->di_dbm);
@@ -122,7 +124,8 @@ free_dbm(struct dbmdata *dbmp)
* Closes the associated database file.
*/
static VALUE
-fgdbm_close(VALUE obj)
+fgdbm_close(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
@@ -140,7 +143,8 @@ fgdbm_close(VALUE obj)
* Returns true if the associated database file has been closed.
*/
static VALUE
-fgdbm_closed(VALUE obj)
+fgdbm_closed(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
@@ -153,8 +157,11 @@ fgdbm_closed(VALUE obj)
return Qfalse;
}
+static VALUE fgdbm_s_alloc _((VALUE));
+
static VALUE
-fgdbm_s_alloc(VALUE klass)
+fgdbm_s_alloc(klass)
+ VALUE klass;
{
return Data_Wrap_Struct(klass, 0, free_dbm, 0);
}
@@ -183,7 +190,10 @@ fgdbm_s_alloc(VALUE klass)
* database file as a reader (cf. flag <tt>READER</tt>).
*/
static VALUE
-fgdbm_initialize(int argc, VALUE *argv, VALUE obj)
+fgdbm_initialize(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE file, vmode, vflags;
GDBM_FILE dbm;
@@ -207,31 +217,31 @@ fgdbm_initialize(int argc, VALUE *argv, VALUE obj)
if (flags & RUBY_GDBM_RW_BIT) {
flags &= ~RUBY_GDBM_RW_BIT;
- dbm = gdbm_open(RSTRING_PTR(file), MY_BLOCK_SIZE,
- flags, mode, MY_FATAL_FUNC);
+ dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
+ flags, mode, MY_FATAL_FUNC);
}
else {
dbm = 0;
if (mode >= 0)
- dbm = gdbm_open(RSTRING_PTR(file), MY_BLOCK_SIZE,
+ dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
GDBM_WRCREAT|flags, mode, MY_FATAL_FUNC);
if (!dbm)
- dbm = gdbm_open(RSTRING_PTR(file), MY_BLOCK_SIZE,
+ dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
GDBM_WRITER|flags, 0, MY_FATAL_FUNC);
if (!dbm)
- dbm = gdbm_open(RSTRING_PTR(file), MY_BLOCK_SIZE,
+ dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE,
GDBM_READER|flags, 0, MY_FATAL_FUNC);
}
if (!dbm) {
- if (mode == -1) return Qnil;
-
- if (gdbm_errno == GDBM_FILE_OPEN_ERROR ||
- gdbm_errno == GDBM_CANT_BE_READER ||
- gdbm_errno == GDBM_CANT_BE_WRITER)
- rb_sys_fail(RSTRING_PTR(file));
- else
- rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
+ if (mode == -1) return Qnil;
+
+ if (gdbm_errno == GDBM_FILE_OPEN_ERROR ||
+ gdbm_errno == GDBM_CANT_BE_READER ||
+ gdbm_errno == GDBM_CANT_BE_WRITER)
+ rb_sys_fail(RSTRING(file)->ptr);
+ else
+ rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
}
dbmp = ALLOC(struct dbmdata);
@@ -263,12 +273,15 @@ fgdbm_initialize(int argc, VALUE *argv, VALUE obj)
* end
*/
static VALUE
-fgdbm_s_open(int argc, VALUE *argv, VALUE klass)
+fgdbm_s_open(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE obj = Data_Wrap_Struct(klass, 0, free_dbm, 0);
if (NIL_P(fgdbm_initialize(argc, argv, obj))) {
- return Qnil;
+ return Qnil;
}
if (rb_block_given_p()) {
@@ -279,7 +292,9 @@ fgdbm_s_open(int argc, VALUE *argv, VALUE klass)
}
static VALUE
-rb_gdbm_fetch(GDBM_FILE dbm, datum key)
+rb_gdbm_fetch(dbm, key)
+ GDBM_FILE dbm;
+ datum key;
{
datum val;
VALUE str;
@@ -288,26 +303,33 @@ rb_gdbm_fetch(GDBM_FILE dbm, datum 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 (VALUE)str;
}
static VALUE
-rb_gdbm_fetch2(GDBM_FILE dbm, VALUE keystr)
+rb_gdbm_fetch2(dbm, keystr)
+ GDBM_FILE dbm;
+ VALUE keystr;
{
datum key;
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
return rb_gdbm_fetch(dbm, key);
}
static VALUE
-rb_gdbm_fetch3(VALUE obj, VALUE keystr)
+rb_gdbm_fetch3(obj, keystr)
+ VALUE obj, keystr;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -317,7 +339,8 @@ rb_gdbm_fetch3(VALUE obj, VALUE keystr)
}
static VALUE
-rb_gdbm_firstkey(GDBM_FILE dbm)
+rb_gdbm_firstkey(dbm)
+ GDBM_FILE dbm;
{
datum key;
VALUE str;
@@ -326,39 +349,51 @@ rb_gdbm_firstkey(GDBM_FILE 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;
}
static VALUE
-rb_gdbm_nextkey(GDBM_FILE dbm, VALUE keystr)
+rb_gdbm_nextkey(dbm, keystr)
+ GDBM_FILE dbm;
+ VALUE keystr;
{
datum key, key2;
VALUE str;
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
key2 = gdbm_nextkey(dbm, key);
if (key2.dptr == 0)
return Qnil;
- str = rb_str_new(key2.dptr, key2.dsize);
+ 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;
}
static VALUE
-fgdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
+fgdbm_fetch(obj, keystr, ifnone)
+ VALUE obj, keystr, ifnone;
{
VALUE valstr;
valstr = rb_gdbm_fetch3(obj, keystr);
if (NIL_P(valstr)) {
- if (ifnone == Qnil && rb_block_given_p())
- return rb_yield(keystr);
- return ifnone;
+ if (ifnone == Qnil && rb_block_given_p())
+ return rb_yield(keystr);
+ return ifnone;
}
return valstr;
}
@@ -370,7 +405,8 @@ fgdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
* Retrieves the _value_ corresponding to _key_.
*/
static VALUE
-fgdbm_aref(VALUE obj, VALUE keystr)
+fgdbm_aref(obj, keystr)
+ VALUE obj, keystr;
{
return rb_gdbm_fetch3(obj, keystr);
}
@@ -383,7 +419,10 @@ fgdbm_aref(VALUE obj, VALUE keystr)
* associated with _key_, _default_ will be returned instead.
*/
static VALUE
-fgdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
+fgdbm_fetch_m(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE keystr, valstr, ifnone;
@@ -403,7 +442,8 @@ fgdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
* same value, the key that is found first will be returned.
*/
static VALUE
-fgdbm_index(VALUE obj, VALUE valstr)
+fgdbm_index(obj, valstr)
+ VALUE obj, valstr;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -414,17 +454,34 @@ fgdbm_index(VALUE obj, VALUE valstr)
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
- valstr2 = rb_gdbm_fetch2(dbm, keystr);
+ valstr2 = rb_gdbm_fetch2(dbm, keystr);
if (!NIL_P(valstr2) &&
- RSTRING_LEN(valstr) == RSTRING_LEN(valstr2) &&
- memcmp(RSTRING_PTR(valstr), RSTRING_PTR(valstr2),
- RSTRING_LEN(valstr)) == 0) {
- return keystr;
+ RSTRING(valstr)->len == RSTRING(valstr2)->len &&
+ memcmp(RSTRING(valstr)->ptr, RSTRING(valstr2)->ptr,
+ RSTRING(valstr)->len) == 0) {
+ return keystr;
}
}
return Qnil;
}
+static VALUE
+fgdbm_indexes(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
+ VALUE new;
+ int i;
+
+ new = rb_ary_new2(argc);
+ for (i=0; i<argc; i++) {
+ rb_ary_push(new, rb_gdbm_fetch3(obj, argv[i]));
+ }
+
+ return new;
+}
+
/*
* call-seq:
* gdbm.select { |value| block } -> array
@@ -433,23 +490,40 @@ fgdbm_index(VALUE obj, VALUE valstr)
* evaluates to true.
*/
static VALUE
-fgdbm_select(VALUE obj)
+fgdbm_select(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
- VALUE new = rb_ary_new();
- GDBM_FILE dbm;
- struct dbmdata *dbmp;
- VALUE keystr;
+ VALUE new = rb_ary_new2(argc);
+ int i;
- GetDBM2(obj, dbmp, dbm);
- for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
- keystr = rb_gdbm_nextkey(dbm, keystr)) {
- VALUE assoc = rb_assoc_new(keystr, rb_gdbm_fetch2(dbm, keystr));
- VALUE v = rb_yield(assoc);
+ if (rb_block_given_p()) {
+ GDBM_FILE dbm;
+ struct dbmdata *dbmp;
+ VALUE keystr;
- if (RTEST(v)) {
- rb_ary_push(new, assoc);
- }
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
+ }
GetDBM2(obj, dbmp, dbm);
+ for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
+ keystr = rb_gdbm_nextkey(dbm, keystr)) {
+ VALUE assoc = rb_assoc_new(keystr, rb_gdbm_fetch2(dbm, keystr));
+ VALUE v = rb_yield(assoc);
+
+ if (RTEST(v)) {
+ rb_ary_push(new, assoc);
+ }
+ GetDBM2(obj, dbmp, dbm);
+ }
+ }
+ else {
+ rb_warn("GDBM#select(index..) is deprecated; use GDBM#values_at");
+
+ for (i=0; i<argc; i++) {
+ rb_ary_push(new, rb_gdbm_fetch3(obj, argv[i]));
+ }
}
return new;
@@ -462,7 +536,10 @@ fgdbm_select(VALUE obj)
* Returns an array of the values associated with each specified _key_.
*/
static VALUE
-fgdbm_values_at(int argc, VALUE *argv, VALUE obj)
+fgdbm_values_at(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE new = rb_ary_new2(argc);
int i;
@@ -475,14 +552,16 @@ fgdbm_values_at(int argc, VALUE *argv, VALUE obj)
}
static void
-rb_gdbm_modify(VALUE obj)
+rb_gdbm_modify(obj)
+ VALUE obj;
{
rb_secure(4);
if (OBJ_FROZEN(obj)) rb_error_frozen("GDBM");
}
static VALUE
-rb_gdbm_delete(VALUE obj, VALUE keystr)
+rb_gdbm_delete(obj, keystr)
+ VALUE obj, keystr;
{
datum key;
struct dbmdata *dbmp;
@@ -490,8 +569,8 @@ rb_gdbm_delete(VALUE obj, VALUE keystr)
rb_gdbm_modify(obj);
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
GetDBM2(obj, dbmp, dbm);
if (!gdbm_exists(dbm, key)) {
@@ -516,7 +595,8 @@ rb_gdbm_delete(VALUE obj, VALUE keystr)
* returns the corresponding _value_. Returns nil if the database is empty.
*/
static VALUE
-fgdbm_delete(VALUE obj, VALUE keystr)
+fgdbm_delete(obj, keystr)
+ VALUE obj, keystr;
{
VALUE valstr;
@@ -533,7 +613,8 @@ fgdbm_delete(VALUE obj, VALUE keystr)
* two-item array [ _key_, _value_ ]. Returns nil if the database is empty.
*/
static VALUE
-fgdbm_shift(VALUE obj)
+fgdbm_shift(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -557,7 +638,8 @@ fgdbm_shift(VALUE obj)
* Deletes every key-value pair from _gdbm_ for which _block_ evaluates to true.
*/
static VALUE
-fgdbm_delete_if(VALUE obj)
+fgdbm_delete_if(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -580,10 +662,10 @@ fgdbm_delete_if(VALUE obj)
GetDBM2(obj, dbmp, dbm);
}
- for (i = 0; i < RARRAY_LEN(ary); i++)
- rb_gdbm_delete(obj, RARRAY_PTR(ary)[i]);
+ for (i = 0; i < RARRAY(ary)->len; i++)
+ rb_gdbm_delete(obj, RARRAY(ary)->ptr[i]);
if (status) rb_jump_tag(status);
- if (n > 0) dbmp->di_size = n - RARRAY_LEN(ary);
+ if (n > 0) dbmp->di_size = n - RARRAY(ary)->len;
return obj;
}
@@ -595,7 +677,8 @@ fgdbm_delete_if(VALUE obj)
* Removes all the key-value pairs within _gdbm_.
*/
static VALUE
-fgdbm_clear(VALUE obj)
+fgdbm_clear(obj)
+ VALUE obj;
{
datum key, nextkey;
struct dbmdata *dbmp;
@@ -639,7 +722,8 @@ fgdbm_clear(VALUE obj)
* as values.
*/
static VALUE
-fgdbm_invert(VALUE obj)
+fgdbm_invert(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -649,55 +733,33 @@ fgdbm_invert(VALUE obj)
GetDBM2(obj, dbmp, dbm);
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
- valstr = rb_gdbm_fetch2(dbm, keystr);
+ valstr = rb_gdbm_fetch2(dbm, keystr);
- rb_hash_aset(hash, valstr, keystr);
+ rb_hash_aset(hash, valstr, keystr);
}
return hash;
}
-/*
- * call-seq:
- * gdbm[key]= value -> value
- * gdbm.store(key, value) -> value
- *
- * Associates the value _value_ with the specified _key_.
- */
+static VALUE each_pair _((VALUE));
+
static VALUE
-fgdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
+each_pair(obj)
+ VALUE obj;
{
- datum key, val;
- struct dbmdata *dbmp;
- GDBM_FILE dbm;
-
- rb_gdbm_modify(obj);
- StringValue(keystr);
- StringValue(valstr);
-
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
-
- val.dptr = RSTRING_PTR(valstr);
- val.dsize = RSTRING_LEN(valstr);
-
- GetDBM2(obj, dbmp, dbm);
- dbmp->di_size = -1;
- if (gdbm_store(dbm, key, val, GDBM_REPLACE)) {
- if (errno == EPERM) rb_sys_fail(0);
- rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
- }
-
- return valstr;
+ return rb_funcall(obj, rb_intern("each_pair"), 0, 0);
}
+static VALUE fgdbm_store _((VALUE,VALUE,VALUE));
+
static VALUE
-update_i(VALUE pair, VALUE dbm)
+update_i(pair, dbm)
+ VALUE pair, dbm;
{
Check_Type(pair, T_ARRAY);
- if (RARRAY_LEN(pair) < 2) {
- rb_raise(rb_eArgError, "pair must be [key, value]");
+ if (RARRAY(pair)->len < 2) {
+ rb_raise(rb_eArgError, "pair must be [key, value]");
}
- fgdbm_store(dbm, RARRAY_PTR(pair)[0], RARRAY_PTR(pair)[1]);
+ fgdbm_store(dbm, RARRAY(pair)->ptr[0], RARRAY(pair)->ptr[1]);
return Qnil;
}
@@ -710,9 +772,10 @@ update_i(VALUE pair, VALUE dbm)
* method.
*/
static VALUE
-fgdbm_update(VALUE obj, VALUE other)
+fgdbm_update(obj, other)
+ VALUE obj, other;
{
- rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
+ rb_iterate(each_pair, other, update_i, obj);
return obj;
}
@@ -724,22 +787,59 @@ fgdbm_update(VALUE obj, VALUE other)
* _other_ must have an each_pair method.
*/
static VALUE
-fgdbm_replace(VALUE obj, VALUE other)
+fgdbm_replace(obj, other)
+ VALUE obj, other;
{
fgdbm_clear(obj);
- rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
+ rb_iterate(each_pair, other, update_i, obj);
return obj;
}
/*
* call-seq:
+ * gdbm[key]= value -> value
+ * gdbm.store(key, value) -> value
+ *
+ * Associates the value _value_ with the specified _key_.
+ */
+static VALUE
+fgdbm_store(obj, keystr, valstr)
+ VALUE obj, keystr, valstr;
+{
+ datum key, val;
+ struct dbmdata *dbmp;
+ GDBM_FILE dbm;
+
+ rb_gdbm_modify(obj);
+ StringValue(keystr);
+ StringValue(valstr);
+
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
+
+ val.dptr = RSTRING(valstr)->ptr;
+ val.dsize = RSTRING(valstr)->len;
+
+ GetDBM2(obj, dbmp, dbm);
+ dbmp->di_size = -1;
+ if (gdbm_store(dbm, key, val, GDBM_REPLACE)) {
+ if (errno == EPERM) rb_sys_fail(0);
+ rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
+ }
+
+ return valstr;
+}
+
+/*
+ * call-seq:
* gdbm.length -> fixnum
* gdbm.size -> fixnum
*
* Returns the number of key-value pairs in this database.
*/
static VALUE
-fgdbm_length(VALUE obj)
+fgdbm_length(obj)
+ VALUE obj;
{
datum key, nextkey;
struct dbmdata *dbmp;
@@ -752,7 +852,7 @@ fgdbm_length(VALUE obj)
for (key = gdbm_firstkey(dbm); key.dptr; key = nextkey) {
nextkey = gdbm_nextkey(dbm, key);
free(key.dptr);
- i++;
+ i++;
}
dbmp->di_size = i;
@@ -766,7 +866,8 @@ fgdbm_length(VALUE obj)
* Returns true if the database is empty.
*/
static VALUE
-fgdbm_empty_p(VALUE obj)
+fgdbm_empty_p(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -774,13 +875,13 @@ fgdbm_empty_p(VALUE obj)
GetDBM(obj, dbmp);
if (dbmp->di_size < 0) {
- dbm = dbmp->di_dbm;
+ dbm = dbmp->di_dbm;
- key = gdbm_firstkey(dbm);
+ key = gdbm_firstkey(dbm);
if (key.dptr) {
free(key.dptr);
return Qfalse;
- }
+ }
return Qtrue;
}
@@ -796,7 +897,8 @@ fgdbm_empty_p(VALUE obj)
* _value_ as a parameter.
*/
static VALUE
-fgdbm_each_value(VALUE obj)
+fgdbm_each_value(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -807,7 +909,7 @@ fgdbm_each_value(VALUE obj)
keystr = rb_gdbm_nextkey(dbm, keystr)) {
rb_yield(rb_gdbm_fetch2(dbm, keystr));
- GetDBM2(obj, dbmp, dbm);
+ GetDBM2(obj, dbmp, dbm);
}
return obj;
}
@@ -820,7 +922,8 @@ fgdbm_each_value(VALUE obj)
* _key_ as a parameter.
*/
static VALUE
-fgdbm_each_key(VALUE obj)
+fgdbm_each_key(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -831,7 +934,7 @@ fgdbm_each_key(VALUE obj)
keystr = rb_gdbm_nextkey(dbm, keystr)) {
rb_yield(keystr);
- GetDBM2(obj, dbmp, dbm);
+ GetDBM2(obj, dbmp, dbm);
}
return obj;
}
@@ -844,7 +947,8 @@ fgdbm_each_key(VALUE obj)
* correspoding _value_ as a parameter.
*/
static VALUE
-fgdbm_each_pair(VALUE obj)
+fgdbm_each_pair(obj)
+ VALUE obj;
{
GDBM_FILE dbm;
struct dbmdata *dbmp;
@@ -868,7 +972,8 @@ fgdbm_each_pair(VALUE obj)
* Returns an array of all keys of this database.
*/
static VALUE
-fgdbm_keys(VALUE obj)
+fgdbm_keys(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -892,7 +997,8 @@ fgdbm_keys(VALUE obj)
* Returns an array of all values of this database.
*/
static VALUE
-fgdbm_values(VALUE obj)
+fgdbm_values(obj)
+ VALUE obj;
{
datum key, nextkey;
struct dbmdata *dbmp;
@@ -920,15 +1026,16 @@ fgdbm_values(VALUE obj)
* Returns false otherwise.
*/
static VALUE
-fgdbm_has_key(VALUE obj, VALUE keystr)
+fgdbm_has_key(obj, keystr)
+ VALUE obj, keystr;
{
datum key;
struct dbmdata *dbmp;
GDBM_FILE dbm;
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
GetDBM2(obj, dbmp, dbm);
if (gdbm_exists(dbm, key))
@@ -945,7 +1052,8 @@ fgdbm_has_key(VALUE obj, VALUE keystr)
* Returns false otherwise.
*/
static VALUE
-fgdbm_has_value(VALUE obj, VALUE valstr)
+fgdbm_has_value(obj, valstr)
+ VALUE obj, valstr;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -956,13 +1064,13 @@ fgdbm_has_value(VALUE obj, VALUE valstr)
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
- valstr2 = rb_gdbm_fetch2(dbm, keystr);
+ valstr2 = rb_gdbm_fetch2(dbm, keystr);
if (!NIL_P(valstr2) &&
- RSTRING_LEN(valstr) == RSTRING_LEN(valstr2) &&
- memcmp(RSTRING_PTR(valstr), RSTRING_PTR(valstr2),
- RSTRING_LEN(valstr)) == 0) {
- return Qtrue;
+ RSTRING(valstr)->len == RSTRING(valstr2)->len &&
+ memcmp(RSTRING(valstr)->ptr, RSTRING(valstr2)->ptr,
+ RSTRING(valstr)->len) == 0) {
+ return Qtrue;
}
}
return Qfalse;
@@ -975,7 +1083,8 @@ fgdbm_has_value(VALUE obj, VALUE valstr)
* Returns an array of all key-value pairs contained in the database.
*/
static VALUE
-fgdbm_to_a(VALUE obj)
+fgdbm_to_a(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -1001,7 +1110,8 @@ fgdbm_to_a(VALUE obj)
* deletions in the database.
*/
static VALUE
-fgdbm_reorganize(VALUE obj)
+fgdbm_reorganize(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -1023,7 +1133,8 @@ fgdbm_reorganize(VALUE obj)
* to the disk have been finished.
*/
static VALUE
-fgdbm_sync(VALUE obj)
+fgdbm_sync(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -1041,7 +1152,8 @@ fgdbm_sync(VALUE obj)
* Sets the size of the internal bucket cache to _size_.
*/
static VALUE
-fgdbm_set_cachesize(VALUE obj, VALUE val)
+fgdbm_set_cachesize(obj, val)
+ VALUE obj, val;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -1066,7 +1178,8 @@ fgdbm_set_cachesize(VALUE obj, VALUE val)
* default. See also: #syncmode=
*/
static VALUE
-fgdbm_set_fastmode(VALUE obj, VALUE val)
+fgdbm_set_fastmode(obj, val)
+ VALUE obj, val;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -1097,7 +1210,8 @@ fgdbm_set_fastmode(VALUE obj, VALUE val)
* by default. See also: #fastmode=
*/
static VALUE
-fgdbm_set_syncmode(VALUE obj, VALUE val)
+fgdbm_set_syncmode(obj, val)
+ VALUE obj, val;
{
#if !defined(GDBM_SYNCMODE)
fgdbm_set_fastmode(obj, RTEST(val) ? Qfalse : Qtrue);
@@ -1126,7 +1240,8 @@ fgdbm_set_syncmode(VALUE obj, VALUE val)
* Returns a hash of all key-value pairs contained in the database.
*/
static VALUE
-fgdbm_to_hash(VALUE obj)
+fgdbm_to_hash(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
@@ -1151,13 +1266,14 @@ fgdbm_to_hash(VALUE obj)
* which _block_ evaluates to true are removed. See also: #delete_if
*/
static VALUE
-fgdbm_reject(VALUE obj)
+fgdbm_reject(obj)
+ VALUE obj;
{
return rb_hash_delete_if(fgdbm_to_hash(obj));
}
void
-Init_gdbm(void)
+Init_gdbm()
{
rb_cGDBM = rb_define_class("GDBM", rb_cObject);
rb_eGDBMError = rb_define_class("GDBMError", rb_eStandardError);
@@ -1175,7 +1291,9 @@ Init_gdbm(void)
rb_define_method(rb_cGDBM, "[]=", fgdbm_store, 2);
rb_define_method(rb_cGDBM, "store", fgdbm_store, 2);
rb_define_method(rb_cGDBM, "index", fgdbm_index, 1);
- rb_define_method(rb_cGDBM, "select", fgdbm_select, 0);
+ rb_define_method(rb_cGDBM, "indexes", fgdbm_indexes, -1);
+ rb_define_method(rb_cGDBM, "indices", fgdbm_indexes, -1);
+ rb_define_method(rb_cGDBM, "select", fgdbm_select, -1);
rb_define_method(rb_cGDBM, "values_at", fgdbm_values_at, -1);
rb_define_method(rb_cGDBM, "length", fgdbm_length, 0);
rb_define_method(rb_cGDBM, "size", fgdbm_length, 0);
diff --git a/ext/iconv/.cvsignore b/ext/iconv/.cvsignore
index 66c8f5297a..394787fced 100644
--- a/ext/iconv/.cvsignore
+++ b/ext/iconv/.cvsignore
@@ -3,4 +3,3 @@ mkmf.log
*.def
iconv.rb
config.charset
-extconf.h
diff --git a/ext/iconv/charset_alias.rb b/ext/iconv/charset_alias.rb
index d4ed9139c8..aed4644290 100644
--- a/ext/iconv/charset_alias.rb
+++ b/ext/iconv/charset_alias.rb
@@ -6,8 +6,8 @@ require 'optparse'
# http://www.ctan.org/tex-archive/macros/texinfo/texinfo/intl/config.charset
# Fri, 30 May 2003 00:09:00 GMT'
-OS = RbConfig::CONFIG["target_os"]
-SHELL = RbConfig::CONFIG['SHELL']
+OS = Config::CONFIG["target_os"]
+SHELL = Config::CONFIG['SHELL']
class Hash::Ordered < Hash
def [](key)
diff --git a/ext/iconv/extconf.rb b/ext/iconv/extconf.rb
index 6e23396843..a9d0cfb5e6 100644
--- a/ext/iconv/extconf.rb
+++ b/ext/iconv/extconf.rb
@@ -23,7 +23,6 @@ if have_func("iconv", "iconv.h") or
end
$defs.push('-DICONV_INPTR_CONST')
end
- have_func("iconvlist", "iconv.h")
if conf
prefix = '$(srcdir)'
prefix = $nmake ? "{#{prefix}}" : "#{prefix}/"
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 0a5d0dface..4674aa330e 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -83,14 +83,6 @@ struct iconv_env_t
VALUE (*append)_((VALUE, VALUE));
};
-struct rb_iconv_opt_t
-{
- VALUE transliterate;
- VALUE discard_ilseq;
-};
-
-static ID id_transliterate, id_discard_ilseq;
-
static VALUE rb_eIconvInvalidEncoding;
static VALUE rb_eIconvFailure;
static VALUE rb_eIconvIllegalSeq;
@@ -104,21 +96,20 @@ static VALUE iconv_failure_initialize _((VALUE error, VALUE mesg, VALUE success,
static VALUE iconv_failure_success _((VALUE self));
static VALUE iconv_failure_failed _((VALUE self));
-static iconv_t iconv_create _((VALUE to, VALUE from, struct rb_iconv_opt_t *opt));
+static iconv_t iconv_create _((VALUE to, VALUE from));
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, int start, int length, struct iconv_env_t* env));
+static VALUE iconv_convert _((iconv_t cd, VALUE str, long start, long length, struct iconv_env_t* env));
static VALUE iconv_s_allocate _((VALUE klass));
-static VALUE iconv_initialize _((int argc, VALUE *argv, VALUE self));
-static VALUE iconv_s_open _((int argc, VALUE *argv, VALUE self));
+static VALUE iconv_initialize _((VALUE self, VALUE to, VALUE from));
+static VALUE iconv_s_open _((VALUE self, VALUE to, VALUE from));
static VALUE iconv_s_convert _((struct iconv_env_t* env));
static VALUE iconv_s_iconv _((int argc, VALUE *argv, VALUE self));
static VALUE iconv_init_state _((VALUE cd));
static VALUE iconv_finish _((VALUE self));
static VALUE iconv_iconv _((int argc, VALUE *argv, VALUE self));
-static VALUE iconv_conv _((int argc, VALUE *argv, VALUE self));
static VALUE charset_map;
@@ -128,13 +119,19 @@ static VALUE charset_map;
*
* Returns the map from canonical name to system dependent name.
*/
-static VALUE charset_map_get(void)
+static VALUE charset_map_get _((void))
{
return charset_map;
}
static char *
-map_charset(VALUE *code)
+map_charset
+#ifdef HAVE_PROTOTYPES
+ (VALUE *code)
+#else /* HAVE_PROTOTYPES */
+ (code)
+ VALUE *code;
+#endif /* HAVE_PROTOTYPES */
{
VALUE val = *code;
@@ -149,7 +146,14 @@ map_charset(VALUE *code)
}
static iconv_t
-iconv_create(VALUE to, VALUE from, struct rb_iconv_opt_t *opt)
+iconv_create
+#ifdef HAVE_PROTOTYPES
+ (VALUE to, VALUE from)
+#else /* HAVE_PROTOTYPES */
+ (to, from)
+ VALUE to;
+ VALUE from;
+#endif /* HAVE_PROTOTYPES */
{
const char* tocode = map_charset(&to);
const char* fromcode = map_charset(&from);
@@ -167,42 +171,30 @@ iconv_create(VALUE to, VALUE from, struct rb_iconv_opt_t *opt)
if (cd == (iconv_t)-1) {
int inval = errno == EINVAL;
const char *s = inval ? "invalid encoding " : "iconv";
- volatile VALUE msg = rb_str_new(0, strlen(s) + RSTRING_LEN(to) +
- RSTRING_LEN(from) + 8);
+ volatile VALUE msg = rb_str_new(0, strlen(s) + RSTRING(to)->len +
+ RSTRING(from)->len + 8);
- sprintf(RSTRING_PTR(msg), "%s(\"%s\", \"%s\")",
- s, RSTRING_PTR(to), RSTRING_PTR(from));
- s = RSTRING_PTR(msg);
- rb_str_set_len(msg, strlen(s));
+ sprintf(RSTRING(msg)->ptr, "%s(\"%s\", \"%s\")",
+ s, RSTRING(to)->ptr, RSTRING(from)->ptr);
+ s = RSTRING(msg)->ptr;
+ RSTRING(msg)->len = strlen(s);
if (!inval) rb_sys_fail(s);
iconv_fail(rb_eIconvInvalidEncoding,
Qnil, rb_ary_new3(2, to, from), NULL, s);
}
}
- if (opt) {
- int flag;
-#ifdef ICONV_SET_TRANSLITERATE
- if (opt->transliterate != Qundef) {
- flag = RTEST(opt->transliterate);
- if (iconvctl(cd, ICONV_SET_TRANSLITERATE, (void *)&flag))
- rb_sys_fail("ICONV_SET_TRANSLITERATE");
- }
-#endif
-#ifdef ICONV_SET_DISCARD_ILSEQ
- if (opt->discard_ilseq != Qundef) {
- flag = RTEST(opt->discard_ilseq);
- if (iconvctl(cd, ICONV_SET_DISCARD_ILSEQ, (void *)&flag))
- rb_sys_fail("ICONV_SET_DISCARD_ILSEQ");
- }
-#endif
- }
-
return cd;
}
static void
-iconv_dfree(void *cd)
+iconv_dfree
+#ifdef HAVE_PROTOTYPES
+ (void *cd)
+#else /* HAVE_PROTOTYPES */
+ (cd)
+ void *cd;
+#endif /* HAVE_PROTOTYPES */
{
iconv_close(VALUE2ICONV(cd));
}
@@ -210,7 +202,13 @@ iconv_dfree(void *cd)
#define ICONV_FREE iconv_dfree
static VALUE
-iconv_free(VALUE cd)
+iconv_free
+#ifdef HAVE_PROTOTYPES
+ (VALUE cd)
+#else /* HAVE_PROTOTYPES */
+ (cd)
+ VALUE cd;
+#endif /* HAVE_PROTOTYPES */
{
if (cd && iconv_close(VALUE2ICONV(cd)) == -1)
rb_sys_fail("iconv_close");
@@ -218,7 +216,13 @@ iconv_free(VALUE cd)
}
static VALUE
-check_iconv(VALUE obj)
+check_iconv
+#ifdef HAVE_PROTOTYPES
+ (VALUE obj)
+#else /* HAVE_PROTOTYPES */
+ (obj)
+ VALUE obj;
+#endif /* HAVE_PROTOTYPES */
{
Check_Type(obj, T_DATA);
if (RDATA(obj)->dfree != ICONV_FREE) {
@@ -228,7 +232,17 @@ check_iconv(VALUE obj)
}
static VALUE
-iconv_try(iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *outlen)
+iconv_try
+#ifdef HAVE_PROTOTYPES
+ (iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *outlen)
+#else /* HAVE_PROTOTYPES */
+ (cd, inptr, inlen, outptr, outlen)
+ iconv_t cd;
+ const char **inptr;
+ size_t *inlen;
+ char **outptr;
+ size_t *outlen;
+#endif /* HAVE_PROTOTYPES */
{
#ifdef ICONV_INPTR_CONST
#define ICONV_INPTR_CAST
@@ -268,7 +282,13 @@ iconv_try(iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *
#define FAILED_MAXLEN 16
-static VALUE iconv_failure_initialize(VALUE error, VALUE mesg, VALUE success, VALUE failed)
+static VALUE iconv_failure_initialize
+#ifdef HAVE_PROTOTYPES
+ (VALUE error, VALUE mesg, VALUE success, VALUE failed)
+#else /* HAVE_PROTOTYPES */
+ (error, mesg, success, failed)
+ VALUE error, mesg, success, failed;
+#endif /* HAVE_PROTOTYPES */
{
rb_call_super(1, &mesg);
rb_ivar_set(error, rb_success, success);
@@ -277,14 +297,22 @@ static VALUE iconv_failure_initialize(VALUE error, VALUE mesg, VALUE success, VA
}
static VALUE
-iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg)
+iconv_fail
+#ifdef HAVE_PROTOTYPES
+ (VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg)
+#else /* HAVE_PROTOTYPES */
+ (error, success, failed, env, mesg)
+ VALUE error, success, failed;
+ struct iconv_env_t *env;
+ const char *mesg;
+#endif /* HAVE_PROTOTYPES */
{
VALUE args[3];
if (mesg && *mesg) {
args[0] = rb_str_new2(mesg);
}
- else if (TYPE(failed) != T_STRING || RSTRING_LEN(failed) < FAILED_MAXLEN) {
+ else if (TYPE(failed) != T_STRING || RSTRING(failed)->len < FAILED_MAXLEN) {
args[0] = rb_inspect(failed);
}
else {
@@ -307,16 +335,24 @@ iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, co
}
static VALUE
-rb_str_derive(VALUE str, const char* ptr, int len)
+rb_str_derive
+#ifdef HAVE_PROTOTYPES
+ (VALUE str, const char* ptr, int len)
+#else /* HAVE_PROTOTYPES */
+ (str, ptr, len)
+ VALUE str;
+ const char *ptr;
+ int len;
+#endif /* HAVE_PROTOTYPES */
{
VALUE ret;
if (NIL_P(str))
return rb_str_new(ptr, len);
- if (RSTRING_PTR(str) == ptr && RSTRING_LEN(str) == len)
+ if (RSTRING(str)->ptr == ptr && RSTRING(str)->len == len)
return str;
- if (RSTRING_PTR(str) + RSTRING_LEN(str) == ptr + len)
- ret = rb_str_substr(str, ptr - RSTRING_PTR(str), len);
+ if (RSTRING(str)->ptr + RSTRING(str)->len == ptr + len)
+ ret = rb_str_substr(str, ptr - RSTRING(str)->ptr, len);
else
ret = rb_str_new(ptr, len);
OBJ_INFECT(ret, str);
@@ -324,7 +360,17 @@ rb_str_derive(VALUE str, const char* ptr, int len)
}
static VALUE
-iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* env)
+iconv_convert
+#ifdef HAVE_PROTOTYPES
+ (iconv_t cd, VALUE str, long start, long length, struct iconv_env_t* env)
+#else /* HAVE_PROTOTYPES */
+ (cd, str, start, length, env)
+ iconv_t cd;
+ VALUE str;
+ long start;
+ long length;
+ struct iconv_env_t *env;
+#endif /* HAVE_PROTOTYPES */
{
VALUE ret = Qfalse;
VALUE error = Qfalse;
@@ -350,7 +396,7 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t*
unsigned int i;
rescue = iconv_fail(error, Qnil, Qnil, env, 0);
if (TYPE(rescue) == T_ARRAY) {
- str = RARRAY_LEN(rescue) > 0 ? RARRAY_PTR(rescue)[0] : Qnil;
+ str = RARRAY(rescue)->len > 0 ? RARRAY(rescue)->ptr[0] : Qnil;
}
if (FIXNUM_P(str) && (i = FIX2INT(str)) <= 0xff) {
char c = i;
@@ -368,17 +414,12 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t*
int slen;
StringValue(str);
- slen = RSTRING_LEN(str);
- inptr = RSTRING_PTR(str);
-
- 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;
+ slen = RSTRING(str)->len;
+ inptr = RSTRING(str)->ptr;
+
+ inptr += start;
+ if (length < 0 || length > start + slen)
+ length = slen - start;
}
instart = inptr;
inlen = length;
@@ -434,12 +475,12 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t*
str = rb_str_derive(str, inptr, inlen);
rescue = iconv_fail(error, ret, str, env, errmsg);
if (TYPE(rescue) == T_ARRAY) {
- if ((len = RARRAY_LEN(rescue)) > 0)
- rb_str_concat(ret, RARRAY_PTR(rescue)[0]);
- if (len > 1 && !NIL_P(str = RARRAY_PTR(rescue)[1])) {
+ if ((len = RARRAY(rescue)->len) > 0)
+ rb_str_concat(ret, RARRAY(rescue)->ptr[0]);
+ if (len > 1 && !NIL_P(str = RARRAY(rescue)->ptr[1])) {
StringValue(str);
- inlen = length = RSTRING_LEN(str);
- instart = inptr = RSTRING_PTR(str);
+ inlen = length = RSTRING(str)->len;
+ instart = inptr = RSTRING(str)->ptr;
continue;
}
}
@@ -458,81 +499,20 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t*
}
static VALUE
-iconv_s_allocate(VALUE klass)
+iconv_s_allocate
+#ifdef HAVE_PROTOTYPES
+ (VALUE klass)
+#else /* HAVE_PROTOTYPES */
+ (klass)
+ VALUE klass;
+#endif /* HAVE_PROTOTYPES */
{
return Data_Wrap_Struct(klass, 0, ICONV_FREE, 0);
}
-static VALUE
-get_iconv_opt_i(VALUE i, VALUE arg)
-{
- struct rb_iconv_opt_t *opt = (struct rb_iconv_opt_t *)arg;
- VALUE name, val;
- i = rb_Array(i);
- name = rb_ary_entry(i, 0);
- val = rb_ary_entry(i, 1);
- do {
- if (SYMBOL_P(name)) {
- ID id = SYM2ID(name);
- if (id == id_transliterate) {
-#ifdef ICONV_SET_TRANSLITERATE
- opt->transliterate = val;
-#else
- rb_notimplement();
-#endif
- break;
- }
- if (id == id_discard_ilseq) {
-#ifdef ICONV_SET_DISCARD_ILSEQ
- opt->discard_ilseq = val;
-#else
- rb_notimplement();
-#endif
- break;
- }
- }
- else {
- const char *s = StringValueCStr(name);
- if (strcmp(s, "transliterate") == 0) {
-#ifdef ICONV_SET_TRANSLITERATE
- opt->transliterate = val;
-#else
- rb_notimplement();
-#endif
- break;
- }
- if (strcmp(s, "discard_ilseq") == 0) {
-#ifdef ICONV_SET_DISCARD_ILSEQ
- opt->discard_ilseq = val;
-#else
- rb_notimplement();
-#endif
- break;
- }
- }
- name = rb_inspect(name);
- rb_raise(rb_eArgError, "unknown option - %s", StringValueCStr(name));
- } while (0);
- return Qnil;
-}
-
-static void
-get_iconv_opt(struct rb_iconv_opt_t *opt, VALUE options)
-{
- opt->transliterate = Qundef;
- opt->discard_ilseq = Qundef;
- if (!NIL_P(options)) {
- rb_block_call(options, rb_intern("each"), 0, 0, get_iconv_opt_i, (VALUE)opt);
- }
-}
-
-#define iconv_ctl(self, func, val) (\
- iconvctl(VALUE2ICONV(check_iconv(self)), func, (void *)&(val)) ? \
- rb_sys_fail(#func) : (void)0)
-
/*
* Document-method: new
- * call-seq: Iconv.new(to, from, [options])
+ * call-seq: Iconv.new(to, from)
*
* Creates new code converter from a coding-system designated with +from+
* to another one designated with +to+.
@@ -541,7 +521,6 @@ get_iconv_opt(struct rb_iconv_opt_t *opt, VALUE options)
*
* +to+:: encoding name for destination
* +from+:: encoding name for source
- * +options+:: options for converter
*
* === Exceptions
*
@@ -550,16 +529,19 @@ get_iconv_opt(struct rb_iconv_opt_t *opt, VALUE options)
* SystemCallError:: if <tt>iconv_open(3)</tt> fails
*/
static VALUE
-iconv_initialize(int argc, VALUE *argv, VALUE self)
+iconv_initialize
+#ifdef HAVE_PROTOTYPES
+ (VALUE self, VALUE to, VALUE from)
+#else /* HAVE_PROTOTYPES */
+ (self, to, from)
+ VALUE self;
+ VALUE to;
+ VALUE from;
+#endif /* HAVE_PROTOTYPES */
{
- VALUE to, from, options;
- struct rb_iconv_opt_t opt;
-
- rb_scan_args(argc, argv, "21", &to, &from, &options);
- get_iconv_opt(&opt, options);
iconv_free(check_iconv(self));
DATA_PTR(self) = NULL;
- DATA_PTR(self) = (void *)ICONV2VALUE(iconv_create(to, from, &opt));
+ DATA_PTR(self) = (void *)ICONV2VALUE(iconv_create(to, from));
return self;
}
@@ -572,14 +554,17 @@ iconv_initialize(int argc, VALUE *argv, VALUE self)
* returned from the block.
*/
static VALUE
-iconv_s_open(int argc, VALUE *argv, VALUE self)
-{
- VALUE to, from, options, cd;
- struct rb_iconv_opt_t opt;
-
- rb_scan_args(argc, argv, "21", &to, &from, &options);
- get_iconv_opt(&opt, options);
- cd = ICONV2VALUE(iconv_create(to, from, &opt));
+iconv_s_open
+#ifdef HAVE_PROTOTYPES
+ (VALUE self, VALUE to, VALUE from)
+#else /* HAVE_PROTOTYPES */
+ (self, to, from)
+ VALUE self;
+ VALUE to;
+ VALUE from;
+#endif /* HAVE_PROTOTYPES */
+{
+ VALUE cd = ICONV2VALUE(iconv_create(to, from));
self = Data_Wrap_Struct(self, NULL, ICONV_FREE, (void *)cd);
if (rb_block_given_p()) {
@@ -591,7 +576,13 @@ iconv_s_open(int argc, VALUE *argv, VALUE self)
}
static VALUE
-iconv_s_convert(struct iconv_env_t* env)
+iconv_s_convert
+#ifdef HAVE_PROTOTYPES
+ (struct iconv_env_t* env)
+#else /* HAVE_PROTOTYPES */
+ (env)
+ struct iconv_env_t *env;
+#endif /* HAVE_PROTOTYPES */
{
VALUE last = 0;
@@ -602,7 +593,7 @@ iconv_s_convert(struct iconv_env_t* env)
if (!NIL_P(last)) {
VALUE s = iconv_convert(env->cd, Qnil, 0, 0, env);
- if (RSTRING_LEN(s))
+ if (RSTRING(s)->len)
env->append(env->ret, s);
}
@@ -628,7 +619,15 @@ iconv_s_convert(struct iconv_env_t* env)
* Exceptions thrown by Iconv.new, Iconv.open and Iconv#iconv.
*/
static VALUE
-iconv_s_iconv(int argc, VALUE *argv, VALUE self)
+iconv_s_iconv
+#ifdef HAVE_PROTOTYPES
+ (int argc, VALUE *argv, VALUE self)
+#else /* HAVE_PROTOTYPES */
+ (argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+#endif /* HAVE_PROTOTYPES */
{
struct iconv_env_t arg;
@@ -639,20 +638,26 @@ iconv_s_iconv(int argc, VALUE *argv, VALUE self)
arg.argv = argv + 2;
arg.append = rb_ary_push;
arg.ret = rb_ary_new2(argc);
- arg.cd = iconv_create(argv[0], argv[1], NULL);
+ arg.cd = iconv_create(argv[0], argv[1]);
return rb_ensure(iconv_s_convert, (VALUE)&arg, iconv_free, ICONV2VALUE(arg.cd));
}
/*
* Document-method: Iconv::conv
- * call-seq: Iconv.iconv(to, from, *strs)
+ * call-seq: Iconv.conv(to, from, str)
*
* Shorthand for
* Iconv.iconv(to, from, str).join
* See Iconv.iconv.
*/
static VALUE
-iconv_s_conv(VALUE self, VALUE to, VALUE from, VALUE str)
+iconv_s_conv
+#ifdef HAVE_PROTOTYPES
+ (VALUE self, VALUE to, VALUE from, VALUE str)
+#else /* HAVE_PROTOTYPES */
+ (self, to, from, str)
+ VALUE self, to, from, str;
+#endif /* HAVE_PROTOTYPES */
{
struct iconv_env_t arg;
@@ -660,75 +665,11 @@ iconv_s_conv(VALUE self, VALUE to, VALUE from, VALUE str)
arg.argv = &str;
arg.append = rb_str_append;
arg.ret = rb_str_new(0, 0);
- arg.cd = iconv_create(to, from, NULL);
+ arg.cd = iconv_create(to, from);
return rb_ensure(iconv_s_convert, (VALUE)&arg, iconv_free, ICONV2VALUE(arg.cd));
}
/*
- * Document-method: list
- * call-seq: Iconv.list {|*aliases| ... }
- *
- * Iterates each alias sets.
- */
-
-#ifdef HAVE_ICONVLIST
-struct iconv_name_list
-{
- unsigned int namescount;
- const char *const *names;
- VALUE array;
-};
-
-static VALUE
-list_iconv_i(VALUE ptr)
-{
- struct iconv_name_list *p = (struct iconv_name_list *)ptr;
- unsigned int i, namescount = p->namescount;
- const char *const *names = p->names;
- VALUE ary = rb_ary_new2(namescount);
-
- for (i = 0; i < namescount; i++) {
- rb_ary_push(ary, rb_str_new2(names[i]));
- }
- if (p->array) {
- return rb_ary_push(p->array, ary);
- }
- return rb_yield(ary);
-}
-
-static int
-list_iconv(unsigned int namescount, const char *const *names, void *data)
-{
- int *state = data;
- struct iconv_name_list list;
-
- list.namescount = namescount;
- list.names = names;
- list.array = ((VALUE *)data)[1];
- rb_protect(list_iconv_i, (VALUE)&list, state);
- return *state;
-}
-#endif
-
-static VALUE
-iconv_s_list(void)
-{
-#ifdef HAVE_ICONVLIST
- int state;
- VALUE args[2];
-
- args[1] = rb_block_given_p() ? 0 : rb_ary_new();
- iconvlist(list_iconv, args);
- state = *(int *)args;
- if (state) rb_jump_tag(state);
- if (args[1]) return args[1];
-#else
- rb_notimplement();
-#endif
- return Qnil;
-}
-
-/*
* Document-method: close
*
* Finishes conversion.
@@ -740,13 +681,25 @@ iconv_s_list(void)
* its initial shift state.
*/
static VALUE
-iconv_init_state(VALUE cd)
+iconv_init_state
+#ifdef HAVE_PROTOTYPES
+ (VALUE cd)
+#else /* HAVE_PROTOTYPES */
+ (cd)
+ VALUE cd;
+#endif /* HAVE_PROTOTYPES */
{
return iconv_convert(VALUE2ICONV(cd), Qnil, 0, 0, NULL);
}
static VALUE
-iconv_finish(VALUE self)
+iconv_finish
+#ifdef HAVE_PROTOTYPES
+ (VALUE self)
+#else /* HAVE_PROTOTYPES */
+ (self)
+ VALUE self;
+#endif /* HAVE_PROTOTYPES */
{
VALUE cd = check_iconv(self);
@@ -784,172 +737,34 @@ iconv_finish(VALUE self)
* See the Iconv documentation.
*/
static VALUE
-iconv_iconv(int argc, VALUE *argv, VALUE self)
+iconv_iconv
+#ifdef HAVE_PROTOTYPES
+ (int argc, VALUE *argv, VALUE self)
+#else /* HAVE_PROTOTYPES */
+ (argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+#endif /* HAVE_PROTOTYPES */
{
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);
-
- return iconv_convert(VALUE2ICONV(cd), str,
- NIL_P(n1) ? 0 : NUM2INT(n1),
- NIL_P(n2) ? -1 : NUM2INT(n2),
- NULL);
-}
-
-/*
- * Document-method: conv
- * call-seq: conv(str...)
- *
- * Equivalent to
- *
- * iconv(nil, str..., nil).join
- */
-static VALUE
-iconv_conv(int argc, VALUE *argv, VALUE self)
-{
- iconv_t cd = VALUE2ICONV(check_iconv(self));
- VALUE str, s;
-
- str = iconv_convert(cd, Qnil, 0, 0, NULL);
- if (argc > 0) {
- do {
- s = iconv_convert(cd, *argv++, 0, -1, NULL);
- if (RSTRING_LEN(s))
- rb_str_buf_append(str, s);
- else
- str = s;
- } while (--argc);
- s = iconv_convert(cd, Qnil, 0, 0, NULL);
- if (RSTRING_LEN(s))
- rb_str_buf_append(str, s);
- else
- str = s;
+ 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 str;
-}
-
-/*
- * Document-method: trivial?
- * call-seq: trivial?
- *
- * Returns trivial flag.
- */
-static VALUE
-iconv_trivialp(VALUE self)
-{
-#ifdef ICONV_TRIVIALP
- int trivial = 0;
- iconv_ctl(self, ICONV_TRIVIALP, trivial);
- if (trivial) return Qtrue;
-#else
- rb_notimplement();
-#endif
- return Qfalse;
-}
-
-/*
- * Document-method: transliterate?
- * call-seq: transliterate?
- *
- * Returns transliterate flag.
- */
-static VALUE
-iconv_get_transliterate(VALUE self)
-{
-#ifdef ICONV_GET_TRANSLITERATE
- int trans = 0;
- iconv_ctl(self, ICONV_GET_TRANSLITERATE, trans);
- if (trans) return Qtrue;
-#else
- rb_notimplement();
-#endif
- return Qfalse;
-}
-
-/*
- * Document-method: transliterate=
- * call-seq: cd.transliterate = flag
- *
- * Sets transliterate flag.
- */
-static VALUE
-iconv_set_transliterate(VALUE self, VALUE transliterate)
-{
-#ifdef ICONV_SET_TRANSLITERATE
- int trans = RTEST(transliterate);
- iconv_ctl(self, ICONV_SET_TRANSLITERATE, trans);
-#else
- rb_notimplement();
-#endif
- return self;
-}
-
-/*
- * Document-method: discard_ilseq?
- * call-seq: discard_ilseq?
- *
- * Returns discard_ilseq flag.
- */
-static VALUE
-iconv_get_discard_ilseq(VALUE self)
-{
-#ifdef ICONV_GET_DISCARD_ILSEQ
- int dis = 0;
- iconv_ctl(self, ICONV_GET_DISCARD_ILSEQ, dis);
- if (dis) return Qtrue;
-#else
- rb_notimplement();
-#endif
- return Qfalse;
-}
-
-/*
- * Document-method: discard_ilseq=
- * call-seq: cd.discard_ilseq = flag
- *
- * Sets discard_ilseq flag.
- */
-static VALUE
-iconv_set_discard_ilseq(VALUE self, VALUE discard_ilseq)
-{
-#ifdef ICONV_SET_DISCARD_ILSEQ
- int dis = RTEST(discard_ilseq);
- iconv_ctl(self, ICONV_SET_DISCARD_ILSEQ, dis);
-#else
- rb_notimplement();
-#endif
- return self;
-}
-
-/*
- * Document-method: ctlmethods
- * call-seq: Iconv.ctlmethods => array
- *
- * Returns available iconvctl() method list.
- */
-static VALUE
-iconv_s_ctlmethods(VALUE klass)
-{
- VALUE ary = rb_ary_new();
-#ifdef ICONV_TRIVIALP
- rb_ary_push(ary, ID2SYM(rb_intern("trivial?")));
-#endif
-#ifdef ICONV_GET_TRANSLITERATE
- rb_ary_push(ary, ID2SYM(rb_intern("transliterate?")));
-#endif
-#ifdef ICONV_SET_TRANSLITERATE
- rb_ary_push(ary, ID2SYM(rb_intern("transliterate=")));
-#endif
-#ifdef ICONV_GET_DISCARD_ILSEQ
- rb_ary_push(ary, ID2SYM(rb_intern("discard_ilseq?")));
-#endif
-#ifdef ICONV_SET_DISCARD_ILSEQ
- rb_ary_push(ary, ID2SYM(rb_intern("discard_ilseq=")));
-#endif
- return ary;
+ return iconv_convert(VALUE2ICONV(cd), str, start, length, NULL);
}
/*
@@ -968,7 +783,13 @@ iconv_s_ctlmethods(VALUE klass)
* failure and the last element is string on the way.
*/
static VALUE
-iconv_failure_success(VALUE self)
+iconv_failure_success
+#ifdef HAVE_PROTOTYPES
+(VALUE self)
+#else /* HAVE_PROTOTYPES */
+ (self)
+ VALUE self;
+#endif /* HAVE_PROTOTYPES */
{
return rb_attr_get(self, rb_success);
}
@@ -981,7 +802,13 @@ iconv_failure_success(VALUE self)
* character caused the exception.
*/
static VALUE
-iconv_failure_failed(VALUE self)
+iconv_failure_failed
+#ifdef HAVE_PROTOTYPES
+(VALUE self)
+#else /* HAVE_PROTOTYPES */
+ (self)
+ VALUE self;
+#endif /* HAVE_PROTOTYPES */
{
return rb_attr_get(self, rb_failed);
}
@@ -993,9 +820,15 @@ iconv_failure_failed(VALUE self)
* Returns inspected string like as: #<_class_: _success_, _failed_>
*/
static VALUE
-iconv_failure_inspect(VALUE self)
-{
- char *cname = rb_class2name(CLASS_OF(self));
+iconv_failure_inspect
+#ifdef HAVE_PROTOTYPES
+ (VALUE self)
+#else /* HAVE_PROTOTYPES */
+ (self)
+ VALUE self;
+#endif /* HAVE_PROTOTYPES */
+{
+ const 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);
@@ -1041,25 +874,17 @@ iconv_failure_inspect(VALUE self)
*/
void
-Init_iconv(void)
+Init_iconv _((void))
{
VALUE rb_cIconv = rb_define_class("Iconv", rb_cData);
rb_define_alloc_func(rb_cIconv, iconv_s_allocate);
- rb_define_singleton_method(rb_cIconv, "open", iconv_s_open, -1);
+ rb_define_singleton_method(rb_cIconv, "open", iconv_s_open, 2);
rb_define_singleton_method(rb_cIconv, "iconv", iconv_s_iconv, -1);
rb_define_singleton_method(rb_cIconv, "conv", iconv_s_conv, 3);
- rb_define_singleton_method(rb_cIconv, "list", iconv_s_list, 0);
- rb_define_singleton_method(rb_cIconv, "ctlmethods", iconv_s_ctlmethods, 0);
- rb_define_method(rb_cIconv, "initialize", iconv_initialize, -1);
+ rb_define_method(rb_cIconv, "initialize", iconv_initialize, 2);
rb_define_method(rb_cIconv, "close", iconv_finish, 0);
rb_define_method(rb_cIconv, "iconv", iconv_iconv, -1);
- rb_define_method(rb_cIconv, "conv", iconv_conv, -1);
- rb_define_method(rb_cIconv, "trivial?", iconv_trivialp, 0);
- rb_define_method(rb_cIconv, "transliterate?", iconv_get_transliterate, 0);
- rb_define_method(rb_cIconv, "transliterate=", iconv_set_transliterate, 1);
- rb_define_method(rb_cIconv, "discard_ilseq?", iconv_get_discard_ilseq, 0);
- rb_define_method(rb_cIconv, "discard_ilseq=", iconv_set_discard_ilseq, 1);
rb_eIconvFailure = rb_define_module_under(rb_cIconv, "Failure");
rb_define_method(rb_eIconvFailure, "initialize", iconv_failure_initialize, 3);
@@ -1080,8 +905,6 @@ Init_iconv(void)
rb_success = rb_intern("success");
rb_failed = rb_intern("failed");
- id_transliterate = rb_intern("transliterate");
- id_discard_ilseq = rb_intern("discard_ilseq");
rb_gc_register_address(&charset_map);
charset_map = rb_hash_new();
diff --git a/ext/iconv/mkwrapper.rb b/ext/iconv/mkwrapper.rb
deleted file mode 100644
index 34718507d6..0000000000
--- a/ext/iconv/mkwrapper.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-#! /usr/bin/ruby
-require 'rbconfig'
-require 'optparse'
-
-# http://www.ctan.org/tex-archive/macros/texinfo/texinfo/intl/config.charset
-# Fri, 30 May 2003 00:09:00 GMT'
-
-HEADER = <<SRC
-require 'iconv.so'
-
-class Iconv
- case RUBY_PLATFORM
-SRC
-
-def charset_alias(config_charset, mapfile = nil)
- found = nil
- src = [HEADER]
- open(config_charset) do |input|
- input.find {|line| /^case "\$os" in/ =~ line} or return
- input.each do |line|
- case line
- when /^\s*([-\w\*]+(?:\s*\|\s*[-\w\*]+)*)(?=\))/
- (s = " when ") << $&.split('|').collect {|targ|
- targ.strip!
- tail = targ.chomp!("*") ? '' : '\z'
- head = targ.slice!(/\A\*/) ? '' : '\A'
- targ.gsub!(/\*/, '.*')
- "/#{head}#{targ}#{tail}/"
- }.join(", ")
- src << s
- found = {}
- when /^\s*echo "(?:\$\w+\.)?([-\w*]+)\s+([-\w]+)"/
- sys, can = $1, $2
- can.downcase!
- unless found[can] or (/\Aen_(?!US\z)/ =~ sys && /\ACP437\z/i =~ can)
- found[can] = true
- src << " charset_map['#{can}'] = '#{sys}'.freeze"
- end
- when /^\s*;;/
- found = nil
- end
- end
- end
- src << " end" << "end"
- if mapfile
- open(mapfile, "wb") {|f| f.puts *src}
- else
- puts *src
- end
-end
-
-(1..2) === ARGV.size or abort "usage: #{$0} config_charset [mapfile]"
-charset_alias(*ARGV)
diff --git a/ext/io/wait/.cvsignore b/ext/io/wait/.cvsignore
index 8767482975..fc802ff1c2 100644
--- a/ext/io/wait/.cvsignore
+++ b/ext/io/wait/.cvsignore
@@ -1,3 +1,2 @@
Makefile
mkmf.log
-extconf.h
diff --git a/ext/io/wait/wait.c b/ext/io/wait/wait.c
index ce2841d410..61d6527b36 100644
--- a/ext/io/wait/wait.c
+++ b/ext/io/wait/wait.c
@@ -41,96 +41,83 @@ void Init_wait _((void));
EXTERN struct timeval rb_time_interval _((VALUE time));
/*
- * call-seq:
- * io.ready? -> true, false or nil
- *
- * Returns non-nil if input available without blocking, or nil.
+=begin
+= IO wait methods.
+=end
*/
+/*
+=begin
+--- IO#ready?
+ returns non-nil if input available without blocking, or nil.
+=end
+*/
static VALUE
-io_ready_p(VALUE io)
+io_ready_p(io)
+ VALUE io;
{
OpenFile *fptr;
+ FILE *fp;
ioctl_arg n;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
- if (rb_io_read_pending(fptr)) return Qtrue;
- if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
- if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
+ if (!FIONREAD_POSSIBLE_P(fileno(fptr->f))) return Qfalse;
+ fp = fptr->f;
+ if (feof(fp)) return Qfalse;
+ if (rb_read_pending(fp)) return Qtrue;
+ if (ioctl(fileno(fp), FIONREAD, &n)) rb_sys_fail(0);
if (n > 0) return ioctl_arg2num(n);
return Qnil;
}
-struct wait_readable_arg {
- rb_fdset_t fds;
- struct timeval *timeout;
-};
-
-#ifdef HAVE_RB_FD_INIT
-static VALUE
-wait_readable(VALUE p)
-{
- struct wait_readable_arg *arg = (struct wait_readable_arg *)p;
- rb_fdset_t *fds = &arg->fds;
-
- return (VALUE)rb_thread_select(rb_fd_max(fds), rb_fd_ptr(fds), NULL, NULL, arg->timeout);
-}
-#endif
-
/*
- * call-seq:
- * io.wait -> IO, true, false or nil
- * io.wait(timeout) -> IO, true, false or nil
- *
- * Waits until input is available or times out and returns self or nil when
- * EOF is reached.
- */
-
+=begin
+--- IO#wait([timeout])
+ waits until input available or timed out and returns self, or nil
+ when EOF reached.
+=end
+*/
static VALUE
-io_wait(int argc, VALUE *argv, VALUE io)
+io_wait(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
OpenFile *fptr;
- struct wait_readable_arg arg;
- int fd, i;
+ fd_set rd;
+ FILE *fp;
+ int fd;
ioctl_arg n;
VALUE timeout;
- struct timeval timerec;
+ struct timeval *tp, timerec;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
rb_scan_args(argc, argv, "01", &timeout);
if (NIL_P(timeout)) {
- arg.timeout = 0;
+ tp = 0;
}
else {
timerec = rb_time_interval(timeout);
- arg.timeout = &timerec;
+ tp = &timerec;
}
- if (rb_io_read_pending(fptr)) return Qtrue;
- if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
- fd = fptr->fd;
- rb_fd_init(&arg.fds);
- rb_fd_set(fd, &arg.fds);
-#ifdef HAVE_RB_FD_INIT
- i = (int)rb_ensure(wait_readable, (VALUE)&arg,
- (VALUE (*)_((VALUE)))rb_fd_term, (VALUE)&arg.fds);
-#else
- i = rb_thread_select(fd + 1, rb_fd_ptr(&arg.fds), NULL, NULL, arg.timeout);
-#endif
- if (i < 0)
+ fp = fptr->f;
+ if (feof(fp)) return Qfalse;
+ if (rb_read_pending(fp)) return Qtrue;
+ fd = fileno(fp);
+ FD_ZERO(&rd);
+ FD_SET(fd, &rd);
+ if (rb_thread_select(fd + 1, &rd, NULL, NULL, tp) < 0)
rb_sys_fail(0);
rb_io_check_closed(fptr);
- if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
+ if (!FIONREAD_POSSIBLE_P(fileno(fptr->f))) return Qfalse;
+ if (ioctl(fileno(fp), FIONREAD, &n)) rb_sys_fail(0);
if (n > 0) return io;
return Qnil;
}
-/*
- * IO wait methods
- */
-
void
Init_wait()
{
diff --git a/ext/nkf/.cvsignore b/ext/nkf/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/nkf/.cvsignore
+++ b/ext/nkf/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/nkf/lib/kconv.rb b/ext/nkf/lib/kconv.rb
index 91553228fe..4ffe8d984e 100644
--- a/ext/nkf/lib/kconv.rb
+++ b/ext/nkf/lib/kconv.rb
@@ -105,8 +105,6 @@ module Kconv
opt << 'W'
when ::NKF::UTF16
opt << 'W16'
- when ::NKF::UTF32
- opt << 'W32'
end
case out_code
@@ -120,8 +118,6 @@ module Kconv
opt << 'w'
when ::NKF::UTF16
opt << 'w16'
- when ::NKF::UTF32
- opt << 'w32'
when ::NKF::NOCONV
return str
end
@@ -206,20 +202,6 @@ module Kconv
end
module_function :toutf16
- # call-seq:
- # Kconv.toutf32(str) -> string
- #
- # Convert <code>str</code> to UTF-32
- #
- # *Note*
- # This method decode MIME encoded string and
- # convert halfwidth katakana to fullwidth katakana.
- # If you don't want it, use NKF.nkf('-w32xm0', str).
- def toutf32(str)
- ::NKF::nkf('-w32m', str)
- end
- module_function :toutf32
-
#
# guess
#
@@ -355,17 +337,6 @@ class String
# If you don't want it, use NKF.nkf('-w16xm0', str).
def toutf16; Kconv.toutf16(self) end
- # call-seq:
- # String#toutf32 -> string
- #
- # Convert <code>self</code> to UTF-32
- #
- # *Note*
- # This method decode MIME encoded string and
- # convert halfwidth katakana to fullwidth katakana.
- # If you don't want it, use NKF.nkf('-w32xm0', str).
- def toutf32; Kconv.toutf32(self) end
-
#
# is Encoding
#
diff --git a/ext/nkf/nkf-utf8/nkf.c b/ext/nkf/nkf-utf8/nkf.c
index bd2e90c77c..3cd1b160da 100644
--- a/ext/nkf/nkf-utf8/nkf.c
+++ b/ext/nkf/nkf-utf8/nkf.c
@@ -41,7 +41,7 @@
***********************************************************************/
/* $Id$ */
#define NKF_VERSION "2.0.8"
-#define NKF_RELEASE_DATE "2006-09-15"
+#define NKF_RELEASE_DATE "2007-01-28"
#include "config.h"
#include "utf8tbl.h"
@@ -548,7 +548,7 @@ static int exec_f = 0;
#ifdef SHIFTJIS_CP932
/* invert IBM extended characters to others */
-static int cp51932_f = TRUE;
+static int cp51932_f = FALSE;
/* invert NEC-selected IBM extended characters to IBM extended characters */
static int cp932inv_f = TRUE;
@@ -854,6 +854,7 @@ int main(int argc, char **argv)
}
} else {
int nfiles = argc;
+ int is_argument_error = FALSE;
while (argc--) {
is_inputcode_mixed = FALSE;
is_inputcode_set = FALSE;
@@ -863,7 +864,9 @@ int main(int argc, char **argv)
#endif
if ((fin = fopen((origfname = *argv++), "r")) == NULL) {
perror(*--argv);
- return(-1);
+ *argv++;
+ is_argument_error = TRUE;
+ continue;
} else {
#ifdef OVERWRITE
int fd = 0;
@@ -1011,6 +1014,8 @@ int main(int argc, char **argv)
#endif
}
}
+ if (is_argument_error)
+ return(-1);
}
#ifdef EASYWIN /*Easy Win */
if (file_out_f == FALSE)
@@ -1191,13 +1196,19 @@ void options(unsigned char *cp)
codeset[i] = nkf_toupper(p[i]);
}
codeset[i] = 0;
- if(strcmp(codeset, "ISO-2022-JP") == 0 ||
- strcmp(codeset, "X-ISO2022JP-CP932") == 0 ||
+ if(strcmp(codeset, "ISO-2022-JP") == 0){
+ input_f = JIS_INPUT;
+ }else if(strcmp(codeset, "X-ISO2022JP-CP932") == 0 ||
strcmp(codeset, "CP50220") == 0 ||
strcmp(codeset, "CP50221") == 0 ||
- strcmp(codeset, "CP50222") == 0 ||
- strcmp(codeset, "ISO-2022-JP-MS") == 0){
+ strcmp(codeset, "CP50222") == 0){
input_f = JIS_INPUT;
+#ifdef SHIFTJIS_CP932
+ cp51932_f = TRUE;
+#endif
+#ifdef UTF8_OUTPUT_ENABLE
+ ms_ucs_map_f = UCS_MAP_CP932;
+#endif
}else if(strcmp(codeset, "ISO-2022-JP-1") == 0){
input_f = JIS_INPUT;
#ifdef X0212_ENABLE
@@ -1211,13 +1222,11 @@ void options(unsigned char *cp)
x0213_f = TRUE;
}else if(strcmp(codeset, "SHIFT_JIS") == 0){
input_f = SJIS_INPUT;
- if (x0201_f==NO_X0201) x0201_f=TRUE;
}else if(strcmp(codeset, "WINDOWS-31J") == 0 ||
strcmp(codeset, "CSWINDOWS31J") == 0 ||
strcmp(codeset, "CP932") == 0 ||
strcmp(codeset, "MS932") == 0){
input_f = SJIS_INPUT;
- x0201_f = FALSE;
#ifdef SHIFTJIS_CP932
cp51932_f = TRUE;
#endif
@@ -1229,7 +1238,6 @@ void options(unsigned char *cp)
input_f = EUC_INPUT;
}else if(strcmp(codeset, "CP51932") == 0){
input_f = EUC_INPUT;
- x0201_f = FALSE;
#ifdef SHIFTJIS_CP932
cp51932_f = TRUE;
#endif
@@ -1240,7 +1248,6 @@ void options(unsigned char *cp)
strcmp(codeset, "EUCJP-MS") == 0 ||
strcmp(codeset, "EUCJPMS") == 0){
input_f = EUC_INPUT;
- x0201_f = FALSE;
#ifdef SHIFTJIS_CP932
cp51932_f = FALSE;
#endif
@@ -1250,7 +1257,6 @@ void options(unsigned char *cp)
}else if(strcmp(codeset, "EUC-JP-ASCII") == 0 ||
strcmp(codeset, "EUCJP-ASCII") == 0){
input_f = EUC_INPUT;
- x0201_f = FALSE;
#ifdef SHIFTJIS_CP932
cp51932_f = FALSE;
#endif
@@ -1263,17 +1269,13 @@ void options(unsigned char *cp)
x0213_f = TRUE;
#ifdef SHIFTJIS_CP932
cp51932_f = FALSE;
- cp932inv_f = FALSE;
#endif
- if (x0201_f==NO_X0201) x0201_f=TRUE;
}else if(strcmp(codeset, "EUC-JISX0213") == 0 ||
strcmp(codeset, "EUC-JIS-2004") == 0){
input_f = EUC_INPUT;
- x0201_f = FALSE;
x0213_f = TRUE;
#ifdef SHIFTJIS_CP932
cp51932_f = FALSE;
- cp932inv_f = FALSE;
#endif
#ifdef UTF8_INPUT_ENABLE
}else if(strcmp(codeset, "UTF-8") == 0 ||
@@ -1309,45 +1311,55 @@ void options(unsigned char *cp)
continue;
}
if (strcmp(long_option[i].name, "oc=") == 0){
+ x0201_f = FALSE;
for (i=0; i < 16 && SPACE < p[i] && p[i] < DEL; i++){
codeset[i] = nkf_toupper(p[i]);
}
codeset[i] = 0;
- if(strcmp(codeset, "ISO-2022-JP") == 0 ||
- strcmp(codeset, "CP50220") == 0){
+ if(strcmp(codeset, "ISO-2022-JP") == 0){
output_conv = j_oconv;
}else if(strcmp(codeset, "X-ISO2022JP-CP932") == 0){
output_conv = j_oconv;
no_cp932ext_f = TRUE;
- }else if(strcmp(codeset, "CP50221") == 0 ||
- strcmp(codeset, "ISO-2022-JP-MS") == 0){
- output_conv = j_oconv;
- x0201_f = FALSE;
- }else if(strcmp(codeset, "ISO-2022-JP-1") == 0){
+#ifdef SHIFTJIS_CP932
+ cp932inv_f = FALSE;
+#endif
+#ifdef UTF8_OUTPUT_ENABLE
+ ms_ucs_map_f = UCS_MAP_CP932;
+#endif
+ }else if(strcmp(codeset, "CP50220") == 0){
output_conv = j_oconv;
-#ifdef X0212_ENABLE
- x0212_f = TRUE;
+ x0201_f = TRUE;
+#ifdef SHIFTJIS_CP932
+ cp932inv_f = FALSE;
+#endif
+#ifdef UTF8_OUTPUT_ENABLE
+ ms_ucs_map_f = UCS_MAP_CP932;
#endif
+ }else if(strcmp(codeset, "CP50221") == 0){
+ output_conv = j_oconv;
#ifdef SHIFTJIS_CP932
- cp51932_f = FALSE;
+ cp932inv_f = FALSE;
#endif
- }else if(strcmp(codeset, "ISO-2022-JP-3") == 0){
+#ifdef UTF8_OUTPUT_ENABLE
+ ms_ucs_map_f = UCS_MAP_CP932;
+#endif
+ }else if(strcmp(codeset, "ISO-2022-JP-1") == 0){
output_conv = j_oconv;
#ifdef X0212_ENABLE
x0212_f = TRUE;
#endif
- x0213_f = TRUE;
#ifdef SHIFTJIS_CP932
- cp51932_f = FALSE;
+ cp932inv_f = FALSE;
#endif
- }else if(strcmp(codeset, "ISO-2022-JP-MS") == 0){
+ }else if(strcmp(codeset, "ISO-2022-JP-3") == 0){
output_conv = j_oconv;
- x0201_f = FALSE;
#ifdef X0212_ENABLE
x0212_f = TRUE;
#endif
+ x0213_f = TRUE;
#ifdef SHIFTJIS_CP932
- cp51932_f = FALSE;
+ cp932inv_f = FALSE;
#endif
}else if(strcmp(codeset, "SHIFT_JIS") == 0){
output_conv = s_oconv;
@@ -1356,11 +1368,6 @@ void options(unsigned char *cp)
strcmp(codeset, "CP932") == 0 ||
strcmp(codeset, "MS932") == 0){
output_conv = s_oconv;
- x0201_f = FALSE;
-#ifdef SHIFTJIS_CP932
- cp51932_f = TRUE;
- cp932inv_f = TRUE;
-#endif
#ifdef UTF8_OUTPUT_ENABLE
ms_ucs_map_f = UCS_MAP_CP932;
#endif
@@ -1369,9 +1376,8 @@ void options(unsigned char *cp)
output_conv = e_oconv;
}else if(strcmp(codeset, "CP51932") == 0){
output_conv = e_oconv;
- x0201_f = FALSE;
#ifdef SHIFTJIS_CP932
- cp51932_f = TRUE;
+ cp932inv_f = FALSE;
#endif
#ifdef UTF8_OUTPUT_ENABLE
ms_ucs_map_f = UCS_MAP_CP932;
@@ -1380,26 +1386,18 @@ void options(unsigned char *cp)
strcmp(codeset, "EUCJP-MS") == 0 ||
strcmp(codeset, "EUCJPMS") == 0){
output_conv = e_oconv;
- x0201_f = FALSE;
#ifdef X0212_ENABLE
x0212_f = TRUE;
#endif
-#ifdef SHIFTJIS_CP932
- cp51932_f = FALSE;
-#endif
#ifdef UTF8_OUTPUT_ENABLE
ms_ucs_map_f = UCS_MAP_MS;
#endif
}else if(strcmp(codeset, "EUC-JP-ASCII") == 0 ||
strcmp(codeset, "EUCJP-ASCII") == 0){
output_conv = e_oconv;
- x0201_f = FALSE;
#ifdef X0212_ENABLE
x0212_f = TRUE;
#endif
-#ifdef SHIFTJIS_CP932
- cp51932_f = FALSE;
-#endif
#ifdef UTF8_OUTPUT_ENABLE
ms_ucs_map_f = UCS_MAP_ASCII;
#endif
@@ -1418,7 +1416,7 @@ void options(unsigned char *cp)
#endif
x0213_f = TRUE;
#ifdef SHIFTJIS_CP932
- cp51932_f = FALSE;
+ cp932inv_f = FALSE;
#endif
#ifdef UTF8_OUTPUT_ENABLE
}else if(strcmp(codeset, "UTF-8") == 0){
@@ -1672,6 +1670,7 @@ void options(unsigned char *cp)
continue;
case 'e': /* AT&T EUC output */
output_conv = e_oconv;
+ cp932inv_f = FALSE;
continue;
case 's': /* SJIS output */
output_conv = s_oconv;
@@ -2551,7 +2550,7 @@ nkf_char kanji_convert(FILE *f)
code_status(c1);
if (c2) {
/* second byte */
- if (c2 > DEL) {
+ if (c2 > ((input_f == JIS_INPUT && ms_ucs_map_f) ? 0x92 : DEL)) {
/* in case of 8th bit is on */
if (!estab_f&&!mime_decode_mode) {
/* in case of not established yet */
@@ -2561,14 +2560,16 @@ nkf_char kanji_convert(FILE *f)
else
c2 = 0;
NEXT;
- } else
- /* in case of already established */
- if (c1 < AT) {
- /* ignore bogus code */
- c2 = 0;
- NEXT;
- } else
- SEND;
+ } else {
+ /* in case of already established */
+ if (c1 < AT) {
+ /* ignore bogus code and not CP5022x UCD */
+ c2 = 0;
+ NEXT;
+ } else {
+ SEND;
+ }
+ }
} else
/* second byte, 7 bit code */
/* it might be kanji shitfted */
@@ -2638,7 +2639,7 @@ nkf_char kanji_convert(FILE *f)
SEND;
} else
#endif
- if (c1 > DEL) {
+ if (c1 > ((input_f == JIS_INPUT && ms_ucs_map_f) ? 0x92 : DEL)) {
/* 8 bit code */
if (!estab_f && !iso8859_f) {
/* not established yet */
@@ -2732,13 +2733,13 @@ nkf_char kanji_convert(FILE *f)
/* normal ASCII code */
SEND;
}
- } else if (!is_8bit && c1 == SI) {
+ } else if (c1 == SI && (!is_8bit || mime_decode_mode)) {
shift_mode = FALSE;
NEXT;
- } else if (!is_8bit && c1 == SO) {
+ } else if (c1 == SO && (!is_8bit || mime_decode_mode)) {
shift_mode = TRUE;
NEXT;
- } else if (!is_8bit && c1 == ESC ) {
+ } else if (c1 == ESC && (!is_8bit || mime_decode_mode)) {
if ((c1 = (*i_getc)(f)) == EOF) {
/* (*oconv)(0, ESC); don't send bogus code */
LAST;
@@ -2846,6 +2847,44 @@ nkf_char kanji_convert(FILE *f)
(*oconv)(0, ESC);
SEND;
}
+ } else if (c1 == ESC && iconv == s_iconv) {
+ /* ESC in Shift_JIS */
+ if ((c1 = (*i_getc)(f)) == EOF) {
+ /* (*oconv)(0, ESC); don't send bogus code */
+ LAST;
+ } else if (c1 == '$') {
+ /* J-PHONE emoji */
+ if ((c1 = (*i_getc)(f)) == EOF) {
+ /*
+ (*oconv)(0, ESC); don't send bogus code
+ (*oconv)(0, '$'); */
+ LAST;
+ } else {
+ if (('E' <= c1 && c1 <= 'G') ||
+ ('O' <= c1 && c1 <= 'Q')) {
+ /*
+ NUM : 0 1 2 3 4 5
+ BYTE: G E F O P Q
+ C%7 : 1 6 0 2 3 4
+ C%7 : 0 1 2 3 4 5 6
+ NUM : 2 0 3 4 5 X 1
+ */
+ static const int jphone_emoji_first_table[7] = {2, 0, 3, 4, 5, 0, 1};
+ c0 = (jphone_emoji_first_table[c1 % 7] << 8) - SPACE + 0xE000 + CLASS_UNICODE;
+ while ((c1 = (*i_getc)(f)) != EOF) {
+ if (SPACE <= c1 && c1 <= 'z') {
+ (*oconv)(0, c1 + c0);
+ } else break; /* c1 == SO */
+ }
+ }
+ }
+ if (c1 == EOF) LAST;
+ NEXT;
+ } else {
+ /* lonely ESC */
+ (*oconv)(0, ESC);
+ SEND;
+ }
} else if ((c1 == NL || c1 == CR) && broken_f&4) {
input_mode = ASCII; set_iconv(FALSE, 0);
SEND;
@@ -2875,6 +2914,10 @@ nkf_char kanji_convert(FILE *f)
}
c1 = CR;
SEND;
+ } else if (c1 == DEL && input_mode == X0208 ) {
+ /* CP5022x */
+ c2 = c1;
+ NEXT;
} else
SEND;
}
@@ -2904,6 +2947,14 @@ nkf_char kanji_convert(FILE *f)
break;
case X0208:
case X0213_1:
+ if (ms_ucs_map_f &&
+ 0x7F <= c2 && c2 <= 0x92 &&
+ 0x21 <= c1 && c1 <= 0x7E) {
+ /* CP932 UDC */
+ if(c1 == 0x7F) return 0;
+ c1 = (c2 - 0x7F) * 94 + c1 - 0x21 + 0xE000 + CLASS_UNICODE;
+ c2 = 0;
+ }
(*oconv)(c2, c1); /* this is JIS, not SJIS/EUC case */
break;
#ifdef X0212_ENABLE
@@ -3073,7 +3124,7 @@ nkf_char s2e_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
#endif
static const nkf_char shift_jisx0213_s1a3_table[5][2] ={ { 1, 8}, { 3, 4}, { 5,12}, {13,14}, {15, 0} };
#ifdef SHIFTJIS_CP932
- if (cp51932_f && is_ibmext_in_sjis(c2)){
+ if (!cp932inv_f && is_ibmext_in_sjis(c2)){
#if 0
extern const unsigned short shiftjis_cp932[3][189];
#endif
@@ -3083,6 +3134,17 @@ nkf_char s2e_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
c1 = val & 0xff;
}
}
+ if (cp932inv_f
+ && CP932INV_TABLE_BEGIN <= c2 && c2 <= CP932INV_TABLE_END){
+#if 0
+ extern const unsigned short cp932inv[2][189];
+#endif
+ nkf_char c = cp932inv[c2 - CP932INV_TABLE_BEGIN][c1 - 0x40];
+ if (c){
+ c2 = c >> 8;
+ c1 = c & 0xff;
+ }
+ }
#endif /* SHIFTJIS_CP932 */
#ifdef X0212_ENABLE
if (!x0213_f && is_ibmext_in_sjis(c2)){
@@ -3092,7 +3154,7 @@ nkf_char s2e_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
val = shiftjis_x0212[c2 - 0xfa][c1 - 0x40];
if (val){
if (val > 0x7FFF){
- c2 = PREFIX_EUCG3 | (val >> 8);
+ c2 = PREFIX_EUCG3 | ((val >> 8) & 0x7f);
c1 = val & 0xff;
}else{
c2 = val >> 8;
@@ -3137,6 +3199,11 @@ nkf_char s_iconv(nkf_char c2, nkf_char c1, nkf_char c0)
c1 &= 0x7f;
} else if ((c2 == EOF) || (c2 == 0) || c2 < SPACE) {
/* NOP */
+ } else if (!x0213_f && 0xF0 <= c2 && c2 <= 0xF9 && 0x40 <= c1 && c1 <= 0xFC) {
+ /* CP932 UDC */
+ if(c1 == 0x7F) return 0;
+ c1 = (c2 - 0xF0) * 188 + (c1 - 0x40 - (0x7E < c1)) + 0xE000 + CLASS_UNICODE;
+ c2 = 0;
} else {
nkf_char ret = s2e_conv(c2, c1, &c2, &c1);
if (ret) return ret;
@@ -3154,20 +3221,26 @@ nkf_char e_iconv(nkf_char c2, nkf_char c1, nkf_char c0)
if (c0 == 0){
return -1;
}
- c2 = (c2 << 8) | (c1 & 0x7f);
- c1 = c0 & 0x7f;
+ if (!cp51932_f && !x0213_f && 0xF5 <= c1 && c1 <= 0xFE && 0xA1 <= c0 && c0 <= 0xFE) {
+ /* encoding is eucJP-ms, so invert to Unicode Private User Area */
+ c1 = (c1 - 0xF5) * 94 + c0 - 0xA1 + 0xE3AC + CLASS_UNICODE;
+ c2 = 0;
+ } else {
+ c2 = (c2 << 8) | (c1 & 0x7f);
+ c1 = c0 & 0x7f;
#ifdef SHIFTJIS_CP932
- if (cp51932_f){
- nkf_char s2, s1;
- if (e2s_conv(c2, c1, &s2, &s1) == 0){
- s2e_conv(s2, s1, &c2, &c1);
- if (c2 < 0x100){
- c1 &= 0x7f;
- c2 &= 0x7f;
- }
- }
- }
+ if (cp51932_f){
+ nkf_char s2, s1;
+ if (e2s_conv(c2, c1, &s2, &s1) == 0){
+ s2e_conv(s2, s1, &c2, &c1);
+ if (c2 < 0x100){
+ c1 &= 0x7f;
+ c2 &= 0x7f;
+ }
+ }
+ }
#endif /* SHIFTJIS_CP932 */
+ }
#endif /* X0212_ENABLE */
} else if (c2 == SSO){
c2 = X0201;
@@ -3175,8 +3248,26 @@ nkf_char e_iconv(nkf_char c2, nkf_char c1, nkf_char c0)
} else if ((c2 == EOF) || (c2 == 0) || c2 < SPACE) {
/* NOP */
} else {
- c1 &= 0x7f;
- c2 &= 0x7f;
+ if (!cp51932_f && ms_ucs_map_f && 0xF5 <= c2 && c2 <= 0xFE && 0xA1 <= c1 && c1 <= 0xFE) {
+ /* encoding is eucJP-ms, so invert to Unicode Private User Area */
+ c1 = (c2 - 0xF5) * 94 + c1 - 0xA1 + 0xE000 + CLASS_UNICODE;
+ c2 = 0;
+ } else {
+ c1 &= 0x7f;
+ c2 &= 0x7f;
+#ifdef SHIFTJIS_CP932
+ if (cp51932_f && 0x79 <= c2 && c2 <= 0x7c){
+ nkf_char s2, s1;
+ if (e2s_conv(c2, c1, &s2, &s1) == 0){
+ s2e_conv(s2, s1, &c2, &c1);
+ if (c2 < 0x100){
+ c1 &= 0x7f;
+ c2 &= 0x7f;
+ }
+ }
+ }
+#endif /* SHIFTJIS_CP932 */
+ }
}
(*oconv)(c2, c1);
return 0;
@@ -3436,7 +3527,7 @@ nkf_char unicode_to_jis_common(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *
if(no_best_fit_chars_table_932_C3[c1&0x3F]) return 1;
break;
}
- }else if(cp51932_f){
+ }else if(!cp932inv_f){
switch(c2){
case 0xC2:
if(no_best_fit_chars_table_C2[c1&0x3F]) return 1;
@@ -3492,7 +3583,7 @@ nkf_char unicode_to_jis_common(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *
if(c0 == 0x8D) return 1;
break;
case 0xBD:
- if(c0 == 0x9E && cp51932_f) return 1;
+ if(c0 == 0x9E && !cp932inv_f) return 1;
break;
case 0xBF:
if(0xA0 <= c0 && c0 <= 0xA5) return 1;
@@ -3509,7 +3600,7 @@ nkf_char unicode_to_jis_common(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *
ret = w_iconv_common(c1, c0, ppp[c2 - 0xE0], sizeof_utf8_to_euc_C2, p2, p1);
}else return -1;
#ifdef SHIFTJIS_CP932
- if (!ret && cp51932_f && is_eucg3(*p2)) {
+ if (!ret && !cp932inv_f && is_eucg3(*p2)) {
nkf_char s2, s1;
if (e2s_conv(*p2, *p1, &s2, &s1) == 0) {
s2e_conv(s2, s1, p2, p1);
@@ -3793,6 +3884,7 @@ void w_oconv16(nkf_char c2, nkf_char c1)
nkf_char val = e2w_conv(c2, c1);
c2 = (val >> 8) & 0xff;
c1 = val & 0xff;
+ if (!val) return;
}
if (output_endian == ENDIAN_LITTLE){
(*o_putc)(c1);
@@ -3833,6 +3925,7 @@ void w_oconv32(nkf_char c2, nkf_char c1)
#endif
} else if (c2) {
c1 = e2w_conv(c2, c1);
+ if (!c1) return;
}
if (output_endian == ENDIAN_LITTLE){
(*o_putc)( c1 & NKF_INT32_C(0x000000FF));
@@ -3854,8 +3947,26 @@ void e_oconv(nkf_char c2, nkf_char c1)
if (c2 == 0 && is_unicode_capsule(c1)){
w16e_conv(c1, &c2, &c1);
if (c2 == 0 && is_unicode_capsule(c1)){
- if(encode_fallback)(*encode_fallback)(c1);
- return;
+ c2 = c1 & VALUE_MASK;
+ if (x0212_f && 0xE000 <= c2 && c2 <= 0xE757) {
+ /* eucJP-ms UDC */
+ c1 &= 0xFFF;
+ c2 = c1 / 94;
+ c2 += c2 < 10 ? 0x75 : 0x8FEB;
+ c1 = 0x21 + c1 % 94;
+ if (is_eucg3(c2)){
+ (*o_putc)(0x8f);
+ (*o_putc)((c2 & 0x7f) | 0x080);
+ (*o_putc)(c1 | 0x080);
+ }else{
+ (*o_putc)((c2 & 0x7f) | 0x080);
+ (*o_putc)(c1 | 0x080);
+ }
+ return;
+ } else {
+ if (encode_fallback) (*encode_fallback)(c1);
+ return;
+ }
}
}
#endif
@@ -3875,7 +3986,7 @@ void e_oconv(nkf_char c2, nkf_char c1)
} else if (is_eucg3(c2)){
output_mode = JAPANESE_EUC;
#ifdef SHIFTJIS_CP932
- if (cp51932_f){
+ if (!cp932inv_f){
nkf_char s2, s1;
if (e2s_conv(c2, c1, &s2, &s1) == 0){
s2e_conv(s2, s1, &c2, &c1);
@@ -3941,7 +4052,7 @@ nkf_char e2s_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
{
nkf_char ndx;
if (is_eucg3(c2)){
- ndx = c2 & 0xff;
+ ndx = c2 & 0x7f;
if (x0213_f){
if((0x21 <= ndx && ndx <= 0x2F)){
if (p2) *p2 = ((ndx - 1) >> 1) + 0xec - ndx / 8 * 3;
@@ -3988,9 +4099,21 @@ void s_oconv(nkf_char c2, nkf_char c1)
if (c2 == 0 && is_unicode_capsule(c1)){
w16e_conv(c1, &c2, &c1);
if (c2 == 0 && is_unicode_capsule(c1)){
- if(encode_fallback)(*encode_fallback)(c1);
- return;
- }
+ c2 = c1 & VALUE_MASK;
+ if (!x0213_f && 0xE000 <= c2 && c2 <= 0xE757) {
+ /* CP932 UDC */
+ c1 &= 0xFFF;
+ c2 = c1 / 188 + 0xF0;
+ c1 = c1 % 188;
+ c1 += 0x40 + (c1 > 0x3e);
+ (*o_putc)(c2);
+ (*o_putc)(c1);
+ return;
+ } else {
+ if(encode_fallback)(*encode_fallback)(c1);
+ return;
+ }
+ }
}
#endif
if (c2 == EOF) {
@@ -4049,8 +4172,16 @@ void j_oconv(nkf_char c2, nkf_char c1)
if (c2 == 0 && is_unicode_capsule(c1)){
w16e_conv(c1, &c2, &c1);
if (c2 == 0 && is_unicode_capsule(c1)){
- if(encode_fallback)(*encode_fallback)(c1);
- return;
+ c2 = c1 & VALUE_MASK;
+ if (ms_ucs_map_f && 0xE000 <= c2 && c2 <= 0xE757) {
+ /* CP5022x UDC */
+ c1 &= 0xFFF;
+ c2 = 0x7F + c1 / 94;
+ c1 = 0x21 + c1 % 94;
+ } else {
+ if (encode_fallback) (*encode_fallback)(c1);
+ return;
+ }
}
}
#endif
@@ -4107,7 +4238,9 @@ void j_oconv(nkf_char c2, nkf_char c1)
}
(*o_putc)(c1);
} else {
- if(c2<0x20 || 0x7e<c2 || c1<0x20 || 0x7e<c1) return;
+ if(ms_ucs_map_f
+ ? c2<0x20 || 0x92<c2 || c1<0x20 || 0x7e<c1
+ : c2<0x20 || 0x7e<c2 || c1<0x20 || 0x7e<c1) return;
if(x0213_f){
if (output_mode!=X0213_1) {
output_mode = X0213_1;
diff --git a/ext/nkf/nkf-utf8/utf8tbl.c b/ext/nkf/nkf-utf8/utf8tbl.c
index 9e59956a0a..e43ad553d6 100644
--- a/ext/nkf/nkf-utf8/utf8tbl.c
+++ b/ext/nkf/nkf-utf8/utf8tbl.c
@@ -7544,7 +7544,7 @@ const unsigned short cp932inv[2][189] = {
0xFBFC, 0xFC40, 0xFC41, 0xFC42, 0xFC43, 0xFC44, 0xFC45, 0xFC46,
0xFC47, 0xFC48, 0xFC49, 0xFC4A, 0xFC4B, 0, 0, 0xFA40,
0xFA41, 0xFA42, 0xFA43, 0xFA44, 0xFA45, 0xFA46, 0xFA47, 0xFA48,
- 0xFA49, 0, 0xFA55, 0xFA56, 0xFA57,
+ 0xFA49, 0x81CA, 0xFA55, 0xFA56, 0xFA57,
},
};
#endif /* SHIFTJIS_CP932 */
diff --git a/ext/nkf/nkf.c b/ext/nkf/nkf.c
index e12df16960..2bb0340a64 100644
--- a/ext/nkf/nkf.c
+++ b/ext/nkf/nkf.c
@@ -56,13 +56,14 @@ static int incsize;
static VALUE result;
static int
-rb_nkf_putchar(unsigned int c)
+rb_nkf_putchar(c)
+ unsigned int c;
{
if (output_ctr >= o_len) {
o_len += incsize;
rb_str_resize(result, o_len);
incsize *= 2;
- output = RSTRING_PTR(result);
+ output = (unsigned char *)RSTRING(result)->ptr;
}
output[output_ctr++] = c;
@@ -77,7 +78,8 @@ rb_nkf_putchar(unsigned int c)
#include "nkf-utf8/utf8tbl.c"
#include "nkf-utf8/nkf.c"
-int nkf_split_options(const char *arg)
+int nkf_split_options(arg)
+ const char* arg;
{
int count = 0;
char option[256];
@@ -140,36 +142,38 @@ int nkf_split_options(const char *arg)
*/
static VALUE
-rb_nkf_kconv(VALUE obj, VALUE opt, VALUE src)
+rb_nkf_kconv(obj, opt, src)
+ VALUE obj, opt, src;
{
char *opt_ptr, *opt_end;
volatile VALUE v;
reinit();
StringValue(opt);
- opt_ptr = RSTRING_PTR(opt);
- opt_end = opt_ptr + RSTRING_LEN(opt);
+ opt_ptr = RSTRING(opt)->ptr;
+ opt_end = opt_ptr + RSTRING(opt)->len;
nkf_split_options(opt_ptr);
incsize = INCSIZE;
input_ctr = 0;
StringValue(src);
- input = RSTRING_PTR(src);
- i_len = RSTRING_LEN(src);
+ input = (unsigned char *)RSTRING(src)->ptr;
+ i_len = RSTRING(src)->len;
result = rb_str_new(0, i_len*3 + 10);
v = result;
output_ctr = 0;
- output = RSTRING_PTR(result);
- o_len = RSTRING_LEN(result);
+ output = (unsigned char *)RSTRING(result)->ptr;
+ o_len = RSTRING(result)->len;
*output = '\0';
if(x0201_f == WISH_TRUE)
x0201_f = ((!iso2022jp_f)? TRUE : NO_X0201);
kanji_convert(NULL);
- rb_str_set_len(result, output_ctr);
+ RSTRING(result)->ptr[output_ctr] = '\0';
+ RSTRING(result)->len = output_ctr;
OBJ_INFECT(result, src);
return result;
@@ -201,15 +205,16 @@ rb_nkf_kconv(VALUE obj, VALUE opt, VALUE src)
*/
static VALUE
-rb_nkf_guess1(VALUE obj, VALUE src)
+rb_nkf_guess1(obj, src)
+ VALUE obj, src;
{
unsigned char *p;
unsigned char *pend;
int sequence_counter = 0;
StringValue(src);
- p = RSTRING_PTR(src);
- pend = p + RSTRING_LEN(src);
+ p = (unsigned char *)RSTRING(src)->ptr;
+ pend = p + RSTRING(src)->len;
if (p == pend) return INT2FIX(_UNKNOWN);
#define INCR do {\
@@ -306,8 +311,6 @@ rb_nkf_guess1(VALUE obj, VALUE src)
* "UTF-8"
* when NKF::UTF16
* "UTF-16"
- * when NKF::UTF32
- * "UTF-32"
* when NKF::UNKNOWN
* "UNKNOWN"
* when NKF::BINARY
@@ -316,7 +319,8 @@ rb_nkf_guess1(VALUE obj, VALUE src)
*/
static VALUE
-rb_nkf_guess2(VALUE obj, VALUE src)
+rb_nkf_guess2(obj, src)
+ VALUE obj, src;
{
int code = _BINARY;
@@ -324,8 +328,8 @@ rb_nkf_guess2(VALUE obj, VALUE src)
input_ctr = 0;
StringValue(src);
- input = RSTRING_PTR(src);
- i_len = RSTRING_LEN(src);
+ input = (unsigned char *)RSTRING(src)->ptr;
+ i_len = RSTRING(src)->len;
if(x0201_f == WISH_TRUE)
x0201_f = ((!iso2022jp_f)? TRUE : NO_X0201);
@@ -347,8 +351,6 @@ rb_nkf_guess2(VALUE obj, VALUE src)
code = _UTF8;
} else if (strcmp(input_codename, "UTF-16") == 0) {
code = _UTF16;
- } else if (strcmp(input_codename, "UTF-32") == 0) {
- code = _UTF32;
} else if (strlen(input_codename) > 0) {
code = _UNKNOWN;
}
@@ -386,16 +388,16 @@ rb_nkf_guess2(VALUE obj, VALUE src)
*
* Output is buffered (DEFAULT), Output is unbuffered.
*
- * === -j -s -e -w -w16 -w32
+ * === -j -s -e -w -w16
*
* Output code is ISO-2022-JP (7bit JIS), Shift_JIS, EUC-JP,
- * UTF-8N, UTF-16BE, UTF-32BE.
+ * UTF-8N, UTF-16BE.
* Without this option and compile option, ISO-2022-JP is assumed.
*
- * === -J -S -E -W -W16 -W32
+ * === -J -S -E -W -W16
*
* Input assumption is JIS 7 bit, Shift_JIS, EUC-JP,
- * UTF-8, UTF-16, UTF-32.
+ * UTF-8, UTF-16LE.
*
* ==== -J
*
@@ -578,16 +580,6 @@ rb_nkf_guess2(VALUE obj, VALUE src)
*
* [UTF-16LE-BOM] UTF-16 Little Endian with BOM
*
- * [UTF-32] same as UTF-32BE
- *
- * [UTF-32BE] UTF-32 Big Endian without BOM
- *
- * [UTF-32BE-BOM] UTF-32 Big Endian with BOM
- *
- * [UTF-32LE] UTF-32 Little Endian without BOM
- *
- * [UTF-32LE-BOM] UTF-32 Little Endian with BOM
- *
* [UTF8-MAC] NKDed UTF-8, a.k.a. UTF8-NFD (input only)
*
* === --fb-{skip, html, xml, perl, java, subchar}
@@ -601,20 +593,10 @@ rb_nkf_guess2(VALUE obj, VALUE src)
* nkf adds a specified escape character to specified 2nd byte of Shift_JIS characters.
* 1st byte of argument is the escape character and following bytes are target characters.
*
- * === --no-cp932ext
+ * === --disable-cp932ext
*
* Handle the characters extended in CP932 as unassigned characters.
*
- * == --no-best-fit-chars
- *
- * When Unicode to Encoded byte conversion,
- * don't convert characters which is not round trip safe.
- * When Unicode to Unicode conversion,
- * with this and -x option, nkf can be used as UTF converter.
- * (In other words, without this and -x option, nkf doesn't save some characters)
- *
- * When nkf convert string which related to path, you should use this opion.
- *
* === --cap-input
*
* Decode hex encoded characters.
diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb
index 11f74ff3d8..98921bc468 100644
--- a/ext/openssl/extconf.rb
+++ b/ext/openssl/extconf.rb
@@ -36,8 +36,6 @@ end
message "=== Checking for system dependent stuff... ===\n"
have_library("nsl", "t_open")
have_library("socket", "socket")
-have_header("unistd.h")
-have_header("sys/time.h")
have_header("assert.h")
message "=== Checking for required stuff... ===\n"
diff --git a/ext/openssl/lib/net/ftptls.rb b/ext/openssl/lib/net/ftptls.rb
index f433457923..a21c1f6c3c 100644
--- a/ext/openssl/lib/net/ftptls.rb
+++ b/ext/openssl/lib/net/ftptls.rb
@@ -29,13 +29,23 @@ 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 a872f41e6a..2b69280432 100644
--- a/ext/openssl/lib/net/telnets.rb
+++ b/ext/openssl/lib/net/telnets.rb
@@ -134,6 +134,9 @@ 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/buffering.rb b/ext/openssl/lib/openssl/buffering.rb
index 8800aa53cc..761a017487 100644
--- a/ext/openssl/lib/openssl/buffering.rb
+++ b/ext/openssl/lib/openssl/buffering.rb
@@ -57,10 +57,10 @@ module Buffering
if size == 0
if buf
buf.clear
- return buf
else
- return ""
+ buf = ""
end
+ return @eof ? nil : buf
end
until @eof
break if size && size <= @rbuffer.size
@@ -78,10 +78,10 @@ module Buffering
if maxlen == 0
if buf
buf.clear
- return buf
else
- return ""
+ buf = ""
end
+ return @eof ? nil : buf
end
if @rbuffer.empty?
begin
diff --git a/ext/openssl/lib/openssl/ssl.rb b/ext/openssl/lib/openssl/ssl.rb
index ef7415f478..9e9a9448ba 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 not match"
+ raise SSLError, "hostname was not match with the server certificate"
end
end
diff --git a/ext/openssl/openssl_missing.h b/ext/openssl/openssl_missing.h
index e8c75ca42c..7b1e019208 100644
--- a/ext/openssl/openssl_missing.h
+++ b/ext/openssl/openssl_missing.h
@@ -15,6 +15,10 @@
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.c b/ext/openssl/ossl.c
index 16e93bc939..a98f2641cc 100644
--- a/ext/openssl/ossl.c
+++ b/ext/openssl/ossl.c
@@ -59,7 +59,7 @@ ossl_x509_ary2sk0(VALUE ary)
sk = sk_X509_new_null();
if (!sk) ossl_raise(eOSSLError, NULL);
- for (i = 0; i < RARRAY_LEN(ary); i++) {
+ for (i = 0; i < RARRAY(ary)->len; i++) {
val = rb_ary_entry(ary, i);
if (!rb_obj_is_kind_of(val, cX509Cert)) {
sk_X509_pop_free(sk, X509_free);
@@ -131,7 +131,7 @@ ossl_buf2str(char *buf, int len)
int status = 0;
str = rb_protect((VALUE(*)_((VALUE)))ossl_str_new, len, &status);
- if(!NIL_P(str)) memcpy(RSTRING_PTR(str), buf, len);
+ if(!NIL_P(str)) memcpy(RSTRING(str)->ptr, buf, len);
OPENSSL_free(buf);
if(status) rb_jump_tag(status);
@@ -170,7 +170,7 @@ ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
rflag = flag ? Qtrue : Qfalse;
pass = rb_protect(ossl_pem_passwd_cb0, rflag, &status);
if (status) return -1; /* exception was raised. */
- len = RSTRING_LEN(pass);
+ len = RSTRING(pass)->len;
if (len < 4) { /* 4 is OpenSSL hardcoded limit */
rb_warning("password must be longer than 4 bytes");
continue;
@@ -179,7 +179,7 @@ ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
rb_warning("password must be shorter then %d bytes", max_len-1);
continue;
}
- memcpy(buf, RSTRING_PTR(pass), len);
+ memcpy(buf, RSTRING(pass)->ptr, len);
break;
}
return len;
diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h
index 3be563005c..0c23f10d38 100644
--- a/ext/openssl/ossl.h
+++ b/ext/openssl/ossl.h
@@ -42,7 +42,11 @@ extern "C" {
#if defined(_WIN32)
# define OpenFile WINAPI_OpenFile
# define OSSL_NO_CONF_API 1
-# include <winsock2.h>
+# ifdef USE_WINSOCK2
+# include <winsock2.h>
+# else
+# include <winsock.h>
+# endif
#endif
#include <errno.h>
#include <openssl/err.h>
@@ -118,10 +122,11 @@ VALUE ossl_x509crl_sk2ary(STACK_OF(X509_CRL) *crl);
VALUE ossl_buf2str(char *buf, int len);
#define ossl_str_adjust(str, p) \
do{\
- int len = RSTRING_LEN(str);\
- int newlen = (p) - (unsigned char*)RSTRING_PTR(str);\
+ int len = RSTRING(str)->len;\
+ int newlen = (p) - (unsigned char*)RSTRING(str)->ptr;\
assert(newlen <= len);\
- rb_str_set_len(str, newlen);\
+ RSTRING(str)->len = newlen;\
+ RSTRING(str)->ptr[newlen] = 0;\
}while(0)
/*
@@ -202,6 +207,7 @@ 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_asn1.c b/ext/openssl/ossl_asn1.c
index fe8a1e0c35..3614f470d9 100644
--- a/ext/openssl/ossl_asn1.c
+++ b/ext/openssl/ossl_asn1.c
@@ -214,7 +214,7 @@ obj_to_asn1bstr(VALUE obj, long unused_bits)
StringValue(obj);
if(!(bstr = ASN1_BIT_STRING_new()))
ossl_raise(eASN1Error, NULL);
- ASN1_BIT_STRING_set(bstr, RSTRING_PTR(obj), RSTRING_LEN(obj));
+ ASN1_BIT_STRING_set(bstr, RSTRING(obj)->ptr, RSTRING(obj)->len);
bstr->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
bstr->flags |= ASN1_STRING_FLAG_BITS_LEFT|(unused_bits&0x07);
@@ -229,7 +229,7 @@ obj_to_asn1str(VALUE obj)
StringValue(obj);
if(!(str = ASN1_STRING_new()))
ossl_raise(eASN1Error, NULL);
- ASN1_STRING_set(str, RSTRING_PTR(obj), RSTRING_LEN(obj));
+ ASN1_STRING_set(str, RSTRING(obj)->ptr, RSTRING(obj)->len);
return str;
}
@@ -253,8 +253,8 @@ obj_to_asn1obj(VALUE obj)
ASN1_OBJECT *a1obj;
StringValue(obj);
- a1obj = OBJ_txt2obj(RSTRING_PTR(obj), 0);
- if(!a1obj) a1obj = OBJ_txt2obj(RSTRING_PTR(obj), 1);
+ a1obj = OBJ_txt2obj(RSTRING(obj)->ptr, 0);
+ if(!a1obj) a1obj = OBJ_txt2obj(RSTRING(obj)->ptr, 1);
if(!a1obj) ossl_raise(eASN1Error, "invalid OBJECT ID");
return a1obj;
@@ -295,7 +295,7 @@ obj_to_asn1derstr(VALUE obj)
str = ossl_to_der(obj);
if(!(a1str = ASN1_STRING_new()))
ossl_raise(eASN1Error, NULL);
- ASN1_STRING_set(a1str, RSTRING_PTR(str), RSTRING_LEN(str));
+ ASN1_STRING_set(a1str, RSTRING(str)->ptr, RSTRING(str)->len);
return a1str;
}
@@ -445,7 +445,7 @@ decode_time(unsigned char* der, int length)
/********/
typedef struct {
- const char *name;
+ char *name;
VALUE *klass;
} ossl_asn1_info_t;
@@ -678,7 +678,7 @@ static VALUE
join_der(VALUE enumerable)
{
VALUE str = rb_str_new(0, 0);
- rb_block_call(enumerable, rb_intern("each"), 0, 0, join_der_i, str);
+ rb_iterate(rb_each, enumerable, join_der_i, str);
return str;
}
@@ -699,13 +699,13 @@ ossl_asn1data_to_der(VALUE self)
tag = ossl_asn1_tag(self);
tag_class = ossl_asn1_tag_class(self);
- if((length = ASN1_object_size(1, RSTRING_LEN(value), tag)) <= 0)
+ if((length = ASN1_object_size(1, RSTRING(value)->len, tag)) <= 0)
ossl_raise(eASN1Error, NULL);
der = rb_str_new(0, length);
- p = RSTRING_PTR(der);
- ASN1_put_object(&p, is_cons, RSTRING_LEN(value), tag, tag_class);
- memcpy(p, RSTRING_PTR(value), RSTRING_LEN(value));
- p += RSTRING_LEN(value);
+ p = RSTRING(der)->ptr;
+ ASN1_put_object(&p, is_cons, RSTRING(value)->len, tag, tag_class);
+ memcpy(p, RSTRING(value)->ptr, RSTRING(value)->len);
+ p += RSTRING(value)->len;
ossl_str_adjust(der, p);
return der;
@@ -824,8 +824,8 @@ ossl_asn1_traverse(VALUE self, VALUE obj)
obj = ossl_to_der_if_possible(obj);
tmp = rb_str_new4(StringValue(obj));
- p = RSTRING_PTR(tmp);
- ossl_asn1_decode0(&p, RSTRING_LEN(tmp), &offset, 0, 0, 1);
+ p = RSTRING(tmp)->ptr;
+ ossl_asn1_decode0(&p, RSTRING(tmp)->len, &offset, 0, 0, 1);
return Qnil;
}
@@ -840,8 +840,8 @@ ossl_asn1_decode(VALUE self, VALUE obj)
obj = ossl_to_der_if_possible(obj);
tmp = rb_str_new4(StringValue(obj));
- p = RSTRING_PTR(tmp);
- ary = ossl_asn1_decode0(&p, RSTRING_LEN(tmp), &offset, 0, 1, 0);
+ p = RSTRING(tmp)->ptr;
+ ary = ossl_asn1_decode0(&p, RSTRING(tmp)->len, &offset, 0, 1, 0);
ret = rb_ary_entry(ary, 0);
return ret;
@@ -857,8 +857,8 @@ ossl_asn1_decode_all(VALUE self, VALUE obj)
obj = ossl_to_der_if_possible(obj);
tmp = rb_str_new4(StringValue(obj));
- p = RSTRING_PTR(tmp);
- ret = ossl_asn1_decode0(&p, RSTRING_LEN(tmp), &offset, 0, 0, 0);
+ p = RSTRING(tmp)->ptr;
+ ret = ossl_asn1_decode0(&p, RSTRING(tmp)->len, &offset, 0, 0, 0);
return ret;
}
@@ -973,21 +973,21 @@ ossl_asn1cons_to_der(VALUE self)
explicit = ossl_asn1_is_explicit(self);
value = join_der(ossl_asn1_get_value(self));
- seq_len = ASN1_object_size(1, RSTRING_LEN(value), tag);
+ seq_len = ASN1_object_size(1, RSTRING(value)->len, tag);
length = ASN1_object_size(1, seq_len, tn);
str = rb_str_new(0, length);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(tc == V_ASN1_UNIVERSAL)
- ASN1_put_object(&p, 1, RSTRING_LEN(value), tn, tc);
+ ASN1_put_object(&p, 1, RSTRING(value)->len, tn, tc);
else{
if(explicit){
ASN1_put_object(&p, 1, seq_len, tn, tc);
- ASN1_put_object(&p, 1, RSTRING_LEN(value), tag, V_ASN1_UNIVERSAL);
+ ASN1_put_object(&p, 1, RSTRING(value)->len, tag, V_ASN1_UNIVERSAL);
}
- else ASN1_put_object(&p, 1, RSTRING_LEN(value), tn, tc);
+ else ASN1_put_object(&p, 1, RSTRING(value)->len, tn, tc);
}
- memcpy(p, RSTRING_PTR(value), RSTRING_LEN(value));
- p += RSTRING_LEN(value);
+ memcpy(p, RSTRING(value)->ptr, RSTRING(value)->len);
+ p += RSTRING(value)->len;
ossl_str_adjust(str, p);
return str;
@@ -1007,7 +1007,7 @@ ossl_asn1obj_s_register(VALUE self, VALUE oid, VALUE sn, VALUE ln)
StringValue(sn);
StringValue(ln);
- if(!OBJ_create(RSTRING_PTR(oid), RSTRING_PTR(sn), RSTRING_PTR(ln)))
+ if(!OBJ_create(RSTRING(oid)->ptr, RSTRING(sn)->ptr, RSTRING(ln)->ptr))
ossl_raise(eASN1Error, NULL);
return Qtrue;
@@ -1087,6 +1087,10 @@ Init_ossl_asn1()
VALUE ary;
int i;
+#if 0 /* let rdoc know about mOSSL */
+ mOSSL = rb_define_module("OpenSSL");
+#endif
+
sUNIVERSAL = rb_intern("UNIVERSAL");
sCONTEXT_SPECIFIC = rb_intern("CONTEXT_SPECIFIC");
sAPPLICATION = rb_intern("APPLICATION");
diff --git a/ext/openssl/ossl_bio.c b/ext/openssl/ossl_bio.c
index aa0b99fe8c..9c9aa24197 100644
--- a/ext/openssl/ossl_bio.c
+++ b/ext/openssl/ossl_bio.c
@@ -20,28 +20,15 @@ ossl_obj2bio(VALUE obj)
if (TYPE(obj) == T_FILE) {
OpenFile *fptr;
- FILE *fp;
- int fd;
-
GetOpenFile(obj, fptr);
rb_io_check_readable(fptr);
- if ((fd = dup(fptr->fd)) < 0){
- rb_sys_fail(0);
- }
- if (!(fp = fdopen(fd, "r"))){
- close(fd);
- rb_sys_fail(0);
- }
- if (!(bio = BIO_new_fp(fp, BIO_CLOSE))){
- fclose(fp);
- ossl_raise(eOSSLError, NULL);
- }
- }
+ bio = BIO_new_fp(fptr->f, BIO_NOCLOSE);
+ }
else {
StringValue(obj);
- bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LEN(obj));
- if (!bio) ossl_raise(eOSSLError, NULL);
+ bio = BIO_new_mem_buf(RSTRING(obj)->ptr, RSTRING(obj)->len);
}
+ if (!bio) ossl_raise(eOSSLError, NULL);
return bio;
}
diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c
index 0ddcb8270d..cc7689eef5 100644
--- a/ext/openssl/ossl_bn.c
+++ b/ext/openssl/ossl_bn.c
@@ -124,22 +124,22 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
switch (base) {
case 0:
- if (!BN_mpi2bn(RSTRING_PTR(str), RSTRING_LEN(str), bn)) {
+ if (!BN_mpi2bn(RSTRING(str)->ptr, RSTRING(str)->len, bn)) {
ossl_raise(eBNError, NULL);
}
break;
case 2:
- if (!BN_bin2bn(RSTRING_PTR(str), RSTRING_LEN(str), bn)) {
+ if (!BN_bin2bn(RSTRING(str)->ptr, RSTRING(str)->len, bn)) {
ossl_raise(eBNError, NULL);
}
break;
case 10:
- if (!BN_dec2bn(&bn, RSTRING_PTR(str))) {
+ if (!BN_dec2bn(&bn, RSTRING(str)->ptr)) {
ossl_raise(eBNError, NULL);
}
break;
case 16:
- if (!BN_hex2bn(&bn, RSTRING_PTR(str))) {
+ if (!BN_hex2bn(&bn, RSTRING(str)->ptr)) {
ossl_raise(eBNError, NULL);
}
break;
@@ -165,13 +165,13 @@ ossl_bn_to_s(int argc, VALUE *argv, VALUE self)
case 0:
len = BN_bn2mpi(bn, NULL);
str = rb_str_new(0, len);
- if (BN_bn2mpi(bn, RSTRING_PTR(str)) != len)
+ if (BN_bn2mpi(bn, RSTRING(str)->ptr) != len)
ossl_raise(eBNError, NULL);
break;
case 2:
len = BN_num_bytes(bn);
str = rb_str_new(0, len);
- if (BN_bn2bin(bn, RSTRING_PTR(str)) != len)
+ if (BN_bn2bin(bn, RSTRING(str)->ptr) != len)
ossl_raise(eBNError, NULL);
break;
case 10:
@@ -600,6 +600,10 @@ ossl_bn_is_prime_fasttest(int argc, VALUE *argv, VALUE self)
void
Init_ossl_bn()
{
+#if 0 /* let rdoc know about mOSSL */
+ mOSSL = rb_define_module("OpenSSL");
+#endif
+
if (!(ossl_bn_ctx = BN_CTX_new())) {
ossl_raise(rb_eRuntimeError, "Cannot init BN_CTX");
}
diff --git a/ext/openssl/ossl_cipher.c b/ext/openssl/ossl_cipher.c
index e38aef8f7a..57b7976617 100644
--- a/ext/openssl/ossl_cipher.c
+++ b/ext/openssl/ossl_cipher.c
@@ -167,23 +167,22 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
* We deprecated the arguments for this method, but we decided
* keeping this behaviour for backward compatibility.
*/
- char *cname = rb_class2name(rb_obj_class(self));
- rb_warn("argumtents for %s#encrypt and %s#decrypt were deprecated; "
- "use %s#pkcs5_keyivgen to derive key and IV",
- cname, cname, cname);
StringValue(pass);
GetCipher(self, ctx);
if (NIL_P(init_v)) memcpy(iv, "OpenSSL for Ruby rulez!", sizeof(iv));
else{
+ char *cname = rb_class2name(rb_obj_class(self));
+ rb_warning("key derivation by %s#encrypt is deprecated; "
+ "use %s::pkcs5_keyivgen instead", cname, cname);
StringValue(init_v);
- if (EVP_MAX_IV_LENGTH > RSTRING_LEN(init_v)) {
+ if (EVP_MAX_IV_LENGTH > RSTRING(init_v)->len) {
memset(iv, 0, EVP_MAX_IV_LENGTH);
- memcpy(iv, RSTRING_PTR(init_v), RSTRING_LEN(init_v));
+ memcpy(iv, RSTRING(init_v)->ptr, RSTRING(init_v)->len);
}
- else memcpy(iv, RSTRING_PTR(init_v), sizeof(iv));
+ else memcpy(iv, RSTRING(init_v)->ptr, sizeof(iv));
}
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), EVP_md5(), iv,
- RSTRING_PTR(pass), RSTRING_LEN(pass), 1, key, NULL);
+ RSTRING(pass)->ptr, RSTRING(pass)->len, 1, key, NULL);
p_key = key;
p_iv = iv;
}
@@ -222,15 +221,15 @@ ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self)
StringValue(vpass);
if(!NIL_P(vsalt)){
StringValue(vsalt);
- if(RSTRING_LEN(vsalt) != PKCS5_SALT_LEN)
+ if(RSTRING(vsalt)->len != PKCS5_SALT_LEN)
rb_raise(eCipherError, "salt must be an 8-octet string");
- salt = RSTRING_PTR(vsalt);
+ salt = RSTRING(vsalt)->ptr;
}
iter = NIL_P(viter) ? 2048 : NUM2INT(viter);
digest = NIL_P(vdigest) ? EVP_md5() : GetDigestPtr(vdigest);
GetCipher(self, ctx);
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), digest, salt,
- RSTRING_PTR(vpass), RSTRING_LEN(vpass), iter, key, iv);
+ RSTRING(vpass)->ptr, RSTRING(vpass)->len, iter, key, iv);
if (EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, -1) != 1)
ossl_raise(eCipherError, NULL);
OPENSSL_cleanse(key, sizeof key);
@@ -248,19 +247,30 @@ ossl_cipher_update(VALUE self, VALUE data)
VALUE str;
StringValue(data);
- in = RSTRING_PTR(data);
- if ((in_len = RSTRING_LEN(data)) == 0)
+ in = RSTRING(data)->ptr;
+ if ((in_len = RSTRING(data)->len) == 0)
rb_raise(rb_eArgError, "data must not be empty");
GetCipher(self, ctx);
str = rb_str_new(0, in_len+EVP_CIPHER_CTX_block_size(ctx));
- if (!EVP_CipherUpdate(ctx, RSTRING_PTR(str), &out_len, in, in_len))
+ if (!EVP_CipherUpdate(ctx, RSTRING(str)->ptr, &out_len, in, in_len))
ossl_raise(eCipherError, NULL);
- assert(out_len < RSTRING_LEN(str));
- rb_str_set_len(str, out_len);
+ assert(out_len < RSTRING(str)->len);
+ RSTRING(str)->len = out_len;
+ RSTRING(str)->ptr[out_len] = 0;
return str;
}
+static VALUE
+ossl_cipher_update_deprecated(VALUE self, VALUE data)
+{
+ char *cname;
+
+ cname = rb_class2name(rb_obj_class(self));
+ rb_warning("%s#<< is deprecated; use %s#update instead", cname, cname);
+ return ossl_cipher_update(self, data);
+}
+
static VALUE
ossl_cipher_final(VALUE self)
{
@@ -270,10 +280,11 @@ ossl_cipher_final(VALUE self)
GetCipher(self, ctx);
str = rb_str_new(0, EVP_CIPHER_CTX_block_size(ctx));
- if (!EVP_CipherFinal_ex(ctx, RSTRING_PTR(str), &out_len))
+ if (!EVP_CipherFinal_ex(ctx, RSTRING(str)->ptr, &out_len))
ossl_raise(eCipherError, NULL);
- assert(out_len <= RSTRING_LEN(str));
- rb_str_set_len(str, out_len);
+ assert(out_len <= RSTRING(str)->len);
+ RSTRING(str)->len = out_len;
+ RSTRING(str)->ptr[out_len] = 0;
return str;
}
@@ -296,10 +307,10 @@ ossl_cipher_set_key(VALUE self, VALUE key)
StringValue(key);
GetCipher(self, ctx);
- if (RSTRING_LEN(key) < EVP_CIPHER_CTX_key_length(ctx))
+ if (RSTRING(key)->len < EVP_CIPHER_CTX_key_length(ctx))
ossl_raise(eCipherError, "key length too short");
- if (EVP_CipherInit_ex(ctx, NULL, NULL, RSTRING_PTR(key), NULL, -1) != 1)
+ if (EVP_CipherInit_ex(ctx, NULL, NULL, RSTRING(key)->ptr, NULL, -1) != 1)
ossl_raise(eCipherError, NULL);
return key;
@@ -313,10 +324,10 @@ ossl_cipher_set_iv(VALUE self, VALUE iv)
StringValue(iv);
GetCipher(self, ctx);
- if (RSTRING_LEN(iv) < EVP_CIPHER_CTX_iv_length(ctx))
+ if (RSTRING(iv)->len < EVP_CIPHER_CTX_iv_length(ctx))
ossl_raise(eCipherError, "iv length too short");
- if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, RSTRING_PTR(iv), -1) != 1)
+ if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, RSTRING(iv)->ptr, -1) != 1)
ossl_raise(eCipherError, NULL);
return iv;
@@ -325,8 +336,8 @@ ossl_cipher_set_iv(VALUE self, VALUE iv)
static VALUE
ossl_cipher_set_key_length(VALUE self, VALUE key_length)
{
- int len = NUM2INT(key_length);
EVP_CIPHER_CTX *ctx;
+ int len = NUM2INT(key_length);
GetCipher(self, ctx);
if (EVP_CIPHER_CTX_set_key_length(ctx, len) != 1)
@@ -369,6 +380,10 @@ CIPHER_0ARG_INT(block_size)
void
Init_ossl_cipher(void)
{
+#if 0 /* let rdoc know about mOSSL */
+ mOSSL = rb_define_module("OpenSSL");
+#endif
+
mCipher = rb_define_module_under(mOSSL, "Cipher");
eCipherError = rb_define_class_under(mOSSL, "CipherError", eOSSLError);
cCipher = rb_define_class_under(mCipher, "Cipher", rb_cObject);
@@ -382,6 +397,7 @@ Init_ossl_cipher(void)
rb_define_method(cCipher, "decrypt", ossl_cipher_decrypt, -1);
rb_define_method(cCipher, "pkcs5_keyivgen", ossl_cipher_pkcs5_keyivgen, -1);
rb_define_method(cCipher, "update", ossl_cipher_update, 1);
+ rb_define_method(cCipher, "<<", ossl_cipher_update_deprecated, 1);
rb_define_method(cCipher, "final", ossl_cipher_final, 0);
rb_define_method(cCipher, "name", ossl_cipher_name, 0);
rb_define_method(cCipher, "key=", ossl_cipher_set_key, 1);
diff --git a/ext/openssl/ossl_config.c b/ext/openssl/ossl_config.c
index 3dfe7f361c..f1d6a98253 100644
--- a/ext/openssl/ossl_config.c
+++ b/ext/openssl/ossl_config.c
@@ -171,16 +171,16 @@ ossl_config_add_value(VALUE self, VALUE section, VALUE name, VALUE value)
StringValue(name);
StringValue(value);
GetConfig(self, conf);
- if(!(sv = _CONF_get_section(conf, RSTRING_PTR(section)))){
- if(!(sv = _CONF_new_section(conf, RSTRING_PTR(section)))){
+ if(!(sv = _CONF_get_section(conf, RSTRING(section)->ptr))){
+ if(!(sv = _CONF_new_section(conf, RSTRING(section)->ptr))){
ossl_raise(eConfigError, NULL);
}
}
if(!(cv = OPENSSL_malloc(sizeof(CONF_VALUE)))){
ossl_raise(eConfigError, NULL);
}
- cv->name = BUF_strdup(RSTRING_PTR(name));
- cv->value = BUF_strdup(RSTRING_PTR(value));
+ cv->name = BUF_strdup(RSTRING(name)->ptr);
+ cv->value = BUF_strdup(RSTRING(value)->ptr);
if(!cv->name || !cv->value || !_CONF_add_string(conf, sv, cv)){
OPENSSL_free(cv->name);
OPENSSL_free(cv->value);
@@ -201,7 +201,7 @@ ossl_config_get_value(VALUE self, VALUE section, VALUE name)
StringValue(section);
StringValue(name);
GetConfig(self, conf);
- str = NCONF_get_string(conf, RSTRING_PTR(section), RSTRING_PTR(name));
+ str = NCONF_get_string(conf, RSTRING(section)->ptr, RSTRING(name)->ptr);
if(!str){
ERR_clear_error();
return Qnil;
@@ -245,8 +245,11 @@ set_conf_section_i(VALUE i, VALUE *arg)
static VALUE
ossl_config_set_section(VALUE self, VALUE section, VALUE hash)
{
- VALUE arg[2] = { self, section };
- rb_block_call(hash, rb_intern("each"), 0, 0, set_conf_section_i, (VALUE)arg);
+ VALUE arg[2];
+
+ arg[0] = self;
+ arg[1] = section;
+ rb_iterate(rb_each, hash, set_conf_section_i, (VALUE)arg);
return hash;
}
diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c
index 09eadc9c9c..4096b097a2 100644
--- a/ext/openssl/ossl_digest.c
+++ b/ext/openssl/ossl_digest.c
@@ -136,7 +136,7 @@ ossl_digest_update(VALUE self, VALUE data)
StringValue(data);
GetDigest(self, ctx);
- EVP_DigestUpdate(ctx, RSTRING_PTR(data), RSTRING_LEN(data));
+ EVP_DigestUpdate(ctx, RSTRING(data)->ptr, RSTRING(data)->len);
return self;
}
@@ -225,12 +225,12 @@ ossl_digest_equal(VALUE self, VALUE other)
str2 = other;
}
GetDigest(self, ctx);
- if (RSTRING_LEN(str2) == EVP_MD_CTX_size(ctx)) {
+ if (RSTRING(str2)->len == EVP_MD_CTX_size(ctx)) {
str1 = ossl_digest_digest(self);
} else {
str1 = ossl_digest_hexdigest(self);
}
- if (RSTRING_LEN(str1) == RSTRING_LEN(str2)
+ if (RSTRING(str1)->len == RSTRING(str2)->len
&& rb_str_cmp(str1, str2) == 0) {
return Qtrue;
}
@@ -264,6 +264,10 @@ ossl_digest_size(VALUE self)
void
Init_ossl_digest()
{
+#if 0 /* let rdoc know about mOSSL */
+ mOSSL = rb_define_module("OpenSSL");
+#endif
+
mDigest = rb_define_module_under(mOSSL, "Digest");
eDigestError = rb_define_class_under(mDigest, "DigestError", eOSSLError);
diff --git a/ext/openssl/ossl_engine.c b/ext/openssl/ossl_engine.c
index cd835d1237..71586e3620 100644
--- a/ext/openssl/ossl_engine.c
+++ b/ext/openssl/ossl_engine.c
@@ -40,7 +40,7 @@ VALUE eEngineError;
*/
#define OSSL_ENGINE_LOAD_IF_MATCH(x) \
do{\
- if(!strcmp(#x, RSTRING_PTR(name))){\
+ if(!strcmp(#x, RSTRING(name)->ptr)){\
ENGINE_load_##x();\
return Qtrue;\
}\
@@ -75,7 +75,7 @@ ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
OSSL_ENGINE_LOAD_IF_MATCH(openbsd_dev_crypto);
#endif
OSSL_ENGINE_LOAD_IF_MATCH(openssl);
- rb_warning("no such builtin loader for `%s'", RSTRING_PTR(name));
+ rb_warning("no such builtin loader for `%s'", RSTRING(name)->ptr);
return Qnil;
#endif /* HAVE_ENGINE_LOAD_BUILTIN_ENGINES */
}
@@ -112,7 +112,7 @@ ossl_engine_s_by_id(VALUE klass, VALUE id)
StringValue(id);
ossl_engine_s_load(1, &id, klass);
- if(!(e = ENGINE_by_id(RSTRING_PTR(id))))
+ if(!(e = ENGINE_by_id(RSTRING(id)->ptr)))
ossl_raise(eEngineError, NULL);
WrapEngine(klass, obj, e);
if(rb_block_given_p()) rb_yield(obj);
@@ -281,8 +281,8 @@ ossl_engine_ctrl_cmd(int argc, VALUE *argv, VALUE self)
rb_scan_args(argc, argv, "11", &cmd, &val);
StringValue(cmd);
if (!NIL_P(val)) StringValue(val);
- ret = ENGINE_ctrl_cmd_string(e, RSTRING_PTR(cmd),
- NIL_P(val) ? NULL : RSTRING_PTR(val), 0);
+ ret = ENGINE_ctrl_cmd_string(e, RSTRING(cmd)->ptr,
+ NIL_P(val) ? NULL : RSTRING(val)->ptr, 0);
if (!ret) ossl_raise(eEngineError, NULL);
return self;
diff --git a/ext/openssl/ossl_hmac.c b/ext/openssl/ossl_hmac.c
index 4ae04046e1..312343e03d 100644
--- a/ext/openssl/ossl_hmac.c
+++ b/ext/openssl/ossl_hmac.c
@@ -64,7 +64,7 @@ ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest)
StringValue(key);
GetHMAC(self, ctx);
- HMAC_Init_ex(ctx, RSTRING_PTR(key), RSTRING_LEN(key),
+ HMAC_Init_ex(ctx, RSTRING(key)->ptr, RSTRING(key)->len,
GetDigestPtr(digest), NULL);
return self;
@@ -94,7 +94,7 @@ ossl_hmac_update(VALUE self, VALUE data)
StringValue(data);
GetHMAC(self, ctx);
- HMAC_Update(ctx, RSTRING_PTR(data), RSTRING_LEN(data));
+ HMAC_Update(ctx, RSTRING(data)->ptr, RSTRING(data)->len);
return self;
}
@@ -159,8 +159,8 @@ ossl_hmac_s_digest(VALUE klass, VALUE digest, VALUE key, VALUE data)
StringValue(key);
StringValue(data);
- buf = HMAC(GetDigestPtr(digest), RSTRING_PTR(key), RSTRING_LEN(key),
- RSTRING_PTR(data), RSTRING_LEN(data), NULL, &buf_len);
+ buf = HMAC(GetDigestPtr(digest), RSTRING(key)->ptr, RSTRING(key)->len,
+ RSTRING(data)->ptr, RSTRING(data)->len, NULL, &buf_len);
return rb_str_new(buf, buf_len);
}
@@ -175,8 +175,8 @@ ossl_hmac_s_hexdigest(VALUE klass, VALUE digest, VALUE key, VALUE data)
StringValue(key);
StringValue(data);
- buf = HMAC(GetDigestPtr(digest), RSTRING_PTR(key), RSTRING_LEN(key),
- RSTRING_PTR(data), RSTRING_LEN(data), NULL, &buf_len);
+ buf = HMAC(GetDigestPtr(digest), RSTRING(key)->ptr, RSTRING(key)->len,
+ RSTRING(data)->ptr, RSTRING(data)->len, NULL, &buf_len);
if (string2hex(buf, buf_len, &hexbuf, NULL) != 2 * buf_len) {
ossl_raise(eHMACError, "Cannot convert buf to hexbuf");
}
@@ -191,6 +191,10 @@ ossl_hmac_s_hexdigest(VALUE klass, VALUE digest, VALUE key, VALUE data)
void
Init_ossl_hmac()
{
+#if 0 /* let rdoc know about mOSSL */
+ mOSSL = rb_define_module("OpenSSL");
+#endif
+
eHMACError = rb_define_class_under(mOSSL, "HMACError", eOSSLError);
cHMAC = rb_define_class_under(mOSSL, "HMAC", rb_cObject);
diff --git a/ext/openssl/ossl_ns_spki.c b/ext/openssl/ossl_ns_spki.c
index 738a203d93..66e28374cc 100644
--- a/ext/openssl/ossl_ns_spki.c
+++ b/ext/openssl/ossl_ns_spki.c
@@ -62,9 +62,9 @@ ossl_spki_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
StringValue(buffer);
- if (!(spki = NETSCAPE_SPKI_b64_decode(RSTRING_PTR(buffer), -1))) {
- p = RSTRING_PTR(buffer);
- if (!(spki = d2i_NETSCAPE_SPKI(NULL, &p, RSTRING_LEN(buffer)))) {
+ if (!(spki = NETSCAPE_SPKI_b64_decode(RSTRING(buffer)->ptr, -1))) {
+ p = RSTRING(buffer)->ptr;
+ if (!(spki = d2i_NETSCAPE_SPKI(NULL, &p, RSTRING(buffer)->len))) {
ossl_raise(eSPKIError, NULL);
}
}
@@ -87,7 +87,7 @@ ossl_spki_to_der(VALUE self)
if ((len = i2d_NETSCAPE_SPKI(spki, NULL)) <= 0)
ossl_raise(eX509CertError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if (i2d_NETSCAPE_SPKI(spki, &p) <= 0)
ossl_raise(eX509CertError, NULL);
ossl_str_adjust(str, p);
@@ -183,8 +183,8 @@ ossl_spki_set_challenge(VALUE self, VALUE str)
StringValue(str);
GetSPKI(self, spki);
- if (!ASN1_STRING_set(spki->spkac->challenge, RSTRING_PTR(str),
- RSTRING_LEN(str))) {
+ if (!ASN1_STRING_set(spki->spkac->challenge, RSTRING(str)->ptr,
+ RSTRING(str)->len)) {
ossl_raise(eSPKIError, NULL);
}
diff --git a/ext/openssl/ossl_ocsp.c b/ext/openssl/ossl_ocsp.c
index aa6bd61b3c..b5ea9dadf5 100644
--- a/ext/openssl/ossl_ocsp.c
+++ b/ext/openssl/ossl_ocsp.c
@@ -109,9 +109,9 @@ ossl_ocspreq_initialize(int argc, VALUE *argv, VALUE self)
if(!NIL_P(arg)){
arg = ossl_to_der_if_possible(arg);
StringValue(arg);
- p = (unsigned char*)RSTRING_PTR(arg);
+ p = (unsigned char*)RSTRING(arg)->ptr;
if(!d2i_OCSP_REQUEST((OCSP_REQUEST**)&DATA_PTR(self), &p,
- RSTRING_LEN(arg))){
+ RSTRING(arg)->len)){
ossl_raise(eOCSPError, "cannot load DER encoded request");
}
}
@@ -134,7 +134,7 @@ ossl_ocspreq_add_nonce(int argc, VALUE *argv, VALUE self)
else{
StringValue(val);
GetOCSPReq(self, req);
- ret = OCSP_request_add1_nonce(req, RSTRING_PTR(val), RSTRING_LEN(val));
+ ret = OCSP_request_add1_nonce(req, RSTRING(val)->ptr, RSTRING(val)->len);
}
if(!ret) ossl_raise(eOCSPError, NULL);
@@ -265,7 +265,7 @@ ossl_ocspreq_to_der(VALUE self)
if((len = i2d_OCSP_REQUEST(req, NULL)) <= 0)
ossl_raise(eOCSPError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_OCSP_REQUEST(req, &p) <= 0)
ossl_raise(eOCSPError, NULL);
ossl_str_adjust(str, p);
@@ -316,9 +316,9 @@ ossl_ocspres_initialize(int argc, VALUE *argv, VALUE self)
if(!NIL_P(arg)){
arg = ossl_to_der_if_possible(arg);
StringValue(arg);
- p = RSTRING_PTR(arg);
+ p = RSTRING(arg)->ptr;
if(!d2i_OCSP_RESPONSE((OCSP_RESPONSE**)&DATA_PTR(self), &p,
- RSTRING_LEN(arg))){
+ RSTRING(arg)->len)){
ossl_raise(eOCSPError, "cannot load DER encoded response");
}
}
@@ -377,7 +377,7 @@ ossl_ocspres_to_der(VALUE self)
if((len = i2d_OCSP_RESPONSE(res, NULL)) <= 0)
ossl_raise(eOCSPError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_OCSP_RESPONSE(res, NULL) <= 0)
ossl_raise(eOCSPError, NULL);
ossl_str_adjust(str, p);
@@ -436,7 +436,7 @@ ossl_ocspbres_add_nonce(int argc, VALUE *argv, VALUE self)
else{
StringValue(val);
GetOCSPBasicRes(self, bs);
- ret = OCSP_basic_add1_nonce(bs, RSTRING_PTR(val), RSTRING_LEN(val));
+ ret = OCSP_basic_add1_nonce(bs, RSTRING(val)->ptr, RSTRING(val)->len);
}
if(!ret) ossl_raise(eOCSPError, NULL);
@@ -461,8 +461,8 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
if(!NIL_P(ext)){
/* All ary's members should be X509Extension */
Check_Type(ext, T_ARRAY);
- for (i = 0; i < RARRAY_LEN(ext); i++)
- OSSL_Check_Kind(RARRAY_PTR(ext)[i], cX509Ext);
+ for (i = 0; i < RARRAY(ext)->len; i++)
+ OSSL_Check_Kind(RARRAY(ext)->ptr[i], cX509Ext);
}
error = 0;
@@ -490,8 +490,8 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
X509_EXTENSION *x509ext;
sk_X509_EXTENSION_pop_free(single->singleExtensions, X509_EXTENSION_free);
single->singleExtensions = NULL;
- for(i = 0; i < RARRAY_LEN(ext); i++){
- x509ext = DupX509ExtPtr(RARRAY_PTR(ext)[i]);
+ for(i = 0; i < RARRAY(ext)->len; i++){
+ x509ext = DupX509ExtPtr(RARRAY(ext)->ptr[i]);
if(!OCSP_SINGLERESP_add_ext(single, x509ext, -1)){
X509_EXTENSION_free(x509ext);
error = 1;
@@ -681,7 +681,7 @@ Init_ossl_ocsp()
{
mOCSP = rb_define_module_under(mOSSL, "OCSP");
- eOCSPError = rb_define_class_under(mOCSP, "OCSPError", rb_cObject);
+ eOCSPError = rb_define_class_under(mOCSP, "OCSPError", eOSSLError);
cOCSPReq = rb_define_class_under(mOCSP, "Request", rb_cObject);
rb_define_alloc_func(cOCSPReq, ossl_ocspreq_alloc);
diff --git a/ext/openssl/ossl_pkcs12.c b/ext/openssl/ossl_pkcs12.c
index 5336a60ecd..e7d9954c5a 100644
--- a/ext/openssl/ossl_pkcs12.c
+++ b/ext/openssl/ossl_pkcs12.c
@@ -129,7 +129,7 @@ ossl_pkcs12_to_der(VALUE self)
if((len = i2d_PKCS12(p12, NULL)) <= 0)
ossl_raise(ePKCS12Error, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_PKCS12(p12, &p) <= 0)
ossl_raise(ePKCS12Error, NULL);
ossl_str_adjust(str, p);
diff --git a/ext/openssl/ossl_pkcs5.h b/ext/openssl/ossl_pkcs5.h
new file mode 100644
index 0000000000..a3b132bc50
--- /dev/null
+++ b/ext/openssl/ossl_pkcs5.h
@@ -0,0 +1,6 @@
+#if !defined(_OSSL_PKCS5_H_)
+#define _OSSL_PKCS5_H_
+
+void Init_ossl_pkcs5(void);
+
+#endif /* _OSSL_PKCS5_H_ */
diff --git a/ext/openssl/ossl_pkcs7.c b/ext/openssl/ossl_pkcs7.c
index 04dd0d8d30..0fcabd7777 100644
--- a/ext/openssl/ossl_pkcs7.c
+++ b/ext/openssl/ossl_pkcs7.c
@@ -335,7 +335,7 @@ static int
ossl_pkcs7_sym2typeid(VALUE sym)
{
int i, ret = Qnil;
- const char *s;
+ char *s;
static struct {
const char *name;
@@ -583,7 +583,7 @@ ossl_pkcs7_set_certificates(VALUE self, VALUE ary)
certs = pkcs7_get_certs_or_crls(self, 1);
while((cert = sk_X509_pop(certs))) X509_free(cert);
- rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_certs_i, self);
+ rb_iterate(rb_each, ary, ossl_pkcs7_set_certs_i, self);
return ary;
}
@@ -623,7 +623,7 @@ ossl_pkcs7_set_crls(VALUE self, VALUE ary)
crls = pkcs7_get_certs_or_crls(self, 0);
while((crl = sk_X509_CRL_pop(crls))) X509_CRL_free(crl);
- rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_crls_i, self);
+ rb_iterate(rb_each, ary, ossl_pkcs7_set_crls_i, self);
return ary;
}
@@ -751,7 +751,7 @@ ossl_pkcs7_to_der(VALUE self)
if((len = i2d_PKCS7(pkcs7, NULL)) <= 0)
ossl_raise(ePKCS7Error, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_PKCS7(pkcs7, &p) <= 0)
ossl_raise(ePKCS7Error, NULL);
ossl_str_adjust(str, p);
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c
index 8858c65382..d54f5b938e 100644
--- a/ext/openssl/ossl_pkey.c
+++ b/ext/openssl/ossl_pkey.c
@@ -68,7 +68,7 @@ ossl_pkey_new_from_file(VALUE filename)
EVP_PKEY *pkey;
SafeStringValue(filename);
- if (!(fp = fopen(RSTRING_PTR(filename), "r"))) {
+ if (!(fp = fopen(RSTRING(filename)->ptr, "r"))) {
ossl_raise(ePKeyError, "%s", strerror(errno));
}
@@ -108,7 +108,7 @@ EVP_PKEY *
DupPKeyPtr(VALUE obj)
{
EVP_PKEY *pkey;
-
+
SafeGetPKey(obj, pkey);
CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
@@ -169,12 +169,13 @@ ossl_pkey_sign(VALUE self, VALUE digest, VALUE data)
GetPKey(self, pkey);
EVP_SignInit(&ctx, GetDigestPtr(digest));
StringValue(data);
- EVP_SignUpdate(&ctx, RSTRING_PTR(data), RSTRING_LEN(data));
+ EVP_SignUpdate(&ctx, RSTRING(data)->ptr, RSTRING(data)->len);
str = rb_str_new(0, EVP_PKEY_size(pkey)+16);
- if (!EVP_SignFinal(&ctx, RSTRING_PTR(str), &buf_len, pkey))
+ if (!EVP_SignFinal(&ctx, RSTRING(str)->ptr, &buf_len, pkey))
ossl_raise(ePKeyError, NULL);
- assert(buf_len <= RSTRING_LEN(str));
- rb_str_set_len(str, buf_len);
+ assert(buf_len <= RSTRING(str)->len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
@@ -189,8 +190,8 @@ ossl_pkey_verify(VALUE self, VALUE digest, VALUE sig, VALUE data)
EVP_VerifyInit(&ctx, GetDigestPtr(digest));
StringValue(sig);
StringValue(data);
- EVP_VerifyUpdate(&ctx, RSTRING_PTR(data), RSTRING_LEN(data));
- switch (EVP_VerifyFinal(&ctx, RSTRING_PTR(sig), RSTRING_LEN(sig), pkey)) {
+ EVP_VerifyUpdate(&ctx, RSTRING(data)->ptr, RSTRING(data)->len);
+ switch (EVP_VerifyFinal(&ctx, RSTRING(sig)->ptr, RSTRING(sig)->len, pkey)) {
case 0:
return Qfalse;
case 1:
@@ -207,6 +208,10 @@ ossl_pkey_verify(VALUE self, VALUE digest, VALUE sig, VALUE data)
void
Init_ossl_pkey()
{
+#if 0 /* let rdoc know about mOSSL */
+ mOSSL = rb_define_module("OpenSSL");
+#endif
+
mPKey = rb_define_module_under(mOSSL, "PKey");
ePKeyError = rb_define_class_under(mPKey, "PKeyError", eOSSLError);
diff --git a/ext/openssl/ossl_pkey_dh.c b/ext/openssl/ossl_pkey_dh.c
index c09508f70e..e16ede8bba 100644
--- a/ext/openssl/ossl_pkey_dh.c
+++ b/ext/openssl/ossl_pkey_dh.c
@@ -213,7 +213,7 @@ ossl_dh_to_der(VALUE self)
if((len = i2d_DHparams(pkey->pkey.dh, NULL)) <= 0)
ossl_raise(eDHError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_DHparams(pkey->pkey.dh, &p) < 0)
ossl_raise(eDHError, NULL);
ossl_str_adjust(str, p);
@@ -335,10 +335,11 @@ ossl_dh_compute_key(VALUE self, VALUE pub)
pub_key = GetBNPtr(pub);
len = DH_size(dh);
str = rb_str_new(0, len);
- if ((len = DH_compute_key(RSTRING_PTR(str), pub_key, dh)) < 0) {
+ if ((len = DH_compute_key(RSTRING(str)->ptr, pub_key, dh)) < 0) {
ossl_raise(eDHError, NULL);
}
- rb_str_set_len(str, len);
+ RSTRING(str)->len = len;
+ RSTRING(str)->ptr[len] = 0;
return str;
}
@@ -366,7 +367,7 @@ static unsigned char DEFAULT_DH_512_PRIM[] = {
};
static unsigned char DEFAULT_DH_512_GEN[] = { 0x02 };
DH *OSSL_DEFAULT_DH_512 = NULL;
-
+
/*
* -----BEGIN DH PARAMETERS-----
* MIGHAoGBAJ0lOVy0VIr/JebWn0zDwY2h+rqITFOpdNr6ugsgvkDXuucdcChhYExJ
@@ -405,7 +406,7 @@ ossl_create_dh(unsigned char *p, size_t plen, unsigned char *g, size_t glen)
dh->g = BN_bin2bn(g, glen, NULL);
if (dh->p == NULL || dh->g == NULL){
DH_free(dh);
- ossl_raise(eDHError, NULL);
+ ossl_raise(eDHError, NULL);
}
return dh;
@@ -417,6 +418,11 @@ ossl_create_dh(unsigned char *p, size_t plen, unsigned char *g, size_t glen)
void
Init_ossl_dh()
{
+#if 0 /* let rdoc know about mOSSL and mPKey */
+ mOSSL = rb_define_module("OpenSSL");
+ mPKey = rb_define_module_under(mOSSL, "PKey");
+#endif
+
eDHError = rb_define_class_under(mPKey, "DHError", ePKeyError);
cDH = rb_define_class_under(mPKey, "DH", cPKey);
rb_define_singleton_method(cDH, "generate", ossl_dh_s_generate, -1);
diff --git a/ext/openssl/ossl_pkey_dsa.c b/ext/openssl/ossl_pkey_dsa.c
index 76675df512..fdf23aa496 100644
--- a/ext/openssl/ossl_pkey_dsa.c
+++ b/ext/openssl/ossl_pkey_dsa.c
@@ -241,7 +241,7 @@ ossl_dsa_to_der(VALUE self)
if((len = i2d_func(pkey->pkey.dsa, NULL)) <= 0)
ossl_raise(eDSAError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_func(pkey->pkey.dsa, &p) < 0)
ossl_raise(eDSAError, NULL);
ossl_str_adjust(str, p);
@@ -334,11 +334,12 @@ ossl_dsa_sign(VALUE self, VALUE data)
ossl_raise(eDSAError, "Private DSA key needed!");
}
str = rb_str_new(0, ossl_dsa_buf_size(pkey));
- if (!DSA_sign(0, RSTRING_PTR(data), RSTRING_LEN(data), RSTRING_PTR(str),
+ if (!DSA_sign(0, RSTRING(data)->ptr, RSTRING(data)->len, RSTRING(str)->ptr,
&buf_len, pkey->pkey.dsa)) { /* type is ignored (0) */
ossl_raise(eDSAError, NULL);
}
- rb_str_set_len(str, buf_len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
@@ -353,8 +354,8 @@ ossl_dsa_verify(VALUE self, VALUE digest, VALUE sig)
StringValue(digest);
StringValue(sig);
/* type is ignored (0) */
- ret = DSA_verify(0, RSTRING_PTR(digest), RSTRING_LEN(digest),
- RSTRING_PTR(sig), RSTRING_LEN(sig), pkey->pkey.dsa);
+ ret = DSA_verify(0, RSTRING(digest)->ptr, RSTRING(digest)->len,
+ RSTRING(sig)->ptr, RSTRING(sig)->len, pkey->pkey.dsa);
if (ret < 0) {
ossl_raise(eDSAError, NULL);
}
@@ -377,6 +378,11 @@ OSSL_PKEY_BN(dsa, priv_key);
void
Init_ossl_dsa()
{
+#if 0 /* let rdoc know about mOSSL and mPKey */
+ mOSSL = rb_define_module("OpenSSL");
+ mPKey = rb_define_module_under(mOSSL, "PKey");
+#endif
+
eDSAError = rb_define_class_under(mPKey, "DSAError", ePKeyError);
cDSA = rb_define_class_under(mPKey, "DSA", cPKey);
diff --git a/ext/openssl/ossl_pkey_rsa.c b/ext/openssl/ossl_pkey_rsa.c
index 35f522f852..0afdcf8d01 100644
--- a/ext/openssl/ossl_pkey_rsa.c
+++ b/ext/openssl/ossl_pkey_rsa.c
@@ -236,7 +236,7 @@ ossl_rsa_to_der(VALUE self)
if((len = i2d_func(pkey->pkey.rsa, NULL)) <= 0)
ossl_raise(eRSAError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_func(pkey->pkey.rsa, &p) < 0)
ossl_raise(eRSAError, NULL);
ossl_str_adjust(str, p);
@@ -258,11 +258,12 @@ ossl_rsa_public_encrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
- buf_len = RSA_public_encrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
- RSTRING_PTR(str), pkey->pkey.rsa,
+ buf_len = RSA_public_encrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
+ RSTRING(str)->ptr, pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
- rb_str_set_len(str, buf_len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
@@ -279,11 +280,12 @@ ossl_rsa_public_decrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
- buf_len = RSA_public_decrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
- RSTRING_PTR(str), pkey->pkey.rsa,
+ buf_len = RSA_public_decrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
+ RSTRING(str)->ptr, pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
- rb_str_set_len(str, buf_len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
@@ -303,11 +305,12 @@ ossl_rsa_private_encrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
- buf_len = RSA_private_encrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
- RSTRING_PTR(str), pkey->pkey.rsa,
+ buf_len = RSA_private_encrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
+ RSTRING(str)->ptr, pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
- rb_str_set_len(str, buf_len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
@@ -327,11 +330,12 @@ ossl_rsa_private_decrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
- buf_len = RSA_private_decrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
- RSTRING_PTR(str), pkey->pkey.rsa,
+ buf_len = RSA_private_decrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
+ RSTRING(str)->ptr, pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
- rb_str_set_len(str, buf_len);
+ RSTRING(str)->len = buf_len;
+ RSTRING(str)->ptr[buf_len] = 0;
return str;
}
@@ -455,6 +459,11 @@ OSSL_PKEY_BN(rsa, iqmp);
void
Init_ossl_rsa()
{
+#if 0 /* let rdoc know about mOSSL and mPKey */
+ mOSSL = rb_define_module("OpenSSL");
+ mPKey = rb_define_module_under(mOSSL, "PKey");
+#endif
+
eRSAError = rb_define_class_under(mPKey, "RSAError", ePKeyError);
cRSA = rb_define_class_under(mPKey, "RSA", cPKey);
diff --git a/ext/openssl/ossl_rand.c b/ext/openssl/ossl_rand.c
index a4247ec013..71bb3bedd5 100644
--- a/ext/openssl/ossl_rand.c
+++ b/ext/openssl/ossl_rand.c
@@ -31,7 +31,7 @@ static VALUE
ossl_rand_seed(VALUE self, VALUE str)
{
StringValue(str);
- RAND_seed(RSTRING_PTR(str), RSTRING_LEN(str));
+ RAND_seed(RSTRING(str)->ptr, RSTRING(str)->len);
return str;
}
@@ -41,7 +41,7 @@ ossl_rand_load_file(VALUE self, VALUE filename)
{
SafeStringValue(filename);
- if(!RAND_load_file(RSTRING_PTR(filename), -1)) {
+ if(!RAND_load_file(RSTRING(filename)->ptr, -1)) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
@@ -51,7 +51,7 @@ static VALUE
ossl_rand_write_file(VALUE self, VALUE filename)
{
SafeStringValue(filename);
- if (RAND_write_file(RSTRING_PTR(filename)) == -1) {
+ if (RAND_write_file(RSTRING(filename)->ptr) == -1) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
@@ -63,7 +63,7 @@ ossl_rand_bytes(VALUE self, VALUE len)
VALUE str;
str = rb_str_new(0, FIX2INT(len));
- if (!RAND_bytes(RSTRING_PTR(str), FIX2INT(len))) {
+ if (!RAND_bytes(RSTRING(str)->ptr, FIX2INT(len))) {
ossl_raise(eRandomError, NULL);
}
@@ -76,7 +76,7 @@ ossl_rand_pseudo_bytes(VALUE self, VALUE len)
VALUE str;
str = rb_str_new(0, FIX2INT(len));
- if (!RAND_pseudo_bytes(RSTRING_PTR(str), FIX2INT(len))) {
+ if (!RAND_pseudo_bytes(RSTRING(str)->ptr, FIX2INT(len))) {
ossl_raise(eRandomError, NULL);
}
@@ -88,7 +88,7 @@ ossl_rand_egd(VALUE self, VALUE filename)
{
SafeStringValue(filename);
- if(!RAND_egd(RSTRING_PTR(filename))) {
+ if(!RAND_egd(RSTRING(filename)->ptr)) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
@@ -99,7 +99,7 @@ ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len)
{
SafeStringValue(filename);
- if (!RAND_egd_bytes(RSTRING_PTR(filename), FIX2INT(len))) {
+ if (!RAND_egd_bytes(RSTRING(filename)->ptr, FIX2INT(len))) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
@@ -115,6 +115,10 @@ ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len)
void
Init_ossl_rand()
{
+#if 0 /* let rdoc know about mOSSL */
+ mOSSL = rb_define_module("OpenSSL");
+#endif
+
mRandom = rb_define_module_under(mOSSL, "Random");
eRandomError = rb_define_class_under(mRandom, "RandomError", eOSSLError);
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index d956c908be..8e632b526b 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -30,6 +30,9 @@ VALUE eSSLError;
VALUE cSSLContext;
VALUE cSSLSocket;
+/*
+ * SSLContext class
+ */
#define ossl_sslctx_set_cert(o,v) rb_iv_set((o),"@cert",(v))
#define ossl_sslctx_set_key(o,v) rb_iv_set((o),"@key",(v))
#define ossl_sslctx_set_client_ca(o,v) rb_iv_set((o),"@client_ca",(v))
@@ -62,7 +65,7 @@ VALUE cSSLSocket;
#define ossl_sslctx_get_tmp_dh_cb(o) rb_iv_get((o),"@tmp_dh_callback")
#define ossl_sslctx_get_sess_id_ctx(o) rb_iv_get((o),"@session_id_context")
-static const char *ossl_sslctx_attrs[] = {
+static char *ossl_sslctx_attrs[] = {
"cert", "key", "client_ca", "ca_file", "ca_path",
"timeout", "verify_mode", "verify_depth",
"verify_callback", "options", "cert_store", "extra_chain_cert",
@@ -83,8 +86,8 @@ static const char *ossl_sslctx_attrs[] = {
#define ossl_ssl_set_key(o,v) rb_iv_set((o),"@key",(v))
#define ossl_ssl_set_tmp_dh(o,v) rb_iv_set((o),"@tmp_dh",(v))
-static const char *ossl_ssl_attr_readers[] = { "io", "context", };
-static const char *ossl_ssl_attrs[] = { "sync_close", };
+static char *ossl_ssl_attr_readers[] = { "io", "context", };
+static char *ossl_ssl_attrs[] = { "sync_close", };
/*
* SSLContext class
@@ -144,7 +147,7 @@ ossl_sslctx_initialize(int argc, VALUE *argv, VALUE self)
SSL_METHOD *method = NULL;
SSL_CTX *ctx;
int i;
- const char *s;
+ char *s;
for(i = 0; i < numberof(ossl_sslctx_attrs); i++){
char buf[32];
@@ -324,7 +327,7 @@ ossl_sslctx_setup(VALUE self)
val = ossl_sslctx_get_extra_cert(self);
if(!NIL_P(val)){
- rb_block_call(val, rb_intern("each"), 0, 0, ossl_sslctx_add_extra_chain_cert_i, self);
+ rb_iterate(rb_each, val, ossl_sslctx_add_extra_chain_cert_i, self);
}
/* private key may be bundled in certificate file. */
@@ -349,8 +352,8 @@ ossl_sslctx_setup(VALUE self)
val = ossl_sslctx_get_client_ca(self);
if(!NIL_P(val)){
if(TYPE(val) == T_ARRAY){
- for(i = 0; i < RARRAY_LEN(val); i++){
- client_ca = GetX509CertPtr(RARRAY_PTR(val)[i]);
+ for(i = 0; i < RARRAY(val)->len; i++){
+ client_ca = GetX509CertPtr(RARRAY(val)->ptr[i]);
if (!SSL_CTX_add_client_CA(ctx, client_ca)){
/* Copies X509_NAME => FREE it. */
ossl_raise(eSSLError, "SSL_CTX_add_client_CA");
@@ -394,9 +397,9 @@ ossl_sslctx_setup(VALUE self)
val = ossl_sslctx_get_sess_id_ctx(self);
if (!NIL_P(val)){
StringValue(val);
- if (!SSL_CTX_set_session_id_context(ctx, RSTRING_PTR(val),
- RSTRING_LEN(val))){
- ossl_raise(eSSLError, "SSL_CTX_set_session_id_context:");
+ if (!SSL_CTX_set_session_id_context(ctx, RSTRING(val)->ptr,
+ RSTRING(val)->len)){
+ ossl_raise(eSSLError, "SSL_CTX_set_session_id_context:");
}
}
@@ -459,12 +462,12 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
return v;
else if (TYPE(v) == T_ARRAY) {
str = rb_str_new(0, 0);
- for (i = 0; i < RARRAY_LEN(v); i++) {
+ for (i = 0; i < RARRAY(v)->len; i++) {
elem = rb_ary_entry(v, i);
if (TYPE(elem) == T_ARRAY) elem = rb_ary_entry(elem, 0);
elem = rb_String(elem);
rb_str_append(str, elem);
- if (i < RARRAY_LEN(v)-1) rb_str_cat2(str, ":");
+ if (i < RARRAY(v)->len-1) rb_str_cat2(str, ":");
}
} else {
str = v;
@@ -476,7 +479,7 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
ossl_raise(eSSLError, "SSL_CTX is not initialized.");
return Qnil;
}
- if (!SSL_CTX_set_cipher_list(ctx, RSTRING_PTR(str))) {
+ if (!SSL_CTX_set_cipher_list(ctx, RSTRING(str)->ptr)) {
ossl_raise(eSSLError, "SSL_CTX_set_cipher_list:");
}
@@ -550,7 +553,7 @@ ossl_ssl_setup(VALUE self)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
rb_io_check_writable(fptr);
- SSL_set_fd(ssl, TO_SOCKET(fptr->fd));
+ SSL_set_fd(ssl, TO_SOCKET(fileno(fptr->f)));
SSL_set_ex_data(ssl, ossl_ssl_ex_ptr_idx, (void*)self);
cb = ossl_sslctx_get_verify_cb(v_ctx);
SSL_set_ex_data(ssl, ossl_ssl_ex_vcb_idx, (void*)cb);
@@ -564,7 +567,8 @@ ossl_ssl_setup(VALUE self)
}
#ifdef _WIN32
-#define ssl_get_error(ssl, ret) (errno = WSAGetLastError(), SSL_get_error(ssl, ret))
+#define ssl_get_error(ssl, ret) \
+ (errno = WSAGetLastError(), SSL_get_error(ssl, ret))
#else
#define ssl_get_error(ssl, ret) SSL_get_error(ssl, ret)
#endif
@@ -582,10 +586,10 @@ ossl_start_ssl(VALUE self, int (*func)())
if((ret = func(ssl)) > 0) break;
switch(ssl_get_error(ssl, ret)){
case SSL_ERROR_WANT_WRITE:
- rb_io_wait_writable(fptr->fd);
+ rb_io_wait_writable(fileno(fptr->f));
continue;
case SSL_ERROR_WANT_READ:
- rb_io_wait_readable(fptr->fd);
+ rb_io_wait_readable(fileno(fptr->f));
continue;
case SSL_ERROR_SYSCALL:
if (errno) rb_sys_fail(0);
@@ -633,19 +637,19 @@ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
GetOpenFile(ossl_ssl_get_io(self), fptr);
if (ssl) {
if(SSL_pending(ssl) <= 0)
- rb_thread_wait_fd(fptr->fd);
+ rb_thread_wait_fd(fileno(fptr->f));
for (;;){
- nread = SSL_read(ssl, RSTRING_PTR(str), RSTRING_LEN(str));
+ nread = SSL_read(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
switch(ssl_get_error(ssl, nread)){
case SSL_ERROR_NONE:
goto end;
case SSL_ERROR_ZERO_RETURN:
rb_eof_error();
case SSL_ERROR_WANT_WRITE:
- rb_io_wait_writable(fptr->fd);
+ rb_io_wait_writable(fileno(fptr->f));
continue;
case SSL_ERROR_WANT_READ:
- rb_io_wait_readable(fptr->fd);
+ rb_io_wait_readable(fileno(fptr->f));
continue;
case SSL_ERROR_SYSCALL:
if(ERR_peek_error() == 0 && nread == 0) rb_eof_error();
@@ -662,7 +666,8 @@ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
}
end:
- rb_str_set_len(str, nread);
+ RSTRING(str)->len = nread;
+ RSTRING(str)->ptr[nread] = 0;
OBJ_TAINT(str);
return str;
@@ -681,15 +686,15 @@ ossl_ssl_write(VALUE self, VALUE str)
if (ssl) {
for (;;){
- nwrite = SSL_write(ssl, RSTRING_PTR(str), RSTRING_LEN(str));
+ nwrite = SSL_write(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
switch(ssl_get_error(ssl, nwrite)){
case SSL_ERROR_NONE:
goto end;
case SSL_ERROR_WANT_WRITE:
- rb_io_wait_writable(fptr->fd);
+ rb_io_wait_writable(fileno(fptr->f));
continue;
case SSL_ERROR_WANT_READ:
- rb_io_wait_readable(fptr->fd);
+ rb_io_wait_readable(fileno(fptr->f));
continue;
case SSL_ERROR_SYSCALL:
if (errno) rb_sys_fail(0);
@@ -850,6 +855,10 @@ Init_ossl_ssl()
{
int i;
+#if 0 /* let rdoc know about mOSSL */
+ mOSSL = rb_define_module("OpenSSL");
+#endif
+
ossl_ssl_ex_vcb_idx = SSL_get_ex_new_index(0,"ossl_ssl_ex_vcb_idx",0,0,0);
ossl_ssl_ex_store_p = SSL_get_ex_new_index(0,"ossl_ssl_ex_store_p",0,0,0);
ossl_ssl_ex_ptr_idx = SSL_get_ex_new_index(0,"ossl_ssl_ex_ptr_idx",0,0,0);
diff --git a/ext/openssl/ossl_x509attr.c b/ext/openssl/ossl_x509attr.c
index 267bd81855..7b88e294a9 100644
--- a/ext/openssl/ossl_x509attr.c
+++ b/ext/openssl/ossl_x509attr.c
@@ -95,9 +95,9 @@ ossl_x509attr_initialize(int argc, VALUE *argv, VALUE self)
if(rb_scan_args(argc, argv, "11", &oid, &value) == 1){
oid = ossl_to_der_if_possible(oid);
StringValue(oid);
- p = RSTRING_PTR(oid);
+ p = RSTRING(oid)->ptr;
if(!d2i_X509_ATTRIBUTE((X509_ATTRIBUTE**)&DATA_PTR(self),
- &p, RSTRING_LEN(oid))){
+ &p, RSTRING(oid)->len)){
ossl_raise(eX509AttrError, NULL);
}
return self;
@@ -192,7 +192,7 @@ ossl_x509attr_get_value(VALUE self)
if(OSSL_X509ATTR_IS_SINGLE(attr)){
length = i2d_ASN1_TYPE(attr->value.single, NULL);
str = rb_str_new(0, length);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
i2d_ASN1_TYPE(attr->value.single, &p);
ossl_str_adjust(str, p);
}
@@ -200,7 +200,7 @@ ossl_x509attr_get_value(VALUE self)
length = i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, NULL,
i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0);
str = rb_str_new(0, length);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, &p,
i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0);
ossl_str_adjust(str, p);
@@ -222,10 +222,10 @@ ossl_x509attr_to_der(VALUE self)
if((len = i2d_X509_ATTRIBUTE(attr, NULL)) <= 0)
ossl_raise(eX509AttrError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_X509_ATTRIBUTE(attr, &p) <= 0)
ossl_raise(eX509AttrError, NULL);
- rb_str_set_len(str, p - (unsigned char*)RSTRING_PTR(str));
+ RSTRING(str)->len = p - (unsigned char*)RSTRING(str)->ptr;
return str;
}
diff --git a/ext/openssl/ossl_x509cert.c b/ext/openssl/ossl_x509cert.c
index 0276764f83..fc587a31f3 100644
--- a/ext/openssl/ossl_x509cert.c
+++ b/ext/openssl/ossl_x509cert.c
@@ -63,7 +63,7 @@ ossl_x509_new_from_file(VALUE filename)
VALUE obj;
SafeStringValue(filename);
- if (!(fp = fopen(RSTRING_PTR(filename), "r"))) {
+ if (!(fp = fopen(RSTRING(filename)->ptr, "r"))) {
ossl_raise(eX509CertError, "%s", strerror(errno));
}
x509 = PEM_read_X509(fp, NULL, NULL, NULL);
@@ -181,7 +181,7 @@ ossl_x509_to_der(VALUE self)
if ((len = i2d_X509(x509, NULL)) <= 0)
ossl_raise(eX509CertError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if (i2d_X509(x509, &p) <= 0)
ossl_raise(eX509CertError, NULL);
ossl_str_adjust(str, p);
@@ -557,14 +557,14 @@ ossl_x509_set_extensions(VALUE self, VALUE ary)
Check_Type(ary, T_ARRAY);
/* All ary's members should be X509Extension */
- for (i=0; i<RARRAY_LEN(ary); i++) {
- OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
}
GetX509(self, x509);
sk_X509_EXTENSION_pop_free(x509->cert_info->extensions, X509_EXTENSION_free);
x509->cert_info->extensions = NULL;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- ext = DupX509ExtPtr(RARRAY_PTR(ary)[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ ext = DupX509ExtPtr(RARRAY(ary)->ptr[i]);
if (!X509_add_ext(x509, ext, -1)) { /* DUPs ext - FREE it */
X509_EXTENSION_free(ext);
diff --git a/ext/openssl/ossl_x509crl.c b/ext/openssl/ossl_x509crl.c
index be9ddacf48..0dc22416e7 100644
--- a/ext/openssl/ossl_x509crl.c
+++ b/ext/openssl/ossl_x509crl.c
@@ -287,14 +287,14 @@ ossl_x509crl_set_revoked(VALUE self, VALUE ary)
Check_Type(ary, T_ARRAY);
/* All ary members should be X509 Revoked */
- for (i=0; i<RARRAY_LEN(ary); i++) {
- OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Rev);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Rev);
}
GetX509CRL(self, crl);
sk_X509_REVOKED_pop_free(crl->crl->revoked, X509_REVOKED_free);
crl->crl->revoked = NULL;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- rev = DupX509RevokedPtr(RARRAY_PTR(ary)[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ rev = DupX509RevokedPtr(RARRAY(ary)->ptr[i]);
if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
ossl_raise(eX509CRLError, NULL);
}
@@ -461,14 +461,14 @@ ossl_x509crl_set_extensions(VALUE self, VALUE ary)
Check_Type(ary, T_ARRAY);
/* All ary members should be X509 Extensions */
- for (i=0; i<RARRAY_LEN(ary); i++) {
- OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
}
GetX509CRL(self, crl);
sk_X509_EXTENSION_pop_free(crl->crl->extensions, X509_EXTENSION_free);
crl->crl->extensions = NULL;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- ext = DupX509ExtPtr(RARRAY_PTR(ary)[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ ext = DupX509ExtPtr(RARRAY(ary)->ptr[i]);
if(!X509_CRL_add_ext(crl, ext, -1)) { /* DUPs ext - FREE it */
X509_EXTENSION_free(ext);
ossl_raise(eX509CRLError, NULL);
diff --git a/ext/openssl/ossl_x509ext.c b/ext/openssl/ossl_x509ext.c
index aa9366f901..31ffec48fa 100644
--- a/ext/openssl/ossl_x509ext.c
+++ b/ext/openssl/ossl_x509ext.c
@@ -229,23 +229,23 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
StringValue(value);
if(NIL_P(critical)) critical = Qfalse;
- nid = OBJ_ln2nid(RSTRING_PTR(oid));
- if(!nid) nid = OBJ_sn2nid(RSTRING_PTR(oid));
- if(!nid) ossl_raise(eX509ExtError, "unknown OID `%s'", RSTRING_PTR(oid));
+ nid = OBJ_ln2nid(RSTRING(oid)->ptr);
+ if(!nid) nid = OBJ_sn2nid(RSTRING(oid)->ptr);
+ if(!nid) ossl_raise(eX509ExtError, "unknown OID `%s'", RSTRING(oid)->ptr);
valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
rb_str_append(valstr, value);
GetX509ExtFactory(self, ctx);
#ifdef HAVE_X509V3_EXT_NCONF_NID
rconf = rb_iv_get(self, "@config");
conf = NIL_P(rconf) ? NULL : GetConfigPtr(rconf);
- ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING_PTR(valstr));
+ ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING(valstr)->ptr);
#else
if (!empty_lhash) empty_lhash = lh_new(NULL, NULL);
- ext = X509V3_EXT_conf_nid(empty_lhash, ctx, nid, RSTRING_PTR(valstr));
+ ext = X509V3_EXT_conf_nid(empty_lhash, ctx, nid, RSTRING(valstr)->ptr);
#endif
if (!ext){
ossl_raise(eX509ExtError, "%s = %s",
- RSTRING_PTR(oid), RSTRING_PTR(value));
+ RSTRING(oid)->ptr, RSTRING(value)->ptr);
}
WrapX509Ext(cX509Ext, obj, ext);
@@ -280,9 +280,9 @@ ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self)
if(rb_scan_args(argc, argv, "12", &oid, &value, &critical) == 1){
oid = ossl_to_der_if_possible(oid);
StringValue(oid);
- p = RSTRING_PTR(oid);
+ p = RSTRING(oid)->ptr;
if(!d2i_X509_EXTENSION((X509_EXTENSION**)&DATA_PTR(self),
- &p, RSTRING_LEN(oid)))
+ &p, RSTRING(oid)->len))
ossl_raise(eX509ExtError, NULL);
return self;
}
@@ -319,14 +319,14 @@ ossl_x509ext_set_value(VALUE self, VALUE data)
data = ossl_to_der_if_possible(data);
StringValue(data);
- if(!(s = OPENSSL_malloc(RSTRING_LEN(data))))
+ if(!(s = OPENSSL_malloc(RSTRING(data)->len)))
ossl_raise(eX509ExtError, "malloc error");
- memcpy(s, RSTRING_PTR(data), RSTRING_LEN(data));
+ memcpy(s, RSTRING(data)->ptr, RSTRING(data)->len);
if(!(asn1s = ASN1_OCTET_STRING_new())){
free(s);
ossl_raise(eX509ExtError, NULL);
}
- if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING_LEN(data))){
+ if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING(data)->len)){
free(s);
ASN1_OCTET_STRING_free(asn1s);
ossl_raise(eX509ExtError, NULL);
@@ -409,7 +409,7 @@ ossl_x509ext_to_der(VALUE obj)
if((len = i2d_X509_EXTENSION(ext, NULL)) <= 0)
ossl_raise(eX509ExtError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_X509_EXTENSION(ext, &p) < 0)
ossl_raise(eX509ExtError, NULL);
ossl_str_adjust(str, p);
diff --git a/ext/openssl/ossl_x509name.c b/ext/openssl/ossl_x509name.c
index 7af3b689dd..076d61fb96 100644
--- a/ext/openssl/ossl_x509name.c
+++ b/ext/openssl/ossl_x509name.c
@@ -125,14 +125,14 @@ ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
VALUE args;
if(NIL_P(template)) template = OBJECT_TYPE_TEMPLATE;
args = rb_ary_new3(2, self, template);
- rb_block_call(tmp, rb_intern("each"), 0, 0, ossl_x509name_init_i, args);
+ rb_iterate(rb_each, tmp, ossl_x509name_init_i, args);
}
else{
unsigned char *p;
VALUE str = ossl_to_der_if_possible(arg);
StringValue(str);
- p = RSTRING_PTR(str);
- if(!d2i_X509_NAME((X509_NAME**)&DATA_PTR(self), &p, RSTRING_LEN(str))){
+ p = RSTRING(str)->ptr;
+ if(!d2i_X509_NAME((X509_NAME**)&DATA_PTR(self), &p, RSTRING(str)->len)){
ossl_raise(eX509NameError, NULL);
}
}
@@ -152,8 +152,8 @@ VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
StringValue(value);
if(NIL_P(type)) type = rb_aref(OBJECT_TYPE_TEMPLATE, oid);
GetX509Name(self, name);
- if (!X509_NAME_add_entry_by_txt(name, RSTRING_PTR(oid), NUM2INT(type),
- RSTRING_PTR(value), RSTRING_LEN(value), -1, 0)) {
+ if (!X509_NAME_add_entry_by_txt(name, RSTRING(oid)->ptr, NUM2INT(type),
+ RSTRING(value)->ptr, RSTRING(value)->len, -1, 0)) {
ossl_raise(eX509NameError, NULL);
}
@@ -177,7 +177,7 @@ ossl_x509name_to_s_old(VALUE self)
static VALUE
ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
-{
+{
X509_NAME *name;
VALUE flag, str;
BIO *out;
@@ -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())))
- rb_raise(eX509NameError, NULL);
+ ossl_raise(eX509NameError, NULL);
GetX509Name(self, name);
if (!X509_NAME_print_ex(out, name, 0, iflag)){
BIO_free(out);
- rb_raise(eX509NameError, NULL);
+ ossl_raise(eX509NameError, NULL);
}
str = ossl_membio2str(out);
@@ -291,7 +291,7 @@ ossl_x509name_to_der(VALUE self)
if((len = i2d_X509_NAME(name, NULL)) <= 0)
ossl_raise(eX509NameError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if(i2d_X509_NAME(name, &p) <= 0)
ossl_raise(eX509NameError, NULL);
ossl_str_adjust(str, p);
diff --git a/ext/openssl/ossl_x509req.c b/ext/openssl/ossl_x509req.c
index 13a42dddaf..d644250433 100644
--- a/ext/openssl/ossl_x509req.c
+++ b/ext/openssl/ossl_x509req.c
@@ -171,7 +171,7 @@ ossl_x509req_to_der(VALUE self)
if ((len = i2d_X509_REQ(req, NULL)) <= 0)
ossl_raise(eX509CertError, NULL);
str = rb_str_new(0, len);
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
if (i2d_X509_REQ(req, &p) <= 0)
ossl_raise(eX509ReqError, NULL);
ossl_str_adjust(str, p);
@@ -403,14 +403,14 @@ ossl_x509req_set_attributes(VALUE self, VALUE ary)
VALUE item;
Check_Type(ary, T_ARRAY);
- for (i=0;i<RARRAY_LEN(ary); i++) {
- OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Attr);
+ for (i=0;i<RARRAY(ary)->len; i++) {
+ OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Attr);
}
GetX509Req(self, req);
sk_X509_ATTRIBUTE_pop_free(req->req_info->attributes, X509_ATTRIBUTE_free);
req->req_info->attributes = NULL;
- for (i=0;i<RARRAY_LEN(ary); i++) {
- item = RARRAY_PTR(ary)[i];
+ for (i=0;i<RARRAY(ary)->len; i++) {
+ item = RARRAY(ary)->ptr[i];
attr = DupX509AttrPtr(item);
if (!X509_REQ_add1_attr(req, attr)) {
ossl_raise(eX509ReqError, NULL);
diff --git a/ext/openssl/ossl_x509revoked.c b/ext/openssl/ossl_x509revoked.c
index d0f816bad4..3ccac8d26a 100644
--- a/ext/openssl/ossl_x509revoked.c
+++ b/ext/openssl/ossl_x509revoked.c
@@ -175,14 +175,14 @@ ossl_x509revoked_set_extensions(VALUE self, VALUE ary)
VALUE item;
Check_Type(ary, T_ARRAY);
- for (i=0; i<RARRAY_LEN(ary); i++) {
- OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
}
GetX509Rev(self, rev);
sk_X509_EXTENSION_pop_free(rev->extensions, X509_EXTENSION_free);
rev->extensions = NULL;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- item = RARRAY_PTR(ary)[i];
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ item = RARRAY(ary)->ptr[i];
ext = DupX509ExtPtr(item);
if(!X509_REVOKED_add_ext(rev, ext, -1)) {
ossl_raise(eX509RevError, NULL);
diff --git a/ext/openssl/ossl_x509store.c b/ext/openssl/ossl_x509store.c
index 64f5bca831..cea845a1cc 100644
--- a/ext/openssl/ossl_x509store.c
+++ b/ext/openssl/ossl_x509store.c
@@ -206,7 +206,7 @@ ossl_x509store_add_file(VALUE self, VALUE file)
if(file != Qnil){
Check_SafeStr(file);
- path = RSTRING_PTR(file);
+ path = RSTRING(file)->ptr;
}
GetX509Store(self, store);
lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
@@ -227,7 +227,7 @@ ossl_x509store_add_path(VALUE self, VALUE dir)
if(dir != Qnil){
Check_SafeStr(dir);
- path = RSTRING_PTR(dir);
+ path = RSTRING(dir)->ptr;
}
GetX509Store(self, store);
lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
diff --git a/ext/pty/.cvsignore b/ext/pty/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/pty/.cvsignore
+++ b/ext/pty/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/pty/lib/expect.rb b/ext/pty/lib/expect.rb
index aa9ab895d3..08191b05b9 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).nil? then
+ if !IO.select([self],nil,nil,timeout) or eof? then
result = nil
break
end
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index 215f2cfd6d..206d4cd131 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -1,7 +1,4 @@
#include "config.h"
-#ifdef RUBY_EXTCONF_H
-#include RUBY_EXTCONF_H
-#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -121,7 +118,8 @@ static char SlaveName[DEVICELEN];
static VALUE eChildExited;
static VALUE
-echild_status(VALUE self)
+echild_status(self)
+ VALUE self;
{
return rb_ivar_get(self, rb_intern("status"));
}
@@ -133,7 +131,9 @@ struct pty_info {
};
static void
-raise_from_wait(char *state, struct pty_info *info)
+raise_from_wait(state, info)
+ struct pty_info *info;
+ char *state;
{
extern VALUE rb_last_status;
char buf[1024];
@@ -146,7 +146,8 @@ raise_from_wait(char *state, struct pty_info *info)
}
static VALUE
-pty_syswait(struct pty_info *info)
+pty_syswait(info)
+ struct pty_info *info;
{
int cpid, status;
@@ -175,32 +176,38 @@ pty_syswait(struct pty_info *info)
}
}
-static void getDevice(int*, int*);
+static void getDevice _((int*, int*));
struct exec_info {
int argc;
VALUE *argv;
};
+static VALUE pty_exec _((VALUE v));
+
static VALUE
-pty_exec(VALUE v)
+pty_exec(v)
+ VALUE v;
{
struct exec_info *arg = (struct exec_info *)v;
return rb_f_exec(arg->argc, arg->argv);
}
static void
-establishShell(int argc, VALUE *argv, struct pty_info *info)
+establishShell(argc, argv, info)
+ int argc;
+ VALUE *argv;
+ struct pty_info *info;
{
int i,master,slave;
- char *p,*getenv();
+ char *p, tmp, *getenv();
struct passwd *pwent;
VALUE v;
struct exec_info arg;
int status;
if (argc == 0) {
- const char *shellname;
+ char *shellname;
if ((p = getenv("SHELL")) != NULL) {
shellname = p;
@@ -266,6 +273,7 @@ establishShell(int argc, VALUE *argv, struct pty_info *info)
}
close(master);
#endif
+ write(slave, "", 1);
dup2(slave,0);
dup2(slave,1);
dup2(slave,2);
@@ -281,6 +289,7 @@ establishShell(int argc, VALUE *argv, struct pty_info *info)
_exit(1);
}
+ read(master, &tmp, 1);
close(slave);
info->child_pid = i;
@@ -288,7 +297,8 @@ establishShell(int argc, VALUE *argv, struct pty_info *info)
}
static VALUE
-pty_finalize_syswait(struct pty_info *info)
+pty_finalize_syswait(info)
+ struct pty_info *info;
{
rb_thread_kill(info->thread);
rb_funcall(info->thread, rb_intern("value"), 0);
@@ -297,7 +307,8 @@ pty_finalize_syswait(struct pty_info *info)
}
static int
-get_device_once(int *master, int *slave, int fail)
+get_device_once(master, slave, fail)
+ int *master, *slave, fail;
{
#if defined HAVE_OPENPTY
/*
@@ -344,6 +355,7 @@ get_device_once(int *master, int *slave, int 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;
@@ -386,7 +398,8 @@ get_device_once(int *master, int *slave, int fail)
}
static void
-getDevice(int *master, int *slave)
+getDevice(master, slave)
+ int *master, *slave;
{
if (get_device_once(master, slave, 0)) {
rb_gc();
@@ -396,7 +409,10 @@ getDevice(int *master, int *slave)
/* ruby function: getpty */
static VALUE
-pty_getpty(int argc, VALUE *argv, VALUE self)
+pty_getpty(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE res;
struct pty_info info;
@@ -411,11 +427,11 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
establishShell(argc, argv, &info);
rfptr->mode = rb_io_mode_flags("r");
- rfptr->fd = info.fd;
+ rfptr->f = fdopen(info.fd, "r");
rfptr->path = strdup(SlaveName);
wfptr->mode = rb_io_mode_flags("w") | FMODE_SYNC;
- wfptr->fd = dup(info.fd);
+ wfptr->f = fdopen(dup(info.fd), "w");
wfptr->path = strdup(SlaveName);
res = rb_ary_new2(3);
@@ -436,7 +452,8 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
/* ruby function: protect_signal - obsolete */
static VALUE
-pty_protect(VALUE self)
+pty_protect(self)
+ VALUE self;
{
rb_warn("PTY::protect_signal is no longer needed");
rb_yield(Qnil);
@@ -445,7 +462,8 @@ pty_protect(VALUE self)
/* ruby function: reset_signal - obsolete */
static VALUE
-pty_reset_signal(VALUE self)
+pty_reset_signal(self)
+ VALUE self;
{
rb_warn("PTY::reset_signal is no longer needed");
return self;
diff --git a/ext/purelib.rb b/ext/purelib.rb
new file mode 100644
index 0000000000..10ee06176c
--- /dev/null
+++ b/ext/purelib.rb
@@ -0,0 +1,3 @@
+if nul = $:.index("-")
+ $:[nul..-1] = ["."]
+end
diff --git a/ext/racc/cparse/.cvsignore b/ext/racc/cparse/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/racc/cparse/.cvsignore
+++ b/ext/racc/cparse/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/racc/cparse/README b/ext/racc/cparse/README
deleted file mode 100644
index 80b4dce311..0000000000
--- a/ext/racc/cparse/README
+++ /dev/null
@@ -1,10 +0,0 @@
-Racc Runtime README
-===================
-
-This directory contains a runtime library of
-Racc parser generator. If you want to generate
-your own parser, you must get Racc full package.
-Get it from:
-
- http://raa.ruby-lang.org/list.rhtml?name=racc
-
diff --git a/ext/racc/cparse/cparse.c b/ext/racc/cparse/cparse.c
index 753cfddda2..18a26f670f 100644
--- a/ext/racc/cparse/cparse.c
+++ b/ext/racc/cparse/cparse.c
@@ -88,7 +88,7 @@ num_to_long(VALUE n)
}
#define AREF(s, idx) \
- ((0 <= idx && idx < RARRAY_LEN(s)) ? RARRAY_PTR(s)[idx] : Qnil)
+ ((0 <= idx && idx < RARRAY(s)->len) ? RARRAY(s)->ptr[idx] : Qnil)
/* -----------------------------------------------------------------------
Parser Stack Interfaces
@@ -101,8 +101,8 @@ static VALUE
get_stack_tail(VALUE stack, long len)
{
if (len < 0) return Qnil; /* system error */
- if (len > RARRAY_LEN(stack)) len = RARRAY_LEN(stack);
- return rb_ary_new4(len, RARRAY_PTR(stack) + RARRAY_LEN(stack) - len);
+ if (len > RARRAY(stack)->len) len = RARRAY(stack)->len;
+ return rb_ary_new4(len, RARRAY(stack)->ptr + RARRAY(stack)->len - len);
}
static void
@@ -116,10 +116,10 @@ cut_stack_tail(VALUE stack, long len)
#define STACK_INIT_LEN 64
#define NEW_STACK() rb_ary_new2(STACK_INIT_LEN)
-#define PUSH(s, i) rb_ary_store(s, RARRAY_LEN(s), i)
+#define PUSH(s, i) rb_ary_store(s, RARRAY(s)->len, i)
#define POP(s) rb_ary_pop(s)
#define LAST_I(s) \
- ((RARRAY_LEN(s) > 0) ? RARRAY_PTR(s)[RARRAY_LEN(s) - 1] : Qnil)
+ ((RARRAY(s)->len > 0) ? RARRAY(s)->ptr[RARRAY(s)->len - 1] : Qnil)
#define GET_TAIL(s, len) get_stack_tail(s, len)
#define CUT_TAIL(s, len) cut_stack_tail(s, len)
@@ -329,23 +329,23 @@ initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lex
v->debug = RTEST(rb_ivar_get(parser, id_yydebug));
Check_Type(arg, T_ARRAY);
- if (!(13 <= RARRAY_LEN(arg) && RARRAY_LEN(arg) <= 14))
- rb_raise(RaccBug, "[Racc Bug] wrong arg.size %ld", RARRAY_LEN(arg));
- v->action_table = assert_array (RARRAY_PTR(arg)[ 0]);
- v->action_check = assert_array (RARRAY_PTR(arg)[ 1]);
- v->action_default = assert_array (RARRAY_PTR(arg)[ 2]);
- v->action_pointer = assert_array (RARRAY_PTR(arg)[ 3]);
- v->goto_table = assert_array (RARRAY_PTR(arg)[ 4]);
- v->goto_check = assert_array (RARRAY_PTR(arg)[ 5]);
- v->goto_default = assert_array (RARRAY_PTR(arg)[ 6]);
- v->goto_pointer = assert_array (RARRAY_PTR(arg)[ 7]);
- v->nt_base = assert_integer(RARRAY_PTR(arg)[ 8]);
- v->reduce_table = assert_array (RARRAY_PTR(arg)[ 9]);
- v->token_table = assert_hash (RARRAY_PTR(arg)[10]);
- v->shift_n = assert_integer(RARRAY_PTR(arg)[11]);
- v->reduce_n = assert_integer(RARRAY_PTR(arg)[12]);
- if (RARRAY_LEN(arg) > 13) {
- v->use_result_var = RTEST(RARRAY_PTR(arg)[13]);
+ if (!(13 <= RARRAY(arg)->len && RARRAY(arg)->len <= 14))
+ rb_raise(RaccBug, "[Racc Bug] wrong arg.size %ld", RARRAY(arg)->len);
+ v->action_table = assert_array (RARRAY(arg)->ptr[ 0]);
+ v->action_check = assert_array (RARRAY(arg)->ptr[ 1]);
+ v->action_default = assert_array (RARRAY(arg)->ptr[ 2]);
+ v->action_pointer = assert_array (RARRAY(arg)->ptr[ 3]);
+ v->goto_table = assert_array (RARRAY(arg)->ptr[ 4]);
+ v->goto_check = assert_array (RARRAY(arg)->ptr[ 5]);
+ v->goto_default = assert_array (RARRAY(arg)->ptr[ 6]);
+ v->goto_pointer = assert_array (RARRAY(arg)->ptr[ 7]);
+ v->nt_base = assert_integer(RARRAY(arg)->ptr[ 8]);
+ v->reduce_table = assert_array (RARRAY(arg)->ptr[ 9]);
+ v->token_table = assert_hash (RARRAY(arg)->ptr[10]);
+ v->shift_n = assert_integer(RARRAY(arg)->ptr[11]);
+ v->reduce_n = assert_integer(RARRAY(arg)->ptr[12]);
+ if (RARRAY(arg)->len > 13) {
+ v->use_result_var = RTEST(RARRAY(arg)->ptr[13]);
}
else {
v->use_result_var = Qtrue;
@@ -393,10 +393,6 @@ cparse_params_mark(void *ptr)
rb_gc_mark(v->goto_check);
rb_gc_mark(v->goto_default);
rb_gc_mark(v->goto_pointer);
- rb_gc_mark(v->goto_pointer);
- rb_gc_mark(v->goto_pointer);
- rb_gc_mark(v->goto_pointer);
- rb_gc_mark(v->goto_pointer);
rb_gc_mark(v->reduce_table);
rb_gc_mark(v->token_table);
rb_gc_mark(v->state);
@@ -424,12 +420,12 @@ extract_user_token(struct cparse_params *v, VALUE block_args,
v->lex_is_iterator ? "yielded" : "returned",
rb_class2name(CLASS_OF(block_args)));
}
- if (RARRAY_LEN(block_args) != 2) {
+ if (RARRAY(block_args)->len != 2) {
rb_raise(rb_eArgError,
"%s() %s wrong size of array (%ld for 2)",
v->lex_is_iterator ? rb_id2name(v->lexmid) : "next_token",
v->lex_is_iterator ? "yielded" : "returned",
- RARRAY_LEN(block_args));
+ RARRAY(block_args)->len);
}
*tok = AREF(block_args, 0);
*val = AREF(block_args, 1);
@@ -565,7 +561,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
accept:
if (v->debug) rb_funcall(v->parser, id_d_accept, 0);
- v->retval = RARRAY_PTR(v->vstack)[0];
+ v->retval = RARRAY(v->vstack)->ptr[0];
v->fin = CP_FIN_ACCEPT;
return;
@@ -625,7 +621,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
error_pop:
D_puts("(err) act not found: can't handle error token; pop");
- if (RARRAY_LEN(v->state) <= 1) {
+ if (RARRAY(v->state)->len <= 1) {
v->retval = Qnil;
v->fin = CP_FIN_CANTPOP;
return;
@@ -694,9 +690,9 @@ reduce0(VALUE val, VALUE data, VALUE self)
VALUE goto_state;
Data_Get_Struct(data, struct cparse_params, v);
- reduce_len = RARRAY_PTR(v->reduce_table)[v->ruleno];
- reduce_to = RARRAY_PTR(v->reduce_table)[v->ruleno+1];
- method_id = RARRAY_PTR(v->reduce_table)[v->ruleno+2];
+ reduce_len = RARRAY(v->reduce_table)->ptr[v->ruleno];
+ reduce_to = RARRAY(v->reduce_table)->ptr[v->ruleno+1];
+ method_id = RARRAY(v->reduce_table)->ptr[v->ruleno+2];
len = NUM2LONG(reduce_len);
mid = value_to_id(method_id);
@@ -711,10 +707,10 @@ reduce0(VALUE val, VALUE data, VALUE self)
else {
if (mid != id_noreduce) {
tmp_v = GET_TAIL(v->vstack, len);
- tmp = RARRAY_PTR(tmp_v)[0];
+ tmp = RARRAY(tmp_v)->ptr[0];
}
else {
- tmp = RARRAY_PTR(v->vstack)[ RARRAY_LEN(v->vstack) - len ];
+ tmp = RARRAY(v->vstack)->ptr[ RARRAY(v->vstack)->len - len ];
}
CUT_TAIL(v->vstack, len);
if (v->debug) {
@@ -743,7 +739,7 @@ reduce0(VALUE val, VALUE data, VALUE self)
}
/* calculate transition state */
- if (RARRAY_LEN(v->state) == 0)
+ if (RARRAY(v->state)->len == 0)
rb_raise(RaccBug, "state stack unexpectedly empty");
k2 = num_to_long(LAST_I(v->state));
k1 = num_to_long(reduce_to) - v->nt_base;
diff --git a/ext/readline/.cvsignore b/ext/readline/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/readline/.cvsignore
+++ b/ext/readline/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/readline/extconf.rb b/ext/readline/extconf.rb
index b67a443dad..b820c0b32f 100644
--- a/ext/readline/extconf.rb
+++ b/ext/readline/extconf.rb
@@ -42,7 +42,9 @@ else
end
end
-have_readline_var("rl_filename_completion_function")
+have_func("rl_filename_completion_function")
+have_func("rl_username_completion_function")
+have_func("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")
@@ -57,7 +59,6 @@ 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 1e64675176..82ddc8a3cb 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -1,10 +1,6 @@
/* readline.c -- GNU Readline module
Copyright (C) 1997-2001 Shugo Maeda */
-#ifdef RUBY_EXTCONF_H
-#include RUBY_EXTCONF_H
-#endif
-
#include "config.h"
#include <errno.h>
#include <stdio.h>
@@ -38,38 +34,67 @@ static ID completion_proc, completion_case_fold;
#ifndef HAVE_RL_FILENAME_COMPLETION_FUNCTION
# define rl_filename_completion_function filename_completion_function
+#endif
+#ifndef HAVE_RL_USERNAME_COMPLETION_FUNCTION
# define rl_username_completion_function username_completion_function
+#endif
+#ifndef HAVE_RL_COMPLETION_MATCHES
# 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()
{
- CHECK_INTS;
+#if BUSY_WAIT
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(int argc, VALUE *argv, VALUE self)
+readline_readline(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE tmp, add_hist, result;
char *prompt = NULL;
char *buff;
int status;
+ OpenFile *ofp, *ifp;
rb_secure(4);
if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) {
SafeStringValue(tmp);
- prompt = RSTRING_PTR(tmp);
+ prompt = RSTRING(tmp)->ptr;
}
if (!isatty(0) && errno == EBADF) rb_raise(rb_eIOError, "stdin closed");
+ Check_Type(rb_stdout, T_FILE);
+ GetOpenFile(rb_stdout, ofp);
+ rl_outstream = GetWriteFile(ofp);
+ Check_Type(rb_stdin, T_FILE);
+ GetOpenFile(rb_stdin, ifp);
+ rl_instream = GetReadFile(ifp);
buff = (char*)rb_protect((VALUE(*)_((VALUE)))readline, (VALUE)prompt,
&status);
if (status) {
@@ -99,31 +124,9 @@ readline_readline(int argc, VALUE *argv, VALUE self)
}
static VALUE
-readline_s_set_input(VALUE self, VALUE input)
-{
- OpenFile *ifp;
-
- rb_secure(4);
- Check_Type(input, T_FILE);
- GetOpenFile(input, ifp);
- rl_instream = rb_io_stdio_file(ifp);
- return input;
-}
-
-static VALUE
-readline_s_set_output(VALUE self, VALUE output)
-{
- OpenFile *ofp;
-
- rb_secure(4);
- Check_Type(output, T_FILE);
- GetOpenFile(output, ofp);
- rl_outstream = rb_io_stdio_file(ofp);
- return output;
-}
-
-static VALUE
-readline_s_set_completion_proc(VALUE self, VALUE proc)
+readline_s_set_completion_proc(self, proc)
+ VALUE self;
+ VALUE proc;
{
rb_secure(4);
if (!rb_respond_to(proc, rb_intern("call")))
@@ -132,28 +135,35 @@ readline_s_set_completion_proc(VALUE self, VALUE proc)
}
static VALUE
-readline_s_get_completion_proc(VALUE self)
+readline_s_get_completion_proc(self)
+ VALUE self;
{
rb_secure(4);
return rb_attr_get(mReadline, completion_proc);
}
static VALUE
-readline_s_set_completion_case_fold(VALUE self, VALUE val)
+readline_s_set_completion_case_fold(self, val)
+ VALUE self;
+ VALUE val;
{
rb_secure(4);
return rb_ivar_set(mReadline, completion_case_fold, val);
}
static VALUE
-readline_s_get_completion_case_fold(VALUE self)
+readline_s_get_completion_case_fold(self)
+ VALUE self;
{
rb_secure(4);
return rb_attr_get(mReadline, completion_case_fold);
}
static char **
-readline_attempted_completion_function(const char *text, int start, int end)
+readline_attempted_completion_function(text, start, end)
+ const char *text;
+ int start;
+ int end;
{
VALUE proc, ary, temp;
char **result;
@@ -170,14 +180,14 @@ readline_attempted_completion_function(const char *text, int start, int end)
ary = rb_funcall(proc, rb_intern("call"), 1, rb_tainted_str_new2(text));
if (TYPE(ary) != T_ARRAY)
ary = rb_Array(ary);
- matches = RARRAY_LEN(ary);
+ matches = RARRAY(ary)->len;
if (matches == 0)
return NULL;
result = ALLOC_N(char *, matches + 2);
for (i = 0; i < matches; i++) {
- temp = rb_obj_as_string(RARRAY_PTR(ary)[i]);
- result[i + 1] = ALLOC_N(char, RSTRING_LEN(temp) + 1);
- strcpy(result[i + 1], RSTRING_PTR(temp));
+ temp = rb_obj_as_string(RARRAY(ary)->ptr[i]);
+ result[i + 1] = ALLOC_N(char, RSTRING(temp)->len + 1);
+ strcpy(result[i + 1], RSTRING(temp)->ptr);
}
result[matches + 1] = NULL;
@@ -217,7 +227,8 @@ readline_attempted_completion_function(const char *text, int start, int end)
}
static VALUE
-readline_s_vi_editing_mode(VALUE self)
+readline_s_vi_editing_mode(self)
+ VALUE self;
{
#ifdef HAVE_RL_VI_EDITING_MODE
rb_secure(4);
@@ -230,7 +241,8 @@ readline_s_vi_editing_mode(VALUE self)
}
static VALUE
-readline_s_emacs_editing_mode(VALUE self)
+readline_s_emacs_editing_mode(self)
+ VALUE self;
{
#ifdef HAVE_RL_EMACS_EDITING_MODE
rb_secure(4);
@@ -243,7 +255,8 @@ readline_s_emacs_editing_mode(VALUE self)
}
static VALUE
-readline_s_set_completion_append_character(VALUE self, VALUE str)
+readline_s_set_completion_append_character(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
rb_secure(4);
@@ -252,10 +265,10 @@ readline_s_set_completion_append_character(VALUE self, VALUE str)
}
else {
SafeStringValue(str);
- if (RSTRING_LEN(str) == 0) {
+ if (RSTRING(str)->len == 0) {
rl_completion_append_character = '\0';
} else {
- rl_completion_append_character = RSTRING_PTR(str)[0];
+ rl_completion_append_character = RSTRING(str)->ptr[0];
}
}
return self;
@@ -266,7 +279,8 @@ readline_s_set_completion_append_character(VALUE self, VALUE str)
}
static VALUE
-readline_s_get_completion_append_character(VALUE self)
+readline_s_get_completion_append_character(self)
+ VALUE self;
{
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
VALUE str;
@@ -276,7 +290,7 @@ readline_s_get_completion_append_character(VALUE self)
return Qnil;
str = rb_str_new("", 1);
- RSTRING_PTR(str)[0] = rl_completion_append_character;
+ RSTRING(str)->ptr[0] = rl_completion_append_character;
return str;
#else
rb_notimplement();
@@ -285,7 +299,8 @@ readline_s_get_completion_append_character(VALUE self)
}
static VALUE
-readline_s_set_basic_word_break_characters(VALUE self, VALUE str)
+readline_s_set_basic_word_break_characters(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS
static char *basic_word_break_characters = NULL;
@@ -294,14 +309,14 @@ readline_s_set_basic_word_break_characters(VALUE self, VALUE str)
SafeStringValue(str);
if (basic_word_break_characters == NULL) {
basic_word_break_characters =
- ALLOC_N(char, RSTRING_LEN(str) + 1);
+ ALLOC_N(char, RSTRING(str)->len + 1);
}
else {
- REALLOC_N(basic_word_break_characters, char, RSTRING_LEN(str) + 1);
+ REALLOC_N(basic_word_break_characters, char, RSTRING(str)->len + 1);
}
strncpy(basic_word_break_characters,
- RSTRING_PTR(str), RSTRING_LEN(str));
- basic_word_break_characters[RSTRING_LEN(str)] = '\0';
+ RSTRING(str)->ptr, RSTRING(str)->len);
+ basic_word_break_characters[RSTRING(str)->len] = '\0';
rl_basic_word_break_characters = basic_word_break_characters;
return self;
#else
@@ -311,7 +326,8 @@ readline_s_set_basic_word_break_characters(VALUE self, VALUE str)
}
static VALUE
-readline_s_get_basic_word_break_characters(VALUE self, VALUE str)
+readline_s_get_basic_word_break_characters(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS
rb_secure(4);
@@ -325,7 +341,8 @@ readline_s_get_basic_word_break_characters(VALUE self, VALUE str)
}
static VALUE
-readline_s_set_completer_word_break_characters(VALUE self, VALUE str)
+readline_s_set_completer_word_break_characters(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS
static char *completer_word_break_characters = NULL;
@@ -334,14 +351,14 @@ readline_s_set_completer_word_break_characters(VALUE self, VALUE str)
SafeStringValue(str);
if (completer_word_break_characters == NULL) {
completer_word_break_characters =
- ALLOC_N(char, RSTRING_LEN(str) + 1);
+ ALLOC_N(char, RSTRING(str)->len + 1);
}
else {
- REALLOC_N(completer_word_break_characters, char, RSTRING_LEN(str) + 1);
+ REALLOC_N(completer_word_break_characters, char, RSTRING(str)->len + 1);
}
strncpy(completer_word_break_characters,
- RSTRING_PTR(str), RSTRING_LEN(str));
- completer_word_break_characters[RSTRING_LEN(str)] = '\0';
+ RSTRING(str)->ptr, RSTRING(str)->len);
+ completer_word_break_characters[RSTRING(str)->len] = '\0';
rl_completer_word_break_characters = completer_word_break_characters;
return self;
#else
@@ -351,7 +368,8 @@ readline_s_set_completer_word_break_characters(VALUE self, VALUE str)
}
static VALUE
-readline_s_get_completer_word_break_characters(VALUE self, VALUE str)
+readline_s_get_completer_word_break_characters(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS
rb_secure(4);
@@ -365,7 +383,8 @@ readline_s_get_completer_word_break_characters(VALUE self, VALUE str)
}
static VALUE
-readline_s_set_basic_quote_characters(VALUE self, VALUE str)
+readline_s_set_basic_quote_characters(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
static char *basic_quote_characters = NULL;
@@ -374,14 +393,14 @@ readline_s_set_basic_quote_characters(VALUE self, VALUE str)
SafeStringValue(str);
if (basic_quote_characters == NULL) {
basic_quote_characters =
- ALLOC_N(char, RSTRING_LEN(str) + 1);
+ ALLOC_N(char, RSTRING(str)->len + 1);
}
else {
- REALLOC_N(basic_quote_characters, char, RSTRING_LEN(str) + 1);
+ REALLOC_N(basic_quote_characters, char, RSTRING(str)->len + 1);
}
strncpy(basic_quote_characters,
- RSTRING_PTR(str), RSTRING_LEN(str));
- basic_quote_characters[RSTRING_LEN(str)] = '\0';
+ RSTRING(str)->ptr, RSTRING(str)->len);
+ basic_quote_characters[RSTRING(str)->len] = '\0';
rl_basic_quote_characters = basic_quote_characters;
return self;
@@ -392,7 +411,8 @@ readline_s_set_basic_quote_characters(VALUE self, VALUE str)
}
static VALUE
-readline_s_get_basic_quote_characters(VALUE self, VALUE str)
+readline_s_get_basic_quote_characters(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
rb_secure(4);
@@ -406,7 +426,8 @@ readline_s_get_basic_quote_characters(VALUE self, VALUE str)
}
static VALUE
-readline_s_set_completer_quote_characters(VALUE self, VALUE str)
+readline_s_set_completer_quote_characters(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS
static char *completer_quote_characters = NULL;
@@ -415,13 +436,14 @@ readline_s_set_completer_quote_characters(VALUE self, VALUE str)
SafeStringValue(str);
if (completer_quote_characters == NULL) {
completer_quote_characters =
- ALLOC_N(char, RSTRING_LEN(str) + 1);
+ ALLOC_N(char, RSTRING(str)->len + 1);
}
else {
- REALLOC_N(completer_quote_characters, char, RSTRING_LEN(str) + 1);
+ REALLOC_N(completer_quote_characters, char, RSTRING(str)->len + 1);
}
- strncpy(completer_quote_characters, RSTRING_PTR(str), RSTRING_LEN(str));
- completer_quote_characters[RSTRING_LEN(str)] = '\0';
+ strncpy(completer_quote_characters,
+ RSTRING(str)->ptr, RSTRING(str)->len);
+ completer_quote_characters[RSTRING(str)->len] = '\0';
rl_completer_quote_characters = completer_quote_characters;
return self;
@@ -432,7 +454,8 @@ readline_s_set_completer_quote_characters(VALUE self, VALUE str)
}
static VALUE
-readline_s_get_completer_quote_characters(VALUE self, VALUE str)
+readline_s_get_completer_quote_characters(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS
rb_secure(4);
@@ -446,7 +469,8 @@ readline_s_get_completer_quote_characters(VALUE self, VALUE str)
}
static VALUE
-readline_s_set_filename_quote_characters(VALUE self, VALUE str)
+readline_s_set_filename_quote_characters(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
static char *filename_quote_characters = NULL;
@@ -455,13 +479,14 @@ readline_s_set_filename_quote_characters(VALUE self, VALUE str)
SafeStringValue(str);
if (filename_quote_characters == NULL) {
filename_quote_characters =
- ALLOC_N(char, RSTRING_LEN(str) + 1);
+ ALLOC_N(char, RSTRING(str)->len + 1);
}
else {
- REALLOC_N(filename_quote_characters, char, RSTRING_LEN(str) + 1);
+ REALLOC_N(filename_quote_characters, char, RSTRING(str)->len + 1);
}
- strncpy(filename_quote_characters, RSTRING_PTR(str), RSTRING_LEN(str));
- filename_quote_characters[RSTRING_LEN(str)] = '\0';
+ strncpy(filename_quote_characters,
+ RSTRING(str)->ptr, RSTRING(str)->len);
+ filename_quote_characters[RSTRING(str)->len] = '\0';
rl_filename_quote_characters = filename_quote_characters;
return self;
@@ -472,7 +497,8 @@ readline_s_set_filename_quote_characters(VALUE self, VALUE str)
}
static VALUE
-readline_s_get_filename_quote_characters(VALUE self, VALUE str)
+readline_s_get_filename_quote_characters(self, str)
+ VALUE self, str;
{
#ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
rb_secure(4);
@@ -486,13 +512,16 @@ readline_s_get_filename_quote_characters(VALUE self, VALUE str)
}
static VALUE
-hist_to_s(VALUE self)
+hist_to_s(self)
+ VALUE self;
{
return rb_str_new2("HISTORY");
}
static VALUE
-hist_get(VALUE self, VALUE index)
+hist_get(self, index)
+ VALUE self;
+ VALUE index;
{
HIST_ENTRY *entry;
int i;
@@ -510,7 +539,10 @@ hist_get(VALUE self, VALUE index)
}
static VALUE
-hist_set(VALUE self, VALUE index, VALUE str)
+hist_set(self, index, str)
+ VALUE self;
+ VALUE index;
+ VALUE str;
{
#ifdef HAVE_REPLACE_HISTORY_ENTRY
HIST_ENTRY *entry;
@@ -522,7 +554,7 @@ hist_set(VALUE self, VALUE index, VALUE str)
if (i < 0) {
i += history_length;
}
- entry = replace_history_entry(i, RSTRING_PTR(str), NULL);
+ entry = replace_history_entry(i, RSTRING(str)->ptr, NULL);
if (entry == NULL) {
rb_raise(rb_eIndexError, "invalid index");
}
@@ -534,16 +566,21 @@ hist_set(VALUE self, VALUE index, VALUE str)
}
static VALUE
-hist_push(VALUE self, VALUE str)
+hist_push(self, str)
+ VALUE self;
+ VALUE str;
{
rb_secure(4);
SafeStringValue(str);
- add_history(RSTRING_PTR(str));
+ add_history(RSTRING(str)->ptr);
return self;
}
static VALUE
-hist_push_method(int argc, VALUE *argv, VALUE self)
+hist_push_method(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE str;
@@ -551,13 +588,14 @@ hist_push_method(int argc, VALUE *argv, VALUE self)
while (argc--) {
str = *argv++;
SafeStringValue(str);
- add_history(RSTRING_PTR(str));
+ add_history(RSTRING(str)->ptr);
}
return self;
}
static VALUE
-rb_remove_history(int index)
+rb_remove_history(index)
+ int index;
{
#ifdef HAVE_REMOVE_HISTORY
HIST_ENTRY *entry;
@@ -579,7 +617,8 @@ rb_remove_history(int index)
}
static VALUE
-hist_pop(VALUE self)
+hist_pop(self)
+ VALUE self;
{
rb_secure(4);
if (history_length > 0) {
@@ -590,7 +629,8 @@ hist_pop(VALUE self)
}
static VALUE
-hist_shift(VALUE self)
+hist_shift(self)
+ VALUE self;
{
rb_secure(4);
if (history_length > 0) {
@@ -601,7 +641,8 @@ hist_shift(VALUE self)
}
static VALUE
-hist_each(VALUE self)
+hist_each(self)
+ VALUE self;
{
HIST_ENTRY *entry;
int i;
@@ -617,21 +658,25 @@ hist_each(VALUE self)
}
static VALUE
-hist_length(VALUE self)
+hist_length(self)
+ VALUE self;
{
rb_secure(4);
return INT2NUM(history_length);
}
static VALUE
-hist_empty_p(VALUE self)
+hist_empty_p(self)
+ VALUE self;
{
rb_secure(4);
return history_length == 0 ? Qtrue : Qfalse;
}
static VALUE
-hist_delete_at(VALUE self, VALUE index)
+hist_delete_at(self, index)
+ VALUE self;
+ VALUE index;
{
int i;
@@ -646,7 +691,9 @@ hist_delete_at(VALUE self, VALUE index)
}
static VALUE
-filename_completion_proc_call(VALUE self, VALUE str)
+filename_completion_proc_call(self, str)
+ VALUE self;
+ VALUE str;
{
VALUE result;
char **matches;
@@ -661,7 +708,7 @@ filename_completion_proc_call(VALUE self, VALUE str)
free(matches[i]);
}
free(matches);
- if (RARRAY_LEN(result) >= 2)
+ if (RARRAY(result)->len >= 2)
rb_ary_shift(result);
}
else {
@@ -671,7 +718,9 @@ filename_completion_proc_call(VALUE self, VALUE str)
}
static VALUE
-username_completion_proc_call(VALUE self, VALUE str)
+username_completion_proc_call(self, str)
+ VALUE self;
+ VALUE str;
{
VALUE result;
char **matches;
@@ -686,7 +735,7 @@ username_completion_proc_call(VALUE self, VALUE str)
free(matches[i]);
}
free(matches);
- if (RARRAY_LEN(result) >= 2)
+ if (RARRAY(result)->len >= 2)
rb_ary_shift(result);
}
else {
@@ -711,10 +760,6 @@ Init_readline()
mReadline = rb_define_module("Readline");
rb_define_module_function(mReadline, "readline",
readline_readline, -1);
- rb_define_singleton_method(mReadline, "input=",
- readline_s_set_input, 1);
- rb_define_singleton_method(mReadline, "output=",
- readline_s_set_output, 1);
rb_define_singleton_method(mReadline, "completion_proc=",
readline_s_set_completion_proc, 1);
rb_define_singleton_method(mReadline, "completion_proc",
@@ -780,7 +825,8 @@ Init_readline()
#if defined HAVE_RL_LIBRARY_VERSION
rb_define_const(mReadline, "VERSION", rb_str_new2(rl_library_version));
#else
- rb_define_const(mReadline, "VERSION", rb_str_new2("2.0 or prior version"));
+ rb_define_const(mReadline, "VERSION",
+ rb_str_new2("2.0 or before version"));
#endif
rl_attempted_completion_function = readline_attempted_completion_function;
diff --git a/ext/ripper/.cvsignore b/ext/ripper/.cvsignore
deleted file mode 100644
index c9adce0b1a..0000000000
--- a/ext/ripper/.cvsignore
+++ /dev/null
@@ -1,8 +0,0 @@
-Makefile
-mkmf.log
-eventids1.c
-eventids2table.c
-ripper.*
-ids1
-ids2
-extconf.h
diff --git a/ext/ripper/README b/ext/ripper/README
deleted file mode 100644
index 0825013ba9..0000000000
--- a/ext/ripper/README
+++ /dev/null
@@ -1,30 +0,0 @@
-Ripper README
-=============
-
- Ripper is a Ruby script parser. You can get information
- by event-based style from the parser.
-
- !! WARNING !!
-
- Ripper is still early-alpha version.
- I never assure any kind of backward compatibility.
-
-Requirements
-------------
-
- * ruby 1.9 (support CVS HEAD only)
- * bison 1.28 or later (Other yaccs do not work)
-
-Usage
------
-
- See test/ripper/* and sample/ripper/*.
-
-License
--------
-
- Ruby License.
-
- Minero Aoki
- aamine@loveruby.net
- http://i.loveruby.net
diff --git a/ext/ripper/depend b/ext/ripper/depend
deleted file mode 100644
index 0e54262759..0000000000
--- a/ext/ripper/depend
+++ /dev/null
@@ -1,32 +0,0 @@
-GEN = $(srcdir)/tools/generate.rb
-SRC1 = $(hdrdir)/parse.y
-SRC2 = $(srcdir)/eventids2.c
-BISON = bison
-
-src: ripper.c eventids1.c eventids2table.c
-
-ripper.o: ripper.c $(hdrdir)/lex.c eventids1.c $(srcdir)/eventids2.c eventids2table.c
-
-.y.c:
- $(BISON) -t -v -o$@ $<
-
-all: check
-static: check
-
-ripper.y: $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y
- $(RUBY) $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y --output=$@
-
-check: $(GEN) $(SRC1) $(SRC2)
- $(RUBY) $(GEN) --mode=check --ids1src=$(SRC1) --ids2src=$(SRC2)
-
-eventids1.c: $(srcdir)/tools/generate.rb $(SRC1)
- $(RUBY) $(GEN) --mode=eventids1 --ids1src=$(SRC1) --output=$@
-
-eventids2table.c: $(srcdir)/tools/generate.rb $(SRC2)
- $(RUBY) $(GEN) --mode=eventids2table --ids2src=$(SRC2) --output=$@
-
-# Entries for Ripper maintainer
-
-preproc: ripper.E
-ripper.E: ripper.c
- $(CC) -E $(CPPFLAGS) ripper.c | $(RUBY) $(srcdir)/tools/strip.rb > $@
diff --git a/ext/ripper/eventids2.c b/ext/ripper/eventids2.c
deleted file mode 100644
index 0c04583b98..0000000000
--- a/ext/ripper/eventids2.c
+++ /dev/null
@@ -1,277 +0,0 @@
-#define tIGNORED_NL (tLAST_TOKEN + 1)
-#define tCOMMENT (tLAST_TOKEN + 2)
-#define tEMBDOC_BEG (tLAST_TOKEN + 3)
-#define tEMBDOC (tLAST_TOKEN + 4)
-#define tEMBDOC_END (tLAST_TOKEN + 5)
-#define tSP (tLAST_TOKEN + 6)
-#define tHEREDOC_BEG (tLAST_TOKEN + 7)
-#define tHEREDOC_END (tLAST_TOKEN + 8)
-#define k__END__ (tLAST_TOKEN + 9)
-
-static ID ripper_id_backref;
-static ID ripper_id_backtick;
-static ID ripper_id_comma;
-static ID ripper_id_const;
-static ID ripper_id_cvar;
-static ID ripper_id_embexpr_beg;
-static ID ripper_id_embexpr_end;
-static ID ripper_id_embvar;
-static ID ripper_id_float;
-static ID ripper_id_gvar;
-static ID ripper_id_ident;
-static ID ripper_id_int;
-static ID ripper_id_ivar;
-static ID ripper_id_kw;
-static ID ripper_id_lbrace;
-static ID ripper_id_lbracket;
-static ID ripper_id_lparen;
-static ID ripper_id_nl;
-static ID ripper_id_op;
-static ID ripper_id_period;
-static ID ripper_id_rbrace;
-static ID ripper_id_rbracket;
-static ID ripper_id_rparen;
-static ID ripper_id_semicolon;
-static ID ripper_id_symbeg;
-static ID ripper_id_tstring_beg;
-static ID ripper_id_tstring_content;
-static ID ripper_id_tstring_end;
-static ID ripper_id_words_beg;
-static ID ripper_id_qwords_beg;
-static ID ripper_id_words_sep;
-static ID ripper_id_regexp_beg;
-static ID ripper_id_regexp_end;
-static ID ripper_id_label;
-static ID ripper_id_tlambda;
-static ID ripper_id_tlambeg;
-
-static ID ripper_id_ignored_nl;
-static ID ripper_id_comment;
-static ID ripper_id_embdoc_beg;
-static ID ripper_id_embdoc;
-static ID ripper_id_embdoc_end;
-static ID ripper_id_sp;
-static ID ripper_id_heredoc_beg;
-static ID ripper_id_heredoc_end;
-static ID ripper_id___end__;
-static ID ripper_id_CHAR;
-
-#include "eventids2table.c"
-
-static void
-ripper_init_eventids2(VALUE self)
-{
- ripper_id_backref = rb_intern("on_backref");
- ripper_id_backtick = rb_intern("on_backtick");
- ripper_id_comma = rb_intern("on_comma");
- ripper_id_const = rb_intern("on_const");
- ripper_id_cvar = rb_intern("on_cvar");
- ripper_id_embexpr_beg = rb_intern("on_embexpr_beg");
- ripper_id_embexpr_end = rb_intern("on_embexpr_end");
- ripper_id_embvar = rb_intern("on_embvar");
- ripper_id_float = rb_intern("on_float");
- ripper_id_gvar = rb_intern("on_gvar");
- ripper_id_ident = rb_intern("on_ident");
- ripper_id_int = rb_intern("on_int");
- ripper_id_ivar = rb_intern("on_ivar");
- ripper_id_kw = rb_intern("on_kw");
- ripper_id_lbrace = rb_intern("on_lbrace");
- ripper_id_lbracket = rb_intern("on_lbracket");
- ripper_id_lparen = rb_intern("on_lparen");
- ripper_id_nl = rb_intern("on_nl");
- ripper_id_op = rb_intern("on_op");
- ripper_id_period = rb_intern("on_period");
- ripper_id_rbrace = rb_intern("on_rbrace");
- ripper_id_rbracket = rb_intern("on_rbracket");
- ripper_id_rparen = rb_intern("on_rparen");
- ripper_id_semicolon = rb_intern("on_semicolon");
- ripper_id_symbeg = rb_intern("on_symbeg");
- ripper_id_tstring_beg = rb_intern("on_tstring_beg");
- ripper_id_tstring_content = rb_intern("on_tstring_content");
- ripper_id_tstring_end = rb_intern("on_tstring_end");
- ripper_id_words_beg = rb_intern("on_words_beg");
- ripper_id_qwords_beg = rb_intern("on_qwords_beg");
- ripper_id_words_sep = rb_intern("on_words_sep");
- ripper_id_regexp_beg = rb_intern("on_regexp_beg");
- ripper_id_regexp_end = rb_intern("on_regexp_end");
- ripper_id_label = rb_intern("on_label");
- ripper_id_tlambda = rb_intern("on_tlambda");
- ripper_id_tlambeg = rb_intern("on_tlambeg");
-
- ripper_id_ignored_nl = rb_intern("on_ignored_nl");
- ripper_id_comment = rb_intern("on_comment");
- ripper_id_embdoc_beg = rb_intern("on_embdoc_beg");
- ripper_id_embdoc = rb_intern("on_embdoc");
- ripper_id_embdoc_end = rb_intern("on_embdoc_end");
- ripper_id_sp = rb_intern("on_sp");
- ripper_id_heredoc_beg = rb_intern("on_heredoc_beg");
- ripper_id_heredoc_end = rb_intern("on_heredoc_end");
- ripper_id___end__ = rb_intern("on___end__");
- ripper_id_CHAR = rb_intern("on_CHAR");
-
- ripper_init_eventids2_table(self);
-}
-
-static struct token_assoc {
- int token;
- ID *id;
-} token_to_eventid[] = {
- {' ', &ripper_id_words_sep},
- {'!', &ripper_id_op},
- {'%', &ripper_id_op},
- {'&', &ripper_id_op},
- {'*', &ripper_id_op},
- {'+', &ripper_id_op},
- {'-', &ripper_id_op},
- {'/', &ripper_id_op},
- {'<', &ripper_id_op},
- {'=', &ripper_id_op},
- {'>', &ripper_id_op},
- {'?', &ripper_id_op},
- {'^', &ripper_id_op},
- {'|', &ripper_id_op},
- {'~', &ripper_id_op},
- {':', &ripper_id_op},
- {',', &ripper_id_comma},
- {'.', &ripper_id_period},
- {';', &ripper_id_semicolon},
- {'`', &ripper_id_backtick},
- {'\n', &ripper_id_nl},
- {keyword_alias, &ripper_id_kw},
- {keyword_and, &ripper_id_kw},
- {keyword_begin, &ripper_id_kw},
- {keyword_break, &ripper_id_kw},
- {keyword_case, &ripper_id_kw},
- {keyword_class, &ripper_id_kw},
- {keyword_def, &ripper_id_kw},
- {keyword_defined, &ripper_id_kw},
- {keyword_do, &ripper_id_kw},
- {keyword_do_block, &ripper_id_kw},
- {keyword_do_cond, &ripper_id_kw},
- {keyword_else, &ripper_id_kw},
- {keyword_elsif, &ripper_id_kw},
- {keyword_end, &ripper_id_kw},
- {keyword_ensure, &ripper_id_kw},
- {keyword_false, &ripper_id_kw},
- {keyword_for, &ripper_id_kw},
- {keyword_if, &ripper_id_kw},
- {modifier_if, &ripper_id_kw},
- {keyword_in, &ripper_id_kw},
- {keyword_module, &ripper_id_kw},
- {keyword_next, &ripper_id_kw},
- {keyword_nil, &ripper_id_kw},
- {keyword_not, &ripper_id_kw},
- {keyword_or, &ripper_id_kw},
- {keyword_redo, &ripper_id_kw},
- {keyword_rescue, &ripper_id_kw},
- {modifier_rescue, &ripper_id_kw},
- {keyword_retry, &ripper_id_kw},
- {keyword_return, &ripper_id_kw},
- {keyword_self, &ripper_id_kw},
- {keyword_super, &ripper_id_kw},
- {keyword_then, &ripper_id_kw},
- {keyword_true, &ripper_id_kw},
- {keyword_undef, &ripper_id_kw},
- {keyword_unless, &ripper_id_kw},
- {modifier_unless, &ripper_id_kw},
- {keyword_until, &ripper_id_kw},
- {modifier_until, &ripper_id_kw},
- {keyword_when, &ripper_id_kw},
- {keyword_while, &ripper_id_kw},
- {modifier_while, &ripper_id_kw},
- {keyword_yield, &ripper_id_kw},
- {keyword__FILE__, &ripper_id_kw},
- {keyword__LINE__, &ripper_id_kw},
- {keyword_BEGIN, &ripper_id_kw},
- {keyword_END, &ripper_id_kw},
- {tAMPER, &ripper_id_op},
- {tANDOP, &ripper_id_op},
- {tAREF, &ripper_id_op},
- {tASET, &ripper_id_op},
- {tASSOC, &ripper_id_op},
- {tBACK_REF, &ripper_id_backref},
- {tCHAR, &ripper_id_CHAR},
- {tCMP, &ripper_id_op},
- {tCOLON2, &ripper_id_op},
- {tCOLON3, &ripper_id_op},
- {tCONSTANT, &ripper_id_const},
- {tCVAR, &ripper_id_cvar},
- {tDOT2, &ripper_id_op},
- {tDOT3, &ripper_id_op},
- {tEQ, &ripper_id_op},
- {tEQQ, &ripper_id_op},
- {tFID, &ripper_id_ident},
- {tFLOAT, &ripper_id_float},
- {tGEQ, &ripper_id_op},
- {tGVAR, &ripper_id_gvar},
- {tIDENTIFIER, &ripper_id_ident},
- {tINTEGER, &ripper_id_int},
- {tIVAR, &ripper_id_ivar},
- {tLBRACE, &ripper_id_lbrace},
- {tLBRACE_ARG, &ripper_id_lbrace},
- {'{', &ripper_id_lbrace},
- {'}', &ripper_id_rbrace},
- {tLBRACK, &ripper_id_lbracket},
- {'[', &ripper_id_lbracket},
- {']', &ripper_id_rbracket},
- {tLEQ, &ripper_id_op},
- {tLPAREN, &ripper_id_lparen},
- {tLPAREN_ARG, &ripper_id_lparen},
- {'(', &ripper_id_lparen},
- {')', &ripper_id_rparen},
- {tLSHFT, &ripper_id_op},
- {tMATCH, &ripper_id_op},
- {tNEQ, &ripper_id_op},
- {tNMATCH, &ripper_id_op},
- {tNTH_REF, &ripper_id_backref},
- {tOP_ASGN, &ripper_id_op},
- {tOROP, &ripper_id_op},
- {tPOW, &ripper_id_op},
- {tQWORDS_BEG, &ripper_id_qwords_beg},
- {tREGEXP_BEG, &ripper_id_regexp_beg},
- {tREGEXP_END, &ripper_id_regexp_end},
- {tRPAREN, &ripper_id_rparen},
- {tRSHFT, &ripper_id_op},
- {tSTAR, &ripper_id_op},
- {tSTRING_BEG, &ripper_id_tstring_beg},
- {tSTRING_CONTENT, &ripper_id_tstring_content},
- {tSTRING_DBEG, &ripper_id_embexpr_beg},
- {tSTRING_DVAR, &ripper_id_embvar},
- {tSTRING_END, &ripper_id_tstring_end},
- {tSYMBEG, &ripper_id_symbeg},
- {tUMINUS, &ripper_id_op},
- {tUMINUS_NUM, &ripper_id_op},
- {tUPLUS, &ripper_id_op},
- {tWORDS_BEG, &ripper_id_words_beg},
- {tXSTRING_BEG, &ripper_id_backtick},
- {tLABEL, &ripper_id_label},
- {tLAMBDA, &ripper_id_tlambda},
- {tLAMBEG, &ripper_id_tlambeg},
-
- /* ripper specific tokens */
- {tIGNORED_NL, &ripper_id_ignored_nl},
- {tCOMMENT, &ripper_id_comment},
- {tEMBDOC_BEG, &ripper_id_embdoc_beg},
- {tEMBDOC, &ripper_id_embdoc},
- {tEMBDOC_END, &ripper_id_embdoc_end},
- {tSP, &ripper_id_sp},
- {tHEREDOC_BEG, &ripper_id_heredoc_beg},
- {tHEREDOC_END, &ripper_id_heredoc_end},
- {k__END__, &ripper_id___end__},
- {0, NULL}
-};
-
-static ID
-ripper_token2eventid(int tok)
-{
- struct token_assoc *a;
-
- for (a = token_to_eventid; a->id != NULL; a++) {
- if (a->token == tok)
- return *a->id;
- }
- if (tok < 256) {
- return ripper_id_CHAR;
- }
- rb_raise(rb_eRuntimeError, "[Ripper FATAL] unknown token %d", tok);
-}
diff --git a/ext/ripper/extconf.rb b/ext/ripper/extconf.rb
deleted file mode 100644
index 6b44073300..0000000000
--- a/ext/ripper/extconf.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-#!ruby -s
-
-require 'mkmf'
-require 'rbconfig'
-
-def main
- unless find_executable('bison')
- unless File.exist?('ripper.c') or File.exist?("#{$srcdir}/ripper.c")
- Logging.message 'missing bison; abort'
- return
- end
- end
- $objs = %w(ripper.o)
- $cleanfiles.concat %w(ripper.y ripper.c ripper.E ripper.output eventids1.c eventids2table.c)
- $CPPFLAGS += ' -DRIPPER'
- $CPPFLAGS += ' -DRIPPER_DEBUG' if $debug
- create_makefile 'ripper'
-end
-
-main
diff --git a/ext/ripper/lib/ripper.rb b/ext/ripper/lib/ripper.rb
deleted file mode 100644
index cb19da334a..0000000000
--- a/ext/ripper/lib/ripper.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'ripper/core'
-require 'ripper/lexer'
-require 'ripper/filter'
-require 'ripper/sexp'
diff --git a/ext/ripper/lib/ripper/core.rb b/ext/ripper/lib/ripper/core.rb
deleted file mode 100644
index 35aa54d090..0000000000
--- a/ext/ripper/lib/ripper/core.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-#
-# $Id$
-#
-# Copyright (c) 2003-2005 Minero Aoki
-#
-# This program is free software.
-# You can distribute and/or modify this program under the Ruby License.
-# For details of Ruby License, see ruby/COPYING.
-#
-
-require 'ripper.so'
-
-class Ripper
-
- # Parses Ruby program read from _src_.
- # _src_ must be a String or a IO or a object which has #gets method.
- def Ripper.parse(src, filename = '(ripper)', lineno = 1)
- new(src, filename, lineno).parse
- end
-
- # This array contains name of parser events.
- PARSER_EVENTS = PARSER_EVENT_TABLE.keys
-
- # This array contains name of scanner events.
- SCANNER_EVENTS = SCANNER_EVENT_TABLE.keys
-
- # This array contains name of all ripper events.
- EVENTS = PARSER_EVENTS + SCANNER_EVENTS
-
- private
-
- #
- # Parser Events
- #
-
- PARSER_EVENT_TABLE.each do |id, arity|
- module_eval(<<-End, __FILE__, __LINE__ + 1)
- def on_#{id}(#{ ('a'..'z').to_a[0, arity].join(', ') })
- #{arity == 0 ? 'nil' : 'a'}
- end
- End
- end
-
- # This method is called when weak warning is produced by the parser.
- # _fmt_ and _args_ is printf style.
- def warn(fmt, *args)
- end
-
- # This method is called when strong warning is produced by the parser.
- # _fmt_ and _args_ is printf style.
- def warning(fmt, *args)
- end
-
- # This method is called when the parser found syntax error.
- def compile_error(msg)
- end
-
- #
- # Scanner Events
- #
-
- SCANNER_EVENTS.each do |id|
- module_eval(<<-End, __FILE__, __LINE__ + 1)
- def on_#{id}(token)
- token
- end
- End
- end
-
-end
diff --git a/ext/ripper/lib/ripper/filter.rb b/ext/ripper/lib/ripper/filter.rb
deleted file mode 100644
index 898501b23c..0000000000
--- a/ext/ripper/lib/ripper/filter.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-#
-# $Id$
-#
-# Copyright (c) 2004,2005 Minero Aoki
-#
-# This program is free software.
-# You can distribute and/or modify this program under the Ruby License.
-# For details of Ruby License, see ruby/COPYING.
-#
-
-require 'ripper/lexer'
-
-class Ripper
-
- # This class handles only scanner events,
- # and they are dispatched in the `right' order (same with input).
- class Filter
-
- def initialize(src, filename = '-', lineno = 1)
- @__lexer = Lexer.new(src, filename, lineno)
- @__line = nil
- @__col = nil
- end
-
- # The file name of the input.
- def filename
- @__lexer.filename
- end
-
- # The line number of the current token.
- # This value starts from 1.
- # This method is valid only in event handlers.
- def lineno
- @__line
- end
-
- # The column number of the current token.
- # This value starts from 0.
- # This method is valid only in event handlers.
- def column
- @__col
- end
-
- # Starts parsing. _init_ is a data accumulator.
- # It is passed to the next event handler (as of Enumerable#inject).
- def parse(init = nil)
- data = init
- @__lexer.lex.each do |pos, event, tok|
- @__line, @__col = *pos
- data = if respond_to?(event, true)
- then __send__(event, tok, data)
- else on_default(event, tok, data)
- end
- end
- data
- end
-
- private
-
- # This method is called when some event handler have not defined.
- # _event_ is :on_XXX, _token_ is scanned token, _data_ is a data
- # accumulator. The return value of this method is passed to the
- # next event handler (as of Enumerable#inject).
- def on_default(event, token, data)
- data
- end
-
- end
-
-end
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
deleted file mode 100644
index 22048f161c..0000000000
--- a/ext/ripper/lib/ripper/lexer.rb
+++ /dev/null
@@ -1,179 +0,0 @@
-#
-# $Id$
-#
-# Copyright (c) 2004,2005 Minero Aoki
-#
-# This program is free software.
-# You can distribute and/or modify this program under the Ruby License.
-# For details of Ruby License, see ruby/COPYING.
-#
-
-require 'ripper/core'
-
-class Ripper
-
- # Tokenizes Ruby program and returns an Array of String.
- def Ripper.tokenize(src, filename = '-', lineno = 1)
- Lexer.new(src, filename, lineno).tokenize
- end
-
- # Tokenizes Ruby program and returns an Array of Array,
- # which is formatted like [[lineno, column], type, token].
- #
- # require 'ripper'
- # require 'pp'
- #
- # p Ripper.scan("def m(a) nil end")
- # #=> [[[1, 0], :on_kw, "def"],
- # [[1, 3], :on_sp, " " ],
- # [[1, 4], :on_ident, "m" ],
- # [[1, 5], :on_lparen, "(" ],
- # [[1, 6], :on_ident, "a" ],
- # [[1, 7], :on_rparen, ")" ],
- # [[1, 8], :on_sp, " " ],
- # [[1, 9], :on_kw, "nil"],
- # [[1, 12], :on_sp, " " ],
- # [[1, 13], :on_kw, "end"]]
- #
- def Ripper.lex(src, filename = '-', lineno = 1)
- Lexer.new(src, filename, lineno).lex
- end
-
- class Lexer < ::Ripper #:nodoc: internal use only
- def tokenize
- lex().map {|pos, event, tok| tok }
- end
-
- def lex
- parse().sort_by {|pos, event, tok| pos }
- end
-
- def parse
- @buf = []
- super
- @buf
- end
-
- private
-
- SCANNER_EVENTS.each do |event|
- module_eval(<<-End, __FILE__+'/module_eval', __LINE__ + 1)
- def on_#{event}(tok)
- @buf.push [[lineno(), column()], :on_#{event}, tok]
- end
- End
- end
- end
-
- # [EXPERIMENTAL]
- # Parses +src+ and return a string which was matched to +pattern+.
- # +pattern+ should be described as Regexp.
- #
- # require 'ripper'
- #
- # p Ripper.slice('def m(a) nil end', 'ident') #=> "m"
- # p Ripper.slice('def m(a) nil end', '[ident lparen rparen]+') #=> "m(a)"
- # p Ripper.slice("<<EOS\nstring\nEOS",
- # 'heredoc_beg nl $(tstring_content*) heredoc_end', 1)
- # #=> "string\n"
- #
- def Ripper.slice(src, pattern, n = 0)
- if m = token_match(src, pattern)
- then m.string(n)
- else nil
- end
- end
-
- def Ripper.token_match(src, pattern) #:nodoc:
- TokenPattern.compile(pattern).match(src)
- end
-
- class TokenPattern #:nodoc:
-
- class Error < ::StandardError; end
- class CompileError < Error; end
- class MatchError < Error; end
-
- class << self
- alias compile new
- end
-
- def initialize(pattern)
- @source = pattern
- @re = compile(pattern)
- end
-
- def match(str)
- match_list(::Ripper.lex(str))
- end
-
- def match_list(tokens)
- if m = @re.match(map_tokens(tokens))
- then MatchData.new(tokens, m)
- else nil
- end
- end
-
- private
-
- def compile(pattern)
- if m = /[^\w\s$()\[\]{}?*+\.]/.match(pattern)
- raise CompileError, "invalid char in pattern: #{m[0].inspect}"
- end
- buf = ''
- pattern.scan(/(?:\w+|\$\(|[()\[\]\{\}?*+\.]+)/) do |tok|
- case tok
- when /\w/
- buf.concat map_token(tok)
- when '$('
- buf.concat '('
- when '('
- buf.concat '(?:'
- when /[?*\[\])\.]/
- buf.concat tok
- else
- raise 'must not happen'
- end
- end
- Regexp.compile(buf)
- rescue RegexpError => err
- raise CompileError, err.message
- end
-
- def map_tokens(tokens)
- tokens.map {|pos,type,str| map_token(type.to_s.sub(/\Aon_/,'')) }.join
- end
-
- MAP = {}
- seed = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
- SCANNER_EVENT_TABLE.each do |ev, |
- raise CompileError, "[RIPPER FATAL] too many system token" if seed.empty?
- MAP[ev.to_s.sub(/\Aon_/,'')] = seed.shift
- end
-
- def map_token(tok)
- MAP[tok] or raise CompileError, "unknown token: #{tok}"
- end
-
- class MatchData
- def initialize(tokens, match)
- @tokens = tokens
- @match = match
- end
-
- def string(n = 0)
- return nil unless @match
- match(n).join
- end
-
- private
-
- def match(n = 0)
- return [] unless @match
- @tokens[@match.begin(n)...@match.end(n)].map {|pos,type,str| str }
- end
- end
-
- end
-
-end
diff --git a/ext/ripper/lib/ripper/sexp.rb b/ext/ripper/lib/ripper/sexp.rb
deleted file mode 100644
index d841f9d665..0000000000
--- a/ext/ripper/lib/ripper/sexp.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-#
-# $Id$
-#
-# Copyright (c) 2004,2005 Minero Aoki
-#
-# This program is free software.
-# You can distribute and/or modify this program under the Ruby License.
-# For details of Ruby License, see ruby/COPYING.
-#
-
-require 'ripper/core'
-
-class Ripper
-
- # [EXPERIMENTAL]
- # Parses +src+ and create S-exp tree.
- # This method is for mainly developper use.
- #
- # require 'ripper'
- # require 'pp
- #
- # pp Ripper.sexp("def m(a) nil end")
- # #=> [:program,
- # [:stmts_add,
- # [:stmts_new],
- # [:def,
- # [:@ident, "m", [1, 4]],
- # [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil]],
- # [:bodystmt,
- # [:stmts_add, [:stmts_new], [:var_ref, [:@kw, "nil", [1, 9]]]],
- # nil,
- # nil,
- # nil]]]]
- #
- def Ripper.sexp(src, filename = '-', lineno = 1)
- SexpBuilderPP.new(src, filename, lineno).parse
- end
-
- def Ripper.sexp_raw(src, filename = '-', lineno = 1)
- SexpBuilder.new(src, filename, lineno).parse
- end
-
- class SexpBuilderPP < ::Ripper #:nodoc:
- private
-
- PARSER_EVENTS.each do |event|
- case event.to_s
- when /_new\z/
- module_eval(<<-End, __FILE__, __LINE__ + 1)
- def on_#{event}(*args)
- []
- end
- End
- when /_add\z/
- module_eval(<<-End, __FILE__, __LINE__ + 1)
- def on_#{event}(list, item)
- list.push item
- list
- end
- End
- else
- module_eval(<<-End, __FILE__, __LINE__ + 1)
- def on_#{event}(*args)
- [:#{event}, *args]
- end
- End
- end
- end
-
- SCANNER_EVENTS.each do |event|
- module_eval(<<-End, __FILE__, __LINE__ + 1)
- def on_#{event}(tok)
- [:@#{event}, tok, [lineno(), column()]]
- end
- End
- end
- end
-
- class SexpBuilder < ::Ripper #:nodoc:
- private
-
- PARSER_EVENTS.each do |event|
- module_eval(<<-End, __FILE__, __LINE__ + 1)
- def on_#{event}(*args)
- args.unshift :#{event}
- args
- end
- End
- end
-
- SCANNER_EVENTS.each do |event|
- module_eval(<<-End, __FILE__, __LINE__ + 1)
- def on_#{event}(tok)
- [:@#{event}, tok, [lineno(), column()]]
- end
- End
- end
- end
-
-end
diff --git a/ext/ripper/tools/generate-param-macros.rb b/ext/ripper/tools/generate-param-macros.rb
deleted file mode 100755
index b19f6e8d5c..0000000000
--- a/ext/ripper/tools/generate-param-macros.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-off = true
-ARGF.each do |line|
- case line
- when /RIPPER_PARAMS_DECL_BEGIN/
- off = false
- when /RIPPER_PARAMS_DECL_END/
- exit
- when /ripper/
- next if off
- var = line.scan(/\w+/).last or next
- base = var.sub(/ripper_/, '')
- puts %"\#define #{base}\t\t(parser->ripper_#{base})"
- end
-end
diff --git a/ext/ripper/tools/generate.rb b/ext/ripper/tools/generate.rb
deleted file mode 100755
index 0efb997604..0000000000
--- a/ext/ripper/tools/generate.rb
+++ /dev/null
@@ -1,152 +0,0 @@
-# $Id$
-
-require 'optparse'
-
-def main
- mode = nil
- ids1src = nil
- ids2src = nil
- template = nil
- output = nil
-
- parser = @parser = OptionParser.new
- parser.banner = "Usage: #{File.basename($0)} --mode=MODE [--ids1src=PATH] [--ids2src=PATH] [--output=PATH]"
- parser.on('--mode=MODE', 'check, eventids1, or eventids2table.') {|m|
- mode = m
- }
- parser.on('--ids1src=PATH', 'A source file of event-IDs 1 (parse.y).') {|path|
- ids1src = path
- }
- parser.on('--ids2src=PATH', 'A source file of event-IDs 2 (eventids2.c).') {|path|
- ids2src = path
- }
- parser.on('--output=PATH', 'An output file.') {|path|
- output = path
- }
- parser.on('--help', 'Prints this message and quit.') {
- puts parser.help
- exit true
- }
- begin
- parser.parse!
- rescue OptionParser::ParseError => err
- usage err.message
- end
- usage 'no mode given' unless mode
- case mode
- when 'check'
- usage 'no --ids1src' unless ids1src
- usage 'no --ids2src' unless ids2src
- h = read_ids1_with_locations(ids1src)
- check_arity h
- ids2 = read_ids2(ids2src)
- common = h.keys & ids2
- unless common.empty?
- abort "event crash: #{common.join(' ')}"
- end
- exit 0
- when 'eventids1'
- usage 'no --ids1src' unless ids1src
- result = generate_eventids1(read_ids1(ids1src))
- when 'eventids2table'
- usage 'no --ids2src' unless ids2src
- result = generate_eventids2_table(read_ids2(ids2src))
- end
- if output
- File.open(output, 'w') {|f|
- f.write result
- }
- else
- puts result
- end
-end
-
-def usage(msg)
- $stderr.puts msg
- $stderr.puts @parser.help
- exit false
-end
-
-def generate_eventids1(ids)
- buf = ""
- ids.each do |id, arity|
- buf << %Q[static ID ripper_id_#{id};\n]
- end
- buf << %Q[\n]
- buf << %Q[static void\n]
- buf << %Q[ripper_init_eventids1(VALUE self)\n]
- buf << %Q[{\n]
- buf << %Q[ VALUE h;\n]
- buf << %Q[ ID id;\n]
- ids.each do |id, arity|
- buf << %Q[ ripper_id_#{id} = rb_intern("on_#{id}");\n]
- end
- buf << %Q[\n]
- buf << %Q[ h = rb_hash_new();\n]
- buf << %Q[ rb_define_const(self, "PARSER_EVENT_TABLE", h);\n]
- ids.each do |id, arity|
- buf << %Q[ id = rb_intern("#{id}");\n]
- buf << %Q[ rb_hash_aset(h, ID2SYM(id), INT2NUM(#{arity}));\n]
- end
- buf << %Q[}\n]
- buf
-end
-
-def generate_eventids2_table(ids)
- buf = ""
- buf << %Q[static void\n]
- buf << %Q[ripper_init_eventids2_table(VALUE self)\n]
- buf << %Q[{\n]
- buf << %Q[ VALUE h = rb_hash_new();\n]
- buf << %Q[ ID id;\n]
- buf << %Q[ rb_define_const(self, "SCANNER_EVENT_TABLE", h);\n]
- ids.each do |id|
- buf << %Q[ id = rb_intern("#{id}");\n]
- buf << %Q[ rb_hash_aset(h, ID2SYM(id), INT2NUM(1));\n]
- end
- buf << %Q[}\n]
- buf
-end
-
-def read_ids1(path)
- strip_locations(read_ids1_with_locations(path))
-end
-
-def strip_locations(h)
- h.map {|event, list| [event, list.first[1]] }\
- .sort_by {|event, arity| event.to_s }
-end
-
-def check_arity(h)
- invalid = false
- h.each do |event, list|
- unless list.map {|line, arity| arity }.uniq.size == 1
- invalid = true
- locations = list.map {|line, a| "#{line}:#{a}" }.join(', ')
- $stderr.puts "arity crash [event=#{event}]: #{locations}"
- end
- end
- abort if invalid
-end
-
-def read_ids1_with_locations(path)
- h = {}
- File.open(path) {|f|
- f.each do |line|
- next if /\A\#\s*define\s+s?dispatch/ =~ line
- next if /ripper_dispatch/ =~ line
- line.scan(/dispatch(\d)\((\w+)/) do |arity, event|
- (h[event] ||= []).push [f.lineno, arity.to_i]
- end
- end
- }
- h
-end
-
-def read_ids2(path)
- File.open(path) {|f|
- return f.read.scan(/ripper_id_(\w+)/).flatten.uniq.sort
- }
-end
-
-main
diff --git a/ext/ripper/tools/preproc.rb b/ext/ripper/tools/preproc.rb
deleted file mode 100755
index 06397cea05..0000000000
--- a/ext/ripper/tools/preproc.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-# $Id$
-
-require 'optparse'
-
-def main
- output = nil
- parser = OptionParser.new
- parser.banner = "Usage: #{File.basename($0)} [--output=PATH] <parse.y>"
- parser.on('--output=PATH', 'An output file.') {|path|
- output = path
- }
- parser.on('--help', 'Prints this message and quit.') {
- puts parser.help
- exit true
- }
- begin
- parser.parse!
- rescue OptionParser::ParseError => err
- $stderr.puts err.message
- $stderr.puts parser.help
- exit false
- end
- unless ARGV.size == 1
- abort "wrong number of arguments (#{ARGV.size} for 1)"
- end
- out = ""
- File.open(ARGV[0]) {|f|
- prelude f, out
- grammar f, out
- usercode f, out
- }
- if output
- File.open(output, 'w') {|f|
- f.write out
- }
- else
- print out
- end
-end
-
-def prelude(f, out)
- while line = f.gets
- case line
- when %r</\*%%%\*/>
- out << '/*' << $/
- when %r</\*%>
- out << '*/' << $/
- when %r<%\*/>
- out << $/
- when /\A%%/
- out << '%%' << $/
- return
- when /\A%token/
- out << line.sub(/<\w+>/, '<val>')
- when /\A%type/
- out << line.sub(/<\w+>/, '<val>')
- else
- out << line
- end
- end
-end
-
-def grammar(f, out)
- while line = f.gets
- case line
- when %r</\*%%%\*/>
- out << '#if 0' << $/
- when %r</\*%c%\*/>
- out << '/*' << $/
- when %r</\*%c>
- out << '*/' << $/
- when %r</\*%>
- out << '#endif' << $/
- when %r<%\*/>
- out << $/
- when /\A%%/
- out << '%%' << $/
- return
- else
- out << line
- end
- end
-end
-
-def usercode(f, out)
- while line = f.gets
- out << line
- end
-end
-
-main
diff --git a/ext/ripper/tools/strip.rb b/ext/ripper/tools/strip.rb
deleted file mode 100755
index 99413c361d..0000000000
--- a/ext/ripper/tools/strip.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-last_is_void = false
-ARGF.each do |line|
- if line.strip.empty?
- #puts() unless last_is_void
- last_is_void = true
- elsif /\A\#/ === line
- ;
- else
- print line
- last_is_void = false
- end
-end
diff --git a/ext/sdbm/.cvsignore b/ext/sdbm/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/sdbm/.cvsignore
+++ b/ext/sdbm/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/sdbm/_sdbm.c b/ext/sdbm/_sdbm.c
index f9a5888624..5b34824afc 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 MSDOS
+#ifdef DOSISH
#include <io.h>
#endif
#include <sys/types.h>
@@ -143,7 +143,10 @@ static long masks[] = {
datum nullitem = {NULL, 0};
DBM *
-sdbm_open(register char *file, register int flags, register int mode)
+sdbm_open(file, flags, mode)
+register char *file;
+register int flags;
+register int mode;
{
register DBM *db;
register char *dirname;
@@ -172,7 +175,11 @@ sdbm_open(register char *file, register int flags, register int mode)
}
DBM *
-sdbm_prep(char *dirname, char *pagname, int flags, int mode)
+sdbm_prep(dirname, pagname, flags, mode)
+char *dirname;
+char *pagname;
+int flags;
+int mode;
{
register DBM *db;
struct stat dstat;
@@ -228,7 +235,8 @@ sdbm_prep(char *dirname, char *pagname, int flags, int mode)
}
void
-sdbm_close(register DBM *db)
+sdbm_close(db)
+register DBM *db;
{
if (db == NULL)
errno = EINVAL;
@@ -240,7 +248,9 @@ sdbm_close(register DBM *db)
}
datum
-sdbm_fetch(register DBM *db, datum key)
+sdbm_fetch(db, key)
+register DBM *db;
+datum key;
{
if (db == NULL || bad(key))
return errno = EINVAL, nullitem;
@@ -252,7 +262,9 @@ sdbm_fetch(register DBM *db, datum key)
}
int
-sdbm_delete(register DBM *db, datum key)
+sdbm_delete(db, key)
+register DBM *db;
+datum key;
{
if (db == NULL || bad(key))
return errno = EINVAL, -1;
@@ -276,7 +288,11 @@ sdbm_delete(register DBM *db, datum key)
}
int
-sdbm_store(register DBM *db, datum key, datum val, int flags)
+sdbm_store(db, key, val, flags)
+register DBM *db;
+datum key;
+datum val;
+int flags;
{
int need;
register long hash;
@@ -334,7 +350,10 @@ sdbm_store(register DBM *db, datum key, datum val, int flags)
* giving up.
*/
static int
-makroom(register DBM *db, long int hash, int need)
+makroom(db, hash, need)
+register DBM *db;
+long hash;
+int need;
{
long newp;
char twin[PBLKSIZ];
@@ -431,7 +450,8 @@ makroom(register DBM *db, long int hash, int need)
* deletions aren't taken into account. (ndbm bug)
*/
datum
-sdbm_firstkey(register DBM *db)
+sdbm_firstkey(db)
+register DBM *db;
{
if (db == NULL)
return errno = EINVAL, nullitem;
@@ -450,7 +470,8 @@ sdbm_firstkey(register DBM *db)
}
datum
-sdbm_nextkey(register DBM *db)
+sdbm_nextkey(db)
+register DBM *db;
{
if (db == NULL)
return errno = EINVAL, nullitem;
@@ -461,7 +482,9 @@ sdbm_nextkey(register DBM *db)
* all important binary trie traversal
*/
static int
-getpage(register DBM *db, register long int hash)
+getpage(db, hash)
+register DBM *db;
+register long hash;
{
register int hbit;
register long dbit;
@@ -503,7 +526,9 @@ getpage(register DBM *db, register long int hash)
}
static int
-getdbit(register DBM *db, register long int dbit)
+getdbit(db, dbit)
+register DBM *db;
+register long dbit;
{
register long c;
register long dirb;
@@ -524,7 +549,9 @@ getdbit(register DBM *db, register long int dbit)
}
static int
-setdbit(register DBM *db, register long int dbit)
+setdbit(db, dbit)
+register DBM *db;
+register long dbit;
{
register long c;
register long dirb;
@@ -558,7 +585,8 @@ setdbit(register DBM *db, register long int dbit)
* the page, try the next page in sequence
*/
static datum
-getnext(register DBM *db)
+getnext(db)
+register DBM *db;
{
datum key;
@@ -633,7 +661,9 @@ static int seepair proto((char *, int, char *, int));
*/
static int
-fitpair(char *pag, int need)
+fitpair(pag, need)
+char *pag;
+int need;
{
register int n;
register int off;
@@ -650,7 +680,10 @@ fitpair(char *pag, int need)
}
static void
-putpair(char *pag, datum key, datum val)
+putpair(pag, key, val)
+char *pag;
+datum key;
+datum val;
{
register int n;
register int off;
@@ -678,7 +711,9 @@ putpair(char *pag, datum key, datum val)
}
static datum
-getpair(char *pag, datum key)
+getpair(pag, key)
+char *pag;
+datum key;
{
register int i;
register int n;
@@ -698,7 +733,9 @@ getpair(char *pag, datum key)
#ifdef SEEDUPS
static int
-duppair(char *pag, datum key)
+duppair(pag, key)
+char *pag;
+datum key;
{
register short *ino = (short *) pag;
return GET_SHORT(ino,0) > 0 &&
@@ -707,7 +744,9 @@ duppair(char *pag, datum key)
#endif
static datum
-getnkey(char *pag, int num)
+getnkey(pag, num)
+char *pag;
+int num;
{
datum key;
register int off;
@@ -726,7 +765,9 @@ getnkey(char *pag, int num)
}
static int
-delpair(char *pag, datum key)
+delpair(pag, key)
+char *pag;
+datum key;
{
register int n;
register int i;
@@ -796,7 +837,11 @@ delpair(char *pag, datum key)
* return 0 if not found.
*/
static int
-seepair(char *pag, register int n, register char *key, register int siz)
+seepair(pag, n, key, siz)
+char *pag;
+register int n;
+register char *key;
+register int siz;
{
register int i;
register int off = PBLKSIZ;
@@ -812,7 +857,10 @@ seepair(char *pag, register int n, register char *key, register int siz)
}
static void
-splpage(char *pag, char *new, long int sbit)
+splpage(pag, new, sbit)
+char *pag;
+char *new;
+long sbit;
{
datum key;
datum val;
@@ -853,7 +901,8 @@ splpage(char *pag, char *new, long int sbit)
* this could be made more rigorous.
*/
static int
-chkpage(char *pag)
+chkpage(pag)
+char *pag;
{
register int n;
register int off;
@@ -893,7 +942,9 @@ chkpage(char *pag)
* 65587 even better.
*/
long
-sdbm_hash(register char *str, register int len)
+sdbm_hash(str, len)
+register char *str;
+register int len;
{
register unsigned long n = 0;
diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c
index 08a3ab8bf5..acadc9b26a 100644
--- a/ext/sdbm/init.c
+++ b/ext/sdbm/init.c
@@ -41,7 +41,8 @@ closed_sdbm()
}
static void
-free_sdbm(struct dbmdata *dbmp)
+free_sdbm(dbmp)
+ struct dbmdata *dbmp;
{
if (dbmp->di_dbm) sdbm_close(dbmp->di_dbm);
@@ -49,7 +50,8 @@ free_sdbm(struct dbmdata *dbmp)
}
static VALUE
-fsdbm_close(VALUE obj)
+fsdbm_close(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
@@ -61,7 +63,8 @@ fsdbm_close(VALUE obj)
}
static VALUE
-fsdbm_closed(VALUE obj)
+fsdbm_closed(obj)
+ VALUE obj;
{
struct dbmdata *dbmp;
@@ -74,14 +77,19 @@ fsdbm_closed(VALUE obj)
return Qfalse;
}
+static VALUE fsdbm_alloc _((VALUE));
static VALUE
-fsdbm_alloc(VALUE klass)
+fsdbm_alloc(klass)
+ VALUE klass;
{
return Data_Wrap_Struct(klass, 0, free_sdbm, 0);
}
static VALUE
-fsdbm_initialize(int argc, VALUE *argv, VALUE obj)
+fsdbm_initialize(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE file, vmode;
DBM *dbm;
@@ -101,15 +109,15 @@ fsdbm_initialize(int argc, VALUE *argv, VALUE obj)
dbm = 0;
if (mode >= 0)
- dbm = sdbm_open(RSTRING_PTR(file), O_RDWR|O_CREAT, mode);
+ dbm = sdbm_open(RSTRING(file)->ptr, O_RDWR|O_CREAT, mode);
if (!dbm)
- dbm = sdbm_open(RSTRING_PTR(file), O_RDWR, 0);
+ dbm = sdbm_open(RSTRING(file)->ptr, O_RDWR, 0);
if (!dbm)
- dbm = sdbm_open(RSTRING_PTR(file), O_RDONLY, 0);
+ dbm = sdbm_open(RSTRING(file)->ptr, O_RDONLY, 0);
if (!dbm) {
if (mode == -1) return Qnil;
- rb_sys_fail(RSTRING_PTR(file));
+ rb_sys_fail(RSTRING(file)->ptr);
}
dbmp = ALLOC(struct dbmdata);
@@ -121,7 +129,10 @@ fsdbm_initialize(int argc, VALUE *argv, VALUE obj)
}
static VALUE
-fsdbm_s_open(int argc, VALUE *argv, VALUE klass)
+fsdbm_s_open(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE obj = Data_Wrap_Struct(klass, 0, free_sdbm, 0);
@@ -137,15 +148,16 @@ fsdbm_s_open(int argc, VALUE *argv, VALUE klass)
}
static VALUE
-fsdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
+fsdbm_fetch(obj, keystr, ifnone)
+ VALUE obj, keystr, ifnone;
{
datum key, value;
struct dbmdata *dbmp;
DBM *dbm;
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
GetDBM2(obj, dbmp, dbm);
value = sdbm_fetch(dbm, key);
@@ -158,13 +170,17 @@ fsdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
}
static VALUE
-fsdbm_aref(VALUE obj, VALUE keystr)
+fsdbm_aref(obj, keystr)
+ VALUE obj, keystr;
{
return fsdbm_fetch(obj, keystr, Qnil);
}
static VALUE
-fsdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
+fsdbm_fetch_m(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE keystr, valstr, ifnone;
@@ -177,52 +193,90 @@ fsdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
}
static VALUE
-fsdbm_index(VALUE obj, VALUE valstr)
+fsdbm_index(obj, valstr)
+ VALUE obj, valstr;
{
datum key, val;
struct dbmdata *dbmp;
DBM *dbm;
StringValue(valstr);
- val.dptr = RSTRING_PTR(valstr);
- val.dsize = RSTRING_LEN(valstr);
+ val.dptr = RSTRING(valstr)->ptr;
+ val.dsize = RSTRING(valstr)->len;
GetDBM2(obj, dbmp, dbm);
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
- if (val.dsize == RSTRING_LEN(valstr) &&
- memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0)
+ if (val.dsize == RSTRING(valstr)->len &&
+ memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0)
return rb_tainted_str_new(key.dptr, key.dsize);
}
return Qnil;
}
static VALUE
-fsdbm_select(VALUE obj)
+fsdbm_indexes(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
- VALUE new = rb_ary_new();
- datum key, val;
- DBM *dbm;
- struct dbmdata *dbmp;
+ VALUE new;
+ int i;
- GetDBM2(obj, dbmp, dbm);
- for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
- VALUE assoc, v;
- val = sdbm_fetch(dbm, key);
- assoc = rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
- rb_tainted_str_new(val.dptr, val.dsize));
- v = rb_yield(assoc);
- if (RTEST(v)) {
- rb_ary_push(new, assoc);
+ new = rb_ary_new2(argc);
+ for (i=0; i<argc; i++) {
+ rb_ary_push(new, fsdbm_fetch(obj, argv[i], Qnil));
+ }
+
+ return new;
+}
+
+static VALUE
+fsdbm_select(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
+ VALUE new = rb_ary_new2(argc);
+ int i;
+
+ if (rb_block_given_p()) {
+ datum key, val;
+ DBM *dbm;
+ struct dbmdata *dbmp;
+
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
}
- GetDBM2(obj, dbmp, dbm);
+ GetDBM2(obj, dbmp, dbm);
+ for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
+ VALUE assoc, v;
+ val = sdbm_fetch(dbm, key);
+ assoc = rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
+ rb_tainted_str_new(val.dptr, val.dsize));
+ v = rb_yield(assoc);
+ if (RTEST(v)) {
+ rb_ary_push(new, assoc);
+ }
+ GetDBM2(obj, dbmp, dbm);
+ }
+ }
+ else {
+ rb_warn("SDBM#select(index..) is deprecated; use SDBM#values_at");
+
+ for (i=0; i<argc; i++) {
+ rb_ary_push(new, fsdbm_fetch(obj, argv[i], Qnil));
+ }
}
return new;
}
static VALUE
-fsdbm_values_at(int argc, VALUE *argv, VALUE obj)
+fsdbm_values_at(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE new = rb_ary_new2(argc);
int i;
@@ -235,14 +289,16 @@ fsdbm_values_at(int argc, VALUE *argv, VALUE obj)
}
static void
-fdbm_modify(VALUE obj)
+fdbm_modify(obj)
+ VALUE obj;
{
rb_secure(4);
if (OBJ_FROZEN(obj)) rb_error_frozen("SDBM");
}
static VALUE
-fsdbm_delete(VALUE obj, VALUE keystr)
+fsdbm_delete(obj, keystr)
+ VALUE obj, keystr;
{
datum key, value;
struct dbmdata *dbmp;
@@ -251,8 +307,8 @@ fsdbm_delete(VALUE obj, VALUE keystr)
fdbm_modify(obj);
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
@@ -277,7 +333,8 @@ fsdbm_delete(VALUE obj, VALUE keystr)
}
static VALUE
-fsdbm_shift(VALUE obj)
+fsdbm_shift(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -300,7 +357,8 @@ fsdbm_shift(VALUE obj)
}
static VALUE
-fsdbm_delete_if(VALUE obj)
+fsdbm_delete_if(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -323,23 +381,24 @@ fsdbm_delete_if(VALUE obj)
GetDBM2(obj, dbmp, dbm);
}
- for (i = 0; i < RARRAY_LEN(ary); i++) {
- keystr = RARRAY_PTR(ary)[i];
+ for (i = 0; i < RARRAY(ary)->len; i++) {
+ keystr = RARRAY(ary)->ptr[i];
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
if (sdbm_delete(dbm, key)) {
rb_raise(rb_eDBMError, "sdbm_delete failed");
}
}
if (status) rb_jump_tag(status);
- if (n > 0) dbmp->di_size = n - RARRAY_LEN(ary);
+ if (n > 0) dbmp->di_size = n - RARRAY(ary)->len;
return obj;
}
static VALUE
-fsdbm_clear(VALUE obj)
+fsdbm_clear(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -359,7 +418,8 @@ fsdbm_clear(VALUE obj)
}
static VALUE
-fsdbm_invert(VALUE obj)
+fsdbm_invert(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -377,8 +437,49 @@ fsdbm_invert(VALUE obj)
return hash;
}
+static VALUE each_pair _((VALUE));
+
static VALUE
-fsdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
+each_pair(obj)
+ VALUE obj;
+{
+ return rb_funcall(obj, rb_intern("each_pair"), 0, 0);
+}
+
+static VALUE fsdbm_store _((VALUE,VALUE,VALUE));
+
+static VALUE
+update_i(pair, dbm)
+ VALUE pair, dbm;
+{
+ Check_Type(pair, T_ARRAY);
+ if (RARRAY(pair)->len < 2) {
+ rb_raise(rb_eArgError, "pair must be [key, value]");
+ }
+ fsdbm_store(dbm, RARRAY(pair)->ptr[0], RARRAY(pair)->ptr[1]);
+ return Qnil;
+}
+
+static VALUE
+fsdbm_update(obj, other)
+ VALUE obj, other;
+{
+ rb_iterate(each_pair, other, update_i, obj);
+ return obj;
+}
+
+static VALUE
+fsdbm_replace(obj, other)
+ VALUE obj, other;
+{
+ fsdbm_clear(obj);
+ rb_iterate(each_pair, other, update_i, obj);
+ return obj;
+}
+
+static VALUE
+fsdbm_store(obj, keystr, valstr)
+ VALUE obj, keystr, valstr;
{
datum key, val;
struct dbmdata *dbmp;
@@ -393,11 +494,11 @@ fsdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
StringValue(keystr);
StringValue(valstr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
- val.dptr = RSTRING_PTR(valstr);
- val.dsize = RSTRING_LEN(valstr);
+ val.dptr = RSTRING(valstr)->ptr;
+ val.dsize = RSTRING(valstr)->len;
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
@@ -413,33 +514,8 @@ fsdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
}
static VALUE
-update_i(VALUE pair, VALUE dbm)
-{
- Check_Type(pair, T_ARRAY);
- if (RARRAY_LEN(pair) < 2) {
- rb_raise(rb_eArgError, "pair must be [key, value]");
- }
- fsdbm_store(dbm, RARRAY_PTR(pair)[0], RARRAY_PTR(pair)[1]);
- return Qnil;
-}
-
-static VALUE
-fsdbm_update(VALUE obj, VALUE other)
-{
- rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
- return obj;
-}
-
-static VALUE
-fsdbm_replace(VALUE obj, VALUE other)
-{
- fsdbm_clear(obj);
- rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
- return obj;
-}
-
-static VALUE
-fsdbm_length(VALUE obj)
+fsdbm_length(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -458,7 +534,8 @@ fsdbm_length(VALUE obj)
}
static VALUE
-fsdbm_empty_p(VALUE obj)
+fsdbm_empty_p(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -481,7 +558,8 @@ fsdbm_empty_p(VALUE obj)
}
static VALUE
-fsdbm_each_value(VALUE obj)
+fsdbm_each_value(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -497,7 +575,8 @@ fsdbm_each_value(VALUE obj)
}
static VALUE
-fsdbm_each_key(VALUE obj)
+fsdbm_each_key(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -512,7 +591,8 @@ fsdbm_each_key(VALUE obj)
}
static VALUE
-fsdbm_each_pair(VALUE obj)
+fsdbm_each_pair(obj)
+ VALUE obj;
{
datum key, val;
DBM *dbm;
@@ -532,7 +612,8 @@ fsdbm_each_pair(VALUE obj)
}
static VALUE
-fsdbm_keys(VALUE obj)
+fsdbm_keys(obj)
+ VALUE obj;
{
datum key;
struct dbmdata *dbmp;
@@ -549,7 +630,8 @@ fsdbm_keys(VALUE obj)
}
static VALUE
-fsdbm_values(VALUE obj)
+fsdbm_values(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -567,15 +649,16 @@ fsdbm_values(VALUE obj)
}
static VALUE
-fsdbm_has_key(VALUE obj, VALUE keystr)
+fsdbm_has_key(obj, keystr)
+ VALUE obj, keystr;
{
datum key, val;
struct dbmdata *dbmp;
DBM *dbm;
StringValue(keystr);
- key.dptr = RSTRING_PTR(keystr);
- key.dsize = RSTRING_LEN(keystr);
+ key.dptr = RSTRING(keystr)->ptr;
+ key.dsize = RSTRING(keystr)->len;
GetDBM2(obj, dbmp, dbm);
val = sdbm_fetch(dbm, key);
@@ -584,28 +667,30 @@ fsdbm_has_key(VALUE obj, VALUE keystr)
}
static VALUE
-fsdbm_has_value(VALUE obj, VALUE valstr)
+fsdbm_has_value(obj, valstr)
+ VALUE obj, valstr;
{
datum key, val;
struct dbmdata *dbmp;
DBM *dbm;
StringValue(valstr);
- val.dptr = RSTRING_PTR(valstr);
- val.dsize = RSTRING_LEN(valstr);
+ val.dptr = RSTRING(valstr)->ptr;
+ val.dsize = RSTRING(valstr)->len;
GetDBM2(obj, dbmp, dbm);
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
- if (val.dsize == RSTRING_LEN(valstr) &&
- memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0)
+ if (val.dsize == RSTRING(valstr)->len &&
+ memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0)
return Qtrue;
}
return Qfalse;
}
static VALUE
-fsdbm_to_a(VALUE obj)
+fsdbm_to_a(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -624,7 +709,8 @@ fsdbm_to_a(VALUE obj)
}
static VALUE
-fsdbm_to_hash(VALUE obj)
+fsdbm_to_hash(obj)
+ VALUE obj;
{
datum key, val;
struct dbmdata *dbmp;
@@ -643,7 +729,8 @@ fsdbm_to_hash(VALUE obj)
}
static VALUE
-fsdbm_reject(VALUE obj)
+fsdbm_reject(obj)
+ VALUE obj;
{
return rb_hash_delete_if(fsdbm_to_hash(obj));
}
@@ -666,7 +753,9 @@ Init_sdbm()
rb_define_method(rb_cDBM, "[]=", fsdbm_store, 2);
rb_define_method(rb_cDBM, "store", fsdbm_store, 2);
rb_define_method(rb_cDBM, "index", fsdbm_index, 1);
- rb_define_method(rb_cDBM, "select", fsdbm_select, 0);
+ rb_define_method(rb_cDBM, "indexes", fsdbm_indexes, -1);
+ rb_define_method(rb_cDBM, "indices", fsdbm_indexes, -1);
+ rb_define_method(rb_cDBM, "select", fsdbm_select, -1);
rb_define_method(rb_cDBM, "values_at", fsdbm_values_at, -1);
rb_define_method(rb_cDBM, "length", fsdbm_length, 0);
rb_define_method(rb_cDBM, "size", fsdbm_length, 0);
diff --git a/ext/socket/.cvsignore b/ext/socket/.cvsignore
index ce98586d91..4088712231 100644
--- a/ext/socket/.cvsignore
+++ b/ext/socket/.cvsignore
@@ -1,5 +1,3 @@
Makefile
mkmf.log
*.def
-constants.h
-extconf.h
diff --git a/ext/socket/depend b/ext/socket/depend
index 77d5b66559..cca6d4e62a 100644
--- a/ext/socket/depend
+++ b/ext/socket/depend
@@ -1,7 +1,3 @@
-socket.o: socket.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/rubyio.h $(hdrdir)/rubysig.h sockport.h constants.h
+socket.o : socket.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/rubyio.h $(hdrdir)/rubysig.h sockport.h
getnameinfo.o: getnameinfo.c $(topdir)/config.h addrinfo.h sockport.h
getaddrinfo.o: getaddrinfo.c $(topdir)/config.h addrinfo.h sockport.h
-
-constants.h: $(srcdir)/mkconstants.rb
- @echo "generating constants.h"
- @$(RUBY) $(srcdir)/mkconstants.rb > $@
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 0791714e49..8a13ddba73 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -1,14 +1,22 @@
require 'mkmf'
case RUBY_PLATFORM
-when /(ms|bcc)win32|mingw/
+when /bccwin32/
test_func = "WSACleanup"
have_library("ws2_32", "WSACleanup")
+when /mswin32|mingw/
+ test_func = "WSACleanup"
+ if with_config("winsock2")
+ have_library("ws2_32", "WSACleanup")
+ else
+ have_library("wsock32", "WSACleanup")
+ end
when /cygwin/
test_func = "socket"
when /beos/
test_func = "socket"
have_library("net", "socket")
+ have_func("closesocket")
when /i386-os2_emx/
test_func = "socket"
have_library("socket", "socket")
@@ -86,10 +94,17 @@ if have_struct_member("struct sockaddr_in", "sin_len", headers)
end
# doug's fix, NOW add -Dss_family... only if required!
-doug = proc {have_struct_member("struct sockaddr_storage", "ss_family", headers)}
-if (doug[] or
- with_cppflags($CPPFLAGS + " -Dss_family=__ss_family -Dss_len=__ss_len", &doug))
- $defs[-1] = "-DHAVE_SOCKADDR_STORAGE"
+[nil, " -Dss_family=__ss_family -Dss_len=__ss_len"].each do |flags|
+ if flags
+ cppflags = $CPPFLAGS
+ $CPPFLAGS += flags
+ end
+ if have_struct_member("struct sockaddr_storage", "ss_family", headers)
+ $defs[-1] = "-DHAVE_SOCKADDR_STORAGE"
+ break
+ elsif flags
+ $CPPFLAGS = cppflags
+ end
end
if have_struct_member("struct sockaddr", "sa_len", headers)
@@ -255,8 +270,6 @@ end
have_header("sys/un.h")
have_header("sys/uio.h")
-$distcleanfiles << "constants.h"
-
if have_func(test_func)
have_func("hsterror")
have_func("getipnodebyname") or have_func("gethostbyname2")
diff --git a/ext/socket/getaddrinfo.c b/ext/socket/getaddrinfo.c
index 49fdf9b597..9fb4ebcb06 100644
--- a/ext/socket/getaddrinfo.c
+++ b/ext/socket/getaddrinfo.c
@@ -40,7 +40,7 @@
#include "config.h"
#include <sys/types.h>
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__VMS)
#include <sys/param.h>
#if defined(__BEOS__)
# include <net/socket.h>
@@ -62,6 +62,11 @@
#include <resolv.h>
#endif
#include <unistd.h>
+#elif defined(__VMS )
+#include <socket.h>
+#include <inet.h>
+#include <in.h>
+#include <netdb.h>
#else
#include <winsock2.h>
#include <io.h>
@@ -198,7 +203,8 @@ if (pai->ai_flags & AI_CANONNAME) {\
const
#endif
char *
-gai_strerror(int ecode)
+gai_strerror(ecode)
+ int ecode;
{
if (ecode < 0 || ecode > EAI_MAX)
ecode = EAI_MAX;
@@ -206,7 +212,8 @@ gai_strerror(int ecode)
}
void
-freeaddrinfo(struct addrinfo *ai)
+freeaddrinfo(ai)
+ struct addrinfo *ai;
{
struct addrinfo *next;
@@ -220,7 +227,8 @@ freeaddrinfo(struct addrinfo *ai)
}
static int
-str_isnumber(const char *p)
+str_isnumber(p)
+ const char *p;
{
char *q = (char *)p;
while (*q) {
@@ -234,7 +242,10 @@ str_isnumber(const char *p)
#ifndef HAVE_INET_PTON
static int
-inet_pton(int af, const char *hostname, void *pton)
+inet_pton(af, hostname, pton)
+ int af;
+ const char *hostname;
+ void *pton;
{
struct in_addr in;
@@ -262,7 +273,10 @@ inet_pton(int af, const char *hostname, void *pton)
#endif
int
-getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res)
+getaddrinfo(hostname, servname, hints, res)
+ const char *hostname, *servname;
+ const struct addrinfo *hints;
+ struct addrinfo **res;
{
struct addrinfo sentinel;
struct addrinfo *top = NULL;
@@ -428,7 +442,7 @@ getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *h
s = socket(afd->a_af, SOCK_DGRAM, 0);
if (s < 0)
continue;
-#if defined(__BEOS__)
+#if defined(HAVE_CLOSESOCKET)
closesocket(s);
#else
close(s);
@@ -529,7 +543,13 @@ getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *h
}
static int
-get_name(const char *addr, const struct afd *afd, struct addrinfo **res, char *numaddr, struct addrinfo *pai, int port0)
+get_name(addr, afd, res, numaddr, pai, port0)
+ const char *addr;
+ const struct afd *afd;
+ struct addrinfo **res;
+ char *numaddr;
+ struct addrinfo *pai;
+ int port0;
{
u_short port = port0 & 0xffff;
struct hostent *hp;
@@ -569,7 +589,12 @@ get_name(const char *addr, const struct afd *afd, struct addrinfo **res, char *n
}
static int
-get_addr(const char *hostname, int af, struct addrinfo **res, struct addrinfo *pai, int port0)
+get_addr(hostname, af, res, pai, port0)
+ const char *hostname;
+ int af;
+ struct addrinfo **res;
+ struct addrinfo *pai;
+ int port0;
{
u_short port = port0 & 0xffff;
struct addrinfo sentinel;
diff --git a/ext/socket/getnameinfo.c b/ext/socket/getnameinfo.c
index 91e18e916f..66f7e8818a 100644
--- a/ext/socket/getnameinfo.c
+++ b/ext/socket/getnameinfo.c
@@ -35,6 +35,7 @@
*/
#include "config.h"
+#include <stdio.h>
#include <sys/types.h>
#ifndef _WIN32
#if defined(__BEOS__)
@@ -51,15 +52,11 @@
#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
@@ -115,7 +112,11 @@ static struct afd {
#ifndef HAVE_INET_NTOP
static const char *
-inet_ntop(int af, const void *addr, char *numaddr, size_t numaddr_len)
+inet_ntop(af, addr, numaddr, numaddr_len)
+ int af;
+ const void *addr;
+ char *numaddr;
+ size_t numaddr_len;
{
#ifdef HAVE_INET_NTOA
struct in_addr in;
@@ -132,7 +133,14 @@ inet_ntop(int af, const void *addr, char *numaddr, size_t numaddr_len)
#endif
int
-getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
+getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
+ const struct sockaddr *sa;
+ size_t salen;
+ char *host;
+ size_t hostlen;
+ char *serv;
+ size_t servlen;
+ int flags;
{
struct afd *afd;
struct servent *sp;
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb
deleted file mode 100644
index 5212739876..0000000000
--- a/ext/socket/mkconstants.rb
+++ /dev/null
@@ -1,262 +0,0 @@
-$out ||= $stdout
-
-# workaround for NetBSD, OpenBSD and etc.
-$out.puts("#define pseudo_AF_FTIP pseudo_AF_RTIP")
-
-# skip empty lines and comment lines
-DATA.each_line do |s|
- name, value = s.scan(/\S+/)
- if name && name[0] != ?#
- $out.puts("#ifdef #{name}")
- $out.puts(" sock_define_const(\"#{name}\", #{name});")
- if value
- $out.puts("#else")
- $out.puts(" sock_define_const(\"#{name}\", #{value});")
- end
- $out.puts("#endif")
- $out.puts
- end
-end
-
-__END__
-
-SOCK_STREAM
-SOCK_DGRAM
-SOCK_RAW
-SOCK_RDM
-SOCK_SEQPACKET
-SOCK_PACKET
-
-AF_INET
-PF_INET
-AF_UNIX
-PF_UNIX
-AF_AX25
-PF_AX25
-AF_IPX
-PF_IPX
-AF_APPLETALK
-PF_APPLETALK
-AF_UNSPEC
-PF_UNSPEC
-AF_LOCAL
-PF_LOCAL
-AF_IMPLINK
-PF_IMPLINK
-AF_PUP
-PF_PUP
-AF_CHAOS
-PF_CHAOS
-AF_NS
-PF_NS
-AF_ISO
-PF_ISO
-AF_OSI
-PF_OSI
-AF_ECMA
-PF_ECMA
-AF_DATAKIT
-PF_DATAKIT
-AF_CCITT
-PF_CCITT
-AF_SNA
-PF_SNA
-AF_DEC
-PF_DEC
-AF_DLI
-PF_DLI
-AF_LAT
-PF_LAT
-AF_HYLINK
-PF_HYLINK
-AF_ROUTE
-PF_ROUTE
-AF_LINK
-PF_LINK
-AF_COIP
-PF_COIP
-AF_CNT
-PF_CNT
-AF_SIP
-PF_SIP
-AF_NDRV
-PF_NDRV
-AF_ISDN
-PF_ISDN
-AF_NATM
-PF_NATM
-AF_SYSTEM
-PF_SYSTEM
-AF_NETBIOS
-PF_NETBIOS
-AF_PPP
-PF_PPP
-AF_ATM
-PF_ATM
-AF_NETGRAPH
-PF_NETGRAPH
-AF_MAX
-PF_MAX
-
-AF_E164
-PF_XTP
-PF_RTIP
-PF_PIP
-PF_KEY
-
-MSG_OOB
-MSG_PEEK
-MSG_DONTROUTE
-MSG_EOR
-MSG_TRUNC
-MSG_CTRUNC
-MSG_WAITALL
-MSG_DONTWAIT
-MSG_EOF
-MSG_FLUSH
-MSG_HOLD
-MSG_SEND
-MSG_HAVEMORE
-MSG_RCVMORE
-MSG_COMPAT
-
-SOL_SOCKET
-SOL_IP
-SOL_IPX
-SOL_AX25
-SOL_ATALK
-SOL_TCP
-SOL_UDP
-
-IPPROTO_IP 0
-IPPROTO_ICMP 1
-IPPROTO_IGMP
-IPPROTO_GGP
-IPPROTO_TCP 6
-IPPROTO_EGP
-IPPROTO_PUP
-IPPROTO_UDP 17
-IPPROTO_IDP
-IPPROTO_HELLO
-IPPROTO_ND
-IPPROTO_TP
-IPPROTO_XTP
-IPPROTO_EON
-IPPROTO_BIP
-IPPROTO_RAW 255
-IPPROTO_MAX
-
-# Some port configuration
-IPPORT_RESERVED 1024
-IPPORT_USERRESERVED 5000
-
-# Some reserved IP v.4 addresses
-INADDR_ANY 0x00000000
-INADDR_BROADCAST 0xffffffff
-INADDR_LOOPBACK 0x7F000001
-INADDR_UNSPEC_GROUP 0xe0000000
-INADDR_ALLHOSTS_GROUP 0xe0000001
-INADDR_MAX_LOCAL_GROUP 0xe00000ff
-INADDR_NONE 0xffffffff
-
-# IP [gs]etsockopt options
-IP_OPTIONS
-IP_HDRINCL
-IP_TOS
-IP_TTL
-IP_RECVOPTS
-IP_RECVRETOPTS
-IP_RECVDSTADDR
-IP_RETOPTS
-IP_MULTICAST_IF
-IP_MULTICAST_TTL
-IP_MULTICAST_LOOP
-IP_ADD_MEMBERSHIP
-IP_DROP_MEMBERSHIP
-IP_DEFAULT_MULTICAST_TTL
-IP_DEFAULT_MULTICAST_LOOP
-IP_MAX_MEMBERSHIPS
-
-SO_DEBUG
-SO_REUSEADDR
-SO_REUSEPORT
-SO_TYPE
-SO_ERROR
-SO_DONTROUTE
-SO_BROADCAST
-SO_SNDBUF
-SO_RCVBUF
-SO_KEEPALIVE
-SO_OOBINLINE
-SO_NO_CHECK
-SO_PRIORITY
-SO_LINGER
-SO_PASSCRED
-SO_PEERCRED
-SO_RCVLOWAT
-SO_SNDLOWAT
-SO_RCVTIMEO
-SO_SNDTIMEO
-SO_ACCEPTCONN
-SO_USELOOPBACK
-SO_ACCEPTFILTER
-SO_DONTTRUNC
-SO_WANTMORE
-SO_WANTOOBFLAG
-SO_NREAD
-SO_NKE
-SO_NOSIGPIPE
-SO_SECURITY_AUTHENTICATION
-SO_SECURITY_ENCRYPTION_TRANSPORT
-SO_SECURITY_ENCRYPTION_NETWORK
-SO_BINDTODEVICE
-SO_ATTACH_FILTER
-SO_DETACH_FILTER
-SO_PEERNAME
-SO_TIMESTAMP
-
-SOPRI_INTERACTIVE
-SOPRI_NORMAL
-SOPRI_BACKGROUND
-
-IPX_TYPE
-
-TCP_NODELAY
-TCP_MAXSEG
-
-EAI_ADDRFAMILY
-EAI_AGAIN
-EAI_BADFLAGS
-EAI_FAIL
-EAI_FAMILY
-EAI_MEMORY
-EAI_NODATA
-EAI_NONAME
-EAI_SERVICE
-EAI_SOCKTYPE
-EAI_SYSTEM
-EAI_BADHINTS
-EAI_PROTOCOL
-EAI_MAX
-
-AI_PASSIVE
-AI_CANONNAME
-AI_NUMERICHOST
-AI_MASK
-AI_ALL
-AI_V4MAPPED_CFG
-AI_ADDRCONFIG
-AI_V4MAPPED
-AI_DEFAULT
-
-NI_MAXHOST
-NI_MAXSERV
-NI_NOFQDN
-NI_NUMERICHOST
-NI_NAMEREQD
-NI_NUMERICSERV
-NI_DGRAM
-
-SHUT_RD 0
-SHUT_WR 1
-SHUT_RDWR 2
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 419f08c6de..22e178a4c8 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -30,6 +30,7 @@
# include <net/socket.h>
#else
# include <sys/socket.h>
+# define pseudo_AF_FTIP pseudo_AF_RTIP /* workaround for NetBSD and etc. */
#endif
#include <netinet/in.h>
#ifdef HAVE_NETINET_IN_SYSTM_H
@@ -73,8 +74,11 @@
#endif
#include "sockport.h"
+#if defined(__vms)
+#include <tcp.h>
+#endif
+
static int do_not_reverse_lookup = 0;
-#define FMODE_NOREVLOOKUP 0x100
VALUE rb_cBasicSocket;
VALUE rb_cIPSocket;
@@ -139,8 +143,11 @@ static int lookup_order_table[LOOKUP_ORDERS] = {
};
static int
-ruby_getaddrinfo(char *nodename, char *servname,
- struct addrinfo *hints, struct addrinfo **res)
+ruby_getaddrinfo(nodename, servname, hints, res)
+ char *nodename;
+ char *servname;
+ struct addrinfo *hints;
+ struct addrinfo **res;
{
struct addrinfo tmp_hints;
int i, af, error;
@@ -171,8 +178,11 @@ ruby_getaddrinfo(char *nodename, char *servname,
#if defined(_AIX)
static int
-ruby_getaddrinfo__aix(char *nodename, char *servname,
- struct addrinfo *hints, struct addrinfo **res)
+ruby_getaddrinfo__aix(nodename, servname, hints, res)
+ char *nodename;
+ char *servname;
+ struct addrinfo *hints;
+ struct addrinfo **res;
{
int error = getaddrinfo(nodename, servname, hints, res);
struct addrinfo *r;
@@ -224,29 +234,30 @@ ruby_getnameinfo__aix(sa, salen, host, hostlen, serv, servlen, flags)
#endif
#endif
-#ifdef __BEOS__
+#ifdef HAVE_CLOSESOCKET
#undef close
#define close closesocket
#endif
static VALUE
-init_sock(VALUE sock, int fd)
+init_sock(sock, fd)
+ VALUE sock;
+ int fd;
{
OpenFile *fp;
MakeOpenFile(sock, fp);
- fp->fd = fd;
- fp->mode = FMODE_READWRITE|FMODE_DUPLEX;
- if (do_not_reverse_lookup) {
- fp->mode |= FMODE_NOREVLOOKUP;
- }
+ fp->f = rb_fdopen(fd, "r");
+ fp->f2 = rb_fdopen(fd, "w");
+ fp->mode = FMODE_READWRITE;
rb_io_synchronized(fp);
return sock;
}
static VALUE
-bsock_s_for_fd(VALUE klass, VALUE fd)
+bsock_s_for_fd(klass, fd)
+ VALUE klass, fd;
{
OpenFile *fptr;
VALUE sock = init_sock(rb_obj_alloc(klass), NUM2INT(fd));
@@ -257,7 +268,10 @@ bsock_s_for_fd(VALUE klass, VALUE fd)
}
static VALUE
-bsock_shutdown(int argc, VALUE *argv, VALUE sock)
+bsock_shutdown(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
VALUE howto;
int how;
@@ -276,14 +290,15 @@ bsock_shutdown(int argc, VALUE *argv, VALUE sock)
}
}
GetOpenFile(sock, fptr);
- if (shutdown(fptr->fd, how) == -1)
+ if (shutdown(fileno(fptr->f), how) == -1)
rb_sys_fail(0);
return INT2FIX(0);
}
static VALUE
-bsock_close_read(VALUE sock)
+bsock_close_read(sock)
+ VALUE sock;
{
OpenFile *fptr;
@@ -291,7 +306,7 @@ bsock_close_read(VALUE sock)
rb_raise(rb_eSecurityError, "Insecure: can't close socket");
}
GetOpenFile(sock, fptr);
- shutdown(fptr->fd, 0);
+ shutdown(fileno(fptr->f), 0);
if (!(fptr->mode & FMODE_WRITABLE)) {
return rb_io_close(sock);
}
@@ -301,7 +316,8 @@ bsock_close_read(VALUE sock)
}
static VALUE
-bsock_close_write(VALUE sock)
+bsock_close_write(sock)
+ VALUE sock;
{
OpenFile *fptr;
@@ -312,7 +328,7 @@ bsock_close_write(VALUE sock)
if (!(fptr->mode & FMODE_READABLE)) {
return rb_io_close(sock);
}
- shutdown(fptr->fd, 1);
+ shutdown(fileno(fptr->f2), 1);
fptr->mode &= ~FMODE_WRITABLE;
return Qnil;
@@ -364,7 +380,8 @@ bsock_close_write(VALUE sock)
*
*/
static VALUE
-bsock_setsockopt(VALUE sock, VALUE lev, VALUE optname, VALUE val)
+bsock_setsockopt(sock, lev, optname, val)
+ VALUE sock, lev, optname, val;
{
int level, option;
OpenFile *fptr;
@@ -390,13 +407,13 @@ bsock_setsockopt(VALUE sock, VALUE lev, VALUE optname, VALUE val)
break;
default:
StringValue(val);
- v = RSTRING_PTR(val);
- vlen = RSTRING_LEN(val);
+ v = RSTRING(val)->ptr;
+ vlen = RSTRING(val)->len;
break;
}
GetOpenFile(sock, fptr);
- if (setsockopt(fptr->fd, level, option, v, vlen) < 0)
+ if (setsockopt(fileno(fptr->f), level, option, v, vlen) < 0)
rb_sys_fail(fptr->path);
return INT2FIX(0);
@@ -443,7 +460,8 @@ bsock_setsockopt(VALUE sock, VALUE lev, VALUE optname, VALUE val)
* onoff, linger = optval.unpack "ii"
*/
static VALUE
-bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
+bsock_getsockopt(sock, lev, optname)
+ VALUE sock, lev, optname;
{
#if !defined(__BEOS__)
int level, option;
@@ -455,9 +473,10 @@ bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
option = NUM2INT(optname);
len = 256;
buf = ALLOCA_N(char,len);
+ GetOpenFile(sock, fptr);
GetOpenFile(sock, fptr);
- if (getsockopt(fptr->fd, level, option, buf, &len) < 0)
+ if (getsockopt(fileno(fptr->f), level, option, buf, &len) < 0)
rb_sys_fail(fptr->path);
return rb_str_new(buf, len);
@@ -467,37 +486,43 @@ bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
}
static VALUE
-bsock_getsockname(VALUE sock)
+bsock_getsockname(sock)
+ VALUE sock;
{
char buf[1024];
socklen_t len = sizeof buf;
OpenFile *fptr;
GetOpenFile(sock, fptr);
- if (getsockname(fptr->fd, (struct sockaddr*)buf, &len) < 0)
+ if (getsockname(fileno(fptr->f), (struct sockaddr*)buf, &len) < 0)
rb_sys_fail("getsockname(2)");
return rb_str_new(buf, len);
}
static VALUE
-bsock_getpeername(VALUE sock)
+bsock_getpeername(sock)
+ VALUE sock;
{
char buf[1024];
socklen_t len = sizeof buf;
OpenFile *fptr;
GetOpenFile(sock, fptr);
- if (getpeername(fptr->fd, (struct sockaddr*)buf, &len) < 0)
+ if (getpeername(fileno(fptr->f), (struct sockaddr*)buf, &len) < 0)
rb_sys_fail("getpeername(2)");
return rb_str_new(buf, len);
}
static VALUE
-bsock_send(int argc, VALUE *argv, VALUE sock)
+bsock_send(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
VALUE mesg, to;
VALUE flags;
OpenFile *fptr;
+ FILE *f;
int fd, n;
rb_secure(4);
@@ -506,18 +531,19 @@ bsock_send(int argc, VALUE *argv, VALUE sock)
StringValue(mesg);
if (!NIL_P(to)) StringValue(to);
GetOpenFile(sock, fptr);
- fd = fptr->fd;
+ f = GetWriteFile(fptr);
+ fd = fileno(f);
rb_thread_fd_writable(fd);
retry:
if (!NIL_P(to)) {
TRAP_BEG;
- n = sendto(fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg), NUM2INT(flags),
- (struct sockaddr*)RSTRING_PTR(to), RSTRING_LEN(to));
+ n = sendto(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
+ (struct sockaddr*)RSTRING(to)->ptr, RSTRING(to)->len);
TRAP_END;
}
else {
TRAP_BEG;
- n = send(fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg), NUM2INT(flags));
+ n = send(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags));
TRAP_END;
}
if (n < 0) {
@@ -529,34 +555,9 @@ bsock_send(int argc, VALUE *argv, VALUE sock)
return INT2FIX(n);
}
-static VALUE
-bsock_do_not_reverse_lookup(VALUE sock)
-{
- OpenFile *fptr;
-
- GetOpenFile(sock, fptr);
- return (fptr->mode & FMODE_NOREVLOOKUP) ? Qtrue : Qfalse;
-}
-
-static VALUE
-bsock_do_not_reverse_lookup_set(VALUE sock, VALUE state)
-{
- OpenFile *fptr;
-
- rb_secure(4);
- GetOpenFile(sock, fptr);
- if (RTEST(state)) {
- fptr->mode |= FMODE_NOREVLOOKUP;
- }
- else {
- fptr->mode &= ~FMODE_NOREVLOOKUP;
- }
- return sock;
-}
-
-static VALUE ipaddr(struct sockaddr*, int);
+static VALUE ipaddr _((struct sockaddr*));
#ifdef HAVE_SYS_UN_H
-static VALUE unixaddr(struct sockaddr_un*, socklen_t);
+static VALUE unixaddr _((struct sockaddr_un*, socklen_t));
#endif
enum sock_recv_type {
@@ -567,7 +568,11 @@ enum sock_recv_type {
};
static VALUE
-s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
+s_recvfrom(sock, argc, argv, from)
+ VALUE sock;
+ int argc;
+ VALUE *argv;
+ enum sock_recv_type from;
{
OpenFile *fptr;
VALUE str;
@@ -585,22 +590,20 @@ s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
buflen = NUM2INT(len);
GetOpenFile(sock, fptr);
- if (rb_io_read_pending(fptr)) {
+ if (rb_read_pending(fptr->f)) {
rb_raise(rb_eIOError, "recv for buffered IO");
}
- fd = fptr->fd;
+ fd = fileno(fptr->f);
str = rb_tainted_str_new(0, buflen);
retry:
+ rb_str_locktmp(str);
rb_thread_wait_fd(fd);
- rb_io_check_closed(fptr);
- if (RSTRING_LEN(str) != buflen) {
- rb_raise(rb_eRuntimeError, "buffer string modified");
- }
TRAP_BEG;
- slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, (struct sockaddr*)buf, &alen);
+ slen = recvfrom(fd, RSTRING(str)->ptr, buflen, flags, (struct sockaddr*)buf, &alen);
TRAP_END;
+ rb_str_unlocktmp(str);
if (slen < 0) {
if (rb_io_wait_readable(fd)) {
@@ -608,8 +611,9 @@ s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
}
rb_sys_fail("recvfrom(2)");
}
- if (slen < RSTRING_LEN(str)) {
- rb_str_set_len(str, slen);
+ if (slen < RSTRING(str)->len) {
+ RSTRING(str)->len = slen;
+ RSTRING(str)->ptr[slen] = '\0';
}
rb_obj_taint(str);
switch (from) {
@@ -621,8 +625,8 @@ s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
#endif
- if (alen) /* OSX doesn't return a from result for connection-oriented sockets */
- return rb_assoc_new(str, ipaddr((struct sockaddr*)buf, fptr->mode & FMODE_NOREVLOOKUP));
+ if (alen && alen != sizeof(buf)) /* 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);
@@ -663,31 +667,32 @@ s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
#endif
GetOpenFile(sock, fptr);
- if (rb_io_read_pending(fptr)) {
+ if (rb_read_pending(fptr->f)) {
rb_raise(rb_eIOError, "recvfrom for buffered IO");
}
- fd = fptr->fd;
+ fd = fileno(fptr->f);
str = rb_tainted_str_new(0, buflen);
rb_io_check_closed(fptr);
rb_io_set_nonblock(fptr);
- slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, (struct sockaddr*)buf, &alen);
+ slen = recvfrom(fd, RSTRING(str)->ptr, buflen, flags, (struct sockaddr*)buf, &alen);
if (slen < 0) {
rb_sys_fail("recvfrom(2)");
}
- if (slen < RSTRING_LEN(str)) {
- rb_str_set_len(str, slen);
+ if (slen < RSTRING(str)->len) {
+ RSTRING(str)->len = slen;
+ RSTRING(str)->ptr[slen] = '\0';
}
rb_obj_taint(str);
switch (from) {
case RECV_RECV:
- return str;
+ return str;
case RECV_IP:
- if (alen) /* connection-oriented socket may not return a from result */
- addr = ipaddr((struct sockaddr*)buf, fptr->mode & FMODE_NOREVLOOKUP);
+ if (alen && alen != sizeof(buf)) /* connection-oriented socket may not return a from result */
+ addr = ipaddr((struct sockaddr*)buf);
break;
case RECV_SOCKET:
@@ -701,7 +706,10 @@ s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
}
static VALUE
-bsock_recv(int argc, VALUE *argv, VALUE sock)
+bsock_recv(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
return s_recvfrom(sock, argc, argv, RECV_RECV);
}
@@ -744,7 +752,10 @@ bsock_recv(int argc, VALUE *argv, VALUE sock)
*/
static VALUE
-bsock_recv_nonblock(int argc, VALUE *argv, VALUE sock)
+bsock_recv_nonblock(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
return s_recvfrom_nonblock(sock, argc, argv, RECV_RECV);
}
@@ -756,36 +767,31 @@ bsock_do_not_rev_lookup()
}
static VALUE
-bsock_do_not_rev_lookup_set(VALUE self, VALUE val)
+bsock_do_not_rev_lookup_set(self, val)
+ VALUE self, val;
{
rb_secure(4);
do_not_reverse_lookup = RTEST(val);
return val;
}
-NORETURN(static void raise_socket_error(char *, int));
static void
-raise_socket_error(char *reason, int error)
-{
-#ifdef EAI_SYSTEM
- if (error == EAI_SYSTEM) rb_sys_fail(reason);
-#endif
- rb_raise(rb_eSocket, "%s: %s", reason, gai_strerror(error));
-}
-
-static void
-make_ipaddr0(struct sockaddr *addr, char *buf, size_t len)
+make_ipaddr0(addr, buf, len)
+ struct sockaddr *addr;
+ char *buf;
+ size_t len;
{
int error;
error = getnameinfo(addr, SA_LEN(addr), buf, len, NULL, 0, NI_NUMERICHOST);
if (error) {
- raise_socket_error("getnameinfo", error);
+ rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error));
}
}
static VALUE
-make_ipaddr(struct sockaddr *addr)
+make_ipaddr(addr)
+ struct sockaddr *addr;
{
char buf[1024];
@@ -794,7 +800,10 @@ make_ipaddr(struct sockaddr *addr)
}
static void
-make_inetaddr(long host, char *buf, size_t len)
+make_inetaddr(host, buf, len)
+ long host;
+ char *buf;
+ size_t len;
{
struct sockaddr_in sin;
@@ -806,7 +815,8 @@ make_inetaddr(long host, char *buf, size_t len)
}
static int
-str_isnumber(const char *p)
+str_isnumber(p)
+ const char *p;
{
char *ep;
@@ -820,8 +830,11 @@ str_isnumber(const char *p)
return 0;
}
-static char*
-host_str(VALUE host, char *hbuf, size_t len)
+static char *
+host_str(host, hbuf, len)
+ VALUE host;
+ char *hbuf;
+ size_t len;
{
if (NIL_P(host)) {
return NULL;
@@ -836,7 +849,7 @@ host_str(VALUE host, char *hbuf, size_t len)
char *name;
SafeStringValue(host);
- name = RSTRING_PTR(host);
+ name = RSTRING(host)->ptr;
if (!name || *name == 0 || (name[0] == '<' && strcmp(name, "<any>") == 0)) {
make_inetaddr(INADDR_ANY, hbuf, len);
}
@@ -853,8 +866,11 @@ host_str(VALUE host, char *hbuf, size_t len)
}
}
-static char*
-port_str(VALUE port, char *pbuf, size_t len)
+static char *
+port_str(port, pbuf, len)
+ VALUE port;
+ char *pbuf;
+ size_t len;
{
if (NIL_P(port)) {
return 0;
@@ -867,7 +883,7 @@ port_str(VALUE port, char *pbuf, size_t len)
char *serv;
SafeStringValue(port);
- serv = RSTRING_PTR(port);
+ serv = RSTRING(port)->ptr;
if (strlen(serv) >= len) {
rb_raise(rb_eArgError, "service name too long (%d)", strlen(serv));
}
@@ -884,7 +900,9 @@ port_str(VALUE port, char *pbuf, size_t len)
#endif
static struct addrinfo*
-sock_addrinfo(VALUE host, VALUE port, int socktype, int flags)
+sock_addrinfo(host, port, socktype, flags)
+ VALUE host, port;
+ int socktype, flags;
{
struct addrinfo hints;
struct addrinfo* res = NULL;
@@ -908,7 +926,7 @@ sock_addrinfo(VALUE host, VALUE port, int socktype, int flags)
if (hostp && hostp[strlen(hostp)-1] == '\n') {
rb_raise(rb_eSocket, "newline at the end of hostname");
}
- raise_socket_error("getaddrinfo", error);
+ rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error));
}
#if defined(__APPLE__) && defined(__MACH__)
@@ -932,7 +950,8 @@ sock_addrinfo(VALUE host, VALUE port, int socktype, int flags)
}
static VALUE
-ipaddr(struct sockaddr *sockaddr, int norevlookup)
+ipaddr(sockaddr)
+ struct sockaddr *sockaddr;
{
VALUE family, port, addr1, addr2;
VALUE ary;
@@ -965,9 +984,8 @@ ipaddr(struct sockaddr *sockaddr, int norevlookup)
family = rb_str_new2(pbuf);
break;
}
-
addr1 = Qnil;
- if (!norevlookup) {
+ if (!do_not_reverse_lookup) {
error = getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf),
NULL, 0, 0);
if (! error) {
@@ -977,7 +995,7 @@ ipaddr(struct sockaddr *sockaddr, int norevlookup)
error = getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf),
pbuf, sizeof(pbuf), NI_NUMERICHOST | NI_NUMERICSERV);
if (error) {
- raise_socket_error("getnameinfo", error);
+ rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error));
}
addr2 = rb_str_new2(hbuf);
if (addr1 == Qnil) {
@@ -990,7 +1008,8 @@ ipaddr(struct sockaddr *sockaddr, int norevlookup)
}
static int
-ruby_socket(int domain, int type, int proto)
+ruby_socket(domain, type, proto)
+ int domain, type, proto;
{
int fd;
@@ -1005,24 +1024,27 @@ ruby_socket(int domain, int type, int proto)
}
static int
-wait_connectable0(int fd, rb_fdset_t *fds_w, rb_fdset_t *fds_e)
+wait_connectable(fd)
+ int fd;
{
int sockerr;
socklen_t sockerrlen;
+ fd_set fds_w;
+ fd_set fds_e;
for (;;) {
- rb_fd_zero(fds_w);
- rb_fd_zero(fds_e);
+ FD_ZERO(&fds_w);
+ FD_ZERO(&fds_e);
- rb_fd_set(fd, fds_w);
- rb_fd_set(fd, fds_e);
+ FD_SET(fd, &fds_w);
+ FD_SET(fd, &fds_e);
- rb_thread_select(fd+1, 0, rb_fd_ptr(fds_w), rb_fd_ptr(fds_e), 0);
+ rb_thread_select(fd+1, 0, &fds_w, &fds_e, 0);
- if (rb_fd_isset(fd, fds_w)) {
+ if (FD_ISSET(fd, &fds_w)) {
return 0;
}
- else if (rb_fd_isset(fd, fds_e)) {
+ else if (FD_ISSET(fd, &fds_e)) {
sockerrlen = sizeof(sockerr);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr,
&sockerrlen) == 0) {
@@ -1037,46 +1059,6 @@ wait_connectable0(int fd, rb_fdset_t *fds_w, rb_fdset_t *fds_e)
return 0;
}
-struct wait_connectable_arg {
- int fd;
- rb_fdset_t fds_w;
- rb_fdset_t fds_e;
-};
-
-#ifdef HAVE_RB_FD_INIT
-static VALUE
-try_wait_connectable(VALUE arg)
-{
- struct wait_connectable_arg *p = (struct wait_connectable_arg *)arg;
- return (VALUE)wait_connectable0(p->fd, &p->fds_w, &p->fds_e);
-}
-
-static VALUE
-wait_connectable_ensure(VALUE arg)
-{
- struct wait_connectable_arg *p = (struct wait_connectable_arg *)arg;
- rb_fd_term(&p->fds_w);
- rb_fd_term(&p->fds_e);
- return Qnil;
-}
-#endif
-
-static int
-wait_connectable(int fd)
-{
- struct wait_connectable_arg arg;
-
- rb_fd_init(&arg.fds_w);
- rb_fd_init(&arg.fds_e);
-#ifdef HAVE_RB_FD_INIT
- arg.fd = fd;
- return (int)rb_ensure(try_wait_connectable, (VALUE)&arg,
- wait_connectable_ensure,(VALUE)&arg);
-#else
- return wait_connectable0(fd, &arg.fds_w, &arg.fds_e);
-#endif
-}
-
#ifdef __CYGWIN__
#define WAIT_IN_PROGRESS 10
#endif
@@ -1093,7 +1075,11 @@ wait_connectable(int fd)
#endif
static int
-ruby_connect(int fd, struct sockaddr *sockaddr, int len, int socks)
+ruby_connect(fd, sockaddr, len, socks)
+ int fd;
+ struct sockaddr *sockaddr;
+ int len;
+ int socks;
{
int status;
int mode;
@@ -1214,7 +1200,8 @@ struct inetsock_arg
};
static VALUE
-inetsock_cleanup(struct inetsock_arg *arg)
+inetsock_cleanup(arg)
+ struct inetsock_arg *arg;
{
if (arg->remote.res) {
freeaddrinfo(arg->remote.res);
@@ -1231,7 +1218,8 @@ inetsock_cleanup(struct inetsock_arg *arg)
}
static VALUE
-init_inetsock_internal(struct inetsock_arg *arg)
+init_inetsock_internal(arg)
+ struct inetsock_arg *arg;
{
int type = arg->type;
struct addrinfo *res;
@@ -1300,8 +1288,9 @@ init_inetsock_internal(struct inetsock_arg *arg)
}
static VALUE
-init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv,
- VALUE local_host, VALUE local_serv, int type)
+init_inetsock(sock, remote_host, remote_serv, local_host, local_serv, type)
+ VALUE sock, remote_host, remote_serv, local_host, local_serv;
+ int type;
{
struct inetsock_arg arg;
arg.sock = sock;
@@ -1326,7 +1315,10 @@ init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv,
* end to establish the connection.
*/
static VALUE
-tcp_init(int argc, VALUE *argv, VALUE sock)
+tcp_init(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
VALUE remote_host, remote_serv;
VALUE local_host, local_serv;
@@ -1340,7 +1332,8 @@ tcp_init(int argc, VALUE *argv, VALUE sock)
#ifdef SOCKS
static VALUE
-socks_init(VALUE sock, VALUE host, VALUE serv)
+socks_init(sock, host, serv)
+ VALUE sock, host, serv;
{
static init = 0;
@@ -1354,7 +1347,8 @@ socks_init(VALUE sock, VALUE host, VALUE serv)
#ifdef SOCKS5
static VALUE
-socks_s_close(VALUE sock)
+socks_s_close(sock)
+ VALUE sock;
{
OpenFile *fptr;
@@ -1362,7 +1356,8 @@ socks_s_close(VALUE sock)
rb_raise(rb_eSecurityError, "Insecure: can't close socket");
}
GetOpenFile(sock, fptr);
- shutdown(fptr->fd, 2);
+ shutdown(fileno(fptr->f), 2);
+ shutdown(fileno(fptr->f2), 2);
return rb_io_close(sock);
}
#endif
@@ -1371,15 +1366,16 @@ socks_s_close(VALUE sock)
struct hostent_arg {
VALUE host;
struct addrinfo* addr;
- VALUE (*ipaddr)(struct sockaddr*, size_t);
+ VALUE (*ipaddr)_((struct sockaddr*, size_t));
};
static VALUE
-make_hostent_internal(struct hostent_arg *arg)
+make_hostent_internal(arg)
+ struct hostent_arg *arg;
{
VALUE host = arg->host;
struct addrinfo* addr = arg->addr;
- VALUE (*ipaddr)(struct sockaddr*, size_t) = arg->ipaddr;
+ VALUE (*ipaddr)_((struct sockaddr*, size_t)) = arg->ipaddr;
struct addrinfo *ai;
struct hostent *h;
@@ -1411,14 +1407,23 @@ make_hostent_internal(struct hostent_arg *arg)
rb_ary_push(ary, names);
rb_ary_push(ary, INT2NUM(addr->ai_family));
for (ai = addr; ai; ai = ai->ai_next) {
- rb_ary_push(ary, (*ipaddr)(ai->ai_addr, ai->ai_addrlen));
+ /* Pushing all addresses regardless of address family is not the
+ * behaviour expected of gethostbyname(). All the addresses in struct
+ * hostent->h_addr_list must be of the same family.
+ */
+ if(ai->ai_family == addr->ai_family) {
+ rb_ary_push(ary, (*ipaddr)(ai->ai_addr, ai->ai_addrlen));
+ }
}
return ary;
}
static VALUE
-make_hostent(VALUE host, struct addrinfo *addr, VALUE (*ipaddr)(struct sockaddr *, size_t))
+make_hostent(host, addr, ipaddr)
+ VALUE host;
+ struct addrinfo* addr;
+ VALUE (*ipaddr)_((struct sockaddr*, size_t));
{
struct hostent_arg arg;
@@ -1429,22 +1434,27 @@ make_hostent(VALUE host, struct addrinfo *addr, VALUE (*ipaddr)(struct sockaddr
RUBY_METHOD_FUNC(freeaddrinfo), (VALUE)addr);
}
-static VALUE
-tcp_sockaddr(struct sockaddr *addr, size_t len)
+VALUE
+tcp_sockaddr(addr, len)
+ struct sockaddr *addr;
+ size_t len;
{
return make_ipaddr(addr);
}
static VALUE
-tcp_s_gethostbyname(VALUE obj, VALUE host)
+tcp_s_gethostbyname(obj, host)
+ VALUE obj, host;
{
rb_secure(3);
- return make_hostent(host, sock_addrinfo(host, Qnil, SOCK_STREAM, AI_CANONNAME),
- tcp_sockaddr);
+ return make_hostent(host, sock_addrinfo(host, Qnil, SOCK_STREAM, AI_CANONNAME), tcp_sockaddr);
}
static VALUE
-tcp_svr_init(int argc, VALUE *argv, VALUE sock)
+tcp_svr_init(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
VALUE arg1, arg2;
@@ -1454,6 +1464,24 @@ tcp_svr_init(int argc, VALUE *argv, VALUE 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)
{
@@ -1461,15 +1489,20 @@ s_accept_nonblock(VALUE klass, OpenFile *fptr, struct sockaddr *sockaddr, sockle
rb_secure(3);
rb_io_set_nonblock(fptr);
- fd2 = accept(fptr->fd, (struct sockaddr*)sockaddr, len);
+ fd2 = accept(fileno(fptr->f), (struct sockaddr*)sockaddr, len);
if (fd2 < 0) {
rb_sys_fail("accept(2)");
}
+ make_fd_nonblock(fd2);
return init_sock(rb_obj_alloc(klass), fd2);
}
static VALUE
-s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
+s_accept(klass, fd, sockaddr, len)
+ VALUE klass;
+ int fd;
+ struct sockaddr *sockaddr;
+ socklen_t *len;
{
int fd2;
int retry = 0;
@@ -1492,6 +1525,8 @@ s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
rb_gc();
retry = 1;
goto retry;
+ case EWOULDBLOCK:
+ break;
default:
if (!rb_io_wait_readable(fd)) break;
retry = 0;
@@ -1504,15 +1539,16 @@ s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
}
static VALUE
-tcp_accept(VALUE sock)
+tcp_accept(sock)
+ VALUE sock;
{
OpenFile *fptr;
struct sockaddr_storage from;
socklen_t fromlen;
-
+
GetOpenFile(sock, fptr);
fromlen = sizeof(from);
- return s_accept(rb_cTCPSocket, fptr->fd,
+ return s_accept(rb_cTCPSocket, fileno(fptr->f),
(struct sockaddr*)&from, &fromlen);
}
@@ -1546,7 +1582,8 @@ tcp_accept(VALUE sock)
* * Socket#accept
*/
static VALUE
-tcp_accept_nonblock(VALUE sock)
+tcp_accept_nonblock(sock)
+ VALUE sock;
{
OpenFile *fptr;
struct sockaddr_storage from;
@@ -1555,11 +1592,12 @@ tcp_accept_nonblock(VALUE sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(from);
return s_accept_nonblock(rb_cTCPSocket, fptr,
- (struct sockaddr *)&from, &fromlen);
+ (struct sockaddr *)&from, &fromlen);
}
static VALUE
-tcp_sysaccept(VALUE sock)
+tcp_sysaccept(sock)
+ VALUE sock;
{
OpenFile *fptr;
struct sockaddr_storage from;
@@ -1567,7 +1605,7 @@ tcp_sysaccept(VALUE sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(from);
- return s_accept(0, fptr->fd, (struct sockaddr*)&from, &fromlen);
+ return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
}
#ifdef HAVE_SYS_UN_H
@@ -1577,14 +1615,18 @@ struct unixsock_arg {
};
static VALUE
-unixsock_connect_internal(struct unixsock_arg *arg)
+unixsock_connect_internal(arg)
+ struct unixsock_arg *arg;
{
- return (VALUE)ruby_connect(arg->fd, (struct sockaddr*)arg->sockaddr,
- sizeof(*arg->sockaddr), 0);
+ return (VALUE)ruby_connect(arg->fd, arg->sockaddr, sizeof(*arg->sockaddr),
+ 0);
}
static VALUE
-init_unixsock(VALUE sock, VALUE path, int server)
+init_unixsock(sock, path, server)
+ VALUE sock;
+ VALUE path;
+ int server;
{
struct sockaddr_un sockaddr;
int fd, status;
@@ -1598,7 +1640,7 @@ init_unixsock(VALUE sock, VALUE path, int server)
MEMZERO(&sockaddr, struct sockaddr_un, 1);
sockaddr.sun_family = AF_UNIX;
- if (sizeof(sockaddr.sun_path) <= RSTRING_LEN(path)) {
+ if (sizeof(sockaddr.sun_path) <= RSTRING(path)->len) {
rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
(int)sizeof(sockaddr.sun_path)-1);
}
@@ -1612,8 +1654,7 @@ init_unixsock(VALUE sock, VALUE path, int server)
struct unixsock_arg arg;
arg.sockaddr = &sockaddr;
arg.fd = fd;
- status = rb_protect((VALUE(*)(VALUE))unixsock_connect_internal,
- (VALUE)&arg, &prot);
+ status = rb_protect(unixsock_connect_internal, (VALUE)&arg, &prot);
if (prot) {
close(fd);
rb_jump_tag(prot);
@@ -1630,7 +1671,7 @@ init_unixsock(VALUE sock, VALUE path, int server)
init_sock(sock, fd);
GetOpenFile(sock, fptr);
if (server) {
- fptr->path = strdup(RSTRING_PTR(path));
+ fptr->path = strdup(RSTRING(path)->ptr);
}
return sock;
@@ -1638,7 +1679,8 @@ init_unixsock(VALUE sock, VALUE path, int server)
#endif
static VALUE
-ip_addr(VALUE sock)
+ip_addr(sock)
+ VALUE sock;
{
OpenFile *fptr;
struct sockaddr_storage addr;
@@ -1646,13 +1688,14 @@ ip_addr(VALUE sock)
GetOpenFile(sock, fptr);
- if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
+ if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getsockname(2)");
- return ipaddr((struct sockaddr*)&addr, fptr->mode & FMODE_NOREVLOOKUP);
+ return ipaddr((struct sockaddr*)&addr);
}
static VALUE
-ip_peeraddr(VALUE sock)
+ip_peeraddr(sock)
+ VALUE sock;
{
OpenFile *fptr;
struct sockaddr_storage addr;
@@ -1660,19 +1703,23 @@ ip_peeraddr(VALUE sock)
GetOpenFile(sock, fptr);
- if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
+ if (getpeername(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getpeername(2)");
- return ipaddr((struct sockaddr*)&addr, fptr->mode & FMODE_NOREVLOOKUP);
+ return ipaddr((struct sockaddr*)&addr);
}
static VALUE
-ip_recvfrom(int argc, VALUE *argv, VALUE sock)
+ip_recvfrom(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
return s_recvfrom(sock, argc, argv, RECV_IP);
}
static VALUE
-ip_s_getaddress(VALUE obj, VALUE host)
+ip_s_getaddress(obj, host)
+ VALUE obj, host;
{
struct sockaddr_storage addr;
struct addrinfo *res = sock_addrinfo(host, Qnil, SOCK_STREAM, 0);
@@ -1685,7 +1732,10 @@ ip_s_getaddress(VALUE obj, VALUE host)
}
static VALUE
-udp_init(int argc, VALUE *argv, VALUE sock)
+udp_init(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
VALUE arg;
int socktype = AF_INET;
@@ -1710,7 +1760,8 @@ struct udp_arg
};
static VALUE
-udp_connect_internal(struct udp_arg *arg)
+udp_connect_internal(arg)
+ struct udp_arg *arg;
{
int fd = arg->fd;
struct addrinfo *res;
@@ -1724,7 +1775,8 @@ udp_connect_internal(struct udp_arg *arg)
}
static VALUE
-udp_connect(VALUE sock, VALUE host, VALUE port)
+udp_connect(sock, host, port)
+ VALUE sock, host, port;
{
OpenFile *fptr;
struct udp_arg arg;
@@ -1733,7 +1785,7 @@ udp_connect(VALUE sock, VALUE host, VALUE port)
rb_secure(3);
arg.res = sock_addrinfo(host, port, SOCK_DGRAM, 0);
GetOpenFile(sock, fptr);
- arg.fd = fptr->fd;
+ arg.fd = fileno(fptr->f);
ret = rb_ensure(udp_connect_internal, (VALUE)&arg,
RUBY_METHOD_FUNC(freeaddrinfo), (VALUE)arg.res);
if (!ret) rb_sys_fail("connect(2)");
@@ -1741,7 +1793,8 @@ udp_connect(VALUE sock, VALUE host, VALUE port)
}
static VALUE
-udp_bind(VALUE sock, VALUE host, VALUE port)
+udp_bind(sock, host, port)
+ VALUE sock, host, port;
{
OpenFile *fptr;
struct addrinfo *res0, *res;
@@ -1750,7 +1803,7 @@ udp_bind(VALUE sock, VALUE host, VALUE port)
res0 = sock_addrinfo(host, port, SOCK_DGRAM, 0);
GetOpenFile(sock, fptr);
for (res = res0; res; res = res->ai_next) {
- if (bind(fptr->fd, res->ai_addr, res->ai_addrlen) < 0) {
+ if (bind(fileno(fptr->f), res->ai_addr, res->ai_addrlen) < 0) {
continue;
}
freeaddrinfo(res0);
@@ -1762,10 +1815,14 @@ udp_bind(VALUE sock, VALUE host, VALUE port)
}
static VALUE
-udp_send(int argc, VALUE *argv, VALUE sock)
+udp_send(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
VALUE mesg, flags, host, port;
OpenFile *fptr;
+ FILE *f;
int n;
struct addrinfo *res0, *res;
@@ -1778,15 +1835,16 @@ udp_send(int argc, VALUE *argv, VALUE sock)
StringValue(mesg);
res0 = sock_addrinfo(host, port, SOCK_DGRAM, 0);
GetOpenFile(sock, fptr);
+ f = GetWriteFile(fptr);
for (res = res0; res; res = res->ai_next) {
retry:
- n = sendto(fptr->fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg), NUM2INT(flags),
+ n = sendto(fileno(f), RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
res->ai_addr, res->ai_addrlen);
if (n >= 0) {
freeaddrinfo(res0);
return INT2FIX(n);
}
- if (rb_io_wait_writable(fptr->fd)) {
+ if (rb_io_wait_writable(fileno(f))) {
goto retry;
}
}
@@ -1843,12 +1901,13 @@ udp_recvfrom_nonblock(int argc, VALUE *argv, VALUE sock)
#ifdef HAVE_SYS_UN_H
static VALUE
-unix_init(VALUE sock, VALUE path)
+unix_init(sock, path)
+ VALUE sock, path;
{
return init_unixsock(sock, path, 0);
}
-static char*
+static char *
unixpath(struct sockaddr_un *sockaddr, socklen_t len)
{
if (sockaddr->sun_path < (char*)sockaddr + len)
@@ -1858,7 +1917,8 @@ unixpath(struct sockaddr_un *sockaddr, socklen_t len)
}
static VALUE
-unix_path(VALUE sock)
+unix_path(sock)
+ VALUE sock;
{
OpenFile *fptr;
@@ -1866,7 +1926,7 @@ unix_path(VALUE sock)
if (fptr->path == 0) {
struct sockaddr_un addr;
socklen_t len = sizeof(addr);
- if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
+ if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail(0);
fptr->path = strdup(unixpath(&addr, len));
}
@@ -1874,13 +1934,17 @@ unix_path(VALUE sock)
}
static VALUE
-unix_svr_init(VALUE sock, VALUE path)
+unix_svr_init(sock, path)
+ VALUE sock, path;
{
return init_unixsock(sock, path, 1);
}
static VALUE
-unix_recvfrom(int argc, VALUE *argv, VALUE sock)
+unix_recvfrom(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
return s_recvfrom(sock, argc, argv, RECV_UNIX);
}
@@ -1898,7 +1962,8 @@ unix_recvfrom(int argc, VALUE *argv, VALUE sock)
#endif
static VALUE
-unix_send_io(VALUE sock, VALUE val)
+unix_send_io(sock, val)
+ VALUE sock, val;
{
#if defined(HAVE_SENDMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
int fd;
@@ -1917,7 +1982,7 @@ unix_send_io(VALUE sock, VALUE val)
if (rb_obj_is_kind_of(val, rb_cIO)) {
OpenFile *valfptr;
GetOpenFile(val, valfptr);
- fd = valfptr->fd;
+ fd = fileno(valfptr->f);
}
else if (FIXNUM_P(val)) {
fd = FIX2INT(val);
@@ -1951,7 +2016,7 @@ unix_send_io(VALUE sock, VALUE val)
msg.msg_accrightslen = sizeof(fd);
#endif
- if (sendmsg(fptr->fd, &msg, 0) == -1)
+ if (sendmsg(fileno(fptr->f), &msg, 0) == -1)
rb_sys_fail("sendmsg(2)");
return Qnil;
@@ -1961,8 +2026,24 @@ unix_send_io(VALUE sock, VALUE val)
#endif
}
+#if defined(HAVE_RECVMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
+static void
+thread_read_select(fd)
+ int fd;
+{
+ fd_set fds;
+
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ rb_thread_select(fd+1, &fds, 0, 0, 0);
+}
+#endif
+
static VALUE
-unix_recv_io(int argc, VALUE *argv, VALUE sock)
+unix_recv_io(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
#if defined(HAVE_RECVMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
VALUE klass, mode;
@@ -1987,7 +2068,7 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
GetOpenFile(sock, fptr);
- rb_io_wait_readable(fptr->fd);
+ thread_read_select(fileno(fptr->f));
msg.msg_name = NULL;
msg.msg_namelen = 0;
@@ -2011,7 +2092,7 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
fd = -1;
#endif
- if (recvmsg(fptr->fd, &msg, 0) == -1)
+ if (recvmsg(fileno(fptr->f), &msg, 0) == -1)
rb_sys_fail("recvmsg(2)");
#if FD_PASSING_BY_MSG_CONTROL
@@ -2067,7 +2148,8 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
}
static VALUE
-unix_accept(VALUE sock)
+unix_accept(sock)
+ VALUE sock;
{
OpenFile *fptr;
struct sockaddr_un from;
@@ -2075,7 +2157,7 @@ unix_accept(VALUE sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(struct sockaddr_un);
- return s_accept(rb_cUNIXSocket, fptr->fd,
+ return s_accept(rb_cUNIXSocket, fileno(fptr->f),
(struct sockaddr*)&from, &fromlen);
}
@@ -2109,7 +2191,8 @@ unix_accept(VALUE sock)
* * Socket#accept
*/
static VALUE
-unix_accept_nonblock(VALUE sock)
+unix_accept_nonblock(sock)
+ VALUE sock;
{
OpenFile *fptr;
struct sockaddr_un from;
@@ -2118,11 +2201,12 @@ unix_accept_nonblock(VALUE sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(from);
return s_accept_nonblock(rb_cUNIXSocket, fptr,
- (struct sockaddr *)&from, &fromlen);
+ (struct sockaddr *)&from, &fromlen);
}
static VALUE
-unix_sysaccept(VALUE sock)
+unix_sysaccept(sock)
+ VALUE sock;
{
OpenFile *fptr;
struct sockaddr_un from;
@@ -2130,20 +2214,21 @@ unix_sysaccept(VALUE sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(struct sockaddr_un);
- return s_accept(0, fptr->fd, (struct sockaddr*)&from, &fromlen);
+ return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
}
-#ifdef HAVE_SYS_UN_H
static VALUE
-unixaddr(struct sockaddr_un *sockaddr, socklen_t len)
+unixaddr(sockaddr, len)
+ struct sockaddr_un *sockaddr;
+ socklen_t len;
{
return rb_assoc_new(rb_str_new2("AF_UNIX"),
rb_str_new2(unixpath(sockaddr, len)));
}
-#endif
static VALUE
-unix_addr(VALUE sock)
+unix_addr(sock)
+ VALUE sock;
{
OpenFile *fptr;
struct sockaddr_un addr;
@@ -2151,13 +2236,14 @@ unix_addr(VALUE sock)
GetOpenFile(sock, fptr);
- if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
+ if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getsockname(2)");
return unixaddr(&addr, len);
}
static VALUE
-unix_peeraddr(VALUE sock)
+unix_peeraddr(sock)
+ VALUE sock;
{
OpenFile *fptr;
struct sockaddr_un addr;
@@ -2165,14 +2251,16 @@ unix_peeraddr(VALUE sock)
GetOpenFile(sock, fptr);
- if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
- rb_sys_fail("getsockname(2)");
+ if (getpeername(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
+ rb_sys_fail("getpeername(2)");
return unixaddr(&addr, len);
}
#endif
static void
-setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv)
+setup_domain_and_type(domain, dv, type, tv)
+ VALUE domain, type;
+ int *dv, *tv;
{
VALUE tmp;
char *ptr;
@@ -2181,7 +2269,7 @@ setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv)
if (!NIL_P(tmp)) {
domain = tmp;
rb_check_safe_obj(domain);
- ptr = RSTRING_PTR(domain);
+ ptr = RSTRING(domain)->ptr;
if (strcmp(ptr, "AF_INET") == 0)
*dv = AF_INET;
#ifdef AF_UNIX
@@ -2232,7 +2320,7 @@ setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv)
if (!NIL_P(tmp)) {
type = tmp;
rb_check_safe_obj(type);
- ptr = RSTRING_PTR(type);
+ ptr = RSTRING(type)->ptr;
if (strcmp(ptr, "SOCK_STREAM") == 0)
*tv = SOCK_STREAM;
else if (strcmp(ptr, "SOCK_DGRAM") == 0)
@@ -2262,7 +2350,8 @@ setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv)
}
static VALUE
-sock_initialize(VALUE sock, VALUE domain, VALUE type, VALUE protocol)
+sock_initialize(sock, domain, type, protocol)
+ VALUE sock, domain, type, protocol;
{
int fd;
int d, t;
@@ -2276,7 +2365,8 @@ sock_initialize(VALUE sock, VALUE domain, VALUE type, VALUE protocol)
}
static VALUE
-sock_s_socketpair(VALUE klass, VALUE domain, VALUE type, VALUE protocol)
+sock_s_socketpair(klass, domain, type, protocol)
+ VALUE klass, domain, type, protocol;
{
#if defined HAVE_SOCKETPAIR
int d, t, p, sp[2];
@@ -2302,7 +2392,10 @@ sock_s_socketpair(VALUE klass, VALUE domain, VALUE type, VALUE protocol)
#ifdef HAVE_SYS_UN_H
static VALUE
-unix_s_socketpair(int argc, VALUE *argv, VALUE klass)
+unix_s_socketpair(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE domain, type, protocol;
domain = INT2FIX(PF_UNIX);
@@ -2429,21 +2522,21 @@ unix_s_socketpair(int argc, VALUE *argv, VALUE klass)
* * connect function in Microsoft's Winsock functions reference
*/
static VALUE
-sock_connect(VALUE sock, VALUE addr)
+sock_connect(sock, addr)
+ VALUE sock, addr;
{
OpenFile *fptr;
- int fd, n;
+ int fd;
StringValue(addr);
addr = rb_str_new4(addr);
GetOpenFile(sock, fptr);
- fd = fptr->fd;
- n = ruby_connect(fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LEN(addr), 0);
- if (n < 0) {
+ fd = fileno(fptr->f);
+ if (ruby_connect(fd, (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len, 0) < 0) {
rb_sys_fail("connect(2)");
}
- return INT2FIX(n);
+ return INT2FIX(0);
}
/*
@@ -2485,7 +2578,8 @@ sock_connect(VALUE sock, VALUE addr)
* * Socket#connect
*/
static VALUE
-sock_connect_nonblock(VALUE sock, VALUE addr)
+sock_connect_nonblock(sock, addr)
+ VALUE sock, addr;
{
OpenFile *fptr;
int n;
@@ -2494,7 +2588,7 @@ sock_connect_nonblock(VALUE sock, VALUE addr)
addr = rb_str_new4(addr);
GetOpenFile(sock, fptr);
rb_io_set_nonblock(fptr);
- n = connect(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LEN(addr));
+ n = connect(fileno(fptr->f), (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len);
if (n < 0) {
rb_sys_fail("connect(2)");
}
@@ -2582,13 +2676,14 @@ sock_connect_nonblock(VALUE sock, VALUE addr)
* * bind function in Microsoft's Winsock functions reference
*/
static VALUE
-sock_bind(VALUE sock, VALUE addr)
+sock_bind(sock, addr)
+ VALUE sock, addr;
{
OpenFile *fptr;
StringValue(addr);
GetOpenFile(sock, fptr);
- if (bind(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LEN(addr)) < 0)
+ if (bind(fileno(fptr->f), (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len) < 0)
rb_sys_fail("bind(2)");
return INT2FIX(0);
@@ -2665,7 +2760,8 @@ sock_bind(VALUE sock, VALUE addr)
* * listen function in Microsoft's Winsock functions reference
*/
static VALUE
-sock_listen(VALUE sock, VALUE log)
+sock_listen(sock, log)
+ VALUE sock, log;
{
OpenFile *fptr;
int backlog;
@@ -2673,7 +2769,7 @@ sock_listen(VALUE sock, VALUE log)
rb_secure(4);
backlog = NUM2INT(log);
GetOpenFile(sock, fptr);
- if (listen(fptr->fd, backlog) < 0)
+ if (listen(fileno(fptr->f), backlog) < 0)
rb_sys_fail("listen(2)");
return INT2FIX(0);
@@ -2785,7 +2881,10 @@ sock_listen(VALUE sock, VALUE log)
* message.
*/
static VALUE
-sock_recvfrom(int argc, VALUE *argv, VALUE sock)
+sock_recvfrom(argc, argv, sock)
+ int argc;
+ VALUE *argv;
+ VALUE sock;
{
return s_recvfrom(sock, argc, argv, RECV_SOCKET);
}
@@ -2854,8 +2953,91 @@ sock_recvfrom_nonblock(int argc, VALUE *argv, VALUE sock)
return s_recvfrom_nonblock(sock, argc, argv, RECV_SOCKET);
}
+/*
+ * call-seq:
+ * socket.accept => [ socket, string ]
+ *
+ * Accepts an incoming connection returning an array containing a new
+ * Socket object and a string holding the +struct+ sockaddr information about
+ * the caller.
+ *
+ * === Example
+ * # In one script, start this first
+ * require 'socket'
+ * include Socket::Constants
+ * socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
+ * sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )
+ * socket.bind( sockaddr )
+ * socket.listen( 5 )
+ * client, client_sockaddr = socket.accept
+ * puts "The client said, '#{client.readline.chomp}'"
+ * client.puts "Hello from script one!"
+ * socket.close
+ *
+ * # In another script, start this second
+ * require 'socket'
+ * include Socket::Constants
+ * socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
+ * sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )
+ * socket.connect( sockaddr )
+ * socket.puts "Hello from script 2."
+ * puts "The server said, '#{socket.readline.chomp}'"
+ * socket.close
+ *
+ * === Unix-based Exceptions
+ * On unix-based based systems the following system exceptions may be raised if the
+ * call to _accept_ fails:
+ * * Errno::EAGAIN - O_NONBLOCK is set for the +socket+ file descriptor and no
+ * connections are parent to be accepted
+ * * Errno::EWOULDBLOCK - same as Errno::EAGAIN
+ * * Errno::EBADF - the +socket+ is not a valid file descriptor
+ * * Errno::ECONNABORTED - a connection has been aborted
+ * * Errno::EFAULT - the socket's internal address or address length parameter
+ * cannot be access or written
+ * * Errno::EINTR - the _accept_ method was interrupted by a signal that was
+ * caught before a valid connection arrived
+ * * Errno::EINVAL - the +socket+ is not accepting connections
+ * * Errno::EMFILE - OPEN_MAX file descriptors are currently open in the calling
+ * process
+ * * Errno::ENOBUFS - no buffer space is available
+ * * Errno::ENOMEM - there was insufficient memory available to complete the
+ * operation
+ * * Errno::ENOSR - there was insufficient STREAMS resources available to
+ * complete the operation
+ * * Errno::ENFILE - the maximum number of file descriptors in the system are
+ * already open
+ * * Errno::ENOTSOCK - the +socket+ does not refer to a socket
+ * * Errno::EOPNOTSUPP - the socket type for the calling +socket+ does not
+ * support accept connections
+ * * Errno::EPROTO - a protocol error has occurred
+ *
+ * === Windows Exceptions
+ * On Windows systems the following system exceptions may be raised if
+ * the call to _accept_ fails:
+ * * Errno::ECONNRESET - an incoming connection was indicated, but was
+ * terminated by the remote peer prior to accepting the connection
+ * * Errno::EFAULT - the socket's internal address or address length parameter
+ * is too small or is not a valid part of the user space address
+ * * Errno::EINVAL - the _listen_ method was not invoked prior to calling _accept_
+ * * Errno::EINPROGRESS - a blocking Windows Sockets 1.1 call is in progress or
+ * the service provider is still processing a callback function
+ * * Errno::EMFILE - the queue is not empty, upong etry to _accept_ and there are
+ * no socket descriptors available
+ * * Errno::ENETDOWN - the network is down
+ * * Errno::ENOBUFS - no buffer space is available
+ * * Errno::ENOTSOCK - +socket+ is not a socket
+ * * Errno::EOPNOTSUPP - +socket+ is not a type that supports connection-oriented
+ * service.
+ * * Errno::EWOULDBLOCK - +socket+ is marked as nonblocking and no connections are
+ * present to be accepted
+ *
+ * === See
+ * * accept manual pages on unix-based systems
+ * * accept function in Microsoft's Winsock functions reference
+ */
static VALUE
-sock_accept(VALUE sock)
+sock_accept(sock)
+ VALUE sock;
{
OpenFile *fptr;
VALUE sock2;
@@ -2863,14 +3045,14 @@ sock_accept(VALUE sock)
socklen_t len = sizeof buf;
GetOpenFile(sock, fptr);
- sock2 = s_accept(rb_cSocket,fptr->fd,(struct sockaddr*)buf,&len);
+ sock2 = s_accept(rb_cSocket,fileno(fptr->f),(struct sockaddr*)buf,&len);
return rb_assoc_new(sock2, rb_str_new(buf, len));
}
/*
* call-seq:
- * socket.accept_nonblock => [client_socket, client_sockaddr]
+ * socket.accept_nonblock => [client_socket, client_sockaddr]
*
* Accepts an incoming connection using accept(2) after
* O_NONBLOCK is set for the underlying file descriptor.
@@ -2893,10 +3075,10 @@ sock_accept(VALUE sock)
* IO.select([socket])
* retry
* end
- * puts "The client said, '#{socket.readline.chomp}'"
+ * puts "The client said, '#{client_socket.readline.chomp}'"
* client_socket.puts "Hello from script one!"
* socket.close
- *
+ *
* # In another script, start this second
* require 'socket'
* include Socket::Constants
@@ -2917,7 +3099,8 @@ sock_accept(VALUE sock)
* * Socket#accept
*/
static VALUE
-sock_accept_nonblock(VALUE sock)
+sock_accept_nonblock(sock)
+ VALUE sock;
{
OpenFile *fptr;
VALUE sock2;
@@ -2947,8 +3130,8 @@ sock_accept_nonblock(VALUE sock)
* socket.bind( sockaddr )
* socket.listen( 5 )
* client_fd, client_sockaddr = socket.sysaccept
- * puts "The client said, '#{socket.readline.chomp}'"
* client_socket = Socket.for_fd( client_fd )
+ * puts "The client said, '#{client_socket.readline.chomp}'"
* client_socket.puts "Hello from script one!"
* socket.close
*
@@ -2969,7 +3152,8 @@ sock_accept_nonblock(VALUE sock)
* * Socket#accept
*/
static VALUE
-sock_sysaccept(VALUE sock)
+sock_sysaccept(sock)
+ VALUE sock;
{
OpenFile *fptr;
VALUE sock2;
@@ -2977,14 +3161,15 @@ sock_sysaccept(VALUE sock)
socklen_t len = sizeof buf;
GetOpenFile(sock, fptr);
- sock2 = s_accept(0,fptr->fd,(struct sockaddr*)buf,&len);
+ sock2 = s_accept(0,fileno(fptr->f),(struct sockaddr*)buf,&len);
return rb_assoc_new(sock2, rb_str_new(buf, len));
}
#ifdef HAVE_GETHOSTNAME
static VALUE
-sock_gethostname(VALUE obj)
+sock_gethostname(obj)
+ VALUE obj;
{
char buf[1024];
@@ -3001,7 +3186,8 @@ sock_gethostname(VALUE obj)
#include <sys/utsname.h>
static VALUE
-sock_gethostname(VALUE obj)
+sock_gethostname(obj)
+ VALUE obj;
{
struct utsname un;
@@ -3011,7 +3197,8 @@ sock_gethostname(VALUE obj)
}
#else
static VALUE
-sock_gethostname(VALUE obj)
+sock_gethostname(obj)
+ VALUE obj;
{
rb_notimplement();
}
@@ -3019,7 +3206,8 @@ sock_gethostname(VALUE obj)
#endif
static VALUE
-make_addrinfo(struct addrinfo *res0)
+make_addrinfo(res0)
+ struct addrinfo *res0;
{
VALUE base, ary;
struct addrinfo *res;
@@ -3029,10 +3217,7 @@ make_addrinfo(struct addrinfo *res0)
}
base = rb_ary_new();
for (res = res0; res; res = res->ai_next) {
- ary = ipaddr(res->ai_addr, do_not_reverse_lookup);
- if (res->ai_canonname) {
- RARRAY_PTR(ary)[2] = rb_str_new2(res->ai_canonname);
- }
+ ary = ipaddr(res->ai_addr);
rb_ary_push(ary, INT2FIX(res->ai_family));
rb_ary_push(ary, INT2FIX(res->ai_socktype));
rb_ary_push(ary, INT2FIX(res->ai_protocol));
@@ -3041,8 +3226,11 @@ make_addrinfo(struct addrinfo *res0)
return base;
}
-static VALUE
-sock_sockaddr(struct sockaddr *addr, size_t len)
+/* Returns a String containing the binary value of a struct sockaddr. */
+VALUE
+sock_sockaddr(addr, len)
+ struct sockaddr *addr;
+ size_t len;
{
char *ptr;
@@ -3064,15 +3252,114 @@ sock_sockaddr(struct sockaddr *addr, size_t len)
return rb_str_new(ptr, len);
}
+/*
+ * Document-class: IPSocket
+ *
+ * IPSocket is the parent of TCPSocket and UDPSocket and implements
+ * functionality common to them.
+ *
+ * A number of APIs in IPSocket, Socket, and their descendants return an
+ * address as an array. The members of that array are:
+ * - address family: A string like "AF_INET" or "AF_INET6" if it is one of the
+ * commonly used families, the string "unknown:#" (where `#' is the address
+ * family number) if it is not one of the common ones. The strings map to
+ * the Socket::AF_* constants.
+ * - port: The port number.
+ * - name: Either the canonical name from looking the address up in the DNS, or
+ * the address in presentation format
+ * - address: The address in presentation format (a dotted decimal string for
+ * IPv4, a hex string for IPv6).
+ *
+ * The address and port can be used directly to create sockets and to bind or
+ * connect them to the address.
+ */
+
+/*
+ * Document-class: Socket
+ *
+ * Socket contains a number of generally useful singleton methods and
+ * constants, as well as offering low-level interfaces that can be used to
+ * develop socket applications using protocols other than TCP, UDP, and UNIX
+ * domain sockets.
+ */
+
+/*
+ * Document-method: gethostbyname
+ * call-seq: Socket.gethostbyname(host) => hostent
+ *
+ * Resolve +host+ and return name and address information for it, similarly to
+ * gethostbyname(3). +host+ can be a domain name or the presentation format of
+ * an address.
+ *
+ * Returns an array of information similar to that found in a +struct hostent+:
+ * - cannonical name: the cannonical name for host in the DNS, or a
+ * string representing the address
+ * - aliases: an array of aliases for the canonical name, there may be no aliases
+ * - address family: usually one of Socket::AF_INET or Socket::AF_INET6
+ * - address: a string, the binary value of the +struct sockaddr+ for this name, in
+ * the indicated address family
+ * - ...: if there are multiple addresses for this host, a series of
+ * strings/+struct sockaddr+s may follow, not all necessarily in the same
+ * address family. Note that the fact that they may not be all in the same
+ * address family is a departure from the behaviour of gethostbyname(3).
+ *
+ * Note: I believe that the fact that the multiple addresses returned are not
+ * necessarily in the same address family may be a bug, since if this function
+ * actually called gethostbyname(3), ALL the addresses returned in the trailing
+ * address list (h_addr_list from struct hostent) would be of the same address
+ * family! Examples from my system, OS X 10.3:
+ *
+ * ["localhost", [], 30, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001", "\177\000\000\001"]
+ * and
+ * ["ensemble.local", [], 30, "\376\200\000\004\000\000\000\000\002\003\223\377\376\255\010\214", "\300\250{\232" ]
+ *
+ * Similar information can be returned by Socket.getaddrinfo if called as:
+ *
+ * Socket.getaddrinfo(+host+, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME)
+ *
+ * == Examples
+ *
+ * Socket.gethostbyname "example.com"
+ * => ["example.com", [], 2, "\300\000\"\246"]
+ *
+ * This name has no DNS aliases, and a single IPv4 address.
+ *
+ * Socket.gethostbyname "smtp.telus.net"
+ * => ["smtp.svc.telus.net", ["smtp.telus.net"], 2, "\307\271\334\371"]
+ *
+ * This name is an an alias so the canonical name is returned, as well as the
+ * alias and a single IPv4 address.
+ *
+ * Socket.gethostbyname "localhost"
+ * => ["localhost", [], 30, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001", "\177\000\000\001"]
+ *
+ * This machine has no aliases, returns an IPv6 address, and has an additional IPv4 address.
+ *
+ * +host+ can also be an IP address in presentation format, in which case a
+ * reverse lookup is done on the address:
+ *
+ * Socket.gethostbyname("127.0.0.1")
+ * => ["localhost", [], 2, "\177\000\000\001"]
+ *
+ * Socket.gethostbyname("192.0.34.166")
+ * => ["www.example.com", [], 2, "\300\000\"\246"]
+ *
+ *
+ * == See
+ * See: Socket.getaddrinfo
+ */
static VALUE
-sock_s_gethostbyname(VALUE obj, VALUE host)
+sock_s_gethostbyname(obj, host)
+ VALUE obj, host;
{
rb_secure(3);
return make_hostent(host, sock_addrinfo(host, Qnil, SOCK_STREAM, AI_CANONNAME), sock_sockaddr);
}
static VALUE
-sock_s_gethostbyaddr(int argc, VALUE *argv)
+sock_s_gethostbyaddr(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE addr, type;
struct hostent *h;
@@ -3087,11 +3374,11 @@ sock_s_gethostbyaddr(int argc, VALUE *argv)
t = NUM2INT(type);
}
#ifdef INET6
- else if (RSTRING_LEN(addr) == 16) {
+ else if (RSTRING(addr)->len == 16) {
t = AF_INET6;
}
#endif
- h = gethostbyaddr(RSTRING_PTR(addr), RSTRING_LEN(addr), t);
+ h = gethostbyaddr(RSTRING(addr)->ptr, RSTRING(addr)->len, t);
if (h == NULL) {
#ifdef HAVE_HSTRERROR
extern int h_errno;
@@ -3121,8 +3408,22 @@ sock_s_gethostbyaddr(int argc, VALUE *argv)
return ary;
}
+/*
+ * Document-method: getservbyname
+ * call-seq: Socket.getservbyname(name, proto="tcp") => port
+ *
+ * +name+ is a service name ("ftp", "telnet", ...) and proto is a protocol name
+ * ("udp", "tcp", ...). '/etc/services' (or your system's equivalent) is
+ * searched for a service for +name+ and +proto+, and the port number is
+ * returned.
+ *
+ * Note that unlike Socket.getaddrinfo, +proto+ may not be specified using the
+ * Socket::SOCK_* constants, a string must must be used.
+ */
static VALUE
-sock_s_getservbyname(int argc, VALUE *argv)
+sock_s_getservbyaname(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE service, proto;
struct servent *sp;
@@ -3138,36 +3439,135 @@ sock_s_getservbyname(int argc, VALUE *argv)
port = ntohs(sp->s_port);
}
else {
- char *s = RSTRING_PTR(service);
+ char *s = RSTRING(service)->ptr;
char *end;
port = strtoul(s, &end, 0);
if (*end != '\0') {
- rb_raise(rb_eSocket, "no such service %s/%s", s, RSTRING_PTR(proto));
+ rb_raise(rb_eSocket, "no such service %s/%s", s, RSTRING(proto)->ptr);
}
}
return INT2FIX(port);
}
-static VALUE
-sock_s_getservbyport(int argc, VALUE *argv)
-{
- VALUE port, proto;
- struct servent *sp;
+/*
+Documentation should explain the following:
- rb_scan_args(argc, argv, "11", &port, &proto);
- if (NIL_P(proto)) proto = rb_str_new2("tcp");
- StringValue(proto);
+ $ pp Socket.getaddrinfo("", 1, Socket::AF_UNSPEC, Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE)
+ [["AF_INET", 1, "0.0.0.0", "0.0.0.0", 2, 1, 6]]
- sp = getservbyport(NUM2INT(port), StringValueCStr(proto));
- if (!sp) {
- rb_raise(rb_eSocket, "no such service for port %d/%s", NUM2INT(port), RSTRING_PTR(proto));
- }
- return rb_tainted_str_new2(sp->s_name);
-}
+ $ pp Socket.getaddrinfo(nil, 1, Socket::AF_UNSPEC, Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE)
+ [["AF_INET6", 1, "::", "::", 30, 1, 6],
+ ["AF_INET", 1, "0.0.0.0", "0.0.0.0", 2, 1, 6]]
+
+ $ pp Socket.getaddrinfo("localhost", 1, Socket::AF_UNSPEC, Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE)
+ [["AF_INET6", 1, "localhost", "::1", 30, 1, 6],
+ ["AF_INET", 1, "localhost", "127.0.0.1", 2, 1, 6]]
+
+ $ pp Socket.getaddrinfo("ensemble.local.", 1, Socket::AF_UNSPEC, Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE)
+ [["AF_INET", 1, "localhost", "192.168.123.154", 2, 1, 6]]
+
+Does it?
+
+API suggestion: this method has too many arguments, it would be backwards compatible and easier
+to understand if limit args were accepted as :family=>..., :flags=>...
+*/
+/*
+ * Document-method: getaddrinfo
+ * call-seq: Socket.getaddrinfo(host, service, family=nil, socktype=nil, protocol=nil, flags=nil) => addrinfo
+ *
+ * Return address information for +host+ and +port+. The remaining arguments
+ * are hints that limit the address information returned.
+ *
+ * This method corresponds closely to the POSIX.1g getaddrinfo() definition.
+ *
+ * === Parameters
+ * - +host+ is a host name or an address string (dotted decimal for IPv4, or a hex string
+ * for IPv6) for which to return information. A nil is also allowed, its meaning
+ * depends on +flags+, see below.
+ * - +service+ is a service name ("http", "ssh", ...), or
+ * a port number (80, 22, ...), see Socket.getservbyname for more
+ * information. A nil is also allowed, meaning zero.
+ * - +family+ limits the output to a specific address family, one of the
+ * Socket::AF_* constants. Socket::AF_INET (IPv4) and Socket::AF_INET6 (IPv6)
+ * are the most commonly used families. You will usually pass either nil or
+ * Socket::AF_UNSPEC, allowing the IPv6 information to be returned first if
+ * +host+ is reachable via IPv6, and IPv4 information otherwise. The two
+ * strings "AF_INET" or "AF_INET6" are also allowed, they are converted to
+ * their respective Socket::AF_* constants.
+ * - +socktype+ limits the output to a specific type of socket, one of the
+ * Socket::SOCK_* constants. Socket::SOCK_STREAM (for TCP) and
+ * Socket::SOCK_DGRAM (for UDP) are the most commonly used socket types. If
+ * nil, then information for all types of sockets supported by +service+ will
+ * be returned. You will usually know what type of socket you intend to
+ * create, and should pass that socket type in.
+ * - +protocol+ limits the output to a specific protocol numpber, one of the
+ * Socket::IPPROTO_* constants. It is usually implied by the socket type
+ * (Socket::SOCK_STREAM => Socket::IPPROTO_TCP, ...), if you pass other than
+ * nil you already know what this is for.
+ * - +flags+ is one of the Socket::AI_* constants. They mean:
+ * - Socket::AI_PASSIVE: when set, if +host+ is nil the 'any' address will be
+ * returned, Socket::INADDR_ANY or 0 for IPv4, "0::0" or "::" for IPv6. This
+ * address is suitable for use by servers that will bind their socket and do
+ * a passive listen, thus the name of the flag. Otherwise the local or
+ * loopback address will be returned, this is "127.0.0.1" for IPv4 and "::1'
+ * for IPv6.
+ * - ...
+ *
+ *
+ * === Returns
+ *
+ * Returns an array of arrays, where each subarray contains:
+ * - address family, a string like "AF_INET" or "AF_INET6"
+ * - port number, the port number for +service+
+ * - host name, either a canonical name for +host+, or it's address in presentation
+ * format if the address could not be looked up.
+ * - host IP, the address of +host+ in presentation format
+ * - address family, as a numeric value (one of the Socket::AF_* constants).
+ * - socket type, as a numeric value (one of the Socket::SOCK_* constants).
+ * - protocol number, as a numeric value (one of the Socket::IPPROTO_* constants).
+ *
+ * The first four values are identical to what is commonly returned as an
+ * address array, see IPSocket for more information.
+ *
+ * === Examples
+ *
+ * Not all input combinations are valid, and while there are many combinations,
+ * only a few cases are common.
+ *
+ * A typical client will call getaddrinfo with the +host+ and +service+ it
+ * wants to connect to. It knows that it will attempt to connect with either
+ * TCP or UDP, and specifies +socktype+ accordingly. It loops through all
+ * returned addresses, and try to connect to them in turn:
+ *
+ * addrinfo = Socket::getaddrinfo('www.example.com', 'www', nil, Socket::SOCK_STREAM)
+ * addrinfo.each do |af, port, name, addr|
+ * begin
+ * sock = TCPSocket.new(addr, port)
+ * # ...
+ * exit 1
+ * rescue
+ * end
+ * end
+ *
+ * With UDP you don't know if connect suceeded, but if communication fails,
+ * the next address can be tried.
+ *
+ * A typical server will call getaddrinfo with a +host+ of nil, the +service+
+ * it listens to, and a +flags+ of Socket::AI_PASSIVE. It will listen for
+ * connections on the first returned address:
+ * addrinfo = Socket::getaddrinfo(nil, 'www', nil, Socket::SOCK_STREAM, nil, Socket::AI_PASSIVE)
+ * af, port, name, addr = addrinfo.first
+ * sock = TCPServer(addr, port)
+ * while( client = s.accept )
+ * # ...
+ * end
+ */
static VALUE
-sock_s_getaddrinfo(int argc, VALUE *argv)
+sock_s_getaddrinfo(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE host, port, family, socktype, protocol, flags, ret;
char hbuf[1024], pbuf[1024];
@@ -3227,7 +3627,7 @@ sock_s_getaddrinfo(int argc, VALUE *argv)
}
error = getaddrinfo(hptr, pptr, &hints, &res);
if (error) {
- raise_socket_error("getaddrinfo", error);
+ rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error));
}
ret = make_addrinfo(res);
@@ -3236,7 +3636,9 @@ sock_s_getaddrinfo(int argc, VALUE *argv)
}
static VALUE
-sock_s_getnameinfo(int argc, VALUE *argv)
+sock_s_getnameinfo(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE sa, af = Qnil, host = Qnil, port = Qnil, flags, tmp;
char *hptr, *pptr;
@@ -3258,11 +3660,11 @@ sock_s_getnameinfo(int argc, VALUE *argv)
tmp = rb_check_string_type(sa);
if (!NIL_P(tmp)) {
sa = tmp;
- if (sizeof(ss) < RSTRING_LEN(sa)) {
+ if (sizeof(ss) < RSTRING(sa)->len) {
rb_raise(rb_eTypeError, "sockaddr length too big");
}
- memcpy(&ss, RSTRING_PTR(sa), RSTRING_LEN(sa));
- if (RSTRING_LEN(sa) != SA_LEN((struct sockaddr*)&ss)) {
+ memcpy(&ss, RSTRING(sa)->ptr, RSTRING(sa)->len);
+ if (RSTRING(sa)->len != SA_LEN((struct sockaddr*)&ss)) {
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
sap = (struct sockaddr*)&ss;
@@ -3272,17 +3674,17 @@ sock_s_getnameinfo(int argc, VALUE *argv)
if (!NIL_P(tmp)) {
sa = tmp;
MEMZERO(&hints, struct addrinfo, 1);
- if (RARRAY_LEN(sa) == 3) {
- af = RARRAY_PTR(sa)[0];
- port = RARRAY_PTR(sa)[1];
- host = RARRAY_PTR(sa)[2];
+ if (RARRAY(sa)->len == 3) {
+ af = RARRAY(sa)->ptr[0];
+ port = RARRAY(sa)->ptr[1];
+ host = RARRAY(sa)->ptr[2];
}
- else if (RARRAY_LEN(sa) >= 4) {
- af = RARRAY_PTR(sa)[0];
- port = RARRAY_PTR(sa)[1];
- host = RARRAY_PTR(sa)[3];
+ else if (RARRAY(sa)->len >= 4) {
+ af = RARRAY(sa)->ptr[0];
+ port = RARRAY(sa)->ptr[1];
+ host = RARRAY(sa)->ptr[3];
if (NIL_P(host)) {
- host = RARRAY_PTR(sa)[2];
+ host = RARRAY(sa)->ptr[2];
}
else {
/*
@@ -3296,7 +3698,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
}
else {
rb_raise(rb_eArgError, "array size should be 3 or 4, %ld given",
- RARRAY_LEN(sa));
+ RARRAY(sa)->len);
}
/* host */
if (NIL_P(host)) {
@@ -3370,15 +3772,16 @@ sock_s_getnameinfo(int argc, VALUE *argv)
error_exit_addr:
if (res) freeaddrinfo(res);
- raise_socket_error("getaddrinfo", error);
+ rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error));
error_exit_name:
if (res) freeaddrinfo(res);
- raise_socket_error("getnameinfo", error);
+ rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error));
}
static VALUE
-sock_s_pack_sockaddr_in(VALUE self, VALUE port, VALUE host)
+sock_s_pack_sockaddr_in(self, port, host)
+ VALUE self, port, host;
{
struct addrinfo *res = sock_addrinfo(host, port, 0, 0);
VALUE addr = rb_str_new((char*)res->ai_addr, res->ai_addrlen);
@@ -3391,7 +3794,8 @@ sock_s_pack_sockaddr_in(VALUE self, VALUE port, VALUE host)
}
static VALUE
-sock_s_unpack_sockaddr_in(VALUE self, VALUE addr)
+sock_s_unpack_sockaddr_in(self, addr)
+ VALUE self, addr;
{
struct sockaddr_in * sockaddr;
VALUE host;
@@ -3415,7 +3819,8 @@ sock_s_unpack_sockaddr_in(VALUE self, VALUE addr)
#ifdef HAVE_SYS_UN_H
static VALUE
-sock_s_pack_sockaddr_un(VALUE self, VALUE path)
+sock_s_pack_sockaddr_un(self, path)
+ VALUE self, path;
{
struct sockaddr_un sockaddr;
char *sun_path;
@@ -3436,7 +3841,8 @@ sock_s_pack_sockaddr_un(VALUE self, VALUE path)
}
static VALUE
-sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
+sock_s_unpack_sockaddr_un(self, addr)
+ VALUE self, addr;
{
struct sockaddr_un * sockaddr;
char *sun_path;
@@ -3446,14 +3852,14 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
if (((struct sockaddr *)sockaddr)->sa_family != AF_UNIX) {
rb_raise(rb_eArgError, "not an AF_UNIX sockaddr");
}
- if (sizeof(struct sockaddr_un) < RSTRING_LEN(addr)) {
- rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d",
- RSTRING_LEN(addr), sizeof(struct sockaddr_un));
+ if (sizeof(struct sockaddr_un) < RSTRING(addr)->len) {
+ rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d",
+ RSTRING(addr)->len, sizeof(struct sockaddr_un));
}
- sun_path = unixpath(sockaddr, RSTRING_LEN(addr));
- if (sizeof(struct sockaddr_un) == RSTRING_LEN(addr) &&
+ sun_path = unixpath(sockaddr, RSTRING(addr)->len);
+ if (sizeof(struct sockaddr_un) == RSTRING(addr)->len &&
sun_path == sockaddr->sun_path &&
- sun_path + strlen(sun_path) == RSTRING_PTR(addr) + RSTRING_LEN(addr)) {
+ sun_path + strlen(sun_path) == RSTRING(addr)->ptr + RSTRING(addr)->len) {
rb_raise(rb_eArgError, "sockaddr_un.sun_path not NUL terminated");
}
path = rb_str_new2(sun_path);
@@ -3465,7 +3871,9 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
static VALUE mConst;
static void
-sock_define_const(char *name, int value)
+sock_define_const(name, value)
+ char *name;
+ int value;
{
rb_define_const(rb_cSocket, name, INT2FIX(value));
rb_define_const(mConst, name, INT2FIX(value));
@@ -3476,7 +3884,7 @@ sock_define_const(char *name, int value)
* socket implementations. It can be used to provide more operating system
* specific functionality than the protocol-specific socket classes but at the
* expense of greater complexity. In particular, the class handles addresses
- * using +struct+ sockaddr structures packed into Ruby strings, which can be
+ * using +struct sockaddr+ structures packed into Ruby strings, which can be
* a joy to manipulate.
*
* === Exception Handling
@@ -3520,21 +3928,22 @@ Init_socket()
rb_define_method(rb_cBasicSocket, "send", bsock_send, -1);
rb_define_method(rb_cBasicSocket, "recv", bsock_recv, -1);
rb_define_method(rb_cBasicSocket, "recv_nonblock", bsock_recv_nonblock, -1);
- rb_define_method(rb_cBasicSocket, "do_not_reverse_lookup", bsock_do_not_reverse_lookup, 0);
- rb_define_method(rb_cBasicSocket, "do_not_reverse_lookup=", bsock_do_not_reverse_lookup_set, 1);
rb_cIPSocket = rb_define_class("IPSocket", rb_cBasicSocket);
+ rb_define_global_const("IPsocket", rb_cIPSocket);
rb_define_method(rb_cIPSocket, "addr", ip_addr, 0);
rb_define_method(rb_cIPSocket, "peeraddr", ip_peeraddr, 0);
rb_define_method(rb_cIPSocket, "recvfrom", ip_recvfrom, -1);
rb_define_singleton_method(rb_cIPSocket, "getaddress", ip_s_getaddress, 1);
rb_cTCPSocket = rb_define_class("TCPSocket", rb_cIPSocket);
+ rb_define_global_const("TCPsocket", rb_cTCPSocket);
rb_define_singleton_method(rb_cTCPSocket, "gethostbyname", tcp_s_gethostbyname, 1);
rb_define_method(rb_cTCPSocket, "initialize", tcp_init, -1);
#ifdef SOCKS
rb_cSOCKSSocket = rb_define_class("SOCKSSocket", rb_cTCPSocket);
+ rb_define_global_const("SOCKSsocket", rb_cSOCKSSocket);
rb_define_method(rb_cSOCKSSocket, "initialize", socks_init, 2);
#ifdef SOCKS5
rb_define_method(rb_cSOCKSSocket, "close", socks_s_close, 0);
@@ -3542,6 +3951,7 @@ Init_socket()
#endif
rb_cTCPServer = rb_define_class("TCPServer", rb_cTCPSocket);
+ rb_define_global_const("TCPserver", rb_cTCPServer);
rb_define_method(rb_cTCPServer, "accept", tcp_accept, 0);
rb_define_method(rb_cTCPServer, "accept_nonblock", tcp_accept_nonblock, 0);
rb_define_method(rb_cTCPServer, "sysaccept", tcp_sysaccept, 0);
@@ -3549,6 +3959,7 @@ Init_socket()
rb_define_method(rb_cTCPServer, "listen", sock_listen, 1);
rb_cUDPSocket = rb_define_class("UDPSocket", rb_cIPSocket);
+ rb_define_global_const("UDPsocket", rb_cUDPSocket);
rb_define_method(rb_cUDPSocket, "initialize", udp_init, -1);
rb_define_method(rb_cUDPSocket, "connect", udp_connect, 2);
rb_define_method(rb_cUDPSocket, "bind", udp_bind, 2);
@@ -3557,6 +3968,7 @@ Init_socket()
#ifdef HAVE_SYS_UN_H
rb_cUNIXSocket = rb_define_class("UNIXSocket", rb_cBasicSocket);
+ rb_define_global_const("UNIXsocket", rb_cUNIXSocket);
rb_define_method(rb_cUNIXSocket, "initialize", unix_init, 1);
rb_define_method(rb_cUNIXSocket, "path", unix_path, 0);
rb_define_method(rb_cUNIXSocket, "addr", unix_addr, 0);
@@ -3568,6 +3980,7 @@ Init_socket()
rb_define_singleton_method(rb_cUNIXSocket, "pair", unix_s_socketpair, -1);
rb_cUNIXServer = rb_define_class("UNIXServer", rb_cUNIXSocket);
+ rb_define_global_const("UNIXserver", rb_cUNIXServer);
rb_define_method(rb_cUNIXServer, "initialize", unix_svr_init, 1);
rb_define_method(rb_cUNIXServer, "accept", unix_accept, 0);
rb_define_method(rb_cUNIXServer, "accept_nonblock", unix_accept_nonblock, 0);
@@ -3594,8 +4007,7 @@ Init_socket()
rb_define_singleton_method(rb_cSocket, "gethostname", sock_gethostname, 0);
rb_define_singleton_method(rb_cSocket, "gethostbyname", sock_s_gethostbyname, 1);
rb_define_singleton_method(rb_cSocket, "gethostbyaddr", sock_s_gethostbyaddr, -1);
- rb_define_singleton_method(rb_cSocket, "getservbyname", sock_s_getservbyname, -1);
- rb_define_singleton_method(rb_cSocket, "getservbyport", sock_s_getservbyport, -1);
+ rb_define_singleton_method(rb_cSocket, "getservbyname", sock_s_getservbyaname, -1);
rb_define_singleton_method(rb_cSocket, "getaddrinfo", sock_s_getaddrinfo, -1);
rb_define_singleton_method(rb_cSocket, "getnameinfo", sock_s_getnameinfo, -1);
rb_define_singleton_method(rb_cSocket, "sockaddr_in", sock_s_pack_sockaddr_in, 2);
@@ -3609,9 +4021,700 @@ Init_socket()
/* constants */
mConst = rb_define_module_under(rb_cSocket, "Constants");
-#include "constants.h"
-#ifdef INET6 /* IPv6 is not supported although AF_INET6 is defined on bcc32/mingw */
+ sock_define_const("SOCK_STREAM", SOCK_STREAM);
+ sock_define_const("SOCK_DGRAM", SOCK_DGRAM);
+#ifdef SOCK_RAW
+ sock_define_const("SOCK_RAW", SOCK_RAW);
+#endif
+#ifdef SOCK_RDM
+ sock_define_const("SOCK_RDM", SOCK_RDM);
+#endif
+#ifdef SOCK_SEQPACKET
+ sock_define_const("SOCK_SEQPACKET", SOCK_SEQPACKET);
+#endif
+#ifdef SOCK_PACKET
+ sock_define_const("SOCK_PACKET", SOCK_PACKET);
+#endif
+
+ sock_define_const("AF_INET", AF_INET);
+#ifdef PF_INET
+ sock_define_const("PF_INET", PF_INET);
+#endif
+#ifdef AF_UNIX
+ sock_define_const("AF_UNIX", AF_UNIX);
+ sock_define_const("PF_UNIX", PF_UNIX);
+#endif
+#ifdef AF_AX25
+ sock_define_const("AF_AX25", AF_AX25);
+ sock_define_const("PF_AX25", PF_AX25);
+#endif
+#ifdef AF_IPX
+ sock_define_const("AF_IPX", AF_IPX);
+ sock_define_const("PF_IPX", PF_IPX);
+#endif
+#ifdef AF_APPLETALK
+ sock_define_const("AF_APPLETALK", AF_APPLETALK);
+ sock_define_const("PF_APPLETALK", PF_APPLETALK);
+#endif
+#ifdef AF_UNSPEC
+ sock_define_const("AF_UNSPEC", AF_UNSPEC);
+ sock_define_const("PF_UNSPEC", PF_UNSPEC);
+#endif
+#ifdef INET6
sock_define_const("AF_INET6", AF_INET6);
+#endif
+#ifdef INET6
sock_define_const("PF_INET6", PF_INET6);
#endif
+#ifdef AF_LOCAL
+ sock_define_const("AF_LOCAL", AF_LOCAL);
+#endif
+#ifdef PF_LOCAL
+ sock_define_const("PF_LOCAL", PF_LOCAL);
+#endif
+#ifdef AF_IMPLINK
+ sock_define_const("AF_IMPLINK", AF_IMPLINK);
+#endif
+#ifdef PF_IMPLINK
+ sock_define_const("PF_IMPLINK", PF_IMPLINK);
+#endif
+#ifdef AF_PUP
+ sock_define_const("AF_PUP", AF_PUP);
+#endif
+#ifdef PF_PUP
+ sock_define_const("PF_PUP", PF_PUP);
+#endif
+#ifdef AF_CHAOS
+ sock_define_const("AF_CHAOS", AF_CHAOS);
+#endif
+#ifdef PF_CHAOS
+ sock_define_const("PF_CHAOS", PF_CHAOS);
+#endif
+#ifdef AF_NS
+ sock_define_const("AF_NS", AF_NS);
+#endif
+#ifdef PF_NS
+ sock_define_const("PF_NS", PF_NS);
+#endif
+#ifdef AF_ISO
+ sock_define_const("AF_ISO", AF_ISO);
+#endif
+#ifdef PF_ISO
+ sock_define_const("PF_ISO", PF_ISO);
+#endif
+#ifdef AF_OSI
+ sock_define_const("AF_OSI", AF_OSI);
+#endif
+#ifdef PF_OSI
+ sock_define_const("PF_OSI", PF_OSI);
+#endif
+#ifdef AF_ECMA
+ sock_define_const("AF_ECMA", AF_ECMA);
+#endif
+#ifdef PF_ECMA
+ sock_define_const("PF_ECMA", PF_ECMA);
+#endif
+#ifdef AF_DATAKIT
+ sock_define_const("AF_DATAKIT", AF_DATAKIT);
+#endif
+#ifdef PF_DATAKIT
+ sock_define_const("PF_DATAKIT", PF_DATAKIT);
+#endif
+#ifdef AF_CCITT
+ sock_define_const("AF_CCITT", AF_CCITT);
+#endif
+#ifdef PF_CCITT
+ sock_define_const("PF_CCITT", PF_CCITT);
+#endif
+#ifdef AF_SNA
+ sock_define_const("AF_SNA", AF_SNA);
+#endif
+#ifdef PF_SNA
+ sock_define_const("PF_SNA", PF_SNA);
+#endif
+#ifdef AF_DEC
+ sock_define_const("AF_DEC", AF_DEC);
+#endif
+#ifdef PF_DEC
+ sock_define_const("PF_DEC", PF_DEC);
+#endif
+#ifdef AF_DLI
+ sock_define_const("AF_DLI", AF_DLI);
+#endif
+#ifdef PF_DLI
+ sock_define_const("PF_DLI", PF_DLI);
+#endif
+#ifdef AF_LAT
+ sock_define_const("AF_LAT", AF_LAT);
+#endif
+#ifdef PF_LAT
+ sock_define_const("PF_LAT", PF_LAT);
+#endif
+#ifdef AF_HYLINK
+ sock_define_const("AF_HYLINK", AF_HYLINK);
+#endif
+#ifdef PF_HYLINK
+ sock_define_const("PF_HYLINK", PF_HYLINK);
+#endif
+#ifdef AF_ROUTE
+ sock_define_const("AF_ROUTE", AF_ROUTE);
+#endif
+#ifdef PF_ROUTE
+ sock_define_const("PF_ROUTE", PF_ROUTE);
+#endif
+#ifdef AF_LINK
+ sock_define_const("AF_LINK", AF_LINK);
+#endif
+#ifdef PF_LINK
+ sock_define_const("PF_LINK", PF_LINK);
+#endif
+#ifdef AF_COIP
+ sock_define_const("AF_COIP", AF_COIP);
+#endif
+#ifdef PF_COIP
+ sock_define_const("PF_COIP", PF_COIP);
+#endif
+#ifdef AF_CNT
+ sock_define_const("AF_CNT", AF_CNT);
+#endif
+#ifdef PF_CNT
+ sock_define_const("PF_CNT", PF_CNT);
+#endif
+#ifdef AF_SIP
+ sock_define_const("AF_SIP", AF_SIP);
+#endif
+#ifdef PF_SIP
+ sock_define_const("PF_SIP", PF_SIP);
+#endif
+#ifdef AF_NDRV
+ sock_define_const("AF_NDRV", AF_NDRV);
+#endif
+#ifdef PF_NDRV
+ sock_define_const("PF_NDRV", PF_NDRV);
+#endif
+#ifdef AF_ISDN
+ sock_define_const("AF_ISDN", AF_ISDN);
+#endif
+#ifdef PF_ISDN
+ sock_define_const("PF_ISDN", PF_ISDN);
+#endif
+#ifdef AF_NATM
+ sock_define_const("AF_NATM", AF_NATM);
+#endif
+#ifdef PF_NATM
+ sock_define_const("PF_NATM", PF_NATM);
+#endif
+#ifdef AF_SYSTEM
+ sock_define_const("AF_SYSTEM", AF_SYSTEM);
+#endif
+#ifdef PF_SYSTEM
+ sock_define_const("PF_SYSTEM", PF_SYSTEM);
+#endif
+#ifdef AF_NETBIOS
+ sock_define_const("AF_NETBIOS", AF_NETBIOS);
+#endif
+#ifdef PF_NETBIOS
+ sock_define_const("PF_NETBIOS", PF_NETBIOS);
+#endif
+#ifdef AF_PPP
+ sock_define_const("AF_PPP", AF_PPP);
+#endif
+#ifdef PF_PPP
+ sock_define_const("PF_PPP", PF_PPP);
+#endif
+#ifdef AF_ATM
+ sock_define_const("AF_ATM", AF_ATM);
+#endif
+#ifdef PF_ATM
+ sock_define_const("PF_ATM", PF_ATM);
+#endif
+#ifdef AF_NETGRAPH
+ sock_define_const("AF_NETGRAPH", AF_NETGRAPH);
+#endif
+#ifdef PF_NETGRAPH
+ sock_define_const("PF_NETGRAPH", PF_NETGRAPH);
+#endif
+#ifdef AF_MAX
+ sock_define_const("AF_MAX", AF_MAX);
+#endif
+#ifdef PF_MAX
+ sock_define_const("PF_MAX", PF_MAX);
+#endif
+#ifdef AF_E164
+ sock_define_const("AF_E164", AF_E164);
+#endif
+#ifdef PF_XTP
+ sock_define_const("PF_XTP", PF_XTP);
+#endif
+#ifdef PF_RTIP
+ sock_define_const("PF_RTIP", PF_RTIP);
+#endif
+#ifdef PF_PIP
+ sock_define_const("PF_PIP", PF_PIP);
+#endif
+#ifdef PF_KEY
+ sock_define_const("PF_KEY", PF_KEY);
+#endif
+
+ sock_define_const("MSG_OOB", MSG_OOB);
+#ifdef MSG_PEEK
+ sock_define_const("MSG_PEEK", MSG_PEEK);
+#endif
+#ifdef MSG_DONTROUTE
+ sock_define_const("MSG_DONTROUTE", MSG_DONTROUTE);
+#endif
+#ifdef MSG_EOR
+ sock_define_const("MSG_EOR", MSG_EOR);
+#endif
+#ifdef MSG_TRUNC
+ sock_define_const("MSG_TRUNC", MSG_TRUNC);
+#endif
+#ifdef MSG_CTRUNC
+ sock_define_const("MSG_CTRUNC", MSG_CTRUNC);
+#endif
+#ifdef MSG_WAITALL
+ sock_define_const("MSG_WAITALL", MSG_WAITALL);
+#endif
+#ifdef MSG_DONTWAIT
+ sock_define_const("MSG_DONTWAIT", MSG_DONTWAIT);
+#endif
+#ifdef MSG_EOF
+ sock_define_const("MSG_EOF", MSG_EOF);
+#endif
+#ifdef MSG_FLUSH
+ sock_define_const("MSG_FLUSH", MSG_FLUSH);
+#endif
+#ifdef MSG_HOLD
+ sock_define_const("MSG_HOLD", MSG_HOLD);
+#endif
+#ifdef MSG_SEND
+ sock_define_const("MSG_SEND", MSG_SEND);
+#endif
+#ifdef MSG_HAVEMORE
+ sock_define_const("MSG_HAVEMORE", MSG_HAVEMORE);
+#endif
+#ifdef MSG_RCVMORE
+ sock_define_const("MSG_RCVMORE", MSG_RCVMORE);
+#endif
+#ifdef MSG_COMPAT
+ sock_define_const("MSG_COMPAT", MSG_COMPAT);
+#endif
+
+ sock_define_const("SOL_SOCKET", SOL_SOCKET);
+#ifdef SOL_IP
+ sock_define_const("SOL_IP", SOL_IP);
+#endif
+#ifdef SOL_IPX
+ sock_define_const("SOL_IPX", SOL_IPX);
+#endif
+#ifdef SOL_AX25
+ sock_define_const("SOL_AX25", SOL_AX25);
+#endif
+#ifdef SOL_ATALK
+ sock_define_const("SOL_ATALK", SOL_ATALK);
+#endif
+#ifdef SOL_TCP
+ sock_define_const("SOL_TCP", SOL_TCP);
+#endif
+#ifdef SOL_UDP
+ sock_define_const("SOL_UDP", SOL_UDP);
+#endif
+
+#ifdef IPPROTO_IP
+ sock_define_const("IPPROTO_IP", IPPROTO_IP);
+#else
+ sock_define_const("IPPROTO_IP", 0);
+#endif
+#ifdef IPPROTO_ICMP
+ sock_define_const("IPPROTO_ICMP", IPPROTO_ICMP);
+#else
+ sock_define_const("IPPROTO_ICMP", 1);
+#endif
+#ifdef IPPROTO_IGMP
+ sock_define_const("IPPROTO_IGMP", IPPROTO_IGMP);
+#endif
+#ifdef IPPROTO_GGP
+ sock_define_const("IPPROTO_GGP", IPPROTO_GGP);
+#endif
+#ifdef IPPROTO_TCP
+ sock_define_const("IPPROTO_TCP", IPPROTO_TCP);
+#else
+ sock_define_const("IPPROTO_TCP", 6);
+#endif
+#ifdef IPPROTO_EGP
+ sock_define_const("IPPROTO_EGP", IPPROTO_EGP);
+#endif
+#ifdef IPPROTO_PUP
+ sock_define_const("IPPROTO_PUP", IPPROTO_PUP);
+#endif
+#ifdef IPPROTO_UDP
+ sock_define_const("IPPROTO_UDP", IPPROTO_UDP);
+#else
+ sock_define_const("IPPROTO_UDP", 17);
+#endif
+#ifdef IPPROTO_IDP
+ sock_define_const("IPPROTO_IDP", IPPROTO_IDP);
+#endif
+#ifdef IPPROTO_HELLO
+ sock_define_const("IPPROTO_HELLO", IPPROTO_HELLO);
+#endif
+#ifdef IPPROTO_ND
+ sock_define_const("IPPROTO_ND", IPPROTO_ND);
+#endif
+#ifdef IPPROTO_TP
+ sock_define_const("IPPROTO_TP", IPPROTO_TP);
+#endif
+#ifdef IPPROTO_XTP
+ sock_define_const("IPPROTO_XTP", IPPROTO_XTP);
+#endif
+#ifdef IPPROTO_EON
+ sock_define_const("IPPROTO_EON", IPPROTO_EON);
+#endif
+#ifdef IPPROTO_BIP
+ sock_define_const("IPPROTO_BIP", IPPROTO_BIP);
+#endif
+/**/
+#ifdef IPPROTO_RAW
+ sock_define_const("IPPROTO_RAW", IPPROTO_RAW);
+#else
+ sock_define_const("IPPROTO_RAW", 255);
+#endif
+#ifdef IPPROTO_MAX
+ sock_define_const("IPPROTO_MAX", IPPROTO_MAX);
+#endif
+
+ /* Some port configuration */
+#ifdef IPPORT_RESERVED
+ sock_define_const("IPPORT_RESERVED", IPPORT_RESERVED);
+#else
+ sock_define_const("IPPORT_RESERVED", 1024);
+#endif
+#ifdef IPPORT_USERRESERVED
+ sock_define_const("IPPORT_USERRESERVED", IPPORT_USERRESERVED);
+#else
+ sock_define_const("IPPORT_USERRESERVED", 5000);
+#endif
+ /* Some reserved IP v.4 addresses */
+#ifdef INADDR_ANY
+ sock_define_const("INADDR_ANY", INADDR_ANY);
+#else
+ sock_define_const("INADDR_ANY", 0x00000000);
+#endif
+#ifdef INADDR_BROADCAST
+ sock_define_const("INADDR_BROADCAST", INADDR_BROADCAST);
+#else
+ sock_define_const("INADDR_BROADCAST", 0xffffffff);
+#endif
+#ifdef INADDR_LOOPBACK
+ sock_define_const("INADDR_LOOPBACK", INADDR_LOOPBACK);
+#else
+ sock_define_const("INADDR_LOOPBACK", 0x7F000001);
+#endif
+#ifdef INADDR_UNSPEC_GROUP
+ sock_define_const("INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP);
+#else
+ sock_define_const("INADDR_UNSPEC_GROUP", 0xe0000000);
+#endif
+#ifdef INADDR_ALLHOSTS_GROUP
+ sock_define_const("INADDR_ALLHOSTS_GROUP", INADDR_ALLHOSTS_GROUP);
+#else
+ sock_define_const("INADDR_ALLHOSTS_GROUP", 0xe0000001);
+#endif
+#ifdef INADDR_MAX_LOCAL_GROUP
+ sock_define_const("INADDR_MAX_LOCAL_GROUP", INADDR_MAX_LOCAL_GROUP);
+#else
+ sock_define_const("INADDR_MAX_LOCAL_GROUP", 0xe00000ff);
+#endif
+#ifdef INADDR_NONE
+ sock_define_const("INADDR_NONE", INADDR_NONE);
+#else
+ sock_define_const("INADDR_NONE", 0xffffffff);
+#endif
+ /* IP [gs]etsockopt options */
+#ifdef IP_OPTIONS
+ sock_define_const("IP_OPTIONS", IP_OPTIONS);
+#endif
+#ifdef IP_HDRINCL
+ sock_define_const("IP_HDRINCL", IP_HDRINCL);
+#endif
+#ifdef IP_TOS
+ sock_define_const("IP_TOS", IP_TOS);
+#endif
+#ifdef IP_TTL
+ sock_define_const("IP_TTL", IP_TTL);
+#endif
+#ifdef IP_RECVOPTS
+ sock_define_const("IP_RECVOPTS", IP_RECVOPTS);
+#endif
+#ifdef IP_RECVRETOPTS
+ sock_define_const("IP_RECVRETOPTS", IP_RECVRETOPTS);
+#endif
+#ifdef IP_RECVDSTADDR
+ sock_define_const("IP_RECVDSTADDR", IP_RECVDSTADDR);
+#endif
+#ifdef IP_RETOPTS
+ sock_define_const("IP_RETOPTS", IP_RETOPTS);
+#endif
+#ifdef IP_MULTICAST_IF
+ sock_define_const("IP_MULTICAST_IF", IP_MULTICAST_IF);
+#endif
+#ifdef IP_MULTICAST_TTL
+ sock_define_const("IP_MULTICAST_TTL", IP_MULTICAST_TTL);
+#endif
+#ifdef IP_MULTICAST_LOOP
+ sock_define_const("IP_MULTICAST_LOOP", IP_MULTICAST_LOOP);
+#endif
+#ifdef IP_ADD_MEMBERSHIP
+ sock_define_const("IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP);
+#endif
+#ifdef IP_DROP_MEMBERSHIP
+ sock_define_const("IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP);
+#endif
+#ifdef IP_DEFAULT_MULTICAST_TTL
+ sock_define_const("IP_DEFAULT_MULTICAST_TTL", IP_DEFAULT_MULTICAST_TTL);
+#endif
+#ifdef IP_DEFAULT_MULTICAST_LOOP
+ sock_define_const("IP_DEFAULT_MULTICAST_LOOP", IP_DEFAULT_MULTICAST_LOOP);
+#endif
+#ifdef IP_MAX_MEMBERSHIPS
+ sock_define_const("IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS);
+#endif
+#ifdef SO_DEBUG
+ sock_define_const("SO_DEBUG", SO_DEBUG);
+#endif
+ sock_define_const("SO_REUSEADDR", SO_REUSEADDR);
+#ifdef SO_REUSEPORT
+ sock_define_const("SO_REUSEPORT", SO_REUSEPORT);
+#endif
+#ifdef SO_TYPE
+ sock_define_const("SO_TYPE", SO_TYPE);
+#endif
+#ifdef SO_ERROR
+ sock_define_const("SO_ERROR", SO_ERROR);
+#endif
+#ifdef SO_DONTROUTE
+ sock_define_const("SO_DONTROUTE", SO_DONTROUTE);
+#endif
+#ifdef SO_BROADCAST
+ sock_define_const("SO_BROADCAST", SO_BROADCAST);
+#endif
+#ifdef SO_SNDBUF
+ sock_define_const("SO_SNDBUF", SO_SNDBUF);
+#endif
+#ifdef SO_RCVBUF
+ sock_define_const("SO_RCVBUF", SO_RCVBUF);
+#endif
+#ifdef SO_KEEPALIVE
+ sock_define_const("SO_KEEPALIVE", SO_KEEPALIVE);
+#endif
+#ifdef SO_OOBINLINE
+ sock_define_const("SO_OOBINLINE", SO_OOBINLINE);
+#endif
+#ifdef SO_NO_CHECK
+ sock_define_const("SO_NO_CHECK", SO_NO_CHECK);
+#endif
+#ifdef SO_PRIORITY
+ sock_define_const("SO_PRIORITY", SO_PRIORITY);
+#endif
+#ifdef SO_LINGER
+ sock_define_const("SO_LINGER", SO_LINGER);
+#endif
+#ifdef SO_PASSCRED
+ sock_define_const("SO_PASSCRED", SO_PASSCRED);
+#endif
+#ifdef SO_PEERCRED
+ sock_define_const("SO_PEERCRED", SO_PEERCRED);
+#endif
+#ifdef SO_RCVLOWAT
+ sock_define_const("SO_RCVLOWAT", SO_RCVLOWAT);
+#endif
+#ifdef SO_SNDLOWAT
+ sock_define_const("SO_SNDLOWAT", SO_SNDLOWAT);
+#endif
+#ifdef SO_RCVTIMEO
+ sock_define_const("SO_RCVTIMEO", SO_RCVTIMEO);
+#endif
+#ifdef SO_SNDTIMEO
+ sock_define_const("SO_SNDTIMEO", SO_SNDTIMEO);
+#endif
+#ifdef SO_ACCEPTCONN
+ sock_define_const("SO_ACCEPTCONN", SO_ACCEPTCONN);
+#endif
+#ifdef SO_USELOOPBACK
+ sock_define_const("SO_USELOOPBACK", SO_USELOOPBACK);
+#endif
+#ifdef SO_ACCEPTFILTER
+ sock_define_const("SO_ACCEPTFILTER", SO_ACCEPTFILTER);
+#endif
+#ifdef SO_DONTTRUNC
+ sock_define_const("SO_DONTTRUNC", SO_DONTTRUNC);
+#endif
+#ifdef SO_WANTMORE
+ sock_define_const("SO_WANTMORE", SO_WANTMORE);
+#endif
+#ifdef SO_WANTOOBFLAG
+ sock_define_const("SO_WANTOOBFLAG", SO_WANTOOBFLAG);
+#endif
+#ifdef SO_NREAD
+ sock_define_const("SO_NREAD", SO_NREAD);
+#endif
+#ifdef SO_NKE
+ sock_define_const("SO_NKE", SO_NKE);
+#endif
+#ifdef SO_NOSIGPIPE
+ sock_define_const("SO_NOSIGPIPE", SO_NOSIGPIPE);
+#endif
+
+#ifdef SO_SECURITY_AUTHENTICATION
+ sock_define_const("SO_SECURITY_AUTHENTICATION", SO_SECURITY_AUTHENTICATION);
+#endif
+#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
+ sock_define_const("SO_SECURITY_ENCRYPTION_TRANSPORT", SO_SECURITY_ENCRYPTION_TRANSPORT);
+#endif
+#ifdef SO_SECURITY_ENCRYPTION_NETWORK
+ sock_define_const("SO_SECURITY_ENCRYPTION_NETWORK", SO_SECURITY_ENCRYPTION_NETWORK);
+#endif
+
+#ifdef SO_BINDTODEVICE
+ sock_define_const("SO_BINDTODEVICE", SO_BINDTODEVICE);
+#endif
+#ifdef SO_ATTACH_FILTER
+ sock_define_const("SO_ATTACH_FILTER", SO_ATTACH_FILTER);
+#endif
+#ifdef SO_DETACH_FILTER
+ sock_define_const("SO_DETACH_FILTER", SO_DETACH_FILTER);
+#endif
+#ifdef SO_PEERNAME
+ sock_define_const("SO_PEERNAME", SO_PEERNAME);
+#endif
+#ifdef SO_TIMESTAMP
+ sock_define_const("SO_TIMESTAMP", SO_TIMESTAMP);
+#endif
+
+#ifdef SOPRI_INTERACTIVE
+ sock_define_const("SOPRI_INTERACTIVE", SOPRI_INTERACTIVE);
+#endif
+#ifdef SOPRI_NORMAL
+ sock_define_const("SOPRI_NORMAL", SOPRI_NORMAL);
+#endif
+#ifdef SOPRI_BACKGROUND
+ sock_define_const("SOPRI_BACKGROUND", SOPRI_BACKGROUND);
+#endif
+
+#ifdef IPX_TYPE
+ sock_define_const("IPX_TYPE", IPX_TYPE);
+#endif
+
+#ifdef TCP_NODELAY
+ sock_define_const("TCP_NODELAY", TCP_NODELAY);
+#endif
+#ifdef TCP_MAXSEG
+ sock_define_const("TCP_MAXSEG", TCP_MAXSEG);
+#endif
+
+#ifdef EAI_ADDRFAMILY
+ sock_define_const("EAI_ADDRFAMILY", EAI_ADDRFAMILY);
+#endif
+#ifdef EAI_AGAIN
+ sock_define_const("EAI_AGAIN", EAI_AGAIN);
+#endif
+#ifdef EAI_BADFLAGS
+ sock_define_const("EAI_BADFLAGS", EAI_BADFLAGS);
+#endif
+#ifdef EAI_FAIL
+ sock_define_const("EAI_FAIL", EAI_FAIL);
+#endif
+#ifdef EAI_FAMILY
+ sock_define_const("EAI_FAMILY", EAI_FAMILY);
+#endif
+#ifdef EAI_MEMORY
+ sock_define_const("EAI_MEMORY", EAI_MEMORY);
+#endif
+#ifdef EAI_NODATA
+ sock_define_const("EAI_NODATA", EAI_NODATA);
+#endif
+#ifdef EAI_NONAME
+ sock_define_const("EAI_NONAME", EAI_NONAME);
+#endif
+#ifdef EAI_SERVICE
+ sock_define_const("EAI_SERVICE", EAI_SERVICE);
+#endif
+#ifdef EAI_SOCKTYPE
+ sock_define_const("EAI_SOCKTYPE", EAI_SOCKTYPE);
+#endif
+#ifdef EAI_SYSTEM
+ sock_define_const("EAI_SYSTEM", EAI_SYSTEM);
+#endif
+#ifdef EAI_BADHINTS
+ sock_define_const("EAI_BADHINTS", EAI_BADHINTS);
+#endif
+#ifdef EAI_PROTOCOL
+ sock_define_const("EAI_PROTOCOL", EAI_PROTOCOL);
+#endif
+#ifdef EAI_MAX
+ sock_define_const("EAI_MAX", EAI_MAX);
+#endif
+#ifdef AI_PASSIVE
+ sock_define_const("AI_PASSIVE", AI_PASSIVE);
+#endif
+#ifdef AI_CANONNAME
+ sock_define_const("AI_CANONNAME", AI_CANONNAME);
+#endif
+#ifdef AI_NUMERICHOST
+ sock_define_const("AI_NUMERICHOST", AI_NUMERICHOST);
+#endif
+#ifdef AI_MASK
+ sock_define_const("AI_MASK", AI_MASK);
+#endif
+#ifdef AI_ALL
+ sock_define_const("AI_ALL", AI_ALL);
+#endif
+#ifdef AI_V4MAPPED_CFG
+ sock_define_const("AI_V4MAPPED_CFG", AI_V4MAPPED_CFG);
+#endif
+#ifdef AI_ADDRCONFIG
+ sock_define_const("AI_ADDRCONFIG", AI_ADDRCONFIG);
+#endif
+#ifdef AI_V4MAPPED
+ sock_define_const("AI_V4MAPPED", AI_V4MAPPED);
+#endif
+#ifdef AI_DEFAULT
+ sock_define_const("AI_DEFAULT", AI_DEFAULT);
+#endif
+#ifdef NI_MAXHOST
+ sock_define_const("NI_MAXHOST", NI_MAXHOST);
+#endif
+#ifdef NI_MAXSERV
+ sock_define_const("NI_MAXSERV", NI_MAXSERV);
+#endif
+#ifdef NI_NOFQDN
+ sock_define_const("NI_NOFQDN", NI_NOFQDN);
+#endif
+#ifdef NI_NUMERICHOST
+ sock_define_const("NI_NUMERICHOST", NI_NUMERICHOST);
+#endif
+#ifdef NI_NAMEREQD
+ sock_define_const("NI_NAMEREQD", NI_NAMEREQD);
+#endif
+#ifdef NI_NUMERICSERV
+ sock_define_const("NI_NUMERICSERV", NI_NUMERICSERV);
+#endif
+#ifdef NI_DGRAM
+ sock_define_const("NI_DGRAM", NI_DGRAM);
+#endif
+#ifdef SHUT_RD
+ sock_define_const("SHUT_RD", SHUT_RD);
+#else
+ sock_define_const("SHUT_RD", 0);
+#endif
+#ifdef SHUT_WR
+ sock_define_const("SHUT_WR", SHUT_WR);
+#else
+ sock_define_const("SHUT_WR", 1);
+#endif
+#ifdef SHUT_RDWR
+ sock_define_const("SHUT_RDWR", SHUT_RDWR);
+#else
+ sock_define_const("SHUT_RDWR", 2);
+#endif
}
diff --git a/ext/stringio/.cvsignore b/ext/stringio/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/stringio/.cvsignore
+++ b/ext/stringio/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index d0c97037e4..86ff56534c 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -20,6 +20,8 @@
#include <sys/fcntl.h>
#endif
+#define STRIO_EOF FMODE_SYNC
+
struct StringIO {
VALUE string;
long pos;
@@ -53,7 +55,8 @@ strio_alloc()
}
static void
-strio_mark(struct StringIO *ptr)
+strio_mark(ptr)
+ struct StringIO *ptr;
{
if (ptr) {
rb_gc_mark(ptr->string);
@@ -61,7 +64,8 @@ strio_mark(struct StringIO *ptr)
}
static void
-strio_free(struct StringIO *ptr)
+strio_free(ptr)
+ struct StringIO *ptr;
{
if (--ptr->count <= 0) {
xfree(ptr);
@@ -69,7 +73,8 @@ strio_free(struct StringIO *ptr)
}
static struct StringIO*
-check_strio(VALUE self)
+check_strio(self)
+ VALUE self;
{
Check_Type(self, T_DATA);
if (!IS_STRIO(self)) {
@@ -80,7 +85,8 @@ check_strio(VALUE self)
}
static struct StringIO*
-get_strio(VALUE self)
+get_strio(self)
+ VALUE self;
{
struct StringIO *ptr = check_strio(self);
@@ -97,7 +103,8 @@ get_strio(VALUE self)
#define WRITABLE(ptr) ((ptr)->flags & FMODE_WRITABLE)
static struct StringIO*
-readable(struct StringIO *ptr)
+readable(ptr)
+ struct StringIO *ptr;
{
if (!READABLE(ptr)) {
rb_raise(rb_eIOError, "not opened for reading");
@@ -106,7 +113,8 @@ readable(struct StringIO *ptr)
}
static struct StringIO*
-writable(struct StringIO *ptr)
+writable(ptr)
+ struct StringIO *ptr;
{
if (!WRITABLE(ptr)) {
rb_raise(rb_eIOError, "not opened for writing");
@@ -118,7 +126,8 @@ writable(struct StringIO *ptr)
}
static void
-check_modifiable(struct StringIO *ptr)
+check_modifiable(ptr)
+ struct StringIO *ptr;
{
if (OBJ_FROZEN(ptr->string)) {
rb_raise(rb_eIOError, "not modifiable string");
@@ -127,6 +136,7 @@ check_modifiable(struct StringIO *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));
@@ -186,7 +196,10 @@ strio_s_allocate(klass)
* returned from the block.
*/
static VALUE
-strio_s_open(int argc, VALUE *argv, VALUE klass)
+strio_s_open(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE obj = rb_class_new_instance(argc, argv, klass);
if (!rb_block_given_p()) return obj;
@@ -199,16 +212,30 @@ strio_s_open(int argc, VALUE *argv, VALUE klass)
* Creates new StringIO instance from with _string_ and _mode_.
*/
static VALUE
-strio_initialize(int argc, VALUE *argv, VALUE self)
+strio_initialize(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ 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)) {
@@ -240,11 +267,11 @@ strio_initialize(int argc, VALUE *argv, VALUE self)
break;
}
ptr->string = string;
- return self;
}
static VALUE
-strio_finalize(VALUE self)
+strio_finalize(self)
+ VALUE self;
{
struct StringIO *ptr = StringIO(self);
ptr->string = Qnil;
@@ -256,7 +283,8 @@ strio_finalize(VALUE self)
* Returns +false+. Just for compatibility to IO.
*/
static VALUE
-strio_false(VALUE self)
+strio_false(self)
+ VALUE self;
{
StringIO(self);
return Qfalse;
@@ -266,7 +294,8 @@ strio_false(VALUE self)
* Returns +nil+. Just for compatibility to IO.
*/
static VALUE
-strio_nil(VALUE self)
+strio_nil(self)
+ VALUE self;
{
StringIO(self);
return Qnil;
@@ -276,7 +305,8 @@ strio_nil(VALUE self)
* Returns *strio* itself. Just for compatibility to IO.
*/
static VALUE
-strio_self(VALUE self)
+strio_self(self)
+ VALUE self;
{
StringIO(self);
return self;
@@ -286,7 +316,8 @@ strio_self(VALUE self)
* Returns 0. Just for compatibility to IO.
*/
static VALUE
-strio_0(VALUE self)
+strio_0(self)
+ VALUE self;
{
StringIO(self);
return INT2FIX(0);
@@ -296,7 +327,8 @@ strio_0(VALUE self)
* Returns the argument unchanged. Just for compatibility to IO.
*/
static VALUE
-strio_first(VALUE self, VALUE arg)
+strio_first(self, arg)
+ VALUE self, arg;
{
StringIO(self);
return arg;
@@ -306,7 +338,10 @@ strio_first(VALUE self, VALUE arg)
* Raises NotImplementedError.
*/
static VALUE
-strio_unimpl(int argc, VALUE *argv, VALUE self)
+strio_unimpl(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
StringIO(self);
rb_notimplement();
@@ -319,7 +354,8 @@ strio_unimpl(int argc, VALUE *argv, VALUE self)
* Returns underlying String object, the subject of IO.
*/
static VALUE
-strio_get_string(VALUE self)
+strio_get_string(self)
+ VALUE self;
{
return StringIO(self)->string;
}
@@ -331,7 +367,8 @@ strio_get_string(VALUE self)
* Changes underlying String object, the subject of IO.
*/
static VALUE
-strio_set_string(VALUE self, VALUE string)
+strio_set_string(self, string)
+ VALUE self, string;
{
struct StringIO *ptr = StringIO(self);
@@ -352,7 +389,8 @@ strio_set_string(VALUE self, VALUE string)
* operations; an +IOError+ is raised if such an attempt is made.
*/
static VALUE
-strio_close(VALUE self)
+strio_close(self)
+ VALUE self;
{
struct StringIO *ptr = StringIO(self);
if (CLOSED(ptr)) {
@@ -370,7 +408,8 @@ strio_close(VALUE self)
* *strio* is not readable.
*/
static VALUE
-strio_close_read(VALUE self)
+strio_close_read(self)
+ VALUE self;
{
struct StringIO *ptr = StringIO(self);
if (!READABLE(ptr)) {
@@ -388,7 +427,8 @@ strio_close_read(VALUE self)
* *strio* is not writeable.
*/
static VALUE
-strio_close_write(VALUE self)
+strio_close_write(self)
+ VALUE self;
{
struct StringIO *ptr = StringIO(self);
if (!WRITABLE(ptr)) {
@@ -405,7 +445,8 @@ strio_close_write(VALUE self)
* Returns +true+ if *strio* is completely closed, +false+ otherwise.
*/
static VALUE
-strio_closed(VALUE self)
+strio_closed(self)
+ VALUE self;
{
struct StringIO *ptr = StringIO(self);
if (!CLOSED(ptr)) return Qfalse;
@@ -419,7 +460,8 @@ strio_closed(VALUE self)
* Returns +true+ if *strio* is not readable, +false+ otherwise.
*/
static VALUE
-strio_closed_read(VALUE self)
+strio_closed_read(self)
+ VALUE self;
{
struct StringIO *ptr = StringIO(self);
if (READABLE(ptr)) return Qfalse;
@@ -433,7 +475,8 @@ strio_closed_read(VALUE self)
* Returns +true+ if *strio* is not writable, +false+ otherwise.
*/
static VALUE
-strio_closed_write(VALUE self)
+strio_closed_write(self)
+ VALUE self;
{
struct StringIO *ptr = StringIO(self);
if (WRITABLE(ptr)) return Qfalse;
@@ -449,16 +492,18 @@ strio_closed_write(VALUE self)
* opened for reading or an +IOError+ will be raised.
*/
static VALUE
-strio_eof(VALUE self)
+strio_eof(self)
+ VALUE self;
{
struct StringIO *ptr = readable(StringIO(self));
- if (ptr->pos < RSTRING_LEN(ptr->string)) return Qfalse;
+ if (ptr->pos < RSTRING(ptr->string)->len) return Qfalse;
return Qtrue;
}
/* :nodoc: */
static VALUE
-strio_copy(VALUE copy, VALUE orig)
+strio_copy(copy, orig)
+ VALUE copy, orig;
{
struct StringIO *ptr;
@@ -485,7 +530,8 @@ strio_copy(VALUE copy, VALUE orig)
* newline. See also the <code>$.</code> variable.
*/
static VALUE
-strio_get_lineno(VALUE self)
+strio_get_lineno(self)
+ VALUE self;
{
return LONG2NUM(StringIO(self)->lineno);
}
@@ -498,7 +544,8 @@ strio_get_lineno(VALUE self)
* <code>$.</code> is updated only on the next read.
*/
static VALUE
-strio_set_lineno(VALUE self, VALUE lineno)
+strio_set_lineno(self, lineno)
+ VALUE self, lineno;
{
StringIO(self)->lineno = NUM2LONG(lineno);
return lineno;
@@ -525,13 +572,17 @@ strio_set_lineno(VALUE self, VALUE lineno)
* and _mode_ (see StringIO#new).
*/
static VALUE
-strio_reopen(int argc, VALUE *argv, VALUE self)
+strio_reopen(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
if (!OBJ_TAINTED(self)) rb_secure(4);
if (argc == 1 && TYPE(*argv) != T_STRING) {
return strio_copy(self, *argv);
}
- return strio_initialize(argc, argv, self);
+ strio_init(argc, argv, StringIO(self));
+ return self;
}
/*
@@ -542,7 +593,8 @@ strio_reopen(int argc, VALUE *argv, VALUE self)
* Returns the current offset (in bytes) of *strio*.
*/
static VALUE
-strio_get_pos(VALUE self)
+strio_get_pos(self)
+ VALUE self;
{
return LONG2NUM(StringIO(self)->pos);
}
@@ -554,7 +606,9 @@ strio_get_pos(VALUE self)
* Seeks to the given position (in bytes) in *strio*.
*/
static VALUE
-strio_set_pos(VALUE self, VALUE pos)
+strio_set_pos(self, pos)
+ VALUE self;
+ VALUE pos;
{
struct StringIO *ptr = StringIO(self);
long p = NUM2LONG(pos);
@@ -562,6 +616,7 @@ strio_set_pos(VALUE self, VALUE pos)
error_inval(0);
}
ptr->pos = p;
+ ptr->flags &= ~STRIO_EOF;
return pos;
}
@@ -573,11 +628,13 @@ strio_set_pos(VALUE self, VALUE pos)
* +lineno+ to zero.
*/
static VALUE
-strio_rewind(VALUE self)
+strio_rewind(self)
+ VALUE self;
{
struct StringIO *ptr = StringIO(self);
ptr->pos = 0;
ptr->lineno = 0;
+ ptr->flags &= ~STRIO_EOF;
return INT2FIX(0);
}
@@ -589,7 +646,10 @@ strio_rewind(VALUE self)
* the value of _whence_ (see IO#seek).
*/
static VALUE
-strio_seek(int argc, VALUE *argv, VALUE self)
+strio_seek(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE whence;
struct StringIO *ptr = StringIO(self);
@@ -604,7 +664,7 @@ strio_seek(int argc, VALUE *argv, VALUE self)
offset += ptr->pos;
break;
case 2:
- offset += RSTRING_LEN(ptr->string);
+ offset += RSTRING(ptr->string)->len;
break;
default:
rb_raise(rb_eArgError, "invalid whence %ld", NUM2LONG(whence));
@@ -613,6 +673,7 @@ strio_seek(int argc, VALUE *argv, VALUE self)
error_inval(0);
}
ptr->pos = offset;
+ ptr->flags &= ~STRIO_EOF;
return INT2FIX(0);
}
@@ -623,7 +684,8 @@ strio_seek(int argc, VALUE *argv, VALUE self)
* Returns +true+ always.
*/
static VALUE
-strio_get_sync(VALUE self)
+strio_get_sync(self)
+ VALUE self;
{
StringIO(self);
return Qtrue;
@@ -641,11 +703,12 @@ strio_get_sync(VALUE self)
* See IO#each_byte.
*/
static VALUE
-strio_each_byte(VALUE self)
+strio_each_byte(self)
+ VALUE self;
{
struct StringIO *ptr = readable(StringIO(self));
- while (ptr->pos < RSTRING_LEN(ptr->string)) {
- char c = RSTRING_PTR(ptr->string)[ptr->pos++];
+ while (ptr->pos < RSTRING(ptr->string)->len) {
+ char c = RSTRING(ptr->string)->ptr[ptr->pos++];
rb_yield(CHR2FIX(c));
}
return Qnil;
@@ -658,28 +721,32 @@ strio_each_byte(VALUE self)
* See IO#getc.
*/
static VALUE
-strio_getc(VALUE self)
+strio_getc(self)
+ VALUE self;
{
struct StringIO *ptr = readable(StringIO(self));
int c;
- if (ptr->pos >= RSTRING_LEN(ptr->string)) {
+ if (ptr->pos >= RSTRING(ptr->string)->len) {
+ ptr->flags |= STRIO_EOF;
return Qnil;
}
- c = RSTRING_PTR(ptr->string)[ptr->pos++];
+ c = RSTRING(ptr->string)->ptr[ptr->pos++];
return CHR2FIX(c);
}
static void
-strio_extend(struct StringIO *ptr, long pos, long len)
+strio_extend(ptr, pos, len)
+ struct StringIO *ptr;
+ long pos, len;
{
long olen;
check_modifiable(ptr);
- olen = RSTRING_LEN(ptr->string);
+ olen = RSTRING(ptr->string)->len;
if (pos + len > olen) {
rb_str_resize(ptr->string, pos + len);
if (pos > olen)
- MEMZERO(RSTRING_PTR(ptr->string) + olen, char, pos - olen);
+ MEMZERO(RSTRING(ptr->string)->ptr + olen, char, pos - olen);
}
else {
rb_str_modify(ptr->string);
@@ -697,21 +764,23 @@ strio_extend(struct StringIO *ptr, long pos, long len)
* In other case, there is no limitation for multiple pushbacks.
*/
static VALUE
-strio_ungetc(VALUE self, VALUE ch)
+strio_ungetc(self, ch)
+ VALUE self, ch;
{
struct StringIO *ptr = readable(StringIO(self));
int cc = NUM2INT(ch);
long len, pos = ptr->pos;
if (cc != EOF && pos > 0) {
- if ((len = RSTRING_LEN(ptr->string)) < pos-- ||
- (unsigned char)RSTRING_PTR(ptr->string)[pos] !=
+ if ((len = RSTRING(ptr->string)->len) < pos-- ||
+ (unsigned char)RSTRING(ptr->string)->ptr[pos] !=
(unsigned char)cc) {
strio_extend(ptr, pos, 1);
- RSTRING_PTR(ptr->string)[pos] = cc;
+ RSTRING(ptr->string)->ptr[pos] = cc;
OBJ_INFECT(ptr->string, self);
}
--ptr->pos;
+ ptr->flags &= ~STRIO_EOF;
}
return Qnil;
}
@@ -723,7 +792,8 @@ strio_ungetc(VALUE self, VALUE ch)
* See IO#readchar.
*/
static VALUE
-strio_readchar(VALUE self)
+strio_readchar(self)
+ VALUE self;
{
VALUE c = strio_getc(self);
if (NIL_P(c)) rb_eof_error();
@@ -731,7 +801,10 @@ strio_readchar(VALUE self)
}
static void
-bm_init_skip(long *skip, const char *pat, long m)
+bm_init_skip(skip, pat, m)
+ long *skip;
+ const char *pat;
+ long m;
{
int c;
@@ -744,7 +817,12 @@ bm_init_skip(long *skip, const char *pat, long m)
}
static long
-bm_search(const char *little, long llen, const char *big, long blen, const long *skip)
+bm_search(little, llen, big, blen, skip)
+ const char *little;
+ long llen;
+ const char *big;
+ long blen;
+ const long *skip;
{
long i, j, k;
@@ -763,7 +841,10 @@ bm_search(const char *little, long llen, const char *big, long blen, const long
}
static VALUE
-strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
+strio_getline(argc, argv, ptr)
+ int argc;
+ VALUE *argv;
+ struct StringIO *ptr;
{
const char *s, *e, *p;
long n;
@@ -777,19 +858,21 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
if (!NIL_P(str)) StringValue(str);
}
- if (ptr->pos >= (n = RSTRING_LEN(ptr->string))) {
+ if (ptr->pos >= (n = RSTRING(ptr->string)->len)) {
+ ptr->flags |= STRIO_EOF;
return Qnil;
}
- s = RSTRING_PTR(ptr->string);
- e = s + RSTRING_LEN(ptr->string);
+ s = RSTRING(ptr->string)->ptr;
+ e = s + RSTRING(ptr->string)->len;
s += ptr->pos;
if (NIL_P(str)) {
str = rb_str_substr(ptr->string, ptr->pos, e - s);
}
- else if ((n = RSTRING_LEN(str)) == 0) {
+ else if ((n = RSTRING(str)->len) == 0) {
p = s;
while (*p == '\n') {
if (++p == e) {
+ ptr->flags |= STRIO_EOF;
return Qnil;
}
}
@@ -800,10 +883,10 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
break;
}
}
- str = rb_str_substr(ptr->string, s - RSTRING_PTR(ptr->string), e - s);
+ str = rb_str_substr(ptr->string, s - RSTRING(ptr->string)->ptr, e - s);
}
else if (n == 1) {
- if ((p = memchr(s, RSTRING_PTR(str)[0], e - s)) != 0) {
+ if ((p = memchr(s, RSTRING(str)->ptr[0], e - s)) != 0) {
e = p + 1;
}
str = rb_str_substr(ptr->string, ptr->pos, e - s);
@@ -812,7 +895,7 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
if (n < e - s) {
if (e - s < 1024) {
for (p = s; p + n <= e; ++p) {
- if (MEMCMP(p, RSTRING_PTR(str), char, n) == 0) {
+ if (MEMCMP(p, RSTRING(str)->ptr, char, n) == 0) {
e = p + n;
break;
}
@@ -820,7 +903,7 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
}
else {
long skip[1 << CHAR_BIT], pos;
- p = RSTRING_PTR(str);
+ p = RSTRING(str)->ptr;
bm_init_skip(skip, p, n);
if ((pos = bm_search(p, n, s, e - s, skip)) >= 0) {
e = s + pos + n;
@@ -829,7 +912,7 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
}
str = rb_str_substr(ptr->string, ptr->pos, e - s);
}
- ptr->pos = e - RSTRING_PTR(ptr->string);
+ ptr->pos = e - RSTRING(ptr->string)->ptr;
ptr->lineno++;
return str;
}
@@ -841,7 +924,10 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
* See IO#gets.
*/
static VALUE
-strio_gets(int argc, VALUE *argv, VALUE self)
+strio_gets(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE str = strio_getline(argc, argv, readable(StringIO(self)));
@@ -856,9 +942,12 @@ strio_gets(int argc, VALUE *argv, VALUE self)
* See IO#readline.
*/
static VALUE
-strio_readline(int argc, VALUE *argv, VALUE self)
+strio_readline(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
- VALUE line = strio_getline(argc, argv, readable(StringIO(self)));
+ VALUE line = strio_gets(argc, argv, self);
if (NIL_P(line)) rb_eof_error();
return line;
}
@@ -871,7 +960,10 @@ strio_readline(int argc, VALUE *argv, VALUE self)
* See IO#each.
*/
static VALUE
-strio_each(int argc, VALUE *argv, VALUE self)
+strio_each(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
struct StringIO *ptr = StringIO(self);
VALUE line;
@@ -889,7 +981,10 @@ strio_each(int argc, VALUE *argv, VALUE self)
* See IO#readlines.
*/
static VALUE
-strio_readlines(int argc, VALUE *argv, VALUE self)
+strio_readlines(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
struct StringIO *ptr = StringIO(self);
VALUE ary = rb_ary_new(), line;
@@ -910,22 +1005,23 @@ strio_readlines(int argc, VALUE *argv, VALUE self)
* Returns the number of bytes written. See IO#write.
*/
static VALUE
-strio_write(VALUE self, VALUE str)
+strio_write(self, str)
+ VALUE self, str;
{
struct StringIO *ptr = writable(StringIO(self));
long len, olen;
if (TYPE(str) != T_STRING)
str = rb_obj_as_string(str);
- len = RSTRING_LEN(str);
+ len = RSTRING(str)->len;
if (!len) return INT2FIX(0);
check_modifiable(ptr);
- olen = RSTRING_LEN(ptr->string);
+ olen = RSTRING(ptr->string)->len;
if (ptr->flags & FMODE_APPEND) {
ptr->pos = olen;
}
if (ptr->pos == olen) {
- rb_str_cat(ptr->string, RSTRING_PTR(str), len);
+ rb_str_cat(ptr->string, RSTRING(str)->ptr, len);
}
else {
strio_extend(ptr, ptr->pos, len);
@@ -968,19 +1064,20 @@ strio_write(VALUE self, VALUE str)
* See IO#putc.
*/
static VALUE
-strio_putc(VALUE self, VALUE ch)
+strio_putc(self, ch)
+ VALUE self, ch;
{
struct StringIO *ptr = writable(StringIO(self));
int c = NUM2CHR(ch);
long olen;
check_modifiable(ptr);
- olen = RSTRING_LEN(ptr->string);
+ olen = RSTRING(ptr->string)->len;
if (ptr->flags & FMODE_APPEND) {
ptr->pos = olen;
}
strio_extend(ptr, ptr->pos, 1);
- RSTRING_PTR(ptr->string)[ptr->pos++] = c;
+ RSTRING(ptr->string)->ptr[ptr->pos++] = c;
OBJ_INFECT(ptr->string, self);
return ch;
}
@@ -1000,7 +1097,10 @@ strio_putc(VALUE self, VALUE ch)
* See IO#read.
*/
static VALUE
-strio_read(int argc, VALUE *argv, VALUE self)
+strio_read(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
struct StringIO *ptr = readable(StringIO(self));
VALUE str = Qnil;
@@ -1017,7 +1117,12 @@ strio_read(int argc, VALUE *argv, VALUE self)
if (len < 0) {
rb_raise(rb_eArgError, "negative length %ld given", len);
}
- if (len > 0 && ptr->pos >= RSTRING_LEN(ptr->string)) {
+ if (len > 0 && ptr->pos >= RSTRING(ptr->string)->len) {
+ ptr->flags |= STRIO_EOF;
+ if (!NIL_P(str)) rb_str_resize(str, 0);
+ return Qnil;
+ }
+ else if (ptr->flags & STRIO_EOF) {
if (!NIL_P(str)) rb_str_resize(str, 0);
return Qnil;
}
@@ -1026,8 +1131,9 @@ strio_read(int argc, VALUE *argv, VALUE self)
/* fall through */
case 0:
olen = -1;
- len = RSTRING_LEN(ptr->string);
+ len = RSTRING(ptr->string)->len;
if (len <= ptr->pos) {
+ ptr->flags |= STRIO_EOF;
if (NIL_P(str)) {
str = rb_str_new(0, 0);
}
@@ -1047,18 +1153,19 @@ strio_read(int argc, VALUE *argv, VALUE self)
str = rb_str_substr(ptr->string, ptr->pos, len);
}
else {
- long rest = RSTRING_LEN(ptr->string) - ptr->pos;
+ long rest = RSTRING(ptr->string)->len - ptr->pos;
if (len > rest) len = rest;
rb_str_resize(str, len);
- MEMCPY(RSTRING_PTR(str), RSTRING_PTR(ptr->string) + ptr->pos, char, len);
+ MEMCPY(RSTRING(str)->ptr, RSTRING(ptr->string)->ptr + ptr->pos, char, len);
}
if (NIL_P(str)) {
- str = rb_str_new(0, 0);
+ if (!(ptr->flags & STRIO_EOF)) str = rb_str_new(0, 0);
len = 0;
}
else {
- ptr->pos += len = RSTRING_LEN(str);
+ ptr->pos += len = RSTRING(str)->len;
}
+ if (olen < 0 || olen > len) ptr->flags |= STRIO_EOF;
return str;
}
@@ -1070,10 +1177,13 @@ strio_read(int argc, VALUE *argv, VALUE self)
* returning +nil+, as well as IO#sysread does.
*/
static VALUE
-strio_sysread(int argc, VALUE *argv, VALUE self)
+strio_sysread(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE val = strio_read(argc, argv, self);
- if (NIL_P(val) || RSTRING_LEN(val) == 0) {
+ if (NIL_P(val) || RSTRING(val)->len == 0) {
rb_eof_error();
}
return val;
@@ -1105,13 +1215,14 @@ strio_sysread(int argc, VALUE *argv, VALUE self)
* Returns the size of the buffer string.
*/
static VALUE
-strio_size(VALUE self)
+strio_size(self)
+ VALUE self;
{
VALUE string = StringIO(self)->string;
if (NIL_P(string)) {
rb_raise(rb_eIOError, "not opened");
}
- return ULONG2NUM(RSTRING_LEN(string));
+ return ULONG2NUM(RSTRING(string)->len);
}
/*
@@ -1122,17 +1233,18 @@ strio_size(VALUE self)
* must be opened for writing.
*/
static VALUE
-strio_truncate(VALUE self, VALUE len)
+strio_truncate(self, len)
+ VALUE self, len;
{
VALUE string = writable(StringIO(self))->string;
long l = NUM2LONG(len);
- long plen = RSTRING_LEN(string);
+ long plen = RSTRING(string)->len;
if (l < 0) {
error_inval("negative legnth");
}
rb_str_resize(string, l);
if (plen < l) {
- MEMZERO(RSTRING_PTR(string) + plen, char, l - plen);
+ MEMZERO(RSTRING(string)->ptr + plen, char, l - plen);
}
return len;
}
@@ -1189,7 +1301,6 @@ Init_stringio()
rb_define_method(StringIO, "readlines", strio_readlines, -1);
rb_define_method(StringIO, "read", strio_read, -1);
rb_define_method(StringIO, "sysread", strio_sysread, -1);
- rb_define_method(StringIO, "readpartial", strio_sysread, -1);
rb_define_method(StringIO, "write", strio_write, 1);
rb_define_method(StringIO, "<<", strio_addstr, 1);
diff --git a/ext/strscan/.cvsignore b/ext/strscan/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/strscan/.cvsignore
+++ b/ext/strscan/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/strscan/depend b/ext/strscan/depend
index 2a4255e916..9199574c3f 100644
--- a/ext/strscan/depend
+++ b/ext/strscan/depend
@@ -1,3 +1 @@
-strscan.o: strscan.c $(hdrdir)/ruby.h $(hdrdir)/re.h $(hdrdir)/regex.h \
- $(hdrdir)/regint.h $(hdrdir)/oniguruma.h $(topdir)/config.h \
- $(hdrdir)/defines.h
+strscan.o: strscan.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h
diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c
index f991a13ac4..b5ee20282c 100644
--- a/ext/strscan/strscan.c
+++ b/ext/strscan/strscan.c
@@ -41,13 +41,13 @@ struct strscanner
#define MATCHED(s) (s)->flags |= FLAG_MATCHED
#define CLEAR_MATCH_STATUS(s) (s)->flags &= ~FLAG_MATCHED
-#define S_PBEG(s) (RSTRING_PTR((s)->str))
-#define S_LEN(s) (RSTRING_LEN((s)->str))
+#define S_PBEG(s) (RSTRING((s)->str)->ptr)
+#define S_LEN(s) (RSTRING((s)->str)->len)
#define S_PEND(s) (S_PBEG(s) + S_LEN(s))
#define CURPTR(s) (S_PBEG(s) + (s)->curr)
#define S_RESTLEN(s) (S_LEN(s) - (s)->curr)
-#define EOS_P(s) ((s)->curr >= RSTRING_LEN(p->str))
+#define EOS_P(s) ((s)->curr >= RSTRING(p->str)->len)
#define GET_SCANNER(obj,var) do {\
Data_Get_Struct(obj, struct strscanner, var);\
@@ -62,7 +62,7 @@ static VALUE infect _((VALUE str, struct strscanner *p));
static VALUE extract_range _((struct strscanner *p, long beg_i, long end_i));
static VALUE extract_beg_len _((struct strscanner *p, long beg_i, long len));
-void check_strscan _((VALUE obj));
+static void check_strscan _((VALUE obj));
static void strscan_mark _((struct strscanner *p));
static void strscan_free _((struct strscanner *p));
static VALUE strscan_s_allocate _((VALUE klass));
@@ -156,7 +156,7 @@ strscan_mark(struct strscanner *p)
static void
strscan_free(struct strscanner *p)
{
- onig_region_free(&(p->regs), 0);
+ re_free_registers(&(p->regs));
free(p);
}
@@ -168,7 +168,7 @@ strscan_s_allocate(VALUE klass)
p = ALLOC(struct strscanner);
MEMZERO(p, struct strscanner, 1);
CLEAR_MATCH_STATUS(p);
- onig_region_init(&(p->regs));
+ MEMZERO(&(p->regs), struct re_registers, 1);
p->str = Qnil;
return Data_Wrap_Struct(klass, strscan_mark, strscan_free, p);
}
@@ -193,7 +193,7 @@ strscan_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
-void
+static void
check_strscan(VALUE obj)
{
if (TYPE(obj) != T_DATA || RDATA(obj)->dmark != (RUBY_DATA_FUNC)strscan_mark) {
@@ -219,13 +219,12 @@ strscan_init_copy(VALUE vself, VALUE vorig)
check_strscan(vorig);
Data_Get_Struct(vorig, struct strscanner, orig);
if (self != orig) {
- self->flags = orig->flags;
- self->str = orig->str;
- self->prev = orig->prev;
- self->curr = orig->curr;
- onig_region_copy(&self->regs, &orig->regs);
+ self->flags = orig->flags;
+ self->str = orig->str;
+ self->prev = orig->prev;
+ self->curr = orig->curr;
+ re_copy_registers(&self->regs, &orig->regs);
}
-
return vself;
}
@@ -404,17 +403,21 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
if (S_RESTLEN(p) < 0) {
return Qnil;
}
+ rb_kcode_set_option(regex);
if (headonly) {
- ret = onig_match(RREGEXP(regex)->ptr, (UChar* )CURPTR(p),
- (UChar* )(CURPTR(p) + S_RESTLEN(p)),
- (UChar* )CURPTR(p), &(p->regs), ONIG_OPTION_NONE);
+ ret = re_match(RREGEXP(regex)->ptr,
+ CURPTR(p), S_RESTLEN(p),
+ 0,
+ &(p->regs));
}
else {
- ret = onig_search(RREGEXP(regex)->ptr,
- (UChar* )CURPTR(p), (UChar* )(CURPTR(p) + S_RESTLEN(p)),
- (UChar* )CURPTR(p), (UChar* )(CURPTR(p) + S_RESTLEN(p)),
- &(p->regs), ONIG_OPTION_NONE);
+ ret = re_search(RREGEXP(regex)->ptr,
+ CURPTR(p), S_RESTLEN(p),
+ 0,
+ S_RESTLEN(p),
+ &(p->regs));
}
+ rb_kcode_reset_option();
if (ret == -2) rb_raise(ScanError, "regexp buffer overflow");
if (ret < 0) {
@@ -533,6 +536,7 @@ strscan_scan_full(VALUE self, VALUE re, VALUE s, VALUE f)
return strscan_do_scan(self, re, RTEST(s), RTEST(f), 1);
}
+
/*
* call-seq: scan_until(pattern)
*
@@ -626,18 +630,26 @@ strscan_search_full(VALUE self, VALUE re, VALUE s, VALUE f)
return strscan_do_scan(self, re, RTEST(s), RTEST(f), 0);
}
+/* DANGEROUS; need to synchronize with regex.c */
static void
adjust_registers_to_matched(struct strscanner *p)
{
- onig_region_clear(&(p->regs));
- onig_region_set(&(p->regs), 0, 0, p->curr - p->prev);
+ if (p->regs.allocated == 0) {
+ p->regs.beg = ALLOC_N(int, RE_NREGS);
+ p->regs.end = ALLOC_N(int, RE_NREGS);
+ p->regs.allocated = RE_NREGS;
+ }
+ p->regs.num_regs = 1;
+ p->regs.beg[0] = 0;
+ p->regs.end[0] = p->curr - p->prev;
}
/*
* Scans one character and returns it.
- * This method is multibyte character sensitive.
+ * This method is multi-byte character sensitive.
+ * See also #get_byte.
*
- * s = StringScanner.new("ab")
+ * s = StringScanner.new('ab')
* s.getch # => "a"
* s.getch # => "b"
* s.getch # => nil
@@ -657,7 +669,6 @@ strscan_getch(VALUE self)
CLEAR_MATCH_STATUS(p);
if (EOS_P(p))
return Qnil;
-
len = mbclen(*CURPTR(p));
if (p->curr + len > S_LEN(p)) {
len = S_LEN(p) - p->curr;
@@ -672,15 +683,14 @@ strscan_getch(VALUE self)
/*
* Scans one byte and returns it.
- * This method is not multibyte character sensitive.
- * See also: #getch.
+ * This method is NOT multi-byte character sensitive.
+ * See also #getch.
*
* s = StringScanner.new('ab')
* s.get_byte # => "a"
* s.get_byte # => "b"
* s.get_byte # => nil
*
- * $KCODE = 'EUC'
* s = StringScanner.new("\244\242")
* s.get_byte # => "\244"
* s.get_byte # => "\242"
@@ -693,9 +703,9 @@ strscan_get_byte(VALUE self)
GET_SCANNER(self, p);
CLEAR_MATCH_STATUS(p);
- if (EOS_P(p))
+ if (EOS_P(p)) {
return Qnil;
-
+ }
p->prev = p->curr;
p->curr++;
MATCHED(p);
@@ -733,13 +743,13 @@ strscan_peek(VALUE self, VALUE vlen)
long len;
GET_SCANNER(self, p);
-
len = NUM2LONG(vlen);
- if (EOS_P(p))
+ if (EOS_P(p)) {
return infect(rb_str_new("", 0), p);
-
- if (p->curr + len > S_LEN(p))
+ }
+ if (p->curr + len > S_LEN(p)) {
len = S_LEN(p) - p->curr;
+ }
return extract_beg_len(p, p->curr, len);
}
@@ -763,7 +773,7 @@ strscan_peep(VALUE self, VALUE vlen)
* s.unscan
* s.scan(/../) # => "te"
* s.scan(/\d/) # => nil
- * s.unscan # ScanError: unscan failed: previous match record not exist
+ * s.unscan # ScanError: unscan failed: previous match had failed
*/
static VALUE
strscan_unscan(VALUE self)
@@ -771,8 +781,9 @@ strscan_unscan(VALUE self)
struct strscanner *p;
GET_SCANNER(self, p);
- if (! MATCHED_P(p))
- rb_raise(ScanError, "unscan failed: previous match record not exist");
+ if (! MATCHED_P(p)) {
+ rb_raise(ScanError, "unscan failed: previous match had failed");
+ }
p->curr = p->prev;
CLEAR_MATCH_STATUS(p);
return self;
@@ -880,6 +891,7 @@ strscan_matched(VALUE self)
GET_SCANNER(self, p);
if (! MATCHED_P(p)) return Qnil;
+
return extract_range(p, p->prev + p->regs.beg[0],
p->prev + p->regs.end[0]);
}
@@ -901,6 +913,7 @@ strscan_matched_size(VALUE self)
GET_SCANNER(self, p);
if (! MATCHED_P(p)) return Qnil;
+
return INT2NUM(p->regs.end[0] - p->regs.beg[0]);
}
@@ -965,6 +978,7 @@ strscan_pre_match(VALUE self)
GET_SCANNER(self, p);
if (! MATCHED_P(p)) return Qnil;
+
return extract_range(p, 0, p->prev + p->regs.beg[0]);
}
@@ -984,6 +998,7 @@ strscan_post_match(VALUE self)
GET_SCANNER(self, p);
if (! MATCHED_P(p)) return Qnil;
+
return extract_range(p, p->prev + p->regs.end[0], S_LEN(p));
}
@@ -1016,6 +1031,7 @@ strscan_rest_size(VALUE self)
if (EOS_P(p)) {
return INT2FIX(0);
}
+
i = S_LEN(p) - p->curr;
return INT2FIX(i);
}
@@ -1069,7 +1085,7 @@ strscan_inspect(VALUE self)
len = snprintf(buf, BUFSIZE, "#<%s %ld/%ld @ %s>",
rb_class2name(CLASS_OF(self)),
p->curr, S_LEN(p),
- RSTRING_PTR(b));
+ RSTRING(b)->ptr);
return infect(rb_str_new(buf, len), p);
}
a = inspect1(p);
@@ -1077,8 +1093,8 @@ strscan_inspect(VALUE self)
len = snprintf(buf, BUFSIZE, "#<%s %ld/%ld %s @ %s>",
rb_class2name(CLASS_OF(self)),
p->curr, S_LEN(p),
- RSTRING_PTR(a),
- RSTRING_PTR(b));
+ RSTRING(a)->ptr,
+ RSTRING(b)->ptr);
return infect(rb_str_new(buf, len), p);
}
@@ -1229,7 +1245,7 @@ inspect2(struct strscanner *p)
* There are aliases to several of the methods.
*/
void
-Init_strscan()
+Init_strscan(void)
{
ID id_scanerr = rb_intern("ScanError");
VALUE tmp;
diff --git a/ext/syck/.cvsignore b/ext/syck/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/syck/.cvsignore
+++ b/ext/syck/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/syck/emitter.c b/ext/syck/emitter.c
index d3704f867b..9c8ab8d49b 100644
--- a/ext/syck/emitter.c
+++ b/ext/syck/emitter.c
@@ -98,7 +98,7 @@ syck_base64dec( char *s, long len )
}
}
*end = '\0';
- /*RSTRING_LEN(buf) = ptr - RSTRING_PTR(buf);*/
+ /*RSTRING(buf)->len = ptr - RSTRING(buf)->ptr;*/
return ptr;
}
@@ -106,7 +106,7 @@ syck_base64dec( char *s, long len )
* Allocate an emitter
*/
SyckEmitter *
-syck_new_emitter(void)
+syck_new_emitter()
{
SyckEmitter *e;
e = S_ALLOC( SyckEmitter );
@@ -282,7 +282,7 @@ syck_emitter_clear( SyckEmitter *e )
* Raw write to the emitter buffer.
*/
void
-syck_emitter_write( SyckEmitter *e, const char *str, long len )
+syck_emitter_write( SyckEmitter *e, char *str, long len )
{
long at;
ASSERT( str != NULL )
@@ -438,7 +438,7 @@ end_emit:
* and the implicit tag which would be assigned to this node. If a tag is
* required, write the tag.
*/
-void syck_emit_tag( SyckEmitter *e, const char *tag, const char *ignore )
+void syck_emit_tag( SyckEmitter *e, char *tag, char *ignore )
{
SyckLevel *lvl;
if ( tag == NULL ) return;
@@ -457,7 +457,7 @@ void syck_emit_tag( SyckEmitter *e, const char *tag, const char *ignore )
int skip = 4 + strlen( YAML_DOMAIN ) + 1;
syck_emitter_write( e, tag + skip, taglen - skip );
} else {
- const char *subd = tag + 4;
+ char *subd = tag + 4;
while ( *subd != ':' && *subd != '\0' ) subd++;
if ( *subd == ':' ) {
if ( subd - tag > ( strlen( YAML_DOMAIN ) + 5 ) &&
@@ -786,8 +786,8 @@ syck_emitter_escape( SyckEmitter *e, char *src, long len )
else
{
syck_emitter_write( e, "x", 1 );
- syck_emitter_write( e, (const char *)hex_table + ((src[i] & 0xF0) >> 4), 1 );
- syck_emitter_write( e, (const char *)hex_table + (src[i] & 0x0F), 1 );
+ syck_emitter_write( e, (char *)hex_table + ((src[i] & 0xF0) >> 4), 1 );
+ syck_emitter_write( e, (char *)hex_table + (src[i] & 0x0F), 1 );
}
}
else
@@ -1221,7 +1221,7 @@ syck_emitter_mark_node( SyckEmitter *e, st_data_t n )
if ( ! st_lookup( e->anchors, (st_data_t)oid, (st_data_t *)&anchor_name ) )
{
int idx = 0;
- const char *anc = ( e->anchor_format == NULL ? DEFAULT_ANCHOR_FORMAT : e->anchor_format );
+ char *anc = ( e->anchor_format == NULL ? DEFAULT_ANCHOR_FORMAT : e->anchor_format );
/*
* Second time hitting this object, let's give it an anchor
diff --git a/ext/syck/handler.c b/ext/syck/handler.c
index b04c4e3c0e..56fe838fbd 100644
--- a/ext/syck/handler.c
+++ b/ext/syck/handler.c
@@ -155,7 +155,7 @@ syck_xprivate( char *type_id, int type_len )
}
char *
-syck_taguri( const char *domain, const char *type_id, int type_len )
+syck_taguri( char *domain, char *type_id, int type_len )
{
char *uri = S_ALLOC_N( char, strlen( domain ) + type_len + 14 );
uri[0] = '\0';
diff --git a/ext/syck/implicit.c b/ext/syck/implicit.c
index cfd5d7b3e6..d356faf7d9 100644
--- a/ext/syck/implicit.c
+++ b/ext/syck/implicit.c
@@ -1585,7 +1585,7 @@ yy201: ++YYCURSOR;
/* Remove ending fragment and compare types */
int
-syck_tagcmp( const char *tag1, const char *tag2 )
+syck_tagcmp( char *tag1, char *tag2 )
{
if ( tag1 == tag2 ) return 1;
if ( tag1 == NULL || tag2 == NULL ) return 0;
diff --git a/ext/syck/node.c b/ext/syck/node.c
index cbc2adb6c5..28fc78c077 100644
--- a/ext/syck/node.c
+++ b/ext/syck/node.c
@@ -100,13 +100,13 @@ syck_alloc_str()
}
SyckNode *
-syck_new_str( const char *str, enum scalar_style style )
+syck_new_str( char *str, enum scalar_style style )
{
return syck_new_str2( str, strlen( str ), style );
}
SyckNode *
-syck_new_str2( const char *str, long len, enum scalar_style style )
+syck_new_str2( char *str, long len, enum scalar_style style )
{
SyckNode *n;
diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c
index 371ef15599..6de3546308 100644
--- a/ext/syck/rubyext.c
+++ b/ext/syck/rubyext.c
@@ -49,8 +49,8 @@ typedef struct {
/*
* symbols and constants
*/
-static ID s_new, s_utc, s_at, s_to_f, s_to_i, s_read, s_binmode, s_call, s_cmp, s_transfer, s_update, s_dup, s_haskey, s_match, s_keys, s_unpack, s_tr_bang, s_default_set, s_tag_read_class, s_tag_subclasses, s_resolver, s_push, s_emitter, s_level, s_detect_implicit, s_node_import, s_out, s_input, s_intern, s_transform, s_yaml_new, s_yaml_initialize, s_node_export, s_to_yaml, s_write, s_set_resolver, s_each;
-static ID s_tags, s_kind, s_name, s_options, s_type_id, s_type_id_set, s_style, s_style_set, s_value, s_value_set;
+static ID s_new, s_utc, s_at, s_to_f, s_to_i, s_read, s_binmode, s_call, s_cmp, s_transfer, s_update, s_dup, s_haskey, s_match, s_keys, s_unpack, s_tr_bang, s_default_set, s_tag_read_class, s_tag_subclasses, s_resolver, s_push, s_emitter, s_level, s_detect_implicit, s_node_import, s_out, s_input, s_intern, s_transform, s_yaml_new, s_yaml_initialize, s_node_export, s_to_yaml, s_write, s_set_resolver;
+static ID s_tags, s_domain, s_kind, s_name, s_options, s_type_id, s_type_id_set, s_style, s_style_set, s_value, s_value_set;
static VALUE sym_model, sym_generic, sym_input, sym_bytecode;
static VALUE sym_scalar, sym_seq, sym_map;
static VALUE sym_1quote, sym_2quote, sym_fold, sym_literal, sym_plain, sym_inline;
@@ -97,7 +97,8 @@ struct emitter_xtra {
* Convert YAML to bytecode
*/
VALUE
-rb_syck_compile(VALUE self, VALUE port)
+rb_syck_compile(self, port)
+ VALUE self, port;
{
SYMID oid;
int taint;
@@ -149,8 +150,8 @@ rb_syck_io_str_read( char *buf, SyckIoStr *str, long max_size, long skip )
if (!NIL_P(str2))
{
StringValue(str2);
- len = RSTRING_LEN(str2);
- memcpy( buf + skip, RSTRING_PTR(str2), len );
+ len = RSTRING(str2)->len;
+ memcpy( buf + skip, RSTRING(str2)->ptr, len );
}
}
len += skip;
@@ -163,14 +164,16 @@ rb_syck_io_str_read( char *buf, SyckIoStr *str, long max_size, long skip )
* (returns tainted? boolean)
*/
int
-syck_parser_assign_io(SyckParser *parser, VALUE *pport)
+syck_parser_assign_io(parser, pport)
+ SyckParser *parser;
+ VALUE *pport;
{
int taint = Qtrue;
VALUE tmp, port = *pport;
if (!NIL_P(tmp = rb_check_string_type(port))) {
taint = OBJ_TAINTED(port); /* original taintedness */
port = tmp;
- syck_parser_str( parser, RSTRING_PTR(port), RSTRING_LEN(port), NULL );
+ syck_parser_str( parser, RSTRING(port)->ptr, RSTRING(port)->len, NULL );
}
else if (rb_respond_to(port, s_read)) {
if (rb_respond_to(port, s_binmode)) {
@@ -189,7 +192,8 @@ syck_parser_assign_io(SyckParser *parser, VALUE *pport)
* Get value in hash by key, forcing an empty hash if nil.
*/
VALUE
-syck_get_hash_aref(VALUE hsh, VALUE key)
+syck_get_hash_aref(hsh, key)
+ VALUE hsh, key;
{
VALUE val = rb_hash_aref( hsh, key );
if ( NIL_P( val ) )
@@ -204,7 +208,9 @@ syck_get_hash_aref(VALUE hsh, VALUE key)
* creating timestamps
*/
SYMID
-rb_syck_mktime(char *str, long len)
+rb_syck_mktime(str, len)
+ char *str;
+ long len;
{
VALUE time;
char *ptr = str;
@@ -309,7 +315,8 @@ rb_syck_mktime(char *str, long len)
* (see http://www.yaml.org/type/merge/)
*/
VALUE
-syck_merge_i(VALUE entry, VALUE hsh )
+syck_merge_i( entry, hsh )
+ VALUE entry, hsh;
{
VALUE tmp;
if ( !NIL_P(tmp = rb_check_convert_type(entry, T_HASH, "Hash", "to_hash")) )
@@ -324,7 +331,9 @@ syck_merge_i(VALUE entry, VALUE hsh )
* default handler for ruby.yaml.org types
*/
int
-yaml_org_handler( SyckNode *n, VALUE *ref )
+yaml_org_handler( n, ref )
+ SyckNode *n;
+ VALUE *ref;
{
char *type_id = n->type_id;
int transferred = 0;
@@ -562,7 +571,7 @@ yaml_org_handler( SyckNode *n, VALUE *ref )
VALUE dup = rb_funcall( tmph, s_dup, 0 );
tmp = rb_ary_reverse( tmp );
rb_ary_push( tmp, obj );
- rb_block_call( tmp, s_each, 0, 0, syck_merge_i, dup );
+ rb_iterate( rb_each, tmp, syck_merge_i, dup );
obj = dup;
skip_aset = 1;
}
@@ -593,7 +602,9 @@ static void syck_node_mark( SyckNode *n );
* - Converts data into native Ruby types
*/
SYMID
-rb_syck_load_handler(SyckParser *p, SyckNode *n)
+rb_syck_load_handler(p, n)
+ SyckParser *p;
+ SyckNode *n;
{
VALUE obj = Qnil;
struct parser_xtra *bonus = (struct parser_xtra *)p->bonus;
@@ -629,7 +640,9 @@ rb_syck_load_handler(SyckParser *p, SyckNode *n)
* friendly errors.
*/
void
-rb_syck_err_handler(SyckParser *p, char *msg)
+rb_syck_err_handler(p, msg)
+ SyckParser *p;
+ char *msg;
{
char *endl = p->cursor;
@@ -648,7 +661,9 @@ rb_syck_err_handler(SyckParser *p, char *msg)
* provide bad anchor object to the parser.
*/
SyckNode *
-rb_syck_bad_anchor_handler(SyckParser *p, char *a)
+rb_syck_bad_anchor_handler(p, a)
+ SyckParser *p;
+ char *a;
{
VALUE anchor_name = rb_str_new2( a );
SyckNode *badanc = syck_new_map( rb_str_new2( "name" ), anchor_name );
@@ -660,7 +675,8 @@ rb_syck_bad_anchor_handler(SyckParser *p, char *a)
* data loaded based on the model requested.
*/
void
-syck_set_model(VALUE p, VALUE input, VALUE model)
+syck_set_model( p, input, model )
+ VALUE p, input, model;
{
SyckParser *parser;
Data_Get_Struct(p, SyckParser, parser);
@@ -700,7 +716,8 @@ syck_st_mark_nodes( char *key, SyckNode *n, char *arg )
* mark parser nodes
*/
static void
-syck_mark_parser(SyckParser *parser)
+syck_mark_parser(parser)
+ SyckParser *parser;
{
struct parser_xtra *bonus = (struct parser_xtra *)parser->bonus;
rb_gc_mark_maybe(parser->root);
@@ -723,7 +740,8 @@ syck_mark_parser(SyckParser *parser)
* Free the parser and any bonus attachment.
*/
void
-rb_syck_free_parser(SyckParser *p)
+rb_syck_free_parser(p)
+ SyckParser *p;
{
S_FREE( p->bonus );
syck_free_parser(p);
@@ -734,7 +752,8 @@ rb_syck_free_parser(SyckParser *p)
*/
VALUE syck_parser_s_alloc _((VALUE));
VALUE
-syck_parser_s_alloc(VALUE class)
+syck_parser_s_alloc(class)
+ VALUE class;
{
VALUE pobj;
SyckParser *parser = syck_new_parser();
@@ -753,7 +772,10 @@ syck_parser_s_alloc(VALUE class)
* YAML::Syck::Parser.initialize( resolver, options )
*/
static VALUE
-syck_parser_initialize(int argc, VALUE *argv, VALUE self)
+syck_parser_initialize(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE options;
if (rb_scan_args(argc, argv, "01", &options) == 0)
@@ -773,7 +795,8 @@ syck_parser_initialize(int argc, VALUE *argv, VALUE self)
* YAML::Syck::Parser.bufsize = Integer
*/
static VALUE
-syck_parser_bufsize_set(VALUE self, VALUE size)
+syck_parser_bufsize_set( self, size )
+ VALUE self, size;
{
SyckParser *parser;
@@ -789,7 +812,8 @@ syck_parser_bufsize_set(VALUE self, VALUE size)
* YAML::Syck::Parser.bufsize => Integer
*/
static VALUE
-syck_parser_bufsize_get(VALUE self)
+syck_parser_bufsize_get( self )
+ VALUE self;
{
SyckParser *parser;
@@ -801,7 +825,10 @@ syck_parser_bufsize_get(VALUE self)
* YAML::Syck::Parser.load( IO or String )
*/
VALUE
-syck_parser_load(int argc, VALUE *argv, VALUE self)
+syck_parser_load(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE port, proc, model, input;
SyckParser *parser;
@@ -828,7 +855,10 @@ syck_parser_load(int argc, VALUE *argv, VALUE self)
* YAML::Syck::Parser.load_documents( IO or String ) { |doc| }
*/
VALUE
-syck_parser_load_documents(int argc, VALUE *argv, VALUE self)
+syck_parser_load_documents(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE port, proc, v, input, model;
SyckParser *parser;
@@ -869,7 +899,8 @@ syck_parser_load_documents(int argc, VALUE *argv, VALUE self)
* YAML::Syck::Parser#set_resolver
*/
VALUE
-syck_parser_set_resolver(VALUE self, VALUE resolver)
+syck_parser_set_resolver( self, resolver )
+ VALUE self, resolver;
{
rb_ivar_set( self, s_resolver, resolver );
return self;
@@ -879,7 +910,8 @@ syck_parser_set_resolver(VALUE self, VALUE resolver)
* YAML::Syck::Resolver.initialize
*/
static VALUE
-syck_resolver_initialize(VALUE self)
+syck_resolver_initialize( self )
+ VALUE self;
{
VALUE tags = rb_hash_new();
rb_ivar_set(self, s_tags, rb_hash_new());
@@ -890,7 +922,8 @@ syck_resolver_initialize(VALUE self)
* YAML::Syck::Resolver#add_type
*/
VALUE
-syck_resolver_add_type(VALUE self, VALUE taguri, VALUE cls)
+syck_resolver_add_type( self, taguri, cls )
+ VALUE self, taguri, cls;
{
VALUE tags = rb_attr_get(self, s_tags);
rb_hash_aset( tags, taguri, cls );
@@ -901,7 +934,8 @@ syck_resolver_add_type(VALUE self, VALUE taguri, VALUE cls)
* YAML::Syck::Resolver#use_types_at
*/
VALUE
-syck_resolver_use_types_at(VALUE self, VALUE hsh)
+syck_resolver_use_types_at( self, hsh )
+ VALUE self, hsh;
{
rb_ivar_set( self, s_tags, hsh );
return Qnil;
@@ -911,7 +945,8 @@ syck_resolver_use_types_at(VALUE self, VALUE hsh)
* YAML::Syck::Resolver#detect_implicit
*/
VALUE
-syck_resolver_detect_implicit(VALUE self, VALUE val)
+syck_resolver_detect_implicit( self, val )
+ VALUE self, val;
{
char *type_id;
return rb_str_new2( "" );
@@ -921,7 +956,8 @@ syck_resolver_detect_implicit(VALUE self, VALUE val)
* YAML::Syck::Resolver#node_import
*/
VALUE
-syck_resolver_node_import(VALUE self, VALUE node)
+syck_resolver_node_import( self, node )
+ VALUE self, node;
{
SyckNode *n;
VALUE obj;
@@ -970,7 +1006,7 @@ syck_resolver_node_import(VALUE self, VALUE node)
VALUE dup = rb_funcall( end, s_dup, 0 );
v = rb_ary_reverse( v );
rb_ary_push( v, obj );
- rb_block_call( v, s_each, 0, 0, syck_merge_i, dup );
+ rb_iterate( rb_each, v, syck_merge_i, dup );
obj = dup;
skip_aset = 1;
}
@@ -1001,15 +1037,16 @@ syck_resolver_node_import(VALUE self, VALUE node)
* Set instance variables
*/
VALUE
-syck_set_ivars(VALUE vars, VALUE obj)
+syck_set_ivars( vars, obj )
+ VALUE vars, obj;
{
VALUE ivname = rb_ary_entry( vars, 0 );
char *ivn;
StringValue( ivname );
- ivn = S_ALLOCA_N( char, RSTRING_LEN(ivname) + 2 );
+ ivn = S_ALLOCA_N( char, RSTRING(ivname)->len + 2 );
ivn[0] = '@';
ivn[1] = '\0';
- strncat( ivn, RSTRING_PTR(ivname), RSTRING_LEN(ivname) );
+ strncat( ivn, RSTRING(ivname)->ptr, RSTRING(ivname)->len );
rb_iv_set( obj, ivn, rb_ary_entry( vars, 1 ) );
return Qnil;
}
@@ -1018,12 +1055,13 @@ syck_set_ivars(VALUE vars, VALUE obj)
* YAML::Syck::Resolver#const_find
*/
VALUE
-syck_const_find(VALUE const_name)
+syck_const_find( const_name )
+ VALUE const_name;
{
VALUE tclass = rb_cObject;
VALUE tparts = rb_str_split( const_name, "::" );
int i = 0;
- for ( i = 0; i < RARRAY_LEN(tparts); i++ ) {
+ for ( i = 0; i < RARRAY(tparts)->len; i++ ) {
VALUE tpart = rb_to_id( rb_ary_entry( tparts, i ) );
if ( !rb_const_defined( tclass, tpart ) ) return Qnil;
tclass = rb_const_get( tclass, tpart );
@@ -1035,14 +1073,15 @@ syck_const_find(VALUE const_name)
* YAML::Syck::Resolver#transfer
*/
VALUE
-syck_resolver_transfer(VALUE self, VALUE type, VALUE val)
+syck_resolver_transfer( self, type, val )
+ VALUE self, type, val;
{
- if (NIL_P(type) || RSTRING_LEN(StringValue(type)) == 0)
+ if (NIL_P(type) || RSTRING(StringValue(type))->len == 0)
{
type = rb_funcall( self, s_detect_implicit, 1, val );
}
- if ( ! (NIL_P(type) || RSTRING_LEN(StringValue(type)) == 0) )
+ if ( ! (NIL_P(type) || RSTRING(StringValue(type))->len == 0) )
{
VALUE str_xprivate = rb_str_new2( "x-private" );
VALUE colon = rb_str_new2( ":" );
@@ -1059,7 +1098,7 @@ syck_resolver_transfer(VALUE self, VALUE type, VALUE val)
VALUE subclass_parts = rb_ary_new();
VALUE parts = rb_str_split( type, ":" );
- while ( RARRAY_LEN(parts) > 1 )
+ while ( RARRAY(parts)->len > 1 )
{
VALUE partial;
rb_ary_unshift( subclass_parts, rb_ary_pop( parts ) );
@@ -1077,7 +1116,7 @@ syck_resolver_transfer(VALUE self, VALUE type, VALUE val)
if ( ! NIL_P( target_class ) )
{
subclass = target_class;
- if ( RARRAY_LEN(subclass_parts) > 0 && rb_respond_to( target_class, s_tag_subclasses ) &&
+ if ( RARRAY(subclass_parts)->len > 0 && rb_respond_to( target_class, s_tag_subclasses ) &&
RTEST( rb_funcall( target_class, s_tag_subclasses, 0 ) ) )
{
VALUE subclass_v;
@@ -1136,7 +1175,7 @@ syck_resolver_transfer(VALUE self, VALUE type, VALUE val)
}
else if ( !NIL_P( obj ) && rb_obj_is_instance_of( val, rb_cHash ) )
{
- rb_block_call( val, s_each, 0, 0, syck_set_ivars, obj );
+ rb_iterate( rb_each, val, syck_set_ivars, obj );
}
}
else
@@ -1166,13 +1205,14 @@ syck_resolver_transfer(VALUE self, VALUE type, VALUE val)
* YAML::Syck::Resolver#tagurize
*/
VALUE
-syck_resolver_tagurize(VALUE self, VALUE val)
+syck_resolver_tagurize( self, val )
+ VALUE self, val;
{
VALUE tmp = rb_check_string_type(val);
if ( !NIL_P(tmp) )
{
- char *taguri = syck_type_id_to_uri( RSTRING_PTR(tmp) );
+ char *taguri = syck_type_id_to_uri( RSTRING(tmp)->ptr );
val = rb_str_new2( taguri );
S_FREE( taguri );
}
@@ -1184,7 +1224,8 @@ syck_resolver_tagurize(VALUE self, VALUE val)
* YAML::Syck::DefaultResolver#detect_implicit
*/
VALUE
-syck_defaultresolver_detect_implicit(VALUE self, VALUE val)
+syck_defaultresolver_detect_implicit( self, val )
+ VALUE self, val;
{
char *type_id;
VALUE tmp = rb_check_string_type(val);
@@ -1192,7 +1233,7 @@ syck_defaultresolver_detect_implicit(VALUE self, VALUE val)
if ( !NIL_P(tmp) )
{
val = tmp;
- type_id = syck_match_implicit( RSTRING_PTR(val), RSTRING_LEN(val) );
+ type_id = syck_match_implicit( RSTRING(val)->ptr, RSTRING(val)->len );
return rb_str_new2( type_id );
}
@@ -1203,7 +1244,8 @@ syck_defaultresolver_detect_implicit(VALUE self, VALUE val)
* YAML::Syck::DefaultResolver#node_import
*/
VALUE
-syck_defaultresolver_node_import(VALUE self, VALUE node)
+syck_defaultresolver_node_import( self, node )
+ VALUE self, node;
{
SyckNode *n;
VALUE obj;
@@ -1219,7 +1261,8 @@ syck_defaultresolver_node_import(VALUE self, VALUE node)
* YAML::Syck::GenericResolver#node_import
*/
VALUE
-syck_genericresolver_node_import(VALUE self, VALUE node)
+syck_genericresolver_node_import( self, node )
+ VALUE self, node;
{
SyckNode *n;
int i = 0;
@@ -1296,7 +1339,8 @@ syck_genericresolver_node_import(VALUE self, VALUE node)
* YAML::Syck::BadAlias.initialize
*/
VALUE
-syck_badalias_initialize(VALUE self, VALUE val)
+syck_badalias_initialize( self, val )
+ VALUE self, val;
{
rb_iv_set( self, "@name", val );
return self;
@@ -1306,7 +1350,8 @@ syck_badalias_initialize(VALUE self, VALUE val)
* YAML::Syck::BadAlias.<=>
*/
VALUE
-syck_badalias_cmp(VALUE alias1, VALUE alias2)
+syck_badalias_cmp( alias1, alias2 )
+ VALUE alias1, alias2;
{
VALUE str1 = rb_ivar_get( alias1, s_name );
VALUE str2 = rb_ivar_get( alias2, s_name );
@@ -1318,7 +1363,8 @@ syck_badalias_cmp(VALUE alias1, VALUE alias2)
* YAML::DomainType.initialize
*/
VALUE
-syck_domaintype_initialize(VALUE self, VALUE domain, VALUE type_id, VALUE val)
+syck_domaintype_initialize( self, domain, type_id, val )
+ VALUE self, domain, type_id, val;
{
rb_iv_set( self, "@domain", domain );
rb_iv_set( self, "@type_id", type_id );
@@ -1330,7 +1376,8 @@ syck_domaintype_initialize(VALUE self, VALUE domain, VALUE type_id, VALUE val)
* YAML::Object.initialize
*/
VALUE
-syck_yobject_initialize(VALUE self, VALUE klass, VALUE ivars)
+syck_yobject_initialize( self, klass, ivars )
+ VALUE self, klass, ivars;
{
rb_iv_set( self, "@class", klass );
rb_iv_set( self, "@ivars", ivars );
@@ -1341,7 +1388,8 @@ syck_yobject_initialize(VALUE self, VALUE klass, VALUE ivars)
* YAML::PrivateType.initialize
*/
VALUE
-syck_privatetype_initialize(VALUE self, VALUE type_id, VALUE val)
+syck_privatetype_initialize( self, type_id, val )
+ VALUE self, type_id, val;
{
rb_iv_set( self, "@type_id", type_id );
rb_iv_set( self, "@value", val );
@@ -1352,7 +1400,8 @@ syck_privatetype_initialize(VALUE self, VALUE type_id, VALUE val)
* Mark node contents.
*/
static void
-syck_node_mark(SyckNode *n)
+syck_node_mark( n )
+ SyckNode *n;
{
int i;
rb_gc_mark_maybe( n->id );
@@ -1382,7 +1431,8 @@ syck_node_mark(SyckNode *n)
* YAML::Syck::Scalar.allocate
*/
VALUE
-syck_scalar_alloc(VALUE class)
+syck_scalar_alloc( class )
+ VALUE class;
{
SyckNode *node = syck_alloc_str();
VALUE obj = Data_Wrap_Struct( class, syck_node_mark, syck_free_node, node );
@@ -1394,7 +1444,8 @@ syck_scalar_alloc(VALUE class)
* YAML::Syck::Scalar.initialize
*/
VALUE
-syck_scalar_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
+syck_scalar_initialize( self, type_id, val, style )
+ VALUE self, type_id, val, style;
{
rb_iv_set( self, "@kind", sym_scalar );
rb_funcall( self, s_type_id_set, 1, type_id );
@@ -1407,7 +1458,8 @@ syck_scalar_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
* YAML::Syck::Scalar.style=
*/
VALUE
-syck_scalar_style_set(VALUE self, VALUE style)
+syck_scalar_style_set( self, style )
+ VALUE self, style;
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
@@ -1445,14 +1497,15 @@ syck_scalar_style_set(VALUE self, VALUE style)
* YAML::Syck::Scalar.value=
*/
VALUE
-syck_scalar_value_set(VALUE self, VALUE val)
+syck_scalar_value_set( self, val )
+ VALUE self, val;
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
StringValue( val );
- node->data.str->ptr = syck_strndup( RSTRING_PTR(val), RSTRING_LEN(val) );
- node->data.str->len = RSTRING_LEN(val);
+ node->data.str->ptr = syck_strndup( RSTRING(val)->ptr, RSTRING(val)->len );
+ node->data.str->len = RSTRING(val)->len;
node->data.str->style = scalar_none;
rb_iv_set( self, "@value", val );
@@ -1463,7 +1516,8 @@ syck_scalar_value_set(VALUE self, VALUE val)
* YAML::Syck::Seq.allocate
*/
VALUE
-syck_seq_alloc(VALUE class)
+syck_seq_alloc( class )
+ VALUE class;
{
SyckNode *node;
VALUE obj;
@@ -1477,7 +1531,8 @@ syck_seq_alloc(VALUE class)
* YAML::Syck::Seq.initialize
*/
VALUE
-syck_seq_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
+syck_seq_initialize( self, type_id, val, style )
+ VALUE self, type_id, val, style;
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
@@ -1493,7 +1548,8 @@ syck_seq_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
* YAML::Syck::Seq.value=
*/
VALUE
-syck_seq_value_set(VALUE self, VALUE val)
+syck_seq_value_set( self, val )
+ VALUE self, val;
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
@@ -1502,7 +1558,7 @@ syck_seq_value_set(VALUE self, VALUE val)
if ( !NIL_P( val ) ) {
int i;
syck_seq_empty( node );
- for ( i = 0; i < RARRAY_LEN( val ); i++ )
+ for ( i = 0; i < RARRAY( val )->len; i++ )
{
syck_seq_add( node, rb_ary_entry(val, i) );
}
@@ -1516,7 +1572,8 @@ syck_seq_value_set(VALUE self, VALUE val)
* YAML::Syck::Seq.add
*/
VALUE
-syck_seq_add_m(VALUE self, VALUE val)
+syck_seq_add_m( self, val )
+ VALUE self, val;
{
SyckNode *node;
VALUE emitter = rb_ivar_get( self, s_emitter );
@@ -1535,7 +1592,8 @@ syck_seq_add_m(VALUE self, VALUE val)
* YAML::Syck::Seq.style=
*/
VALUE
-syck_seq_style_set(VALUE self, VALUE style)
+syck_seq_style_set( self, style )
+ VALUE self, style;
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
@@ -1557,7 +1615,8 @@ syck_seq_style_set(VALUE self, VALUE style)
* YAML::Syck::Map.allocate
*/
VALUE
-syck_map_alloc(VALUE class)
+syck_map_alloc( class )
+ VALUE class;
{
SyckNode *node;
VALUE obj;
@@ -1571,7 +1630,8 @@ syck_map_alloc(VALUE class)
* YAML::Syck::Map.initialize
*/
VALUE
-syck_map_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
+syck_map_initialize( self, type_id, val, style )
+ VALUE self, type_id, val, style;
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
@@ -1587,7 +1647,7 @@ syck_map_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
}
keys = rb_funcall( hsh, s_keys, 0 );
- for ( i = 0; i < RARRAY_LEN(keys); i++ )
+ for ( i = 0; i < RARRAY(keys)->len; i++ )
{
VALUE key = rb_ary_entry(keys, i);
syck_map_add( node, key, rb_hash_aref(hsh, key) );
@@ -1605,7 +1665,8 @@ syck_map_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
* YAML::Syck::Map.value=
*/
VALUE
-syck_map_value_set(VALUE self, VALUE val)
+syck_map_value_set( self, val )
+ VALUE self, val;
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
@@ -1622,7 +1683,7 @@ syck_map_value_set(VALUE self, VALUE val)
syck_map_empty( node );
keys = rb_funcall( hsh, s_keys, 0 );
- for ( i = 0; i < RARRAY_LEN(keys); i++ )
+ for ( i = 0; i < RARRAY(keys)->len; i++ )
{
VALUE key = rb_ary_entry(keys, i);
syck_map_add( node, key, rb_hash_aref(hsh, key) );
@@ -1637,7 +1698,8 @@ syck_map_value_set(VALUE self, VALUE val)
* YAML::Syck::Map.add
*/
VALUE
-syck_map_add_m(VALUE self, VALUE key, VALUE val)
+syck_map_add_m( self, key, val )
+ VALUE self, key, val;
{
SyckNode *node;
VALUE emitter = rb_ivar_get( self, s_emitter );
@@ -1657,7 +1719,8 @@ syck_map_add_m(VALUE self, VALUE key, VALUE val)
* YAML::Syck::Map.style=
*/
VALUE
-syck_map_style_set(VALUE self, VALUE style)
+syck_map_style_set( self, style )
+ VALUE self, style;
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
@@ -1679,7 +1742,8 @@ syck_map_style_set(VALUE self, VALUE style)
* Cloning method for all node types
*/
VALUE
-syck_node_init_copy(VALUE copy, VALUE orig)
+syck_node_init_copy( copy, orig )
+ VALUE copy, orig;
{
SyckNode *copy_n;
SyckNode *orig_n;
@@ -1702,7 +1766,8 @@ syck_node_init_copy(VALUE copy, VALUE orig)
* YAML::Syck::Node#type_id=
*/
VALUE
-syck_node_type_id_set(VALUE self, VALUE type_id)
+syck_node_type_id_set( self, type_id )
+ VALUE self, type_id;
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
@@ -1711,7 +1776,7 @@ syck_node_type_id_set(VALUE self, VALUE type_id)
if ( !NIL_P( type_id ) ) {
StringValue( type_id );
- node->type_id = syck_strndup( RSTRING_PTR(type_id), RSTRING_LEN(type_id) );
+ node->type_id = syck_strndup( RSTRING(type_id)->ptr, RSTRING(type_id)->len );
}
rb_iv_set( self, "@type_id", type_id );
@@ -1722,7 +1787,8 @@ syck_node_type_id_set(VALUE self, VALUE type_id)
* YAML::Syck::Node.transform
*/
VALUE
-syck_node_transform(VALUE self)
+syck_node_transform( self )
+ VALUE self;
{
VALUE t;
SyckNode *n;
@@ -1778,7 +1844,9 @@ syck_node_transform(VALUE self)
* No one could possibly object.
*/
void
-rb_syck_emitter_handler(SyckEmitter *e, st_data_t data)
+rb_syck_emitter_handler(e, data)
+ SyckEmitter *e;
+ st_data_t data;
{
SyckNode *n;
Data_Get_Struct((VALUE)data, SyckNode, n);
@@ -1822,7 +1890,10 @@ rb_syck_emitter_handler(SyckEmitter *e, st_data_t data)
* Handle output from the emitter
*/
void
-rb_syck_output_handler(SyckEmitter * emitter, char *str, long len)
+rb_syck_output_handler( emitter, str, len )
+ SyckEmitter *emitter;
+ char *str;
+ long len;
{
struct emitter_xtra *bonus = (struct emitter_xtra *)emitter->bonus;
VALUE dest = bonus->port;
@@ -1838,7 +1909,8 @@ rb_syck_output_handler(SyckEmitter * emitter, char *str, long len)
* symbol table.
*/
void
-syck_out_mark(VALUE emitter, VALUE node)
+syck_out_mark( emitter, node )
+ VALUE emitter, node;
{
SyckEmitter *emitterPtr;
struct emitter_xtra *bonus;
@@ -1855,7 +1927,8 @@ syck_out_mark(VALUE emitter, VALUE node)
* Mark emitter values.
*/
static void
-syck_mark_emitter(SyckEmitter *emitter)
+syck_mark_emitter(emitter)
+ SyckEmitter *emitter;
{
struct emitter_xtra *bonus = (struct emitter_xtra *)emitter->bonus;
rb_gc_mark( bonus->oid );
@@ -1867,7 +1940,8 @@ syck_mark_emitter(SyckEmitter *emitter)
* Free the emitter and any bonus attachment.
*/
void
-rb_syck_free_emitter(SyckEmitter *e)
+rb_syck_free_emitter(e)
+ SyckEmitter *e;
{
S_FREE( e->bonus );
syck_free_emitter(e);
@@ -1878,7 +1952,8 @@ rb_syck_free_emitter(SyckEmitter *e)
*/
VALUE syck_emitter_s_alloc _((VALUE));
VALUE
-syck_emitter_s_alloc(VALUE class)
+syck_emitter_s_alloc(class)
+ VALUE class;
{
VALUE pobj;
SyckEmitter *emitter = syck_new_emitter();
@@ -1898,7 +1973,10 @@ syck_emitter_s_alloc(VALUE class)
* YAML::Syck::Emitter.reset( options )
*/
VALUE
-syck_emitter_reset(int argc, VALUE *argv, VALUE self)
+syck_emitter_reset( argc, argv, self )
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE options, tmp;
SyckEmitter *emitter;
@@ -1940,7 +2018,10 @@ syck_emitter_reset(int argc, VALUE *argv, VALUE self)
* YAML::Syck::Emitter.emit( object_id ) { |out| ... }
*/
VALUE
-syck_emitter_emit(int argc, VALUE *argv, VALUE self)
+syck_emitter_emit( argc, argv, self )
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE oid, proc;
char *anchor_name;
@@ -1981,7 +2062,8 @@ syck_emitter_emit(int argc, VALUE *argv, VALUE self)
* YAML::Syck::Emitter#node_export
*/
VALUE
-syck_emitter_node_export(VALUE self, VALUE node)
+syck_emitter_node_export( self, node )
+ VALUE self, node;
{
return rb_funcall( node, s_to_yaml, 1, self );
}
@@ -1990,7 +2072,8 @@ syck_emitter_node_export(VALUE self, VALUE node)
* YAML::Syck::Emitter#set_resolver
*/
VALUE
-syck_emitter_set_resolver(VALUE self, VALUE resolver)
+syck_emitter_set_resolver( self, resolver )
+ VALUE self, resolver;
{
rb_ivar_set( self, s_resolver, resolver );
return self;
@@ -2000,7 +2083,8 @@ syck_emitter_set_resolver(VALUE self, VALUE resolver)
* YAML::Syck::Out::initialize
*/
VALUE
-syck_out_initialize(VALUE self, VALUE emitter)
+syck_out_initialize( self, emitter )
+ VALUE self, emitter;
{
rb_ivar_set( self, s_emitter, emitter );
return self;
@@ -2010,7 +2094,10 @@ syck_out_initialize(VALUE self, VALUE emitter)
* YAML::Syck::Out::map
*/
VALUE
-syck_out_map(int argc, VALUE *argv, VALUE self)
+syck_out_map( argc, argv, self )
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE type_id, style, map;
if (rb_scan_args(argc, argv, "11", &type_id, &style) == 1) {
@@ -2026,7 +2113,10 @@ syck_out_map(int argc, VALUE *argv, VALUE self)
* YAML::Syck::Out::seq
*/
VALUE
-syck_out_seq(int argc, VALUE *argv, VALUE self)
+syck_out_seq( argc, argv, self )
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE type_id, style, seq;
if (rb_scan_args(argc, argv, "11", &type_id, &style) == 1) {
@@ -2044,7 +2134,10 @@ syck_out_scalar( self, type_id, str, style )
VALUE self, type_id, str, style;
*/
VALUE
-syck_out_scalar(int argc, VALUE *argv, VALUE self)
+syck_out_scalar( argc, argv, self )
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE type_id, str, style, scalar;
if (rb_scan_args(argc, argv, "21", &type_id, &str, &style) == 2) {
@@ -2101,7 +2194,6 @@ Init_syck()
s_transform = rb_intern( "transform" );
s_yaml_new = rb_intern("yaml_new");
s_yaml_initialize = rb_intern("yaml_initialize");
- s_each = rb_intern("each");
s_tags = rb_intern("@tags");
s_name = rb_intern("@name");
@@ -2188,7 +2280,6 @@ 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.c b/ext/syck/syck.c
index daf531632f..a83c8813c1 100644
--- a/ext/syck/syck.c
+++ b/ext/syck/syck.c
@@ -32,7 +32,7 @@ syck_assert( char *file_name, unsigned line_num )
* Allocates and copies a string
*/
char *
-syck_strndup( const char *buf, long len )
+syck_strndup( char *buf, long len )
{
char *new = S_ALLOC_N( char, len + 1 );
S_MEMZERO( new, char, len + 1 );
diff --git a/ext/syck/syck.h b/ext/syck/syck.h
index 083364452a..e7d07e9c0d 100644
--- a/ext/syck/syck.h
+++ b/ext/syck/syck.h
@@ -17,6 +17,7 @@
#define YAML_DOMAIN "yaml.org,2002"
#include <stdio.h>
+#include <stdlib.h>
#include <ctype.h>
#include "st.h"
@@ -346,8 +347,8 @@ void syck_hdlr_remove_anchor( SyckParser *, char * );
SyckNode *syck_hdlr_get_anchor( SyckParser *, char * );
void syck_add_transfer( char *, SyckNode *, int );
char *syck_xprivate( char *, int );
-char *syck_taguri( const char *, const char *, int );
-int syck_tagcmp( const char *, const char * );
+char *syck_taguri( char *, char *, int );
+int syck_tagcmp( char *, char * );
int syck_add_sym( SyckParser *, char * );
int syck_lookup_sym( SyckParser *, SYMID, char ** );
int syck_try_implicit( SyckNode * );
@@ -358,19 +359,19 @@ char *syck_match_implicit( char *, size_t );
/*
* API prototypes
*/
-char *syck_strndup( const char *, long );
+char *syck_strndup( char *, long );
long syck_io_file_read( char *, SyckIoFile *, long, long );
long syck_io_str_read( char *, SyckIoStr *, long, long );
char *syck_base64enc( char *, long );
char *syck_base64dec( char *, long );
-SyckEmitter *syck_new_emitter(void);
+SyckEmitter *syck_new_emitter();
SYMID syck_emitter_mark_node( SyckEmitter *, st_data_t );
void syck_emitter_ignore_id( SyckEmitter *, SYMID );
void syck_output_handler( SyckEmitter *, SyckOutputHandler );
void syck_emitter_handler( SyckEmitter *, SyckEmitterHandler );
void syck_free_emitter( SyckEmitter * );
void syck_emitter_clear( SyckEmitter * );
-void syck_emitter_write( SyckEmitter *, const char *, long );
+void syck_emitter_write( SyckEmitter *, char *, long );
void syck_emitter_escape( SyckEmitter *, char *, long );
void syck_emitter_flush( SyckEmitter *, long );
void syck_emit( SyckEmitter *, st_data_t );
@@ -383,7 +384,7 @@ void syck_emit_seq( SyckEmitter *, char *, enum seq_style );
void syck_emit_item( SyckEmitter *, st_data_t );
void syck_emit_map( SyckEmitter *, char *, enum map_style );
void syck_emit_end( SyckEmitter * );
-void syck_emit_tag( SyckEmitter *, const char *, const char * );
+void syck_emit_tag( SyckEmitter *, char *, char * );
void syck_emit_indent( SyckEmitter * );
SyckLevel *syck_emitter_current_level( SyckEmitter * );
SyckLevel *syck_emitter_parent_level( SyckEmitter * );
@@ -399,6 +400,7 @@ 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 );
@@ -421,8 +423,8 @@ SyckNode *syck_alloc_seq();
SyckNode *syck_alloc_str();
void syck_free_node( SyckNode * );
void syck_free_members( SyckNode * );
-SyckNode *syck_new_str( const char *, enum scalar_style );
-SyckNode *syck_new_str2( const char *, long, enum scalar_style );
+SyckNode *syck_new_str( char *, enum scalar_style );
+SyckNode *syck_new_str2( char *, long, enum scalar_style );
void syck_replace_str( SyckNode *, char *, enum scalar_style );
void syck_replace_str2( SyckNode *, char *, long, enum scalar_style );
void syck_str_blow_away_commas( SyckNode * );
diff --git a/ext/syck/yaml2byte.c b/ext/syck/yaml2byte.c
index bcc428e1cd..821a3cd5b5 100644
--- a/ext/syck/yaml2byte.c
+++ b/ext/syck/yaml2byte.c
@@ -35,7 +35,7 @@ typedef struct {
long remaining;
int printed;
} bytestring_t;
-bytestring_t *bytestring_alloc(void) {
+bytestring_t *bytestring_alloc() {
bytestring_t *ret;
/*TRACE0("bytestring_alloc()");*/
ret = S_ALLOC(bytestring_t);
diff --git a/ext/syslog/.cvsignore b/ext/syslog/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/syslog/.cvsignore
+++ b/ext/syslog/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/syslog/syslog.c b/ext/syslog/syslog.c
index d4945ae7b4..ecc49318f7 100644
--- a/ext/syslog/syslog.c
+++ b/ext/syslog/syslog.c
@@ -22,6 +22,7 @@ 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");
}
@@ -32,12 +33,13 @@ static void syslog_write(int pri, int argc, VALUE *argv)
str = rb_f_sprintf(argc, argv);
- syslog(pri, "%s", RSTRING_PTR(str));
+ syslog(pri, "%s", RSTRING(str)->ptr);
}
/* Syslog module methods */
static VALUE mSyslog_close(VALUE self)
{
+ rb_secure(4);
if (!syslog_opened) {
rb_raise(rb_eRuntimeError, "syslog not opened");
}
@@ -70,7 +72,7 @@ static VALUE mSyslog_open(int argc, VALUE *argv, VALUE self)
#else
Check_SafeStr(ident);
#endif
- syslog_ident = strdup(RSTRING_PTR(ident));
+ syslog_ident = strdup(RSTRING(ident)->ptr);
if (NIL_P(opt)) {
syslog_options = LOG_PID | LOG_CONS;
@@ -132,6 +134,7 @@ 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/extconf.rb b/ext/thread/extconf.rb
new file mode 100644
index 0000000000..2f984efc6d
--- /dev/null
+++ b/ext/thread/extconf.rb
@@ -0,0 +1,9 @@
+require 'mkmf'
+
+enable_config('fastthread', true) or exit
+
+if with_config('mem-pools', true)
+ $CPPFLAGS << ' -DUSE_MEM_POOLS'
+end
+
+create_makefile("thread")
diff --git a/ext/thread/lib/thread.rb b/ext/thread/lib/thread.rb
new file mode 100644
index 0000000000..6c533aba39
--- /dev/null
+++ b/ext/thread/lib/thread.rb
@@ -0,0 +1,5 @@
+unless defined? Thread
+ fail "Thread not available for this ruby interpreter"
+end
+
+require 'thread.so'
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
new file mode 100644
index 0000000000..bca807725e
--- /dev/null
+++ b/ext/thread/thread.c
@@ -0,0 +1,1203 @@
+/*
+ * Optimized Ruby Mutex implementation, loosely based on thread.rb by
+ * Yukihiro Matsumoto <matz@ruby-lang.org>
+ *
+ * Copyright 2006-2007 MenTaLguY <mental@rydia.net>
+ *
+ * RDoc taken from original.
+ *
+ * This file is made available under the same terms as Ruby.
+ */
+
+#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;
+static VALUE rb_cQueue;
+static VALUE rb_cSizedQueue;
+
+static VALUE set_critical(VALUE value);
+
+static VALUE
+thread_exclusive(VALUE (*func)(ANYARGS), VALUE arg)
+{
+ VALUE critical = rb_thread_critical;
+
+ rb_thread_critical = 1;
+ return rb_ensure(func, arg, set_critical, (VALUE)critical);
+}
+
+/*
+ * call-seq:
+ * Thread.exclusive { block } => obj
+ *
+ * Wraps a block in Thread.critical, restoring the original value
+ * upon exit from the critical section, and returns the value of the
+ * block.
+ */
+
+static VALUE
+rb_thread_exclusive(void)
+{
+ return thread_exclusive(rb_yield, Qundef);
+}
+
+typedef struct _Entry {
+ VALUE value;
+ struct _Entry *next;
+} Entry;
+
+typedef struct _List {
+ Entry *entries;
+ Entry *last_entry;
+ Entry *entry_pool;
+ unsigned long size;
+} List;
+
+static void
+init_list(List *list)
+{
+ list->entries = NULL;
+ list->last_entry = NULL;
+ list->entry_pool = NULL;
+ list->size = 0;
+}
+
+static void
+mark_list(List *list)
+{
+ Entry *entry;
+ for (entry = list->entries; entry; entry = entry->next) {
+ rb_gc_mark(entry->value);
+ }
+}
+
+static void
+free_entries(Entry *first)
+{
+ Entry *next;
+ while (first) {
+ next = first->next;
+ xfree(first);
+ first = next;
+ }
+}
+
+static void
+finalize_list(List *list)
+{
+ free_entries(list->entries);
+ free_entries(list->entry_pool);
+}
+
+static void
+push_list(List *list, VALUE value)
+{
+ Entry *entry;
+
+ if (list->entry_pool) {
+ entry = list->entry_pool;
+ list->entry_pool = entry->next;
+ } else {
+ entry = ALLOC(Entry);
+ }
+
+ entry->value = value;
+ entry->next = NULL;
+
+ if (list->last_entry) {
+ list->last_entry->next = entry;
+ } else {
+ list->entries = entry;
+ }
+ list->last_entry = entry;
+
+ ++list->size;
+}
+
+static void
+push_multiple_list(List *list, VALUE *values, unsigned count)
+{
+ unsigned i;
+ for (i = 0; i < count; i++) {
+ push_list(list, values[i]);
+ }
+}
+
+static void
+recycle_entries(List *list, Entry *first_entry, Entry *last_entry)
+{
+#ifdef USE_MEM_POOLS
+ last_entry->next = list->entry_pool;
+ list->entry_pool = first_entry;
+#else
+ last_entry->next = NULL;
+ free_entries(first_entry);
+#endif
+}
+
+static VALUE
+shift_list(List *list)
+{
+ Entry *entry;
+ VALUE value;
+
+ entry = list->entries;
+ if (!entry) return Qnil;
+
+ list->entries = entry->next;
+ if (entry == list->last_entry) {
+ list->last_entry = NULL;
+ }
+
+ --list->size;
+
+ value = entry->value;
+ recycle_entries(list, entry, entry);
+
+ return value;
+}
+
+static void
+remove_one(List *list, VALUE value)
+{
+ Entry **ref;
+ Entry *prev;
+ Entry *entry;
+
+ for (ref = &list->entries, prev = NULL, entry = list->entries;
+ entry != NULL;
+ ref = &entry->next, prev = entry, 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;
+ }
+ }
+}
+
+static void
+clear_list(List *list)
+{
+ if (list->last_entry) {
+ recycle_entries(list, list->entries, list->last_entry);
+ list->entries = NULL;
+ list->last_entry = NULL;
+ list->size = 0;
+ }
+}
+
+static VALUE
+array_from_list(List const *list)
+{
+ VALUE ary;
+ Entry *entry;
+ ary = rb_ary_new();
+ for (entry = list->entries; entry; entry = entry->next) {
+ rb_ary_push(ary, entry->value);
+ }
+ return ary;
+}
+
+static VALUE
+wake_thread(VALUE thread)
+{
+ return rb_thread_wakeup_alive(thread);
+}
+
+static VALUE
+run_thread(VALUE thread)
+{
+ thread = wake_thread(thread);
+ if (RTEST(thread) && !rb_thread_critical)
+ rb_thread_schedule();
+ return thread;
+}
+
+static VALUE
+wake_one(List *list)
+{
+ VALUE waking;
+
+ waking = Qnil;
+ while (list->entries && !RTEST(waking)) {
+ waking = shift_list(list);
+ if (waking == Qundef) break;
+ waking = wake_thread(waking);
+ }
+
+ return waking;
+}
+
+static VALUE
+wake_all(List *list)
+{
+ while (list->entries) {
+ wake_one(list);
+ }
+ return Qnil;
+}
+
+static VALUE
+wait_list_inner(List *list)
+{
+ push_list(list, rb_thread_current());
+ rb_thread_stop();
+ return Qnil;
+}
+
+static VALUE
+wait_list_cleanup(List *list)
+{
+ /* cleanup in case of spurious wakeups */
+ remove_one(list, rb_thread_current());
+ return Qnil;
+}
+
+static void
+wait_list(List *list)
+{
+ rb_ensure(wait_list_inner, (VALUE)list, wait_list_cleanup, (VALUE)list);
+}
+
+static void
+kill_waiting_threads(List *waiting)
+{
+ Entry *entry;
+
+ for (entry = waiting->entries; entry; entry = entry->next) {
+ rb_thread_kill(entry->value);
+ }
+}
+
+/*
+ * Document-class: Mutex
+ *
+ * Mutex implements a simple semaphore that can be used to coordinate access to
+ * shared data from multiple concurrent threads.
+ *
+ * Example:
+ *
+ * require 'thread'
+ * semaphore = Mutex.new
+ *
+ * a = Thread.new {
+ * semaphore.synchronize {
+ * # access shared resource
+ * }
+ * }
+ *
+ * b = Thread.new {
+ * semaphore.synchronize {
+ * # access shared resource
+ * }
+ * }
+ *
+ */
+
+typedef struct _Mutex {
+ VALUE owner;
+ List waiting;
+} Mutex;
+
+#define MUTEX_LOCKED_P(mutex) (RTEST((mutex)->owner) && rb_thread_alive_p((mutex)->owner))
+
+static void
+mark_mutex(Mutex *mutex)
+{
+ rb_gc_mark(mutex->owner);
+ mark_list(&mutex->waiting);
+}
+
+static void
+finalize_mutex(Mutex *mutex)
+{
+ finalize_list(&mutex->waiting);
+}
+
+static void
+free_mutex(Mutex *mutex)
+{
+ kill_waiting_threads(&mutex->waiting);
+ finalize_mutex(mutex);
+ xfree(mutex);
+}
+
+static void
+init_mutex(Mutex *mutex)
+{
+ mutex->owner = Qnil;
+ init_list(&mutex->waiting);
+}
+
+/*
+ * Document-method: new
+ * call-seq: Mutex.new
+ *
+ * Creates a new Mutex
+ *
+ */
+
+static VALUE
+rb_mutex_alloc(VALUE klass)
+{
+ Mutex *mutex;
+ mutex = ALLOC(Mutex);
+ init_mutex(mutex);
+ return Data_Wrap_Struct(klass, mark_mutex, free_mutex, mutex);
+}
+
+/*
+ * Document-method: locked?
+ * call-seq: locked?
+ *
+ * Returns +true+ if this lock is currently held by some thread.
+ *
+ */
+
+static VALUE
+rb_mutex_locked_p(VALUE self)
+{
+ Mutex *mutex;
+ Data_Get_Struct(self, Mutex, mutex);
+ return MUTEX_LOCKED_P(mutex) ? Qtrue : Qfalse;
+}
+
+/*
+ * Document-method: try_lock
+ * call-seq: try_lock
+ *
+ * Attempts to obtain the lock and returns immediately. Returns +true+ if the
+ * lock was granted.
+ *
+ */
+
+static VALUE
+rb_mutex_try_lock(VALUE self)
+{
+ Mutex *mutex;
+
+ Data_Get_Struct(self, Mutex, mutex);
+
+ if (MUTEX_LOCKED_P(mutex))
+ return Qfalse;
+
+ mutex->owner = rb_thread_current();
+ return Qtrue;
+}
+
+/*
+ * Document-method: lock
+ * call-seq: lock
+ *
+ * Attempts to grab the lock and waits if it isn't available.
+ *
+ */
+
+static VALUE
+lock_mutex(Mutex *mutex)
+{
+ VALUE current;
+ current = rb_thread_current();
+
+ 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);
+ }
+
+ rb_thread_critical = 0;
+ return Qnil;
+}
+
+static VALUE
+rb_mutex_lock(VALUE self)
+{
+ Mutex *mutex;
+ Data_Get_Struct(self, Mutex, mutex);
+ lock_mutex(mutex);
+ 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
+ *
+ * Releases the lock. Returns +nil+ if ref wasn't locked.
+ *
+ */
+
+static VALUE
+unlock_mutex_inner(Mutex *mutex)
+{
+ VALUE waking;
+
+ if (mutex->owner != rb_thread_current()) {
+ rb_raise(rb_eThreadError, "not owner");
+ }
+
+ waking = wake_one(&mutex->waiting);
+ mutex->owner = waking;
+
+ return waking;
+}
+
+static VALUE
+set_critical(VALUE value)
+{
+ rb_thread_critical = (int)value;
+ return Qundef;
+}
+
+static VALUE
+unlock_mutex(Mutex *mutex)
+{
+ VALUE waking = thread_exclusive(unlock_mutex_inner, (VALUE)mutex);
+
+ if (!RTEST(waking)) {
+ return Qfalse;
+ }
+
+ run_thread(waking);
+
+ return Qtrue;
+}
+
+static VALUE
+rb_mutex_unlock(VALUE self)
+{
+ Mutex *mutex;
+ Data_Get_Struct(self, Mutex, mutex);
+
+ if (RTEST(unlock_mutex(mutex))) {
+ return self;
+ } else {
+ return Qnil;
+ }
+}
+
+/*
+ * Document-method: exclusive_unlock
+ * call-seq: exclusive_unlock { ... }
+ *
+ * If the mutex is locked, unlocks the mutex, wakes one waiting thread, and
+ * yields in a critical section.
+ *
+ */
+
+static VALUE
+rb_mutex_exclusive_unlock_inner(Mutex *mutex)
+{
+ VALUE waking;
+ waking = unlock_mutex_inner(mutex);
+ rb_yield(Qundef);
+ return waking;
+}
+
+static VALUE
+rb_mutex_exclusive_unlock(VALUE self)
+{
+ Mutex *mutex;
+ VALUE waking;
+ Data_Get_Struct(self, Mutex, mutex);
+
+ waking = thread_exclusive(rb_mutex_exclusive_unlock_inner, (VALUE)mutex);
+
+ if (!RTEST(waking)) {
+ return Qnil;
+ }
+
+ run_thread(waking);
+
+ return self;
+}
+
+/*
+ * Document-method: synchronize
+ * call-seq: synchronize { ... }
+ *
+ * Obtains a lock, runs the block, and releases the lock when the block
+ * completes. See the example under Mutex.
+ *
+ */
+
+static VALUE
+rb_mutex_synchronize(VALUE self)
+{
+ rb_mutex_lock(self);
+ return rb_ensure(rb_yield, Qundef, rb_mutex_unlock, self);
+}
+
+/*
+ * Document-class: ConditionVariable
+ *
+ * ConditionVariable objects augment class Mutex. Using condition variables,
+ * it is possible to suspend while in the middle of a critical section until a
+ * resource becomes available.
+ *
+ * Example:
+ *
+ * require 'thread'
+ *
+ * mutex = Mutex.new
+ * resource = ConditionVariable.new
+ *
+ * a = Thread.new {
+ * mutex.synchronize {
+ * # Thread 'a' now needs the resource
+ * resource.wait(mutex)
+ * # 'a' can now have the resource
+ * }
+ * }
+ *
+ * b = Thread.new {
+ * mutex.synchronize {
+ * # Thread 'b' has finished using the resource
+ * resource.signal
+ * }
+ * }
+ *
+ */
+
+typedef struct _ConditionVariable {
+ List waiting;
+} ConditionVariable;
+
+static void
+mark_condvar(ConditionVariable *condvar)
+{
+ mark_list(&condvar->waiting);
+}
+
+static void
+finalize_condvar(ConditionVariable *condvar)
+{
+ finalize_list(&condvar->waiting);
+}
+
+static void
+free_condvar(ConditionVariable *condvar)
+{
+ kill_waiting_threads(&condvar->waiting);
+ finalize_condvar(condvar);
+ xfree(condvar);
+}
+
+static void
+init_condvar(ConditionVariable *condvar)
+{
+ init_list(&condvar->waiting);
+}
+
+/*
+ * Document-method: new
+ * call-seq: ConditionVariable.new
+ *
+ * Creates a new ConditionVariable
+ *
+ */
+
+static VALUE
+rb_condvar_alloc(VALUE klass)
+{
+ ConditionVariable *condvar;
+
+ condvar = ALLOC(ConditionVariable);
+ init_condvar(condvar);
+
+ return Data_Wrap_Struct(klass, mark_condvar, free_condvar, condvar);
+}
+
+/*
+ * Document-method: wait
+ * call-seq: wait
+ *
+ * Releases the lock held in +mutex+ and waits; reacquires the lock on wakeup.
+ *
+ */
+
+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);
+}
+
+static VALUE
+legacy_exclusive_unlock(VALUE mutex)
+{
+ return rb_funcall(mutex, rb_intern("exclusive_unlock"), 0);
+}
+
+typedef struct {
+ ConditionVariable *condvar;
+ VALUE mutex;
+} legacy_wait_args;
+
+static VALUE
+legacy_wait(VALUE unused, legacy_wait_args *args)
+{
+ wait_list(&args->condvar->waiting);
+ rb_funcall(args->mutex, rb_intern("lock"), 0);
+ return Qnil;
+}
+
+static VALUE
+rb_condvar_wait(VALUE self, VALUE mutex_v)
+{
+ ConditionVariable *condvar;
+ Data_Get_Struct(self, ConditionVariable, condvar);
+
+ if (CLASS_OF(mutex_v) != rb_cMutex) {
+ /* interoperate with legacy mutex */
+ legacy_wait_args args;
+ args.condvar = condvar;
+ args.mutex = mutex_v;
+ rb_iterate(legacy_exclusive_unlock, mutex_v, legacy_wait, (VALUE)&args);
+ } else {
+ Mutex *mutex;
+ Data_Get_Struct(mutex_v, Mutex, mutex);
+ wait_condvar(condvar, mutex);
+ }
+
+ return self;
+}
+
+/*
+ * Document-method: broadcast
+ * call-seq: broadcast
+ *
+ * Wakes up all threads waiting for this condition.
+ *
+ */
+
+static VALUE
+rb_condvar_broadcast(VALUE self)
+{
+ ConditionVariable *condvar;
+
+ Data_Get_Struct(self, ConditionVariable, condvar);
+
+ thread_exclusive(wake_all, (VALUE)&condvar->waiting);
+ rb_thread_schedule();
+
+ return self;
+}
+
+/*
+ * Document-method: signal
+ * call-seq: signal
+ *
+ * Wakes up the first thread in line waiting for this condition.
+ *
+ */
+
+static void
+signal_condvar(ConditionVariable *condvar)
+{
+ VALUE waking = thread_exclusive(wake_one, (VALUE)&condvar->waiting);
+
+ if (RTEST(waking)) {
+ run_thread(waking);
+ }
+}
+
+static VALUE
+rb_condvar_signal(VALUE self)
+{
+ ConditionVariable *condvar;
+ Data_Get_Struct(self, ConditionVariable, condvar);
+ signal_condvar(condvar);
+ return self;
+}
+
+/*
+ * Document-class: Queue
+ *
+ * This class provides a way to synchronize communication between threads.
+ *
+ * Example:
+ *
+ * require 'thread'
+ *
+ * queue = Queue.new
+ *
+ * producer = Thread.new do
+ * 5.times do |i|
+ * sleep rand(i) # simulate expense
+ * queue << i
+ * puts "#{i} produced"
+ * end
+ * end
+ *
+ * consumer = Thread.new do
+ * 5.times do |i|
+ * value = queue.pop
+ * sleep rand(i/2) # simulate expense
+ * puts "consumed #{value}"
+ * end
+ * end
+ *
+ * consumer.join
+ *
+ */
+
+typedef struct _Queue {
+ Mutex mutex;
+ ConditionVariable value_available;
+ ConditionVariable space_available;
+ List values;
+ unsigned long capacity;
+} Queue;
+
+static void
+mark_queue(Queue *queue)
+{
+ mark_mutex(&queue->mutex);
+ mark_condvar(&queue->value_available);
+ mark_condvar(&queue->space_available);
+ mark_list(&queue->values);
+}
+
+static void
+finalize_queue(Queue *queue)
+{
+ finalize_mutex(&queue->mutex);
+ finalize_condvar(&queue->value_available);
+ finalize_condvar(&queue->space_available);
+ finalize_list(&queue->values);
+}
+
+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);
+ finalize_queue(queue);
+ xfree(queue);
+}
+
+static void
+init_queue(Queue *queue)
+{
+ init_mutex(&queue->mutex);
+ init_condvar(&queue->value_available);
+ init_condvar(&queue->space_available);
+ init_list(&queue->values);
+ queue->capacity = 0;
+}
+
+/*
+ * Document-method: new
+ * call-seq: new
+ *
+ * Creates a new queue.
+ *
+ */
+
+static VALUE
+rb_queue_alloc(VALUE klass)
+{
+ Queue *queue;
+ queue = ALLOC(Queue);
+ init_queue(queue);
+ return Data_Wrap_Struct(klass, mark_queue, free_queue, queue);
+}
+
+static VALUE
+rb_queue_marshal_load(VALUE self, VALUE data)
+{
+ Queue *queue;
+ VALUE array;
+ Data_Get_Struct(self, Queue, queue);
+
+ array = rb_marshal_load(data);
+ if (TYPE(array) != T_ARRAY) {
+ rb_raise(rb_eTypeError, "expected Array of queue data");
+ }
+ if (RARRAY(array)->len < 1) {
+ rb_raise(rb_eArgError, "missing capacity value");
+ }
+ queue->capacity = NUM2ULONG(rb_ary_shift(array));
+ push_multiple_list(&queue->values, RARRAY(array)->ptr, (unsigned)RARRAY(array)->len);
+
+ return self;
+}
+
+static VALUE
+rb_queue_marshal_dump(VALUE self)
+{
+ Queue *queue;
+ VALUE array;
+ Data_Get_Struct(self, Queue, queue);
+
+ array = array_from_list(&queue->values);
+ rb_ary_unshift(array, ULONG2NUM(queue->capacity));
+ return rb_marshal_dump(array, Qnil);
+}
+
+/*
+ * Document-method: clear
+ * call-seq: clear
+ *
+ * Removes all objects from the queue.
+ *
+ */
+
+static VALUE
+rb_queue_clear(VALUE self)
+{
+ Queue *queue;
+ Data_Get_Struct(self, Queue, queue);
+
+ lock_mutex(&queue->mutex);
+ clear_list(&queue->values);
+ signal_condvar(&queue->space_available);
+ unlock_mutex(&queue->mutex);
+
+ return self;
+}
+
+/*
+ * Document-method: empty?
+ * call-seq: empty?
+ *
+ * Returns +true+ if the queue is empty.
+ *
+ */
+
+static VALUE
+rb_queue_empty_p(VALUE self)
+{
+ Queue *queue;
+ VALUE result;
+ Data_Get_Struct(self, Queue, queue);
+
+ lock_mutex(&queue->mutex);
+ result = queue->values.size == 0 ? Qtrue : Qfalse;
+ unlock_mutex(&queue->mutex);
+
+ return result;
+}
+
+/*
+ * Document-method: length
+ * call-seq: length
+ *
+ * Returns the length of the queue.
+ *
+ */
+
+static VALUE
+rb_queue_length(VALUE self)
+{
+ Queue *queue;
+ VALUE result;
+ Data_Get_Struct(self, Queue, queue);
+
+ lock_mutex(&queue->mutex);
+ result = ULONG2NUM(queue->values.size);
+ unlock_mutex(&queue->mutex);
+
+ return result;
+}
+
+/*
+ * Document-method: num_waiting
+ * call-seq: num_waiting
+ *
+ * Returns the number of threads waiting on the queue.
+ *
+ */
+
+static VALUE
+rb_queue_num_waiting(VALUE self)
+{
+ Queue *queue;
+ VALUE result;
+ Data_Get_Struct(self, Queue, queue);
+
+ lock_mutex(&queue->mutex);
+ result = ULONG2NUM(queue->value_available.waiting.size +
+ queue->space_available.waiting.size);
+ unlock_mutex(&queue->mutex);
+
+ return result;
+}
+
+/*
+ * Document-method: pop
+ * call_seq: pop(non_block=false)
+ *
+ * Retrieves data from the queue. If the queue is empty, the calling thread is
+ * suspended until data is pushed onto the queue. If +non_block+ is true, the
+ * thread isn't suspended, and an exception is raised.
+ *
+ */
+
+static VALUE
+rb_queue_pop(int argc, VALUE *argv, VALUE self)
+{
+ Queue *queue;
+ int should_block;
+ VALUE result;
+ Data_Get_Struct(self, Queue, queue);
+
+ if (argc == 0) {
+ should_block = 1;
+ } else if (argc == 1) {
+ should_block = !RTEST(argv[0]);
+ } else {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
+ }
+
+ lock_mutex(&queue->mutex);
+ if (!queue->values.entries && !should_block) {
+ unlock_mutex(&queue->mutex);
+ rb_raise(rb_eThreadError, "queue empty");
+ }
+
+ while (!queue->values.entries) {
+ wait_condvar(&queue->value_available, &queue->mutex);
+ }
+
+ result = shift_list(&queue->values);
+ if (queue->capacity && queue->values.size < queue->capacity) {
+ signal_condvar(&queue->space_available);
+ }
+ unlock_mutex(&queue->mutex);
+
+ return result;
+}
+
+/*
+ * Document-method: push
+ * call-seq: push(obj)
+ *
+ * Pushes +obj+ to the queue.
+ *
+ */
+
+static VALUE
+rb_queue_push(VALUE self, VALUE value)
+{
+ Queue *queue;
+ Data_Get_Struct(self, Queue, queue);
+
+ lock_mutex(&queue->mutex);
+ while (queue->capacity && queue->values.size >= queue->capacity) {
+ wait_condvar(&queue->space_available, &queue->mutex);
+ }
+ push_list(&queue->values, value);
+ signal_condvar(&queue->value_available);
+ unlock_mutex(&queue->mutex);
+
+ return self;
+}
+
+/*
+ * Document-class: SizedQueue
+ *
+ * This class represents queues of specified size capacity. The push operation
+ * may be blocked if the capacity is full.
+ *
+ * See Queue for an example of how a SizedQueue works.
+ *
+ */
+
+/*
+ * Document-method: new
+ * call-seq: new
+ *
+ * Creates a fixed-length queue with a maximum size of +max+.
+ *
+ */
+
+/*
+ * Document-method: max
+ * call-seq: max
+ *
+ * Returns the maximum size of the queue.
+ *
+ */
+
+static VALUE
+rb_sized_queue_max(VALUE self)
+{
+ Queue *queue;
+ VALUE result;
+ Data_Get_Struct(self, Queue, queue);
+
+ lock_mutex(&queue->mutex);
+ result = ULONG2NUM(queue->capacity);
+ unlock_mutex(&queue->mutex);
+
+ return result;
+}
+
+/*
+ * Document-method: max=
+ * call-seq: max=(size)
+ *
+ * Sets the maximum size of the queue.
+ *
+ */
+
+static VALUE
+rb_sized_queue_max_set(VALUE self, VALUE value)
+{
+ Queue *queue;
+ unsigned long new_capacity;
+ unsigned long difference;
+ Data_Get_Struct(self, Queue, queue);
+
+ new_capacity = NUM2ULONG(value);
+
+ if (new_capacity < 1) {
+ rb_raise(rb_eArgError, "value must be positive");
+ }
+
+ lock_mutex(&queue->mutex);
+ if (queue->capacity && new_capacity > queue->capacity) {
+ difference = new_capacity - queue->capacity;
+ } else {
+ difference = 0;
+ }
+ queue->capacity = new_capacity;
+ for (; difference > 0; --difference) {
+ signal_condvar(&queue->space_available);
+ }
+ unlock_mutex(&queue->mutex);
+
+ return self;
+}
+
+/*
+ * Document-method: push
+ * call-seq: push(obj)
+ *
+ * Pushes +obj+ to the queue. If there is no space left in the queue, waits
+ * until space becomes available.
+ *
+ */
+
+/*
+ * Document-method: pop
+ * call-seq: pop(non_block=false)
+ *
+ * Retrieves data from the queue and runs a waiting thread, if any.
+ *
+ */
+
+/* for marshalling mutexes and condvars */
+
+static VALUE
+dummy_load(VALUE self, VALUE string)
+{
+ return Qnil;
+}
+
+static VALUE
+dummy_dump(VALUE self)
+{
+ return rb_str_new2("");
+}
+
+void
+Init_thread(void)
+{
+ rb_define_singleton_method(rb_cThread, "exclusive", rb_thread_exclusive, 0);
+
+ rb_cMutex = rb_define_class("Mutex", rb_cObject);
+ rb_define_alloc_func(rb_cMutex, rb_mutex_alloc);
+ rb_define_method(rb_cMutex, "marshal_load", dummy_load, 1);
+ rb_define_method(rb_cMutex, "marshal_dump", dummy_dump, 0);
+ rb_define_method(rb_cMutex, "locked?", rb_mutex_locked_p, 0);
+ rb_define_method(rb_cMutex, "try_lock", rb_mutex_try_lock, 0);
+ rb_define_method(rb_cMutex, "lock", rb_mutex_lock, 0);
+ rb_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0);
+ rb_define_method(rb_cMutex, "exclusive_unlock", rb_mutex_exclusive_unlock, 0);
+ rb_define_method(rb_cMutex, "synchronize", rb_mutex_synchronize, 0);
+
+ rb_cConditionVariable = rb_define_class("ConditionVariable", rb_cObject);
+ rb_define_alloc_func(rb_cConditionVariable, rb_condvar_alloc);
+ rb_define_method(rb_cConditionVariable, "marshal_load", dummy_load, 1);
+ rb_define_method(rb_cConditionVariable, "marshal_dump", dummy_dump, 0);
+ rb_define_method(rb_cConditionVariable, "wait", rb_condvar_wait, 1);
+ rb_define_method(rb_cConditionVariable, "broadcast", rb_condvar_broadcast, 0);
+ rb_define_method(rb_cConditionVariable, "signal", rb_condvar_signal, 0);
+
+ rb_cQueue = rb_define_class("Queue", rb_cObject);
+ rb_define_alloc_func(rb_cQueue, rb_queue_alloc);
+ rb_define_method(rb_cQueue, "marshal_load", rb_queue_marshal_load, 1);
+ rb_define_method(rb_cQueue, "marshal_dump", rb_queue_marshal_dump, 0);
+ rb_define_method(rb_cQueue, "clear", rb_queue_clear, 0);
+ rb_define_method(rb_cQueue, "empty?", rb_queue_empty_p, 0);
+ rb_define_method(rb_cQueue, "length", rb_queue_length, 0);
+ rb_define_method(rb_cQueue, "num_waiting", rb_queue_num_waiting, 0);
+ rb_define_method(rb_cQueue, "pop", rb_queue_pop, -1);
+ rb_define_method(rb_cQueue, "push", rb_queue_push, 1);
+ rb_alias(rb_cQueue, rb_intern("enq"), rb_intern("push"));
+ rb_alias(rb_cQueue, rb_intern("<<"), rb_intern("push"));
+ rb_alias(rb_cQueue, rb_intern("deq"), rb_intern("pop"));
+ rb_alias(rb_cQueue, rb_intern("shift"), rb_intern("pop"));
+ rb_alias(rb_cQueue, rb_intern("size"), rb_intern("length"));
+
+ rb_cSizedQueue = rb_define_class("SizedQueue", rb_cQueue);
+ rb_define_method(rb_cSizedQueue, "initialize", rb_sized_queue_max_set, 1);
+ rb_define_method(rb_cSizedQueue, "num_waiting", rb_queue_num_waiting, 0);
+ rb_define_method(rb_cSizedQueue, "pop", rb_queue_pop, -1);
+ rb_define_method(rb_cSizedQueue, "push", rb_queue_push, 1);
+ rb_define_method(rb_cSizedQueue, "max", rb_sized_queue_max, 0);
+ rb_define_method(rb_cSizedQueue, "max=", rb_sized_queue_max_set, 1);
+ rb_alias(rb_cSizedQueue, rb_intern("enq"), rb_intern("push"));
+ rb_alias(rb_cSizedQueue, rb_intern("<<"), rb_intern("push"));
+ rb_alias(rb_cSizedQueue, rb_intern("deq"), rb_intern("pop"));
+ rb_alias(rb_cSizedQueue, rb_intern("shift"), rb_intern("pop"));
+}
+
diff --git a/ext/tk/.cvsignore b/ext/tk/.cvsignore
index 90c83ed9b1..44e7f262dc 100644
--- a/ext/tk/.cvsignore
+++ b/ext/tk/.cvsignore
@@ -1,3 +1,3 @@
Makefile
+mkmf.log
*.log
-*.def
diff --git a/ext/tk/ChangeLog.tkextlib b/ext/tk/ChangeLog.tkextlib
index 40977b4776..359b466a32 100644
--- a/ext/tk/ChangeLog.tkextlib
+++ b/ext/tk/ChangeLog.tkextlib
@@ -1,3 +1,23 @@
+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].
+
+ * ext/tk/lib/tkextlib/iwidgets/radiobox.rb: ditto.
+
+ * ext/tk/lib/tkextlib/blt/tile/checkbutton.rb: change primary name
+ of class [ruby-dev:30080].
+
+ * ext/tk/lib/tkextlib/blt/tile/radiobutton.rb: ditto.
+
2006-11-07 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* lib/tkextlib/tile/treeview.rb : minor bug fix.
diff --git a/ext/tk/README.1st b/ext/tk/README.1st
index fce5b0242b..df6c819d26 100644
--- a/ext/tk/README.1st
+++ b/ext/tk/README.1st
@@ -1,6 +1,7 @@
If you want to use Ruby/Tk (tk.rb and so on), you must have tcltklib.so
-which is working correctly. When you have some troubles on compiling,
-please read README.tcltklib and README.ActiveTcl.
+which is working correctly. If you fail to call 'require "tcltklib"',
+you may not have tcltklib.so. When you have some troubles on compiling
+tcltklib, please read README files on tcltklib.
Even if there is a tcltklib.so on your Ruby library directry, it will not
work without Tcl/Tk libraries (e.g. libtcl8.4.so) on your environment.
You must also check that your Tcl/Tk is installed properly.
@@ -8,9 +9,11 @@ You must also check that your Tcl/Tk is installed properly.
--------------------------------------------
( the following is written in EUC-JP )
-Ruby/Tk (tk.rb ¤Ê¤É) ¤ò»È¤¤¤¿¤¤¾ì¹ç¤Ë¤Ï¡¤tcltklib.so ¤¬Àµ¤·¤¯Æ°¤¤¤Æ¤¤¤Ê
-¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡¥¥³¥ó¥Ñ¥¤¥ë»þ¤Ë²¿¤«ÌäÂ꤬À¸¤¸¤¿¾ì¹ç¤Ï¡¤README.tcltklib
-¤ä README.ActiveTcl ¤ò¸«¤Æ¤¯¤À¤µ¤¤¡¥
+Ruby/Tk (tk.rb ¤Ê¤É) ¤ò»È¤¤¤¿¤¤¾ì¹ç¤Ë¤Ï¡¤tcltklib.so ¤¬Àµ¤·¤¯Æ°¤¤¤Æ
+¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡¥¤â¤· 'require "tcltklib"' ¤Ë¼ºÇÔ¤¹¤ë¤è¤¦¤Ê¤é¡¤
+tcltklib.so ¤¬¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤Ê¤¤¤Î¤«¤â¤·¤ì¤Þ¤»¤ó¡¥tcltklib ¤Î
+¥³¥ó¥Ñ¥¤¥ë»þ¤Ë²¿¤«ÌäÂ꤬À¸¤¸¤Æ¤¤¤ë¾ì¹ç¤Ï¡¤tcltklib ¤Î README ¥Õ¥¡¥¤¥ë
+¤ò¸«¤Æ¤¯¤À¤µ¤¤¡¥
¤¿¤È¤¨ Ruby ¤Î¥é¥¤¥Ö¥é¥ê¥Ç¥£¥ì¥¯¥È¥ê¤Ë tcltklib.so ¤¬Â¸ºß¤·¤Æ¤¤¤¿¤È¤·¤Æ
¤â¡¤¼Â¹Ô´Ä¶­¤Ë Tcl/Tk ¥é¥¤¥Ö¥é¥ê (libtcl8.4.so ¤Ê¤É) ¤¬¤Ê¤±¤ì¤Ðµ¡Ç½¤·¤Þ
¤»¤ó¡¥Tcl/Tk ¤¬Àµ¤·¤¯¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤ë¤«¤â¥Á¥§¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡¥
diff --git a/ext/tk/README.tcltklib b/ext/tk/README.tcltklib
index 5d1da48a45..e939ba1f51 100644
--- a/ext/tk/README.tcltklib
+++ b/ext/tk/README.tcltklib
@@ -41,6 +41,15 @@ some or all of the following options.
(e.g. "/Library/Frameworks/Tk.framework/Headers")
+ --with-X11 / --without-X11 use / not use the X Window System
+
+ --with-X11-dir=<path>
+ equal to "--with-X11-include=<path>/include --with-X11-lib=<path>/lib"
+
+ --with-X11-include=<dir> the directry contains X11 header files
+ --with-X11-lib=<dir> the directry contains X11 libraries
+
+
If you forgot to give the options when do 'configure' on toplevel
directry of Ruby sources, please try something like as the followings.
diff --git a/ext/tk/extconf.rb b/ext/tk/extconf.rb
index 8c8d833481..5ed86a8b76 100644
--- a/ext/tk/extconf.rb
+++ b/ext/tk/extconf.rb
@@ -47,6 +47,8 @@ tklib = with_config("tklib")
tcllib = with_config("tcllib")
stubs = enable_config("tcltk_stubs") || with_config("tcltk_stubs")
+use_X = with_config("X11", (! is_win32))
+
def find_tcl(tcllib, stubs)
paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
if stubs
@@ -273,8 +275,9 @@ end
if tcltk_framework ||
(have_header("tcl.h") && have_header("tk.h") &&
- (is_win32 || find_library("X11", "XOpenDisplay",
- "/usr/X11/lib", "/usr/lib/X11", "/usr/X11R6/lib", "/usr/openwin/lib")) &&
+ ( !use_X || find_library("X11", "XOpenDisplay",
+ "/usr/X11/lib", "/usr/lib/X11",
+ "/usr/X11R6/lib", "/usr/openwin/lib")) &&
find_tcl(tcllib, stubs) &&
find_tk(tklib, stubs))
$CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index 071d60237c..32b5e20bc5 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -2829,7 +2829,7 @@ module TkConfigMethod
def __confinfo_cmd
__config_cmd
end
- private :__config_cmd
+ private :__confinfo_cmd
def __configinfo_struct
{:key=>0, :alias=>1, :db_name=>1, :db_class=>2,
@@ -2926,6 +2926,7 @@ module TkConfigMethod
}
keys2
end
+ private :__conv_keyonly_opts
def config_hash_kv(keys, enc_mode = nil, conf = nil)
hash_kv(__conv_keyonly_opts(keys), enc_mode, conf)
@@ -4597,7 +4598,7 @@ end
#Tk.freeze
module Tk
- RELEASE_DATE = '2006-11-07'.freeze
+ RELEASE_DATE = '2007-01-26'.freeze
autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable'
diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb
index 02b4a8cb20..c30fd79bb9 100644
--- a/ext/tk/lib/tk/canvas.rb
+++ b/ext/tk/lib/tk/canvas.rb
@@ -42,7 +42,7 @@ end
class TkCanvas<TkWindow
include TkCanvasItemConfig
- include Scrollable
+ include Tk::Scrollable
TkCommandNames = ['canvas'.freeze].freeze
WidgetClassName = 'Canvas'.freeze
@@ -543,8 +543,8 @@ class TkCanvas<TkWindow
tk_send_without_enc('scan', 'mark', x, y)
self
end
- def scan_dragto(x, y)
- tk_send_without_enc('scan', 'dragto', x, y)
+ def scan_dragto(x, y, gain=None)
+ tk_send_without_enc('scan', 'dragto', x, y, gain)
self
end
diff --git a/ext/tk/lib/tk/scrollable.rb b/ext/tk/lib/tk/scrollable.rb
index ec27b76467..96959b7a4b 100644
--- a/ext/tk/lib/tk/scrollable.rb
+++ b/ext/tk/lib/tk/scrollable.rb
@@ -4,7 +4,7 @@
require 'tk'
module Tk
- module X_Scrollable
+ module XScrollable
def xscrollcommand(cmd=Proc.new)
configure_cmd 'xscrollcommand', cmd
# Tk.update # avoid scrollbar trouble
@@ -38,7 +38,7 @@ module Tk
end
end
- module Y_Scrollable
+ module YScrollable
def yscrollcommand(cmd=Proc.new)
configure_cmd 'yscrollcommand', cmd
# Tk.update # avoid scrollbar trouble
@@ -72,8 +72,11 @@ module Tk
end
end
+ X_Scrollable = XScrollable
+ Y_Scrollable = YScrollable
+
module Scrollable
- include X_Scrollable
- include Y_Scrollable
+ include XScrollable
+ include YScrollable
end
end
diff --git a/ext/tk/lib/tk/txtwin_abst.rb b/ext/tk/lib/tk/txtwin_abst.rb
index 5520360eab..540f806d17 100644
--- a/ext/tk/lib/tk/txtwin_abst.rb
+++ b/ext/tk/lib/tk/txtwin_abst.rb
@@ -4,7 +4,7 @@
require 'tk'
class TkTextWin<TkWindow
- TkCommnadNames = [].freeze
+ TkCommandNames = [].freeze
#def create_self
# fail RuntimeError, "TkTextWin is an abstract class"
#end
diff --git a/ext/tk/lib/tkextlib/blt/tile/checkbutton.rb b/ext/tk/lib/tkextlib/blt/tile/checkbutton.rb
index ebe79179a5..ad58999d86 100644
--- a/ext/tk/lib/tkextlib/blt/tile/checkbutton.rb
+++ b/ext/tk/lib/tkextlib/blt/tile/checkbutton.rb
@@ -9,9 +9,9 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
- class Checkbutton < TkCheckbutton
+ class CheckButton < TkCheckButton
TkCommandNames = ['::blt::tile::checkbutton'.freeze].freeze
end
- CheckButton = Checkbutton
+ Checkbutton = CheckButton
end
end
diff --git a/ext/tk/lib/tkextlib/blt/tile/radiobutton.rb b/ext/tk/lib/tkextlib/blt/tile/radiobutton.rb
index 7573aa08d6..2316923b19 100644
--- a/ext/tk/lib/tkextlib/blt/tile/radiobutton.rb
+++ b/ext/tk/lib/tkextlib/blt/tile/radiobutton.rb
@@ -9,9 +9,9 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
- class Radiobutton < TkRadiobutton
+ class RadioButton < TkRadioButton
TkCommandNames = ['::blt::tile::radiobutton'.freeze].freeze
end
- RadioButton = Radiobutton
+ Radiobutton = RadioButton
end
end
diff --git a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb
index abd23299a8..46ca389db2 100644
--- a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb
@@ -87,7 +87,7 @@ class Tk::Iwidgets::Checkbox
def get(idx)
simplelist(tk_call(@path, 'get', index(idx))).collect{|id|
- Tk::Itk::Component.id2obj(id)
+ Tk::Itk::Component.id2obj(self, id)
}
end
diff --git a/ext/tk/lib/tkextlib/iwidgets/radiobox.rb b/ext/tk/lib/tkextlib/iwidgets/radiobox.rb
index d4316754f2..1a2821bd6a 100644
--- a/ext/tk/lib/tkextlib/iwidgets/radiobox.rb
+++ b/ext/tk/lib/tkextlib/iwidgets/radiobox.rb
@@ -87,7 +87,7 @@ class Tk::Iwidgets::Radiobox
def get(idx)
simplelist(tk_call(@path, 'get', index(idx))).collect{|id|
- Tk::Itk::Component.id2obj(id)
+ Tk::Itk::Component.id2obj(self, id)
}
end
diff --git a/ext/tk/lib/tkextlib/tcllib/tablelist.rb b/ext/tk/lib/tkextlib/tcllib/tablelist.rb
index 42435a1971..efeb8fbbac 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')
- requrie 'tkextlib/tcllib/tablelist_core'
+ require 'tkextlib/tcllib/tablelist_core'
end
diff --git a/ext/tk/lib/tkextlib/tile/dialog.rb b/ext/tk/lib/tkextlib/tile/dialog.rb
index f8ddf62598..b10378d7de 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'))
+ window(tk_call_without_enc('::ttk::dialog::clientframe', @path))
end
def cget(slot)
diff --git a/ext/tk/lib/tkextlib/version.rb b/ext/tk/lib/tkextlib/version.rb
index 3f2f83027e..c7816fd4a5 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 = '2006-11-07'.freeze
+ Tkextlib_RELEASE_DATE = '2007-05-26'.freeze
end
diff --git a/ext/tk/sample/images/teapot.ppm b/ext/tk/sample/images/teapot.ppm
index 78afefbf82..b8ab85f3a5 100644
--- a/ext/tk/sample/images/teapot.ppm
+++ b/ext/tk/sample/images/teapot.ppm
@@ -1,8 +1,7 @@
P6
256 256
255
-\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À[7 eOLjQLmSMoTMnSMlRMhPL_9 \À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀnSMtVMzYN~[N~[N\N\O€\O€]O€]O€]O€]O€\O€\O}[NyYNtVM\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀG-wXN}[N€]O„^O†_O†`O‡`Oˆ`Oˆ`OˆaO‰aO‰aO‰aO‰aO‰aO‰aOˆaOˆ`O†_Oƒ^O\N \À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀaMLyYN…_O‰aP‹bPcPŽcPŽdPŽdPdPdPdPdPdPdPdPeP‘eP’eP’eP‘ePdPcP…_OpUM\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀwXN…_OdP“fP•gQ–hQ˜hQ˜iQ™iQ™iQšiQšiQšjQ›jQ›jQœjQœjQœjQœjQœjQ›jQœjQ™iQ“fP‡`O\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀNCJiQL‹bP—hQkQ¡mR¤nR¥oR¥oR¥oR¥oR¥oR¥oR¦oR¦oR¦pR¨pS©qSªqS«rS¬rS«rS©qS¤oRœjQ€]O\KK\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀfOLrUMcPŸlR©qS¯tS²uTµwT·xT¸xT¹yTºyT»zT»zU¼zU¼zU¼zU»zUºyT¸xT¶wT¯tS¡mR‰aOhPL\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\Àa0 cNLqUM€\O”fQ¦pS²wVºzV¿|VÂ}VÄVÆVÇ€VÉ‚WÌ…[Õeæ w÷³‹êª…Ĉg§qT“fQ{ZNYIK9\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀO1{G#‘JkRMqUMtVN–iS¨v\·€d¹bµzZ±vU°uT®sSªqS¤nRœjQ’eP„^OrUMHh>!T4\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀG-V5wE"~I#†M%U+¥e7²l:°g2®b*­a(­`(©^(¥])¡^-›]1ŠS,qC$`9 R3G-\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À@)J/i>!pA"tD"wF$yH&xH&tE$wE#yG%}M+ƒT4S5mE*Z7!K/B*;'\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À‰aO¦oR½{UÇ€VÏ…X<(F-a: e<!h>!j@#k@$h>"d<!c=$hD-fF2[<)K0@);'5$Ë‚VÇ€V¿|U_LKYIK\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À…_O·xTÉ‚Wó«€ûµ‹Ö’k¼|X×>µf-¨^(¡Z'šW&–T&œN>)F-J/b; g>#nD(jB&c<!b=%jH2_A/I0!<(8&5$”J¥Y’S%8&;'?)E,<:HA=HE?IJAISFJYIKXIK\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À£nRÁ}UܘqÊŠe±vU²e,™V&¥V†C
-€@ |> y< u: r9 o7 l6
+\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À[7 eOLjQLmSMoTMnSMlRMhPL_9 \À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀnSMtVMzYN~[N~[N\N\O€\O€]O€]O€]O€]O€\O€\O}[NyYNtVM\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀG-wXN}[N€]O„^O†_O†`O‡`Oˆ`Oˆ`OˆaO‰aO‰aO‰aO‰aO‰aO‰aOˆaOˆ`O†_Oƒ^O\N \À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀaMLyYN…_O‰aP‹bPcPŽcPŽdPŽdPdPdPdPdPdPdPdPeP‘eP’eP’eP‘ePdPcP…_OpUM\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀwXN…_OdP“fP•gQ–hQ˜hQ˜iQ™iQ™iQšiQšiQšjQ›jQ›jQœjQœjQœjQœjQœjQ›jQœjQ™iQ“fP‡`O\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀNCJiQL‹bP—hQkQ¡mR¤nR¥oR¥oR¥oR¥oR¥oR¥oR¦oR¦oR¦pR¨pS©qSªqS«rS¬rS«rS©qS¤oRœjQ€]O\KK\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀfOLrUMcPŸlR©qS¯tS²uTµwT·xT¸xT¹yTºyT»zT»zU¼zU¼zU¼zU»zUºyT¸xT¶wT¯tS¡mR‰aOhPL\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\Àa0 cNLqUM€\O”fQ¦pS²wVºzV¿|VÂ}VÄVÆVÇ€VÉ‚WÌ…[Õeæ w÷³‹êª…Ĉg§qT“fQ{ZNYIK9\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀO1{G#‘JkRMqUMtVN–iS¨v\·€d¹bµzZ±vU°uT®sSªqS¤nRœjQ’eP„^OrUMHh>!T4\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀG-V5wE"~I#†M%U+¥e7²l:°g2®b*­a(­`(©^(¥])¡^-›]1ŠS,qC$`9 R3G-\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À@)J/i>!pA"tD"wF$yH&xH&tE$wE#yG%}M+ƒT4S5mE*Z7!K/B*;'\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À‰aO¦oR½{UÇ€VÏ…X<(F-a: e<!h>!j@#k@$h>"d<!c=$hD-fF2[<)K0@);'5$Ë‚VÇ€V¿|U_LKYIK\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À…_O·xTÉ‚Wó«€ûµ‹Ö’k¼|X×>µf-¨^(¡Z'šW&–T&œN>)F-J/b; g>#nD(jB&c<!b=%jH2_A/I0!<(8&5$”J¥Y’S%8&;'?)E,<:HA=HE?IJAISFJYIKXIK\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À£nRÁ}UܘqÊŠe±vU²e,™V&¥V†C €@ |> y< u: r9 o7 l6
j5
h4
g3
@@ -13,44 +12,20 @@ f3
a0 _/ ]. [- I¡\*ª_(‘LkRMmSMmSMnSMnSMD,R3W5mA"|O0|P1j?"c<!a=%Y7"N1F,;'NCJNCJNDJODJODJODJh>!a: X/K%
g3
a0 Z- \/ T*Q(ŠHµm8kRMmSMnTMoTMpTMpUM15G15G05G04G04GpUMpTM5^9 d<!yF#O+€N,rC#qB"pB#k?"a: Z7 6ODJPDJPEJQEJQEJREJREJREJRFJSFJSFJSFJSFJe<!X/
-^/ V+Q(L&I$r9  TlRMnSM46G47G47G46G46G46G46G46G36G36G25G25G15G04G/4F.3F
-ˆ`O~[NqUM[- ‰HUGJUGJVGJVGJVHJWHJWHJWHKWHKXHKXHKXHKXHKXHKXIKXIKXIKXIKXIKh>!Y0
-
-L&C!:4
+^/ V+Q(L&I$r9  TlRMnSM46G47G47G46G46G46G46G46G36G36G25G25G15G04G/4F.3F
+
X&pUMuWMwXNxXN<:H<:H<:H<:H<;H<;H<;H<;H=;H=;H=;H=;H>;H>;H?<H@<HA=HC>HG@ILBIREJ[JKcNLjQL§pR±uTºzUÃ~VÈWË‚XÖŽcäsÒŽe¼{V²vT¨pSžkR•gQŒbP†_O‚^O]O€\O€\O€\O€\O€]O]O]O]O]O]O]O]O]O]O]O€\O€\O~\N}[N|ZNxXN•T%H$
-›W&rVMvWNyYNzYN|ZN}[N}[N><H?<H?<H?<H?<H?<H@<H@<H@<HA=HA=HB=HC>HE?IG@IIAIKBIODJSFJWHK—hQŸlR§pR°b(¾i*Én+Ù|7Û|6Ïr,Íq+Êp-Ãl+»g)±b(®sS§pS lRšiQ•gQePcPŠaPˆaO‡`O‡`O†_O†_O…_O…_O…_O…_O…_O…_O…_O„_O„^O„^Oƒ^Oƒ^O‚]O]O€\O~[N{ZN•T%
-
-
+›W&rVMvWNyYNzYN|ZN}[N}[N><H?<H?<H?<H?<H?<H@<H@<H@<HA=HA=HB=HC>HE?IG@IIAIKBIODJSFJWHK—hQŸlR§pR°b(¾i*Én+Ù|7Û|6Ïr,Íq+Êp-Ãl+»g)±b(®sS§pS lRšiQ•gQePcPŠaPˆaO‡`O‡`O†_O†_O…_O…_O…_O…_O…_O…_O…_O„_O„^O„^Oƒ^Oƒ^O‚]O]O€\O~[N{ZN•T%
 
@%<-$G?@…pfdNLuWM\NdNL\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀTFJvWN‰aP./01„E}[N]O…_Oˆ`O‰aP‹bPŒbPcPcPŽcPdPdPdPeP‘eP’eP’eP“fP“fQ”fQ•gQ•gQ–gQ–hQ—hQ˜hQ™iQšiQ›jQœjQkQkRžlRŸlRžY&¤\'¨^'µ^½bÀcÃeÇi ÄgÀc½b¼a¹`µ^´]¯X¢[' Z'žY&¢mR¡mR¡mR lRŸlRŸlRžkRkQœkQœjQ›jQšjQšiQ™iQ™iQ˜iQ˜hQ—hQ—hQ—hQ–gQ–gQ•gQ•gQ•gQ”fQ”fQ“fQ“fP’eP‘ePdPcP‰aP—O
 B\À\À\À\À\À\À\À\À\À\À%7!!C*F#P) {dYœze»p€\OgPL\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀSFJ`LKvWNŠaPm6
- 
-\À\À\À\À\À\À\À\À\À B B
-$5 ¬`(¶e)£nRœjQƒ^OJAI\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀXIK^KKdNLhPLuWM‚]OŒbP”fQeP
-m6
-†`OŽcP“fQ—hQ˜hQ™iQšiQšjQ›jQ›jQ›jQœjQœjQœjQœkQkQkQkRžkRžkRžkRžlRŸlRŸlRŸlR lR lR lR¡mR¡mR¡mR¡mRºg)³c(²c(±b(­V¿cÂeÅi!Åi!Àd¼bº`¹`·_·_¶^¢Q§]'ª_(­`(¹f)£nR£nR£nR£nR£nR£nR£nR¢nR¢nR¢nR¢nR¢nR¢nR¢mR¢mR¢mR¢mR¢mR¢mR¢mR¢mR¢mR¢nR¢mR¢mR£nR¢mR¢mR¡mR mRkR—hQˆGa0 ŠbP mRœjQ“fQ‰aP}[NrUMmSM…L$\À\À\À\À\À\À\À\À B B
-#C, 8&H.Z7 §pR›jQ{ZN\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀQEJ[JK`LKdNLhQLqUM{ZN…_OŽcP–gQ—hQ
-‹bP‘eP–hQšiQ›jQœjQkQkQkRžkRžkRžlRžlRŸlRŸlRŸlRŸlRŸlR lR lR lR mR¡mR¡mR¡mR¡mR¡mR¢mR¢mR¢mR¢nR£nRÀj*ºg)·e)¶d)Âd°XÅgÅhÂe¿c½b½b¾bªU­`(®a(¯a(³c(¾i*¤oR¤oR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤oR¤oR¥oR¥oR¥oR¥oR¥oR¥oR¦oR¦oR¥oR¥oR¤nR¡mR›jQŽQ%Z- œjQ£nRŸlR—hQŽdP…_OuWMpTMnSMkRLa: \À\À\À\À\À\À\À B B&D2
-@*S6#G@IPDJ˜hQmSM\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀVGJ]KKbMLeOLiQLlRMvWN\OˆaO‘eP—hQœjQ•gQ
-\À\À\À\À\À B'D+E$(1 J/jH1NCJUGJYIKUGJ\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀXHK]KKbNLfOLiQLkRMmSMoTMqUMxXN\N†_OŒbP’fP˜hQkQ¡mR¥oR§pS¦pR˜hQ¢mR¥oR¨pSªqS«rS«rS«rS«rS«rS«rS«rS«rS«rS«rS«rSªrSªrSªrS«rS«rS«rS«rS«rS«rS«rS«rS«rS«rS«rS«rS«rS«rS«rS«rS¬rS¬rS¬rS¬rS¬rS¬rS¬rS¬sS¬sS­sS­sS­sS­sS­sS­sS®sS®sS®sS®sS®tS¯tS°tS°uS±uS±uT±uT²uT²uT²uT´vTµwT´vT³vT²uT¯tS¢mR¯tS±uT±uS®tS«rS§pR¢mRkQ—hQ‘ePŠaPƒ^O\N{ZNvXNqUMpTMnSMlRMP%\À\À\À\À B#C*E$.E- .!G$Y:%d<"SFJYIKZIKNCJ\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀPDJZIK_LKdNLgPLjQLlRMnSMpTMqUMuWMyYN€\O†`OcP’fP—hQœjQ¡mR¥oR¨qS«rS«rSªrS mR
+ 
+$5 ¬`(¶e)£nRœjQƒ^OJAI\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀXIK^KKdNLhPLuWM‚]OŒbP”fQeP m6
+†`OŽcP“fQ—hQ˜hQ™iQšiQšjQ›jQ›jQ›jQœjQœjQœjQœkQkQkQkRžkRžkRžkRžlRŸlRŸlRŸlR lR lR lR¡mR¡mR¡mR¡mRºg)³c(²c(±b(­V¿cÂeÅi!Åi!Àd¼bº`¹`·_·_¶^¢Q§]'ª_(­`(¹f)£nR£nR£nR£nR£nR£nR£nR¢nR¢nR¢nR¢nR¢nR¢nR¢mR¢mR¢mR¢mR¢mR¢mR¢mR¢mR¢mR¢nR¢mR¢mR£nR¢mR¢mR¡mR mRkR—hQˆGa0 ŠbP mRœjQ“fQ‰aP}[NrUMmSM…L$\À\À\À\À\À\À\À\À B B #C, 8&H.Z7 §pR›jQ{ZN\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀQEJ[JK`LKdNLhQLqUM{ZN…_OŽcP–gQ—hQ
+‹bP‘eP–hQšiQ›jQœjQkQkQkRžkRžkRžlRžlRŸlRŸlRŸlRŸlRŸlR lR lR lR mR¡mR¡mR¡mR¡mR¡mR¢mR¢mR¢mR¢nR£nRÀj*ºg)·e)¶d)Âd°XÅgÅhÂe¿c½b½b¾bªU­`(®a(¯a(³c(¾i*¤oR¤oR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤nR¤oR¤oR¥oR¥oR¥oR¥oR¥oR¥oR¦oR¦oR¥oR¥oR¤nR¡mR›jQŽQ%Z- œjQ£nRŸlR—hQŽdP…_OuWMpTMnSMkRLa: \À\À\À\À\À\À\À B B&D2 @*S6#G@IPDJ˜hQmSM\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀVGJ]KKbMLeOLiQLlRMvWN\OˆaO‘eP—hQœjQ•gQ
!C+E'0F.4F7%8%U/lG.SFJZIK]KKZIKB=H\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀREJZJK`LKdNLgPLjQLlRMnSMpTMqUMtWMxXN{ZN~[N]O„^O†`O‰aO‹bPdP•gQ™iQœkQ lR¤nR§pSªrS­sS¯tT²uT´vT¶wT·xT¹yT¹yTºyTºyT¹yT¶xT´vT¬rS¢nR—hQ¿|U¿|UÀ|UÀ|UÀ|UÀ|UÀ|UÀ|UÀ|UÀ|UÀ|UÀ|UÀ|UÀ|UÀ}UÀ}UÁ}UÁ}UÁ}UÁ}UÂ}UÂ~UÃ~UÃ~VÃ~VÄVÅ€WÆX®a(ŸlRªrS´vT¸yT¼zU¾|UÁ~VÃXÆ‚[Ɇ_΋dÓ‘jÔ“mÔ“nБlÊŒhĆd½_¶{[°vWªsU¦pS¢nRžkRšiQ˜hQ•gQ“fQ‘ePdPŒbP‰aO†_Oƒ^O€\O|ZNxXNsVMpTMnTMmSMjQL€C B)D&/F-3F47G6%>" Y7 kA$YIK]KK^KKSFJ\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀVGJ\KKbMLeOLhPLkRLmSMnTMpTMrUMuWNyYN|ZN\N‚]O„_O‡`OŠaPŒbPŽcPeP“fP—hQ›jQžlR¢nR¥oS©qT¬sT¯uU²vU´wV¶xV¸yV¹yUºzU»zU¼{U½{U¾{U¾|U¿|U¿|U¿|U¿|U¾{U½{U¼{U¼zU»zTºyT¹yT¸xTµwT³vT´vT´vT´vT´wT´wTµwT·xT¹yTºzT¼zU½{U¾{U¿|UÀ|UÂ}UÄVÅ€WÇ‚YÉ„\͈_ÑŒdÙ”láuç£|쩂ſt명æ¦ÞŸ{Õ—sËŽl†d¹^³yZ­uW¨qU¤oSŸlRžkRœjQšiQ˜hQ–gQ”fQ‘ePdPcPŠaP‡`O„^O]O}[NyYNuWMpTMoTMmSMkRLgPL&D#.E,3F46G;'<(D"iB(VGJ]KK`LK[JKB>H\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀNCJYIK^LKcNLfOLiQLkRMmSMoTMqUMsVMvXNzYN}[N€\O‚^O…_Oˆ`OŠaPŒcPdP‘eP“fQ•gQ—hQ™iQkR mS¤oT¨rU¬tW°wY´zZ¸}\»]¾€^À^Á‚^‚^Â\Á€ZÁYÁXÁ~WÁ~WÂ~VÂ~VÂ~VÃ~VÃ~UÃ~UÄ~UÄ~UÄUÄUÅVÅVÅVÅVÆVÆ€VÆ€VÇ€WÇWÈ‚XɃZË…[͇^ЊaÓdØ’iÜ—nâtè£zî©ó¯‡ø´û¸‘üº“û¹“÷¶ñ±Œé©…à¡~Ö˜vËmÇf»€`´z[®vX©rU¥pT£oS¢nS lRžkRœkRšjQ˜iQ–hQ”fQ’ePdPcP‹bPˆ`O…_O‚]O~[NzYNvWNpTMoTMnSMkRMhQLo7 ,2F36G99HC+@ ]8 nA"\JK`ML_LKSFJ\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀSFJ[JK`LKdNLgPLjQLlRMnSMpTMqUMtVMwXNzZN}[N€]Oƒ^O†_OˆaO‹bPcPdP‘eP“fQ•gQ—hQ™iQ›jRžlR mS£oU§rW¬vZ²{]¹€a¿…fÅŠjËnГqÓ•sÕ–sÕ–rÕ–qÕ”oÓ’mÑjÏgÍŠcˈaɆ^È„\Ç‚[ÆYÅ€XÅ€WÅWÅWÅVÅVÅWÅ€WÆ€WÇXÈ‚YɃ[Ê…\͇_ÏŠaÒeÕ‘hÙ•mÝ™qávä¡zç¤}꧀멃몄騃奀ߠ|Ù›wÓ•rÌmƉh¿„c¸~^²yZ®vX¬tWªsV¨qU¦pT¤oS¢nS mRžlRœkR›jQ™iQ—hQ•gQ“fPePŽcP‹bPˆaO…_O‚^O\N{ZNwXNsVMoTMnSMlRMiQL~I#26G99G?<HA*E$ i@$ZIKaMLbML[JK;:H\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀWHJ]KKbMLeOLhPLjRLlSMnTMpTMrUMuWMxXN{ZN~\N]O„^O†`O‰aO‹bPŽcPdP’eP”fQ–gQ˜hQšiQœkRžlS mT£oU¦rWªuZ¯y]´~aºƒfŠlË’sÔšzÜ¡€ã§†è«‰ë®‹í¯Œí®‹ë¬ˆè¨„ã£~ßžyÚ™tÖ•oÒjÎŒfˈbÈ…_ƃ\ÅZÄ€YÃXÂWÂ~WÂ~WÂ~WÃXÀXÄ€YÅZƃ\Ç…^Ɇ`ˈbÌŠdÍ‹fÎgÎŽiÎŽjÎŽjÍŽjËŒiljgÆd¿ƒaº^¸}]¶|\´{[²yZ°xY®vX¬tWªsV¨qU¦pT¤oS¢nS mRžlRkR›jQ™iQ—hQ•gQ“fP‘ePŽdPŒbP‰aO†_Oƒ^O€\O|ZNxXNtVMpTMnSMmSMjQLgPL99G?<HG-E&b;!YIK`MLdOM`LKNCJ\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀŸlRºyTÄ~UÊ‚XʃYÄXº{W­tUšW'¢[(—hQ lRcP€\OhQL\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀNCJYIK^LKcNLfOLiQLkRLmSMoTMqUMrVMvWNyYN|ZN\N‚]O„_O‡`O‰aPŒbPŽcPdP’fP”gQ–hQ˜iQšjRœkRžlS¡nT¤pU§sW«vZ°z]µb»„gŠlÉ‘sИyØžÞ¤…㩊è­ì±ï³‘ﳑ뭊穅⣀ݞzؘtÒ“nÎiɉdÆ…`Â]Á€[¿~Y¾}X½|W½|V¼{V¼{V¼{V¼{V¼{V¼|W¼|W½}X½}Y½~Z½~Z¼~Z»}[º}[º}[º~\º~\º~]º~]¹~]¸~]·}]¶|\´z[²yZ°wY®vX¬tWªsV¨rU¦pT¤oS¢nS mRŸlRkR›jQšiQ˜hQ–gQ“fQ‘ePdPŒcPŠaP‡`O„^O]O}[NyYNuWNpTMnTMmSMkRLhPL|H$D>IQ2P+XHK_LLfQOcNLXIK\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À©qSºyTÃ~VΈ`遲ޜv¾€]ªqS–LŽG|> g3
-S)?*%.—hQ—hQ‘eP‡`OuWM\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀSFJ[JK`LKdNLgPLjQLlRMnSMoTMqUMsVMwXNzYN}[N€\O‚^O…_O‡`OŠaPŒbPŽdP‘eP“fP•gQ—hQ˜iQšjRœkRŸlS¡nT¤pV§sX«vZ°z^¶b¼…gËmÊ’sјzØŸ€Þ¤…㩊è­ê¯ë°ê¯Žè¬‹å¨‡à¤‚Ûž|Ö™wÑ“qÌŽlljgÃ…bÀ‚_½\»}Zº{X¹zW¸yV·yU·xU·xU·xT·xT·xU·xU·xU·yV·yV·yW¸zW¸{X¹{Y¹|Zº}[º}[º}\º~\¹~]¹~]¸}]·|\µ{\´z[²yZ°wY®vX¬tWªsV¨rU¦pT¤oS¢nS¡mRŸlRkRœjQšiQ˜hQ–gQ”fQ’ePdPcPŠbP‡`O…_O‚]O~[NzZNvWNrUMoTMmSMlRMiQLeOLJAIJ(h>!]KKfQOgQN_LKD>I\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À™iQ°tS¸yT¼{UÂYÎŒeï­ˆô´Õ—u¶|\ Z'™LˆD
-|>
-
-+,!.! "`E6†iYŒlZo\“q]•s^^J™va›wbycŸzd {e¤}foTMqUMsVMuWNwXNyYN{ZN|ZN~[N\O]O‚]Oƒ^O…_O†_O‡`Oˆ`O‰aOŠaP‹bPŒbPŒcPcPŽcPŽdPdPdPdPeP‘eP‘eP‘eP’eP’eP’eP’eP’fP’fP’fP“fP’fP’fP’fP’eP’eP’eP‘eP‘eP‘ePePdPdPdPŽdPŽcPcPŒcPŒbP‹bPŠaP‰aOˆ`O‡`O†_O…_Oƒ^O‚]O]O\O~[N|[N{ZNyYNwXN®ƒi¬ƒiª‚i¨i¦€hŒhR‰fQ†dQ‚bP•wfx]Oˆpdkbtd_m`]OEDG?A;:@.S….S….S….S….S…/S…/S…/S…/S…/S…/S…/S…/S…TxªTxªTxªTxªTxªTx«Tx«Tx«Ty«/S†GlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlž…ªÜ…ªÜ…ªÜHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlž…ªÜ…ªÜ£Ö£Ö£Ö£Ö¤Ö¤Ö¤Ö¤Ö¤ÖEi›€¤Ö€¤Ö€¤Ö€¤Ö€¤Ö€¤Ö€¤Ö€¤Ö€¤Ö€¤Ö€¤Ö€¤Ö€¤×€¤×€¤×€¤×€¥×€¥×€¥×Bg™Bg™Bg™Bg™Bg™&J|&J|&J|&J|&J|&J|&J|&J|&J|&J|&J|&J|&J|Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Af˜Af˜%J|%J|%J|%J|%J|%J|%J|%J|%J|%J|%I|%I|%I|%I|%I|%I|
-+,YA5jPBpSD‹l[o]’q^–t`‚_Kšwbœycžze {f¡}g¤h¨i”lSrVMtWMvWNxXNyYN{ZN|[N~[N\O]O‚]Oƒ^O„_O…_O†`O‡`Oˆ`O‰aPŠaP‹bP‹bPŒbPcPcPŽcPŽcPdPdPdPdPdPdPdPdPePePePePePdPdPdPdPdPdPdPŽcPŽcPcPcPŒbP‹bP‹bPŠaP‰aOˆ`O‡`O†`O…_O„^Oƒ^O‚]O€]O\O~[N|[N{ZNyYNxXN°…j®„j¬„jªƒj¨‚j¦€jŒhSŠgS†eRƒcR|`QŒsf…oe}jcrd`k_]LCDC=@,,3(4F(4F.S….S…/S…/S…/S…/S…/S…/S…/S…TxªTxªTxªTxªTxªTxªTx«Tx«Tx«Ty«Ty«Ty«…ªÜHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlž†ªÜHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžChšChš¤Ö€¤Ö€¤Ö€¤Ö€¤ÖEi›Ei›Ei›€¤Ö€¤Ö€¤Ö€¤Ö€¤Ö€¤Ö€¤×€¤×€¤×€¤×Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Bg™Bg™&J|&J|&J|&J|&J|&J|&J|&J|&J|&J|Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜&J|%J|%J|%J|%J|%J|%J|%J|%J|%J|%J|%J|%I|%I|%I|%I|%I|#5H71O;3V?4iOBoSDsVFo]{[I^Kƒ`L…bN‡dOŸ{f }g¢~h¥€j’kT•mU˜oVšqWrWwXNxXNzYN{ZN}[N~[N\O€]O‚]Oƒ^O„^O…_O…_O†`O‡`Oˆ`O‰aO‰aPŠaP‹bP‹bPŒbPŒbPŒcPcPcPcPŽcPŽcPŽcPŽcPŽcPŽcPŽcPŽcPŽcPŽcPcPcPcPŒcPŒbP‹bP‹bP‹bPŠaP‰aP‰aOˆ`O‡`O†_O…_O„_O„^Oƒ^O]O€\O\N~[N|ZN{ZNyYN›oTšoT™oT—nT¬„lªƒl¨‚ljUŒiTŠhT†fT€cSvi‰rgnfyidqdah^^HBD?<@)+3OZkMYk(5F(5F(5F/S…/S…/S…/S…/S…TxªTxªTxªTxªTxªTxªTx«Tx«Ty«Ty«Ty«Ty«Uy«†ªÜ†ªÜ†ªÜ†ªÜHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlž†ªÜ†ªÜ†ªÜ†ªÜ†ªÜHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžHlžDhšDhšDhšChš&K}&K}&K}&K}&K}&K}ChšChšCgšCgšCgšCgšCgšCgšCg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™&J|&J|&J|&J|&J|&J|Bg™Bg™Bg™Bf™Bf™Bf™Bf™Bf™Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜&J|&J|&J|&J|%J|%J|%J|%J|%J|%J|%J|%J|%J|%J|%J|%I|%I|A99N?;L:2T>4gNBlRD‡k\‹n^z[J~^LaN…cO‡dP‰fQŠgRŒhTjU’lV•nW˜pXšrXsY¶‹q¸qºŽr¼r½r¿s©z[©z[ªz[«{[¬{[¬{ZÅ“rÅ’qÅ’qÅ’pÅ’pÅ‘o­yV­xV¬xU¬wT¬wTŠaPŠbP‹bP‹bP‹bP‹bP‹bP‹bP‹bP‹bP‹bP‹bP‹bP‹bPŠaPŠaPŠaP‰aP‰aOˆaOˆ`O‡`O‡`O†_O…_O„^Oƒ^O‚^O‚]O]O€\O~\N}[N|ZNzYNpTœpU›pUšpU˜oV—oV•nV“mV‘lVkVŒjVˆhVƒfU~cUuj†qh~mfugdkaad\^E@D98?$(2minffm^blV^lMYk(5F(5F/S…TxªTxªTxªTxªTxªTxªTxªTx«Tx«Ty«Ty«Ty«Uy«Uy«†ªÜ†ªÜ†ªÜ†ªÜ†ªÜ†ªÜ†ªÜ†ªÜHlžHlžHlžHlžHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸ†ªÝ†ªÝ†ªÝ†ªÝ†ªÝ†ªÝ†ªÝ†ªÝ†ªÝ†ªÝHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸHlŸ'K}'K}'K}'K}'K}'K}'K}'K}'K}&K}&K}ChšChšChšChšChšChšChšCgšCgšCgšCgšCgšCgšCg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™&J|Cg™Cg™Cg™Cg™Cg™Bg™Bg™Bg™Bg™Bg™Bg™Bf™Bf™Bf™Bf™Bf™Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜Bf˜&J|&J|&J|&J|&J|&J|&J|%J|%J|%J|%J|%J|%J|%J|Ae˜Ae˜;GY<68I=:I82Q=4XA6~fZ„j\‰m^p`|]L€`NƒcP†eQˆgS¡j£€l¦‚m©„n•oX˜qYšrZt[¶Œr¸sºs¼t½t¾‘t¨z]©{]ª{]«{\«{\¬{\¬{[Ä“sÄ“rÄ’rÄ’qÄ’pÄ‘p¬yWÄoÃnÃmÃlÂŽlÂŽkÁkˆaOˆaOˆaOˆaOˆaOˆaOˆaOˆ`Oˆ`O‡`O‡`O‡`O†`O†_O…_O…_O„_O„^Oƒ^O‚]O]O€]O\O~\N}[N|ZN¶‰l¶‰lµˆmœqV›qVšqV™pW˜pW–oW¬…nª…n§„n¤‚nŸ€n›~n€eW‘xlŠtk‚piykfodcf_`JDG@>C*,5$1MYktr~tstmolinadmX_lNZkMZkTxªTxªTxªTxªTx«Tx«Tx«Ty«Ty«Ty«Uy«Uy«Uy«†ªÝ†ªÝ†ªÝ†ªÝ†ªÝ†ªÝ†«Ý†«Ý†«Ý†«ÝHlŸHlŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸ†«Ý†«Ý†«Ý‡«Ý‡«Ý‡«Ý‡«Ý‡«Ý‡«Ý‡«Ý‡«Ý‡«Ý‡«ÝHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸHmŸ'K}'K}'K}'K}'K}'K}'K}'K}'K}'K}'K}'K}DhšDhšDhšDhšChšChšChšChšChšChšChšCgšCgšCgšCgšCgšCgšCg™Cg™Cg™Cg™Cg™&J}&J}&J}Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Cg™Bg™Bg™Bg™Bg™Bg™Bg™Bf™Bf™Bf™Bf™Bf˜Bf˜Bf˜Bf˜Bf˜&J|&J|&J|&J|&J|&J|&J|&J|&J|&J|Af˜Af˜Af˜Af˜;GY;GY;GY1'!D:9N?;N;3]I?zdY€h[†l^‹oasc“ue€bQ„dR‡fT l¢m¦ƒn©…o«‡p®ˆq±Šr³‹sžv] w]¹u»u¼‘u¾‘u¿’v¨{^©{^ª|^«|]«|]«{\¬{\¬{[¬{[¬zZ«zZ«yY«yX«xXÂoÂnÂnÁŽmÁŽm¨uT¨uS§tS§tS§tR¦sR¦sQ…_O…_O…_O„^O„^Oƒ^Oƒ^O‚^O‚]O]O€]O¢rS¡rS¡rS¸‰k·‰l·‰l¶‰m¶‰mµ‰m´‰n³‰n›qWšqX™qX®‡o­‡o«†p¨…p¤ƒp pœp—}o{cXv`Vp]U}nishfhaba\_DAF::B$)4
-., 7(8'A1&F4(L8*oXIw]Jpdasfcvhexkg{mi~oj€qll\Xn^Yp`Zpa[qa\rb]rc^sc^sd_ue`wf`xgayhayhayhbxy‘y‘y‘y‘yy~ywgbvfateasd`qd`pc`nb_la_€ut|ssxqrunpZUXVRWROUMMSHIRIC@967-/3'+0(*-ACF?AD;=@#%(
-.+>1(B3)B2&F4'E4)gTGlXJs^OzcTzaPqfethgvjhbVTcWUdXVeYWfZXg[Yh\Zi]Zi][j^\€us€ususts~tt~tt}tt|st{stut~tt|sszrsyqrwpquoqsmpqloXTXTQWPOULLSSJEA<:=99757335./2113)+.'),)+.8:="(
-"6*#5*">2)>0&A2'C3(I8-^OFbRHfUJjXMq^RwcVzfYfRDfQCdN@zdTqijrjksklrklrklrklqjmpjmpjmojmojmnimmimkhliflscYm`Xg\VbYT^VRE>;A<:>98:77645:873220/0,-/)+.*,/#%( &
-
-&3#.$-% .% .& /&!,#,#@70A71XNHXNHWNHWNHZRLYQLYQLXQLWQLWPLUOLSNLQMKOLJMJJ0//.-.,,-&(+"(!'
-
- %' %$#" ! !$
-
-
- 
-
-
-*  
-  ;?E7CU;HY=I[ 
+S)?*%.—hQ—hQ‘eP‡`OuWM\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\ÀSFJ[JK`LKdNLgPLjQLlRMnSMoTMqUMsVMwXNzYN}[N€\O‚^O…_O‡`OŠaPŒbPŽdP‘eP“fP•gQ—hQ˜iQšjRœkRŸlS¡nT¤pV§sX«vZ°z^¶b¼…gËmÊ’sјzØŸ€Þ¤…㩊è­ê¯ë°ê¯Žè¬‹å¨‡à¤‚Ûž|Ö™wÑ“qÌŽlljgÃ…bÀ‚_½\»}Zº{X¹zW¸yV·yU·xU·xU·xT·xT·xU·xU·xU·yV·yV·yW¸zW¸{X¹{Y¹|Zº}[º}[º}\º~\¹~]¹~]¸}]·|\µ{\´z[²yZ°wY®vX¬tWªsV¨rU¦pT¤oS¢nS¡mRŸlRkRœjQšiQ˜hQ–gQ”fQ’ePdPcPŠbP‡`O…_O‚]O~[NzZNvWNrUMoTMmSMlRMiQLeOLJAIJ(h>!]KKfQOgQN_LKD>I\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À\À™iQ°tS¸yT¼{UÂYÎŒeï­ˆô´Õ—u¶|\ Z'™LˆD |>
+
+ &3#.$-% .% .& /&!,#,#@70A71XNHXNHWNHWNHZRLYQLYQLXQLWQLWPLUOLSNLQMKOLJMJJ0//.-.,,-&(+"(!'
+ %' %$#" ! !$ 
diff --git a/ext/tk/sample/irbtkw.rbw b/ext/tk/sample/irbtkw.rbw
index 92fa5692f2..f6a35be6ed 100644
--- a/ext/tk/sample/irbtkw.rbw
+++ b/ext/tk/sample/irbtkw.rbw
@@ -26,7 +26,11 @@ console.yscrollbar(TkScrollbar.new(top, :width=>10).pack(:before=>console,
:side=>:right,
:expand=>false,
:fill=>:y))
-ev_loop = Thread.new{Tk.mainloop}
+irb_thread = nil
+ev_loop = Thread.new{
+ Tk.mainloop
+ irb_thread.kill if irb_thread
+}
# window position control
root = Tk.root
@@ -116,4 +120,5 @@ console.bind('Control-c'){
irb_thread.join
# exit
+ev_thread.kill
Tk.exit
diff --git a/ext/tk/sample/tcltklib/sample2.rb b/ext/tk/sample/tcltklib/sample2.rb
index 110e81ebc4..444bb1eef7 100644
--- a/ext/tk/sample/tcltklib/sample2.rb
+++ b/ext/tk/sample/tcltklib/sample2.rb
@@ -41,7 +41,7 @@ class Othello
[ 1, -1], [ 1, 0], [ 1, 1]
]
- attr_accessor :com_disk
+ attr :com_disk, TRUE
def initialize(othello)
@othello = othello
diff --git a/ext/tk/sample/tktextio.rb b/ext/tk/sample/tktextio.rb
index 0b78f45b10..4573bcebdf 100644
--- a/ext/tk/sample/tktextio.rb
+++ b/ext/tk/sample/tktextio.rb
@@ -108,7 +108,7 @@ class TkTextIO < TkText
@lineno = 0
@line_offset = 0
- @hist_max = opts['hist_size']
+ @hist_max = opts['hist_size'].to_i
@hist_index = 0
@history = Array.new(@hist_max)
@history[0] = ''
diff --git a/ext/tk/stubs.c b/ext/tk/stubs.c
index 426505f3ae..23ff42a4f4 100644
--- a/ext/tk/stubs.c
+++ b/ext/tk/stubs.c
@@ -86,7 +86,8 @@ static DL_HANDLE tcl_dll = (DL_HANDLE)0;
static DL_HANDLE tk_dll = (DL_HANDLE)0;
int
-ruby_open_tcl_dll(char *appname)
+ruby_open_tcl_dll(appname)
+ char *appname;
{
void (*p_Tcl_FindExecutable)(const char *);
int n;
@@ -140,8 +141,8 @@ ruby_open_tk_dll()
char tk_name[20];
if (!tcl_dll) {
- /* int ret = ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */
- int ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* int ret = ruby_open_tcl_dll(RSTRING(rb_argv0)->ptr); */
+ int ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
if (ret != TCLTK_STUBS_OK) return ret;
}
@@ -168,7 +169,8 @@ ruby_open_tk_dll()
}
int
-ruby_open_tcltk_dll(char *appname)
+ruby_open_tcltk_dll(appname)
+ char *appname;
{
return( ruby_open_tcl_dll(appname) || ruby_open_tk_dll() );
}
@@ -187,7 +189,8 @@ tk_stubs_init_p()
Tcl_Interp *
-ruby_tcl_create_ip_and_stubs_init(int *st)
+ruby_tcl_create_ip_and_stubs_init(st)
+ int *st;
{
Tcl_Interp *tcl_ip;
@@ -210,8 +213,8 @@ ruby_tcl_create_ip_and_stubs_init(int *st)
Tcl_Interp *(*p_Tcl_DeleteInterp)();
if (!tcl_dll) {
- /* int ret = ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */
- int ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* int ret = ruby_open_tcl_dll(RSTRING(rb_argv0)->ptr); */
+ int ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
if (ret != TCLTK_STUBS_OK) {
if (st) *st = ret;
@@ -269,7 +272,8 @@ ruby_tcl_stubs_init()
}
int
-ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
+ruby_tk_stubs_init(tcl_ip)
+ Tcl_Interp *tcl_ip;
{
Tcl_ResetResult(tcl_ip);
@@ -304,7 +308,8 @@ ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
}
int
-ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
+ruby_tk_stubs_safeinit(tcl_ip)
+ Tcl_Interp *tcl_ip;
{
Tcl_ResetResult(tcl_ip);
@@ -343,8 +348,8 @@ ruby_tcltk_stubs()
int st;
Tcl_Interp *tcl_ip;
- /* st = ruby_open_tcltk_dll(RSTRING_PTR(rb_argv0)); */
- st = ruby_open_tcltk_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* st = ruby_open_tcltk_dll(RSTRING(rb_argv0)->ptr); */
+ st = ruby_open_tcltk_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
switch(st) {
case NO_FindExecutable:
return -7;
@@ -390,7 +395,8 @@ static int open_tcl_dll = 0;
static int call_tk_stubs_init = 0;
int
-ruby_open_tcl_dll(char *appname)
+ruby_open_tcl_dll(appname)
+ char *appname;
{
if (appname) {
Tcl_FindExecutable(appname);
@@ -405,14 +411,15 @@ ruby_open_tcl_dll(char *appname)
int ruby_open_tk_dll()
{
if (!open_tcl_dll) {
- /* ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */
- ruby_open_tcl_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* ruby_open_tcl_dll(RSTRING(rb_argv0)->ptr); */
+ ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
}
return TCLTK_STUBS_OK;
}
-int ruby_open_tcltk_dll(char *appname)
+int ruby_open_tcltk_dll(appname)
+ char *appname;
{
return( ruby_open_tcl_dll(appname) || ruby_open_tk_dll() );
}
@@ -430,13 +437,14 @@ tk_stubs_init_p()
}
Tcl_Interp *
-ruby_tcl_create_ip_and_stubs_init(int *st)
+ruby_tcl_create_ip_and_stubs_init(st)
+ int *st;
{
Tcl_Interp *tcl_ip;
if (!open_tcl_dll) {
- /* ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */
- ruby_open_tcl_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* ruby_open_tcl_dll(RSTRING(rb_argv0)->ptr); */
+ ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
}
if (st) *st = 0;
@@ -458,7 +466,8 @@ ruby_tcl_stubs_init()
}
int
-ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
+ruby_tk_stubs_init(tcl_ip)
+ Tcl_Interp *tcl_ip;
{
if (Tk_Init(tcl_ip) == TCL_ERROR)
return FAIL_Tk_Init;
@@ -474,7 +483,8 @@ ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
}
int
-ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
+ruby_tk_stubs_safeinit(tcl_ip)
+ Tcl_Interp *tcl_ip;
{
#if TCL_MAJOR_VERSION >= 8
if (Tk_SafeInit(tcl_ip) == TCL_ERROR)
@@ -498,8 +508,8 @@ ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
int
ruby_tcltk_stubs()
{
- /* Tcl_FindExecutable(RSTRING_PTR(rb_argv0)); */
- Tcl_FindExecutable(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ /* Tcl_FindExecutable(RSTRING(rb_argv0)->ptr); */
+ Tcl_FindExecutable(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
return 0;
}
diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c
index 45f6a82e65..ff1f7640bd 100644
--- a/ext/tk/tcltklib.c
+++ b/ext/tk/tcltklib.c
@@ -4,7 +4,7 @@
* Oct. 24, 1997 Y. Matsumoto
*/
-#define TCLTKLIB_RELEASE_DATE "2006-07-10"
+#define TCLTKLIB_RELEASE_DATE "2006-12-01"
#include "ruby.h"
#include "rubysig.h"
@@ -126,7 +126,9 @@ static VALUE tk_funcall _((VALUE(), int, VALUE*, VALUE));
/* safe Tcl_Eval and Tcl_GlobalEval */
static int
-tcl_eval(Tcl_Interp *interp, const char *cmd)
+tcl_eval(interp, cmd)
+ Tcl_Interp *interp;
+ const char *cmd; /* don't have to be writable */
{
char *buf = strdup(cmd);
int ret;
@@ -141,7 +143,9 @@ tcl_eval(Tcl_Interp *interp, const char *cmd)
#define Tcl_Eval tcl_eval
static int
-tcl_global_eval(Tcl_Interp *interp, const char *cmd)
+tcl_global_eval(interp, cmd)
+ Tcl_Interp *interp;
+ const char *cmd; /* don't have to be writable */
{
char *buf = strdup(cmd);
int ret;
@@ -896,7 +900,7 @@ call_original_exit(ptr, state)
char **argv;
argv = (char **)ALLOC_N(char *, 3);
argv[0] = "exit";
- argv[1] = RSTRING_PTR(rb_fix2str(INT2NUM(state), 10));
+ argv[1] = RSTRING(rb_fix2str(INT2NUM(state), 10))->ptr;
argv[2] = (char *)NULL;
ptr->return_value = (*(info->proc))(info->clientData, ptr->ip,
@@ -1133,15 +1137,15 @@ set_max_block_time(self, time)
case T_BIGNUM:
/* time is micro-second value */
divmod = rb_funcall(time, rb_intern("divmod"), 1, LONG2NUM(1000000));
- tcl_time.sec = NUM2LONG(RARRAY_PTR(divmod)[0]);
- tcl_time.usec = NUM2LONG(RARRAY_PTR(divmod)[1]);
+ tcl_time.sec = NUM2LONG(RARRAY(divmod)->ptr[0]);
+ tcl_time.usec = NUM2LONG(RARRAY(divmod)->ptr[1]);
break;
case T_FLOAT:
/* time is second value */
divmod = rb_funcall(time, rb_intern("divmod"), 1, INT2FIX(1));
- tcl_time.sec = NUM2LONG(RARRAY_PTR(divmod)[0]);
- tcl_time.usec = (long)(NUM2DBL(RARRAY_PTR(divmod)[1]) * 1000000);
+ tcl_time.sec = NUM2LONG(RARRAY(divmod)->ptr[0]);
+ tcl_time.usec = (long)(NUM2DBL(RARRAY(divmod)->ptr[1]) * 1000000);
default:
{
@@ -2151,20 +2155,20 @@ ip_set_exc_message(interp, exc)
if (NIL_P(enc)) {
encoding = (Tcl_Encoding)NULL;
} else if (TYPE(enc) == T_STRING) {
- encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc));
+ encoding = Tcl_GetEncoding(interp, RSTRING(enc)->ptr);
} else {
enc = rb_funcall(enc, ID_to_s, 0, 0);
- encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc));
+ encoding = Tcl_GetEncoding(interp, RSTRING(enc)->ptr);
}
/* to avoid a garbled error message dialog */
- buf = ALLOC_N(char, (RSTRING_LEN(msg))+1);
- memcpy(buf, RSTRING_PTR(msg), RSTRING_LEN(msg));
- buf[RSTRING_LEN(msg)] = 0;
+ buf = ALLOC_N(char, (RSTRING(msg)->len)+1);
+ memcpy(buf, RSTRING(msg)->ptr, RSTRING(msg)->len);
+ buf[RSTRING(msg)->len] = 0;
Tcl_DStringInit(&dstr);
Tcl_DStringFree(&dstr);
- Tcl_ExternalToUtfDString(encoding, buf, RSTRING_LEN(msg), &dstr);
+ Tcl_ExternalToUtfDString(encoding, buf, RSTRING(msg)->len, &dstr);
Tcl_AppendResult(interp, Tcl_DStringValue(&dstr), (char*)NULL);
DUMP2("error message:%s", Tcl_DStringValue(&dstr));
@@ -2172,7 +2176,7 @@ ip_set_exc_message(interp, exc)
free(buf);
#else /* TCL_VERSION <= 8.0 */
- Tcl_AppendResult(interp, RSTRING_PTR(msg), (char*)NULL);
+ Tcl_AppendResult(interp, RSTRING(msg)->ptr, (char*)NULL);
#endif
rb_thread_critical = thr_crit_bup;
@@ -2367,12 +2371,12 @@ tcl_protect_core(interp, proc, data) /* should not raise exception */
ret = TkStringValue(ret);
DUMP1("Tcl_AppendResult");
- Tcl_AppendResult(interp, RSTRING_PTR(ret), (char *)NULL);
+ Tcl_AppendResult(interp, RSTRING(ret)->ptr, (char *)NULL);
rb_thread_critical = thr_crit_bup;
}
- DUMP2("(result) %s", NIL_P(ret) ? "nil" : RSTRING_PTR(ret));
+ DUMP2("(result) %s", NIL_P(ret) ? "nil" : RSTRING(ret)->ptr);
return TCL_OK;
}
@@ -2595,14 +2599,15 @@ ip_ruby_cmd(clientData, interp, argc, argv)
/* get args */
args = rb_ary_new2(argc - 2);
+ RARRAY(args)->len = 0;
for(i = 3; i < argc; i++) {
#if TCL_MAJOR_VERSION >= 8
str = Tcl_GetStringFromObj(argv[i], &len);
DUMP2("arg:%s",str);
- rb_ary_push(args, rb_tainted_str_new(str, len));
+ RARRAY(args)->ptr[RARRAY(args)->len++] = rb_tainted_str_new(str, len);
#else /* TCL_MAJOR_VERSION < 8 */
DUMP2("arg:%s",argv[i]);
- rb_ary_push(args, rb_tainted_str_new2(argv[i]));
+ RARRAY(args)->ptr[RARRAY(args)->len++] = rb_tainted_str_new2(argv[i]);
#endif
}
@@ -4359,12 +4364,11 @@ delete_slaves(ip)
/* finalize operation */
-static VALUE
+static void
lib_mark_at_exit(self)
VALUE self;
{
at_exit = 1;
- return Qnil;
}
static int
@@ -4409,13 +4413,13 @@ ip_finalize(ip)
}
if (Tcl_InterpDeleted(ip)) {
- DUMP2("ip(%lx) is already deleted", ip);
+ DUMP2("ip(%p) is already deleted", ip);
return;
}
#if TCL_NAMESPACE_DEBUG
if (ip_null_namespace(ip)) {
- DUMP2("ip(%lx) has null namespace", ip);
+ DUMP2("ip(%p) has null namespace", ip);
return;
}
#endif
@@ -5412,25 +5416,25 @@ get_obj_from_str(str)
const char *s = StringValuePtr(str);
#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0
- return Tcl_NewStringObj((char*)s, RSTRING_LEN(str));
+ return Tcl_NewStringObj((char*)s, RSTRING(str)->len);
#else /* TCL_VERSION >= 8.1 */
VALUE enc = rb_attr_get(str, ID_at_enc);
if (!NIL_P(enc)) {
StringValue(enc);
- if (strcmp(RSTRING_PTR(enc), "binary") == 0) {
+ if (strcmp(RSTRING(enc)->ptr, "binary") == 0) {
/* binary string */
- return Tcl_NewByteArrayObj(s, RSTRING_LEN(str));
+ return Tcl_NewByteArrayObj(s, RSTRING(str)->len);
} else {
/* text string */
- return Tcl_NewStringObj(s, RSTRING_LEN(str));
+ return Tcl_NewStringObj(s, RSTRING(str)->len);
}
- } else if (strlen(s) != RSTRING_LEN(str)) {
+ } else if (strlen(s) != RSTRING(str)->len) {
/* probably binary string */
- return Tcl_NewByteArrayObj(s, RSTRING_LEN(str));
+ return Tcl_NewByteArrayObj(s, RSTRING(str)->len);
} else {
/* probably text string */
- return Tcl_NewStringObj(s, RSTRING_LEN(str));
+ return Tcl_NewStringObj(s, RSTRING(str)->len);
}
#endif
}
@@ -5515,16 +5519,21 @@ call_queue_handler(evPtr, flags)
}
/* set result */
- RARRAY_PTR(q->result)[0] = ret;
+ RARRAY(q->result)->ptr[0] = ret;
/* complete */
*(q->done) = -1;
/* back to caller */
- DUMP2("back to caller (caller thread:%lx)", q->thread);
- DUMP2(" (current thread:%lx)", rb_thread_current());
- rb_thread_run(q->thread);
- DUMP1("finish back to caller");
+ if (RTEST(rb_funcall(q->thread, ID_alive_p, 0, 0))) {
+ DUMP2("back to caller (caller thread:%lx)", q->thread);
+ DUMP2(" (current thread:%lx)", rb_thread_current());
+ rb_thread_run(q->thread);
+ DUMP1("finish back to caller");
+ } else {
+ DUMP2("caller is dead (caller thread:%lx)", q->thread);
+ DUMP2(" (current thread:%lx)", rb_thread_current());
+ }
/* end of handler : remove it */
return 1;
@@ -5584,7 +5593,9 @@ tk_funcall(func, argc, argv, obj)
Tcl_Preserve(callq);
/* allocate result obj */
- result = rb_ary_new3(1, Qnil);
+ result = rb_ary_new2(1);
+ RARRAY(result)->ptr[0] = Qnil;
+ RARRAY(result)->len = 1;
/* construct event data */
callq->done = alloc_done;
@@ -5611,7 +5622,7 @@ tk_funcall(func, argc, argv, obj)
DUMP2("back from handler (current thread:%lx)", current);
/* get result & free allocated memory */
- ret = RARRAY_PTR(result)[0];
+ ret = RARRAY(result)->ptr[0];
free(alloc_done);
if (argv) free(argv);
@@ -5831,16 +5842,21 @@ eval_queue_handler(evPtr, flags)
}
/* set result */
- RARRAY_PTR(q->result)[0] = ret;
+ RARRAY(q->result)->ptr[0] = ret;
/* complete */
*(q->done) = -1;
/* back to caller */
- DUMP2("back to caller (caller thread:%lx)", q->thread);
- DUMP2(" (current thread:%lx)", rb_thread_current());
- rb_thread_run(q->thread);
- DUMP1("finish back to caller");
+ if (RTEST(rb_funcall(q->thread, ID_alive_p, 0, 0))) {
+ DUMP2("back to caller (caller thread:%lx)", q->thread);
+ DUMP2(" (current thread:%lx)", rb_thread_current());
+ rb_thread_run(q->thread);
+ DUMP1("finish back to caller");
+ } else {
+ DUMP2("caller is dead (caller thread:%lx)", q->thread);
+ DUMP2(" (current thread:%lx)", rb_thread_current());
+ }
/* end of handler : remove it */
return 1;
@@ -5872,7 +5888,7 @@ ip_eval(self, str)
} else {
DUMP2("eval from current eventloop %lx", current);
}
- result = ip_eval_real(self, RSTRING_PTR(str), RSTRING_LEN(str));
+ result = ip_eval_real(self, RSTRING(str)->ptr, RSTRING(str)->len);
if (rb_obj_is_kind_of(result, rb_eException)) {
rb_exc_raise(result);
}
@@ -5888,21 +5904,23 @@ ip_eval(self, str)
alloc_done = (int*)ALLOC(int);
*alloc_done = 0;
- eval_str = ALLOC_N(char, RSTRING_LEN(str) + 1);
- memcpy(eval_str, RSTRING_PTR(str), RSTRING_LEN(str));
- eval_str[RSTRING_LEN(str)] = 0;
+ eval_str = ALLOC_N(char, RSTRING(str)->len + 1);
+ memcpy(eval_str, RSTRING(str)->ptr, RSTRING(str)->len);
+ eval_str[RSTRING(str)->len] = 0;
/* allocate memory (freed by Tcl_ServiceEvent) */
evq = (struct eval_queue *)Tcl_Alloc(sizeof(struct eval_queue));
Tcl_Preserve(evq);
/* allocate result obj */
- result = rb_ary_new3(1, Qnil);
+ result = rb_ary_new2(1);
+ RARRAY(result)->ptr[0] = Qnil;
+ RARRAY(result)->len = 1;
/* construct event data */
evq->done = alloc_done;
evq->str = eval_str;
- evq->len = RSTRING_LEN(str);
+ evq->len = RSTRING(str)->len;
evq->interp = ip_obj;
evq->result = result;
evq->thread = current;
@@ -5925,7 +5943,7 @@ ip_eval(self, str)
DUMP2("back from handler (current thread:%lx)", current);
/* get result & free allocated memory */
- ret = RARRAY_PTR(result)[0];
+ ret = RARRAY(result)->ptr[0];
free(alloc_done);
free(eval_str);
@@ -6097,21 +6115,21 @@ lib_toUTF8_core(ip_obj, src, encodename)
encoding = (Tcl_Encoding)NULL;
} else {
StringValue(enc);
- encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc));
+ encoding = Tcl_GetEncoding(interp, RSTRING(enc)->ptr);
if (encoding == (Tcl_Encoding)NULL) {
- rb_warning("Tk-interp has unknown encoding information (@encoding:'%s')", RSTRING_PTR(enc));
+ rb_warning("Tk-interp has unknown encoding information (@encoding:'%s')", RSTRING(enc)->ptr);
}
}
}
} else {
StringValue(enc);
- if (strcmp(RSTRING_PTR(enc), "binary") == 0) {
+ if (strcmp(RSTRING(enc)->ptr, "binary") == 0) {
rb_thread_critical = thr_crit_bup;
return str;
}
- encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc));
+ encoding = Tcl_GetEncoding(interp, RSTRING(enc)->ptr);
if (encoding == (Tcl_Encoding)NULL) {
- rb_warning("string has unknown encoding information (@encoding:'%s')", RSTRING_PTR(enc));
+ rb_warning("string has unknown encoding information (@encoding:'%s')", RSTRING(enc)->ptr);
}
}
} else {
@@ -6119,30 +6137,30 @@ lib_toUTF8_core(ip_obj, src, encodename)
}
} else {
StringValue(encodename);
- encoding = Tcl_GetEncoding(interp, RSTRING_PTR(encodename));
+ encoding = Tcl_GetEncoding(interp, RSTRING(encodename)->ptr);
if (encoding == (Tcl_Encoding)NULL) {
/*
rb_warning("unknown encoding name '%s'",
- RSTRING_PTR(encodename));
+ RSTRING(encodename)->ptr);
*/
rb_raise(rb_eArgError, "unknown encoding name '%s'",
- RSTRING_PTR(encodename));
+ RSTRING(encodename)->ptr);
}
}
StringValue(str);
- if (!RSTRING_LEN(str)) {
+ if (!RSTRING(str)->len) {
rb_thread_critical = thr_crit_bup;
return str;
}
- buf = ALLOC_N(char,RSTRING_LEN(str)+1);
- memcpy(buf, RSTRING_PTR(str), RSTRING_LEN(str));
- buf[RSTRING_LEN(str)] = 0;
+ buf = ALLOC_N(char,(RSTRING(str)->len)+1);
+ memcpy(buf, RSTRING(str)->ptr, RSTRING(str)->len);
+ buf[RSTRING(str)->len] = 0;
Tcl_DStringInit(&dstr);
Tcl_DStringFree(&dstr);
/* Tcl_ExternalToUtfDString(encoding,buf,strlen(buf),&dstr); */
- Tcl_ExternalToUtfDString(encoding, buf, RSTRING_LEN(str), &dstr);
+ Tcl_ExternalToUtfDString(encoding, buf, RSTRING(str)->len, &dstr);
/* str = rb_tainted_str_new2(Tcl_DStringValue(&dstr)); */
/* str = rb_str_new2(Tcl_DStringValue(&dstr)); */
@@ -6233,7 +6251,7 @@ lib_fromUTF8_core(ip_obj, src, encodename)
enc = rb_attr_get(str, ID_at_enc);
if (!NIL_P(enc)) {
StringValue(enc);
- if (strcmp(RSTRING_PTR(enc), "binary") == 0) {
+ if (strcmp(RSTRING(enc)->ptr, "binary") == 0) {
rb_thread_critical = thr_crit_bup;
return str;
}
@@ -6248,9 +6266,9 @@ lib_fromUTF8_core(ip_obj, src, encodename)
encoding = (Tcl_Encoding)NULL;
} else {
StringValue(enc);
- encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc));
+ encoding = Tcl_GetEncoding(interp, RSTRING(enc)->ptr);
if (encoding == (Tcl_Encoding)NULL) {
- rb_warning("Tk-interp has unknown encoding information (@encoding:'%s')", RSTRING_PTR(enc));
+ rb_warning("Tk-interp has unknown encoding information (@encoding:'%s')", RSTRING(enc)->ptr);
} else {
encodename = rb_obj_dup(enc);
}
@@ -6260,13 +6278,13 @@ lib_fromUTF8_core(ip_obj, src, encodename)
} else {
StringValue(encodename);
- if (strcmp(RSTRING_PTR(encodename), "binary") == 0) {
+ if (strcmp(RSTRING(encodename)->ptr, "binary") == 0) {
char *s;
int len;
StringValue(str);
- s = Tcl_GetByteArrayFromObj(Tcl_NewStringObj(RSTRING_PTR(str),
- RSTRING_LEN(str)),
+ s = Tcl_GetByteArrayFromObj(Tcl_NewStringObj(RSTRING(str)->ptr,
+ RSTRING(str)->len),
&len);
str = rb_tainted_str_new(s, len);
rb_ivar_set(str, ID_at_enc, rb_tainted_str_new2("binary"));
@@ -6275,33 +6293,33 @@ lib_fromUTF8_core(ip_obj, src, encodename)
return str;
}
- encoding = Tcl_GetEncoding(interp, RSTRING_PTR(encodename));
+ encoding = Tcl_GetEncoding(interp, RSTRING(encodename)->ptr);
if (encoding == (Tcl_Encoding)NULL) {
/*
rb_warning("unknown encoding name '%s'",
- RSTRING_PTR(encodename));
+ RSTRING(encodename)->ptr);
encodename = Qnil;
*/
rb_raise(rb_eArgError, "unknown encoding name '%s'",
- RSTRING_PTR(encodename));
+ RSTRING(encodename)->ptr);
}
}
StringValue(str);
- if (RSTRING_LEN(str) == 0) {
+ if (RSTRING(str)->len == 0) {
rb_thread_critical = thr_crit_bup;
return rb_tainted_str_new2("");
}
- buf = ALLOC_N(char,strlen(RSTRING_PTR(str))+1);
- memcpy(buf, RSTRING_PTR(str), RSTRING_LEN(str));
- buf[RSTRING_LEN(str)] = 0;
+ buf = ALLOC_N(char,strlen(RSTRING(str)->ptr)+1);
+ memcpy(buf, RSTRING(str)->ptr, RSTRING(str)->len);
+ buf[RSTRING(str)->len] = 0;
Tcl_DStringInit(&dstr);
Tcl_DStringFree(&dstr);
/* Tcl_UtfToExternalDString(encoding,buf,strlen(buf),&dstr); */
- Tcl_UtfToExternalDString(encoding,buf,RSTRING_LEN(str),&dstr);
+ Tcl_UtfToExternalDString(encoding,buf,RSTRING(str)->len,&dstr);
/* str = rb_tainted_str_new2(Tcl_DStringValue(&dstr)); */
/* str = rb_str_new2(Tcl_DStringValue(&dstr)); */
@@ -6366,21 +6384,21 @@ lib_UTF_backslash_core(self, str, all_bs)
tcl_stubs_check();
StringValue(str);
- if (!RSTRING_LEN(str)) {
+ if (!RSTRING(str)->len) {
return str;
}
thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue;
- src_buf = ALLOC_N(char,RSTRING_LEN(str)+1);
- memcpy(src_buf, RSTRING_PTR(str), RSTRING_LEN(str));
- src_buf[RSTRING_LEN(str)] = 0;
+ src_buf = ALLOC_N(char,(RSTRING(str)->len)+1);
+ memcpy(src_buf, RSTRING(str)->ptr, RSTRING(str)->len);
+ src_buf[RSTRING(str)->len] = 0;
- dst_buf = ALLOC_N(char,RSTRING_LEN(str)+1);
+ dst_buf = ALLOC_N(char,(RSTRING(str)->len)+1);
ptr = src_buf;
- while(RSTRING_LEN(str) > ptr - src_buf) {
+ while(RSTRING(str)->len > ptr - src_buf) {
if (*ptr == '\\' && (all_bs || *(ptr + 1) == 'u')) {
dst_len += Tcl_UtfBackslash(ptr, &read_len, (dst_buf + dst_len));
ptr += read_len;
@@ -6446,7 +6464,7 @@ lib_set_system_encoding(self, enc_name)
if (Tcl_SetSystemEncoding((Tcl_Interp *)NULL,
StringValuePtr(enc_name)) != TCL_OK) {
rb_raise(rb_eArgError, "unknown encoding name '%s'",
- RSTRING_PTR(enc_name));
+ RSTRING(enc_name)->ptr);
}
return enc_name;
@@ -6906,16 +6924,21 @@ invoke_queue_handler(evPtr, flags)
}
/* set result */
- RARRAY_PTR(q->result)[0] = ret;
+ RARRAY(q->result)->ptr[0] = ret;
/* complete */
*(q->done) = -1;
/* back to caller */
- DUMP2("back to caller (caller thread:%lx)", q->thread);
- DUMP2(" (current thread:%lx)", rb_thread_current());
- rb_thread_run(q->thread);
- DUMP1("finish back to caller");
+ if (RTEST(rb_funcall(q->thread, ID_alive_p, 0, 0))) {
+ DUMP2("back to caller (caller thread:%lx)", q->thread);
+ DUMP2(" (current thread:%lx)", rb_thread_current());
+ rb_thread_run(q->thread);
+ DUMP1("finish back to caller");
+ } else {
+ DUMP2("caller is dead (caller thread:%lx)", q->thread);
+ DUMP2(" (current thread:%lx)", rb_thread_current());
+ }
/* end of handler : remove it */
return 1;
@@ -6975,7 +6998,9 @@ ip_invoke_with_position(argc, argv, obj, position)
Tcl_Preserve(ivq);
/* allocate result obj */
- result = rb_ary_new3(1, Qnil);
+ result = rb_ary_new2(1);
+ RARRAY(result)->ptr[0] = Qnil;
+ RARRAY(result)->len = 1;
/* construct event data */
ivq->done = alloc_done;
@@ -7001,7 +7026,7 @@ ip_invoke_with_position(argc, argv, obj, position)
DUMP2("back from handler (current thread:%lx)", current);
/* get result & free allocated memory */
- ret = RARRAY_PTR(result)[0];
+ ret = RARRAY(result)->ptr[0];
free(alloc_done);
Tcl_Release(ivq);
@@ -7094,8 +7119,8 @@ ip_get_variable2_core(interp, argc, argv)
} else {
/* Tcl_Preserve(ptr->ip); */
rbtk_preserve_ip(ptr);
- ret = Tcl_GetVar2Ex(ptr->ip, RSTRING_PTR(varname),
- NIL_P(index) ? NULL : RSTRING_PTR(index),
+ ret = Tcl_GetVar2Ex(ptr->ip, RSTRING(varname)->ptr,
+ NIL_P(index) ? NULL : RSTRING(index)->ptr,
FIX2INT(flag));
}
@@ -7132,8 +7157,8 @@ ip_get_variable2_core(interp, argc, argv)
} else {
/* Tcl_Preserve(ptr->ip); */
rbtk_preserve_ip(ptr);
- ret = Tcl_GetVar2(ptr->ip, RSTRING_PTR(varname),
- NIL_P(index) ? NULL : RSTRING_PTR(index),
+ ret = Tcl_GetVar2(ptr->ip, RSTRING(varname)->ptr,
+ NIL_P(index) ? NULL : RSTRING(index)->ptr,
FIX2INT(flag));
}
@@ -7231,8 +7256,8 @@ ip_set_variable2_core(interp, argc, argv)
} else {
/* Tcl_Preserve(ptr->ip); */
rbtk_preserve_ip(ptr);
- ret = Tcl_SetVar2Ex(ptr->ip, RSTRING_PTR(varname),
- NIL_P(index) ? NULL : RSTRING_PTR(index),
+ ret = Tcl_SetVar2Ex(ptr->ip, RSTRING(varname)->ptr,
+ NIL_P(index) ? NULL : RSTRING(index)->ptr,
valobj, FIX2INT(flag));
}
@@ -7272,9 +7297,9 @@ ip_set_variable2_core(interp, argc, argv)
} else {
/* Tcl_Preserve(ptr->ip); */
rbtk_preserve_ip(ptr);
- ret = Tcl_SetVar2(ptr->ip, RSTRING_PTR(varname),
- NIL_P(index) ? NULL : RSTRING_PTR(index),
- RSTRING_PTR(value), FIX2INT(flag));
+ ret = Tcl_SetVar2(ptr->ip, RSTRING(varname)->ptr,
+ NIL_P(index) ? NULL : RSTRING(index)->ptr,
+ RSTRING(value)->ptr, FIX2INT(flag));
}
if (ret == (char*)NULL) {
@@ -7354,8 +7379,8 @@ ip_unset_variable2_core(interp, argc, argv)
return Qtrue;
}
- ptr->return_value = Tcl_UnsetVar2(ptr->ip, RSTRING_PTR(varname),
- NIL_P(index) ? NULL : RSTRING_PTR(index),
+ ptr->return_value = Tcl_UnsetVar2(ptr->ip, RSTRING(varname)->ptr,
+ NIL_P(index) ? NULL : RSTRING(index)->ptr,
FIX2INT(flag));
if (ptr->return_value == TCL_ERROR) {
@@ -7528,9 +7553,11 @@ lib_split_tklist_core(ip_obj, list_str)
for(idx = 0; idx < objc; idx++) {
elem = get_str_from_obj(objv[idx]);
if (taint_flag) OBJ_TAINT(elem);
- rb_ary_push(ary, elem);
+ RARRAY(ary)->ptr[idx] = elem;
}
+ RARRAY(ary)->len = objc;
+
if (old_gc == Qfalse) rb_gc_enable();
rb_thread_critical = thr_crit_bup;
@@ -7546,7 +7573,7 @@ lib_split_tklist_core(ip_obj, list_str)
int argc;
char **argv;
- if (Tcl_SplitList(interp, RSTRING_PTR(list_str),
+ if (Tcl_SplitList(interp, RSTRING(list_str)->ptr,
&argc, &argv) == TCL_ERROR) {
if (interp == (Tcl_Interp*)NULL) {
rb_raise(rb_eRuntimeError, "can't get elements from list");
@@ -7567,8 +7594,10 @@ lib_split_tklist_core(ip_obj, list_str)
elem = rb_str_new2(argv[idx]);
}
/* rb_ivar_set(elem, ID_at_enc, rb_str_new2("binary")); */
- rb_ary_push(ary, elem);
+ RARRAY(ary)->ptr[idx] = elem;
}
+ RARRAY(ary)->len = argc;
+
if (old_gc == Qfalse) rb_gc_enable();
#endif
}
@@ -7624,7 +7653,7 @@ lib_merge_tklist(argc, argv, obj)
if (OBJ_TAINTED(argv[num])) taint_flag = 1;
dst = StringValuePtr(argv[num]);
#if TCL_MAJOR_VERSION >= 8
- len += Tcl_ScanCountedElement(dst, RSTRING_LEN(argv[num]),
+ len += Tcl_ScanCountedElement(dst, RSTRING(argv[num])->len,
&flagPtr[num]) + 1;
#else /* TCL_MAJOR_VERSION < 8 */
len += Tcl_ScanElement(dst, &flagPtr[num]) + 1;
@@ -7636,11 +7665,11 @@ lib_merge_tklist(argc, argv, obj)
dst = result;
for(num = 0; num < argc; num++) {
#if TCL_MAJOR_VERSION >= 8
- len = Tcl_ConvertCountedElement(RSTRING_PTR(argv[num]),
- RSTRING_LEN(argv[num]),
+ len = Tcl_ConvertCountedElement(RSTRING(argv[num])->ptr,
+ RSTRING(argv[num])->len,
dst, flagPtr[num]);
#else /* TCL_MAJOR_VERSION < 8 */
- len = Tcl_ConvertElement(RSTRING_PTR(argv[num]), dst, flagPtr[num]);
+ len = Tcl_ConvertElement(RSTRING(argv[num])->ptr, dst, flagPtr[num]);
#endif
dst += len;
*dst = ' ';
@@ -7683,18 +7712,19 @@ lib_conv_listelement(self, src)
StringValue(src);
#if TCL_MAJOR_VERSION >= 8
- len = Tcl_ScanCountedElement(RSTRING_PTR(src), RSTRING_LEN(src),
+ len = Tcl_ScanCountedElement(RSTRING(src)->ptr, RSTRING(src)->len,
&scan_flag);
dst = rb_str_new(0, len + 1);
- len = Tcl_ConvertCountedElement(RSTRING_PTR(src), RSTRING_LEN(src),
- RSTRING_PTR(dst), scan_flag);
+ len = Tcl_ConvertCountedElement(RSTRING(src)->ptr, RSTRING(src)->len,
+ RSTRING(dst)->ptr, scan_flag);
#else /* TCL_MAJOR_VERSION < 8 */
- len = Tcl_ScanElement(RSTRING_PTR(src), &scan_flag);
+ len = Tcl_ScanElement(RSTRING(src)->ptr, &scan_flag);
dst = rb_str_new(0, len + 1);
- len = Tcl_ConvertElement(RSTRING_PTR(src), RSTRING_PTR(dst), scan_flag);
+ len = Tcl_ConvertElement(RSTRING(src)->ptr, RSTRING(dst)->ptr, scan_flag);
#endif
- rb_str_resize(dst, len);
+ RSTRING(dst)->len = len;
+ RSTRING(dst)->ptr[len] = '\0';
if (taint_flag) OBJ_TAINT(dst);
rb_thread_critical = thr_crit_bup;
@@ -7816,7 +7846,7 @@ ip_make_menu_embeddable(interp, menu_path)
StringValue(menu_path);
- menuRefPtr = TkFindMenuReferences(ptr->ip, RSTRING_PTR(menu_path));
+ menuRefPtr = TkFindMenuReferences(ptr->ip, RSTRING(menu_path)->ptr);
if (menuRefPtr == (struct dummy_TkMenuRef *) NULL) {
rb_raise(rb_eArgError, "not a menu widget, or invalid widget path");
}
@@ -7964,8 +7994,6 @@ 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);
@@ -8102,11 +8130,11 @@ Init_tcltklib()
/* --------------------------------------------------------------- */
- rb_eval_string("at_exit{ TclTkLib._mark_at_exit }");
+ rb_set_end_proc(lib_mark_at_exit, 0);
/* --------------------------------------------------------------- */
- ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING_PTR(rb_argv0) : 0);
+ ret = ruby_open_tcl_dll(rb_argv0 ? RSTRING(rb_argv0)->ptr : 0);
switch(ret) {
case TCLTK_STUBS_OK:
break;
diff --git a/ext/tk/tkutil/extconf.rb b/ext/tk/tkutil/extconf.rb
index e3aa00a4b2..dd00d5d535 100644
--- a/ext/tk/tkutil/extconf.rb
+++ b/ext/tk/tkutil/extconf.rb
@@ -1,4 +1,11 @@
-if compiled?('tk')
+begin
+ has_tk = compiled?('tk')
+rescue NoMethodError
+ # Probably, called manually (NOT from 'extmk.rb'). Force to make Makefile.
+ has_tk = true
+end
+
+if has_tk
require 'mkmf'
create_makefile('tkutil')
end
diff --git a/ext/tk/tkutil/tkutil.c b/ext/tk/tkutil/tkutil.c
index 0b2597ec1a..f4271a724c 100644
--- a/ext/tk/tkutil/tkutil.c
+++ b/ext/tk/tkutil/tkutil.c
@@ -155,16 +155,16 @@ tk_uninstall_cmd(self, cmd_id)
int prefix_len = strlen(cmd_id_prefix);
StringValue(cmd_id);
- if (strncmp(cmd_id_head, RSTRING_PTR(cmd_id), head_len) != 0) {
+ if (strncmp(cmd_id_head, RSTRING(cmd_id)->ptr, head_len) != 0) {
return Qnil;
}
if (strncmp(cmd_id_prefix,
- RSTRING_PTR(cmd_id) + head_len, prefix_len) != 0) {
+ RSTRING(cmd_id)->ptr + head_len, prefix_len) != 0) {
return Qnil;
}
return rb_hash_delete(CALLBACK_TABLE,
- rb_str_new2(RSTRING_PTR(cmd_id) + head_len));
+ rb_str_new2(RSTRING(cmd_id)->ptr + head_len));
}
static VALUE
@@ -267,24 +267,25 @@ ary2list(ary, enc_flag, self)
req_chk_flag = 0;
}
- /* size = RARRAY_LEN(ary); */
+ /* size = RARRAY(ary)->len; */
size = 0;
- for(idx = 0; idx < RARRAY_LEN(ary); idx++) {
- if (TYPE(RARRAY_PTR(ary)[idx]) == T_HASH) {
- size += 2 * RHASH(RARRAY_PTR(ary)[idx])->tbl->num_entries;
+ for(idx = 0; idx < RARRAY(ary)->len; idx++) {
+ if (TYPE(RARRAY(ary)->ptr[idx]) == T_HASH) {
+ size += 2 * RHASH(RARRAY(ary)->ptr[idx])->tbl->num_entries;
} else {
size++;
}
}
dst = rb_ary_new2(size);
- for(idx = 0; idx < RARRAY_LEN(ary); idx++) {
- val = RARRAY_PTR(ary)[idx];
+ RARRAY(dst)->len = 0;
+ for(idx = 0; idx < RARRAY(ary)->len; idx++) {
+ val = RARRAY(ary)->ptr[idx];
str_val = Qnil;
switch(TYPE(val)) {
case T_ARRAY:
str_val = ary2list(val, enc_flag, self);
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
if (req_chk_flag) {
str_enc = rb_ivar_get(str_val, ID_at_enc);
@@ -302,19 +303,19 @@ ary2list(ary, enc_flag, self)
break;
case T_HASH:
- /* rb_ary_push(dst, hash2list(val, self)); */
+ /* RARRAY(dst)->ptr[RARRAY(dst)->len++] = hash2list(val, self); */
if (RTEST(enc_flag)) {
val = hash2kv_enc(val, Qnil, self);
} else {
val = hash2kv(val, Qnil, self);
}
- size2 = RARRAY_LEN(val);
+ size2 = RARRAY(val)->len;
for(idx2 = 0; idx2 < size2; idx2++) {
- val2 = RARRAY_PTR(val)[idx2];
+ val2 = RARRAY(val)->ptr[idx2];
switch(TYPE(val2)) {
case T_ARRAY:
str_val = ary2list(val2, enc_flag, self);
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
break;
case T_HASH:
@@ -323,13 +324,13 @@ ary2list(ary, enc_flag, self)
} else {
str_val = hash2list(val2, self);
}
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
break;
default:
if (val2 != TK_None) {
str_val = get_eval_string_core(val2, enc_flag, self);
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
}
}
@@ -351,7 +352,7 @@ ary2list(ary, enc_flag, self)
default:
if (val != TK_None) {
str_val = get_eval_string_core(val, enc_flag, self);
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
if (req_chk_flag) {
str_enc = rb_ivar_get(str_val, ID_at_enc);
@@ -370,14 +371,14 @@ ary2list(ary, enc_flag, self)
}
if (RTEST(dst_enc) && !NIL_P(sys_enc)) {
- for(idx = 0; idx < RARRAY_LEN(dst); idx++) {
- str_val = RARRAY_PTR(dst)[idx];
+ for(idx = 0; idx < RARRAY(dst)->len; idx++) {
+ str_val = RARRAY(dst)->ptr[idx];
if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) {
str_val = rb_funcall(self, ID_toUTF8, 1, str_val);
} else {
str_val = rb_funcall(cTclTkLib, ID_toUTF8, 1, str_val);
}
- RARRAY_PTR(dst)[idx] = str_val;
+ RARRAY(dst)->ptr[idx] = str_val;
}
val = rb_apply(cTclTkLib, ID_merge_tklist, dst);
if (TYPE(dst_enc) == T_STRING) {
@@ -420,10 +421,11 @@ ary2list2(ary, enc_flag, self)
req_chk_flag = 0;
}
- size = RARRAY_LEN(ary);
+ size = RARRAY(ary)->len;
dst = rb_ary_new2(size);
- for(idx = 0; idx < RARRAY_LEN(ary); idx++) {
- val = RARRAY_PTR(ary)[idx];
+ RARRAY(dst)->len = 0;
+ for(idx = 0; idx < RARRAY(ary)->len; idx++) {
+ val = RARRAY(ary)->ptr[idx];
str_val = Qnil;
switch(TYPE(val)) {
case T_ARRAY:
@@ -445,7 +447,7 @@ ary2list2(ary, enc_flag, self)
}
if (!NIL_P(str_val)) {
- rb_ary_push(dst, str_val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = str_val;
if (req_chk_flag) {
str_enc = rb_ivar_get(str_val, ID_at_enc);
@@ -463,14 +465,14 @@ ary2list2(ary, enc_flag, self)
}
if (RTEST(dst_enc) && !NIL_P(sys_enc)) {
- for(idx = 0; idx < RARRAY_LEN(dst); idx++) {
- str_val = RARRAY_PTR(dst)[idx];
+ for(idx = 0; idx < RARRAY(dst)->len; idx++) {
+ str_val = RARRAY(dst)->ptr[idx];
if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) {
str_val = rb_funcall(self, ID_toUTF8, 1, str_val);
} else {
str_val = rb_funcall(cTclTkLib, ID_toUTF8, 1, str_val);
}
- RARRAY_PTR(dst)[idx] = str_val;
+ RARRAY(dst)->ptr[idx] = str_val;
}
val = rb_apply(cTclTkLib, ID_merge_tklist, dst);
if (TYPE(dst_enc) == T_STRING) {
@@ -501,35 +503,38 @@ assoc2kv(assoc, ary, self)
int i, j, len;
volatile VALUE pair;
volatile VALUE val;
- volatile VALUE dst = rb_ary_new2(2 * RARRAY_LEN(assoc));
+ volatile VALUE dst = rb_ary_new2(2 * RARRAY(assoc)->len);
- len = RARRAY_LEN(assoc);
+ len = RARRAY(assoc)->len;
for(i = 0; i < len; i++) {
- pair = RARRAY_PTR(assoc)[i];
+ pair = RARRAY(assoc)->ptr[i];
if (TYPE(pair) != T_ARRAY) {
- rb_ary_push(dst, key2keyname(pair));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = key2keyname(pair);
continue;
}
- switch(RARRAY_LEN(assoc)) {
+ switch(RARRAY(assoc)->len) {
case 2:
- rb_ary_push(dst, RARRAY_PTR(pair)[2]);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = RARRAY(pair)->ptr[2];
case 1:
- rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = key2keyname(RARRAY(pair)->ptr[0]);
case 0:
continue;
default:
- rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = key2keyname(RARRAY(pair)->ptr[0]);
- val = rb_ary_new2(RARRAY_LEN(pair) - 1);
- for(j = 1; j < RARRAY_LEN(pair); j++) {
- rb_ary_push(val, RARRAY_PTR(pair)[j]);
+ val = rb_ary_new2(RARRAY(pair)->len - 1);
+ RARRAY(val)->len = 0;
+ for(j = 1; j < RARRAY(pair)->len; j++) {
+ RARRAY(val)->ptr[RARRAY(val)->len++] = RARRAY(pair)->ptr[j];
}
- rb_ary_push(dst, val);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = val;
}
}
@@ -549,35 +554,40 @@ assoc2kv_enc(assoc, ary, self)
int i, j, len;
volatile VALUE pair;
volatile VALUE val;
- volatile VALUE dst = rb_ary_new2(2 * RARRAY_LEN(assoc));
+ volatile VALUE dst = rb_ary_new2(2 * RARRAY(assoc)->len);
- len = RARRAY_LEN(assoc);
+ len = RARRAY(assoc)->len;
for(i = 0; i < len; i++) {
- pair = RARRAY_PTR(assoc)[i];
+ pair = RARRAY(assoc)->ptr[i];
if (TYPE(pair) != T_ARRAY) {
- rb_ary_push(dst, key2keyname(pair));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = key2keyname(pair);
continue;
}
- switch(RARRAY_LEN(assoc)) {
+ switch(RARRAY(assoc)->len) {
case 2:
- rb_ary_push(dst, get_eval_string_core(RARRAY_PTR(pair)[2], Qtrue, self));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = get_eval_string_core(RARRAY(pair)->ptr[2], Qtrue, self);
case 1:
- rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = key2keyname(RARRAY(pair)->ptr[0]);
case 0:
continue;
default:
- rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0]));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = key2keyname(RARRAY(pair)->ptr[0]);
- val = rb_ary_new2(RARRAY_LEN(pair) - 1);
- for(j = 1; j < RARRAY_LEN(pair); j++) {
- rb_ary_push(val, RARRAY_PTR(pair)[j]);
+ val = rb_ary_new2(RARRAY(pair)->len - 1);
+ RARRAY(val)->len = 0;
+ for(j = 1; j < RARRAY(pair)->len; j++) {
+ RARRAY(val)->ptr[RARRAY(val)->len++] = RARRAY(pair)->ptr[j];
}
- rb_ary_push(dst, get_eval_string_core(val, Qtrue, self));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = get_eval_string_core(val, Qtrue, self);
}
}
@@ -596,18 +606,19 @@ push_kv(key, val, args)
{
volatile VALUE ary;
- ary = RARRAY_PTR(args)[0];
+ ary = RARRAY(args)->ptr[0];
if (key == Qundef) return ST_CONTINUE;
#if 0
rb_ary_push(ary, key2keyname(key));
if (val != TK_None) rb_ary_push(ary, val);
#endif
- rb_ary_push(ary, key2keyname(key));
+ RARRAY(ary)->ptr[RARRAY(ary)->len++] = key2keyname(key);
if (val == TK_None) return ST_CHECK;
- rb_ary_push(ary, get_eval_string_core(val, Qnil, RARRAY_PTR(args)[1]));
+ RARRAY(ary)->ptr[RARRAY(ary)->len++]
+ = get_eval_string_core(val, Qnil, RARRAY(args)->ptr[1]);
return ST_CHECK;
}
@@ -618,9 +629,14 @@ hash2kv(hash, ary, self)
VALUE ary;
VALUE self;
{
+ volatile VALUE args = rb_ary_new2(2);
volatile VALUE dst = rb_ary_new2(2 * RHASH(hash)->tbl->num_entries);
- volatile VALUE args = rb_ary_new3(2, dst, self);
+ RARRAY(dst)->len = 0;
+
+ RARRAY(args)->ptr[0] = dst;
+ RARRAY(args)->ptr[1] = self;
+ RARRAY(args)->len = 2;
st_foreach(RHASH(hash)->tbl, push_kv, args);
if (NIL_P(ary)) {
@@ -638,21 +654,22 @@ push_kv_enc(key, val, args)
{
volatile VALUE ary;
- ary = RARRAY_PTR(args)[0];
+ ary = RARRAY(args)->ptr[0];
if (key == Qundef) return ST_CONTINUE;
#if 0
rb_ary_push(ary, key2keyname(key));
if (val != TK_None) {
rb_ary_push(ary, get_eval_string_core(val, Qtrue,
- RARRAY_PTR(args)[1]));
+ RARRAY(args)->ptr[1]));
}
#endif
- rb_ary_push(ary, key2keyname(key));
+ RARRAY(ary)->ptr[RARRAY(ary)->len++] = key2keyname(key);
if (val == TK_None) return ST_CHECK;
- rb_ary_push(ary, get_eval_string_core(val, Qtrue, RARRAY_PTR(args)[1]));
+ RARRAY(ary)->ptr[RARRAY(ary)->len++]
+ = get_eval_string_core(val, Qtrue, RARRAY(args)->ptr[1]);
return ST_CHECK;
}
@@ -663,9 +680,14 @@ hash2kv_enc(hash, ary, self)
VALUE ary;
VALUE self;
{
+ volatile VALUE args = rb_ary_new2(2);
volatile VALUE dst = rb_ary_new2(2 * RHASH(hash)->tbl->num_entries);
- volatile VALUE args = rb_ary_new3(2, dst, self);
+ RARRAY(dst)->len = 0;
+
+ RARRAY(args)->ptr[0] = dst;
+ RARRAY(args)->ptr[1] = self;
+ RARRAY(args)->len = 2;
st_foreach(RHASH(hash)->tbl, push_kv_enc, args);
if (NIL_P(ary)) {
@@ -840,7 +862,7 @@ get_eval_string_core(obj, enc_flag, self)
}
rb_warning("fail to convert '%s' to string for Tk",
- RSTRING_PTR(rb_funcall(obj, rb_intern("inspect"), 0, 0)));
+ RSTRING(rb_funcall(obj, rb_intern("inspect"), 0, 0))->ptr);
return obj;
}
@@ -900,6 +922,7 @@ tk_conv_args(argc, argv, self)
}
/* dst = rb_ary_new2(argc - 2); */
dst = rb_ary_new2(size);
+ RARRAY(dst)->len = 0;
for(idx = 2; idx < argc; idx++) {
if (TYPE(argv[idx]) == T_HASH) {
if (RTEST(argv[1])) {
@@ -908,7 +931,8 @@ tk_conv_args(argc, argv, self)
hash2kv(argv[idx], dst, self);
}
} else if (argv[idx] != TK_None) {
- rb_ary_push(dst, get_eval_string_core(argv[idx], argv[1], self));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = get_eval_string_core(argv[idx], argv[1], self);
}
}
@@ -942,13 +966,13 @@ tcl2rb_bool(self, value)
value = rb_funcall(value, ID_downcase, 0);
- if (RSTRING_PTR(value) == (char*)NULL) return Qnil;
+ if (RSTRING(value)->ptr == (char*)NULL) return Qnil;
- if (RSTRING_PTR(value)[0] == '\0'
- || strcmp(RSTRING_PTR(value), "0") == 0
- || strcmp(RSTRING_PTR(value), "no") == 0
- || strcmp(RSTRING_PTR(value), "off") == 0
- || strcmp(RSTRING_PTR(value), "false") == 0) {
+ if (RSTRING(value)->ptr[0] == '\0'
+ || strcmp(RSTRING(value)->ptr, "0") == 0
+ || strcmp(RSTRING(value)->ptr, "no") == 0
+ || strcmp(RSTRING(value)->ptr, "off") == 0
+ || strcmp(RSTRING(value)->ptr, "false") == 0) {
return Qfalse;
} else {
return Qtrue;
@@ -959,21 +983,21 @@ static VALUE
tkstr_to_dec(value)
VALUE value;
{
- return rb_cstr_to_inum(RSTRING_PTR(value), 10, 1);
+ return rb_cstr_to_inum(RSTRING(value)->ptr, 10, 1);
}
static VALUE
tkstr_to_int(value)
VALUE value;
{
- return rb_cstr_to_inum(RSTRING_PTR(value), 0, 1);
+ return rb_cstr_to_inum(RSTRING(value)->ptr, 0, 1);
}
static VALUE
tkstr_to_float(value)
VALUE value;
{
- return rb_float_new(rb_cstr_to_dbl(RSTRING_PTR(value), 1));
+ return rb_float_new(rb_cstr_to_dbl(RSTRING(value)->ptr, 1));
}
static VALUE
@@ -981,7 +1005,7 @@ tkstr_invalid_numstr(value)
VALUE value;
{
rb_raise(rb_eArgError,
- "invalid value for Number: '%s'", RSTRING_PTR(value));
+ "invalid value for Number: '%s'", RSTRING(value)->ptr);
return Qnil; /*dummy*/
}
@@ -1000,7 +1024,7 @@ tkstr_to_number(value)
{
rb_check_type(value, T_STRING);
- if (RSTRING_PTR(value) == (char*)NULL) return INT2FIX(0);
+ if (RSTRING(value)->ptr == (char*)NULL) return INT2FIX(0);
return rb_rescue2(tkstr_to_int, value,
tkstr_rescue_float, value,
@@ -1022,8 +1046,8 @@ tkstr_to_str(value)
char * ptr;
int len;
- ptr = RSTRING_PTR(value);
- len = RSTRING_LEN(value);
+ ptr = RSTRING(value)->ptr;
+ len = RSTRING(value)->len;
if (len > 1 && *ptr == '{' && *(ptr + len - 1) == '}') {
return rb_str_new(ptr + 1, len - 2);
@@ -1038,7 +1062,7 @@ tcl2rb_string(self, value)
{
rb_check_type(value, T_STRING);
- if (RSTRING_PTR(value) == (char*)NULL) return rb_tainted_str_new2("");
+ if (RSTRING(value)->ptr == (char*)NULL) return rb_tainted_str_new2("");
return tkstr_to_str(value);
}
@@ -1050,7 +1074,7 @@ tcl2rb_num_or_str(self, value)
{
rb_check_type(value, T_STRING);
- if (RSTRING_PTR(value) == (char*)NULL) return rb_tainted_str_new2("");
+ if (RSTRING(value)->ptr == (char*)NULL) return rb_tainted_str_new2("");
return rb_rescue2(tkstr_to_number, value,
tkstr_to_str, value,
@@ -1157,7 +1181,7 @@ each_attr_def(key, value, klass)
switch(TYPE(key)) {
case T_STRING:
- key_id = rb_intern(RSTRING_PTR(key));
+ key_id = rb_intern(RSTRING(key)->ptr);
break;
case T_SYMBOL:
key_id = SYM2ID(key);
@@ -1169,7 +1193,7 @@ each_attr_def(key, value, klass)
switch(TYPE(value)) {
case T_STRING:
- value_id = rb_intern(RSTRING_PTR(value));
+ value_id = rb_intern(RSTRING(value)->ptr);
break;
case T_SYMBOL:
value_id = SYM2ID(value);
@@ -1210,8 +1234,7 @@ cbsubst_get_subst_arg(argc, argv, self)
VALUE self;
{
struct cbsubst_info *inf;
- const char *str;
- char *buf, *ptr;
+ char *str, *buf, *ptr;
int i, j, len;
ID id;
volatile VALUE arg_sym, ret;
@@ -1226,7 +1249,7 @@ cbsubst_get_subst_arg(argc, argv, self)
for(i = 0; i < argc; i++) {
switch(TYPE(argv[i])) {
case T_STRING:
- str = RSTRING_PTR(argv[i]);
+ str = RSTRING(argv[i])->ptr;
arg_sym = ID2SYM(rb_intern(str));
break;
case T_SYMBOL:
@@ -1241,7 +1264,7 @@ cbsubst_get_subst_arg(argc, argv, self)
str = rb_id2name(SYM2ID(ret));
}
- id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str)));
+ id = rb_intern(RSTRING(rb_str_cat2(rb_str_new2("@"), str))->ptr);
for(j = 0; j < len; j++) {
if (inf->ivar[j] == id) break;
@@ -1277,11 +1300,11 @@ cbsubst_get_subst_key(self, str)
list = rb_funcall(cTclTkLib, ID_split_tklist, 1, str);
- len = RARRAY_LEN(list);
+ len = RARRAY(list)->len;
buf = ALLOC_N(char, len + 1);
for(i = 0; i < len; i++) {
- ptr = RSTRING_PTR(RARRAY_PTR(list)[i]);
+ ptr = RSTRING(RARRAY(list)->ptr[i])->ptr;
if (*ptr == '%' && *(ptr + 2) == '\0') {
*(buf + i) = *(ptr + 1);
} else {
@@ -1332,7 +1355,7 @@ cbsubst_table_setup(self, key_inf, proc_inf)
{
struct cbsubst_info *subst_inf;
int idx;
- int len = RARRAY_LEN(key_inf);
+ int len = RARRAY(key_inf)->len;
int real_len = 0;
char *key = ALLOC_N(char, len + 1);
char *type = ALLOC_N(char, len + 1);
@@ -1357,20 +1380,20 @@ cbsubst_table_setup(self, key_inf, proc_inf)
* ivar ==> symbol
*/
for(idx = 0; idx < len; idx++) {
- inf = RARRAY_PTR(key_inf)[idx];
+ inf = RARRAY(key_inf)->ptr[idx];
if (TYPE(inf) != T_ARRAY) continue;
- *(key + real_len) = NUM2CHR(RARRAY_PTR(inf)[0]);
- *(type + real_len) = NUM2CHR(RARRAY_PTR(inf)[1]);
+ *(key + real_len) = (char)NUM2INT(RARRAY(inf)->ptr[0]);
+ *(type + real_len) = (char)NUM2INT(RARRAY(inf)->ptr[1]);
*(ivar + real_len)
= rb_intern(
- RSTRING_PTR(
+ RSTRING(
rb_str_cat2(rb_str_new2("@"),
- rb_id2name(SYM2ID(RARRAY_PTR(inf)[2])))
- )
+ rb_id2name(SYM2ID(RARRAY(inf)->ptr[2])))
+ )->ptr
);
- rb_attr(self, SYM2ID(RARRAY_PTR(inf)[2]), 1, 0, Qtrue);
+ rb_attr(self, SYM2ID(RARRAY(inf)->ptr[2]), 1, 0, Qtrue);
real_len++;
}
*(key + real_len) = '\0';
@@ -1382,11 +1405,11 @@ cbsubst_table_setup(self, key_inf, proc_inf)
* type ==> char code
* proc ==> proc/method/obj (must respond to 'call')
*/
- len = RARRAY_LEN(proc_inf);
+ len = RARRAY(proc_inf)->len;
for(idx = 0; idx < len; idx++) {
- inf = RARRAY_PTR(proc_inf)[idx];
+ inf = RARRAY(proc_inf)->ptr[idx];
if (TYPE(inf) != T_ARRAY) continue;
- rb_hash_aset(proc, RARRAY_PTR(inf)[0], RARRAY_PTR(inf)[1]);
+ rb_hash_aset(proc, RARRAY(inf)->ptr[0], RARRAY(inf)->ptr[1]);
}
rb_const_set(self, ID_SUBST_INFO,
@@ -1411,7 +1434,7 @@ cbsubst_scan_args(self, arg_key, val_ary)
{
struct cbsubst_info *inf;
int idx;
- int len = RARRAY_LEN(val_ary);
+ int len = RARRAY(val_ary)->len;
char c;
char *ptr;
volatile VALUE dst = rb_ary_new2(len);
@@ -1427,13 +1450,14 @@ cbsubst_scan_args(self, arg_key, val_ary)
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
struct cbsubst_info, inf);
+ RARRAY(dst)->len = 0;
for(idx = 0; idx < len; idx++) {
- if (idx >= RSTRING_LEN(arg_key)) {
+ if (idx >= RSTRING(arg_key)->len) {
proc = Qnil;
- } else if (*(RSTRING_PTR(arg_key) + idx) == ' ') {
+ } else if (*(RSTRING(arg_key)->ptr + idx) == ' ') {
proc = Qnil;
} else {
- ptr = strchr(inf->key, *(RSTRING_PTR(arg_key) + idx));
+ ptr = strchr(inf->key, *(RSTRING(arg_key)->ptr + idx));
if (ptr == (char*)NULL) {
proc = Qnil;
} else {
@@ -1443,9 +1467,10 @@ cbsubst_scan_args(self, arg_key, val_ary)
}
if (NIL_P(proc)) {
- rb_ary_push(dst, RARRAY_PTR(val_ary)[idx]);
+ RARRAY(dst)->ptr[RARRAY(dst)->len++] = RARRAY(val_ary)->ptr[idx];
} else {
- rb_ary_push(dst, rb_funcall(proc, ID_call, 1, RARRAY_PTR(val_ary)[idx]));
+ RARRAY(dst)->ptr[RARRAY(dst)->len++]
+ = rb_funcall(proc, ID_call, 1, RARRAY(val_ary)->ptr[idx]);
}
}
diff --git a/ext/win32ole/extconf.rb b/ext/win32ole/extconf.rb
index de306d0578..cee922554a 100644
--- a/ext/win32ole/extconf.rb
+++ b/ext/win32ole/extconf.rb
@@ -32,7 +32,6 @@ def create_win32ole_makefile
end
end
-
case RUBY_PLATFORM
when /mswin32/
$CFLAGS += ' /W3'
diff --git a/ext/win32ole/sample/excel2.rb b/ext/win32ole/sample/excel2.rb
index dbe4178051..46f459b36b 100644
--- a/ext/win32ole/sample/excel2.rb
+++ b/ext/win32ole/sample/excel2.rb
@@ -9,14 +9,14 @@ excel = WIN32OLE.new("excel.application")
# Create and rotate the chart
-excel.visible = TRUE;
+excel['Visible'] = TRUE;
excel.Workbooks.Add();
-excel.Range("a1").value = 3;
-excel.Range("a2").value = 2;
-excel.Range("a3").value = 1;
+excel.Range("a1")['Value'] = 3;
+excel.Range("a2")['Value'] = 2;
+excel.Range("a3")['Value'] = 1;
excel.Range("a1:a3").Select();
excelchart = excel.Charts.Add();
-excelchart.type = ChartTypeVal;
+excelchart['Type'] = ChartTypeVal;
i = 30
i.step(180, 10) do |rot|
diff --git a/ext/win32ole/tests/testNIL2VTEMPTY.rb b/ext/win32ole/tests/testNIL2VTEMPTY.rb
new file mode 100644
index 0000000000..555d35fbf3
--- /dev/null
+++ b/ext/win32ole/tests/testNIL2VTEMPTY.rb
@@ -0,0 +1,28 @@
+# This is test script to check that WIN32OLE should convert nil to VT_EMPTY in second try.
+# [ruby-talk:137054]
+
+require 'win32ole'
+require 'test/unit'
+
+class TestNIL2VT_EMPTY < Test::Unit::TestCase
+ def setup
+ fs = WIN32OLE.new('Scripting.FileSystemObject')
+ @path = fs.GetFolder(".").path
+ end
+ def test_openSchema
+ con = nil
+ begin
+ con = WIN32OLE.new('ADODB.Connection')
+ con.connectionString = "Provider=MSDASQL;Extended Properties="
+ con.connectionString +="\"DRIVER={Microsoft Text Driver (*.txt; *.csv)};DBQ=#{@path}\""
+ con.open
+ rescue
+ con = nil
+ end
+ if con
+ rs = con.openSchema(4, [nil,nil,"DUMMY", "TABLE"])
+ assert(rs)
+ end
+ end
+end
+
diff --git a/ext/win32ole/tests/testOLEMETHOD.rb b/ext/win32ole/tests/testOLEMETHOD.rb
new file mode 100644
index 0000000000..390c9999f8
--- /dev/null
+++ b/ext/win32ole/tests/testOLEMETHOD.rb
@@ -0,0 +1,92 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'rubyunit'
+
+require 'win32ole'
+require 'oleserver'
+
+class TestOLEMETHOD < RUNIT::TestCase
+ include OLESERVER
+ def setup
+ @excel_app = WIN32OLE_TYPE.new(MS_EXCEL_TYPELIB, 'Application')
+ end
+ def test_s_new
+ m = WIN32OLE_METHOD.new(@excel_app, 'Quit')
+ assert_instance_of(WIN32OLE_METHOD, m)
+ m = WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
+ assert_instance_of(WIN32OLE_METHOD, m)
+ m = WIN32OLE_METHOD.new(@excel_app, 'workbookopen')
+ assert_instance_of(WIN32OLE_METHOD, m)
+ end
+ def test_name
+ m = WIN32OLE_METHOD.new(@excel_app, 'Quit')
+ assert_equal('Quit', m.name)
+ end
+ def test_to_s
+ m = WIN32OLE_METHOD.new(@excel_app, 'Quit')
+ assert_equal('Quit', "#{m}")
+ end
+ def test_return_type
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_equal('Range', m.return_type)
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
+ assert_equal('BSTR', m.return_type)
+ end
+ def test_return_vtype
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_equal(WIN32OLE::VARIANT::VT_PTR, m.return_vtype)
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
+ assert_equal(WIN32OLE::VARIANT::VT_BSTR, m.return_vtype)
+ end
+ def test_return_type_detail
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_equal(['PTR', 'USERDEFINED', 'Range'], m.return_type_detail)
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActivePrinter')
+ assert_equal(['BSTR'], m.return_type_detail)
+ end
+
+ def test_invoke_kind
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_equal('PROPERTYGET', m.invoke_kind)
+ end
+ def test_visible
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert(m.visible?)
+ m = WIN32OLE_METHOD.new(@excel_app, 'AddRef')
+ assert(!m.visible?)
+ end
+ def test_event
+ m = WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
+ assert(m.event?)
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert(!m.event?)
+ end
+ def test_event_interface
+ m = WIN32OLE_METHOD.new(@excel_app, 'WorkbookOpen')
+ assert_equal('AppEvents', m.event_interface)
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_nil(m.event_interface)
+ end
+ def test_helpstring
+ domdoc = WIN32OLE_TYPE.new(MS_XML_TYPELIB, 'DOMDocument')
+ m = WIN32OLE_METHOD.new(domdoc, 'abort')
+ assert_equal('abort an asynchronous download', m.helpstring)
+ end
+ def test_helpfile
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert_match(/VBAXL.*\.(HLP|CHM)$/i, m.helpfile)
+ end
+ def test_helpcontext
+ m = WIN32OLE_METHOD.new(@excel_app, 'ActiveCell')
+ assert(m.helpcontext > 0)
+ end
+ def test_offset_vtbl
+ m = WIN32OLE_METHOD.new(@excel_app, 'QueryInterface')
+ assert_equal(0, m.offset_vtbl)
+ end
+ def test_dispid
+ tobj = WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation', 'FolderItem2')
+ method = WIN32OLE_METHOD.new(tobj, 'InvokeVerb')
+ assert_equal(1610743824, method.dispid)
+ end
+end
diff --git a/ext/win32ole/tests/testOLEPARAM.rb b/ext/win32ole/tests/testOLEPARAM.rb
new file mode 100644
index 0000000000..4014fadbfc
--- /dev/null
+++ b/ext/win32ole/tests/testOLEPARAM.rb
@@ -0,0 +1,65 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'rubyunit'
+
+require 'win32ole'
+require 'oleserver'
+
+class TestOLEPARAM < RUNIT::TestCase
+ include OLESERVER
+ def test_name
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ sh = classes.find {|c| c.name == 'Worksheet'}
+ saveas = sh.ole_methods.find {|m| m.name == 'SaveAs'}
+ param_names = saveas.params.collect{|p| p.name}
+ assert(param_names.size > 0)
+ assert(param_names.include?('Filename'))
+ end
+ def test_to_s
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ sh = classes.find {|c| c.name == 'Worksheet'}
+ saveas = sh.ole_methods.find {|m| m.name == 'SaveAs'}
+ param_names = saveas.params.collect{|p| "#{p}"}
+ assert(param_names.include?('Filename'))
+ end
+ def test_ole_type
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert_equal('BSTR', f.params[0].ole_type)
+ methods = classes.find {|c| c.name == 'Workbook'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert_equal('XlSaveAsAccessMode', f.params[6].ole_type)
+ end
+ def test_ole_type_detail
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert_equal(['BSTR'], f.params[0].ole_type_detail)
+ methods = classes.find {|c| c.name == 'Workbook'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert_equal(['USERDEFINED', 'XlSaveAsAccessMode'], f.params[6].ole_type_detail)
+ end
+ def test_input
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert(f.params[0].input?)
+ end
+
+ def test_output
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert(!f.params[0].output?)
+ end
+ def test_optional
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert(!f.params[0].optional?)
+ methods = classes.find {|c| c.name == 'Workbook'}.ole_methods
+ f = methods.find {|m| m.name == 'SaveAs'}
+ assert(f.params[0].optional?)
+ end
+end
diff --git a/ext/win32ole/tests/testOLETYPE.rb b/ext/win32ole/tests/testOLETYPE.rb
new file mode 100644
index 0000000000..d4eb1146e1
--- /dev/null
+++ b/ext/win32ole/tests/testOLETYPE.rb
@@ -0,0 +1,96 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'rubyunit'
+
+require 'win32ole'
+require 'oleserver'
+
+class TestOLETYPE < RUNIT::TestCase
+ include OLESERVER
+ def test_s_new
+ type = WIN32OLE_TYPE.new(MS_EXCEL_TYPELIB, 'Application')
+ assert_instance_of(WIN32OLE_TYPE, type)
+ end
+ def test_s_ole_classes
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ assert(classes.size > 0)
+ end
+ def test_s_typelibs
+ libs = WIN32OLE_TYPE.typelibs
+ assert(libs.include?(MS_EXCEL_TYPELIB))
+ assert(libs.include?(MS_XML_TYPELIB))
+ end
+ def test_s_progids
+ progids = WIN32OLE_TYPE.progids
+ assert(progids.include?('Excel.Application'))
+ end
+ def test_name
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ class_names = classes.collect{|c|
+ c.name
+ }
+ assert(class_names.include?('Application'))
+ end
+
+ def test_class_to_s
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ class_names = classes.collect{|c|
+ "#{c}"
+ }
+ assert(class_names.include?('Application'))
+ end
+
+ def test_ole_type
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ app = classes.find {|c| c.name == 'Application'}
+ assert_equal('Class', app.ole_type)
+ app = classes.find {|c| c.name == '_Application'}
+ assert_equal('Dispatch', app.ole_type)
+ end
+ def test_typekind
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ app = classes.find {|c| c.name == 'Application'}
+ assert_equal(5, app.typekind)
+ end
+ def test_visible
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ app = classes.find {|c| c.name == 'Application'}
+ assert(app.visible?)
+ app = classes.find {|c| c.name == 'IAppEvents'}
+ assert(!app.visible?)
+ end
+ def test_src_type
+ classes = WIN32OLE_TYPE.ole_classes(MS_XML_TYPELIB)
+ domnode = classes.find {|c| c.name == 'DOMNodeType'}
+ assert_equal('tagDOMNodeType', domnode.src_type)
+ end
+ def test_helpstring
+ classes = WIN32OLE_TYPE.ole_classes(MS_XML_TYPELIB)
+ domdoc = classes.find {|c| c.name == 'DOMDocument'}
+ assert_equal('W3C-DOM XML Document', domdoc.helpstring)
+ end
+ def test_variables
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ xlchart = classes.find {|c| c.name == 'XlChartType'}
+ assert(xlchart.variables.size > 0)
+ end
+ def test_ole_methods
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ worksheet = classes.find {|c| c.name == 'Worksheet'}
+ assert(worksheet.ole_methods.size > 0)
+ end
+ def test_helpfile
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ worksheet = classes.find {|c| c.name == 'Worksheet'}
+ assert_match(/VBAXL.*\.(CHM|HLP)$/, worksheet.helpfile)
+ end
+ def test_helpcontext
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ worksheet = classes.find {|c| c.name == 'Worksheet'}
+ assert_equal(131088, worksheet.helpcontext)
+ end
+ def test_to_s
+ type = WIN32OLE_TYPE.new(MS_EXCEL_TYPELIB, 'Application')
+ assert_equal("Application", "#{type}");
+ end
+end
diff --git a/ext/win32ole/tests/testOLEVARIABLE.rb b/ext/win32ole/tests/testOLEVARIABLE.rb
new file mode 100644
index 0000000000..b4bb0b57d9
--- /dev/null
+++ b/ext/win32ole/tests/testOLEVARIABLE.rb
@@ -0,0 +1,49 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'rubyunit'
+
+require 'win32ole'
+require 'oleserver'
+
+class TestOLEVARIABLE < RUNIT::TestCase
+ include OLESERVER
+ def test_name
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var_names = chart.variables.collect {|m| m.name}
+ assert(var_names.size > 0)
+ assert(var_names.include?('xl3DColumn'))
+ end
+ def test_to_s
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var_names = chart.variables.collect {|m| "#{m}"}
+ assert(var_names.size > 0)
+ assert(var_names.include?('xl3DColumn'))
+ end
+ def test_ole_type
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var = chart.variables.find {|m| m.name == 'xl3DColumn'}
+ assert_equal('INT', var.ole_type)
+ end
+ def test_ole_type_detail
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var = chart.variables.find {|m| m.name == 'xl3DColumn'}
+ assert_equal(['INT'], var.ole_type_detail)
+ end
+
+ def test_value
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var = chart.variables.find {|m| m.name == 'xl3DColumn'}
+ assert_equal(-4100, var.value)
+ end
+ def test_visible
+ classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
+ chart = classes.find {|c| c.name == 'XlChartType'}
+ var = chart.variables.find {|m| m.name == 'xl3DColumn'}
+ assert(var.visible?)
+ end
+end
diff --git a/ext/win32ole/tests/testVARIANT.rb b/ext/win32ole/tests/testVARIANT.rb
new file mode 100644
index 0000000000..f274778f27
--- /dev/null
+++ b/ext/win32ole/tests/testVARIANT.rb
@@ -0,0 +1,32 @@
+# You need RubyUnit and MS Excel and MSI to run this test script
+
+require 'rubyunit'
+
+require 'win32ole'
+
+class TestWin32OLE_VARIANT < RUNIT::TestCase
+ include WIN32OLE::VARIANT
+ def test_variant
+ assert_equal(2, VT_I2)
+ assert_equal(3, VT_I4)
+ assert_equal(4, VT_R4)
+ assert_equal(5, VT_R8)
+ assert_equal(6, VT_CY)
+ assert_equal(7, VT_DATE)
+ assert_equal(8, VT_BSTR)
+ assert_equal(9, VT_DISPATCH)
+ assert_equal(10, VT_ERROR)
+ assert_equal(11, VT_BOOL)
+ assert_equal(12, VT_VARIANT)
+ assert_equal(13, VT_UNKNOWN)
+ assert_equal(16, VT_I1)
+ assert_equal(17, VT_UI1)
+ assert_equal(18, VT_UI2)
+ assert_equal(19, VT_UI4)
+ assert_equal(22, VT_INT)
+ assert_equal(23, VT_UINT)
+ assert_equal(0x2000, VT_ARRAY)
+ assert_equal(0x4000, VT_BYREF)
+ end
+end
+
diff --git a/ext/win32ole/tests/testWIN32OLE.rb b/ext/win32ole/tests/testWIN32OLE.rb
index 401825815b..d7f9dd2543 100644
--- a/ext/win32ole/tests/testWIN32OLE.rb
+++ b/ext/win32ole/tests/testWIN32OLE.rb
@@ -1,8 +1,7 @@
# You need RubyUnit and MS Excel and MSI to run this test script
-require 'test/unit'
require 'runit/testcase'
-# require 'runit/cui/testrunner'
+require 'runit/cui/testrunner'
require 'win32ole'
require 'oleserver'
@@ -139,10 +138,11 @@ class TestWin32OLE < RUNIT::TestCase
book = @excel.workbooks.add
sheet = book.worksheets(1)
begin
- sheet.range("A1").value = 10
+ sheet.range("A1")['Value'] = 10
assert_equal(10, sheet.range("A1").value)
- sheet.cells[1, 2] = 10
+ sheet['Cells', 1, 2] = 10
assert_equal(10, sheet.range("B1").value)
+ assert_equal(10, sheet['Cells', 1, 2].value)
ensure
book.saved = true
end
@@ -156,7 +156,8 @@ 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
@@ -239,14 +240,6 @@ class TestWin32OLE < RUNIT::TestCase
book = workbooks.invoke( 'add' )
assert_instance_of(WIN32OLE, book)
end
- def test_ole_type
- tobj = @excel.ole_type
- assert_equal('_Application', tobj.name)
- end
- def test_ole_obj_help
- tobj = @excel.ole_type
- assert_equal('_Application', tobj.name)
- end
def test_ole_methods
methods = @excel.ole_methods
method_names = methods.collect{|m| m.name}
@@ -283,18 +276,6 @@ class TestWin32OLE < RUNIT::TestCase
assert(add_info.params[0].optional?)
assert_equal('VARIANT', add_info.params[0].ole_type)
end
-
- def test_ole_typelib
- tlib = @excel.ole_typelib
- assert_equal(tlib.name, MS_EXCEL_TYPELIB);
- end
-
- def test_s_create_guid
- guid = WIN32OLE.create_guid
- assert_match(/^\{[A-Z0-9]{8}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{12}/,
- guid)
- end
-
def teardown
@excel.quit
@excel = nil
@@ -302,8 +283,7 @@ class TestWin32OLE < RUNIT::TestCase
end
end
-# class TestWin32OLE_WITH_MSI < RUNIT::TestCase
-class TestWin32OLE_WITH_MSI < Test::Unit::TestCase
+class TestWin32OLE_WITH_MSI < RUNIT::TestCase
def setup
installer = WIN32OLE.new("WindowsInstaller.Installer")
@record = installer.CreateRecord(2)
@@ -322,7 +302,7 @@ class TestWin32OLE_WITH_MSI < Test::Unit::TestCase
assert_equal('dddd', @record.StringData(1))
end
def test_bracket_equal_with_arg
- @record.StringData[1] = 'ffff'
+ @record[ "StringData", 1 ] = 'ffff'
assert_equal('ffff', @record.StringData(1))
end
@@ -369,3 +349,25 @@ class TestMyExcel < TestWin32OLE
#
private :test_s_const_load
end
+
+if $0 == __FILE__
+ puts "Now Test Win32OLE version #{WIN32OLE::VERSION}"
+ if ARGV.size == 0
+ suite = RUNIT::TestSuite.new
+ suite.add_test(TestWin32OLE.suite)
+ suite.add_test(TestMyExcel.suite)
+ begin
+ installer = WIN32OLE.new("WindowsInstaller.Installer")
+ suite.add_test(TestWin32OLE_WITH_MSI.suite)
+ rescue
+ puts "Skip some test with MSI"
+ end
+ else
+ suite = RUNIT::TestSuite.new
+ ARGV.each do |testmethod|
+ suite.add_test(TestWin32OLE.new(testmethod))
+ end
+ end
+ RUNIT::CUI::TestRunner.quiet_mode = true
+ RUNIT::CUI::TestRunner.run(suite)
+end
diff --git a/test/win32ole/test_ole_methods.rb b/ext/win32ole/tests/test_ole_methods.rb
index ca1c03b010..ca1c03b010 100644
--- a/test/win32ole/test_ole_methods.rb
+++ b/ext/win32ole/tests/test_ole_methods.rb
diff --git a/ext/win32ole/tests/test_propertyputref.rb b/ext/win32ole/tests/test_propertyputref.rb
new file mode 100644
index 0000000000..befc35ca9c
--- /dev/null
+++ b/ext/win32ole/tests/test_propertyputref.rb
@@ -0,0 +1,19 @@
+require 'test/unit'
+require 'win32ole'
+
+class TestWIN32OLE_PROPERTYPUTREF < Test::Unit::TestCase
+ def setup
+ begin
+ @sapi = WIN32OLE.new('SAPI.SpVoice')
+ rescue WIN32OLERuntimeError
+ @sapi = nil
+ end
+ end
+ def test_sapi
+ if @sapi
+ new_id = @sapi.getvoices.item(2).Id
+ @sapi.voice = @sapi.getvoices.item(2)
+ assert_equal(new_id, @sapi.voice.Id)
+ end
+ end
+end
diff --git a/test/win32ole/test_win32ole_event.rb b/ext/win32ole/tests/test_win32ole_event.rb
index 0945eac78b..744021dfd2 100644
--- a/test/win32ole/test_win32ole_event.rb
+++ b/ext/win32ole/tests/test_win32ole_event.rb
@@ -6,12 +6,24 @@ 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)
@@ -21,9 +33,11 @@ if defined?(WIN32OLE_EVENT)
def test_on_event
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
ev.on_event {|*args| default_handler(*args)}
- @ie.gohome
+ @ie.navigate("file:///#{@f}")
while @ie.busy
- WIN32OLE_EVENT.message_loop
+ WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
+ GC.start
+ sleep 0.1
end
assert_match(/BeforeNavigate/, @event)
assert_match(/NavigateComplete/, @event)
@@ -33,9 +47,9 @@ if defined?(WIN32OLE_EVENT)
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
ev.on_event('BeforeNavigate') {|*args| handler1}
ev.on_event('BeforeNavigate') {|*args| handler2}
- @ie.gohome
+ @ie.navigate("file:///#{@f}")
while @ie.busy
- WIN32OLE_EVENT.message_loop
+ sleep 0.1
end
assert_equal("handler2", @event2)
end
@@ -44,9 +58,9 @@ if defined?(WIN32OLE_EVENT)
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
ev.on_event {|*args| handler1}
ev.on_event {|*args| handler2}
- @ie.gohome
+ @ie.navigate("file:///#{@f}")
while @ie.busy
- WIN32OLE_EVENT.message_loop
+ sleep 0.1
end
assert_equal("handler2", @event2)
end
@@ -56,9 +70,9 @@ if defined?(WIN32OLE_EVENT)
ev.on_event{|*args| handler1}
ev.on_event{|*args| handler2}
ev.on_event('NavigateComplete'){|*args| handler3(*args)}
- @ie.gohome
+ @ie.navigate("file:///#{@f}")
while @ie.busy
- WIN32OLE_EVENT.message_loop
+ sleep 0.1
end
assert(@event3!="")
assert("handler2", @event2)
@@ -68,15 +82,35 @@ if defined?(WIN32OLE_EVENT)
ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
ev.on_event {|*args| default_handler(*args)}
ev.on_event('NavigateComplete'){|*args| handler3(*args)}
- @ie.gohome
+ @ie.navigate("file:///#{@f}")
while @ie.busy
- WIN32OLE_EVENT.message_loop
+ 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
@@ -92,8 +126,8 @@ if defined?(WIN32OLE_EVENT)
def teardown
@ie.quit
@ie = nil
+ File.unlink(@f)
GC.start
- sleep 1
end
end
end
diff --git a/test/win32ole/test_word.rb b/ext/win32ole/tests/test_word.rb
index 53a6c521ba..53a6c521ba 100644
--- a/test/win32ole/test_word.rb
+++ b/ext/win32ole/tests/test_word.rb
diff --git a/ext/win32ole/tests/testall.rb b/ext/win32ole/tests/testall.rb
index 12e97e3913..553ce88509 100644
--- a/ext/win32ole/tests/testall.rb
+++ b/ext/win32ole/tests/testall.rb
@@ -1,4 +1,16 @@
-require 'test/unit'
+require 'rubyunit'
require 'win32ole'
puts "Now Test Win32OLE version #{WIN32OLE::VERSION}"
+# RUNIT::CUI::TestRunner.quiet_mode = true
require "testWIN32OLE"
+require "testOLETYPE"
+require "testOLEPARAM"
+require "testOLEMETHOD"
+require "testOLEVARIABLE"
+require "testVARIANT"
+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 34eebeff45..dc1b77d5e9 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -18,7 +18,6 @@
#include "ruby.h"
#include "st.h"
-#include <ctype.h>
#include <windows.h>
#include <ocidl.h>
#include <olectl.h>
@@ -30,6 +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.8.0"
+#define WIN32OLE_VERSION "0.7.6"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -139,16 +139,13 @@ typedef struct tagIEVENTSINKOBJ {
}IEVENTSINKOBJ, *PIEVENTSINKOBJ;
VALUE cWIN32OLE;
-VALUE cWIN32OLE_TYPELIB;
VALUE cWIN32OLE_TYPE;
VALUE cWIN32OLE_VARIABLE;
VALUE cWIN32OLE_METHOD;
VALUE cWIN32OLE_PARAM;
VALUE cWIN32OLE_EVENT;
-VALUE cWIN32OLE_VARIANT;
VALUE eWIN32OLE_RUNTIME_ERROR;
VALUE mWIN32OLE_VARIANT;
-VALUE cWIN32OLE_PROPERTY;
static VALUE ary_ole_event;
static ID id_events;
@@ -160,6 +157,9 @@ 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;
@@ -196,22 +196,111 @@ struct oleparam {
OLECHAR** pNamedArgs;
};
-struct olevariantdata {
- VARIANT realvar;
- VARIANT var;
-};
-
-static VALUE folemethod_s_allocate(VALUE);
-static VALUE olemethod_set_member(VALUE, ITypeInfo *, ITypeInfo *, int, VALUE);
-static VALUE foletype_s_allocate(VALUE);
-static VALUE oletype_set_member(VALUE, ITypeInfo *, VALUE);
-static VALUE olemethod_from_typeinfo(VALUE, ITypeInfo *, VALUE);
-static HRESULT ole_docinfo_from_type(ITypeInfo *, BSTR *, BSTR *, DWORD *, BSTR *);
+static VALUE folemethod_s_allocate _((VALUE));
+static VALUE olemethod_set_member _((VALUE, ITypeInfo *, ITypeInfo *, int, VALUE));
+static VALUE foletype_s_allocate _((VALUE));
+static VALUE oletype_set_member _((VALUE, ITypeInfo *, VALUE));
+static VALUE olemethod_from_typeinfo _((VALUE, ITypeInfo *, VALUE));
+static HRESULT ole_docinfo_from_type _((ITypeInfo *, BSTR *, BSTR *, DWORD *, BSTR *));
static char *ole_wc2mb(LPWSTR);
static VALUE ole_variant2val(VARIANT*);
static void ole_val2variant(VALUE, VARIANT*);
-static VALUE create_property_object(VALUE, VALUE, HRESULT, VALUE);
+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;
@@ -280,9 +369,7 @@ static HRESULT ( STDMETHODCALLTYPE GetIDsOfNames )(
/* [in] */ LCID lcid,
/* [size_is][out] */ DISPID __RPC_FAR *rgDispId)
{
- /*
Win32OLEIDispatch* p = (Win32OLEIDispatch*)This;
- */
char* psz = ole_wc2mb(*rgszNames); // support only one method
*rgDispId = rb_intern(psz);
free(psz);
@@ -321,7 +408,8 @@ static /* [local] */ HRESULT ( STDMETHODCALLTYPE Invoke )(
}
static IDispatch*
-val2dispatch(VALUE val)
+val2dispatch(val)
+ VALUE val;
{
struct st_table *tbl = DATA_PTR(com_hash);
Win32OLEIDispatch* pdisp;
@@ -342,13 +430,17 @@ val2dispatch(VALUE val)
}
static void
-time2d(int hh, int mm, int ss, double *pv)
+time2d(hh, mm, ss, pv)
+ int hh, mm, ss;
+ double *pv;
{
*pv = (hh * 60.0 * 60.0 + mm * 60.0 + ss) / 86400.0;
}
static void
-d2time(double v, int *hh, int *mm, int *ss)
+d2time(v, hh, mm, ss)
+ double v;
+ int *hh, *mm, *ss;
{
double d_hh, d_mm, d_ss;
int i_hh, i_mm, i_ss;
@@ -388,7 +480,9 @@ d2time(double v, int *hh, int *mm, int *ss)
}
static void
-civil2jd(int y, int m, int d, long *jd)
+civil2jd(y, m, d, jd)
+ int y, m, d;
+ long *jd;
{
long a, b;
if (m <= 2) {
@@ -403,7 +497,9 @@ civil2jd(int y, int m, int d, long *jd)
}
static void
-jd2civil(long day, int *yy, int *mm, int *dd)
+jd2civil(day, yy, mm, dd)
+ long day;
+ int *yy, *mm, *dd;
{
long x, a, b, c, d, e;
x = (long)(((double)day - 1867216.25) / 36524.25);
@@ -424,7 +520,9 @@ jd2civil(long day, int *yy, int *mm, int *dd)
}
static void
-double2time(double v, int *y, int *m, int *d, int *hh, int *mm, int *ss)
+double2time(v, y, m, d, hh, mm, ss)
+ double v;
+ int *y, *m, *d, *hh, *mm, *ss;
{
long day;
double t;
@@ -437,7 +535,8 @@ double2time(double v, int *y, int *m, int *d, int *hh, int *mm, int *ss)
}
static double
-time_object2date(VALUE tmobj)
+time_object2date(tmobj)
+ VALUE tmobj;
{
long y, m, d, hh, mm, ss;
long day;
@@ -454,13 +553,14 @@ time_object2date(VALUE tmobj)
}
static VALUE
-date2time_str(double date)
+date2time_str(date)
+ double date;
{
int y, m, d, hh, mm, ss;
- char szTime[20];
+ char szTime[40];
double2time(date, &y, &m, &d, &hh, &mm, &ss);
sprintf(szTime,
- "%04d/%02d/%02d %02d:%02d:%02d",
+ "%4.4d/%02.2d/%02.2d %02.2d:%02.2d:%02.2d",
y, m, d, hh, mm, ss);
return rb_str_new2(szTime);
}
@@ -468,14 +568,16 @@ date2time_str(double date)
static void ole_val2variant();
static char *
-ole_wc2mb(LPWSTR pw)
+ole_wc2mb(pw)
+ LPWSTR pw;
{
int size;
LPSTR pm;
size = WideCharToMultiByte(cWIN32OLE_cp, 0, pw, -1, NULL, 0, NULL, NULL);
if (size) {
- pm = ALLOC_N(char, size);
+ pm = ALLOC_N(char, size + 1);
WideCharToMultiByte(cWIN32OLE_cp, 0, pw, -1, pm, size, NULL, NULL);
+ pm[size] = '\0';
}
else {
pm = ALLOC_N(char, 1);
@@ -485,7 +587,8 @@ ole_wc2mb(LPWSTR pw)
}
static VALUE
-ole_hresult2msg(HRESULT hr)
+ole_hresult2msg(hr)
+ HRESULT hr;
{
VALUE msg = Qnil;
char *p_msg = NULL;
@@ -493,7 +596,7 @@ ole_hresult2msg(HRESULT hr)
DWORD dwCount;
char strhr[100];
- sprintf(strhr, " HRESULT error code:0x%08x\n ", (unsigned)hr);
+ sprintf(strhr, " HRESULT error code:0x%08lx\n ", hr);
msg = rb_str_new2(strhr);
dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
@@ -517,8 +620,18 @@ ole_hresult2msg(HRESULT hr)
return msg;
}
+static void
+ole_freeexceptinfo(pExInfo)
+ EXCEPINFO *pExInfo;
+{
+ SysFreeString(pExInfo->bstrDescription);
+ SysFreeString(pExInfo->bstrSource);
+ SysFreeString(pExInfo->bstrHelpFile);
+}
+
static VALUE
-ole_excepinfo2msg(EXCEPINFO *pExInfo)
+ole_excepinfo2msg(pExInfo)
+ EXCEPINFO *pExInfo;
{
char error_code[40];
char *pSource = NULL;
@@ -555,14 +668,20 @@ ole_excepinfo2msg(EXCEPINFO *pExInfo)
}
if(pSource) free(pSource);
if(pDescription) free(pDescription);
- SysFreeString(pExInfo->bstrDescription);
- SysFreeString(pExInfo->bstrSource);
- SysFreeString(pExInfo->bstrHelpFile);
+ ole_freeexceptinfo(pExInfo);
return error_msg;
}
static void
+#ifdef HAVE_STDARG_PROTOTYPES
ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...)
+#else
+ole_raise(hr, exc, fmt, va_alist)
+ HRESULT hr;
+ VALUE exc;
+ const char *fmt;
+ va_dcl
+#endif
{
va_list args;
char buf[BUFSIZ];
@@ -604,6 +723,11 @@ 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");
+ }
}
}
@@ -617,38 +741,50 @@ ole_msg_loop() {
}
static void
-ole_free(struct oledata *pole)
+ole_free(pole)
+ struct oledata *pole;
{
OLE_FREE(pole->pDispatch);
+ free(pole);
}
static void
-oletype_free(struct oletypedata *poletype)
+oletype_free(poletype)
+ struct oletypedata *poletype;
{
OLE_FREE(poletype->pTypeInfo);
+ free(poletype);
}
static void
-olemethod_free(struct olemethoddata *polemethod)
+olemethod_free(polemethod)
+ struct olemethoddata *polemethod;
{
OLE_FREE(polemethod->pTypeInfo);
OLE_FREE(polemethod->pOwnerTypeInfo);
+ free(polemethod);
}
static void
-olevariable_free(struct olevariabledata *polevar)
+olevariable_free(polevar)
+ struct olevariabledata *polevar;
{
OLE_FREE(polevar->pTypeInfo);
+ free(polevar);
}
static void
-oleparam_free(struct oleparamdata *pole)
+oleparam_free(pole)
+ struct oleparamdata *pole;
{
OLE_FREE(pole->pTypeInfo);
+ free(pole);
}
static LPWSTR
-ole_mb2wc(char *pm, int len)
+ole_mb2wc(pm, len)
+ char *pm;
+ int len;
{
int size;
LPWSTR pw;
@@ -659,7 +795,9 @@ ole_mb2wc(char *pm, int len)
}
static VALUE
-ole_wc2vstr(LPWSTR pw, BOOL isfree)
+ole_wc2vstr(pw, isfree)
+ LPWSTR pw;
+ BOOL isfree;
{
char *p = ole_wc2mb(pw);
VALUE vstr = rb_str_new2(p);
@@ -670,7 +808,9 @@ ole_wc2vstr(LPWSTR pw, BOOL isfree)
}
static VALUE
-ole_ary_m_entry(VALUE val, long *pid)
+ole_ary_m_entry(val, pid)
+ VALUE val;
+ long *pid;
{
VALUE obj = Qnil;
int i = 0;
@@ -683,7 +823,13 @@ ole_ary_m_entry(VALUE val, long *pid)
}
static void
-ole_set_safe_array(long n, SAFEARRAY *psa, long *pid, long *pub, VALUE val, long dim)
+ole_set_safe_array(n, psa, pid, pub, val, dim)
+ long n;
+ SAFEARRAY *psa;
+ long *pid;
+ long *pub;
+ VALUE val;
+ long dim;
{
VALUE val1;
VARIANT var;
@@ -704,116 +850,12 @@ ole_set_safe_array(long n, SAFEARRAY *psa, long *pid, long *pub, VALUE val, long
}
}
-static void * get_ptr_of_variant(VARIANT *pvar)
-{
- switch(V_VT(pvar)) {
- case VT_UI1:
- return &V_UI1(pvar);
- break;
- case VT_I2:
- return &V_I2(pvar);
- break;
- case VT_I4:
- return &V_I4(pvar);
- break;
- case VT_UI4:
- return &V_UI4(pvar);
- break;
-/*
- case VT_I8:
- return &V_I8(pvar);
- break;
-*/
- case VT_R4:
- return &V_R4(pvar);
- break;
- case VT_R8:
- return &V_R8(pvar);
- break;
- case VT_CY:
- return &V_CY(pvar);
- break;
- case VT_DATE:
- return &V_DATE(pvar);
- break;
- case VT_BSTR:
- return &V_BSTR(pvar);
- break;
- case VT_DISPATCH:
- return &V_DISPATCH(pvar);
- break;
- case VT_ERROR:
- return &V_ERROR(pvar);
- break;
- case VT_BOOL:
- return &V_BOOL(pvar);
- break;
-/*
- case VT_VARIANT:
- return &V_VARIANT(pvar);
- break;
-*/
- case VT_UNKNOWN:
- return &V_UNKNOWN(pvar);
- break;
- case VT_ARRAY:
- return &V_ARRAY(pvar);
- break;
- default:
- return NULL;
- break;
- }
-}
-
static void
-ole_set_safe_array_with_type(long n, SAFEARRAY *psa, long *pid, long *pub, VALUE val, long dim, VARTYPE vtype)
-{
- VALUE val1;
- HRESULT hr;
- VARIANT var;
- VARIANT vart;
- VOID *p = NULL;
- VariantInit(&var);
- VariantInit(&vart);
- if(n < 0) return;
- if(n == dim) {
- val1 = ole_ary_m_entry(val, pid);
- ole_val2variant(val1, &var);
- VariantInit(&vart);
- if (vtype != V_VT(&var)) {
- hr = VariantChangeTypeEx(&vart, &var,
- LOCALE_SYSTEM_DEFAULT, 0, (VARTYPE)(vtype & ~VT_BYREF));
- if (FAILED(hr)) {
- ole_raise(hr, rb_eRuntimeError, "failed to change type");
- }
- p = get_ptr_of_variant(&vart);
- }
- else {
- p = get_ptr_of_variant(&var);
- }
- if (p == NULL) {
- rb_raise(rb_eRuntimeError, "failed to get ponter of variant");
- }
- hr = SafeArrayPutElement(psa, pid, p);
- if (FAILED(hr)) {
- ole_raise(hr, rb_eRuntimeError, "failed to SafeArrayPutElement");
- }
- }
- pid[n] += 1;
- if (pid[n] < pub[n]) {
- ole_set_safe_array_with_type(dim, psa, pid, pub, val, dim, vtype);
- }
- else {
- pid[n] = 0;
- ole_set_safe_array_with_type(n-1, psa, pid, pub, val, dim, vtype);
- }
-}
-
-static void
-ole_val2variant(VALUE val, VARIANT *var)
+ole_val2variant(val, var)
+ VALUE val;
+ VARIANT *var;
{
struct oledata *pole;
- struct olevariantdata *pvar;
if(rb_obj_is_kind_of(val, cWIN32OLE)) {
Data_Get_Struct(val, struct oledata, pole);
OLE_ADDREF(pole->pDispatch);
@@ -821,13 +863,6 @@ ole_val2variant(VALUE val, VARIANT *var)
V_DISPATCH(var) = pole->pDispatch;
return;
}
-
- if (rb_obj_is_kind_of(val, cWIN32OLE_VARIANT)) {
- Data_Get_Struct(val, struct olevariantdata, pvar);
- VariantCopy(var, &(pvar->var));
- return;
- }
-
if (rb_obj_is_kind_of(val, rb_cTime)) {
V_VT(var) = VT_DATE;
V_DATE(var) = time_object2date(val);
@@ -863,7 +898,7 @@ ole_val2variant(VALUE val, VARIANT *var)
val1 = val;
i = 0;
while(TYPE(val1) == T_ARRAY) {
- psab[i].cElements = RARRAY_LEN(val1);
+ psab[i].cElements = RARRAY(val1)->len;
psab[i].lLbound = 0;
pub[i] = psab[i].cElements;
pid[i] = 0;
@@ -932,249 +967,9 @@ ole_val2variant(VALUE val, VARIANT *var)
}
static void
-ole_val2ptr_variant(VALUE val, VARIANT *var)
-{
- switch (TYPE(val)) {
- case T_STRING:
- if (V_VT(var) == (VT_BSTR | VT_BYREF)) {
- *V_BSTRREF(var) = ole_mb2wc(StringValuePtr(val), -1);
- }
- break;
- case T_FIXNUM:
- switch(V_VT(var)) {
- case (VT_UI1 | VT_BYREF) :
- *V_UI1REF(var) = NUM2CHR(val);
- break;
- case (VT_I2 | VT_BYREF) :
- *V_I2REF(var) = (short)NUM2INT(val);
- break;
- case (VT_I4 | VT_BYREF) :
- *V_I4REF(var) = NUM2INT(val);
- break;
- case (VT_R4 | VT_BYREF) :
- *V_R4REF(var) = (float)NUM2INT(val);
- break;
- case (VT_R8 | VT_BYREF) :
- *V_R8REF(var) = NUM2INT(val);
- break;
- default:
- break;
- }
- break;
- case T_FLOAT:
- switch(V_VT(var)) {
- case (VT_I2 | VT_BYREF) :
- *V_I2REF(var) = (short)NUM2INT(val);
- break;
- case (VT_I4 | VT_BYREF) :
- *V_I4REF(var) = NUM2INT(val);
- break;
- case (VT_R4 | VT_BYREF) :
- *V_R4REF(var) = (float)NUM2DBL(val);
- break;
- case (VT_R8 | VT_BYREF) :
- *V_R8REF(var) = NUM2DBL(val);
- break;
- default:
- break;
- }
- break;
- case T_BIGNUM:
- if (V_VT(var) == (VT_R8 | VT_BYREF)) {
- *V_R8REF(var) = rb_big2dbl(val);
- }
- break;
- case T_TRUE:
- if (V_VT(var) == (VT_BOOL | VT_BYREF)) {
- *V_BOOLREF(var) = VARIANT_TRUE;
- }
- break;
- case T_FALSE:
- if (V_VT(var) == (VT_BOOL | VT_BYREF)) {
- *V_BOOLREF(var) = VARIANT_FALSE;
- }
- break;
- default:
- break;
- }
-}
-
-static void
-ole_var2ptr_var(VARIANT *var, VARIANT *pvar)
-{
- VARTYPE vt = V_VT(var);
- V_VT(pvar) = V_VT(var) | VT_BYREF;
- switch(vt) {
- case VT_UI1:
- V_UI1REF(pvar) = &V_UI1(var);
- break;
- case VT_I2:
- V_I2REF(pvar) = &V_I2(var);
- break;
- case VT_I4:
- V_I4REF(pvar) = &V_I4(var);
- break;
- case VT_UI4:
- V_UI4REF(pvar) = &V_UI4(var);
- break;
-/*
- case VT_I8:
- V_I8REF(pvar) = &V_I8(var);
- break;
-*/
- case VT_R4:
- V_R4REF(pvar) = &V_R4(var);
- break;
- case VT_R8:
- V_R8REF(pvar) = &V_R8(var);
- break;
- case VT_CY:
- V_CYREF(pvar) = &V_CY(var);
- break;
- case VT_DATE:
- V_DATEREF(pvar) = &V_DATE(var);
- break;
- case VT_BSTR:
- V_BSTRREF(pvar) = &V_BSTR(var);
- break;
- case VT_DISPATCH:
- V_DISPATCHREF(pvar) = &V_DISPATCH(var);
- break;
- case VT_ERROR:
- V_ERRORREF(pvar) = &V_ERROR(var);
- break;
- case VT_BOOL:
- V_BOOLREF(pvar) = &V_BOOL(var);
- break;
-/*
- case VT_VARIANT:
- V_VARIANTREF(pvar) = &V_VARIANT(var);
- break;
-*/
- case VT_UNKNOWN:
- V_UNKNOWNREF(pvar) = &V_UNKNOWN(var);
- break;
- case VT_ARRAY:
- V_ARRAYREF(pvar) = &V_ARRAY(var);
- break;
- default:
- break;
- }
-}
-
-static void
-ole_val2olevariantdata(VALUE val, VARTYPE vtype, struct olevariantdata *pvar)
-{
- HRESULT hr = S_OK;
- VARIANT var;
-
- if (((vtype & ~VT_BYREF) == (VT_ARRAY | VT_UI1)) && TYPE(val) == T_STRING) {
- long len = RSTRING_LEN(val);
- char *pdest = NULL;
- SAFEARRAY *psa = SafeArrayCreateVector(VT_UI1, 0, len);
- if (!psa) {
- rb_raise(rb_eRuntimeError, "fail to SafeArrayCreateVector");
- }
- hr = SafeArrayAccessData(psa, (void **)&pdest);
- if (SUCCEEDED(hr)) {
- memcpy(pdest, RSTRING_PTR(val), len);
- SafeArrayUnaccessData(psa);
- V_VT(&(pvar->realvar)) = vtype;
- V_ARRAY(&(pvar->realvar)) = psa;
- hr = VariantCopy(&(pvar->var), &(pvar->realvar));
- } else {
- if (psa)
- SafeArrayDestroy(psa);
- }
- } else if (vtype & VT_ARRAY) {
- VALUE val1;
- long dim = 0;
- int i = 0;
-
- SAFEARRAYBOUND *psab = NULL;
- SAFEARRAY *psa = NULL;
- long *pub, *pid;
-
- val1 = val;
- while(TYPE(val1) == T_ARRAY) {
- val1 = rb_ary_entry(val1, 0);
- dim += 1;
- }
- psab = ALLOC_N(SAFEARRAYBOUND, dim);
- pub = ALLOC_N(long, dim);
- pid = ALLOC_N(long, dim);
-
- if(!psab || !pub || !pid) {
- if(pub) free(pub);
- if(psab) free(psab);
- if(pid) free(pid);
- rb_raise(rb_eRuntimeError, "memory allocation error");
- }
- val1 = val;
- i = 0;
- while(TYPE(val1) == T_ARRAY) {
- psab[i].cElements = RARRAY_LEN(val1);
- psab[i].lLbound = 0;
- pub[i] = psab[i].cElements;
- pid[i] = 0;
- i ++;
- val1 = rb_ary_entry(val1, 0);
- }
- /* Create and fill VARIANT array */
- psa = SafeArrayCreate(vtype & VT_TYPEMASK, dim, psab);
- if (psa == NULL)
- hr = E_OUTOFMEMORY;
- else
- hr = SafeArrayLock(psa);
- if (SUCCEEDED(hr)) {
- ole_set_safe_array_with_type(dim-1, psa, pid, pub, val, dim-1, vtype& VT_TYPEMASK);
- hr = SafeArrayUnlock(psa);
- }
- if(pub) free(pub);
- if(psab) free(psab);
- if(pid) free(pid);
-
- if (SUCCEEDED(hr)) {
- V_VT(&(pvar->realvar)) = vtype;
- V_ARRAY(&(pvar->realvar)) = psa;
- hr = VariantCopy(&(pvar->var), &(pvar->realvar));
- }
- else {
- if (psa != NULL)
- SafeArrayDestroy(psa);
- }
- } else {
- ole_val2variant(val, &(pvar->realvar));
- if (vtype & VT_BYREF) {
- if ( (vtype & ~VT_BYREF) == V_VT(&(pvar->realvar))) {
- ole_var2ptr_var(&(pvar->realvar), &(pvar->var));
- } else {
- VariantInit(&var);
- hr = VariantChangeTypeEx(&(var), &(pvar->realvar),
- LOCALE_SYSTEM_DEFAULT, 0, (VARTYPE)(vtype & ~VT_BYREF));
- if (SUCCEEDED(hr)) {
- VariantClear(&(pvar->realvar));
- hr = VariantCopy(&(pvar->realvar), &var);
- VariantClear(&var);
- ole_var2ptr_var(&(pvar->realvar), &(pvar->var));
- }
- }
- } else {
- if (vtype == V_VT(&(pvar->realvar))) {
- hr = VariantCopy(&(pvar->var), &(pvar->realvar));
- } else {
- hr = VariantChangeTypeEx(&(pvar->var), &(pvar->realvar),
- LOCALE_SYSTEM_DEFAULT, 0, vtype);
- }
- }
- }
- if (FAILED(hr)) {
- ole_raise(hr, rb_eRuntimeError, "failed to change type");
- }
-}
-
-static void
-ole_val2variant2(VALUE val, VARIANT *var)
+ole_val2variant2(val, var)
+ VALUE val;
+ VARIANT *var;
{
g_nil_to = VT_EMPTY;
ole_val2variant(val, var);
@@ -1182,26 +977,9 @@ ole_val2variant2(VALUE val, VARIANT *var)
}
static VALUE
-make_inspect(const char *class_name, VALUE detail)
-{
- VALUE str;
- str = rb_str_new2("#<");
- rb_str_cat2(str, class_name);
- rb_str_cat2(str, ":");
- rb_str_concat(str, detail);
- rb_str_cat2(str, ">");
- return str;
-}
-
-static VALUE
-default_inspect(VALUE self, const char *class_name)
-{
- VALUE detail = rb_funcall(self, rb_intern("to_s"), 0);
- return make_inspect(class_name, detail);
-}
-
-static VALUE
-ole_set_member(VALUE self, IDispatch *dispatch)
+ole_set_member(self, dispatch)
+ VALUE self;
+ IDispatch * dispatch;
{
struct oledata *pole;
Data_Get_Struct(self, struct oledata, pole);
@@ -1213,9 +991,10 @@ ole_set_member(VALUE self, IDispatch *dispatch)
return self;
}
-
+static VALUE fole_s_allocate _((VALUE));
static VALUE
-fole_s_allocate(VALUE klass)
+fole_s_allocate(klass)
+ VALUE klass;
{
struct oledata *pole;
VALUE obj;
@@ -1226,7 +1005,11 @@ fole_s_allocate(VALUE klass)
}
static VALUE
-create_win32ole_object(VALUE klass, IDispatch *pDispatch, int argc, VALUE *argv)
+create_win32ole_object(klass, pDispatch, argc, argv)
+ VALUE klass;
+ IDispatch *pDispatch;
+ int argc;
+ VALUE *argv;
{
VALUE obj = fole_s_allocate(klass);
ole_set_member(obj, pDispatch);
@@ -1234,7 +1017,8 @@ create_win32ole_object(VALUE klass, IDispatch *pDispatch, int argc, VALUE *argv)
}
static VALUE
-ole_variant2val(VARIANT *pvar)
+ole_variant2val(pvar)
+ VARIANT *pvar;
{
VALUE obj = Qnil;
HRESULT hr;
@@ -1247,9 +1031,14 @@ ole_variant2val(VARIANT *pvar)
long *pID, *pLB, *pUB;
VARIANT variant;
VALUE val;
- VALUE val2 = Qnil;
+ VALUE val2;
+ int dim = 0;
+
+ if (!psa) {
+ return obj;
+ }
+ dim = SafeArrayGetDim(psa);
- int dim = SafeArrayGetDim(psa);
VariantInit(&variant);
V_VT(&variant) = (V_VT(pvar) & ~VT_ARRAY) | VT_BYREF;
@@ -1271,6 +1060,7 @@ ole_variant2val(VARIANT *pvar)
SafeArrayGetLBound(psa, i+1, &pID[i]);
SafeArrayGetUBound(psa, i+1, &pUB[i]);
}
+
hr = SafeArrayLock(psa);
if (SUCCEEDED(hr)) {
val2 = rb_ary_new();
@@ -1278,6 +1068,7 @@ ole_variant2val(VARIANT *pvar)
hr = SafeArrayPtrOfIndex(psa, pID, &V_BYREF(&variant));
if (FAILED(hr))
break;
+
val = ole_variant2val(&variant);
rb_ary_push(val2, val);
for (i = dim-1 ; i >= 0 ; --i) {
@@ -1436,55 +1227,58 @@ ole_variant2val(VARIANT *pvar)
return obj;
}
-static LONG reg_open_key(HKEY hkey, const char *name, HKEY *phkey)
+
+static LONG reg_open_key(hkey, name, phkey)
+ HKEY hkey;
+ const char *name;
+ HKEY *phkey;
{
return RegOpenKeyEx(hkey, name, 0, KEY_READ, phkey);
}
-static LONG reg_open_vkey(HKEY hkey, VALUE key, HKEY *phkey)
+static LONG reg_open_vkey(hkey, key, phkey)
+ HKEY hkey;
+ VALUE key;
+ HKEY *phkey;
{
return reg_open_key(hkey, StringValuePtr(key), phkey);
}
static VALUE
-reg_enum_key(HKEY hkey, DWORD i)
+reg_enum_key(hkey, i)
+ HKEY hkey;
+ DWORD i;
{
- char buf[BUFSIZ];
- DWORD size_buf = sizeof(buf);
+ char buf[BUFSIZ + 1];
+ DWORD size_buf = sizeof(buf) - 1;
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;
}
static VALUE
-reg_get_val(HKEY hkey, const char *subkey)
+reg_get_val(hkey, subkey)
+ HKEY hkey;
+ const char *subkey;
{
- char buf[BUFSIZ];
- LONG size_buf = sizeof(buf);
+ char buf[BUFSIZ + 1];
+ LONG size_buf = sizeof(buf) - 1;
LONG err = RegQueryValue(hkey, subkey, buf, &size_buf);
if (err == ERROR_SUCCESS) {
+ buf[BUFSIZ] = '\0';
return rb_str_new2(buf);
}
return Qnil;
}
static VALUE
-reg_get_typelib_file_path(HKEY hkey)
-{
- VALUE path = Qnil;
- path = reg_get_val(hkey, "win32");
- if (path == Qnil) {
- path = reg_get_val(hkey, "win16");
- }
- return path;
-}
-
-static VALUE
-typelib_file_from_clsid(VALUE ole)
+typelib_file_from_clsid(ole)
+ VALUE ole;
{
OLECHAR *pbuf;
CLSID clsid;
@@ -1493,6 +1287,7 @@ typelib_file_from_clsid(VALUE ole)
LONG err;
VALUE typelib;
VALUE vclsid;
+ char *pclsid = NULL;
pbuf = ole_mb2wc(StringValuePtr(ole), -1);
hr = CLSIDFromProgID(pbuf, &clsid);
@@ -1518,7 +1313,8 @@ typelib_file_from_clsid(VALUE ole)
}
static VALUE
-typelib_file_from_typelib(VALUE ole)
+typelib_file_from_typelib(ole)
+ VALUE ole;
{
HKEY htypelib, hclsid, hversion, hlang;
double fver;
@@ -1561,7 +1357,7 @@ typelib_file_from_typelib(VALUE ole)
break;
err = reg_open_vkey(hversion, lang, &hlang);
if (err == ERROR_SUCCESS) {
- if ((file = reg_get_typelib_file_path(hlang)) != Qnil)
+ if ((file = reg_get_val(hlang, "win32")) != Qnil)
found = TRUE;
RegCloseKey(hlang);
}
@@ -1576,7 +1372,8 @@ typelib_file_from_typelib(VALUE ole)
}
static VALUE
-typelib_file(VALUE ole)
+typelib_file(ole)
+ VALUE ole;
{
VALUE file = typelib_file_from_clsid(ole);
if (file != Qnil) {
@@ -1586,7 +1383,10 @@ typelib_file(VALUE ole)
}
static void
-ole_const_load(ITypeLib *pTypeLib, VALUE klass, VALUE self)
+ole_const_load(pTypeLib, klass, self)
+ ITypeLib *pTypeLib;
+ VALUE klass;
+ VALUE self;
{
unsigned int count;
unsigned int index;
@@ -1649,7 +1449,10 @@ ole_const_load(ITypeLib *pTypeLib, VALUE klass, VALUE self)
}
static HRESULT
-clsid_from_remote(VALUE host, VALUE com, CLSID *pclsid)
+clsid_from_remote(host, com, pclsid)
+ VALUE host;
+ VALUE com;
+ CLSID *pclsid;
{
HKEY hlm;
HKEY hpid;
@@ -1671,7 +1474,7 @@ clsid_from_remote(VALUE host, VALUE com, CLSID *pclsid)
hr = HRESULT_FROM_WIN32(err);
else {
len = sizeof(clsid);
- err = RegQueryValueEx(hpid, (LPBYTE)"", NULL, &dwtype, clsid, &len);
+ err = RegQueryValueEx(hpid, "", NULL, &dwtype, clsid, &len);
if (err == ERROR_SUCCESS && dwtype == REG_SZ) {
pbuf = ole_mb2wc(clsid, -1);
hr = CLSIDFromString(pbuf, pclsid);
@@ -1687,7 +1490,10 @@ clsid_from_remote(VALUE host, VALUE com, CLSID *pclsid)
}
static VALUE
-ole_create_dcom(int argc, VALUE *argv, VALUE self)
+ole_create_dcom(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE ole, host, others;
HRESULT hr;
@@ -1737,7 +1543,11 @@ ole_create_dcom(int argc, VALUE *argv, VALUE self)
}
static VALUE
-ole_bind_obj(VALUE moniker, int argc, VALUE *argv, VALUE self)
+ole_bind_obj(moniker, argc, argv, self)
+ VALUE moniker;
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
IBindCtx *pBindCtx;
IMoniker *pMoniker;
@@ -1787,7 +1597,10 @@ ole_bind_obj(VALUE moniker, int argc, VALUE *argv, VALUE self)
* WIN32OLE.connect('Excel.Application') # => WIN32OLE object which represents running Excel.
*/
static VALUE
-fole_s_connect(int argc, VALUE *argv, VALUE self)
+fole_s_connect(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE svr_name;
VALUE others;
@@ -1867,7 +1680,10 @@ fole_s_connect(int argc, VALUE *argv, VALUE self)
* puts MSO::MsoLineSingle # => 1
*/
static VALUE
-fole_s_const_load(int argc, VALUE *argv, VALUE self)
+fole_s_const_load(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE ole;
VALUE klass;
@@ -1917,7 +1733,7 @@ fole_s_const_load(int argc, VALUE *argv, VALUE self)
hr = LoadTypeLibEx(pBuf, REGKIND_NONE, &pTypeLib);
SysFreeString(pBuf);
if (FAILED(hr))
- ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "failed to LoadTypeLibEx");
+ ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "failed to LoadTypeLibEx");
if(TYPE(klass) != T_NIL) {
ole_const_load(pTypeLib, klass, self);
}
@@ -1933,7 +1749,9 @@ fole_s_const_load(int argc, VALUE *argv, VALUE self)
}
static VALUE
-ole_classes_from_typelib(ITypeLib *pTypeLib, VALUE classes)
+ole_classes_from_typelib(pTypeLib, classes)
+ ITypeLib *pTypeLib;
+ VALUE classes;
{
long count;
@@ -1965,7 +1783,8 @@ ole_classes_from_typelib(ITypeLib *pTypeLib, VALUE classes)
}
static ULONG
-reference_count(struct oledata * pole)
+reference_count(pole)
+ struct oledata * pole;
{
ULONG n = 0;
if(pole->pDispatch) {
@@ -1984,7 +1803,9 @@ reference_count(struct oledata * pole)
* exists only for debugging WIN32OLE.
*/
static VALUE
-fole_s_reference_count(VALUE self, VALUE obj)
+fole_s_reference_count(self, obj)
+ VALUE self;
+ VALUE obj;
{
struct oledata * pole;
OLEData_Get_Struct(obj, pole);
@@ -2001,7 +1822,9 @@ fole_s_reference_count(VALUE self, VALUE obj)
* The return value is reference counter of OLE object.
*/
static VALUE
-fole_s_free(VALUE self, VALUE obj)
+fole_s_free(self, obj)
+ VALUE self;
+ VALUE obj;
{
ULONG n = 0;
struct oledata * pole;
@@ -2015,7 +1838,9 @@ fole_s_free(VALUE self, VALUE obj)
}
static HWND
-ole_show_help(VALUE helpfile, VALUE helpcontext)
+ole_show_help(helpfile, helpcontext)
+ VALUE helpfile;
+ VALUE helpcontext;
{
FNHTMLHELP *pfnHtmlHelp;
HWND hwnd = 0;
@@ -2047,7 +1872,10 @@ ole_show_help(VALUE helpfile, VALUE helpcontext)
* WIN32OLE.ole_show_help(typeobj)
*/
static VALUE
-fole_s_show_help(int argc, VALUE *argv, VALUE self)
+fole_s_show_help(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE target;
VALUE helpcontext;
@@ -2086,7 +1914,8 @@ fole_s_show_help(int argc, VALUE *argv, VALUE self)
* WIN32OLE.codepage # => WIN32OLE::CP_ACP
*/
static VALUE
-fole_s_get_code_page(VALUE self)
+fole_s_get_code_page(self)
+ VALUE self;
{
return INT2FIX(cWIN32OLE_cp);
}
@@ -2099,7 +1928,9 @@ fole_s_get_code_page(VALUE self)
* WIN32OLE.codepage = WIN32OLE::CP_UTF8
*/
static VALUE
-fole_s_set_code_page(VALUE self, VALUE vcp)
+fole_s_set_code_page(self, vcp)
+ VALUE self;
+ VALUE vcp;
{
UINT cp = FIX2INT(vcp);
@@ -2124,31 +1955,6 @@ fole_s_set_code_page(VALUE self, VALUE vcp)
return Qnil;
}
-/*
- * call-seq:
- * WIN32OLE.create_guid
- *
- * Creates GUID.
- * WIN32OLE.create_guid # => {1CB530F1-F6B1-404D-BCE6-1959BF91F4A8}
- */
-static VALUE
-fole_s_create_guid(VALUE self)
-{
- GUID guid;
- HRESULT hr;
- OLECHAR bstr[80];
- int len = 0;
- hr = CoCreateGuid(&guid);
- if (FAILED(hr)) {
- ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "failed to create GUID");
- }
- len = StringFromGUID2(&guid, bstr, sizeof(bstr)/sizeof(OLECHAR));
- if (len == 0) {
- rb_raise(rb_eRuntimeError, "failed to create GUID(buffer over)");
- }
- return ole_wc2vstr(bstr, FALSE);
-}
-
/*
* Document-class: WIN32OLE
*
@@ -2169,7 +1975,10 @@ fole_s_create_guid(VALUE self)
* WIN32OLE.new('{00024500-0000-0000-C000-000000000046}') # => Excel OLE Automation WIN32OLE object.
*/
static VALUE
-fole_initialize(int argc, VALUE *argv, VALUE self)
+fole_initialize(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE svr_name;
VALUE host;
@@ -2222,17 +2031,19 @@ fole_initialize(int argc, VALUE *argv, VALUE self)
}
static VALUE
-hash2named_arg(VALUE pair, struct oleparam* pOp)
+hash2named_arg(pair, pOp)
+ VALUE pair;
+ struct oleparam* pOp;
{
unsigned int index, i;
VALUE key, value;
index = pOp->dp.cNamedArgs;
- /*---------------------------------------------
- the data-type of key must be String or Symbol
- -----------------------------------------------*/
+ /*-------------------------------------
+ the data-type of key must be String
+ ---------------------------------------*/
key = rb_ary_entry(pair, 0);
- if(TYPE(key) != T_STRING && TYPE(key) != T_SYMBOL) {
+ if(TYPE(key) != T_STRING) {
/* clear name of dispatch parameters */
for(i = 1; i < index + 1; i++) {
SysFreeString(pOp->pNamedArgs[i]);
@@ -2242,10 +2053,7 @@ hash2named_arg(VALUE pair, struct oleparam* pOp)
VariantClear(&(pOp->dp.rgvarg[i]));
}
/* raise an exception */
- rb_raise(rb_eTypeError, "wrong argument type (expected String or Symbol)");
- }
- if (TYPE(key) == T_SYMBOL) {
- key = rb_str_new2(rb_id2name(SYM2ID(key)));
+ Check_Type(key, T_STRING);
}
/* pNamedArgs[0] is <method name>, so "index + 1" */
@@ -2260,7 +2068,9 @@ hash2named_arg(VALUE pair, struct oleparam* pOp)
}
static VALUE
-set_argv(VARIANTARG* realargs, unsigned int beg, unsigned int end)
+set_argv(realargs, beg, end)
+ VARIANTARG* realargs;
+ unsigned int beg, end;
{
VALUE argv = rb_const_get(cWIN32OLE, rb_intern("ARGV"));
@@ -2274,7 +2084,11 @@ set_argv(VARIANTARG* realargs, unsigned int beg, unsigned int end)
}
static VALUE
-ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
+ole_invoke(argc, argv, self, wFlags)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+ USHORT wFlags;
{
LCID lcid = LOCALE_SYSTEM_DEFAULT;
struct oledata *pole;
@@ -2297,7 +2111,6 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
unsigned int cNamedArgs;
int n;
struct oleparam op;
- struct olevariantdata *pvar;
memset(&excepinfo, 0, sizeof(EXCEPINFO));
VariantInit(&result);
@@ -2312,20 +2125,14 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
if(!pole->pDispatch) {
rb_raise(rb_eRuntimeError, "failed to get dispatch interface");
}
- if (is_bracket) {
- DispID = DISPID_VALUE;
- argc += 1;
- rb_funcall(paramS, rb_intern("unshift"), 1, cmd);
- } else {
- wcmdname = ole_mb2wc(StringValuePtr(cmd), -1);
- hr = pole->pDispatch->lpVtbl->GetIDsOfNames( pole->pDispatch, &IID_NULL,
- &wcmdname, 1, lcid, &DispID);
- SysFreeString(wcmdname);
- if(FAILED(hr)) {
- ole_raise(hr, eWIN32OLE_RUNTIME_ERROR,
- "unknown property or method: `%s'",
- StringValuePtr(cmd));
- }
+ wcmdname = ole_mb2wc(StringValuePtr(cmd), -1);
+ hr = pole->pDispatch->lpVtbl->GetIDsOfNames( pole->pDispatch, &IID_NULL,
+ &wcmdname, 1, lcid, &DispID);
+ SysFreeString(wcmdname);
+ if(FAILED(hr)) {
+ ole_raise(hr, eWIN32OLE_RUNTIME_ERROR,
+ "unknown property or method `%s'",
+ StringValuePtr(cmd));
}
/* pick up last argument of method */
@@ -2342,7 +2149,7 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
op.dp.cArgs = cNamedArgs + argc - 2;
op.pNamedArgs = ALLOCA_N(OLECHAR*, cNamedArgs + 1);
op.dp.rgvarg = ALLOCA_N(VARIANTARG, op.dp.cArgs);
- rb_block_call(param, rb_intern("each"), 0, 0, hash2named_arg, (VALUE)&op);
+ rb_iterate(rb_each, param, hash2named_arg, (VALUE)&op);
pDispID = ALLOCA_N(DISPID, cNamedArgs + 1);
op.pNamedArgs[0] = ole_mb2wc(StringValuePtr(cmd), -1);
@@ -2384,20 +2191,17 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
VariantInit(&realargs[n]);
VariantInit(&op.dp.rgvarg[n]);
param = rb_ary_entry(paramS, i-cNamedArgs);
- if (rb_obj_is_kind_of(param, cWIN32OLE_VARIANT)) {
- Data_Get_Struct(param, struct olevariantdata, pvar);
- VariantCopy(&op.dp.rgvarg[n], &(pvar->var));
- } else {
- ole_val2variant(param, &realargs[n]);
- V_VT(&op.dp.rgvarg[n]) = VT_VARIANT | VT_BYREF;
- V_VARIANTREF(&op.dp.rgvarg[n]) = &realargs[n];
- }
+
+ ole_val2variant(param, &realargs[n]);
+ V_VT(&op.dp.rgvarg[n]) = VT_VARIANT | VT_BYREF;
+ V_VARIANTREF(&op.dp.rgvarg[n]) = &realargs[n];
+
}
}
/* apparent you need to call propput, you need this */
if (wFlags & DISPATCH_PROPERTYPUT) {
if (op.dp.cArgs == 0)
- ole_raise(ResultFromScode(E_INVALIDARG), eWIN32OLE_RUNTIME_ERROR, "argument error");
+ return ResultFromScode(E_INVALIDARG);
op.dp.cNamedArgs = 1;
op.dp.rgdispidNamedArgs = ALLOCA_N( DISPID, 1 );
@@ -2407,15 +2211,17 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
hr = pole->pDispatch->lpVtbl->Invoke(pole->pDispatch, DispID,
&IID_NULL, lcid, wFlags, &op.dp,
&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,
@@ -2428,19 +2234,20 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
* 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,
&op.dp, NULL,
&excepinfo, &argErr);
-
}
for(i = cNamedArgs; i < op.dp.cArgs; i++) {
n = op.dp.cArgs - i + cNamedArgs - 1;
VariantClear(&op.dp.rgvarg[n]);
}
}
-
if (FAILED(hr)) {
/* retry after converting nil to VT_EMPTY */
if (op.dp.cArgs > cNamedArgs) {
@@ -2449,6 +2256,9 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
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,
@@ -2475,26 +2285,8 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
if (FAILED(hr)) {
v = ole_excepinfo2msg(&excepinfo);
- if (is_bracket) {
- ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "%s",
- StringValuePtr(v));
- } else {
- /*
- * This is the trick to save following script.
- *
- * installer = WIN32OLE.new("WindowsInstaller.Installer")
- * record = installer.CreateRecord(2)
- * record.StringData[1] = 'ffff'
- *
- * record.StringData failed, but we expect [] or []=
- * method called next, so we use this trick.
- *
- * If this trick may be confused.
- * If so, we should raise WIN32OLERuntimeError here...
- * And we give up saving the above script.
- */
- return create_property_object(self, cmd, hr, v);
- }
+ ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "%s%s",
+ StringValuePtr(cmd), StringValuePtr(v));
}
obj = ole_variant2val(&result);
VariantClear(&result);
@@ -2515,13 +2307,21 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
*
*/
static VALUE
-fole_invoke(int argc, VALUE *argv, VALUE self)
+fole_invoke(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
- return ole_invoke(argc, argv, self, DISPATCH_METHOD|DISPATCH_PROPERTYGET, FALSE);
+ return ole_invoke(argc, argv, self, DISPATCH_METHOD|DISPATCH_PROPERTYGET);
}
static VALUE
-ole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types, USHORT dispkind)
+ole_invoke2(self, dispid, args, types, dispkind)
+ VALUE self;
+ VALUE dispid;
+ VALUE args;
+ VALUE types;
+ USHORT dispkind;
{
HRESULT hr;
struct oledata *pole;
@@ -2544,7 +2344,7 @@ ole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types, USHORT dispkind)
VariantInit(&result);
OLEData_Get_Struct(self, pole);
- dispParams.cArgs = RARRAY_LEN(args);
+ dispParams.cArgs = RARRAY(args)->len;
dispParams.rgvarg = ALLOCA_N(VARIANTARG, dispParams.cArgs);
realargs = ALLOCA_N(VARIANTARG, dispParams.cArgs);
for (i = 0, j = dispParams.cArgs - 1; i < (int)dispParams.cArgs; i++, j--)
@@ -2575,7 +2375,7 @@ ole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types, USHORT dispkind)
SAFEARRAYBOUND rgsabound[1];
Check_Type(param, T_ARRAY);
rgsabound[0].lLbound = 0;
- rgsabound[0].cElements = RARRAY_LEN(param);
+ rgsabound[0].cElements = RARRAY(param)->len;
v = vt & ~(VT_ARRAY | VT_BYREF);
V_ARRAY(&realargs[i]) = SafeArrayCreate(v, 1, rgsabound);
V_VT(&realargs[i]) = VT_ARRAY | v;
@@ -2722,7 +2522,11 @@ ole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types, USHORT dispkind)
* excel._invoke(302, [], []) # same effect as excel.Quit
*/
static VALUE
-fole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types)
+fole_invoke2(self, dispid, args, types)
+ VALUE self;
+ VALUE dispid;
+ VALUE args;
+ VALUE types;
{
return ole_invoke2(self, dispid, args, types, DISPATCH_METHOD);
}
@@ -2740,7 +2544,11 @@ fole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types)
* puts excel._getproperty(558, [], []) # same effect as puts excel.visible
*/
static VALUE
-fole_getproperty2(VALUE self, VALUE dispid, VALUE args, VALUE types)
+fole_getproperty2(self, dispid, args, types)
+ VALUE self;
+ VALUE dispid;
+ VALUE args;
+ VALUE types;
{
return ole_invoke2(self, dispid, args, types, DISPATCH_PROPERTYGET);
}
@@ -2758,7 +2566,11 @@ fole_getproperty2(VALUE self, VALUE dispid, VALUE args, VALUE types)
* excel._setproperty(558, [true], [WIN32OLE::VARIANT::VT_BOOL]) # same effect as excel.visible = true
*/
static VALUE
-fole_setproperty2(VALUE self, VALUE dispid, VALUE args, VALUE types)
+fole_setproperty2(self, dispid, args, types)
+ VALUE self;
+ VALUE dispid;
+ VALUE args;
+ VALUE types;
{
return ole_invoke2(self, dispid, args, types, DISPATCH_PROPERTYPUT);
}
@@ -2769,32 +2581,21 @@ fole_setproperty2(VALUE self, VALUE dispid, VALUE args, VALUE types)
* WIN32OLE.setproperty('property', [arg1, arg2,...] val)
*
* Sets property of OLE object.
- *
- */
-static VALUE
-fole_setproperty_with_bracket(int argc, VALUE *argv, VALUE self)
-{
- return ole_invoke(argc, argv, self, DISPATCH_PROPERTYPUT, TRUE);
-}
-
-/*
- * call-seq:
- * WIN32OLE['property']=val
- * WIN32OLE.setproperty('property', [arg1, arg2,...] val)
- *
- * Sets property of OLE object.
* When you want to set property with argument, you can use this method.
*
* excel = WIN32OLE.new('Excel.Application')
- * excel.Visible = true
+ * excel['Visible'] = true
* book = excel.workbooks.add
* sheet = book.worksheets(1)
* sheet.setproperty('Cells', 1, 2, 10) # => The B1 cell value is 10.
*/
static VALUE
-fole_setproperty(int argc, VALUE *argv, VALUE self)
+fole_setproperty(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
- return ole_invoke(argc, argv, self, DISPATCH_PROPERTYPUT, FALSE);
+ return ole_invoke(argc, argv, self, DISPATCH_PROPERTYPUT);
}
/*
@@ -2807,13 +2608,17 @@ fole_setproperty(int argc, VALUE *argv, VALUE self)
* puts excel['Visible'] # => false
*/
static VALUE
-fole_getproperty_with_bracket(int argc, VALUE *argv, VALUE self)
+fole_getproperty(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
- return ole_invoke(argc, argv, self, DISPATCH_PROPERTYGET, TRUE);
+ return ole_invoke(argc, argv, self, DISPATCH_PROPERTYGET);
}
static VALUE
-ole_propertyput(VALUE self, VALUE property, VALUE value)
+ole_propertyput(self, property, value)
+ VALUE self, property, value;
{
struct oledata *pole;
unsigned argErr;
@@ -2877,7 +2682,8 @@ ole_propertyput(VALUE self, VALUE property, VALUE value)
*
*/
static VALUE
-fole_free(VALUE self)
+fole_free(self)
+ VALUE self;
{
struct oledata *pole;
rb_secure(4);
@@ -2888,7 +2694,8 @@ fole_free(VALUE self)
}
static VALUE
-ole_each_sub(VALUE pEnumV)
+ole_each_sub(pEnumV)
+ VALUE pEnumV;
{
VARIANT variant;
VALUE obj = Qnil;
@@ -2904,7 +2711,8 @@ ole_each_sub(VALUE pEnumV)
}
static VALUE
-ole_ienum_free(VALUE pEnumV)
+ole_ienum_free(pEnumV)
+ VALUE pEnumV;
{
IEnumVARIANT *pEnum = (IEnumVARIANT *)pEnumV;
OLE_RELEASE(pEnum);
@@ -2926,7 +2734,8 @@ ole_ienum_free(VALUE pEnumV)
* end
*/
static VALUE
-fole_each(VALUE self)
+fole_each(self)
+ VALUE self;
{
LCID lcid = LOCALE_SYSTEM_DEFAULT;
@@ -2983,10 +2792,13 @@ fole_each(VALUE self)
* Calls WIN32OLE#invoke method.
*/
static VALUE
-fole_missing(int argc, VALUE *argv, VALUE self)
+fole_missing(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
ID id;
- const char* mname;
+ char* mname;
int n;
id = rb_to_id(argv[0]);
mname = rb_id2name(id);
@@ -3001,12 +2813,16 @@ fole_missing(int argc, VALUE *argv, VALUE self)
}
else {
argv[0] = rb_str_new2(mname);
- return ole_invoke(argc, argv, self, DISPATCH_METHOD|DISPATCH_PROPERTYGET, FALSE);
+ return ole_invoke(argc, argv, self, DISPATCH_METHOD|DISPATCH_PROPERTYGET);
}
}
static VALUE
-ole_method_sub(VALUE self, ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE name)
+ole_method_sub(self, pOwnerTypeInfo, pTypeInfo, name)
+ VALUE self;
+ ITypeInfo *pOwnerTypeInfo;
+ ITypeInfo *pTypeInfo;
+ VALUE name;
{
HRESULT hr;
TYPEATTR *pTypeAttr;
@@ -3043,7 +2859,10 @@ ole_method_sub(VALUE self, ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALU
}
static VALUE
-olemethod_from_typeinfo(VALUE self, ITypeInfo *pTypeInfo, VALUE name)
+olemethod_from_typeinfo(self, pTypeInfo, name)
+ VALUE self;
+ ITypeInfo *pTypeInfo;
+ VALUE name;
{
HRESULT hr;
TYPEATTR *pTypeAttr;
@@ -3074,7 +2893,11 @@ olemethod_from_typeinfo(VALUE self, ITypeInfo *pTypeInfo, VALUE name)
}
static VALUE
-ole_methods_sub(ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE methods, int mask)
+ole_methods_sub(pOwnerTypeInfo, pTypeInfo, methods, mask)
+ ITypeInfo *pOwnerTypeInfo;
+ ITypeInfo *pTypeInfo;
+ VALUE methods;
+ int mask;
{
HRESULT hr;
TYPEATTR *pTypeAttr;
@@ -3114,7 +2937,9 @@ ole_methods_sub(ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE methods,
}
static VALUE
-ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask)
+ole_methods_from_typeinfo(pTypeInfo, mask)
+ ITypeInfo *pTypeInfo;
+ int mask;
{
HRESULT hr;
TYPEATTR *pTypeAttr;
@@ -3143,7 +2968,9 @@ ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask)
}
static HRESULT
-typeinfo_from_ole(struct oledata *pole, ITypeInfo **ppti)
+typeinfo_from_ole(pole, ppti)
+ struct oledata *pole;
+ ITypeInfo **ppti;
{
ITypeInfo *pTypeInfo;
ITypeLib *pTypeLib;
@@ -3184,7 +3011,9 @@ typeinfo_from_ole(struct oledata *pole, ITypeInfo **ppti)
}
static VALUE
-ole_methods(VALUE self, int mask)
+ole_methods(self,mask)
+ VALUE self;
+ int mask;
{
ITypeInfo *pTypeInfo;
HRESULT hr;
@@ -3214,7 +3043,8 @@ ole_methods(VALUE self, int mask)
*
*/
static VALUE
-fole_methods(VALUE self)
+fole_methods( self )
+ VALUE self;
{
return ole_methods( self, INVOKE_FUNC | INVOKE_PROPERTYGET | INVOKE_PROPERTYPUT | INVOKE_PROPERTYPUTREF);
}
@@ -3230,7 +3060,8 @@ fole_methods(VALUE self)
* properties = excel.ole_get_methods
*/
static VALUE
-fole_get_methods(VALUE self)
+fole_get_methods( self )
+ VALUE self;
{
return ole_methods( self, INVOKE_PROPERTYGET);
}
@@ -3246,9 +3077,10 @@ fole_get_methods(VALUE self)
* properties = excel.ole_put_methods
*/
static VALUE
-fole_put_methods(VALUE self)
+fole_put_methods( self )
+ VALUE self;
{
- return ole_methods( self, INVOKE_PROPERTYPUT|INVOKE_PROPERTYPUTREF);
+ return ole_methods( self, INVOKE_PROPERTYPUT | INVOKE_PROPERTYPUTREF);
}
/*
@@ -3256,57 +3088,38 @@ fole_put_methods(VALUE self)
* WIN32OLE#ole_func_methods
*
* Returns the array of WIN32OLE_METHOD object .
- * The element of the array is property (settable) of WIN32OLE object.
+ * The element of the array is functional method of WIN32OLE object.
*
* excel = WIN32OLE.new('Excel.Application')
* properties = excel.ole_func_methods
*
*/
static VALUE
-fole_func_methods(VALUE self)
+fole_func_methods( self )
+ VALUE self;
{
return ole_methods( self, INVOKE_FUNC);
}
-static VALUE
-ole_type_from_itypeinfo(ITypeInfo *pTypeInfo)
-{
- ITypeLib *pTypeLib;
- VALUE type = Qnil;
- HRESULT hr;
- unsigned int index;
- BSTR bstr;
-
- hr = pTypeInfo->lpVtbl->GetContainingTypeLib( pTypeInfo, &pTypeLib, &index );
- if(FAILED(hr)) {
- return Qnil;
- }
- hr = pTypeLib->lpVtbl->GetDocumentation( pTypeLib, index,
- &bstr, NULL, NULL, NULL);
- OLE_RELEASE(pTypeLib);
- if (FAILED(hr)) {
- return Qnil;
- }
- type = foletype_s_allocate(cWIN32OLE_TYPE);
- oletype_set_member(type, pTypeInfo, WC2VSTR(bstr));
- return type;
-}
-
/*
* call-seq:
- * WIN32OLE#ole_type
+ * WIN32OLE#ole_obj_help
*
* Returns WIN32OLE_TYPE object.
*
* excel = WIN32OLE.new('Excel.Application')
- * tobj = excel.ole_type
+ * tobj = excel.ole_obj_help
*/
static VALUE
-fole_type(VALUE self)
+fole_obj_help( self )
+ VALUE self;
{
+ unsigned int index;
ITypeInfo *pTypeInfo;
+ ITypeLib *pTypeLib;
HRESULT hr;
struct oledata *pole;
+ BSTR bstr;
LCID lcid = LOCALE_SYSTEM_DEFAULT;
VALUE type = Qnil;
@@ -3316,105 +3129,30 @@ fole_type(VALUE self)
if(FAILED(hr)) {
ole_raise(hr, rb_eRuntimeError, "failed to GetTypeInfo");
}
- type = ole_type_from_itypeinfo(pTypeInfo);
- OLE_RELEASE(pTypeInfo);
- if (type == Qnil) {
- rb_raise(rb_eRuntimeError, "failed to create WIN32OLE_TYPE obj from ITypeInfo");
- }
- return type;
-}
-
-static VALUE
-make_oletypelib_obj(VALUE guid, VALUE major_version, VALUE minor_version)
-{
- VALUE args = rb_ary_new();
- rb_ary_push(args, guid);
- rb_ary_push(args, major_version);
- rb_ary_push(args, minor_version);
- return rb_apply(cWIN32OLE_TYPELIB, rb_intern("new"), args);
-}
-
-static VALUE
-ole_typelib_from_itypelib(ITypeLib *pTypeLib)
-{
- TLIBATTR *pTLibAttr;
- OLECHAR bstr[80];
- VALUE guid = Qnil;
- VALUE major;
- VALUE minor;
- int len = 0;
- HRESULT hr = S_OK;
- hr = pTypeLib->lpVtbl->GetLibAttr(pTypeLib, &pTLibAttr);
- if (FAILED(hr)) {
- return Qnil;
- }
- len = StringFromGUID2(&pTLibAttr->guid, bstr, sizeof(bstr)/sizeof(OLECHAR));
- if (len > 3) {
- guid = ole_wc2vstr(bstr, FALSE);
- }
- major = INT2NUM(pTLibAttr->wMajorVerNum);
- minor = INT2NUM(pTLibAttr->wMinorVerNum);
- pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
- if (guid == Qnil) {
- return Qnil;
- }
- return make_oletypelib_obj(guid, major, minor);
-}
-
-
-static VALUE
-ole_typelib_from_itypeinfo(ITypeInfo *pTypeInfo)
-{
- HRESULT hr;
- ITypeLib *pTypeLib;
- unsigned int index;
- VALUE retval = Qnil;
-
- hr = pTypeInfo->lpVtbl->GetContainingTypeLib(pTypeInfo, &pTypeLib, &index);
+ hr = pTypeInfo->lpVtbl->GetContainingTypeLib( pTypeInfo, &pTypeLib, &index );
if(FAILED(hr)) {
- return Qnil;
+ OLE_RELEASE(pTypeInfo);
+ ole_raise(hr, rb_eRuntimeError, "failed to GetContainingTypeLib");
}
- retval = ole_typelib_from_itypelib(pTypeLib);
- OLE_RELEASE(pTypeLib);
- return retval;
-}
-
-/*
- * call-seq:
- * WIN32OLE#ole_typelib -> The WIN32OLE_TYPELIB object
- *
- * Returns the WIN32OLE_TYPELIB object. The object represents the
- * type library which contains the WIN32OLE object.
- *
- * excel = WIN32OLE.new('Excel.Application')
- * tlib = excel.ole_typelib
- * puts tlib.name # -> 'Microsoft Excel 9.0 Object Library'
- */
-static VALUE
-fole_typelib(VALUE self)
-{
- struct oledata *pole;
- HRESULT hr;
- ITypeInfo *pTypeInfo;
- LCID lcid = LOCALE_SYSTEM_DEFAULT;
- VALUE vtlib = Qnil;
-
- OLEData_Get_Struct(self, pole);
- hr = pole->pDispatch->lpVtbl->GetTypeInfo(pole->pDispatch,
- 0, lcid, &pTypeInfo);
- if(FAILED(hr)) {
- ole_raise(hr, rb_eRuntimeError, "failed to GetTypeInfo");
+ hr = pTypeLib->lpVtbl->GetDocumentation( pTypeLib, index,
+ &bstr, NULL, NULL, NULL);
+ if (SUCCEEDED(hr)) {
+ type = foletype_s_allocate(cWIN32OLE_TYPE);
+ oletype_set_member(type, pTypeInfo, WC2VSTR(bstr));
}
- vtlib = ole_typelib_from_itypeinfo(pTypeInfo);
+ OLE_RELEASE(pTypeLib);
OLE_RELEASE(pTypeInfo);
- if (vtlib == Qnil) {
- rb_raise(rb_eRuntimeError, "failed to get type library info.");
- }
- return vtlib;
+
+ return type;
}
static HRESULT
-ole_docinfo_from_type(ITypeInfo *pTypeInfo, BSTR *name, BSTR *helpstr, DWORD *helpcontext, BSTR *helpfile)
+ole_docinfo_from_type(pTypeInfo, name, helpstr, helpcontext, helpfile)
+ ITypeInfo *pTypeInfo;
+ BSTR *name;
+ BSTR *helpstr;
+ DWORD *helpcontext;
+ BSTR *helpfile;
{
HRESULT hr;
ITypeLib *pTypeLib;
@@ -3437,7 +3175,10 @@ ole_docinfo_from_type(ITypeInfo *pTypeInfo, BSTR *name, BSTR *helpstr, DWORD *he
}
static VALUE
-ole_usertype2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails)
+ole_usertype2val(pTypeInfo, pTypeDesc, typedetails)
+ ITypeInfo *pTypeInfo;
+ TYPEDESC *pTypeDesc;
+ VALUE typedetails;
{
HRESULT hr;
BSTR bstr;
@@ -3463,7 +3204,10 @@ ole_usertype2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails)
static VALUE ole_typedesc2val();
static VALUE
-ole_ptrtype2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails)
+ole_ptrtype2val(pTypeInfo, pTypeDesc, typedetails)
+ ITypeInfo *pTypeInfo;
+ TYPEDESC *pTypeDesc;
+ VALUE typedetails;
{
TYPEDESC *p = pTypeDesc;
VALUE type = rb_str_new2("");
@@ -3480,7 +3224,10 @@ ole_ptrtype2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails)
}
static VALUE
-ole_typedesc2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails)
+ole_typedesc2val(pTypeInfo, pTypeDesc, typedetails)
+ ITypeInfo *pTypeInfo;
+ TYPEDESC *pTypeDesc;
+ VALUE typedetails;
{
VALUE str;
switch(pTypeDesc->vt) {
@@ -3590,19 +3337,6 @@ ole_typedesc2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails)
if(typedetails != Qnil)
rb_ary_push(typedetails, rb_str_new2("DISPATCH"));
return rb_str_new2("DISPATCH");
- case VT_ERROR:
- if(typedetails != Qnil)
- rb_ary_push(typedetails, rb_str_new2("ERROR"));
- return rb_str_new2("ERROR");
-
- case VT_LPWSTR:
- if(typedetails != Qnil)
- rb_ary_push(typedetails, rb_str_new2("LPWSTR"));
- return rb_str_new2("LPWSTR");
- case VT_LPSTR:
- if(typedetails != Qnil)
- rb_ary_push(typedetails, rb_str_new2("LPSTR"));
- return rb_str_new2("LPSTR");
default:
str = rb_str_new2("Unknown Type ");
rb_str_concat(str, rb_fix2str(INT2FIX(pTypeDesc->vt), 10));
@@ -3622,12 +3356,15 @@ ole_typedesc2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails)
*
*/
static VALUE
-fole_method_help(VALUE self, VALUE cmdname)
+fole_method_help( self, cmdname )
+ VALUE self;
+ VALUE cmdname;
{
ITypeInfo *pTypeInfo;
HRESULT hr;
struct oledata *pole;
VALUE method, obj;
+ LCID lcid = LOCALE_SYSTEM_DEFAULT;
Check_SafeStr(cmdname);
OLEData_Get_Struct(self, pole);
@@ -3648,21 +3385,17 @@ fole_method_help(VALUE self, VALUE cmdname)
* WIN32OLE_TYPE.ole_classes(typelib)
*
* Returns array of WIN32OLE_TYPE objects defined by the <i>typelib</i> type library.
- * This method will be OBSOLETE. Use WIN32OLE_TYPELIB.new(typelib).ole_classes instead.
*/
static VALUE
-foletype_s_ole_classes(VALUE self, VALUE typelib)
+foletype_s_ole_classes(self, typelib)
+ VALUE self;
+ VALUE typelib;
{
VALUE file, classes;
OLECHAR * pbuf;
ITypeLib *pTypeLib;
HRESULT hr;
- /*
- rb_warn("%s is obsolete; use %s instead.",
- "WIN32OLE_TYPE.ole_classes",
- "WIN32OLE_TYPELIB.new(typelib).ole_classes");
- */
rb_secure(4);
classes = rb_ary_new();
if(TYPE(typelib) == T_STRING) {
@@ -3688,11 +3421,11 @@ foletype_s_ole_classes(VALUE self, VALUE typelib)
* WIN32OLE_TYPE.typelibs
*
* Returns array of type libraries.
- * This method will be OBSOLETE. Use WIN32OLE_TYPELIB.typelibs.collect{|t| t.name} instead.
*
*/
static VALUE
-foletype_s_typelibs(VALUE self)
+foletype_s_typelibs(self)
+ VALUE self;
{
HKEY htypelib, hclsid;
double fversion;
@@ -3703,11 +3436,6 @@ foletype_s_typelibs(VALUE self)
VALUE v = Qnil;
VALUE typelibs = rb_ary_new();
- /*
- rb_warn("%s is obsolete. use %s instead.",
- "WIN32OLE_TYPE.typelibs",
- "WIN32OLE_TYPELIB.typelibs.collect{t|t.name}");
- */
err = reg_open_key(HKEY_CLASSES_ROOT, "TypeLib", &htypelib);
if(err != ERROR_SUCCESS) {
return typelibs;
@@ -3744,7 +3472,8 @@ foletype_s_typelibs(VALUE self)
* Returns array of ProgID.
*/
static VALUE
-foletype_s_progids(VALUE self)
+foletype_s_progids(self)
+ VALUE self;
{
HKEY hclsids, hclsid;
DWORD i;
@@ -3775,7 +3504,8 @@ foletype_s_progids(VALUE self)
}
static VALUE
-foletype_s_allocate(VALUE klass)
+foletype_s_allocate(klass)
+ VALUE klass;
{
struct oletypedata *poletype;
VALUE obj;
@@ -3786,7 +3516,10 @@ foletype_s_allocate(VALUE klass)
}
static VALUE
-oletype_set_member(VALUE self, ITypeInfo *pTypeInfo, VALUE name)
+oletype_set_member(self, pTypeInfo, name)
+ VALUE self;
+ ITypeInfo *pTypeInfo;
+ VALUE name;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -3797,7 +3530,10 @@ oletype_set_member(VALUE self, ITypeInfo *pTypeInfo, VALUE name)
}
static VALUE
-oleclass_from_typelib(VALUE self, ITypeLib *pTypeLib, VALUE oleclass)
+oleclass_from_typelib(self, pTypeLib, oleclass)
+ VALUE self;
+ ITypeLib *pTypeLib;
+ VALUE oleclass;
{
long count;
@@ -3829,445 +3565,6 @@ oleclass_from_typelib(VALUE self, ITypeLib *pTypeLib, VALUE oleclass)
}
/*
- * Document-class: WIN32OLE_TYPELIB
- *
- * <code>WIN32OLE_TYPELIB</code> objects represent OLE tyblib information.
- */
-
-
-static VALUE
-oletypelib_set_member(VALUE self, VALUE typelib, VALUE guid, VALUE version)
-{
- rb_ivar_set(self, rb_intern("name"), typelib);
- rb_ivar_set(self, rb_intern("guid"), guid);
- rb_ivar_set(self, rb_intern("version"), version);
- return self;
-}
-
-/*
- * call-seq:
- *
- * WIN32OLE_TYPELIB.typelibs
- *
- * Returns the array of WIN32OLE_TYPELIB object.
- *
- * tlibs = WIN32OLE_TYPELIB.typelibs
- *
- */
-static VALUE
-foletypelib_s_typelibs(VALUE self)
-{
- HKEY htypelib, hguid;
- DWORD i, j;
- LONG err;
- VALUE guid;
- VALUE version;
- VALUE name = Qnil;
- VALUE typelibs = rb_ary_new();
- VALUE typelib = Qnil;
-
- err = reg_open_key(HKEY_CLASSES_ROOT, "TypeLib", &htypelib);
- if(err != ERROR_SUCCESS) {
- return typelibs;
- }
- for(i = 0; ; i++) {
- guid = reg_enum_key(htypelib, i);
- if (guid == Qnil)
- break;
- err = reg_open_vkey(htypelib, guid, &hguid);
- if (err != ERROR_SUCCESS)
- continue;
- for(j = 0; ; j++) {
- version = reg_enum_key(hguid, j);
- if (version == Qnil)
- break;
- if ( (name = reg_get_val(hguid, StringValuePtr(version))) != Qnil ) {
- typelib = rb_funcall(cWIN32OLE_TYPELIB, rb_intern("allocate"), 0);
- oletypelib_set_member(typelib, name, guid, version);
- rb_ary_push(typelibs, typelib);
- }
- }
- RegCloseKey(hguid);
- }
- RegCloseKey(htypelib);
- return typelibs;
-}
-
-static VALUE
-make_version_str(VALUE major, VALUE minor)
-{
- VALUE version_str = Qnil;
- VALUE minor_str = Qnil;
- if (major == Qnil) {
- return Qnil;
- }
- version_str = rb_String(major);
- if (minor != Qnil) {
- minor_str = rb_String(minor);
- rb_str_cat2(version_str, ".");
- rb_str_append(version_str, minor_str);
- }
- return version_str;
-}
-
-static VALUE
-oletypelib_search_registry2(VALUE self, VALUE args)
-{
- HKEY htypelib, hguid, hversion;
- double fver;
- DWORD j;
- LONG err;
- VALUE found = Qfalse;
- VALUE tlib;
- VALUE ver;
- VALUE version_str;
- VALUE version = Qnil;
- VALUE typelib = Qnil;
-
- VALUE guid = rb_ary_entry(args, 0);
- version_str = make_version_str(rb_ary_entry(args, 1), rb_ary_entry(args, 2));
-
- err = reg_open_key(HKEY_CLASSES_ROOT, "TypeLib", &htypelib);
- if(err != ERROR_SUCCESS) {
- return Qfalse;
- }
- err = reg_open_vkey(htypelib, guid, &hguid);
- if (err != ERROR_SUCCESS) {
- RegCloseKey(htypelib);
- return Qfalse;
- }
- if (version_str != Qnil) {
- err = reg_open_vkey(hguid, version_str, &hversion);
- if (err == ERROR_SUCCESS) {
- tlib = reg_get_val(hversion, NULL);
- if (tlib != Qnil) {
- typelib = tlib;
- version = version_str;
- }
- }
- RegCloseKey(hversion);
- } else {
- fver = 0.0;
- for(j = 0; ;j++) {
- ver = reg_enum_key(hguid, j);
- if (ver == Qnil)
- break;
- err = reg_open_vkey(hguid, ver, &hversion);
- if (err != ERROR_SUCCESS)
- continue;
- tlib = reg_get_val(hversion, NULL);
- if (tlib == Qnil) {
- RegCloseKey(hversion);
- continue;
- }
- if (fver < atof(StringValuePtr(ver))) {
- fver = atof(StringValuePtr(ver));
- version = ver;
- typelib = tlib;
- }
- RegCloseKey(hversion);
- }
- }
- RegCloseKey(hguid);
- RegCloseKey(htypelib);
- if (typelib != Qnil) {
- found = Qtrue;
- oletypelib_set_member(self, typelib, guid, version);
- }
- return found;
-}
-
-static VALUE
-oletypelib_search_registry(VALUE self, VALUE typelib)
-{
- HKEY htypelib, hguid, hversion;
- DWORD i, j;
- LONG err;
- VALUE found = Qfalse;
- VALUE tlib;
- VALUE guid;
- VALUE ver;
-
- err = reg_open_key(HKEY_CLASSES_ROOT, "TypeLib", &htypelib);
- if(err != ERROR_SUCCESS) {
- return Qfalse;
- }
- for(i = 0; !found; i++) {
- guid = reg_enum_key(htypelib, i);
- if (guid == Qnil)
- break;
- err = reg_open_vkey(htypelib, guid, &hguid);
- if (err != ERROR_SUCCESS)
- continue;
- for(j = 0; found == Qfalse; j++) {
- ver = reg_enum_key(hguid, j);
- if (ver == Qnil)
- break;
- err = reg_open_vkey(hguid, ver, &hversion);
- if (err != ERROR_SUCCESS)
- continue;
- tlib = reg_get_val(hversion, NULL);
- if (tlib == Qnil) {
- RegCloseKey(hversion);
- continue;
- }
- if (rb_str_cmp(typelib, tlib) == 0) {
- oletypelib_set_member(self, typelib, guid, ver);
- found = Qtrue;
- }
- RegCloseKey(hversion);
- }
- RegCloseKey(hguid);
- }
- RegCloseKey(htypelib);
- return found;
-}
-
-/*
- * call-seq:
- * WIN32OLE_TYPELIB.new(typelib [, version1, version2]) -> WIN32OLE_TYPELIB object
- *
- * Returns a new WIN32OLE_TYPELIB object.
- *
- * The first argument <i>typelib</i> specifies OLE type library name or GUID or
- * OLE library file.
- * The second argument is major version or version of the type library.
- * The third argument is minor version.
- * The second argument and third argument are optional.
- * If the first argument is type library name, then the second and third argument
- * are ignored.
- *
- * tlib1 = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
- * tlib2 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}')
- * tlib3 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}', 1.3)
- * tlib4 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}', 1, 3)
- * tlib5 = WIN32OLE_TYPELIB.new("C:\\WINNT\\SYSTEM32\\SHELL32.DLL")
- * puts tlib1.name # -> 'Microsoft Excel 9.0 Object Library'
- * puts tlib2.name # -> 'Microsoft Excel 9.0 Object Library'
- * puts tlib3.name # -> 'Microsoft Excel 9.0 Object Library'
- * puts tlib4.name # -> 'Microsoft Excel 9.0 Object Library'
- * puts tlib5.name # -> 'Microsoft Shell Controls And Automation'
- *
- */
-static VALUE
-foletypelib_initialize(VALUE self, VALUE args)
-{
- VALUE found = Qfalse;
- VALUE typelib = Qnil;
- int len = 0;
- OLECHAR * pbuf;
- ITypeLib *pTypeLib;
- VALUE retval;
- HRESULT hr = S_OK;
-
- len = RARRAY_LEN(args);
- if (len < 1 || len > 3) {
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", len);
- }
-
- typelib = rb_ary_entry(args, 0);
-
- Check_SafeStr(typelib);
-
- found = oletypelib_search_registry(self, typelib);
- if (found == Qfalse) {
- found = oletypelib_search_registry2(self, args);
- }
- if (found == Qfalse) {
- pbuf = ole_mb2wc(StringValuePtr(typelib), -1);
- hr = LoadTypeLibEx(pbuf, REGKIND_NONE, &pTypeLib);
- SysFreeString(pbuf);
- if (SUCCEEDED(hr)) {
- retval = ole_typelib_from_itypelib(pTypeLib);
- OLE_RELEASE(pTypeLib);
- if (retval != Qnil) {
- found = Qtrue;
- oletypelib_set_member(self,
- rb_ivar_get(retval, rb_intern("name")),
- rb_ivar_get(retval, rb_intern("guid")),
- rb_ivar_get(retval, rb_intern("version")));
- }
- }
- }
-
- if (found == Qfalse) {
- rb_raise(eWIN32OLE_RUNTIME_ERROR, "not found type library `%s`",
- StringValuePtr(typelib));
- }
- return self;
-}
-
-/*
- * call-seq:
- * WIN32OLE_TYPELIB#guid -> The guid string.
- *
- * Returns guid string which specifies type library.
- *
- * tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
- * guid = tlib.guid # -> '{00020813-0000-0000-C000-000000000046}'
- */
-static VALUE
-foletypelib_guid(VALUE self)
-{
- return rb_ivar_get(self, rb_intern("guid"));
-}
-
-/*
- * call-seq:
- * WIN32OLE_TYPELIB#name -> The type library name
- *
- * Returns the type library name.
- *
- * tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
- * name = tlib.name # -> 'Microsoft Excel 9.0 Object Library'
- */
-static VALUE
-foletypelib_name(VALUE self)
-{
- return rb_ivar_get(self, rb_intern("name"));
-}
-
-/*
- * call-seq:
- * WIN32OLE_TYPELIB#version -> The type library version.
- *
- * Returns the type library version.
- *
- * tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
- * puts tlib.version #-> 1.3
- */
-static VALUE
-foletypelib_version(VALUE self)
-{
- VALUE ver = rb_ivar_get(self, rb_intern("version"));
- return rb_Float(ver);
-}
-
-/*
- * call-seq:
- * WIN32OLE_TYPELIB#major_version -> The type library major version.
- *
- * Returns the type library major version.
- *
- * tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
- * puts tlib.major_version # -> 1
- */
-static VALUE
-foletypelib_major_version(VALUE self)
-{
- VALUE ver = rb_ivar_get(self, rb_intern("version"));
- VALUE ary = rb_str_split(ver, ".");
- return rb_Integer(rb_ary_entry(ary, 0));
-}
-
-/*
- * call-seq:
- * WIN32OLE_TYPELIB#minor_version -> The type library minor version.
- *
- * Returns the type library minor version.
- *
- * tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
- * puts tlib.minor_version # -> 3
- */
-static VALUE
-foletypelib_minor_version(VALUE self)
-{
- VALUE ver = rb_ivar_get(self, rb_intern("version"));
- VALUE ary = rb_str_split(ver, ".");
- return rb_Integer(rb_ary_entry(ary, 1));
-}
-
-static VALUE
-oletypelib_path(VALUE guid, VALUE version)
-{
- int k;
- LONG err;
- HKEY hkey;
- HKEY hlang;
- VALUE lang;
- VALUE path = Qnil;
-
- VALUE key = rb_str_new2("TypeLib\\");
- rb_str_concat(key, guid);
- rb_str_cat2(key, "\\");
- rb_str_concat(key, version);
-
- err = reg_open_vkey(HKEY_CLASSES_ROOT, key, &hkey);
- if (err != ERROR_SUCCESS) {
- return Qnil;
- }
- for(k = 0; path == Qnil; k++) {
- lang = reg_enum_key(hkey, k);
- if (lang == Qnil)
- break;
- err = reg_open_vkey(hkey, lang, &hlang);
- if (err == ERROR_SUCCESS) {
- path = reg_get_typelib_file_path(hlang);
- RegCloseKey(hlang);
- }
- }
- RegCloseKey(hkey);
- return path;
-}
-
-/*
- * call-seq:
- * WIN32OLE_TYPELIB#path -> The type library file path.
- *
- * Returns the type library file path.
- *
- * tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
- * puts tlib.path #-> 'C:\...\EXCEL9.OLB'
- */
-static VALUE
-foletypelib_path(VALUE self)
-{
- VALUE guid = rb_ivar_get(self, rb_intern("guid"));
- VALUE version = rb_ivar_get(self, rb_intern("version"));
- return oletypelib_path(guid, version);
-}
-
-
-/*
- * call-seq:
- * WIN32OLE_TYPELIB#ole_classes -> The array of WIN32OLE_TYPE object included the type library.
- *
- * Returns the type library file path.
- *
- * tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
- * classes = tlib.ole_classes.collect{|k| k.name} # -> ['AddIn', 'AddIns' ...]
- */
-static VALUE
-foletypelib_ole_classes(VALUE self)
-{
- OLECHAR * pbuf;
- HRESULT hr;
- ITypeLib *pTypeLib;
- VALUE path = Qnil;
- VALUE classes = rb_ary_new();
- path = rb_funcall(self, rb_intern("path"), 0);
- if (path != Qnil) {
- pbuf = ole_mb2wc(StringValuePtr(path), -1);
- hr = LoadTypeLibEx(pbuf, REGKIND_NONE, &pTypeLib);
- SysFreeString(pbuf);
- if (FAILED(hr))
- ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "failed to LoadTypeLibEx from `%s'",
- StringValuePtr(path));
- ole_classes_from_typelib(pTypeLib, classes);
- OLE_RELEASE(pTypeLib);
- } else {
- rb_raise(eWIN32OLE_RUNTIME_ERROR, "failed to get type library path");
- }
- return classes;
-}
-
-static VALUE
-foletypelib_inspect(VALUE self)
-{
- return default_inspect(self, "WIN32OLE_TYPELIB");
-}
-
-/*
* Document-class: WIN32OLE_TYPE
*
* <code>WIN32OLE_TYPE</code> objects represent OLE type libarary information.
@@ -4285,7 +3582,10 @@ foletypelib_inspect(VALUE self)
* # => WIN32OLE_TYPE object of Application class of Excel.
*/
static VALUE
-foletype_initialize(VALUE self, VALUE typelib, VALUE oleclass)
+foletype_initialize(self, typelib, oleclass)
+ VALUE self;
+ VALUE typelib;
+ VALUE oleclass;
{
VALUE file;
OLECHAR * pbuf;
@@ -4321,13 +3621,15 @@ foletype_initialize(VALUE self, VALUE typelib, VALUE oleclass)
* puts tobj.name # => Application
*/
static VALUE
-foletype_name(VALUE self)
+foletype_name(self)
+ VALUE self;
{
return rb_ivar_get(self, rb_intern("name"));
}
static VALUE
-ole_ole_type(ITypeInfo *pTypeInfo)
+ole_ole_type(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
HRESULT hr;
TYPEATTR *pTypeAttr;
@@ -4381,7 +3683,8 @@ ole_ole_type(ITypeInfo *pTypeInfo)
* puts tobj.ole_type # => Class
*/
static VALUE
-foletype_ole_type(VALUE self)
+foletype_ole_type(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4389,7 +3692,8 @@ foletype_ole_type(VALUE self)
}
static VALUE
-ole_type_guid(ITypeInfo *pTypeInfo)
+ole_type_guid(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
HRESULT hr;
TYPEATTR *pTypeAttr;
@@ -4416,7 +3720,8 @@ ole_type_guid(ITypeInfo *pTypeInfo)
* puts tobj.guid # => {00024500-0000-0000-C000-000000000046}
*/
static VALUE
-foletype_guid(VALUE self)
+foletype_guid(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4424,7 +3729,8 @@ foletype_guid(VALUE self)
}
static VALUE
-ole_type_progid(ITypeInfo *pTypeInfo)
+ole_type_progid(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
HRESULT hr;
TYPEATTR *pTypeAttr;
@@ -4434,8 +3740,10 @@ ole_type_progid(ITypeInfo *pTypeInfo)
if (FAILED(hr))
return progid;
hr = ProgIDFromCLSID(&pTypeAttr->guid, &pbuf);
- if (SUCCEEDED(hr))
- progid = WC2VSTR(pbuf);
+ if (SUCCEEDED(hr)) {
+ progid = ole_wc2vstr(pbuf, FALSE);
+ CoTaskMemFree(pbuf);
+ }
OLE_RELEASE_TYPEATTR(pTypeInfo, pTypeAttr);
return progid;
}
@@ -4449,7 +3757,8 @@ ole_type_progid(ITypeInfo *pTypeInfo)
* puts tobj.progid # => Excel.Application.9
*/
static VALUE
-foletype_progid(VALUE self)
+foletype_progid(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4458,7 +3767,8 @@ foletype_progid(VALUE self)
static VALUE
-ole_type_visible(ITypeInfo *pTypeInfo)
+ole_type_visible(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
HRESULT hr;
TYPEATTR *pTypeAttr;
@@ -4484,7 +3794,8 @@ ole_type_visible(ITypeInfo *pTypeInfo)
* puts tobj.visible # => true
*/
static VALUE
-foletype_visible(VALUE self)
+foletype_visible(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4492,7 +3803,8 @@ foletype_visible(VALUE self)
}
static VALUE
-ole_type_major_version(ITypeInfo *pTypeInfo)
+ole_type_major_version(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
VALUE ver;
TYPEATTR *pTypeAttr;
@@ -4514,7 +3826,8 @@ ole_type_major_version(ITypeInfo *pTypeInfo)
* puts tobj.major_version # => 8
*/
static VALUE
-foletype_major_version(VALUE self)
+foletype_major_version(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4522,7 +3835,8 @@ foletype_major_version(VALUE self)
}
static VALUE
-ole_type_minor_version(ITypeInfo *pTypeInfo)
+ole_type_minor_version(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
VALUE ver;
TYPEATTR *pTypeAttr;
@@ -4544,7 +3858,8 @@ ole_type_minor_version(ITypeInfo *pTypeInfo)
* puts tobj.minor_version # => 2
*/
static VALUE
-foletype_minor_version(VALUE self)
+foletype_minor_version(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4552,7 +3867,8 @@ foletype_minor_version(VALUE self)
}
static VALUE
-ole_type_typekind(ITypeInfo *pTypeInfo)
+ole_type_typekind(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
VALUE typekind;
TYPEATTR *pTypeAttr;
@@ -4575,7 +3891,8 @@ ole_type_typekind(ITypeInfo *pTypeInfo)
*
*/
static VALUE
-foletype_typekind(VALUE self)
+foletype_typekind(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4583,7 +3900,8 @@ foletype_typekind(VALUE self)
}
static VALUE
-ole_type_helpstring(ITypeInfo *pTypeInfo)
+ole_type_helpstring(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
HRESULT hr;
BSTR bhelpstr;
@@ -4603,7 +3921,8 @@ ole_type_helpstring(ITypeInfo *pTypeInfo)
* puts tobj.helpstring # => Web Browser interface
*/
static VALUE
-foletype_helpstring(VALUE self)
+foletype_helpstring(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4611,7 +3930,8 @@ foletype_helpstring(VALUE self)
}
static VALUE
-ole_type_src_type(ITypeInfo *pTypeInfo)
+ole_type_src_type(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
HRESULT hr;
TYPEATTR *pTypeAttr;
@@ -4638,7 +3958,8 @@ ole_type_src_type(ITypeInfo *pTypeInfo)
*
*/
static VALUE
-foletype_src_type(VALUE self)
+foletype_src_type(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4646,7 +3967,8 @@ foletype_src_type(VALUE self)
}
static VALUE
-ole_type_helpfile(ITypeInfo *pTypeInfo)
+ole_type_helpfile(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
HRESULT hr;
BSTR bhelpfile;
@@ -4667,7 +3989,8 @@ ole_type_helpfile(ITypeInfo *pTypeInfo)
*
*/
static VALUE
-foletype_helpfile(VALUE self)
+foletype_helpfile(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4675,7 +3998,8 @@ foletype_helpfile(VALUE self)
}
static VALUE
-ole_type_helpcontext(ITypeInfo *pTypeInfo)
+ole_type_helpcontext(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
HRESULT hr;
DWORD helpcontext;
@@ -4695,93 +4019,17 @@ ole_type_helpcontext(ITypeInfo *pTypeInfo)
* puts tobj.helpfile # => 131185
*/
static VALUE
-foletype_helpcontext(VALUE self)
+foletype_helpcontext(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
return ole_type_helpcontext(ptype->pTypeInfo);
}
-/*
- * call-seq:
- * WIN32OLE_TYPE#ole_typelib
- *
- * Returns the WIN32OLE_TYPELIB object which is including the WIN32OLE_TYPE
- * object. If it is not found, then returns nil.
- * tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Worksheet')
- * puts tobj.ole_typelib # => 'Microsoft Excel 9.0 Object Library'
- */
-static VALUE
-foletype_ole_typelib(VALUE self)
-{
- struct oletypedata *ptype;
- Data_Get_Struct(self, struct oletypedata, ptype);
- return ole_typelib_from_itypeinfo(ptype->pTypeInfo);
-}
-
static VALUE
-ole_type_impl_ole_types(ITypeInfo *pTypeInfo)
-{
- HRESULT hr;
- ITypeInfo *pRefTypeInfo;
- HREFTYPE href;
- WORD i;
- VALUE type;
- TYPEATTR *pTypeAttr;
- int flags;
-
- VALUE types = rb_ary_new();
- hr = OLE_GET_TYPEATTR(pTypeInfo, &pTypeAttr);
- if (FAILED(hr)) {
- return types;
- }
- for (i = 0; i < pTypeAttr->cImplTypes; i++) {
- hr = pTypeInfo->lpVtbl->GetImplTypeFlags(pTypeInfo, i, &flags);
- if (FAILED(hr))
- continue;
-
- hr = pTypeInfo->lpVtbl->GetRefTypeOfImplType(pTypeInfo, i, &href);
- if (FAILED(hr))
- continue;
- hr = pTypeInfo->lpVtbl->GetRefTypeInfo(pTypeInfo, href, &pRefTypeInfo);
- if (FAILED(hr))
- continue;
- type = ole_type_from_itypeinfo(pRefTypeInfo);
- if (type != Qnil) {
- rb_ary_push(types, type);
- }
-
- OLE_RELEASE(pRefTypeInfo);
- }
- OLE_RELEASE_TYPEATTR(pTypeInfo, pTypeAttr);
- return types;
-}
-
-/*
- * call-seq:
- * WIN32OLE_TYPE#implemented_ole_types
- *
- * Returns the array of WIN32OLE_TYPE object which is implemented by the WIN32OLE_TYPE
- * object.
- * tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Worksheet')
- * p tobj.implemented_ole_types # => [_Worksheet, DocEvents]
- */
-static VALUE
-foletype_impl_ole_types(VALUE self)
-{
- struct oletypedata *ptype;
- Data_Get_Struct(self, struct oletypedata, ptype);
- return ole_type_impl_ole_types(ptype->pTypeInfo);
-}
-
-static VALUE
-foletype_inspect(VALUE self)
-{
- return default_inspect(self, "WIN32OLE_TYPE");
-}
-
-static VALUE
-ole_variables(ITypeInfo *pTypeInfo)
+ole_variables(pTypeInfo)
+ ITypeInfo *pTypeInfo;
{
HRESULT hr;
TYPEATTR *pTypeAttr;
@@ -4845,7 +4093,8 @@ ole_variables(ITypeInfo *pTypeInfo)
*
*/
static VALUE
-foletype_variables(VALUE self)
+foletype_variables(self)
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4865,7 +4114,10 @@ foletype_variables(VALUE self)
* # => ['Activate', 'Copy', 'Delete',....]
*/
static VALUE
-foletype_methods(VALUE self)
+foletype_methods(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
@@ -4899,13 +4151,16 @@ foletype_methods(VALUE self)
*
*/
static VALUE
-folevariable_name(VALUE self)
+folevariable_name(self)
+ VALUE self;
{
return rb_ivar_get(self, rb_intern("name"));
}
static VALUE
-ole_variable_ole_type(ITypeInfo *pTypeInfo, UINT var_index)
+ole_variable_ole_type(pTypeInfo, var_index)
+ ITypeInfo *pTypeInfo;
+ UINT var_index;
{
VARDESC *pVarDesc;
HRESULT hr;
@@ -4939,7 +4194,8 @@ ole_variable_ole_type(ITypeInfo *pTypeInfo, UINT var_index)
*
*/
static VALUE
-folevariable_ole_type(VALUE self)
+folevariable_ole_type(self)
+ VALUE self;
{
struct olevariabledata *pvar;
Data_Get_Struct(self, struct olevariabledata, pvar);
@@ -4947,7 +4203,9 @@ folevariable_ole_type(VALUE self)
}
static VALUE
-ole_variable_ole_type_detail(ITypeInfo *pTypeInfo, UINT var_index)
+ole_variable_ole_type_detail(pTypeInfo, var_index)
+ ITypeInfo *pTypeInfo;
+ UINT var_index;
{
VARDESC *pVarDesc;
HRESULT hr;
@@ -4973,7 +4231,8 @@ ole_variable_ole_type_detail(ITypeInfo *pTypeInfo, UINT var_index)
*
*/
static VALUE
-folevariable_ole_type_detail(VALUE self)
+folevariable_ole_type_detail(self)
+ VALUE self;
{
struct olevariabledata *pvar;
Data_Get_Struct(self, struct olevariabledata, pvar);
@@ -4981,7 +4240,9 @@ folevariable_ole_type_detail(VALUE self)
}
static VALUE
-ole_variable_value(ITypeInfo *pTypeInfo, UINT var_index)
+ole_variable_value(pTypeInfo, var_index)
+ ITypeInfo *pTypeInfo;
+ UINT var_index;
{
VARDESC *pVarDesc;
HRESULT hr;
@@ -5005,7 +4266,7 @@ ole_variable_value(ITypeInfo *pTypeInfo, UINT var_index)
* tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'XlSheetType')
* variables = tobj.variables
* variables.each do |variable|
- * puts "#{variable.name} #{variable.value}"
+ * puts "#{variable.name} = #{variable.value}"
* end
*
* The result of above script is following:
@@ -5017,7 +4278,8 @@ ole_variable_value(ITypeInfo *pTypeInfo, UINT var_index)
*
*/
static VALUE
-folevariable_value(VALUE self)
+folevariable_value(self)
+ VALUE self;
{
struct olevariabledata *pvar;
Data_Get_Struct(self, struct olevariabledata, pvar);
@@ -5025,7 +4287,9 @@ folevariable_value(VALUE self)
}
static VALUE
-ole_variable_visible(ITypeInfo *pTypeInfo, UINT var_index)
+ole_variable_visible(pTypeInfo, var_index)
+ ITypeInfo *pTypeInfo;
+ UINT var_index;
{
VARDESC *pVarDesc;
HRESULT hr;
@@ -5063,7 +4327,8 @@ ole_variable_visible(ITypeInfo *pTypeInfo, UINT var_index)
*
*/
static VALUE
-folevariable_visible(VALUE self)
+folevariable_visible(self)
+ VALUE self;
{
struct olevariabledata *pvar;
Data_Get_Struct(self, struct olevariabledata, pvar);
@@ -5071,7 +4336,9 @@ folevariable_visible(VALUE self)
}
static VALUE
-ole_variable_kind(ITypeInfo *pTypeInfo, UINT var_index)
+ole_variable_kind(pTypeInfo, var_index)
+ ITypeInfo *pTypeInfo;
+ UINT var_index;
{
VARDESC *pVarDesc;
HRESULT hr;
@@ -5119,7 +4386,8 @@ ole_variable_kind(ITypeInfo *pTypeInfo, UINT var_index)
* xlWorksheet CONSTANT
*/
static VALUE
-folevariable_variable_kind(VALUE self)
+folevariable_variable_kind(self)
+ VALUE self;
{
struct olevariabledata *pvar;
Data_Get_Struct(self, struct olevariabledata, pvar);
@@ -5127,7 +4395,9 @@ folevariable_variable_kind(VALUE self)
}
static VALUE
-ole_variable_varkind(ITypeInfo *pTypeInfo, UINT var_index)
+ole_variable_varkind(pTypeInfo, var_index)
+ ITypeInfo *pTypeInfo;
+ UINT var_index;
{
VARDESC *pVarDesc;
HRESULT hr;
@@ -5159,22 +4429,14 @@ ole_variable_varkind(ITypeInfo *pTypeInfo, UINT var_index)
* xlWorksheet 2
*/
static VALUE
-folevariable_varkind(VALUE self)
+folevariable_varkind(self)
+ VALUE self;
{
struct olevariabledata *pvar;
Data_Get_Struct(self, struct olevariabledata, pvar);
return ole_variable_varkind(pvar->pTypeInfo, pvar->index);
}
-static VALUE
-folevariable_inspect(VALUE self)
-{
- VALUE detail = rb_funcall(self, rb_intern("to_s"), 0);
- rb_str_cat2(detail, "=");
- rb_str_concat(detail, rb_funcall(rb_funcall(self, rb_intern("value"), 0), rb_intern("inspect"), 0));
- return make_inspect("WIN32OLE_VARIABLE", detail);
-}
-
/*
* Document-class: WIN32OLE_METHOD
*
@@ -5182,7 +4444,12 @@ folevariable_inspect(VALUE self)
*/
static VALUE
-olemethod_set_member(VALUE self, ITypeInfo *pTypeInfo, ITypeInfo *pOwnerTypeInfo, int index, VALUE name)
+olemethod_set_member(self, pTypeInfo, pOwnerTypeInfo, index, name)
+ VALUE self;
+ ITypeInfo *pTypeInfo;
+ ITypeInfo *pOwnerTypeInfo;
+ int index;
+ VALUE name;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5196,7 +4463,8 @@ olemethod_set_member(VALUE self, ITypeInfo *pTypeInfo, ITypeInfo *pOwnerTypeInfo
}
static VALUE
-folemethod_s_allocate(VALUE klass)
+folemethod_s_allocate(klass)
+ VALUE klass;
{
struct olemethoddata *pmethod;
VALUE obj;
@@ -5223,7 +4491,10 @@ folemethod_s_allocate(VALUE klass)
* method = WIN32OLE_METHOD.new(tobj, 'SaveAs')
*/
static VALUE
-folemethod_initialize(VALUE self, VALUE oletype, VALUE method)
+folemethod_initialize(self, oletype, method)
+ VALUE self;
+ VALUE oletype;
+ VALUE method;
{
struct oletypedata *ptype;
VALUE obj = Qnil;
@@ -5254,13 +4525,16 @@ folemethod_initialize(VALUE self, VALUE oletype, VALUE method)
*
*/
static VALUE
-folemethod_name(VALUE self)
+folemethod_name(self)
+ VALUE self;
{
return rb_ivar_get(self, rb_intern("name"));
}
static VALUE
-ole_method_return_type(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_return_type(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5286,7 +4560,8 @@ ole_method_return_type(ITypeInfo *pTypeInfo, UINT method_index)
*
*/
static VALUE
-folemethod_return_type(VALUE self)
+folemethod_return_type(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5294,7 +4569,9 @@ folemethod_return_type(VALUE self)
}
static VALUE
-ole_method_return_vtype(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_return_vtype(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5320,7 +4597,8 @@ ole_method_return_vtype(ITypeInfo *pTypeInfo, UINT method_index)
*
*/
static VALUE
-folemethod_return_vtype(VALUE self)
+folemethod_return_vtype(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5328,7 +4606,9 @@ folemethod_return_vtype(VALUE self)
}
static VALUE
-ole_method_return_type_detail(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_return_type_detail(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5354,7 +4634,8 @@ ole_method_return_type_detail(ITypeInfo *pTypeInfo, UINT method_index)
* p method.return_type_detail # => ["PTR", "USERDEFINED", "Workbook"]
*/
static VALUE
-folemethod_return_type_detail(VALUE self)
+folemethod_return_type_detail(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5362,7 +4643,9 @@ folemethod_return_type_detail(VALUE self)
}
static VALUE
-ole_method_invkind(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_invkind(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5376,7 +4659,9 @@ ole_method_invkind(ITypeInfo *pTypeInfo, UINT method_index)
}
static VALUE
-ole_method_invoke_kind(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_invoke_kind(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ WORD method_index;
{
VALUE type = rb_str_new2("UNKNOWN");
VALUE invkind = ole_method_invkind(pTypeInfo, method_index);
@@ -5406,7 +4691,8 @@ ole_method_invoke_kind(ITypeInfo *pTypeInfo, UINT method_index)
*
*/
static VALUE
-folemethod_invkind(VALUE self)
+folemethod_invkind(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5425,7 +4711,8 @@ folemethod_invkind(VALUE self)
* puts method.invoke_kind # => "FUNC"
*/
static VALUE
-folemethod_invoke_kind(VALUE self)
+folemethod_invoke_kind(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5433,7 +4720,9 @@ folemethod_invoke_kind(VALUE self)
}
static VALUE
-ole_method_visible(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_visible(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5462,7 +4751,8 @@ ole_method_visible(ITypeInfo *pTypeInfo, UINT method_index)
* puts method.visible? # => true
*/
static VALUE
-folemethod_visible(VALUE self)
+folemethod_visible(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5470,7 +4760,10 @@ folemethod_visible(VALUE self)
}
static VALUE
-ole_method_event(ITypeInfo *pTypeInfo, UINT method_index, VALUE method_name)
+ole_method_event(pTypeInfo, method_index, method_name)
+ ITypeInfo *pTypeInfo;
+ WORD method_index;
+ VALUE method_name;
{
TYPEATTR *pTypeAttr;
HRESULT hr;
@@ -5544,7 +4837,8 @@ ole_method_event(ITypeInfo *pTypeInfo, UINT method_index, VALUE method_name)
*
*/
static VALUE
-folemethod_event(VALUE self)
+folemethod_event(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5565,7 +4859,8 @@ folemethod_event(VALUE self)
* puts method.event_interface # => WorkbookEvents
*/
static VALUE
-folemethod_event_interface(VALUE self)
+folemethod_event_interface(self)
+ VALUE self;
{
BSTR name;
struct olemethoddata *pmethod;
@@ -5580,14 +4875,14 @@ folemethod_event_interface(VALUE self)
}
static VALUE
-ole_method_docinfo_from_type(
- ITypeInfo *pTypeInfo,
- UINT method_index,
- BSTR *name,
- BSTR *helpstr,
- DWORD *helpcontext,
- BSTR *helpfile
- )
+ole_method_docinfo_from_type(pTypeInfo, method_index, name, helpstr,
+ helpcontext, helpfile)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
+ BSTR *name;
+ BSTR *helpstr;
+ DWORD *helpcontext;
+ BSTR *helpfile;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5602,7 +4897,9 @@ ole_method_docinfo_from_type(
}
static VALUE
-ole_method_helpstring(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_helpstring(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
HRESULT hr;
BSTR bhelpstring;
@@ -5625,7 +4922,8 @@ ole_method_helpstring(ITypeInfo *pTypeInfo, UINT method_index)
*
*/
static VALUE
-folemethod_helpstring(VALUE self)
+folemethod_helpstring(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5633,7 +4931,9 @@ folemethod_helpstring(VALUE self)
}
static VALUE
-ole_method_helpfile(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_helpfile(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
HRESULT hr;
BSTR bhelpfile;
@@ -5655,7 +4955,8 @@ ole_method_helpfile(ITypeInfo *pTypeInfo, UINT method_index)
* puts method.helpfile # => C:\...\VBAXL9.CHM
*/
static VALUE
-folemethod_helpfile(VALUE self)
+folemethod_helpfile(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5664,7 +4965,9 @@ folemethod_helpfile(VALUE self)
}
static VALUE
-ole_method_helpcontext(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_helpcontext(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
HRESULT hr;
DWORD helpcontext = 0;
@@ -5685,7 +4988,8 @@ ole_method_helpcontext(ITypeInfo *pTypeInfo, UINT method_index)
* puts method.helpcontext # => 65717
*/
static VALUE
-folemethod_helpcontext(VALUE self)
+folemethod_helpcontext(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5693,7 +4997,9 @@ folemethod_helpcontext(VALUE self)
}
static VALUE
-ole_method_dispid(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_dispid(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5716,7 +5022,8 @@ ole_method_dispid(ITypeInfo *pTypeInfo, UINT method_index)
* puts method.dispid # => 181
*/
static VALUE
-folemethod_dispid(VALUE self)
+folemethod_dispid(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5724,7 +5031,9 @@ folemethod_dispid(VALUE self)
}
static VALUE
-ole_method_offset_vtbl(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_offset_vtbl(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5747,7 +5056,8 @@ ole_method_offset_vtbl(ITypeInfo *pTypeInfo, UINT method_index)
* puts method.offset_vtbl # => 40
*/
static VALUE
-folemethod_offset_vtbl(VALUE self)
+folemethod_offset_vtbl(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5755,7 +5065,9 @@ folemethod_offset_vtbl(VALUE self)
}
static VALUE
-ole_method_size_params(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_size_params(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5779,7 +5091,8 @@ ole_method_size_params(ITypeInfo *pTypeInfo, UINT method_index)
*
*/
static VALUE
-folemethod_size_params(VALUE self)
+folemethod_size_params(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5787,7 +5100,9 @@ folemethod_size_params(VALUE self)
}
static VALUE
-ole_method_size_opt_params(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_size_opt_params(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5810,7 +5125,8 @@ ole_method_size_opt_params(ITypeInfo *pTypeInfo, UINT method_index)
* puts method.size_opt_params # => 4
*/
static VALUE
-folemethod_size_opt_params(VALUE self)
+folemethod_size_opt_params(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
@@ -5818,7 +5134,9 @@ folemethod_size_opt_params(VALUE self)
}
static VALUE
-ole_method_params(ITypeInfo *pTypeInfo, UINT method_index)
+ole_method_params(pTypeInfo, method_index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5857,7 +5175,6 @@ ole_method_params(ITypeInfo *pTypeInfo, UINT method_index)
return params;
}
-
/*
* call-seq:
* WIN32OLE_METHOD#params
@@ -5871,19 +5188,14 @@ ole_method_params(ITypeInfo *pTypeInfo, UINT method_index)
* TextVisualLayout]
*/
static VALUE
-folemethod_params(VALUE self)
+folemethod_params(self)
+ VALUE self;
{
struct olemethoddata *pmethod;
Data_Get_Struct(self, struct olemethoddata, pmethod);
return ole_method_params(pmethod->pTypeInfo, pmethod->index);
}
-static VALUE
-folemethod_inspect(VALUE self)
-{
- return default_inspect(self, "WIN32OLE_METHOD");
-}
-
/*
* Document-class: WIN32OLE_PARAM
*
@@ -5902,17 +5214,21 @@ folemethod_inspect(VALUE self)
* puts param1.name # => Filename
*/
static VALUE
-foleparam_name(VALUE self)
+foleparam_name(self)
+ VALUE self;
{
return rb_ivar_get(self, rb_intern("name"));
}
static VALUE
-ole_param_ole_type(ITypeInfo *pTypeInfo, UINT method_index, UINT index)
+ole_param_ole_type(pTypeInfo, method_index, index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
+ UINT index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
- VALUE type = rb_str_new2("unknown type");
+ VALUE type = rb_str_new2("UNKNOWN");
hr = pTypeInfo->lpVtbl->GetFuncDesc(pTypeInfo, method_index, &pFuncDesc);
if (FAILED(hr))
return type;
@@ -5933,7 +5249,8 @@ ole_param_ole_type(ITypeInfo *pTypeInfo, UINT method_index, UINT index)
* puts param1.ole_type # => VARIANT
*/
static VALUE
-foleparam_ole_type(VALUE self)
+foleparam_ole_type(self)
+ VALUE self;
{
struct oleparamdata *pparam;
Data_Get_Struct(self, struct oleparamdata, pparam);
@@ -5942,7 +5259,10 @@ foleparam_ole_type(VALUE self)
}
static VALUE
-ole_param_ole_type_detail(ITypeInfo *pTypeInfo, UINT method_index, UINT index)
+ole_param_ole_type_detail(pTypeInfo, method_index, index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
+ UINT index;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -5967,7 +5287,8 @@ ole_param_ole_type_detail(ITypeInfo *pTypeInfo, UINT method_index, UINT index)
* p param1.ole_type_detail # => ["PTR", "USERDEFINED", "Range"]
*/
static VALUE
-foleparam_ole_type_detail(VALUE self)
+foleparam_ole_type_detail(self)
+ VALUE self;
{
struct oleparamdata *pparam;
Data_Get_Struct(self, struct oleparamdata, pparam);
@@ -5976,7 +5297,11 @@ foleparam_ole_type_detail(VALUE self)
}
static VALUE
-ole_param_flag_mask(ITypeInfo *pTypeInfo, UINT method_index, UINT index, USHORT mask)
+ole_param_flag_mask(pTypeInfo, method_index, index, mask)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
+ UINT index;
+ USHORT mask;
{
FUNCDESC *pFuncDesc;
HRESULT hr;
@@ -6000,7 +5325,8 @@ ole_param_flag_mask(ITypeInfo *pTypeInfo, UINT method_index, UINT index, USHORT
* param1 = method.params[0]
* puts param1.input? # => true
*/
-static VALUE foleparam_input(VALUE self)
+static VALUE foleparam_input(self)
+ VALUE self;
{
struct oleparamdata *pparam;
Data_Get_Struct(self, struct oleparamdata, pparam);
@@ -6027,7 +5353,8 @@ static VALUE foleparam_input(VALUE self)
* Headers false
* Processed true
*/
-static VALUE foleparam_output(VALUE self)
+static VALUE foleparam_output(self)
+ VALUE self;
{
struct oleparamdata *pparam;
Data_Get_Struct(self, struct oleparamdata, pparam);
@@ -6045,7 +5372,8 @@ static VALUE foleparam_output(VALUE self)
* param1 = method.params[0]
* puts "#{param1.name} #{param1.optional?}" # => Filename true
*/
-static VALUE foleparam_optional(VALUE self)
+static VALUE foleparam_optional(self)
+ VALUE self;
{
struct oleparamdata *pparam;
Data_Get_Struct(self, struct oleparamdata, pparam);
@@ -6064,7 +5392,8 @@ static VALUE foleparam_optional(VALUE self)
* param = method.params[0]
* puts "#{param.name} #{param.retval?}" # => name true
*/
-static VALUE foleparam_retval(VALUE self)
+static VALUE foleparam_retval(self)
+ VALUE self;
{
struct oleparamdata *pparam;
Data_Get_Struct(self, struct oleparamdata, pparam);
@@ -6073,7 +5402,10 @@ static VALUE foleparam_retval(VALUE self)
}
static VALUE
-ole_param_default(ITypeInfo *pTypeInfo, UINT method_index, UINT index)
+ole_param_default(pTypeInfo, method_index, index)
+ ITypeInfo *pTypeInfo;
+ UINT method_index;
+ UINT index;
{
FUNCDESC *pFuncDesc;
ELEMDESC *pElemDesc;
@@ -6124,7 +5456,8 @@ ole_param_default(ITypeInfo *pTypeInfo, UINT method_index, UINT index)
* TextCodepage
* TextVisualLayout
*/
-static VALUE foleparam_default(VALUE self)
+static VALUE foleparam_default(self)
+ VALUE self;
{
struct oleparamdata *pparam;
Data_Get_Struct(self, struct oleparamdata, pparam);
@@ -6132,19 +5465,6 @@ static VALUE foleparam_default(VALUE self)
pparam->index);
}
-static VALUE
-foleparam_inspect(VALUE self)
-{
- VALUE detail = foleparam_name(self);
- VALUE defval = foleparam_default(self);
- if (defval != Qnil) {
- rb_str_cat2(detail, "=");
- rb_str_concat(detail, rb_funcall(defval, rb_intern("inspect"), 0));
- }
- return make_inspect("WIN32OLE_PARAM", detail);
-}
-
-
/*
* Document-class: WIN32OLE_EVENT
@@ -6225,7 +5545,9 @@ STDMETHODIMP EVENTSINK_GetIDsOfNames(
}
static long
-ole_search_event_at(VALUE ary, VALUE ev)
+ole_search_event_at(ary, ev)
+ VALUE ary;
+ VALUE ev;
{
VALUE event;
VALUE def_event;
@@ -6233,7 +5555,7 @@ ole_search_event_at(VALUE ary, VALUE ev)
long i, len;
long ret = -1;
def_event = Qnil;
- len = RARRAY_LEN(ary);
+ len = RARRAY(ary)->len;
for(i = 0; i < len; i++) {
event = rb_ary_entry(ary, i);
event_name = rb_ary_entry(event, 1);
@@ -6252,15 +5574,18 @@ ole_search_event_at(VALUE ary, VALUE ev)
}
static VALUE
-ole_search_event(VALUE ary, VALUE ev, BOOL *is_default)
+ole_search_event(ary, ev, is_default)
+ VALUE ary;
+ VALUE ev;
+ BOOL *is_default;
{
VALUE event;
VALUE def_event;
VALUE event_name;
- int i, len;
+ long i, len;
*is_default = FALSE;
def_event = Qnil;
- len = RARRAY_LEN(ary);
+ len = RARRAY(ary)->len;
for(i = 0; i < len; i++) {
event = rb_ary_entry(ary, i);
event_name = rb_ary_entry(event, 1);
@@ -6276,17 +5601,88 @@ ole_search_event(VALUE ary, VALUE ev, BOOL *is_default)
return def_event;
}
+static void
+val2ptr_variant(val, var)
+ VALUE val;
+ VARIANT *var;
+{
+ switch (TYPE(val)) {
+ case T_STRING:
+ if (V_VT(var) == (VT_BSTR | VT_BYREF)) {
+ *V_BSTRREF(var) = ole_mb2wc(StringValuePtr(val), -1);
+ }
+ break;
+ case T_FIXNUM:
+ switch(V_VT(var)) {
+ case (VT_UI1 | VT_BYREF) :
+ *V_UI1REF(var) = NUM2CHR(val);
+ break;
+ case (VT_I2 | VT_BYREF) :
+ *V_I2REF(var) = (short)NUM2INT(val);
+ break;
+ case (VT_I4 | VT_BYREF) :
+ *V_I4REF(var) = NUM2INT(val);
+ break;
+ case (VT_R4 | VT_BYREF) :
+ *V_R4REF(var) = (float)NUM2INT(val);
+ break;
+ case (VT_R8 | VT_BYREF) :
+ *V_R8REF(var) = NUM2INT(val);
+ break;
+ default:
+ break;
+ }
+ break;
+ case T_FLOAT:
+ switch(V_VT(var)) {
+ case (VT_I2 | VT_BYREF) :
+ *V_I2REF(var) = (short)NUM2INT(val);
+ break;
+ case (VT_I4 | VT_BYREF) :
+ *V_I4REF(var) = NUM2INT(val);
+ break;
+ case (VT_R4 | VT_BYREF) :
+ *V_R4REF(var) = (float)NUM2DBL(val);
+ break;
+ case (VT_R8 | VT_BYREF) :
+ *V_R8REF(var) = NUM2DBL(val);
+ break;
+ default:
+ break;
+ }
+ break;
+ case T_BIGNUM:
+ if (V_VT(var) == (VT_R8 | VT_BYREF)) {
+ *V_R8REF(var) = rb_big2dbl(val);
+ }
+ break;
+ case T_TRUE:
+ if (V_VT(var) == (VT_BOOL | VT_BYREF)) {
+ *V_BOOLREF(var) = VARIANT_TRUE;
+ }
+ break;
+ case T_FALSE:
+ if (V_VT(var) == (VT_BOOL | VT_BYREF)) {
+ *V_BOOLREF(var) = VARIANT_FALSE;
+ }
+ break;
+ default:
+ break;
+ }
+}
static void
-ary2ptr_dispparams(VALUE ary, DISPPARAMS *pdispparams)
+ary2ptr_dispparams(ary, pdispparams)
+ VALUE ary;
+ DISPPARAMS *pdispparams;
{
int i;
VALUE v;
VARIANT *pvar;
- for(i = 0; i < RARRAY_LEN(ary) && (unsigned int) i < pdispparams->cArgs; i++) {
+ for(i = 0; i < RARRAY(ary)->len && (unsigned int) i < pdispparams->cArgs; i++) {
v = rb_ary_entry(ary, i);
pvar = &pdispparams->rgvarg[pdispparams->cArgs-i-1];
- ole_val2ptr_variant(v, pvar);
+ val2ptr_variant(v, pvar);
}
}
@@ -6354,6 +5750,7 @@ STDMETHODIMP EVENTSINK_Invoke(
else {
result = rb_apply(handler, rb_intern("call"), args);
}
+
if (pvarResult) {
ole_val2variant(result, pvarResult);
}
@@ -6397,7 +5794,11 @@ void EVENTSINK_Destructor(
}
static HRESULT
-find_iid(VALUE ole, char *pitf, IID *piid, ITypeInfo **ppTypeInfo)
+find_iid(ole, pitf, piid, ppTypeInfo)
+ VALUE ole;
+ char *pitf;
+ IID *piid;
+ ITypeInfo **ppTypeInfo;
{
HRESULT hr;
IDispatch *pDispatch;
@@ -6508,7 +5909,10 @@ find_iid(VALUE ole, char *pitf, IID *piid, ITypeInfo **ppTypeInfo)
}
static HRESULT
-find_default_source(VALUE ole, IID *piid, ITypeInfo **ppTypeInfo)
+find_default_source(ole, piid, ppTypeInfo)
+ VALUE ole;
+ IID *piid;
+ ITypeInfo **ppTypeInfo;
{
HRESULT hr;
IProvideClassInfo2 *pProvideClassInfo2;
@@ -6600,12 +6004,18 @@ find_default_source(VALUE ole, IID *piid, ITypeInfo **ppTypeInfo)
}
static void
-ole_event_free(struct oleeventdata *poleev)
+ole_event_free(poleev)
+ struct oleeventdata *poleev;
{
ITypeInfo *pti = NULL;
IConnectionPoint *pcp = NULL;
if (poleev->freed == 1) {
+ /*
+ * this return create memory leak.
+ * but poleev->pEvent->pConnectionPoint shoul'd not be freed
+ * until poleev-> freed == 0.
+ */
return;
}
if(poleev->pEvent) {
@@ -6616,11 +6026,14 @@ ole_event_free(struct oleeventdata *poleev)
pcp->lpVtbl->Unadvise(pcp, poleev->pEvent->m_dwCookie);
OLE_RELEASE(pcp);
}
+ free(poleev);
}
}
+static VALUE fev_s_allocate _((VALUE));
static VALUE
-fev_s_allocate(VALUE klass)
+fev_s_allocate(klass)
+ VALUE klass;
{
VALUE obj;
struct oleeventdata *poleev;
@@ -6640,7 +6053,10 @@ fev_s_allocate(VALUE klass)
* ev = WIN32OLE_EVENT.new(ie, 'DWebBrowserEvents')
*/
static VALUE
-fev_initialize(int argc, VALUE *argv, VALUE self)
+fev_initialize(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE ole, itf;
struct oledata *pole;
@@ -6652,9 +6068,8 @@ fev_initialize(int argc, VALUE *argv, VALUE self)
IConnectionPointContainer *pContainer;
IConnectionPoint *pConnectionPoint;
IEVENTSINKOBJ *pIEV;
- DWORD dwCookie;
+ DWORD dwCookie = 0;
struct oleeventdata *poleev;
- VALUE events = Qnil;
rb_secure(4);
rb_scan_args(argc, argv, "11", &ole, &itf);
@@ -6683,7 +6098,7 @@ fev_initialize(int argc, VALUE *argv, VALUE self)
pDispatch = pole->pDispatch;
hr = pDispatch->lpVtbl->QueryInterface(pDispatch,
&IID_IConnectionPointContainer,
- (void **)&pContainer);
+ (void**)&pContainer);
if (FAILED(hr)) {
OLE_RELEASE(pTypeInfo);
ole_raise(hr, rb_eRuntimeError,
@@ -6717,9 +6132,6 @@ fev_initialize(int argc, VALUE *argv, VALUE self)
poleev->freed = 0;
poleev->pEvent->ptr_freed = &(poleev->freed);
rb_ary_push(ary_ole_event, self);
-
- events = rb_ary_new();
- rb_ivar_set(self, id_events, events);
return self;
}
@@ -6730,7 +6142,8 @@ fev_initialize(int argc, VALUE *argv, VALUE self)
* Translates and dispatches Windows message.
*/
static VALUE
-fev_s_msg_loop(VALUE klass)
+fev_s_msg_loop(klass)
+ VALUE klass;
{
ole_msg_loop();
return Qnil;
@@ -6738,23 +6151,30 @@ fev_s_msg_loop(VALUE klass)
static void
-add_event_call_back(VALUE obj, VALUE event, VALUE data)
+add_event_call_back(obj, event, data)
+ VALUE obj;
+ VALUE event;
+ VALUE data;
{
- long at = -1;
+ long at;
VALUE events = rb_ivar_get(obj, id_events);
if (NIL_P(events) || TYPE(events) != T_ARRAY) {
events = rb_ary_new();
rb_ivar_set(obj, id_events, events);
}
at = ole_search_event_at(events, event);
- if (at >= 0) {
+ if (at > -1) {
rb_ary_delete_at(events, at);
}
rb_ary_push(events, data);
}
static VALUE
-ev_on_event(int argc, VALUE *argv, VALUE self, VALUE is_ary_arg)
+ev_on_event(argc, argv, self, is_ary_arg)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+ VALUE is_ary_arg;
{
VALUE event, args, data;
rb_scan_args(argc, argv, "01*", &event, &args);
@@ -6777,7 +6197,10 @@ ev_on_event(int argc, VALUE *argv, VALUE self, VALUE is_ary_arg)
* ev.on_event("NavigateComplete") {|url| puts url}
*/
static VALUE
-fev_on_event(int argc, VALUE *argv, VALUE self)
+fev_on_event(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
return ev_on_event(argc, argv, self, Qfalse);
}
@@ -6791,126 +6214,14 @@ fev_on_event(int argc, VALUE *argv, VALUE self)
* you should use this method instead of WIN32OLE_EVENT#on_event.
*/
static VALUE
-fev_on_event_with_outargs(int argc, VALUE *argv, VALUE self)
+fev_on_event_with_outargs(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
return ev_on_event(argc, argv, self, Qtrue);
}
-static void
-olevariant_free(struct olevariantdata *pvar)
-{
- VariantClear(&(pvar->realvar));
- VariantClear(&(pvar->var));
-}
-
-static VALUE
-folevariant_s_allocate(VALUE klass)
-{
- struct olevariantdata *pvar;
- VALUE obj;
- ole_initialize();
- obj = Data_Make_Struct(klass,struct olevariantdata,0,olevariant_free,pvar);
- VariantInit(&(pvar->var));
- VariantInit(&(pvar->realvar));
- return obj;
-}
-
-static VALUE
-folevariant_initialize(VALUE self, VALUE args)
-{
- int len = 0;
- VARIANT var;
- VALUE val;
- VALUE vvt;
- VARTYPE vt;
- struct olevariantdata *pvar;
-
- len = RARRAY_LEN(args);
- if (len < 1 || len > 3) {
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", len);
- }
- VariantInit(&var);
- val = rb_ary_entry(args, 0);
- Data_Get_Struct(self, struct olevariantdata, pvar);
- if (len == 1) {
- ole_val2variant(val, &(pvar->var));
- } else {
- vvt = rb_ary_entry(args, 1);
- vt = NUM2INT(vvt);
- ole_val2olevariantdata(val, vt, pvar);
- }
- return self;
-}
-
-static VALUE
-folevariant_value(VALUE self)
-{
- struct olevariantdata *pvar;
- VALUE val = Qnil;
- VARTYPE vt;
- Data_Get_Struct(self, struct olevariantdata, pvar);
-
- val = ole_variant2val(&(pvar->var));
- vt = V_VT(&(pvar->var));
-
- if ((vt & ~VT_BYREF) == (VT_UI1|VT_ARRAY)) {
- SAFEARRAY *psa;
- int dim;
- if (vt & VT_BYREF) {
- psa = *V_ARRAYREF(&(pvar->var));
- } else {
- psa = V_ARRAY(&(pvar->var));
- }
- dim = SafeArrayGetDim(psa);
- if (dim == 1) {
- VALUE args = rb_ary_new3(1, rb_str_new2("C*"));
- val = rb_apply(val, rb_intern("pack"), args);
- }
- }
- return val;
-}
-
-static VALUE
-create_property_object(VALUE oleobj, VALUE propname, HRESULT prehr, VALUE premsg)
-{
- VALUE prop = rb_funcall(cWIN32OLE_PROPERTY, rb_intern("new"), 0);
- rb_ivar_set(prop, rb_intern("oleobj"), oleobj);
- rb_ivar_set(prop, rb_intern("property"), propname);
- rb_ivar_set(prop, rb_intern("prehresult"), INT2NUM(prehr));
- rb_ivar_set(prop, rb_intern("premsg"), premsg);
- return prop;
-}
-
-static VALUE
-foleproperty_getproperty(VALUE self, VALUE args)
-{
- VALUE oleobj = rb_ivar_get(self, rb_intern("oleobj"));
- VALUE params = rb_ary_new();
- rb_ary_push(params, rb_ivar_get(self, rb_intern("property")));
- rb_ary_concat(params, args);
- return rb_apply(oleobj, rb_intern("[]"), params);
-}
-
-static VALUE
-foleproperty_setproperty(VALUE self, VALUE args)
-{
- VALUE oleobj = rb_ivar_get(self, rb_intern("oleobj"));
- VALUE params = rb_ary_new();
- rb_ary_push(params, rb_ivar_get(self, rb_intern("property")));
- rb_ary_concat(params, args);
- return rb_apply(oleobj, rb_intern("setproperty"), params);
-}
-
-static VALUE
-foleproperty_method_missing(VALUE self, VALUE args)
-{
- HRESULT hr = NUM2INT(rb_ivar_get(self, rb_intern("prehresult")));
- VALUE prop = rb_ivar_get(self, rb_intern("property"));
- VALUE msg = rb_ivar_get(self, rb_intern("premsg"));
- ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "%s%s",
- StringValuePtr(prop), StringValuePtr(msg));
- return Qnil;
-}
void
Init_win32ole()
@@ -6919,6 +6230,7 @@ Init_win32ole()
ary_ole_event = rb_ary_new();
id_events = rb_intern("events");
+ rb_global_variable(&com_hash);
com_vtbl.QueryInterface = QueryInterface;
com_vtbl.AddRef = AddRef;
com_vtbl.Release = Release;
@@ -6926,7 +6238,14 @@ Init_win32ole()
com_vtbl.GetTypeInfo = GetTypeInfo;
com_vtbl.GetIDsOfNames = GetIDsOfNames;
com_vtbl.Invoke = Invoke;
- rb_global_variable(&com_hash);
+
+ 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);
@@ -6943,16 +6262,16 @@ Init_win32ole()
rb_define_singleton_method(cWIN32OLE, "ole_show_help", fole_s_show_help, -1);
rb_define_singleton_method(cWIN32OLE, "codepage", fole_s_get_code_page, 0);
rb_define_singleton_method(cWIN32OLE, "codepage=", fole_s_set_code_page, 1);
- rb_define_singleton_method(cWIN32OLE, "create_guid", fole_s_create_guid, 0);
+
rb_define_method(cWIN32OLE, "invoke", fole_invoke, -1);
- rb_define_method(cWIN32OLE, "[]", fole_getproperty_with_bracket, -1);
+ rb_define_method(cWIN32OLE, "[]", fole_getproperty, -1);
rb_define_method(cWIN32OLE, "_invoke", fole_invoke2, 3);
rb_define_method(cWIN32OLE, "_getproperty", fole_getproperty2, 3);
rb_define_method(cWIN32OLE, "_setproperty", fole_setproperty2, 3);
/* support propput method that takes an argument */
- rb_define_method(cWIN32OLE, "[]=", fole_setproperty_with_bracket, -1);
+ rb_define_method(cWIN32OLE, "[]=", fole_setproperty, -1);
rb_define_method(cWIN32OLE, "ole_free", fole_free, 0);
@@ -6969,9 +6288,7 @@ Init_win32ole()
rb_define_method(cWIN32OLE, "ole_method", fole_method_help, 1);
rb_define_alias(cWIN32OLE, "ole_method_help", "ole_method");
- rb_define_method(cWIN32OLE, "ole_type", fole_type, 0);
- rb_define_alias(cWIN32OLE, "ole_obj_help", "ole_type");
- rb_define_method(cWIN32OLE, "ole_typelib", fole_typelib, 0);
+ rb_define_method(cWIN32OLE, "ole_obj_help", fole_obj_help, 0);
rb_define_const(cWIN32OLE, "VERSION", rb_str_new2(WIN32OLE_VERSION));
rb_define_const(cWIN32OLE, "ARGV", rb_ary_new());
@@ -7006,19 +6323,6 @@ Init_win32ole()
rb_define_const(mWIN32OLE_VARIANT, "VT_UINT", INT2FIX(VT_UINT));
rb_define_const(mWIN32OLE_VARIANT, "VT_ARRAY", INT2FIX(VT_ARRAY));
rb_define_const(mWIN32OLE_VARIANT, "VT_BYREF", INT2FIX(VT_BYREF));
-
- cWIN32OLE_TYPELIB = rb_define_class("WIN32OLE_TYPELIB", rb_cObject);
- rb_define_singleton_method(cWIN32OLE_TYPELIB, "typelibs", foletypelib_s_typelibs, 0);
- rb_define_method(cWIN32OLE_TYPELIB, "initialize", foletypelib_initialize, -2);
- rb_define_method(cWIN32OLE_TYPELIB, "guid", foletypelib_guid, 0);
- rb_define_method(cWIN32OLE_TYPELIB, "name", foletypelib_name, 0);
- rb_define_method(cWIN32OLE_TYPELIB, "version", foletypelib_version, 0);
- rb_define_method(cWIN32OLE_TYPELIB, "major_version", foletypelib_major_version, 0);
- rb_define_method(cWIN32OLE_TYPELIB, "minor_version", foletypelib_minor_version, 0);
- rb_define_method(cWIN32OLE_TYPELIB, "path", foletypelib_path, 0);
- rb_define_method(cWIN32OLE_TYPELIB, "ole_classes", foletypelib_ole_classes, 0);
- rb_define_alias(cWIN32OLE_TYPELIB, "to_s", "name");
- rb_define_method(cWIN32OLE_TYPELIB, "inspect", foletypelib_inspect, 0);
cWIN32OLE_TYPE = rb_define_class("WIN32OLE_TYPE", rb_cObject);
rb_define_singleton_method(cWIN32OLE_TYPE, "ole_classes", foletype_s_ole_classes, 1);
@@ -7032,6 +6336,7 @@ Init_win32ole()
rb_define_method(cWIN32OLE_TYPE, "progid", foletype_progid, 0);
rb_define_method(cWIN32OLE_TYPE, "visible?", foletype_visible, 0);
rb_define_alias(cWIN32OLE_TYPE, "to_s", "name");
+
rb_define_method(cWIN32OLE_TYPE, "major_version", foletype_major_version, 0);
rb_define_method(cWIN32OLE_TYPE, "minor_version", foletype_minor_version, 0);
rb_define_method(cWIN32OLE_TYPE, "typekind", foletype_typekind, 0);
@@ -7040,10 +6345,7 @@ Init_win32ole()
rb_define_method(cWIN32OLE_TYPE, "helpfile", foletype_helpfile, 0);
rb_define_method(cWIN32OLE_TYPE, "helpcontext", foletype_helpcontext, 0);
rb_define_method(cWIN32OLE_TYPE, "variables", foletype_variables, 0);
- rb_define_method(cWIN32OLE_TYPE, "ole_methods", foletype_methods, 0);
- rb_define_method(cWIN32OLE_TYPE, "ole_typelib", foletype_ole_typelib, 0);
- rb_define_method(cWIN32OLE_TYPE, "implemented_ole_types", foletype_impl_ole_types, 0);
- rb_define_method(cWIN32OLE_TYPE, "inspect", foletype_inspect, 0);
+ rb_define_method(cWIN32OLE_TYPE, "ole_methods", foletype_methods, -1);
cWIN32OLE_VARIABLE = rb_define_class("WIN32OLE_VARIABLE", rb_cObject);
rb_define_method(cWIN32OLE_VARIABLE, "name", folevariable_name, 0);
@@ -7053,12 +6355,12 @@ Init_win32ole()
rb_define_method(cWIN32OLE_VARIABLE, "visible?", folevariable_visible, 0);
rb_define_method(cWIN32OLE_VARIABLE, "variable_kind", folevariable_variable_kind, 0);
rb_define_method(cWIN32OLE_VARIABLE, "varkind", folevariable_varkind, 0);
- rb_define_method(cWIN32OLE_VARIABLE, "inspect", folevariable_inspect, 0);
rb_define_alias(cWIN32OLE_VARIABLE, "to_s", "name");
cWIN32OLE_METHOD = rb_define_class("WIN32OLE_METHOD", rb_cObject);
rb_define_alloc_func(cWIN32OLE_METHOD, folemethod_s_allocate);
rb_define_method(cWIN32OLE_METHOD, "initialize", folemethod_initialize, 2);
+
rb_define_method(cWIN32OLE_METHOD, "name", folemethod_name, 0);
rb_define_method(cWIN32OLE_METHOD, "return_type", folemethod_return_type, 0);
rb_define_method(cWIN32OLE_METHOD, "return_vtype", folemethod_return_vtype, 0);
@@ -7077,7 +6379,6 @@ Init_win32ole()
rb_define_method(cWIN32OLE_METHOD, "size_opt_params", folemethod_size_opt_params, 0);
rb_define_method(cWIN32OLE_METHOD, "params", folemethod_params, 0);
rb_define_alias(cWIN32OLE_METHOD, "to_s", "name");
- rb_define_method(cWIN32OLE_METHOD, "inspect", folemethod_inspect, 0);
cWIN32OLE_PARAM = rb_define_class("WIN32OLE_PARAM", rb_cObject);
rb_define_method(cWIN32OLE_PARAM, "name", foleparam_name, 0);
@@ -7089,24 +6390,14 @@ Init_win32ole()
rb_define_method(cWIN32OLE_PARAM, "retval?", foleparam_retval, 0);
rb_define_method(cWIN32OLE_PARAM, "default", foleparam_default, 0);
rb_define_alias(cWIN32OLE_PARAM, "to_s", "name");
- rb_define_method(cWIN32OLE_PARAM, "inspect", foleparam_inspect, 0);
cWIN32OLE_EVENT = rb_define_class("WIN32OLE_EVENT", rb_cObject);
- rb_define_singleton_method(cWIN32OLE_EVENT, "message_loop", fev_s_msg_loop, 0);
+
rb_define_alloc_func(cWIN32OLE_EVENT, fev_s_allocate);
rb_define_method(cWIN32OLE_EVENT, "initialize", fev_initialize, -1);
+ rb_define_singleton_method(cWIN32OLE_EVENT, "message_loop", fev_s_msg_loop, 0);
+
rb_define_method(cWIN32OLE_EVENT, "on_event", fev_on_event, -1);
rb_define_method(cWIN32OLE_EVENT, "on_event_with_outargs", fev_on_event_with_outargs, -1);
-
- cWIN32OLE_VARIANT = rb_define_class("WIN32OLE_VARIANT", rb_cObject);
- rb_define_alloc_func(cWIN32OLE_VARIANT, folevariant_s_allocate);
- rb_define_method(cWIN32OLE_VARIANT, "initialize", folevariant_initialize, -2);
- rb_define_method(cWIN32OLE_VARIANT, "value", folevariant_value, 0);
-
eWIN32OLE_RUNTIME_ERROR = rb_define_class("WIN32OLERuntimeError", rb_eRuntimeError);
-
- cWIN32OLE_PROPERTY = rb_define_class_under(cWIN32OLE, "PROPERTY", rb_cObject);
- rb_define_method(cWIN32OLE_PROPERTY, "[]", foleproperty_getproperty, -2);
- rb_define_method(cWIN32OLE_PROPERTY, "[]=", foleproperty_setproperty, -2);
- rb_define_method(cWIN32OLE_PROPERTY, "method_missing", foleproperty_method_missing, -2);
}
diff --git a/ext/zlib/.cvsignore b/ext/zlib/.cvsignore
index 814345ece8..4088712231 100644
--- a/ext/zlib/.cvsignore
+++ b/ext/zlib/.cvsignore
@@ -1,4 +1,3 @@
Makefile
mkmf.log
*.def
-extconf.h
diff --git a/ext/zlib/extconf.rb b/ext/zlib/extconf.rb
index b4e76af3c6..53b971b189 100644
--- a/ext/zlib/extconf.rb
+++ b/ext/zlib/extconf.rb
@@ -10,7 +10,7 @@ require 'rbconfig'
dir_config 'zlib'
-if %w'z libz zlib zdll'.find {|z| have_library(z, 'deflateReset')} and
+if %w'z libz zlib1 zlib zdll'.find {|z| have_library(z, 'deflateReset')} and
have_header('zlib.h') then
defines = []
@@ -22,7 +22,7 @@ if %w'z libz zlib zdll'.find {|z| have_library(z, 'deflateReset')} and
os_code = 'AMIGA'
when /\Aos2[\-_]emx\z/ then
os_code = 'OS2'
- when 'mswin32', 'mingw32', 'bccwin32' then
+ when /mswin|mingw|bccwin/ 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 ed3f9bcbc6..306e267856 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -31,7 +31,7 @@
/*--------- Prototypes --------*/
-static NORETURN(void raise_zlib_error _((int, const char*)));
+static NORETURN(void raise_zlib_error _((int, const char *)));
static VALUE rb_zlib_version _((VALUE));
static VALUE do_checksum _((int, VALUE*, uLong (*) _((uLong, const Bytef*, uInt))));
static VALUE rb_zlib_adler32 _((int, VALUE*, VALUE));
@@ -43,14 +43,14 @@ static void finalizer_warn _((const char*));
struct zstream;
struct zstream_funcs;
-static void zstream_init _((struct zstream*, const struct zstream_funcs*));
+static void zstream_init _((struct zstream*, const struct zstream_funcs *));
static void zstream_expand_buffer _((struct zstream*));
static void zstream_expand_buffer_into _((struct zstream*, int));
-static void zstream_append_buffer _((struct zstream*, const Bytef*, int));
+static void zstream_append_buffer _((struct zstream*, const char*, int));
static VALUE zstream_detach_buffer _((struct zstream*));
static VALUE zstream_shift_buffer _((struct zstream*, int));
static void zstream_buffer_ungetc _((struct zstream*, int));
-static void zstream_append_input _((struct zstream*, const Bytef*, unsigned int));
+static void zstream_append_input _((struct zstream*, const char*, unsigned int));
static void zstream_discard_input _((struct zstream*, unsigned int));
static void zstream_reset_input _((struct zstream*));
static void zstream_passthrough_input _((struct zstream*));
@@ -111,8 +111,6 @@ static VALUE gzfile_new _((VALUE, const struct zstream_funcs*, void (*) _((struc
static void gzfile_reset _((struct gzfile*));
static void gzfile_close _((struct gzfile*, int));
static void gzfile_write_raw _((struct gzfile*));
-static VALUE gzfile_read_raw_partial _((VALUE));
-static VALUE gzfile_read_raw_rescue _((VALUE));
static VALUE gzfile_read_raw _((struct gzfile*));
static int gzfile_read_raw_ensure _((struct gzfile*, int));
static char *gzfile_read_raw_until_zero _((struct gzfile*, long));
@@ -197,7 +195,9 @@ static VALUE cZError, cStreamEnd, cNeedDict;
static VALUE cStreamError, cDataError, cMemError, cBufError, cVersionError;
static void
-raise_zlib_error(int err, const char *msg)
+raise_zlib_error(err, msg)
+ int err;
+ const char *msg;
{
VALUE exc;
@@ -245,7 +245,8 @@ raise_zlib_error(int err, const char *msg)
/*--- Warning (in finalizer) ---*/
static void
-finalizer_warn(const char *msg)
+finalizer_warn(msg)
+ const char *msg;
{
fprintf(stderr, "zlib(finalizer): %s\n", msg);
}
@@ -257,7 +258,8 @@ finalizer_warn(const char *msg)
* Returns the string which represents the version of zlib library.
*/
static VALUE
-rb_zlib_version(VALUE klass)
+rb_zlib_version(klass)
+ VALUE klass;
{
VALUE str;
@@ -270,7 +272,7 @@ static VALUE
do_checksum(argc, argv, func)
int argc;
VALUE *argv;
- uLong (*func) _((uLong, const Bytef*, uInt));
+ uLong (*func) _((uLong, const Bytef *, uInt));
{
VALUE str, vsum;
unsigned long sum;
@@ -292,7 +294,7 @@ do_checksum(argc, argv, func)
}
else {
StringValue(str);
- sum = func(sum, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
+ sum = func(sum, RSTRING(str)->ptr, RSTRING(str)->len);
}
return rb_uint2inum(sum);
}
@@ -307,7 +309,10 @@ do_checksum(argc, argv, func)
* FIXME: expression.
*/
static VALUE
-rb_zlib_adler32(int argc, VALUE *argv, VALUE klass)
+rb_zlib_adler32(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
return do_checksum(argc, argv, adler32);
}
@@ -322,7 +327,10 @@ rb_zlib_adler32(int argc, VALUE *argv, VALUE klass)
* FIXME: expression.
*/
static VALUE
-rb_zlib_crc32(int argc, VALUE *argv, VALUE klass)
+rb_zlib_crc32(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
return do_checksum(argc, argv, crc32);
}
@@ -331,7 +339,8 @@ rb_zlib_crc32(int argc, VALUE *argv, VALUE klass)
* Returns the table for calculating CRC checksum as an array.
*/
static VALUE
-rb_zlib_crc_table(VALUE obj)
+rb_zlib_crc_table(obj)
+ VALUE obj;
{
const unsigned long *crctbl;
VALUE dst;
@@ -390,19 +399,24 @@ static const struct zstream_funcs inflate_funcs = {
static voidpf
-zlib_mem_alloc(voidpf opaque, uInt items, uInt size)
+zlib_mem_alloc(opaque, items, size)
+ voidpf opaque;
+ uInt items, size;
{
return xmalloc(items * size);
}
static void
-zlib_mem_free(voidpf opaque, voidpf address)
+zlib_mem_free(opaque, address)
+ voidpf opaque, address;
{
free(address);
}
static void
-zstream_init(struct zstream *z, const struct zstream_funcs *func)
+zstream_init(z, func)
+ struct zstream *z;
+ const struct zstream_funcs *func;
{
z->flags = 0;
z->buf = Qnil;
@@ -423,7 +437,8 @@ zstream_init(struct zstream *z, const struct zstream_funcs *func)
#define zstream_init_inflate(z) zstream_init((z), &inflate_funcs)
static void
-zstream_expand_buffer(struct zstream *z)
+zstream_expand_buffer(z)
+ struct zstream *z;
{
long inc;
@@ -432,13 +447,13 @@ zstream_expand_buffer(struct zstream *z)
rb_str_buf_new makes a zero-length string. */
z->buf = rb_str_new(0, ZSTREAM_INITIAL_BUFSIZE);
z->buf_filled = 0;
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
+ z->stream.next_out = RSTRING(z->buf)->ptr;
z->stream.avail_out = ZSTREAM_INITIAL_BUFSIZE;
RBASIC(z->buf)->klass = 0;
return;
}
- if (RSTRING_LEN(z->buf) - z->buf_filled >= ZSTREAM_AVAIL_OUT_STEP_MAX) {
+ if (RSTRING(z->buf)->len - z->buf_filled >= ZSTREAM_AVAIL_OUT_STEP_MAX) {
/* to keep other threads from freezing */
z->stream.avail_out = ZSTREAM_AVAIL_OUT_STEP_MAX;
}
@@ -451,42 +466,47 @@ zstream_expand_buffer(struct zstream *z)
z->stream.avail_out = (inc < ZSTREAM_AVAIL_OUT_STEP_MAX) ?
inc : ZSTREAM_AVAIL_OUT_STEP_MAX;
}
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
+ z->stream.next_out = RSTRING(z->buf)->ptr + z->buf_filled;
}
static void
-zstream_expand_buffer_into(struct zstream *z, int size)
+zstream_expand_buffer_into(z, size)
+ struct zstream *z;
+ int size;
{
if (NIL_P(z->buf)) {
/* I uses rb_str_new here not rb_str_buf_new because
rb_str_buf_new makes a zero-length string. */
z->buf = rb_str_new(0, size);
z->buf_filled = 0;
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
+ z->stream.next_out = RSTRING(z->buf)->ptr;
z->stream.avail_out = size;
RBASIC(z->buf)->klass = 0;
}
else if (z->stream.avail_out != size) {
rb_str_resize(z->buf, z->buf_filled + size);
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
+ z->stream.next_out = RSTRING(z->buf)->ptr + z->buf_filled;
z->stream.avail_out = size;
}
}
static void
-zstream_append_buffer(struct zstream *z, const Bytef *src, int len)
+zstream_append_buffer(z, src, len)
+ struct zstream *z;
+ const char *src;
+ int len;
{
if (NIL_P(z->buf)) {
z->buf = rb_str_buf_new(len);
- rb_str_buf_cat(z->buf, (const char*)src, len);
+ rb_str_buf_cat(z->buf, src, len);
z->buf_filled = len;
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
+ z->stream.next_out = RSTRING(z->buf)->ptr;
z->stream.avail_out = 0;
RBASIC(z->buf)->klass = 0;
return;
}
- if (RSTRING_LEN(z->buf) < z->buf_filled + len) {
+ if (RSTRING(z->buf)->len < z->buf_filled + len) {
rb_str_resize(z->buf, z->buf_filled + len);
z->stream.avail_out = 0;
}
@@ -498,16 +518,17 @@ zstream_append_buffer(struct zstream *z, const Bytef *src, int len)
z->stream.avail_out = 0;
}
}
- memcpy(RSTRING_PTR(z->buf) + z->buf_filled, src, len);
+ memcpy(RSTRING(z->buf)->ptr + z->buf_filled, src, len);
z->buf_filled += len;
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
+ z->stream.next_out = RSTRING(z->buf)->ptr + z->buf_filled;
}
#define zstream_append_buffer2(z,v) \
- zstream_append_buffer((z),(Bytef*)RSTRING_PTR(v),RSTRING_LEN(v))
+ zstream_append_buffer((z),RSTRING(v)->ptr,RSTRING(v)->len)
static VALUE
-zstream_detach_buffer(struct zstream *z)
+zstream_detach_buffer(z)
+ struct zstream *z;
{
VALUE dst;
@@ -528,7 +549,9 @@ zstream_detach_buffer(struct zstream *z)
}
static VALUE
-zstream_shift_buffer(struct zstream *z, int len)
+zstream_shift_buffer(z, len)
+ struct zstream *z;
+ int len;
{
VALUE dst;
@@ -539,10 +562,10 @@ zstream_shift_buffer(struct zstream *z, int len)
dst = rb_str_substr(z->buf, 0, len);
RBASIC(dst)->klass = rb_cString;
z->buf_filled -= len;
- memmove(RSTRING_PTR(z->buf), RSTRING_PTR(z->buf) + len,
+ memmove(RSTRING(z->buf)->ptr, RSTRING(z->buf)->ptr + len,
z->buf_filled);
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
- z->stream.avail_out = RSTRING_LEN(z->buf) - z->buf_filled;
+ z->stream.next_out = RSTRING(z->buf)->ptr + z->buf_filled;
+ z->stream.avail_out = RSTRING(z->buf)->len - z->buf_filled;
if (z->stream.avail_out > ZSTREAM_AVAIL_OUT_STEP_MAX) {
z->stream.avail_out = ZSTREAM_AVAIL_OUT_STEP_MAX;
}
@@ -551,14 +574,16 @@ zstream_shift_buffer(struct zstream *z, int len)
}
static void
-zstream_buffer_ungetc(struct zstream *z, int c)
+zstream_buffer_ungetc(z, c)
+ struct zstream *z;
+ int c;
{
- if (NIL_P(z->buf) || RSTRING_LEN(z->buf) - z->buf_filled == 0) {
+ if (NIL_P(z->buf) || RSTRING(z->buf)->len - z->buf_filled == 0) {
zstream_expand_buffer(z);
}
- memmove(RSTRING_PTR(z->buf) + 1, RSTRING_PTR(z->buf), z->buf_filled);
- RSTRING_PTR(z->buf)[0] = (char)c;
+ memmove(RSTRING(z->buf)->ptr + 1, RSTRING(z->buf)->ptr, z->buf_filled);
+ RSTRING(z->buf)->ptr[0] = (char)c;
z->buf_filled++;
if (z->stream.avail_out > 0) {
z->stream.next_out++;
@@ -567,44 +592,51 @@ zstream_buffer_ungetc(struct zstream *z, int c)
}
static void
-zstream_append_input(struct zstream *z, const Bytef *src, unsigned int len)
+zstream_append_input(z, src, len)
+ struct zstream *z;
+ const char *src;
+ unsigned int len;
{
if (len <= 0) return;
if (NIL_P(z->input)) {
z->input = rb_str_buf_new(len);
- rb_str_buf_cat(z->input, (const char*)src, len);
+ rb_str_buf_cat(z->input, src, len);
RBASIC(z->input)->klass = 0;
}
else {
- rb_str_buf_cat(z->input, (const char*)src, len);
+ rb_str_buf_cat(z->input, src, len);
}
}
#define zstream_append_input2(z,v)\
- zstream_append_input((z), (Bytef*)RSTRING_PTR(v), RSTRING_LEN(v))
+ zstream_append_input((z), RSTRING(v)->ptr, RSTRING(v)->len)
static void
-zstream_discard_input(struct zstream *z, unsigned int len)
+zstream_discard_input(z, len)
+ struct zstream *z;
+ unsigned int len;
{
- if (NIL_P(z->input) || RSTRING_LEN(z->input) <= len) {
+ if (NIL_P(z->input) || RSTRING(z->input)->len <= len) {
z->input = Qnil;
}
else {
- memmove(RSTRING_PTR(z->input), RSTRING_PTR(z->input) + len,
- RSTRING_LEN(z->input) - len);
- rb_str_resize(z->input, RSTRING_LEN(z->input) - len);
+ memmove(RSTRING(z->input)->ptr, RSTRING(z->input)->ptr + len,
+ RSTRING(z->input)->len - len);
+ rb_str_resize(z->input, RSTRING(z->input)->len - len);
}
}
static void
-zstream_reset_input(struct zstream *z)
+zstream_reset_input(z)
+ struct zstream *z;
{
z->input = Qnil;
}
static void
-zstream_passthrough_input(struct zstream *z)
+zstream_passthrough_input(z)
+ struct zstream *z;
{
if (!NIL_P(z->input)) {
zstream_append_buffer2(z, z->input);
@@ -613,7 +645,8 @@ zstream_passthrough_input(struct zstream *z)
}
static VALUE
-zstream_detach_input(struct zstream *z)
+zstream_detach_input(z)
+ struct zstream *z;
{
VALUE dst;
@@ -625,12 +658,12 @@ zstream_detach_input(struct zstream *z)
RBASIC(dst)->klass = rb_cString;
}
z->input = Qnil;
- RBASIC(dst)->klass = rb_cString;
return dst;
}
static void
-zstream_reset(struct zstream *z)
+zstream_reset(z)
+ struct zstream *z;
{
int err;
@@ -647,7 +680,8 @@ zstream_reset(struct zstream *z)
}
static VALUE
-zstream_end(struct zstream *z)
+zstream_end(z)
+ struct zstream *z;
{
int err;
@@ -670,20 +704,24 @@ zstream_end(struct zstream *z)
}
static void
-zstream_run(struct zstream *z, Bytef *src, uInt len, int flush)
+zstream_run(z, src, len, flush)
+ struct zstream *z;
+ Bytef *src;
+ uInt len;
+ int flush;
{
uInt n;
int err;
volatile VALUE guard;
if (NIL_P(z->input) && len == 0) {
- z->stream.next_in = (Bytef*)"";
+ z->stream.next_in = "";
z->stream.avail_in = 0;
}
else {
zstream_append_input(z, src, len);
- z->stream.next_in = (Bytef*)RSTRING_PTR(z->input);
- z->stream.avail_in = RSTRING_LEN(z->input);
+ z->stream.next_in = RSTRING(z->input)->ptr;
+ z->stream.avail_in = RSTRING(z->input)->len;
/* keep reference to `z->input' so as not to be garbage collected
after zstream_reset_input() and prevent `z->stream.next_in'
from dangling. */
@@ -732,24 +770,27 @@ zstream_run(struct zstream *z, Bytef *src, uInt len, int flush)
}
static VALUE
-zstream_sync(struct zstream *z, Bytef *src, uInt len)
+zstream_sync(z, src, len)
+ struct zstream *z;
+ Bytef *src;
+ uInt len;
{
VALUE rest;
int err;
if (!NIL_P(z->input)) {
- z->stream.next_in = (Bytef*)RSTRING_PTR(z->input);
- z->stream.avail_in = RSTRING_LEN(z->input);
+ z->stream.next_in = RSTRING(z->input)->ptr;
+ z->stream.avail_in = RSTRING(z->input)->len;
err = inflateSync(&z->stream);
if (err == Z_OK) {
zstream_discard_input(z,
- RSTRING_LEN(z->input) - z->stream.avail_in);
+ RSTRING(z->input)->len - z->stream.avail_in);
zstream_append_input(z, src, len);
return Qtrue;
}
zstream_reset_input(z);
if (err != Z_DATA_ERROR) {
- rest = rb_str_new((char*)z->stream.next_in, z->stream.avail_in);
+ rest = rb_str_new(z->stream.next_in, z->stream.avail_in);
raise_zlib_error(err, z->stream.msg);
}
}
@@ -764,21 +805,23 @@ zstream_sync(struct zstream *z, Bytef *src, uInt len)
return Qtrue;
}
if (err != Z_DATA_ERROR) {
- rest = rb_str_new((char*)z->stream.next_in, z->stream.avail_in);
+ rest = rb_str_new(z->stream.next_in, z->stream.avail_in);
raise_zlib_error(err, z->stream.msg);
}
return Qfalse;
}
static void
-zstream_mark(struct zstream *z)
+zstream_mark(z)
+ struct zstream *z;
{
rb_gc_mark(z->buf);
rb_gc_mark(z->input);
}
static void
-zstream_finalize(struct zstream *z)
+zstream_finalize(z)
+ struct zstream *z;
{
int err = z->func->end(&z->stream);
if (err == Z_STREAM_ERROR)
@@ -788,7 +831,8 @@ zstream_finalize(struct zstream *z)
}
static void
-zstream_free(struct zstream *z)
+zstream_free(z)
+ struct zstream *z;
{
if (ZSTREAM_IS_READY(z)) {
zstream_finalize(z);
@@ -797,7 +841,9 @@ zstream_free(struct zstream *z)
}
static VALUE
-zstream_new(VALUE klass, const struct zstream_funcs *funcs)
+zstream_new(klass, funcs)
+ VALUE klass;
+ const struct zstream_funcs *funcs;
{
VALUE obj;
struct zstream *z;
@@ -812,7 +858,8 @@ zstream_new(VALUE klass, const struct zstream_funcs *funcs)
#define zstream_inflate_new(klass) zstream_new((klass), &inflate_funcs)
static struct zstream *
-get_zstream(VALUE obj)
+get_zstream(obj)
+ VALUE obj;
{
struct zstream *z;
@@ -892,7 +939,8 @@ get_zstream(VALUE obj)
* exception.
*/
static VALUE
-rb_zstream_end(VALUE obj)
+rb_zstream_end(obj)
+ VALUE obj;
{
zstream_end(get_zstream(obj));
return Qnil;
@@ -903,7 +951,8 @@ rb_zstream_end(VALUE obj)
* are discarded.
*/
static VALUE
-rb_zstream_reset(VALUE obj)
+rb_zstream_reset(obj)
+ VALUE obj;
{
zstream_reset(get_zstream(obj));
return Qnil;
@@ -914,12 +963,13 @@ rb_zstream_reset(VALUE obj)
* Zlib::Inflate#finish for details of this behavior.
*/
static VALUE
-rb_zstream_finish(VALUE obj)
+rb_zstream_finish(obj)
+ VALUE obj;
{
struct zstream *z = get_zstream(obj);
VALUE dst;
- zstream_run(z, (Bytef*)"", 0, Z_FINISH);
+ zstream_run(z, "", 0, Z_FINISH);
dst = zstream_detach_buffer(z);
OBJ_INFECT(dst, obj);
@@ -930,7 +980,8 @@ rb_zstream_finish(VALUE obj)
* Flushes input buffer and returns all data in that buffer.
*/
static VALUE
-rb_zstream_flush_next_in(VALUE obj)
+rb_zstream_flush_next_in(obj)
+ VALUE obj;
{
struct zstream *z;
VALUE dst;
@@ -945,7 +996,8 @@ rb_zstream_flush_next_in(VALUE obj)
* Flushes output buffer and returns all data in that buffer.
*/
static VALUE
-rb_zstream_flush_next_out(VALUE obj)
+rb_zstream_flush_next_out(obj)
+ VALUE obj;
{
struct zstream *z;
VALUE dst;
@@ -961,7 +1013,8 @@ rb_zstream_flush_next_out(VALUE obj)
* space is allocated automatically, this method returns 0 normally.
*/
static VALUE
-rb_zstream_avail_out(VALUE obj)
+rb_zstream_avail_out(obj)
+ VALUE obj;
{
struct zstream *z;
Data_Get_Struct(obj, struct zstream, z);
@@ -975,7 +1028,8 @@ rb_zstream_avail_out(VALUE obj)
* method.
*/
static VALUE
-rb_zstream_set_avail_out(VALUE obj, VALUE size)
+rb_zstream_set_avail_out(obj, size)
+ VALUE obj, size;
{
struct zstream *z = get_zstream(obj);
@@ -988,18 +1042,20 @@ rb_zstream_set_avail_out(VALUE obj, VALUE size)
* Returns bytes of data in the input buffer. Normally, returns 0.
*/
static VALUE
-rb_zstream_avail_in(VALUE obj)
+rb_zstream_avail_in(obj)
+ VALUE obj;
{
struct zstream *z;
Data_Get_Struct(obj, struct zstream, z);
- return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING_LEN(z->input)));
+ return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING(z->input)->len));
}
/*
* Returns the total bytes of the input data to the stream. FIXME
*/
static VALUE
-rb_zstream_total_in(VALUE obj)
+rb_zstream_total_in(obj)
+ VALUE obj;
{
return rb_uint2inum(get_zstream(obj)->stream.total_in);
}
@@ -1008,7 +1064,8 @@ rb_zstream_total_in(VALUE obj)
* Returns the total bytes of the output data from the stream. FIXME
*/
static VALUE
-rb_zstream_total_out(VALUE obj)
+rb_zstream_total_out(obj)
+ VALUE obj;
{
return rb_uint2inum(get_zstream(obj)->stream.total_out);
}
@@ -1019,7 +1076,8 @@ rb_zstream_total_out(VALUE obj)
* <tt>Zlib::UNKNOWN</tt>.
*/
static VALUE
-rb_zstream_data_type(VALUE obj)
+rb_zstream_data_type(obj)
+ VALUE obj;
{
return INT2FIX(get_zstream(obj)->stream.data_type);
}
@@ -1028,7 +1086,8 @@ rb_zstream_data_type(VALUE obj)
* Returns the adler-32 checksum.
*/
static VALUE
-rb_zstream_adler(VALUE obj)
+rb_zstream_adler(obj)
+ VALUE obj;
{
return rb_uint2inum(get_zstream(obj)->stream.adler);
}
@@ -1037,7 +1096,8 @@ rb_zstream_adler(VALUE obj)
* Returns true if the stream is finished.
*/
static VALUE
-rb_zstream_finished_p(VALUE obj)
+rb_zstream_finished_p(obj)
+ VALUE obj;
{
return ZSTREAM_IS_FINISHED(get_zstream(obj)) ? Qtrue : Qfalse;
}
@@ -1046,7 +1106,8 @@ rb_zstream_finished_p(VALUE obj)
* Returns true if the stream is closed.
*/
static VALUE
-rb_zstream_closed_p(VALUE obj)
+rb_zstream_closed_p(obj)
+ VALUE obj;
{
struct zstream *z;
Data_Get_Struct(obj, struct zstream, z);
@@ -1075,7 +1136,8 @@ rb_zstream_closed_p(VALUE obj)
static VALUE
-rb_deflate_s_allocate(VALUE klass)
+rb_deflate_s_allocate(klass)
+ VALUE klass;
{
return zstream_deflate_new(klass);
}
@@ -1090,7 +1152,10 @@ rb_deflate_s_allocate(VALUE klass)
* TODO: document better!
*/
static VALUE
-rb_deflate_initialize(int argc, VALUE *argv, VALUE obj)
+rb_deflate_initialize(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
struct zstream *z;
VALUE level, wbits, memlevel, strategy;
@@ -1114,28 +1179,35 @@ rb_deflate_initialize(int argc, VALUE *argv, VALUE obj)
* Duplicates the deflate stream.
*/
static VALUE
-rb_deflate_init_copy(VALUE self, VALUE orig)
+rb_deflate_init_copy(self, orig)
+ VALUE self, orig;
{
- struct zstream *z1 = get_zstream(self);
- struct zstream *z2 = get_zstream(orig);
+ struct zstream *z1, *z2;
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;
}
static VALUE
-deflate_run(VALUE args)
+deflate_run(args)
+ VALUE args;
{
- struct zstream *z = (struct zstream*)((VALUE*)args)[0];
- VALUE src = ((VALUE*)args)[1];
+ struct zstream *z = (struct zstream *)((VALUE *)args)[0];
+ VALUE src = ((VALUE *)args)[1];
- zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_FINISH);
+ zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, Z_FINISH);
return zstream_detach_buffer(z);
}
@@ -1160,7 +1232,10 @@ deflate_run(VALUE args)
*
*/
static VALUE
-rb_deflate_s_deflate(int argc, VALUE *argv, VALUE klass)
+rb_deflate_s_deflate(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
struct zstream z;
VALUE src, level, dst, args[2];
@@ -1186,15 +1261,18 @@ rb_deflate_s_deflate(int argc, VALUE *argv, VALUE klass)
}
static void
-do_deflate(struct zstream *z, VALUE src, int flush)
+do_deflate(z, src, flush)
+ struct zstream *z;
+ VALUE src;
+ int flush;
{
if (NIL_P(src)) {
- zstream_run(z, (Bytef*)"", 0, Z_FINISH);
+ zstream_run(z, "", 0, Z_FINISH);
return;
}
StringValue(src);
- if (flush != Z_NO_FLUSH || RSTRING_LEN(src) > 0) { /* prevent BUF_ERROR */
- zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), flush);
+ if (flush != Z_NO_FLUSH || RSTRING(src)->len > 0) { /* prevent BUF_ERROR */
+ zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, flush);
}
}
@@ -1213,7 +1291,10 @@ do_deflate(struct zstream *z, VALUE src, int flush)
* TODO: document better!
*/
static VALUE
-rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
+rb_deflate_deflate(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
struct zstream *z = get_zstream(obj);
VALUE src, flush, dst;
@@ -1235,7 +1316,8 @@ rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
* preserved in output buffer.
*/
static VALUE
-rb_deflate_addstr(VALUE obj, VALUE src)
+rb_deflate_addstr(obj, src)
+ VALUE obj, src;
{
OBJ_INFECT(obj, src);
do_deflate(get_zstream(obj), src, Z_NO_FLUSH);
@@ -1252,7 +1334,10 @@ rb_deflate_addstr(VALUE obj, VALUE src)
* TODO: document better!
*/
static VALUE
-rb_deflate_flush(int argc, VALUE *argv, VALUE obj)
+rb_deflate_flush(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
struct zstream *z = get_zstream(obj);
VALUE v_flush, dst;
@@ -1261,7 +1346,7 @@ rb_deflate_flush(int argc, VALUE *argv, VALUE obj)
rb_scan_args(argc, argv, "01", &v_flush);
flush = FIXNUMARG(v_flush, Z_SYNC_FLUSH);
if (flush != Z_NO_FLUSH) { /* prevent Z_BUF_ERROR */
- zstream_run(z, (Bytef*)"", 0, flush);
+ zstream_run(z, "", 0, flush);
}
dst = zstream_detach_buffer(z);
@@ -1279,7 +1364,8 @@ rb_deflate_flush(int argc, VALUE *argv, VALUE obj)
* TODO: document better!
*/
static VALUE
-rb_deflate_params(VALUE obj, VALUE v_level, VALUE v_strategy)
+rb_deflate_params(obj, v_level, v_strategy)
+ VALUE obj, v_level, v_strategy;
{
struct zstream *z = get_zstream(obj);
int level, strategy;
@@ -1311,7 +1397,8 @@ rb_deflate_params(VALUE obj, VALUE v_level, VALUE v_strategy)
* TODO: document better!
*/
static VALUE
-rb_deflate_set_dictionary(VALUE obj, VALUE dic)
+rb_deflate_set_dictionary(obj, dic)
+ VALUE obj, dic;
{
struct zstream *z = get_zstream(obj);
VALUE src = dic;
@@ -1320,7 +1407,7 @@ rb_deflate_set_dictionary(VALUE obj, VALUE dic)
OBJ_INFECT(obj, dic);
StringValue(src);
err = deflateSetDictionary(&z->stream,
- (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
+ RSTRING(src)->ptr, RSTRING(src)->len);
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
@@ -1342,7 +1429,8 @@ rb_deflate_set_dictionary(VALUE obj, VALUE dic)
static VALUE
-rb_inflate_s_allocate(VALUE klass)
+rb_inflate_s_allocate(klass)
+ VALUE klass;
{
return zstream_inflate_new(klass);
}
@@ -1356,7 +1444,10 @@ rb_inflate_s_allocate(VALUE klass)
* TODO: document better!
*/
static VALUE
-rb_inflate_initialize(int argc, VALUE *argv, VALUE obj)
+rb_inflate_initialize(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
struct zstream *z;
VALUE wbits;
@@ -1375,13 +1466,14 @@ rb_inflate_initialize(int argc, VALUE *argv, VALUE obj)
}
static VALUE
-inflate_run(VALUE args)
+inflate_run(args)
+ VALUE args;
{
- struct zstream *z = (struct zstream*)((VALUE*)args)[0];
- VALUE src = ((VALUE*)args)[1];
+ struct zstream *z = (struct zstream *)((VALUE *)args)[0];
+ VALUE src = ((VALUE *)args)[1];
- zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_SYNC_FLUSH);
- zstream_run(z, (Bytef*)"", 0, Z_FINISH); /* for checking errors */
+ zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
+ zstream_run(z, "", 0, Z_FINISH); /* for checking errors */
return zstream_detach_buffer(z);
}
@@ -1403,7 +1495,8 @@ inflate_run(VALUE args)
*
*/
static VALUE
-rb_inflate_s_inflate(VALUE obj, VALUE src)
+rb_inflate_s_inflate(obj, src)
+ VALUE obj, src;
{
struct zstream z;
VALUE dst, args[2];
@@ -1426,15 +1519,17 @@ rb_inflate_s_inflate(VALUE obj, VALUE src)
}
static void
-do_inflate(struct zstream *z, VALUE src)
+do_inflate(z, src)
+ struct zstream *z;
+ VALUE src;
{
if (NIL_P(src)) {
- zstream_run(z, (Bytef*)"", 0, Z_FINISH);
+ zstream_run(z, "", 0, Z_FINISH);
return;
}
StringValue(src);
- if (RSTRING_LEN(src) > 0) { /* prevent Z_BUF_ERROR */
- zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_SYNC_FLUSH);
+ if (RSTRING(src)->len > 0) { /* prevent Z_BUF_ERROR */
+ zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
}
}
@@ -1453,7 +1548,8 @@ do_inflate(struct zstream *z, VALUE src)
* TODO: document better!
*/
static VALUE
-rb_inflate_inflate(VALUE obj, VALUE src)
+rb_inflate_inflate(obj, src)
+ VALUE obj, src;
{
struct zstream *z = get_zstream(obj);
VALUE dst;
@@ -1490,7 +1586,8 @@ rb_inflate_inflate(VALUE obj, VALUE src)
* preserved in output buffer.
*/
static VALUE
-rb_inflate_addstr(VALUE obj, VALUE src)
+rb_inflate_addstr(obj, src)
+ VALUE obj, src;
{
struct zstream *z = get_zstream(obj);
@@ -1521,13 +1618,14 @@ rb_inflate_addstr(VALUE obj, VALUE src)
* following data of full flush point is preserved in the buffer.
*/
static VALUE
-rb_inflate_sync(VALUE obj, VALUE src)
+rb_inflate_sync(obj, src)
+ VALUE obj, src;
{
struct zstream *z = get_zstream(obj);
OBJ_INFECT(obj, src);
StringValue(src);
- return zstream_sync(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
+ return zstream_sync(z, RSTRING(src)->ptr, RSTRING(src)->len);
}
/*
@@ -1538,7 +1636,8 @@ rb_inflate_sync(VALUE obj, VALUE src)
* <tt>:)</tt>
*/
static VALUE
-rb_inflate_sync_point_p(VALUE obj)
+rb_inflate_sync_point_p(obj)
+ VALUE obj;
{
struct zstream *z = get_zstream(obj);
int err;
@@ -1560,7 +1659,8 @@ rb_inflate_sync_point_p(VALUE obj)
* TODO: document better!
*/
static VALUE
-rb_inflate_set_dictionary(VALUE obj, VALUE dic)
+rb_inflate_set_dictionary(obj, dic)
+ VALUE obj, dic;
{
struct zstream *z = get_zstream(obj);
VALUE src = dic;
@@ -1569,7 +1669,7 @@ rb_inflate_set_dictionary(VALUE obj, VALUE dic)
OBJ_INFECT(obj, dic);
StringValue(src);
err = inflateSetDictionary(&z->stream,
- (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
+ RSTRING(src)->ptr, RSTRING(src)->len);
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
@@ -1623,7 +1723,7 @@ rb_inflate_set_dictionary(VALUE obj, VALUE dic)
#define OS_CODE OS_UNIX
#endif
-static ID id_write, id_read, id_readpartial, id_flush, id_seek, id_close;
+static ID id_write, id_read, id_flush, id_seek, id_close;
static VALUE cGzError, cNoFooter, cCRCError, cLengthError;
@@ -1655,7 +1755,8 @@ struct gzfile {
static void
-gzfile_mark(struct gzfile *gz)
+gzfile_mark(gz)
+ struct gzfile *gz;
{
rb_gc_mark(gz->io);
rb_gc_mark(gz->orig_name);
@@ -1664,7 +1765,8 @@ gzfile_mark(struct gzfile *gz)
}
static void
-gzfile_free(struct gzfile *gz)
+gzfile_free(gz)
+ struct gzfile *gz;
{
struct zstream *z = &gz->z;
@@ -1706,7 +1808,8 @@ gzfile_new(klass, funcs, endfunc)
#define gzfile_reader_new(gz) gzfile_new((gz),&inflate_funcs,gzfile_reader_end)
static void
-gzfile_reset(struct gzfile *gz)
+gzfile_reset(gz)
+ struct gzfile *gz;
{
zstream_reset(&gz->z);
gz->crc = crc32(0, Z_NULL, 0);
@@ -1715,7 +1818,9 @@ gzfile_reset(struct gzfile *gz)
}
static void
-gzfile_close(struct gzfile *gz, int closeflag)
+gzfile_close(gz, closeflag)
+ struct gzfile *gz;
+ int closeflag;
{
VALUE io = gz->io;
@@ -1729,7 +1834,8 @@ gzfile_close(struct gzfile *gz, int closeflag)
}
static void
-gzfile_write_raw(struct gzfile *gz)
+gzfile_write_raw(gz)
+ struct gzfile *gz;
{
VALUE str;
@@ -1744,44 +1850,26 @@ gzfile_write_raw(struct gzfile *gz)
}
static VALUE
-gzfile_read_raw_partial(VALUE arg)
+gzfile_read_raw(gz)
+ struct gzfile *gz;
{
- struct gzfile *gz = (struct gzfile*)arg;
VALUE str;
- str = rb_funcall(gz->io, id_readpartial, 1, INT2FIX(GZFILE_READ_SIZE));
- Check_Type(str, T_STRING);
- return str;
-}
-
-static VALUE
-gzfile_read_raw_rescue(VALUE arg)
-{
- struct gzfile *gz = (struct gzfile*)arg;
- VALUE str = Qnil;
- if (rb_obj_is_kind_of(ruby_errinfo, rb_eNoMethodError)) {
- str = rb_funcall(gz->io, id_read, 1, INT2FIX(GZFILE_READ_SIZE));
- if (!NIL_P(str)) {
- Check_Type(str, T_STRING);
- }
+ str = rb_funcall(gz->io, id_read, 1, INT2FIX(GZFILE_READ_SIZE));
+ if (!NIL_P(str)) {
+ Check_Type(str, T_STRING);
}
- return str; /* return nil when EOFError */
-}
-
-static VALUE
-gzfile_read_raw(struct gzfile *gz)
-{
- return rb_rescue2(gzfile_read_raw_partial, (VALUE)gz,
- gzfile_read_raw_rescue, (VALUE)gz,
- rb_eEOFError, rb_eNoMethodError, (VALUE)0);
+ return str;
}
static int
-gzfile_read_raw_ensure(struct gzfile *gz, int size)
+gzfile_read_raw_ensure(gz, size)
+ struct gzfile *gz;
+ int size;
{
VALUE str;
- while (NIL_P(gz->z.input) || RSTRING_LEN(gz->z.input) < size) {
+ while (NIL_P(gz->z.input) || RSTRING(gz->z.input)->len < size) {
str = gzfile_read_raw(gz);
if (NIL_P(str)) return Qfalse;
zstream_append_input2(&gz->z, str);
@@ -1790,27 +1878,30 @@ gzfile_read_raw_ensure(struct gzfile *gz, int size)
}
static char *
-gzfile_read_raw_until_zero(struct gzfile *gz, long offset)
+gzfile_read_raw_until_zero(gz, offset)
+ struct gzfile *gz;
+ long offset;
{
VALUE str;
char *p;
for (;;) {
- p = memchr(RSTRING_PTR(gz->z.input) + offset, '\0',
- RSTRING_LEN(gz->z.input) - offset);
+ p = memchr(RSTRING(gz->z.input)->ptr + offset, '\0',
+ RSTRING(gz->z.input)->len - offset);
if (p) break;
str = gzfile_read_raw(gz);
if (NIL_P(str)) {
rb_raise(cGzError, "unexpected end of file");
}
- offset = RSTRING_LEN(gz->z.input);
+ offset = RSTRING(gz->z.input)->len;
zstream_append_input2(&gz->z, str);
}
return p;
}
static unsigned int
-gzfile_get16(const unsigned char *src)
+gzfile_get16(src)
+ const unsigned char *src;
{
unsigned int n;
n = *(src++) & 0xff;
@@ -1819,7 +1910,8 @@ gzfile_get16(const unsigned char *src)
}
static unsigned long
-gzfile_get32(const unsigned char *src)
+gzfile_get32(src)
+ const unsigned char *src;
{
unsigned long n;
n = *(src++) & 0xff;
@@ -1830,7 +1922,9 @@ gzfile_get32(const unsigned char *src)
}
static void
-gzfile_set32(unsigned long n, unsigned char *dst)
+gzfile_set32(n, dst)
+ unsigned long n;
+ unsigned char *dst;
{
*(dst++) = n & 0xff;
*(dst++) = (n >> 8) & 0xff;
@@ -1839,9 +1933,10 @@ gzfile_set32(unsigned long n, unsigned char *dst)
}
static void
-gzfile_make_header(struct gzfile *gz)
+gzfile_make_header(gz)
+ struct gzfile *gz;
{
- Bytef buf[10]; /* the size of gzip header */
+ unsigned char buf[10]; /* the size of gzip header */
unsigned char flags = 0, extraflags = 0;
if (!NIL_P(gz->orig_name)) {
@@ -1872,20 +1967,21 @@ gzfile_make_header(struct gzfile *gz)
if (!NIL_P(gz->orig_name)) {
zstream_append_buffer2(&gz->z, gz->orig_name);
- zstream_append_buffer(&gz->z, (Bytef*)"\0", 1);
+ zstream_append_buffer(&gz->z, "\0", 1);
}
if (!NIL_P(gz->comment)) {
zstream_append_buffer2(&gz->z, gz->comment);
- zstream_append_buffer(&gz->z, (Bytef*)"\0", 1);
+ zstream_append_buffer(&gz->z, "\0", 1);
}
gz->z.flags |= GZFILE_FLAG_HEADER_FINISHED;
}
static void
-gzfile_make_footer(struct gzfile *gz)
+gzfile_make_footer(gz)
+ struct gzfile *gz;
{
- Bytef buf[8]; /* 8 is the size of gzip footer */
+ unsigned char buf[8]; /* 8 is the size of gzip footer */
gzfile_set32(gz->crc, buf);
gzfile_set32(gz->z.stream.total_in, &buf[4]);
@@ -1894,7 +1990,8 @@ gzfile_make_footer(struct gzfile *gz)
}
static void
-gzfile_read_header(struct gzfile *gz)
+gzfile_read_header(gz)
+ struct gzfile *gz;
{
const unsigned char *head;
long len;
@@ -1904,7 +2001,7 @@ gzfile_read_header(struct gzfile *gz)
rb_raise(cGzError, "not in gzip format");
}
- head = (unsigned char*)RSTRING_PTR(gz->z.input);
+ head = RSTRING(gz->z.input)->ptr;
if (head[0] != GZ_MAGIC1 || head[1] != GZ_MAGIC2) {
rb_raise(cGzError, "not in gzip format");
@@ -1942,7 +2039,7 @@ gzfile_read_header(struct gzfile *gz)
if (!gzfile_read_raw_ensure(gz, 2)) {
rb_raise(cGzError, "unexpected end of file");
}
- len = gzfile_get16((Bytef*)RSTRING_PTR(gz->z.input));
+ len = gzfile_get16(RSTRING(gz->z.input)->ptr);
if (!gzfile_read_raw_ensure(gz, 2 + len)) {
rb_raise(cGzError, "unexpected end of file");
}
@@ -1950,26 +2047,27 @@ gzfile_read_header(struct gzfile *gz)
}
if (flags & GZ_FLAG_ORIG_NAME) {
p = gzfile_read_raw_until_zero(gz, 0);
- len = p - RSTRING_PTR(gz->z.input);
- gz->orig_name = rb_str_new(RSTRING_PTR(gz->z.input), len);
+ len = p - RSTRING(gz->z.input)->ptr;
+ gz->orig_name = rb_str_new(RSTRING(gz->z.input)->ptr, len);
OBJ_TAINT(gz->orig_name); /* for safe */
zstream_discard_input(&gz->z, len + 1);
}
if (flags & GZ_FLAG_COMMENT) {
p = gzfile_read_raw_until_zero(gz, 0);
- len = p - RSTRING_PTR(gz->z.input);
- gz->comment = rb_str_new(RSTRING_PTR(gz->z.input), len);
+ len = p - RSTRING(gz->z.input)->ptr;
+ gz->comment = rb_str_new(RSTRING(gz->z.input)->ptr, len);
OBJ_TAINT(gz->comment); /* for safe */
zstream_discard_input(&gz->z, len + 1);
}
- if (gz->z.input != Qnil && RSTRING_LEN(gz->z.input) > 0) {
+ if (gz->z.input != Qnil && RSTRING(gz->z.input)->len > 0) {
zstream_run(&gz->z, 0, 0, Z_SYNC_FLUSH);
}
}
static void
-gzfile_check_footer(struct gzfile *gz)
+gzfile_check_footer(gz)
+ struct gzfile *gz;
{
unsigned long crc, length;
@@ -1979,8 +2077,8 @@ gzfile_check_footer(struct gzfile *gz)
rb_raise(cNoFooter, "footer is not found");
}
- crc = gzfile_get32((Bytef*)RSTRING_PTR(gz->z.input));
- length = gzfile_get32((Bytef*)RSTRING_PTR(gz->z.input) + 4);
+ crc = gzfile_get32(RSTRING(gz->z.input)->ptr);
+ length = gzfile_get32(RSTRING(gz->z.input)->ptr + 4);
gz->z.stream.total_in += 8; /* to rewind correctly */
zstream_discard_input(&gz->z, 8);
@@ -1994,7 +2092,10 @@ gzfile_check_footer(struct gzfile *gz)
}
static void
-gzfile_write(struct gzfile *gz, Bytef *str, uInt len)
+gzfile_write(gz, str, len)
+ struct gzfile *gz;
+ Bytef *str;
+ uInt len;
{
if (!(gz->z.flags & GZFILE_FLAG_HEADER_FINISHED)) {
gzfile_make_header(gz);
@@ -2009,7 +2110,8 @@ gzfile_write(struct gzfile *gz, Bytef *str, uInt len)
}
static long
-gzfile_read_more(struct gzfile *gz)
+gzfile_read_more(gz)
+ struct gzfile *gz;
{
volatile VALUE str;
@@ -2021,8 +2123,8 @@ gzfile_read_more(struct gzfile *gz)
}
break;
}
- if (RSTRING_LEN(str) > 0) { /* prevent Z_BUF_ERROR */
- zstream_run(&gz->z, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str),
+ if (RSTRING(str)->len > 0) { /* prevent Z_BUF_ERROR */
+ zstream_run(&gz->z, RSTRING(str)->ptr, RSTRING(str)->len,
Z_SYNC_FLUSH);
}
if (gz->z.buf_filled > 0) break;
@@ -2031,20 +2133,24 @@ gzfile_read_more(struct gzfile *gz)
}
static void
-gzfile_calc_crc(struct gzfile *gz, VALUE str)
+gzfile_calc_crc(gz, str)
+ struct gzfile *gz;
+ VALUE str;
{
- if (RSTRING_LEN(str) <= gz->ungetc) {
- gz->ungetc -= RSTRING_LEN(str);
+ if (RSTRING(str)->len <= gz->ungetc) {
+ gz->ungetc -= RSTRING(str)->len;
}
else {
- gz->crc = crc32(gz->crc, (Bytef*)RSTRING_PTR(str) + gz->ungetc,
- RSTRING_LEN(str) - gz->ungetc);
+ gz->crc = crc32(gz->crc, RSTRING(str)->ptr + gz->ungetc,
+ RSTRING(str)->len - gz->ungetc);
gz->ungetc = 0;
}
}
static VALUE
-gzfile_read(struct gzfile *gz, int len)
+gzfile_read(gz, len)
+ struct gzfile *gz;
+ int len;
{
VALUE dst;
@@ -2070,52 +2176,8 @@ gzfile_read(struct gzfile *gz, int len)
}
static VALUE
-gzfile_readpartial(struct gzfile *gz, int len, VALUE outbuf)
-{
- VALUE dst;
-
- if (len < 0)
- rb_raise(rb_eArgError, "negative length %d given", len);
-
- if (!NIL_P(outbuf))
- OBJ_TAINT(outbuf);
-
- if (len == 0) {
- if (NIL_P(outbuf))
- return rb_str_new(0, 0);
- else {
- rb_str_resize(outbuf, 0);
- return outbuf;
- }
- }
- while (!ZSTREAM_IS_FINISHED(&gz->z) && gz->z.buf_filled == 0) {
- gzfile_read_more(gz);
- }
- if (GZFILE_IS_FINISHED(gz)) {
- if (!(gz->z.flags & GZFILE_FLAG_FOOTER_FINISHED)) {
- gzfile_check_footer(gz);
- }
- if (!NIL_P(outbuf))
- rb_str_resize(outbuf, 0);
- rb_raise(rb_eEOFError, "end of file reached");
- }
-
- dst = zstream_shift_buffer(&gz->z, len);
- gzfile_calc_crc(gz, dst);
-
- if (NIL_P(outbuf)) {
- OBJ_TAINT(dst); /* for safe */
- return dst;
- }
- else {
- rb_str_resize(outbuf, RSTRING_LEN(dst));
- memcpy(RSTRING_PTR(outbuf), RSTRING_PTR(dst), RSTRING_LEN(dst));
- return outbuf;
- }
-}
-
-static VALUE
-gzfile_read_all(struct gzfile *gz)
+gzfile_read_all(gz)
+ struct gzfile *gz;
{
VALUE dst;
@@ -2137,14 +2199,17 @@ gzfile_read_all(struct gzfile *gz)
}
static void
-gzfile_ungetc(struct gzfile *gz, int c)
+gzfile_ungetc(gz, c)
+ struct gzfile *gz;
+ int c;
{
zstream_buffer_ungetc(&gz->z, c);
gz->ungetc++;
}
static VALUE
-gzfile_writer_end_run(VALUE arg)
+gzfile_writer_end_run(arg)
+ VALUE arg;
{
struct gzfile *gz = (struct gzfile *)arg;
@@ -2152,7 +2217,7 @@ gzfile_writer_end_run(VALUE arg)
gzfile_make_header(gz);
}
- zstream_run(&gz->z, (Bytef*)"", 0, Z_FINISH);
+ zstream_run(&gz->z, "", 0, Z_FINISH);
gzfile_make_footer(gz);
gzfile_write_raw(gz);
@@ -2160,7 +2225,8 @@ gzfile_writer_end_run(VALUE arg)
}
static void
-gzfile_writer_end(struct gzfile *gz)
+gzfile_writer_end(gz)
+ struct gzfile *gz;
{
if (ZSTREAM_IS_CLOSING(&gz->z)) return;
gz->z.flags |= ZSTREAM_FLAG_CLOSING;
@@ -2169,7 +2235,8 @@ gzfile_writer_end(struct gzfile *gz)
}
static VALUE
-gzfile_reader_end_run(VALUE arg)
+gzfile_reader_end_run(arg)
+ VALUE arg;
{
struct gzfile *gz = (struct gzfile *)arg;
@@ -2182,7 +2249,8 @@ gzfile_reader_end_run(VALUE arg)
}
static void
-gzfile_reader_end(struct gzfile *gz)
+gzfile_reader_end(gz)
+ struct gzfile *gz;
{
if (ZSTREAM_IS_CLOSING(&gz->z)) return;
gz->z.flags |= ZSTREAM_FLAG_CLOSING;
@@ -2191,13 +2259,14 @@ gzfile_reader_end(struct gzfile *gz)
}
static void
-gzfile_reader_rewind(struct gzfile *gz)
+gzfile_reader_rewind(gz)
+ struct gzfile *gz;
{
long n;
n = gz->z.stream.total_in;
if (!NIL_P(gz->z.input)) {
- n += RSTRING_LEN(gz->z.input);
+ n += RSTRING(gz->z.input)->len;
}
rb_funcall(gz->io, id_seek, 2, rb_int2inum(-n), INT2FIX(1));
@@ -2205,7 +2274,8 @@ gzfile_reader_rewind(struct gzfile *gz)
}
static VALUE
-gzfile_reader_get_unused(struct gzfile *gz)
+gzfile_reader_get_unused(gz)
+ struct gzfile *gz;
{
VALUE str;
@@ -2222,7 +2292,8 @@ gzfile_reader_get_unused(struct gzfile *gz)
}
static struct gzfile *
-get_gzfile(VALUE obj)
+get_gzfile(obj)
+ VALUE obj;
{
struct gzfile *gz;
@@ -2248,7 +2319,8 @@ get_gzfile(VALUE obj)
static VALUE
-gzfile_ensure_close(VALUE obj)
+gzfile_ensure_close(obj)
+ VALUE obj;
{
struct gzfile *gz;
@@ -2263,7 +2335,10 @@ gzfile_ensure_close(VALUE obj)
* See Zlib::GzipReader#wrap and Zlib::GzipWriter#wrap.
*/
static VALUE
-rb_gzfile_s_wrap(int argc, VALUE *argv, VALUE klass)
+rb_gzfile_s_wrap(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE obj = rb_class_new_instance(argc, argv, klass);
@@ -2279,7 +2354,11 @@ rb_gzfile_s_wrap(int argc, VALUE *argv, VALUE klass)
* See Zlib::GzipReader#open and Zlib::GzipWriter#open.
*/
static VALUE
-gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode)
+gzfile_s_open(argc, argv, klass, mode)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
+ const char *mode;
{
VALUE io, filename;
@@ -2288,7 +2367,7 @@ gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode)
}
filename = argv[0];
SafeStringValue(filename);
- io = rb_file_open(RSTRING_PTR(filename), mode);
+ io = rb_file_open(RSTRING(filename)->ptr, mode);
argv[0] = io;
return rb_gzfile_s_wrap(argc, argv, klass);
@@ -2298,7 +2377,8 @@ gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode)
* Same as IO.
*/
static VALUE
-rb_gzfile_to_io(VALUE obj)
+rb_gzfile_to_io(obj)
+ VALUE obj;
{
return get_gzfile(obj)->io;
}
@@ -2307,7 +2387,8 @@ rb_gzfile_to_io(VALUE obj)
* Returns CRC value of the uncompressed data.
*/
static VALUE
-rb_gzfile_crc(VALUE obj)
+rb_gzfile_crc(obj)
+ VALUE obj;
{
return rb_uint2inum(get_gzfile(obj)->crc);
}
@@ -2316,7 +2397,8 @@ rb_gzfile_crc(VALUE obj)
* Returns last modification time recorded in the gzip file header.
*/
static VALUE
-rb_gzfile_mtime(VALUE obj)
+rb_gzfile_mtime(obj)
+ VALUE obj;
{
return rb_time_new(get_gzfile(obj)->mtime, (time_t)0);
}
@@ -2325,7 +2407,8 @@ rb_gzfile_mtime(VALUE obj)
* Returns compression level.
*/
static VALUE
-rb_gzfile_level(VALUE obj)
+rb_gzfile_level(obj)
+ VALUE obj;
{
return INT2FIX(get_gzfile(obj)->level);
}
@@ -2334,7 +2417,8 @@ rb_gzfile_level(VALUE obj)
* Returns OS code number recorded in the gzip file header.
*/
static VALUE
-rb_gzfile_os_code(VALUE obj)
+rb_gzfile_os_code(obj)
+ VALUE obj;
{
return INT2FIX(get_gzfile(obj)->os_code);
}
@@ -2344,7 +2428,8 @@ rb_gzfile_os_code(VALUE obj)
* original filename is not present.
*/
static VALUE
-rb_gzfile_orig_name(VALUE obj)
+rb_gzfile_orig_name(obj)
+ VALUE obj;
{
VALUE str = get_gzfile(obj)->orig_name;
if (!NIL_P(str)) {
@@ -2359,7 +2444,8 @@ rb_gzfile_orig_name(VALUE obj)
* is not present.
*/
static VALUE
-rb_gzfile_comment(VALUE obj)
+rb_gzfile_comment(obj)
+ VALUE obj;
{
VALUE str = get_gzfile(obj)->comment;
if (!NIL_P(str)) {
@@ -2373,7 +2459,8 @@ rb_gzfile_comment(VALUE obj)
* ???
*/
static VALUE
-rb_gzfile_lineno(VALUE obj)
+rb_gzfile_lineno(obj)
+ VALUE obj;
{
return INT2NUM(get_gzfile(obj)->lineno);
}
@@ -2382,7 +2469,8 @@ rb_gzfile_lineno(VALUE obj)
* ???
*/
static VALUE
-rb_gzfile_set_lineno(VALUE obj, VALUE lineno)
+rb_gzfile_set_lineno(obj, lineno)
+ VALUE obj, lineno;
{
struct gzfile *gz = get_gzfile(obj);
gz->lineno = NUM2INT(lineno);
@@ -2393,7 +2481,8 @@ rb_gzfile_set_lineno(VALUE obj, VALUE lineno)
* ???
*/
static VALUE
-rb_gzfile_set_mtime(VALUE obj, VALUE mtime)
+rb_gzfile_set_mtime(obj, mtime)
+ VALUE obj, mtime;
{
struct gzfile *gz = get_gzfile(obj);
VALUE val;
@@ -2402,7 +2491,7 @@ rb_gzfile_set_mtime(VALUE obj, VALUE mtime)
rb_raise(cGzError, "header is already written");
}
- if (FIXNUM_P(time)) {
+ if (FIXNUM_P(mtime)) {
gz->mtime = FIX2INT(mtime);
}
else {
@@ -2416,7 +2505,8 @@ rb_gzfile_set_mtime(VALUE obj, VALUE mtime)
* ???
*/
static VALUE
-rb_gzfile_set_orig_name(VALUE obj, VALUE str)
+rb_gzfile_set_orig_name(obj, str)
+ VALUE obj, str;
{
struct gzfile *gz = get_gzfile(obj);
VALUE s;
@@ -2426,9 +2516,9 @@ rb_gzfile_set_orig_name(VALUE obj, VALUE str)
rb_raise(cGzError, "header is already written");
}
s = rb_str_dup(rb_str_to_str(str));
- p = memchr(RSTRING_PTR(s), '\0', RSTRING_LEN(s));
+ p = memchr(RSTRING(s)->ptr, '\0', RSTRING(s)->len);
if (p) {
- rb_str_resize(s, p - RSTRING_PTR(s));
+ rb_str_resize(s, p - RSTRING(s)->ptr);
}
gz->orig_name = s;
return str;
@@ -2438,7 +2528,8 @@ rb_gzfile_set_orig_name(VALUE obj, VALUE str)
* ???
*/
static VALUE
-rb_gzfile_set_comment(VALUE obj, VALUE str)
+rb_gzfile_set_comment(obj, str)
+ VALUE obj, str;
{
struct gzfile *gz = get_gzfile(obj);
VALUE s;
@@ -2448,9 +2539,9 @@ rb_gzfile_set_comment(VALUE obj, VALUE str)
rb_raise(cGzError, "header is already written");
}
s = rb_str_dup(rb_str_to_str(str));
- p = memchr(RSTRING_PTR(s), '\0', RSTRING_LEN(s));
+ p = memchr(RSTRING(s)->ptr, '\0', RSTRING(s)->len);
if (p) {
- rb_str_resize(s, p - RSTRING_PTR(s));
+ rb_str_resize(s, p - RSTRING(s)->ptr);
}
gz->comment = s;
return str;
@@ -2461,7 +2552,8 @@ rb_gzfile_set_comment(VALUE obj, VALUE str)
* associated IO object. Returns the associated IO object.
*/
static VALUE
-rb_gzfile_close(VALUE obj)
+rb_gzfile_close(obj)
+ VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
VALUE io;
@@ -2477,7 +2569,8 @@ rb_gzfile_close(VALUE obj)
* object.
*/
static VALUE
-rb_gzfile_finish(VALUE obj)
+rb_gzfile_finish(obj)
+ VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
VALUE io;
@@ -2491,7 +2584,8 @@ rb_gzfile_finish(VALUE obj)
* Same as IO.
*/
static VALUE
-rb_gzfile_closed_p(VALUE obj)
+rb_gzfile_closed_p(obj)
+ VALUE obj;
{
struct gzfile *gz;
Data_Get_Struct(obj, struct gzfile, gz);
@@ -2502,7 +2596,8 @@ rb_gzfile_closed_p(VALUE obj)
* ???
*/
static VALUE
-rb_gzfile_eof_p(VALUE obj)
+rb_gzfile_eof_p(obj)
+ VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
return GZFILE_IS_FINISHED(gz) ? Qtrue : Qfalse;
@@ -2512,7 +2607,8 @@ rb_gzfile_eof_p(VALUE obj)
* Same as IO.
*/
static VALUE
-rb_gzfile_sync(VALUE obj)
+rb_gzfile_sync(obj)
+ VALUE obj;
{
return (get_gzfile(obj)->z.flags & GZFILE_FLAG_SYNC) ? Qtrue : Qfalse;
}
@@ -2525,7 +2621,8 @@ rb_gzfile_sync(VALUE obj)
* decreases sharply.
*/
static VALUE
-rb_gzfile_set_sync(VALUE obj, VALUE mode)
+rb_gzfile_set_sync(obj, mode)
+ VALUE obj, mode;
{
struct gzfile *gz = get_gzfile(obj);
@@ -2542,7 +2639,8 @@ rb_gzfile_set_sync(VALUE obj, VALUE mode)
* ???
*/
static VALUE
-rb_gzfile_total_in(VALUE obj)
+rb_gzfile_total_in(obj)
+ VALUE obj;
{
return rb_uint2inum(get_gzfile(obj)->z.stream.total_in);
}
@@ -2551,7 +2649,8 @@ rb_gzfile_total_in(VALUE obj)
* ???
*/
static VALUE
-rb_gzfile_total_out(VALUE obj)
+rb_gzfile_total_out(obj)
+ VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
return rb_uint2inum(gz->z.stream.total_out - gz->z.buf_filled);
@@ -2588,7 +2687,8 @@ rb_gzfile_total_out(VALUE obj)
*/
static VALUE
-rb_gzwriter_s_allocate(VALUE klass)
+rb_gzwriter_s_allocate(klass)
+ VALUE klass;
{
return gzfile_writer_new(klass);
}
@@ -2601,7 +2701,10 @@ rb_gzwriter_s_allocate(VALUE klass)
* this method are found in Zlib::GzipWriter.new and Zlib::GzipWriter#wrap.
*/
static VALUE
-rb_gzwriter_s_open(int argc, VALUE *argv, VALUE klass)
+rb_gzwriter_s_open(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
return gzfile_s_open(argc, argv, klass, "wb");
}
@@ -2615,7 +2718,10 @@ rb_gzwriter_s_open(int argc, VALUE *argv, VALUE klass)
* +write+ method that behaves same as write method in IO class.
*/
static VALUE
-rb_gzwriter_initialize(int argc, VALUE *argv, VALUE obj)
+rb_gzwriter_initialize(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
struct gzfile *gz;
VALUE io, level, strategy;
@@ -2645,7 +2751,10 @@ rb_gzwriter_initialize(int argc, VALUE *argv, VALUE obj)
* +flush+ is omitted. It is no use giving flush <tt>Zlib::NO_FLUSH</tt>.
*/
static VALUE
-rb_gzwriter_flush(int argc, VALUE *argv, VALUE obj)
+rb_gzwriter_flush(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
VALUE v_flush;
@@ -2655,7 +2764,7 @@ rb_gzwriter_flush(int argc, VALUE *argv, VALUE obj)
flush = FIXNUMARG(v_flush, Z_SYNC_FLUSH);
if (flush != Z_NO_FLUSH) { /* prevent Z_BUF_ERROR */
- zstream_run(&gz->z, (Bytef*)"", 0, flush);
+ zstream_run(&gz->z, "", 0, flush);
}
gzfile_write_raw(gz);
@@ -2669,27 +2778,29 @@ rb_gzwriter_flush(int argc, VALUE *argv, VALUE obj)
* Same as IO.
*/
static VALUE
-rb_gzwriter_write(VALUE obj, VALUE str)
+rb_gzwriter_write(obj, str)
+ VALUE obj, str;
{
struct gzfile *gz = get_gzfile(obj);
if (TYPE(str) != T_STRING) {
str = rb_obj_as_string(str);
}
- gzfile_write(gz, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
- return INT2FIX(RSTRING_LEN(str));
+ gzfile_write(gz, RSTRING(str)->ptr, RSTRING(str)->len);
+ return INT2FIX(RSTRING(str)->len);
}
/*
* Same as IO.
*/
static VALUE
-rb_gzwriter_putc(VALUE obj, VALUE ch)
+rb_gzwriter_putc(obj, ch)
+ VALUE obj, ch;
{
struct gzfile *gz = get_gzfile(obj);
char c = NUM2CHR(ch);
- gzfile_write(gz, (Bytef*)&c, 1);
+ gzfile_write(gz, &c, 1);
return ch;
}
@@ -2775,7 +2886,8 @@ rb_gzwriter_putc(VALUE obj, VALUE ch)
*/
static VALUE
-rb_gzreader_s_allocate(VALUE klass)
+rb_gzreader_s_allocate(klass)
+ VALUE klass;
{
return gzfile_reader_new(klass);
}
@@ -2788,7 +2900,10 @@ rb_gzreader_s_allocate(VALUE klass)
* are in Zlib::GzipReader.new and ZLib::GzipReader.wrap.
*/
static VALUE
-rb_gzreader_s_open(int argc, VALUE *argv, VALUE klass)
+rb_gzreader_s_open(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
return gzfile_s_open(argc, argv, klass, "rb");
}
@@ -2804,7 +2919,8 @@ rb_gzreader_s_open(int argc, VALUE *argv, VALUE klass)
* exception.
*/
static VALUE
-rb_gzreader_initialize(VALUE obj, VALUE io)
+rb_gzreader_initialize(obj, io)
+ VALUE obj, io;
{
struct gzfile *gz;
int err;
@@ -2828,7 +2944,8 @@ rb_gzreader_initialize(VALUE obj, VALUE io)
* object. The associated IO object needs to respond to the +seek+ method.
*/
static VALUE
-rb_gzreader_rewind(VALUE obj)
+rb_gzreader_rewind(obj)
+ VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
gzfile_reader_rewind(gz);
@@ -2840,7 +2957,8 @@ rb_gzreader_rewind(VALUE obj)
* +nil+ if the whole gzip file is not parsed yet.
*/
static VALUE
-rb_gzreader_unused(VALUE obj)
+rb_gzreader_unused(obj)
+ VALUE obj;
{
struct gzfile *gz;
Data_Get_Struct(obj, struct gzfile, gz);
@@ -2851,7 +2969,10 @@ rb_gzreader_unused(VALUE obj)
* See Zlib::GzipReader documentation for a description.
*/
static VALUE
-rb_gzreader_read(int argc, VALUE *argv, VALUE obj)
+rb_gzreader_read(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
VALUE vlen;
@@ -2870,45 +2991,18 @@ rb_gzreader_read(int argc, VALUE *argv, VALUE obj)
}
/*
- * call-seq:
- * gzipreader.readpartial(maxlen [, outbuf]) => string, outbuf
- *
- * Reads at most <i>maxlen</i> bytes from the gziped stream but
- * it blocks only if <em>gzipreader</em> has no data immediately available.
- * If the optional <i>outbuf</i> argument is present,
- * it must reference a String, which will receive the data.
- * It raises <code>EOFError</code> on end of file.
- */
-static VALUE
-rb_gzreader_readpartial(int argc, VALUE *argv, VALUE obj)
-{
- struct gzfile *gz = get_gzfile(obj);
- VALUE vlen, outbuf;
- int len;
-
- rb_scan_args(argc, argv, "11", &vlen, &outbuf);
-
- len = NUM2INT(vlen);
- if (len < 0) {
- rb_raise(rb_eArgError, "negative length %d given", len);
- }
- if (!NIL_P(outbuf))
- Check_Type(outbuf, T_STRING);
- return gzfile_readpartial(gz, len, outbuf);
-}
-
-/*
* See Zlib::GzipReader documentation for a description.
*/
static VALUE
-rb_gzreader_getc(VALUE obj)
+rb_gzreader_getc(obj)
+ VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
VALUE dst;
dst = gzfile_read(gz, 1);
if (!NIL_P(dst)) {
- dst = INT2FIX((unsigned int)(RSTRING_PTR(dst)[0]) & 0xff);
+ dst = INT2FIX((unsigned int)(RSTRING(dst)->ptr[0]) & 0xff);
}
return dst;
}
@@ -2917,7 +3011,8 @@ rb_gzreader_getc(VALUE obj)
* See Zlib::GzipReader documentation for a description.
*/
static VALUE
-rb_gzreader_readchar(VALUE obj)
+rb_gzreader_readchar(obj)
+ VALUE obj;
{
VALUE dst;
dst = rb_gzreader_getc(obj);
@@ -2931,7 +3026,8 @@ rb_gzreader_readchar(VALUE obj)
* See Zlib::GzipReader documentation for a description.
*/
static VALUE
-rb_gzreader_each_byte(VALUE obj)
+rb_gzreader_each_byte(obj)
+ VALUE obj;
{
VALUE c;
while (!NIL_P(c = rb_gzreader_getc(obj))) {
@@ -2944,7 +3040,8 @@ rb_gzreader_each_byte(VALUE obj)
* See Zlib::GzipReader documentation for a description.
*/
static VALUE
-rb_gzreader_ungetc(VALUE obj, VALUE ch)
+rb_gzreader_ungetc(obj, ch)
+ VALUE obj, ch;
{
struct gzfile *gz = get_gzfile(obj);
gzfile_ungetc(gz, NUM2CHR(ch));
@@ -2952,7 +3049,8 @@ rb_gzreader_ungetc(VALUE obj, VALUE ch)
}
static void
-gzreader_skip_linebreaks(struct gzfile *gz)
+gzreader_skip_linebreaks(gz)
+ struct gzfile *gz;
{
VALUE str;
char *p;
@@ -2963,7 +3061,7 @@ gzreader_skip_linebreaks(struct gzfile *gz)
gzfile_read_more(gz);
}
n = 0;
- p = RSTRING_PTR(gz->z.buf);
+ p = RSTRING(gz->z.buf)->ptr;
while (n++, *(p++) == '\n') {
if (n >= gz->z.buf_filled) {
@@ -2974,7 +3072,7 @@ gzreader_skip_linebreaks(struct gzfile *gz)
gzfile_read_more(gz);
}
n = 0;
- p = RSTRING_PTR(gz->z.buf);
+ p = RSTRING(gz->z.buf)->ptr;
}
}
@@ -2983,20 +3081,25 @@ gzreader_skip_linebreaks(struct gzfile *gz)
}
static void
-rscheck(const char *rsptr, long rslen, VALUE rs)
+rscheck(rsptr, rslen, rs)
+ char *rsptr;
+ long rslen;
+ VALUE rs;
{
- if (RSTRING_PTR(rs) != rsptr && RSTRING_LEN(rs) != rslen)
+ if (RSTRING(rs)->ptr != rsptr && RSTRING(rs)->len != rslen)
rb_raise(rb_eRuntimeError, "rs modified");
}
static VALUE
-gzreader_gets(int argc, VALUE *argv, VALUE obj)
+gzreader_gets(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
volatile VALUE rs;
VALUE dst;
- const char *rsptr;
- char *p, *res;
+ char *rsptr, *p, *res;
long rslen, n;
int rspara;
@@ -3012,17 +3115,19 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
if (NIL_P(rs)) {
dst = gzfile_read_all(gz);
- if (RSTRING_LEN(dst) != 0) gz->lineno++;
+ if (RSTRING(dst)->len != 0) gz->lineno++;
+ else
+ return Qnil;
return dst;
}
- if (RSTRING_LEN(rs) == 0) {
+ if (RSTRING(rs)->len == 0) {
rsptr = "\n\n";
rslen = 2;
rspara = 1;
} else {
- rsptr = RSTRING_PTR(rs);
- rslen = RSTRING_LEN(rs);
+ rsptr = RSTRING(rs)->ptr;
+ rslen = RSTRING(rs)->len;
rspara = 0;
}
@@ -3038,13 +3143,13 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
gzfile_read_more(gz);
}
- p = RSTRING_PTR(gz->z.buf);
+ p = RSTRING(gz->z.buf)->ptr;
n = rslen;
for (;;) {
if (n > gz->z.buf_filled) {
if (ZSTREAM_IS_FINISHED(&gz->z)) break;
gzfile_read_more(gz);
- p = RSTRING_PTR(gz->z.buf) + n - rslen;
+ p = RSTRING(gz->z.buf)->ptr + n - rslen;
}
if (!rspara) rscheck(rsptr, rslen, rs);
res = memchr(p, rsptr[0], (gz->z.buf_filled - n + 1));
@@ -3071,7 +3176,10 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
* See Zlib::GzipReader documentation for a description.
*/
static VALUE
-rb_gzreader_gets(int argc, VALUE *argv, VALUE obj)
+rb_gzreader_gets(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE dst;
dst = gzreader_gets(argc, argv, obj);
@@ -3085,7 +3193,10 @@ rb_gzreader_gets(int argc, VALUE *argv, VALUE obj)
* See Zlib::GzipReader documentation for a description.
*/
static VALUE
-rb_gzreader_readline(int argc, VALUE *argv, VALUE obj)
+rb_gzreader_readline(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE dst;
dst = rb_gzreader_gets(argc, argv, obj);
@@ -3099,7 +3210,10 @@ rb_gzreader_readline(int argc, VALUE *argv, VALUE obj)
* See Zlib::GzipReader documentation for a description.
*/
static VALUE
-rb_gzreader_each(int argc, VALUE *argv, VALUE obj)
+rb_gzreader_each(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE str;
while (!NIL_P(str = gzreader_gets(argc, argv, obj))) {
@@ -3112,7 +3226,10 @@ rb_gzreader_each(int argc, VALUE *argv, VALUE obj)
* See Zlib::GzipReader documentation for a description.
*/
static VALUE
-rb_gzreader_readlines(int argc, VALUE *argv, VALUE obj)
+rb_gzreader_readlines(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE str, dst;
dst = rb_ary_new();
@@ -3259,7 +3376,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, 0);
+ rb_define_method(cDeflate, "initialize_copy", rb_deflate_init_copy, 1);
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);
@@ -3298,7 +3415,6 @@ void Init_zlib()
#if GZIP_SUPPORT
id_write = rb_intern("write");
id_read = rb_intern("read");
- id_readpartial = rb_intern("readpartial");
id_flush = rb_intern("flush");
id_seek = rb_intern("seek");
id_close = rb_intern("close");
@@ -3357,7 +3473,6 @@ void Init_zlib()
rb_define_method(cGzipReader, "rewind", rb_gzreader_rewind, 0);
rb_define_method(cGzipReader, "unused", rb_gzreader_unused, 0);
rb_define_method(cGzipReader, "read", rb_gzreader_read, -1);
- rb_define_method(cGzipReader, "readpartial", rb_gzreader_readpartial, -1);
rb_define_method(cGzipReader, "getc", rb_gzreader_getc, 0);
rb_define_method(cGzipReader, "readchar", rb_gzreader_readchar, 0);
rb_define_method(cGzipReader, "each_byte", rb_gzreader_each_byte, 0);
diff --git a/file.c b/file.c
index 6018862d11..8e8dae3a97 100644
--- a/file.c
+++ b/file.c
@@ -15,12 +15,19 @@
#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>
@@ -29,7 +36,7 @@
#ifdef HAVE_SYS_FILE_H
# include <sys/file.h>
#else
-int flock(int, int);
+int flock _((int, int));
#endif
#ifdef HAVE_SYS_PARAM_H
@@ -39,11 +46,9 @@ int flock(int, int);
# define MAXPATHLEN 1024
#endif
-#include <ctype.h>
-
#include <time.h>
-VALUE rb_time_new(time_t, time_t);
+VALUE rb_time_new _((time_t, time_t));
#ifdef HAVE_UTIME_H
#include <utime.h>
@@ -55,6 +60,10 @@ VALUE rb_time_new(time_t, time_t);
#include <pwd.h>
#endif
+#ifndef HAVE_STRING_H
+char *strrchr _((const char*,const char));
+#endif
+
#include <sys/types.h>
#include <sys/stat.h>
@@ -65,6 +74,9 @@ VALUE rb_time_new(time_t, time_t);
#if !defined HAVE_LSTAT && !defined lstat
#define lstat stat
#endif
+#if !HAVE_FSEEKO && !defined(fseeko)
+# define fseeko fseek
+#endif
#ifdef __BEOS__ /* should not change ID if -1 */
static int
@@ -97,43 +109,24 @@ VALUE rb_cFile;
VALUE rb_mFileTest;
VALUE rb_cStat;
-VALUE
-rb_get_path(VALUE obj)
-{
- VALUE tmp;
- static ID to_path;
-
- rb_check_safe_obj(obj);
- tmp = rb_check_string_type(obj);
- if (!NIL_P(tmp)) goto exit;
-
- if (!to_path) {
- to_path = rb_intern("to_path");
- }
- if (rb_respond_to(obj, to_path)) {
- tmp = rb_funcall(obj, to_path, 0, 0);
- }
- exit:
- StringValueCStr(tmp);
- if (obj != tmp) {
- rb_check_safe_obj(tmp);
- }
- return tmp;
-}
-
+static long apply2files _((void (*)(const char *, void *), VALUE, void *));
static long
-apply2files(void (*func)(const char *, void *), VALUE vargs, void *arg)
+apply2files(func, vargs, arg)
+ void (*func)_((const char *, void *));
+ VALUE vargs;
+ void *arg;
{
long i;
VALUE path;
+ struct RArray *args = RARRAY(vargs);
- rb_secure(4);
- for (i=0; i<RARRAY_LEN(vargs); i++) {
- path = rb_get_path(RARRAY_PTR(vargs)[i]);
+ for (i=0; i<args->len; i++) {
+ path = args->ptr[i];
+ SafeStringValue(path);
(*func)(StringValueCStr(path), arg);
}
- return RARRAY_LEN(vargs);
+ return args->len;
}
/*
@@ -149,7 +142,8 @@ apply2files(void (*func)(const char *, void *), VALUE vargs, void *arg)
*/
static VALUE
-rb_file_path(VALUE obj)
+rb_file_path(obj)
+ VALUE obj;
{
OpenFile *fptr;
@@ -160,7 +154,9 @@ rb_file_path(VALUE obj)
}
static VALUE
-stat_new_0(VALUE klass, struct stat *st)
+stat_new_0(klass, st)
+ VALUE klass;
+ struct stat *st;
{
struct stat *nst = 0;
@@ -172,13 +168,15 @@ stat_new_0(VALUE klass, struct stat *st)
}
static VALUE
-stat_new(struct stat *st)
+stat_new(st)
+ struct stat *st;
{
return stat_new_0(rb_cStat, st);
}
static struct stat*
-get_stat(VALUE self)
+get_stat(self)
+ VALUE self;
{
struct stat* st;
Data_Get_Struct(self, struct stat, st);
@@ -200,7 +198,8 @@ get_stat(VALUE self)
*/
static VALUE
-rb_stat_cmp(VALUE self, VALUE other)
+rb_stat_cmp(self, other)
+ VALUE self, other;
{
if (rb_obj_is_kind_of(other, rb_obj_class(self))) {
time_t t1 = get_stat(self)->st_mtime;
@@ -215,6 +214,20 @@ rb_stat_cmp(VALUE self, VALUE other)
return Qnil;
}
+static VALUE rb_stat_dev _((VALUE));
+static VALUE rb_stat_ino _((VALUE));
+static VALUE rb_stat_mode _((VALUE));
+static VALUE rb_stat_nlink _((VALUE));
+static VALUE rb_stat_uid _((VALUE));
+static VALUE rb_stat_gid _((VALUE));
+static VALUE rb_stat_rdev _((VALUE));
+static VALUE rb_stat_size _((VALUE));
+static VALUE rb_stat_blksize _((VALUE));
+static VALUE rb_stat_blocks _((VALUE));
+static VALUE rb_stat_atime _((VALUE));
+static VALUE rb_stat_mtime _((VALUE));
+static VALUE rb_stat_ctime _((VALUE));
+
/*
* call-seq:
* stat.dev => fixnum
@@ -226,7 +239,8 @@ rb_stat_cmp(VALUE self, VALUE other)
*/
static VALUE
-rb_stat_dev(VALUE self)
+rb_stat_dev(self)
+ VALUE self;
{
return INT2NUM(get_stat(self)->st_dev);
}
@@ -243,7 +257,8 @@ rb_stat_dev(VALUE self)
*/
static VALUE
-rb_stat_dev_major(VALUE self)
+rb_stat_dev_major(self)
+ VALUE self;
{
#if defined(major)
long dev = get_stat(self)->st_dev;
@@ -265,7 +280,8 @@ rb_stat_dev_major(VALUE self)
*/
static VALUE
-rb_stat_dev_minor(VALUE self)
+rb_stat_dev_minor(self)
+ VALUE self;
{
#if defined(minor)
long dev = get_stat(self)->st_dev;
@@ -287,7 +303,8 @@ rb_stat_dev_minor(VALUE self)
*/
static VALUE
-rb_stat_ino(VALUE self)
+rb_stat_ino(self)
+ VALUE self;
{
#ifdef HUGE_ST_INO
return ULL2NUM(get_stat(self)->st_ino);
@@ -310,7 +327,8 @@ rb_stat_ino(VALUE self)
*/
static VALUE
-rb_stat_mode(VALUE self)
+rb_stat_mode(self)
+ VALUE self;
{
#ifdef __BORLANDC__
return UINT2NUM((unsigned short)(get_stat(self)->st_mode));
@@ -332,7 +350,8 @@ rb_stat_mode(VALUE self)
*/
static VALUE
-rb_stat_nlink(VALUE self)
+rb_stat_nlink(self)
+ VALUE self;
{
return UINT2NUM(get_stat(self)->st_nlink);
}
@@ -349,7 +368,8 @@ rb_stat_nlink(VALUE self)
*/
static VALUE
-rb_stat_uid(VALUE self)
+rb_stat_uid(self)
+ VALUE self;
{
return UINT2NUM(get_stat(self)->st_uid);
}
@@ -365,7 +385,8 @@ rb_stat_uid(VALUE self)
*/
static VALUE
-rb_stat_gid(VALUE self)
+rb_stat_gid(self)
+ VALUE self;
{
return UINT2NUM(get_stat(self)->st_gid);
}
@@ -384,7 +405,8 @@ rb_stat_gid(VALUE self)
*/
static VALUE
-rb_stat_rdev(VALUE self)
+rb_stat_rdev(self)
+ VALUE self;
{
#ifdef HAVE_ST_RDEV
return ULONG2NUM(get_stat(self)->st_rdev);
@@ -405,7 +427,8 @@ rb_stat_rdev(VALUE self)
*/
static VALUE
-rb_stat_rdev_major(VALUE self)
+rb_stat_rdev_major(self)
+ VALUE self;
{
#if defined(HAVE_ST_RDEV) && defined(major)
long rdev = get_stat(self)->st_rdev;
@@ -427,7 +450,8 @@ rb_stat_rdev_major(VALUE self)
*/
static VALUE
-rb_stat_rdev_minor(VALUE self)
+rb_stat_rdev_minor(self)
+ VALUE self;
{
#if defined(HAVE_ST_RDEV) && defined(minor)
long rdev = get_stat(self)->st_rdev;
@@ -447,7 +471,8 @@ rb_stat_rdev_minor(VALUE self)
*/
static VALUE
-rb_stat_size(VALUE self)
+rb_stat_size(self)
+ VALUE self;
{
return OFFT2NUM(get_stat(self)->st_size);
}
@@ -464,7 +489,8 @@ rb_stat_size(VALUE self)
*/
static VALUE
-rb_stat_blksize(VALUE self)
+rb_stat_blksize(self)
+ VALUE self;
{
#ifdef HAVE_ST_BLKSIZE
return ULONG2NUM(get_stat(self)->st_blksize);
@@ -485,7 +511,8 @@ rb_stat_blksize(VALUE self)
*/
static VALUE
-rb_stat_blocks(VALUE self)
+rb_stat_blocks(self)
+ VALUE self;
{
#ifdef HAVE_ST_BLOCKS
return ULONG2NUM(get_stat(self)->st_blocks);
@@ -507,7 +534,8 @@ rb_stat_blocks(VALUE self)
*/
static VALUE
-rb_stat_atime(VALUE self)
+rb_stat_atime(self)
+ VALUE self;
{
return rb_time_new(get_stat(self)->st_atime, 0);
}
@@ -523,7 +551,8 @@ rb_stat_atime(VALUE self)
*/
static VALUE
-rb_stat_mtime(VALUE self)
+rb_stat_mtime(self)
+ VALUE self;
{
return rb_time_new(get_stat(self)->st_mtime, 0);
}
@@ -541,7 +570,8 @@ rb_stat_mtime(VALUE self)
*/
static VALUE
-rb_stat_ctime(VALUE self)
+rb_stat_ctime(self)
+ VALUE self;
{
return rb_time_new(get_stat(self)->st_ctime, 0);
}
@@ -561,13 +591,14 @@ rb_stat_ctime(VALUE self)
*/
static VALUE
-rb_stat_inspect(VALUE self)
+rb_stat_inspect(self)
+ VALUE self;
{
VALUE str;
int i;
static const struct {
const char *name;
- VALUE (*func)(VALUE);
+ VALUE (*func)_((VALUE));
} member[] = {
{"dev", rb_stat_dev},
{"ino", rb_stat_ino},
@@ -620,25 +651,29 @@ rb_stat_inspect(VALUE self)
}
static int
-rb_stat(VALUE file, struct stat *st)
+rb_stat(file, st)
+ VALUE file;
+ struct stat *st;
{
VALUE tmp;
- rb_secure(2);
tmp = rb_check_convert_type(file, T_FILE, "IO", "to_io");
if (!NIL_P(tmp)) {
OpenFile *fptr;
+ rb_secure(2);
GetOpenFile(tmp, fptr);
- return fstat(fptr->fd, st);
+ return fstat(fileno(fptr->f), st);
}
- FilePathValue(file);
+ SafeStringValue(file);
return stat(StringValueCStr(file), st);
}
#ifdef _WIN32
static HANDLE
-w32_io_info(VALUE *file, BY_HANDLE_FILE_INFORMATION *st)
+w32_io_info(file, st)
+ VALUE *file;
+ BY_HANDLE_FILE_INFORMATION *st;
{
VALUE tmp;
HANDLE f, ret = 0;
@@ -648,11 +683,11 @@ w32_io_info(VALUE *file, BY_HANDLE_FILE_INFORMATION *st)
OpenFile *fptr;
GetOpenFile(tmp, fptr);
- f = (HANDLE)rb_w32_get_osfhandle(fptr->fd);
+ f = (HANDLE)rb_w32_get_osfhandle(fileno(fptr->f));
if (f == (HANDLE)-1) return INVALID_HANDLE_VALUE;
}
else {
- FilePathValue(*file);
+ SafeStringValue(*file);
f = CreateFile(StringValueCStr(*file), 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
rb_w32_iswin95() ? 0 : FILE_FLAG_BACKUP_SEMANTICS, NULL);
@@ -680,12 +715,12 @@ w32_io_info(VALUE *file, BY_HANDLE_FILE_INFORMATION *st)
*/
static VALUE
-rb_file_s_stat(VALUE klass, VALUE fname)
+rb_file_s_stat(klass, fname)
+ VALUE klass, fname;
{
struct stat st;
- rb_secure(4);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (rb_stat(fname, &st) < 0) {
rb_sys_fail(StringValueCStr(fname));
}
@@ -708,13 +743,14 @@ rb_file_s_stat(VALUE klass, VALUE fname)
*/
static VALUE
-rb_io_stat(VALUE obj)
+rb_io_stat(obj)
+ VALUE obj;
{
OpenFile *fptr;
struct stat st;
GetOpenFile(obj, fptr);
- if (fstat(fptr->fd, &st) == -1) {
+ if (fstat(fileno(fptr->f), &st) == -1) {
rb_sys_fail(fptr->path);
}
return stat_new(&st);
@@ -735,15 +771,15 @@ rb_io_stat(VALUE obj)
*/
static VALUE
-rb_file_s_lstat(VALUE klass, VALUE fname)
+rb_file_s_lstat(klass, fname)
+ VALUE klass, fname;
{
#ifdef HAVE_LSTAT
struct stat st;
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (lstat(StringValueCStr(fname), &st) == -1) {
- rb_sys_fail(RSTRING_PTR(fname));
+ rb_sys_fail(RSTRING(fname)->ptr);
}
return stat_new(&st);
#else
@@ -767,7 +803,8 @@ rb_file_s_lstat(VALUE klass, VALUE fname)
*/
static VALUE
-rb_file_lstat(VALUE obj)
+rb_file_lstat(obj)
+ VALUE obj;
{
#ifdef HAVE_LSTAT
OpenFile *fptr;
@@ -785,11 +822,13 @@ rb_file_lstat(VALUE obj)
#endif
}
+#ifndef HAVE_GROUP_MEMBER
static int
-group_member(GETGROUPS_T gid)
+group_member(gid)
+ GETGROUPS_T gid;
{
#ifndef _WIN32
- if (getgid() == gid)
+ if (getgid() == gid || getegid() == gid)
return Qtrue;
# ifdef HAVE_GETGROUPS
@@ -813,6 +852,7 @@ group_member(GETGROUPS_T gid)
#endif
return Qfalse;
}
+#endif
#ifndef S_IXUGO
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
@@ -824,7 +864,9 @@ group_member(GETGROUPS_T gid)
#ifndef HAVE_EACCESS
int
-eaccess(const char *path, int mode)
+eaccess(path, mode)
+ const char *path;
+ int mode;
{
#ifdef USE_GETEUID
struct stat st;
@@ -849,7 +891,7 @@ eaccess(const char *path, int mode)
if (st.st_uid == euid) /* owner */
mode <<= 6;
- else if (getegid() == st.st_gid || group_member(st.st_gid))
+ else if (group_member(st.st_gid))
mode <<= 3;
if ((st.st_mode & mode) == mode) return 0;
@@ -887,7 +929,8 @@ eaccess(const char *path, int mode)
*/
static VALUE
-test_d(VALUE obj, VALUE fname)
+test_d(obj, fname)
+ VALUE obj, fname;
{
#ifndef S_ISDIR
# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
@@ -908,7 +951,8 @@ test_d(VALUE obj, VALUE fname)
*/
static VALUE
-test_p(VALUE obj, VALUE fname)
+test_p(obj, fname)
+ VALUE obj, fname;
{
#ifdef S_IFIFO
# ifndef S_ISFIFO
@@ -932,11 +976,20 @@ test_p(VALUE obj, VALUE fname)
*/
static VALUE
-test_l(VALUE obj, VALUE fname)
+test_l(obj, fname)
+ VALUE obj, fname;
{
#ifndef S_ISLNK
# ifdef _S_ISLNK
# define S_ISLNK(m) _S_ISLNK(m)
+# elif defined __BORLANDC__
+# ifdef _S_IFLNK
+# define S_ISLNK(m) (((unsigned short)(m) & S_IFMT) == _S_IFLNK)
+# else
+# ifdef S_IFLNK
+# define S_ISLNK(m) (((unsigned short)(m) & S_IFMT) == S_IFLNK)
+# endif
+# endif
# else
# ifdef _S_IFLNK
# define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
@@ -951,8 +1004,7 @@ test_l(VALUE obj, VALUE fname)
#ifdef S_ISLNK
struct stat st;
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (lstat(StringValueCStr(fname), &st) < 0) return Qfalse;
if (S_ISLNK(st.st_mode)) return Qtrue;
#endif
@@ -968,11 +1020,20 @@ test_l(VALUE obj, VALUE fname)
*/
static VALUE
-test_S(VALUE obj, VALUE fname)
+test_S(obj, fname)
+ VALUE obj, fname;
{
#ifndef S_ISSOCK
# ifdef _S_ISSOCK
# define S_ISSOCK(m) _S_ISSOCK(m)
+# elif defined __BORLANDC__
+# ifdef _S_IFSOCK
+# define S_ISSOCK(m) (((unsigned short)(m) & S_IFMT) == _S_IFSOCK)
+# else
+# ifdef S_IFSOCK
+# define S_ISSOCK(m) (((unsigned short)(m) & S_IFMT) == S_IFSOCK)
+# endif
+# endif
# else
# ifdef _S_IFSOCK
# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
@@ -1002,7 +1063,8 @@ test_S(VALUE obj, VALUE fname)
*/
static VALUE
-test_b(VALUE obj, VALUE fname)
+test_b(obj, fname)
+ VALUE obj, fname;
{
#ifndef S_ISBLK
# ifdef S_IFBLK
@@ -1029,7 +1091,8 @@ test_b(VALUE obj, VALUE fname)
* Returns <code>true</code> if the named file is a character device.
*/
static VALUE
-test_c(VALUE obj, VALUE fname)
+test_c(obj, fname)
+ VALUE obj, fname;
{
#ifndef S_ISCHR
# define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
@@ -1053,7 +1116,8 @@ test_c(VALUE obj, VALUE fname)
*/
static VALUE
-test_e(VALUE obj, VALUE fname)
+test_e(obj, fname)
+ VALUE obj, fname;
{
struct stat st;
@@ -1070,10 +1134,10 @@ test_e(VALUE obj, VALUE fname)
*/
static VALUE
-test_r(VALUE obj, VALUE fname)
+test_r(obj, fname)
+ VALUE obj, fname;
{
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (eaccess(StringValueCStr(fname), R_OK) < 0) return Qfalse;
return Qtrue;
}
@@ -1087,49 +1151,14 @@ test_r(VALUE obj, VALUE fname)
*/
static VALUE
-test_R(VALUE obj, VALUE fname)
+test_R(obj, fname)
+ VALUE obj, fname;
{
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (access(StringValueCStr(fname), R_OK) < 0) return Qfalse;
return Qtrue;
}
-#ifndef S_IRUGO
-# define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH)
-#endif
-
-#ifndef S_IWUGO
-# define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH)
-#endif
-
-/*
- * call-seq:
- * File.world_readable?(file_name) => fixnum or nil
- *
- * If <i>file_name</i> is readable by others, returns an integer
- * representing the file permission bits of <i>file_name</i>. Returns
- * <code>nil</code> otherwise. The meaning of the bits is platform
- * dependent; on Unix systems, see <code>stat(2)</code>.
- *
- * File.world_readable?("/etc/passwd") # => 420
- * m = File.world_readable?("/etc/passwd")
- * sprintf("%o", m) # => "644"
- */
-
-static VALUE
-test_wr(VALUE obj, VALUE fname)
-{
-#ifdef S_IROTH
- struct stat st;
-
- if (rb_stat(fname, &st) < 0) return Qnil;
- if ((st.st_mode & (S_IROTH)) == S_IROTH) {
- return UINT2NUM(st.st_mode & (S_IRUGO|S_IWUGO|S_IXUGO));
- }
-#endif
- return Qnil;
-}
/*
* call-seq:
@@ -1140,10 +1169,10 @@ test_wr(VALUE obj, VALUE fname)
*/
static VALUE
-test_w(VALUE obj, VALUE fname)
+test_w(obj, fname)
+ VALUE obj, fname;
{
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (eaccess(StringValueCStr(fname), W_OK) < 0) return Qfalse;
return Qtrue;
}
@@ -1157,44 +1186,16 @@ test_w(VALUE obj, VALUE fname)
*/
static VALUE
-test_W(VALUE obj, VALUE fname)
+test_W(obj, fname)
+ VALUE obj, fname;
{
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (access(StringValueCStr(fname), W_OK) < 0) return Qfalse;
return Qtrue;
}
/*
* call-seq:
- * File.world_writable?(file_name) => fixnum or nil
- *
- * If <i>file_name</i> is writable by others, returns an integer
- * representing the file permission bits of <i>file_name</i>. Returns
- * <code>nil</code> otherwise. The meaning of the bits is platform
- * dependent; on Unix systems, see <code>stat(2)</code>.
- *
- * File.world_writable?("/tmp") #=> 511
- * m = File.world_writable?("/tmp")
- * sprintf("%o", m) #=> "777"
- */
-
-static VALUE
-test_ww(VALUE obj, VALUE fname)
-{
-#ifdef S_IWOTH
- struct stat st;
-
- if (rb_stat(fname, &st) < 0) return Qfalse;
- if ((st.st_mode & (S_IWOTH)) == S_IWOTH) {
- return UINT2NUM(st.st_mode & (S_IRUGO|S_IWUGO|S_IXUGO));
- }
-#endif
- return Qnil;
-}
-
-/*
- * call-seq:
* File.executable?(file_name) => true or false
*
* Returns <code>true</code> if the named file is executable by the effective
@@ -1202,10 +1203,10 @@ test_ww(VALUE obj, VALUE fname)
*/
static VALUE
-test_x(VALUE obj, VALUE fname)
+test_x(obj, fname)
+ VALUE obj, fname;
{
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (eaccess(StringValueCStr(fname), X_OK) < 0) return Qfalse;
return Qtrue;
}
@@ -1219,10 +1220,10 @@ test_x(VALUE obj, VALUE fname)
*/
static VALUE
-test_X(VALUE obj, VALUE fname)
+test_X(obj, fname)
+ VALUE obj, fname;
{
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (access(StringValueCStr(fname), X_OK) < 0) return Qfalse;
return Qtrue;
}
@@ -1240,7 +1241,8 @@ test_X(VALUE obj, VALUE fname)
*/
static VALUE
-test_f(VALUE obj, VALUE fname)
+test_f(obj, fname)
+ VALUE obj, fname;
{
struct stat st;
@@ -1258,7 +1260,8 @@ test_f(VALUE obj, VALUE fname)
*/
static VALUE
-test_z(VALUE obj, VALUE fname)
+test_z(obj, fname)
+ VALUE obj, fname;
{
struct stat st;
@@ -1276,7 +1279,8 @@ test_z(VALUE obj, VALUE fname)
*/
static VALUE
-test_s(VALUE obj, VALUE fname)
+test_s(obj, fname)
+ VALUE obj, fname;
{
struct stat st;
@@ -1295,7 +1299,8 @@ test_s(VALUE obj, VALUE fname)
*/
static VALUE
-test_owned(VALUE obj, VALUE fname)
+test_owned(obj, fname)
+ VALUE obj, fname;
{
struct stat st;
@@ -1305,7 +1310,8 @@ test_owned(VALUE obj, VALUE fname)
}
static VALUE
-test_rowned(VALUE obj, VALUE fname)
+test_rowned(obj, fname)
+ VALUE obj, fname;
{
struct stat st;
@@ -1324,25 +1330,27 @@ test_rowned(VALUE obj, VALUE fname)
*/
static VALUE
-test_grpowned(VALUE obj, VALUE fname)
+test_grpowned(obj, fname)
+ VALUE obj, fname;
{
#ifndef _WIN32
struct stat st;
if (rb_stat(fname, &st) < 0) return Qfalse;
- if (st.st_gid == getegid()) return Qtrue;
+ if (group_member(st.st_gid)) return Qtrue;
#endif
return Qfalse;
}
#if defined(S_ISUID) || defined(S_ISGID) || defined(S_ISVTX)
static VALUE
-check3rdbyte(VALUE fname, int mode)
+check3rdbyte(fname, mode)
+ VALUE fname;
+ int mode;
{
struct stat st;
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (stat(StringValueCStr(fname), &st) < 0) return Qfalse;
if (st.st_mode & mode) return Qtrue;
return Qfalse;
@@ -1357,7 +1365,8 @@ check3rdbyte(VALUE fname, int mode)
*/
static VALUE
-test_suid(VALUE obj, VALUE fname)
+test_suid(obj, fname)
+ VALUE obj, fname;
{
#ifdef S_ISUID
return check3rdbyte(fname, S_ISUID);
@@ -1374,7 +1383,8 @@ test_suid(VALUE obj, VALUE fname)
*/
static VALUE
-test_sgid(VALUE obj, VALUE fname)
+test_sgid(obj, fname)
+ VALUE obj, fname;
{
#ifdef S_ISGID
return check3rdbyte(fname, S_ISGID);
@@ -1391,7 +1401,8 @@ test_sgid(VALUE obj, VALUE fname)
*/
static VALUE
-test_sticky(VALUE obj, VALUE fname)
+test_sticky(obj, fname)
+ VALUE obj, fname;
{
#ifdef S_ISVTX
return check3rdbyte(fname, S_ISVTX);
@@ -1418,7 +1429,8 @@ test_sticky(VALUE obj, VALUE fname)
*/
static VALUE
-test_identical(VALUE obj, VALUE fname1, VALUE fname2)
+test_identical(obj, fname1, fname2)
+ VALUE obj, fname1, fname2;
{
#ifndef DOSISH
struct stat st1, st2;
@@ -1449,16 +1461,16 @@ test_identical(VALUE obj, VALUE fname1, VALUE fname2)
if (!f1 || !f2) return Qfalse;
if (rb_w32_iswin95()) return Qfalse;
#else
- FilePathValue(fname1);
+ SafeStringValue(fname1);
fname1 = rb_str_new4(fname1);
- FilePathValue(fname2);
- if (access(RSTRING_PTR(fname1), 0)) return Qfalse;
- if (access(RSTRING_PTR(fname2), 0)) return Qfalse;
+ SafeStringValue(fname2);
+ if (access(RSTRING(fname1)->ptr, 0)) return Qfalse;
+ if (access(RSTRING(fname2)->ptr, 0)) return Qfalse;
#endif
fname1 = rb_file_expand_path(fname1, Qnil);
fname2 = rb_file_expand_path(fname2, Qnil);
- if (RSTRING_LEN(fname1) != RSTRING_LEN(fname2)) return Qfalse;
- if (rb_memcicmp(RSTRING_PTR(fname1), RSTRING_PTR(fname2), RSTRING_LEN(fname1)))
+ if (RSTRING(fname1)->len != RSTRING(fname2)->len) return Qfalse;
+ if (rb_memcicmp(RSTRING(fname1)->ptr, RSTRING(fname2)->ptr, RSTRING(fname1)->len))
return Qfalse;
#endif
return Qtrue;
@@ -1472,7 +1484,8 @@ test_identical(VALUE obj, VALUE fname1, VALUE fname2)
*/
static VALUE
-rb_file_s_size(VALUE klass, VALUE fname)
+rb_file_s_size(klass, fname)
+ VALUE klass, fname;
{
struct stat st;
@@ -1482,9 +1495,10 @@ rb_file_s_size(VALUE klass, VALUE fname)
}
static VALUE
-rb_file_ftype(const struct stat *st)
+rb_file_ftype(st)
+ struct stat *st;
{
- const char *t;
+ char *t;
if (S_ISREG(st->st_mode)) {
t = "file";
@@ -1538,14 +1552,14 @@ rb_file_ftype(const struct stat *st)
*/
static VALUE
-rb_file_s_ftype(VALUE klass, VALUE fname)
+rb_file_s_ftype(klass, fname)
+ VALUE klass, fname;
{
struct stat st;
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (lstat(StringValueCStr(fname), &st) == -1) {
- rb_sys_fail(RSTRING_PTR(fname));
+ rb_sys_fail(RSTRING(fname)->ptr);
}
return rb_file_ftype(&st);
@@ -1562,7 +1576,8 @@ rb_file_s_ftype(VALUE klass, VALUE fname)
*/
static VALUE
-rb_file_s_atime(VALUE klass, VALUE fname)
+rb_file_s_atime(klass, fname)
+ VALUE klass, fname;
{
struct stat st;
@@ -1583,13 +1598,14 @@ rb_file_s_atime(VALUE klass, VALUE fname)
*/
static VALUE
-rb_file_atime(VALUE obj)
+rb_file_atime(obj)
+ VALUE obj;
{
OpenFile *fptr;
struct stat st;
GetOpenFile(obj, fptr);
- if (fstat(fptr->fd, &st) == -1) {
+ if (fstat(fileno(fptr->f), &st) == -1) {
rb_sys_fail(fptr->path);
}
return rb_time_new(st.st_atime, 0);
@@ -1606,12 +1622,13 @@ rb_file_atime(VALUE obj)
*/
static VALUE
-rb_file_s_mtime(VALUE klass, VALUE fname)
+rb_file_s_mtime(klass, fname)
+ VALUE klass, fname;
{
struct stat st;
if (rb_stat(fname, &st) < 0)
- rb_sys_fail(RSTRING_PTR(fname));
+ rb_sys_fail(RSTRING(fname)->ptr);
return rb_time_new(st.st_mtime, 0);
}
@@ -1626,13 +1643,14 @@ rb_file_s_mtime(VALUE klass, VALUE fname)
*/
static VALUE
-rb_file_mtime(VALUE obj)
+rb_file_mtime(obj)
+ VALUE obj;
{
OpenFile *fptr;
struct stat st;
GetOpenFile(obj, fptr);
- if (fstat(fptr->fd, &st) == -1) {
+ if (fstat(fileno(fptr->f), &st) == -1) {
rb_sys_fail(fptr->path);
}
return rb_time_new(st.st_mtime, 0);
@@ -1651,12 +1669,13 @@ rb_file_mtime(VALUE obj)
*/
static VALUE
-rb_file_s_ctime(VALUE klass, VALUE fname)
+rb_file_s_ctime(klass, fname)
+ VALUE klass, fname;
{
struct stat st;
if (rb_stat(fname, &st) < 0)
- rb_sys_fail(RSTRING_PTR(fname));
+ rb_sys_fail(RSTRING(fname)->ptr);
return rb_time_new(st.st_ctime, 0);
}
@@ -1672,20 +1691,24 @@ rb_file_s_ctime(VALUE klass, VALUE fname)
*/
static VALUE
-rb_file_ctime(VALUE obj)
+rb_file_ctime(obj)
+ VALUE obj;
{
OpenFile *fptr;
struct stat st;
GetOpenFile(obj, fptr);
- if (fstat(fptr->fd, &st) == -1) {
+ if (fstat(fileno(fptr->f), &st) == -1) {
rb_sys_fail(fptr->path);
}
return rb_time_new(st.st_ctime, 0);
}
+static void chmod_internal _((const char *, void *));
static void
-chmod_internal(const char *path, void *mode)
+chmod_internal(path, mode)
+ const char *path;
+ void *mode;
{
if (chmod(path, *(int *)mode) < 0)
rb_sys_fail(path);
@@ -1705,7 +1728,9 @@ chmod_internal(const char *path, void *mode)
*/
static VALUE
-rb_file_s_chmod(int argc, VALUE *argv)
+rb_file_s_chmod(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE vmode;
VALUE rest;
@@ -1734,7 +1759,8 @@ rb_file_s_chmod(int argc, VALUE *argv)
*/
static VALUE
-rb_file_chmod(VALUE obj, VALUE vmode)
+rb_file_chmod(obj, vmode)
+ VALUE obj, vmode;
{
OpenFile *fptr;
int mode;
@@ -1744,7 +1770,7 @@ rb_file_chmod(VALUE obj, VALUE vmode)
GetOpenFile(obj, fptr);
#ifdef HAVE_FCHMOD
- if (fchmod(fptr->fd, mode) == -1)
+ if (fchmod(fileno(fptr->f), mode) == -1)
rb_sys_fail(fptr->path);
#else
if (!fptr->path) return Qnil;
@@ -1756,8 +1782,11 @@ rb_file_chmod(VALUE obj, VALUE vmode)
}
#if defined(HAVE_LCHMOD)
+static void lchmod_internal _((const char *, void *));
static void
-lchmod_internal(const char *path, void *mode)
+lchmod_internal(path, mode)
+ const char *path;
+ void *mode;
{
if (lchmod(path, (int)mode) < 0)
rb_sys_fail(path);
@@ -1774,7 +1803,9 @@ lchmod_internal(const char *path, void *mode)
*/
static VALUE
-rb_file_s_lchmod(int argc, VALUE *argv)
+rb_file_s_lchmod(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE vmode;
VALUE rest;
@@ -1789,7 +1820,9 @@ rb_file_s_lchmod(int argc, VALUE *argv)
}
#else
static VALUE
-rb_file_s_lchmod(int argc, VALUE *argv)
+rb_file_s_lchmod(argc, argv)
+ int argc;
+ VALUE *argv;
{
rb_notimplement();
return Qnil; /* not reached */
@@ -1800,10 +1833,13 @@ struct chown_args {
int owner, group;
};
+static void chown_internal _((const char *, void *));
static void
-chown_internal(const char *path, void *arg)
+chown_internal(path, argp)
+ const char *path;
+ void *argp;
{
- struct chown_args *args = arg;
+ struct chown_args *args = (struct chown_args *)argp;
if (chown(path, args->owner, args->group) < 0)
rb_sys_fail(path);
}
@@ -1824,7 +1860,9 @@ chown_internal(const char *path, void *arg)
*/
static VALUE
-rb_file_s_chown(int argc, VALUE *argv)
+rb_file_s_chown(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE o, g, rest;
struct chown_args arg;
@@ -1865,7 +1903,8 @@ rb_file_s_chown(int argc, VALUE *argv)
*/
static VALUE
-rb_file_chown(VALUE obj, VALUE owner, VALUE group)
+rb_file_chown(obj, owner, group)
+ VALUE obj, owner, group;
{
OpenFile *fptr;
int o, g;
@@ -1879,7 +1918,7 @@ rb_file_chown(VALUE obj, VALUE owner, VALUE group)
if (chown(fptr->path, o, g) == -1)
rb_sys_fail(fptr->path);
#else
- if (fchown(fptr->fd, o, g) == -1)
+ if (fchown(fileno(fptr->f), o, g) == -1)
rb_sys_fail(fptr->path);
#endif
@@ -1887,10 +1926,13 @@ rb_file_chown(VALUE obj, VALUE owner, VALUE group)
}
#if defined(HAVE_LCHOWN) && !defined(__CHECKER__)
+static void lchown_internal _((const char *, void *));
static void
-lchown_internal(const char *path, void *arg)
+lchown_internal(path, argp)
+ const char *path;
+ void *argp;
{
- struct chown_args *args = arg;
+ struct chown_args *args = (struct chown_args *)argp;
if (lchown(path, args->owner, args->group) < 0)
rb_sys_fail(path);
}
@@ -1908,7 +1950,9 @@ lchown_internal(const char *path, void *arg)
*/
static VALUE
-rb_file_s_lchown(int argc, VALUE *argv)
+rb_file_s_lchown(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE o, g, rest;
struct chown_args arg;
@@ -1934,18 +1978,24 @@ rb_file_s_lchown(int argc, VALUE *argv)
}
#else
static VALUE
-rb_file_s_lchown(int argc, VALUE *argv)
+rb_file_s_lchown(argc, argv)
+ int argc;
+ VALUE *argv;
{
rb_notimplement();
}
#endif
-struct timeval rb_time_timeval(VALUE time);
+struct timeval rb_time_timeval();
+
+static void utime_internal _((const char *, void *));
#if defined(HAVE_UTIMES) && !defined(__CHECKER__)
static void
-utime_internal(const char *path, void *arg)
+utime_internal(path, arg)
+ const char *path;
+ void *arg;
{
struct timeval *tvp = arg;
if (utimes(path, tvp) < 0)
@@ -1962,16 +2012,21 @@ utime_internal(const char *path, void *arg)
*/
static VALUE
-rb_file_s_utime(int argc, VALUE *argv)
+rb_file_s_utime(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE atime, mtime, rest;
- struct timeval tvp[2];
+ struct timeval tvs[2], *tvp = NULL;
long n;
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
- tvp[0] = rb_time_timeval(atime);
- tvp[1] = rb_time_timeval(mtime);
+ if (!NIL_P(atime) || !NIL_P(mtime)) {
+ tvp = tvs;
+ tvp[0] = rb_time_timeval(atime);
+ tvp[1] = rb_time_timeval(mtime);
+ }
n = apply2files(utime_internal, rest, tvp);
return LONG2FIX(n);
@@ -1987,7 +2042,9 @@ struct utimbuf {
#endif
static void
-utime_internal(const char *path, void *arg)
+utime_internal(path, arg)
+ const char *path;
+ void *arg;
{
struct utimbuf *utp = arg;
if (utime(path, utp) < 0)
@@ -1995,36 +2052,42 @@ utime_internal(const char *path, void *arg)
}
static VALUE
-rb_file_s_utime(int argc, VALUE *argv)
+rb_file_s_utime(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE atime, mtime, rest;
long n;
struct timeval tv;
- struct utimbuf utbuf;
+ struct utimbuf utbuf, *utp = NULL;
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
- tv = rb_time_timeval(atime);
- utbuf.actime = tv.tv_sec;
- tv = rb_time_timeval(mtime);
- utbuf.modtime = tv.tv_sec;
+ if (!NIL_P(atime) || !NIL_P(mtime)) {
+ utp = &utbuf;
+ tv = rb_time_timeval(atime);
+ utp->actime = tv.tv_sec;
+ tv = rb_time_timeval(mtime);
+ utp->modtime = tv.tv_sec;
+ }
- n = apply2files(utime_internal, rest, &utbuf);
+ n = apply2files(utime_internal, rest, utp);
return LONG2FIX(n);
}
#endif
-NORETURN(static void sys_fail2(VALUE,VALUE));
+NORETURN(static void sys_fail2 _((VALUE,VALUE)));
static void
-sys_fail2(VALUE s1, VALUE s2)
+sys_fail2(s1, s2)
+ VALUE s1, s2;
{
char *buf;
int len;
- len = RSTRING_LEN(s1) + RSTRING_LEN(s2) + 5;
+ len = RSTRING(s1)->len + RSTRING(s2)->len + 5;
buf = ALLOCA_N(char, len);
- snprintf(buf, len, "(%s, %s)", RSTRING_PTR(s1), RSTRING_PTR(s2));
+ snprintf(buf, len, "%s or %s", RSTRING(s1)->ptr, RSTRING(s2)->ptr);
rb_sys_fail(buf);
}
@@ -2041,12 +2104,12 @@ sys_fail2(VALUE s1, VALUE s2)
*/
static VALUE
-rb_file_s_link(VALUE klass, VALUE from, VALUE to)
+rb_file_s_link(klass, from, to)
+ VALUE klass, from, to;
{
#ifdef HAVE_LINK
- rb_secure(2);
- FilePathValue(from);
- FilePathValue(to);
+ SafeStringValue(from);
+ SafeStringValue(to);
if (link(StringValueCStr(from), StringValueCStr(to)) < 0) {
sys_fail2(from, to);
@@ -2071,12 +2134,12 @@ rb_file_s_link(VALUE klass, VALUE from, VALUE to)
*/
static VALUE
-rb_file_s_symlink(VALUE klass, VALUE from, VALUE to)
+rb_file_s_symlink(klass, from, to)
+ VALUE klass, from, to;
{
#ifdef HAVE_SYMLINK
- rb_secure(2);
- FilePathValue(from);
- FilePathValue(to);
+ SafeStringValue(from);
+ SafeStringValue(to);
if (symlink(StringValueCStr(from), StringValueCStr(to)) < 0) {
sys_fail2(from, to);
@@ -2100,7 +2163,8 @@ rb_file_s_symlink(VALUE klass, VALUE from, VALUE to)
*/
static VALUE
-rb_file_s_readlink(VALUE klass, VALUE path)
+rb_file_s_readlink(klass, path)
+ VALUE klass, path;
{
#ifdef HAVE_READLINK
char *buf;
@@ -2108,10 +2172,9 @@ rb_file_s_readlink(VALUE klass, VALUE path)
int rv;
VALUE v;
- rb_secure(2);
- FilePathValue(path);
+ SafeStringValue(path);
buf = xmalloc(size);
- while ((rv = readlink(RSTRING_PTR(path), buf, size)) == size
+ while ((rv = readlink(RSTRING(path)->ptr, buf, size)) == size
#ifdef _AIX
|| (rv < 0 && errno == ERANGE) /* quirky behavior of GPFS */
#endif
@@ -2121,7 +2184,7 @@ rb_file_s_readlink(VALUE klass, VALUE path)
}
if (rv < 0) {
free(buf);
- rb_sys_fail(RSTRING_PTR(path));
+ rb_sys_fail(RSTRING(path)->ptr);
}
v = rb_tainted_str_new(buf, rv);
free(buf);
@@ -2133,8 +2196,11 @@ rb_file_s_readlink(VALUE klass, VALUE path)
#endif
}
+static void unlink_internal _((const char *, void *));
static void
-unlink_internal(const char *path, void *arg)
+unlink_internal(path, arg)
+ const char *path;
+ void *arg;
{
if (unlink(path) < 0)
rb_sys_fail(path);
@@ -2151,7 +2217,8 @@ unlink_internal(const char *path, void *arg)
*/
static VALUE
-rb_file_s_unlink(VALUE klass, VALUE args)
+rb_file_s_unlink(klass, args)
+ VALUE klass, args;
{
long n;
@@ -2171,31 +2238,25 @@ rb_file_s_unlink(VALUE klass, VALUE args)
*/
static VALUE
-rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
+rb_file_s_rename(klass, from, to)
+ VALUE klass, from, to;
{
const char *src, *dst;
+ SafeStringValue(from);
+ SafeStringValue(to);
- rb_secure(2);
- FilePathValue(from);
- FilePathValue(to);
src = StringValueCStr(from);
dst = StringValueCStr(to);
#if defined __CYGWIN__
errno = 0;
#endif
if (rename(src, dst) < 0) {
-#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 DOSISH && !defined _WIN32
+ switch (errno) {
+ case EEXIST:
#if defined (__EMX__)
- || errno == EACCES
+ case EACCES:
#endif
- ) {
if (chmod(dst, 0666) == 0 &&
unlink(dst) == 0 &&
rename(src, dst) == 0)
@@ -2224,7 +2285,9 @@ rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
*/
static VALUE
-rb_file_s_umask(int argc, VALUE *argv)
+rb_file_s_umask(argc, argv)
+ int argc;
+ VALUE *argv;
{
int omask = 0;
@@ -2242,29 +2305,41 @@ rb_file_s_umask(int argc, VALUE *argv)
return INT2FIX(omask);
}
-#if defined DOSISH
+#ifdef __CYGWIN__
+#undef DOSISH
+#endif
+#if defined __CYGWIN__ || 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, RUBY_MBCHAR_MAXSIZE))
+# define CharNext(p) ((p) + mblen(p, MB_CUR_MAX))
# else
# define CharNext(p) ((p) + 1)
# endif
#endif
-#ifdef __CYGWIN__
-#undef DOSISH
-#define DOSISH_UNC
-#define DOSISH_DRIVE_LETTER
-#endif
-
#ifdef DOSISH_DRIVE_LETTER
static inline int
-has_drive_letter(const char *buf)
+has_drive_letter(buf)
+ const char *buf;
{
if (ISALPHA(buf[0]) && buf[1] == ':') {
return 1;
@@ -2275,7 +2350,8 @@ has_drive_letter(const char *buf)
}
static char*
-getcwdofdrv(int drv)
+getcwdofdrv(drv)
+ int drv;
{
char drive[4];
char *drvcwd, *oldcwd;
@@ -2303,7 +2379,8 @@ getcwdofdrv(int drv)
#endif
static inline char *
-skiproot(const char *path)
+skiproot(path)
+ const char *path;
{
#ifdef DOSISH_DRIVE_LETTER
if (has_drive_letter(path)) path += 2;
@@ -2314,7 +2391,8 @@ skiproot(const char *path)
#define nextdirsep rb_path_next
char *
-rb_path_next(const char *s)
+rb_path_next(s)
+ const char *s;
{
while (*s && !isdirsep(*s)) {
s = CharNext(s);
@@ -2328,7 +2406,8 @@ rb_path_next(const char *s)
#define skipprefix(path) (path)
#endif
char *
-rb_path_skip_prefix(const char *path)
+rb_path_skip_prefix(path)
+ const char *path;
{
#if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER)
#ifdef DOSISH_UNC
@@ -2350,7 +2429,8 @@ rb_path_skip_prefix(const char *path)
#define strrdirsep rb_path_last_separator
char *
-rb_path_last_separator(const char *path)
+rb_path_last_separator(path)
+ const char *path;
{
char *last = NULL;
while (*path) {
@@ -2368,7 +2448,8 @@ rb_path_last_separator(const char *path)
}
static char *
-chompdirsep(const char *path)
+chompdirsep(path)
+ const char *path;
{
while (*path) {
if (isdirsep(*path)) {
@@ -2384,42 +2465,69 @@ chompdirsep(const char *path)
}
char *
-rb_path_end(const char *path)
+rb_path_end(path)
+ const char *path;
{
if (isdirsep(*path)) 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;\
- while (cond) {\
- buflen *= 2;\
+ if (cond) {\
+ do {buflen *= 2;} while (cond);\
+ rb_str_resize(result, buflen);\
+ buf = RSTRING(result)->ptr;\
+ p = buf + bdiff;\
+ pend = buf + buflen;\
}\
- rb_str_resize(result, buflen);\
- buf = RSTRING_PTR(result);\
- p = buf + bdiff;\
- pend = buf + buflen;\
} while (0)
#define BUFINIT() (\
- p = buf = RSTRING_PTR(result),\
- buflen = RSTRING_LEN(result),\
+ p = buf = RSTRING(result)->ptr,\
+ buflen = RSTRING(result)->len,\
pend = p + buflen)
#if !defined(TOLOWER)
#define TOLOWER(c) (ISUPPER(c) ? tolower(c) : (c))
#endif
-static int is_absolute_path(const char*);
+static int is_absolute_path _((const char*));
static VALUE
-file_expand_path(VALUE fname, VALUE dname, VALUE result)
+file_expand_path(fname, dname, result)
+ VALUE fname, dname, result;
{
- char *s, *buf, *b, *p, *pend, *root;
+ const char *s, *b;
+ char *buf, *p, *pend, *root;
long buflen, dirlen;
int tainted;
- FilePathValue(fname);
s = StringValuePtr(fname);
BUFINIT();
tainted = OBJ_TAINTED(fname);
@@ -2557,15 +2665,21 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result)
case '.':
if (*(s+1) == '\0' || isdirsep(*(s+1))) {
/* We must go back to the parent */
+ char *n;
*p = '\0';
- if (!(b = strrdirsep(root))) {
+ if (!(n = strrdirsep(root))) {
*p = '/';
}
else {
- p = b;
+ p = n;
}
b = ++s;
}
+#if USE_NTFS
+ else {
+ do *++s; while (istrailinggabage(*s));
+ }
+#endif
break;
case '/':
#if defined DOSISH || defined __CYGWIN__
@@ -2578,6 +2692,19 @@ file_expand_path(VALUE fname, VALUE dname, VALUE 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__
@@ -2600,19 +2727,83 @@ file_expand_path(VALUE fname, VALUE dname, VALUE 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);
- rb_str_set_len(result, p - buf);
+ RSTRING(result)->len = p - buf;
+ RSTRING(result)->ptr[p - buf] = '\0';
return result;
}
VALUE
-rb_file_expand_path(VALUE fname, VALUE dname)
+rb_file_expand_path(fname, dname)
+ VALUE fname, dname;
{
return file_expand_path(fname, dname, rb_str_new(0, MAXPATHLEN + 2));
}
@@ -2635,7 +2826,9 @@ rb_file_expand_path(VALUE fname, VALUE dname)
*/
VALUE
-rb_file_s_expand_path(int argc, VALUE *argv)
+rb_file_s_expand_path(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE fname, dname;
@@ -2648,22 +2841,31 @@ rb_file_s_expand_path(int argc, VALUE *argv)
}
static int
-rmext(const char *p, const char *e)
+rmext(p, l1, e)
+ const char *p, *e;
+ int l1;
{
- int l1, l2;
+ int l2;
if (!e) return 0;
- l1 = chompdirsep(p) - p;
l2 = strlen(e);
if (l2 == 2 && e[1] == '*') {
- e = strrchr(p, *e);
- if (!e) return 0;
+ unsigned char c = *e;
+ e = p + l1;
+ do {
+ if (e <= p) return 0;
+ } while (*--e != c);
return e - p;
}
if (l1 < l2) return l1;
- if (strncmp(p+l1-l2, e, l2) == 0) {
+#if CASEFOLD_FILESYSTEM
+#define fncomp strncasecmp
+#else
+#define fncomp strncmp
+#endif
+ if (fncomp(p+l1-l2, e, l2) == 0) {
return l1-l2;
}
return 0;
@@ -2684,20 +2886,22 @@ rmext(const char *p, const char *e)
*/
static VALUE
-rb_file_s_basename(int argc, VALUE *argv)
+rb_file_s_basename(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE fname, fext, basename;
char *name, *p;
#if defined DOSISH_DRIVE_LETTER || defined DOSISH_UNC
char *root;
#endif
- int f;
+ int f, n;
if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) {
StringValue(fext);
}
StringValue(fname);
- if (RSTRING_LEN(fname) == 0 || !*(name = RSTRING_PTR(fname)))
+ if (RSTRING(fname)->len == 0 || !*(name = RSTRING(fname)->ptr))
return fname;
name = skipprefix(name);
#if defined DOSISH_DRIVE_LETTER || defined DOSISH_UNC
@@ -2725,18 +2929,22 @@ rb_file_s_basename(int argc, VALUE *argv)
#endif
#endif
}
- else if (!(p = strrdirsep(name))) {
- if (NIL_P(fext) || !(f = rmext(name, StringValueCStr(fext)))) {
- f = chompdirsep(name) - name;
- if (f == RSTRING_LEN(fname)) return fname;
- }
- p = name;
- }
else {
- while (isdirsep(*p)) p++; /* skip last / */
- if (NIL_P(fext) || !(f = rmext(p, StringValueCStr(fext)))) {
- f = chompdirsep(p) - p;
+ if (!(p = strrdirsep(name))) {
+ p = name;
+ }
+ 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;
}
+ if (f == RSTRING_LEN(fname)) return fname;
}
basename = rb_str_new(p, f);
OBJ_INFECT(basename, fname);
@@ -2756,7 +2964,8 @@ rb_file_s_basename(int argc, VALUE *argv)
*/
static VALUE
-rb_file_s_dirname(VALUE klass, VALUE fname)
+rb_file_s_dirname(klass, fname)
+ VALUE klass, fname;
{
const char *name, *root, *p;
VALUE dirname;
@@ -2808,45 +3017,56 @@ rb_file_s_dirname(VALUE klass, VALUE fname)
*/
static VALUE
-rb_file_s_extname(VALUE klass, VALUE fname)
+rb_file_s_extname(klass, fname)
+ VALUE klass, fname;
{
- char *name, *p, *e;
+ const char *name, *p, *e;
VALUE extname;
name = StringValueCStr(fname);
p = strrdirsep(name); /* get the last path component */
if (!p)
- p = name;
+ p = name;
else
- 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! */
+ 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;
}
/*
* call-seq:
- * File.path(path) -> string
- *
- * Returns the string representation of the path
- *
- * File.path("/dev/null") #=> "/dev/null"
- * File.path(Pathname.new("/tmp")) #=> "/tmp"
- *
- */
-
-static VALUE
-rb_file_s_path(VALUE klass, VALUE fname)
-{
- return rb_get_path(fname);
-}
-
-/*
- * call-seq:
* File.split(file_name) => array
*
* Splits the given string into a directory and a file component and
@@ -2857,7 +3077,8 @@ rb_file_s_path(VALUE klass, VALUE fname)
*/
static VALUE
-rb_file_s_split(VALUE klass, VALUE path)
+rb_file_s_split(klass, path)
+ VALUE klass, path;
{
StringValue(path); /* get rid of converting twice */
return rb_assoc_new(rb_file_s_dirname(Qnil, path), rb_file_s_basename(1,&path));
@@ -2865,70 +3086,77 @@ rb_file_s_split(VALUE klass, VALUE path)
static VALUE separator;
-static VALUE rb_file_join(VALUE ary, VALUE sep);
+static VALUE rb_file_join _((VALUE ary, VALUE sep));
static VALUE
-file_inspect_join(VALUE ary, VALUE argp, int recur)
+file_inspect_join(ary, arg)
+ VALUE ary;
+ VALUE *arg;
{
- VALUE *arg = (VALUE *)argp;
- if (recur) return rb_str_new2("[...]");
return rb_file_join(arg[0], arg[1]);
}
static VALUE
-rb_file_join(VALUE ary, VALUE sep)
+rb_file_join(ary, sep)
+ VALUE ary, sep;
{
long len, i;
+ int taint = 0;
VALUE result, tmp;
char *name, *tail;
- if (RARRAY_LEN(ary) == 0) return rb_str_new(0, 0);
+ if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
+ if (OBJ_TAINTED(ary)) taint = 1;
+ if (OBJ_TAINTED(sep)) taint = 1;
len = 1;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- if (TYPE(RARRAY_PTR(ary)[i]) == T_STRING) {
- len += RSTRING_LEN(RARRAY_PTR(ary)[i]);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ if (TYPE(RARRAY(ary)->ptr[i]) == T_STRING) {
+ len += RSTRING(RARRAY(ary)->ptr[i])->len;
}
else {
len += 10;
}
}
- if (!NIL_P(sep)) {
- StringValue(sep);
- len += RSTRING_LEN(sep) * RARRAY_LEN(ary) - 1;
+ if (!NIL_P(sep) && TYPE(sep) == T_STRING) {
+ len += RSTRING(sep)->len * RARRAY(ary)->len - 1;
}
result = rb_str_buf_new(len);
- OBJ_INFECT(result, ary);
- for (i=0; i<RARRAY_LEN(ary); i++) {
- tmp = RARRAY_PTR(ary)[i];
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ tmp = RARRAY(ary)->ptr[i];
switch (TYPE(tmp)) {
case T_STRING:
break;
case T_ARRAY:
- {
+ if (rb_inspecting_p(tmp)) {
+ tmp = rb_str_new2("[...]");
+ }
+ else {
VALUE args[2];
args[0] = tmp;
args[1] = sep;
- tmp = rb_exec_recursive(file_inspect_join, ary, (VALUE)args);
+ tmp = rb_protect_inspect(file_inspect_join, ary, (VALUE)args);
}
break;
default:
- FilePathValue(tmp);
+ StringValueCStr(tmp);
}
name = StringValueCStr(result);
if (i > 0 && !NIL_P(sep)) {
tail = chompdirsep(name);
- if (RSTRING_PTR(tmp) && isdirsep(RSTRING_PTR(tmp)[0])) {
- rb_str_set_len(result, tail - name);
+ if (RSTRING(tmp)->ptr && isdirsep(RSTRING(tmp)->ptr[0])) {
+ RSTRING(result)->len = tail - name;
}
else if (!*tail) {
rb_str_buf_append(result, sep);
}
}
rb_str_buf_append(result, tmp);
+ if (OBJ_TAINTED(tmp)) taint = 1;
}
+ if (taint) OBJ_TAINT(result);
return result;
}
@@ -2944,7 +3172,8 @@ rb_file_join(VALUE ary, VALUE sep)
*/
static VALUE
-rb_file_s_join(VALUE klass, VALUE args)
+rb_file_s_join(klass, args)
+ VALUE klass, args;
{
return rb_file_join(args, separator);
}
@@ -2965,16 +3194,18 @@ rb_file_s_join(VALUE klass, VALUE args)
*/
static VALUE
-rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
+rb_file_s_truncate(klass, path, len)
+ VALUE klass, path, len;
{
off_t pos;
rb_secure(2);
pos = NUM2OFFT(len);
- FilePathValue(path);
+ SafeStringValue(path);
+
#ifdef HAVE_TRUNCATE
if (truncate(StringValueCStr(path), pos) < 0)
- rb_sys_fail(RSTRING_PTR(path));
+ rb_sys_fail(RSTRING(path)->ptr);
#else
# ifdef HAVE_CHSIZE
{
@@ -2982,16 +3213,16 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
# ifdef _WIN32
if ((tmpfd = open(StringValueCStr(path), O_RDWR)) < 0) {
- rb_sys_fail(RSTRING_PTR(path));
+ rb_sys_fail(RSTRING(path)->ptr);
}
# else
if ((tmpfd = open(StringValueCStr(path), 0)) < 0) {
- rb_sys_fail(RSTRING_PTR(path));
+ rb_sys_fail(RSTRING(path)->ptr);
}
# endif
if (chsize(tmpfd, pos) < 0) {
close(tmpfd);
- rb_sys_fail(RSTRING_PTR(path));
+ rb_sys_fail(RSTRING(path)->ptr);
}
close(tmpfd);
}
@@ -3017,9 +3248,11 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
*/
static VALUE
-rb_file_truncate(VALUE obj, VALUE len)
+rb_file_truncate(obj, len)
+ VALUE obj, len;
{
OpenFile *fptr;
+ FILE *f;
off_t pos;
rb_secure(2);
@@ -3028,13 +3261,15 @@ rb_file_truncate(VALUE obj, VALUE len)
if (!(fptr->mode & FMODE_WRITABLE)) {
rb_raise(rb_eIOError, "not opened for writing");
}
- rb_io_flush(obj);
-#ifdef HAVE_TRUNCATE
- if (ftruncate(fptr->fd, pos) < 0)
+ f = GetWriteFile(fptr);
+ fflush(f);
+ fseeko(f, (off_t)0, SEEK_CUR);
+#ifdef HAVE_FTRUNCATE
+ if (ftruncate(fileno(f), pos) < 0)
rb_sys_fail(fptr->path);
#else
# ifdef HAVE_CHSIZE
- if (chsize(fptr->fd, pos) < 0)
+ if (chsize(fileno(f), pos) < 0)
rb_sys_fail(fptr->path);
# else
rb_notimplement();
@@ -3058,6 +3293,8 @@ rb_file_truncate(VALUE obj, VALUE len)
#ifdef __CYGWIN__
#include <winerror.h>
+extern unsigned long __attribute__((stdcall)) GetLastError(void);
+
static int
cygwin_flock(int fd, int op)
{
@@ -3073,7 +3310,9 @@ cygwin_flock(int fd, int op)
#endif
static int
-rb_thread_flock(int fd, int op, OpenFile *fptr)
+rb_thread_flock(fd, op, fptr)
+ int fd, op;
+ OpenFile *fptr;
{
if (rb_thread_alone() || (op & LOCK_NB)) {
int ret;
@@ -3134,7 +3373,9 @@ rb_thread_flock(int fd, int op, OpenFile *fptr)
*/
static VALUE
-rb_file_flock(VALUE obj, VALUE operation)
+rb_file_flock(obj, operation)
+ VALUE obj;
+ VALUE operation;
{
#ifndef __CHECKER__
OpenFile *fptr;
@@ -3145,10 +3386,10 @@ rb_file_flock(VALUE obj, VALUE operation)
GetOpenFile(obj, fptr);
if (fptr->mode & FMODE_WRITABLE) {
- rb_io_flush(obj);
+ fflush(GetWriteFile(fptr));
}
retry:
- if (flock(fptr->fd, op) < 0) {
+ if (flock(fileno(fptr->f), op) < 0) {
switch (errno) {
case EAGAIN:
case EACCES:
@@ -3170,18 +3411,19 @@ rb_file_flock(VALUE obj, VALUE operation)
#undef flock
static void
-test_check(int n, int argc, VALUE *argv)
+test_check(n, argc, argv)
+ int n, argc;
+ VALUE *argv;
{
int i;
- rb_secure(2);
n+=1;
if (n != argc) rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, n);
for (i=1; i<n; i++) {
switch (TYPE(argv[i])) {
case T_STRING:
default:
- FilePathValue(argv[i]);
+ SafeStringValue(argv[i]);
break;
case T_FILE:
break;
@@ -3251,13 +3493,20 @@ test_check(int n, int argc, VALUE *argv)
*/
static VALUE
-rb_f_test(int argc, VALUE *argv)
+rb_f_test(argc, argv)
+ int argc;
+ VALUE *argv;
{
int cmd;
if (argc == 0) rb_raise(rb_eArgError, "wrong number of arguments");
+#if 0 /* 1.7 behavior? */
+ if (argc == 1) {
+ return RTEST(argv[0]) ? Qtrue : Qfalse;
+ }
+#endif
cmd = NUM2CHR(argv[0]);
- if (cmd == 0) goto unknown;
+ if (cmd == 0) return Qfalse;
if (strchr("bcdefgGkloOprRsSuwWxXz", cmd)) {
CHECK(1);
switch (cmd) {
@@ -3335,7 +3584,7 @@ rb_f_test(int argc, VALUE *argv)
CHECK(1);
if (rb_stat(argv[1], &st) == -1) {
- rb_sys_fail(RSTRING_PTR(argv[1]));
+ rb_sys_fail(RSTRING(argv[1])->ptr);
}
switch (cmd) {
@@ -3374,14 +3623,8 @@ rb_f_test(int argc, VALUE *argv)
return Qfalse;
}
}
- unknown:
/* unknown command */
- if (ISPRINT(cmd)) {
- rb_raise(rb_eArgError, "unknown command ?%c", cmd);
- }
- else {
- rb_raise(rb_eArgError, "unknown command ?\\%03o", cmd);
- }
+ rb_raise(rb_eArgError, "unknown command ?%c", cmd);
return Qnil; /* not reached */
}
@@ -3401,8 +3644,10 @@ rb_f_test(int argc, VALUE *argv)
* meaningful on all systems. See also <code>Kernel#test</code>.
*/
+static VALUE rb_stat_s_alloc _((VALUE));
static VALUE
-rb_stat_s_alloc(VALUE klass)
+rb_stat_s_alloc(klass)
+ VALUE klass;
{
return stat_new_0(klass, 0);
}
@@ -3417,14 +3662,15 @@ rb_stat_s_alloc(VALUE klass)
*/
static VALUE
-rb_stat_init(VALUE obj, VALUE fname)
+rb_stat_init(obj, fname)
+ VALUE obj, fname;
{
struct stat st, *nst;
- rb_secure(2);
- FilePathValue(fname);
+ SafeStringValue(fname);
+
if (stat(StringValueCStr(fname), &st) == -1) {
- rb_sys_fail(RSTRING_PTR(fname));
+ rb_sys_fail(RSTRING(fname)->ptr);
}
if (DATA_PTR(obj)) {
free(DATA_PTR(obj));
@@ -3439,7 +3685,8 @@ rb_stat_init(VALUE obj, VALUE fname)
/* :nodoc: */
static VALUE
-rb_stat_init_copy(VALUE copy, VALUE orig)
+rb_stat_init_copy(copy, orig)
+ VALUE copy, orig;
{
struct stat *nst;
@@ -3477,7 +3724,8 @@ rb_stat_init_copy(VALUE copy, VALUE orig)
*/
static VALUE
-rb_stat_ftype(VALUE obj)
+rb_stat_ftype(obj)
+ VALUE obj;
{
return rb_file_ftype(get_stat(obj));
}
@@ -3494,7 +3742,8 @@ rb_stat_ftype(VALUE obj)
*/
static VALUE
-rb_stat_d(VALUE obj)
+rb_stat_d(obj)
+ VALUE obj;
{
if (S_ISDIR(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
@@ -3509,7 +3758,8 @@ rb_stat_d(VALUE obj)
*/
static VALUE
-rb_stat_p(VALUE obj)
+rb_stat_p(obj)
+ VALUE obj;
{
#ifdef S_IFIFO
if (S_ISFIFO(get_stat(obj)->st_mode)) return Qtrue;
@@ -3536,7 +3786,8 @@ rb_stat_p(VALUE obj)
*/
static VALUE
-rb_stat_l(VALUE obj)
+rb_stat_l(obj)
+ VALUE obj;
{
#ifdef S_ISLNK
if (S_ISLNK(get_stat(obj)->st_mode)) return Qtrue;
@@ -3557,7 +3808,8 @@ rb_stat_l(VALUE obj)
*/
static VALUE
-rb_stat_S(VALUE obj)
+rb_stat_S(obj)
+ VALUE obj;
{
#ifdef S_ISSOCK
if (S_ISSOCK(get_stat(obj)->st_mode)) return Qtrue;
@@ -3580,7 +3832,8 @@ rb_stat_S(VALUE obj)
*/
static VALUE
-rb_stat_b(VALUE obj)
+rb_stat_b(obj)
+ VALUE obj;
{
#ifdef S_ISBLK
if (S_ISBLK(get_stat(obj)->st_mode)) return Qtrue;
@@ -3602,7 +3855,8 @@ rb_stat_b(VALUE obj)
*/
static VALUE
-rb_stat_c(VALUE obj)
+rb_stat_c(obj)
+ VALUE obj;
{
if (S_ISCHR(get_stat(obj)->st_mode)) return Qtrue;
@@ -3622,14 +3876,16 @@ rb_stat_c(VALUE obj)
*/
static VALUE
-rb_stat_owned(VALUE obj)
+rb_stat_owned(obj)
+ VALUE obj;
{
if (get_stat(obj)->st_uid == geteuid()) return Qtrue;
return Qfalse;
}
static VALUE
-rb_stat_rowned(VALUE obj)
+rb_stat_rowned(obj)
+ VALUE obj;
{
if (get_stat(obj)->st_uid == getuid()) return Qtrue;
return Qfalse;
@@ -3648,10 +3904,11 @@ rb_stat_rowned(VALUE obj)
*/
static VALUE
-rb_stat_grpowned(VALUE obj)
+rb_stat_grpowned(obj)
+ VALUE obj;
{
#ifndef _WIN32
- if (get_stat(obj)->st_gid == getegid()) return Qtrue;
+ if (group_member(get_stat(obj)->st_gid)) return Qtrue;
#endif
return Qfalse;
}
@@ -3668,7 +3925,8 @@ rb_stat_grpowned(VALUE obj)
*/
static VALUE
-rb_stat_r(VALUE obj)
+rb_stat_r(obj)
+ VALUE obj;
{
struct stat *st = get_stat(obj);
@@ -3703,7 +3961,8 @@ rb_stat_r(VALUE obj)
*/
static VALUE
-rb_stat_R(VALUE obj)
+rb_stat_R(obj)
+ VALUE obj;
{
struct stat *st = get_stat(obj);
@@ -3725,32 +3984,6 @@ rb_stat_R(VALUE obj)
}
/*
- * call-seq:
- * stat.world_readable? => fixnum or nil
- *
- * If <i>stat</i> is readable by others, returns an integer
- * representing the file permission bits of <i>stat</i>. Returns
- * <code>nil</code> otherwise. The meaning of the bits is platform
- * dependent; on Unix systems, see <code>stat(2)</code>.
- *
- * m = File.stat("/etc/passwd").world_readable? # => 420
- * sprintf("%o", m) # => "644"
- */
-
-static VALUE
-rb_stat_wr(VALUE obj)
-{
-#ifdef S_IROTH
- if ((get_stat(obj)->st_mode & (S_IROTH)) == S_IROTH) {
- return UINT2NUM(get_stat(obj)->st_mode & (S_IRUGO|S_IWUGO|S_IXUGO));
- }
- else {
- return Qnil;
- }
-#endif
-}
-
-/*
* call-seq:
* stat.writable? -> true or false
*
@@ -3762,7 +3995,8 @@ rb_stat_wr(VALUE obj)
*/
static VALUE
-rb_stat_w(VALUE obj)
+rb_stat_w(obj)
+ VALUE obj;
{
struct stat *st = get_stat(obj);
@@ -3795,7 +4029,8 @@ rb_stat_w(VALUE obj)
*/
static VALUE
-rb_stat_W(VALUE obj)
+rb_stat_W(obj)
+ VALUE obj;
{
struct stat *st = get_stat(obj);
@@ -3817,32 +4052,6 @@ rb_stat_W(VALUE obj)
}
/*
- * call-seq:
- * stat.world_writable? => fixnum or nil
- *
- * If <i>stat</i> is writable by others, returns an integer
- * representing the file permission bits of <i>stat</i>. Returns
- * <code>nil</code> otherwise. The meaning of the bits is platform
- * dependent; on Unix systems, see <code>stat(2)</code>.
- *
- * m = File.stat("/tmp").world_writable? # => 511
- * sprintf("%o", m) # => "777"
- */
-
-static VALUE
-rb_stat_ww(VALUE obj)
-{
-#ifdef S_IROTH
- if ((get_stat(obj)->st_mode & (S_IWOTH)) == S_IWOTH) {
- return UINT2NUM(get_stat(obj)->st_mode & (S_IRUGO|S_IWUGO|S_IXUGO));
- }
- else {
- return Qnil;
- }
-#endif
-}
-
-/*
* call-seq:
* stat.executable? => true or false
*
@@ -3856,7 +4065,8 @@ rb_stat_ww(VALUE obj)
*/
static VALUE
-rb_stat_x(VALUE obj)
+rb_stat_x(obj)
+ VALUE obj;
{
struct stat *st = get_stat(obj);
@@ -3889,7 +4099,8 @@ rb_stat_x(VALUE obj)
static VALUE
-rb_stat_X(VALUE obj)
+rb_stat_X(obj)
+ VALUE obj;
{
struct stat *st = get_stat(obj);
@@ -3924,7 +4135,8 @@ rb_stat_X(VALUE obj)
*/
static VALUE
-rb_stat_f(VALUE obj)
+rb_stat_f(obj)
+ VALUE obj;
{
if (S_ISREG(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
@@ -3942,7 +4154,8 @@ rb_stat_f(VALUE obj)
*/
static VALUE
-rb_stat_z(VALUE obj)
+rb_stat_z(obj)
+ VALUE obj;
{
if (get_stat(obj)->st_size == 0) return Qtrue;
return Qfalse;
@@ -3960,7 +4173,8 @@ rb_stat_z(VALUE obj)
*/
static VALUE
-rb_stat_s(VALUE obj)
+rb_stat_s(obj)
+ VALUE obj;
{
off_t size = get_stat(obj)->st_size;
@@ -3980,7 +4194,8 @@ rb_stat_s(VALUE obj)
*/
static VALUE
-rb_stat_suid(VALUE obj)
+rb_stat_suid(obj)
+ VALUE obj;
{
#ifdef S_ISUID
if (get_stat(obj)->st_mode & S_ISUID) return Qtrue;
@@ -4001,7 +4216,8 @@ rb_stat_suid(VALUE obj)
*/
static VALUE
-rb_stat_sgid(VALUE obj)
+rb_stat_sgid(obj)
+ VALUE obj;
{
#ifdef S_ISGID
if (get_stat(obj)->st_mode & S_ISGID) return Qtrue;
@@ -4022,7 +4238,8 @@ rb_stat_sgid(VALUE obj)
*/
static VALUE
-rb_stat_sticky(VALUE obj)
+rb_stat_sticky(obj)
+ VALUE obj;
{
#ifdef S_ISVTX
if (get_stat(obj)->st_mode & S_ISVTX) return Qtrue;
@@ -4033,13 +4250,16 @@ rb_stat_sticky(VALUE obj)
VALUE rb_mFConst;
void
-rb_file_const(const char *name, VALUE value)
+rb_file_const(name, value)
+ const char *name;
+ VALUE value;
{
rb_define_const(rb_mFConst, name, value);
}
static int
-is_absolute_path(const char *path)
+is_absolute_path(path)
+ const char *path;
{
#ifdef DOSISH_DRIVE_LETTER
if (has_drive_letter(path) && isdirsep(path[2])) return 1;
@@ -4063,10 +4283,12 @@ is_absolute_path(const char *path)
#if ENABLE_PATH_CHECK
static int
-path_check_0(VALUE path, int execpath)
+path_check_0(fpath, execpath)
+ VALUE fpath;
+ int execpath;
{
struct stat st;
- char *p0 = StringValueCStr(path);
+ char *p0 = StringValueCStr(fpath);
char *p = 0, *s;
if (!is_absolute_path(p0)) {
@@ -4078,7 +4300,7 @@ path_check_0(VALUE path, int execpath)
rb_str_cat2(newpath, "/");
rb_str_cat2(newpath, p0);
- p0 = RSTRING_PTR(path = newpath);
+ p0 = RSTRING(fpath = newpath)->ptr;
}
for (;;) {
#ifndef S_IWOTH
@@ -4088,7 +4310,7 @@ path_check_0(VALUE path, int execpath)
#ifdef S_ISVTX
&& !(p && execpath && (st.st_mode & S_ISVTX))
#endif
- && !access(p0, W_OK)) {
+ ) {
rb_warn("Insecure world writable dir %s in %sPATH, mode 0%o",
p0, (execpath ? "" : "LOAD_"), st.st_mode);
if (p) *p = '/';
@@ -4104,7 +4326,8 @@ path_check_0(VALUE path, int execpath)
#endif
static int
-fpath_check(const char *path)
+fpath_check(path)
+ char *path;
{
#if ENABLE_PATH_CHECK
return path_check_0(rb_str_new2(path), Qfalse);
@@ -4114,10 +4337,11 @@ fpath_check(const char *path)
}
int
-rb_path_check(const char *path)
+rb_path_check(path)
+ char *path;
{
#if ENABLE_PATH_CHECK
- const char *p0, *p, *pend;
+ char *p0, *p, *pend;
const char sep = PATH_SEP_CHAR;
if (!path) return 1;
@@ -4142,7 +4366,8 @@ rb_path_check(const char *path)
#if defined(__MACOS__) || defined(riscos)
static int
-is_macos_native_path(const char *path)
+is_macos_native_path(path)
+ const char *path;
{
if (strchr(path, ':')) return 1;
return 0;
@@ -4150,18 +4375,27 @@ is_macos_native_path(const char *path)
#endif
static int
-file_load_ok(const char *path)
+file_load_ok(file)
+ char *file;
{
- return eaccess(path, R_OK) == 0;
+ FILE *f;
+
+ if (!file) return 0;
+ f = fopen(file, "r");
+ if (f == NULL) return 0;
+ fclose(f);
+ return 1;
}
extern VALUE rb_load_path;
int
-rb_find_file_ext(VALUE *filep, const char *const *ext)
+rb_find_file_ext(filep, ext)
+ VALUE *filep;
+ const char * const *ext;
{
char *path, *found;
- char *f = RSTRING_PTR(*filep);
+ char *f = RSTRING(*filep)->ptr;
VALUE fname;
long i, j;
@@ -4191,19 +4425,19 @@ rb_find_file_ext(VALUE *filep, const char *const *ext)
if (!rb_load_path) return 0;
Check_Type(rb_load_path, T_ARRAY);
- for (i=0;i<RARRAY_LEN(rb_load_path);i++) {
- VALUE str = RARRAY_PTR(rb_load_path)[i];
+ for (i=0;i<RARRAY(rb_load_path)->len;i++) {
+ VALUE str = RARRAY(rb_load_path)->ptr[i];
- FilePathValue(str);
- if (RSTRING_LEN(str) == 0) continue;
- path = RSTRING_PTR(str);
+ SafeStringValue(str);
+ if (RSTRING(str)->len == 0) continue;
+ path = RSTRING(str)->ptr;
for (j=0; ext[j]; j++) {
fname = rb_str_dup(*filep);
rb_str_cat2(fname, ext[j]);
OBJ_FREEZE(fname);
found = dln_find_file(StringValueCStr(fname), path);
if (found && file_load_ok(found)) {
- *filep = rb_str_new2(found);
+ *filep = fname;
return j+1;
}
}
@@ -4212,7 +4446,8 @@ rb_find_file_ext(VALUE *filep, const char *const *ext)
}
VALUE
-rb_find_file(VALUE path)
+rb_find_file(path)
+ VALUE path;
{
VALUE tmp;
char *f = StringValueCStr(path);
@@ -4252,19 +4487,19 @@ rb_find_file(VALUE path)
Check_Type(rb_load_path, T_ARRAY);
tmp = rb_ary_new();
- for (i=0;i<RARRAY_LEN(rb_load_path);i++) {
- VALUE str = RARRAY_PTR(rb_load_path)[i];
- FilePathValue(str);
- if (RSTRING_LEN(str) > 0) {
+ for (i=0;i<RARRAY(rb_load_path)->len;i++) {
+ VALUE str = RARRAY(rb_load_path)->ptr[i];
+ SafeStringValue(str);
+ if (RSTRING(str)->len > 0) {
rb_ary_push(tmp, str);
}
}
tmp = rb_ary_join(tmp, rb_str_new2(PATH_SEP));
- if (RSTRING_LEN(tmp) == 0) {
+ if (RSTRING(tmp)->len == 0) {
lpath = 0;
}
else {
- lpath = RSTRING_PTR(tmp);
+ lpath = RSTRING(tmp)->ptr;
}
}
else {
@@ -4274,7 +4509,9 @@ rb_find_file(VALUE path)
if (!lpath) {
return 0; /* no path, no load */
}
- f = dln_find_file(f, lpath);
+ if (!(f = dln_find_file(f, lpath))) {
+ return 0;
+ }
if (rb_safe_level() >= 1 && !fpath_check(f)) {
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
}
@@ -4287,7 +4524,10 @@ rb_find_file(VALUE path)
}
static void
-define_filetest_function(const char *name, VALUE (*func)(ANYARGS), int argc)
+define_filetest_function(name, func, argc)
+ const char *name;
+ VALUE (*func)();
+ int argc;
{
rb_define_module_function(rb_mFileTest, name, func, argc);
rb_define_singleton_method(rb_cFile, name, func, argc);
@@ -4327,7 +4567,7 @@ define_filetest_function(const char *name, VALUE (*func)(ANYARGS), int argc)
*/
void
-Init_File(void)
+Init_File()
{
rb_mFileTest = rb_define_module("FileTest");
rb_cFile = rb_define_class("File", rb_cIO);
@@ -4337,10 +4577,8 @@ Init_File(void)
define_filetest_function("exists?", test_e, 1); /* temporary */
define_filetest_function("readable?", test_r, 1);
define_filetest_function("readable_real?", test_R, 1);
- define_filetest_function("world_readable?", test_wr, 1);
define_filetest_function("writable?", test_w, 1);
define_filetest_function("writable_real?", test_W, 1);
- define_filetest_function("world_writable?", test_ww, 1);
define_filetest_function("executable?", test_x, 1);
define_filetest_function("executable_real?", test_X, 1);
define_filetest_function("file?", test_f, 1);
@@ -4390,7 +4628,6 @@ Init_File(void)
rb_define_singleton_method(rb_cFile, "basename", rb_file_s_basename, -1);
rb_define_singleton_method(rb_cFile, "dirname", rb_file_s_dirname, 1);
rb_define_singleton_method(rb_cFile, "extname", rb_file_s_extname, 1);
- rb_define_singleton_method(rb_cFile, "path", rb_file_s_path, 1);
separator = rb_obj_freeze(rb_str_new2("/"));
rb_define_const(rb_cFile, "Separator", separator);
@@ -4462,10 +4699,8 @@ Init_File(void)
rb_define_method(rb_cStat, "directory?", rb_stat_d, 0);
rb_define_method(rb_cStat, "readable?", rb_stat_r, 0);
rb_define_method(rb_cStat, "readable_real?", rb_stat_R, 0);
- rb_define_method(rb_cStat, "world_readable?", rb_stat_wr, 0);
rb_define_method(rb_cStat, "writable?", rb_stat_w, 0);
rb_define_method(rb_cStat, "writable_real?", rb_stat_W, 0);
- rb_define_method(rb_cStat, "world_writable?", rb_stat_ww, 0);
rb_define_method(rb_cStat, "executable?", rb_stat_x, 0);
rb_define_method(rb_cStat, "executable_real?", rb_stat_X, 0);
rb_define_method(rb_cStat, "file?", rb_stat_f, 0);
diff --git a/gc.c b/gc.c
index dcad5a10fb..00c4257a17 100644
--- a/gc.c
+++ b/gc.c
@@ -34,7 +34,8 @@
#include <windows.h>
#endif
-int rb_io_fptr_finalize(struct OpenFile*);
+void re_free_registers _((struct re_registers*));
+void rb_io_fptr_finalize _((struct OpenFile*));
#if !defined(setjmp) && defined(HAVE__SETJMP)
#define setjmp(env) _setjmp(env)
@@ -69,60 +70,32 @@ void *alloca ();
static unsigned long malloc_increase = 0;
static unsigned long malloc_limit = GC_MALLOC_LIMIT;
-static void run_final(VALUE obj);
+static void run_final();
static VALUE nomem_error;
-static int garbage_collect(void);
+static void garbage_collect();
+
+NORETURN(void rb_exc_jump _((VALUE)));
void
-rb_memerror(void)
+rb_memerror()
{
- static int recurse = 0;
+ rb_thread_t th = rb_curr_thread;
- if (!nomem_error || (recurse > 0 && rb_safe_level() < 4)) {
+ if (!nomem_error ||
+ (rb_thread_raised_p(th, RAISED_NOMEMORY) && rb_safe_level() < 4)) {
fprintf(stderr, "[FATAL] failed to allocate memory\n");
exit(1);
}
- recurse++;
+ if (rb_thread_raised_p(th, RAISED_NOMEMORY)) {
+ rb_exc_jump(nomem_error);
+ }
+ rb_thread_raised_set(th, RAISED_NOMEMORY);
rb_exc_raise(nomem_error);
}
-int gc_stress = 0;
-
-/*
- * call-seq:
- * GC.stress => true or false
- *
- * returns current status of GC stress mode.
- */
-
-static VALUE
-gc_stress_get(VALUE self)
-{
- return gc_stress ? Qtrue : Qfalse;
-}
-
-/*
- * call-seq:
- * GC.stress = bool => bool
- *
- * updates GC stress mode.
- *
- * When GC.stress = true, GC is invoked for all GC opportunity:
- * all memory and object allocation.
- *
- * Since it makes Ruby very slow, it is only for debugging.
- */
-
-static VALUE
-gc_stress_set(VALUE self, VALUE bool)
-{
- rb_secure(2);
- gc_stress = RTEST(bool);
- return bool;
-}
-
void *
-ruby_xmalloc(size_t size)
+ruby_xmalloc(size)
+ long size;
{
void *mem;
@@ -130,87 +103,69 @@ ruby_xmalloc(size_t size)
rb_raise(rb_eNoMemError, "negative allocation size (or too big)");
}
if (size == 0) size = 1;
- malloc_increase += size;
- if (gc_stress || malloc_increase > malloc_limit) {
+ if ((malloc_increase+size) > malloc_limit) {
garbage_collect();
}
RUBY_CRITICAL(mem = malloc(size));
if (!mem) {
- if (garbage_collect()) {
- RUBY_CRITICAL(mem = malloc(size));
- }
+ garbage_collect();
+ RUBY_CRITICAL(mem = malloc(size));
if (!mem) {
rb_memerror();
}
}
+ malloc_increase += size;
return mem;
}
void *
-ruby_xmalloc2(size_t n, size_t size)
-{
- long len = size * n;
- if (n != 0 && size != len / n) {
- rb_raise(rb_eArgError, "malloc: possible integer overflow");
- }
- return ruby_xmalloc(len);
-}
-
-void *
-ruby_xcalloc(size_t n, size_t size)
+ruby_xcalloc(n, size)
+ long n, size;
{
void *mem;
- mem = ruby_xmalloc2(n, size);
+ mem = xmalloc(n * size);
memset(mem, 0, n * size);
return mem;
}
void *
-ruby_xrealloc(void *ptr, size_t size)
+ruby_xrealloc(ptr, size)
+ void *ptr;
+ long size;
{
void *mem;
if (size < 0) {
rb_raise(rb_eArgError, "negative re-allocation size");
}
- if (!ptr) return ruby_xmalloc(size);
+ if (!ptr) return xmalloc(size);
if (size == 0) size = 1;
- malloc_increase += size;
- if (gc_stress) garbage_collect();
RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
- if (garbage_collect()) {
- RUBY_CRITICAL(mem = realloc(ptr, size));
- }
+ garbage_collect();
+ RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
rb_memerror();
}
}
+ malloc_increase += size;
return mem;
}
-void *
-ruby_xrealloc2(void *ptr, size_t n, size_t size)
-{
- size_t len = size * n;
- if (n != 0 && size != len / n) {
- rb_raise(rb_eArgError, "realloc: possible integer overflow");
- }
- return ruby_xrealloc(ptr, len);
-}
-
void
-ruby_xfree(void *x)
+ruby_xfree(x)
+ void *x;
{
if (x)
RUBY_CRITICAL(free(x));
}
+extern int ruby_in_compile;
static int dont_gc;
static int during_gc;
static int need_call_final = 0;
@@ -231,7 +186,7 @@ static st_table *finalizer_table = 0;
*/
VALUE
-rb_gc_enable(void)
+rb_gc_enable()
{
int old = dont_gc;
@@ -252,7 +207,7 @@ rb_gc_enable(void)
*/
VALUE
-rb_gc_disable(void)
+rb_gc_disable()
{
int old = dont_gc;
@@ -268,7 +223,8 @@ static struct gc_list {
} *global_List = 0;
void
-rb_gc_register_address(VALUE *addr)
+rb_gc_register_address(addr)
+ VALUE *addr;
{
struct gc_list *tmp;
@@ -279,7 +235,8 @@ rb_gc_register_address(VALUE *addr)
}
void
-rb_gc_unregister_address(VALUE *addr)
+rb_gc_unregister_address(addr)
+ VALUE *addr;
{
struct gc_list *tmp = global_List;
@@ -303,7 +260,8 @@ rb_gc_unregister_address(VALUE *addr)
#undef GC_DEBUG
void
-rb_global_variable(VALUE *var)
+rb_global_variable(var)
+ VALUE *var;
{
rb_gc_register_address(var);
}
@@ -365,7 +323,7 @@ static int heap_slots = HEAP_MIN_SLOTS;
static RVALUE *himem, *lomem;
static void
-add_heap(void)
+add_heap()
{
RVALUE *p, *pend;
@@ -421,13 +379,21 @@ add_heap(void)
}
#define RANY(o) ((RVALUE*)(o))
+int
+rb_during_gc()
+{
+ return during_gc;
+}
+
VALUE
-rb_newobj(void)
+rb_newobj()
{
VALUE obj;
- if ((gc_stress || !freelist) && !garbage_collect())
- rb_memerror();
+ if (during_gc)
+ rb_bug("object allocation during garbage collection phase");
+
+ if (!freelist) garbage_collect();
obj = (VALUE)freelist;
freelist = freelist->as.free.next;
@@ -440,7 +406,11 @@ rb_newobj(void)
}
VALUE
-rb_data_object_alloc(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
+rb_data_object_alloc(klass, datap, dmark, dfree)
+ VALUE klass;
+ void *datap;
+ RUBY_DATA_FUNC dmark;
+ RUBY_DATA_FUNC dfree;
{
NEWOBJ(data, struct RData);
if (klass) Check_Type(klass, T_CLASS);
@@ -458,7 +428,6 @@ VALUE *rb_gc_stack_start = 0;
VALUE *rb_gc_register_stack_start = 0;
#endif
-
#ifdef DJGPP
/* set stack size (http://www.delorie.com/djgpp/v2faq/faq15_9.html) */
unsigned int _stklen = 0x180000; /* 1.5 kB */
@@ -476,20 +445,27 @@ static unsigned int STACK_LEVEL_MAX = 655300;
# define STACK_LEVEL_MAX 655300
#endif
-NOINLINE(static void set_stack_end(VALUE **stack_end_p));
-
+#ifdef C_ALLOCA
+# define SET_STACK_END VALUE stack_end; alloca(0);
+# define STACK_END (&stack_end)
+#else
+# if defined(__GNUC__) && defined(USE_BUILTIN_FRAME_ADDRESS) && !defined(__ia64)
+# if ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) || __GNUC__ > 3
+__attribute__ ((noinline))
+# endif
static void
-set_stack_end(VALUE **stack_end_p)
+stack_end_address(VALUE **stack_end_p)
{
VALUE stack_end;
*stack_end_p = &stack_end;
}
-#define SET_STACK_END VALUE *stack_end; set_stack_end(&stack_end)
-#define STACK_END (stack_end)
-
-#if defined(sparc) || defined(__sparc__)
-# define STACK_LENGTH (rb_gc_stack_start - STACK_END + 0x80)
-#elif STACK_GROW_DIRECTION < 0
+# define SET_STACK_END VALUE *stack_end; stack_end_address(&stack_end)
+# else
+# define SET_STACK_END VALUE *stack_end = alloca(1)
+# endif
+# define STACK_END (stack_end)
+#endif
+#if 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)
@@ -504,7 +480,8 @@ set_stack_end(VALUE **stack_end_p)
#else
static int grow_direction;
static int
-stack_grow_direction(VALUE *addr)
+stack_grow_direction(addr)
+ VALUE *addr;
{
SET_STACK_END;
@@ -523,7 +500,8 @@ stack_grow_direction(VALUE *addr)
} while (0)
int
-ruby_stack_length(VALUE **p)
+ruby_stack_length(p)
+ VALUE **p;
{
SET_STACK_END;
if (p) *p = STACK_UPPER(STACK_END, rb_gc_stack_start, STACK_END);
@@ -531,7 +509,7 @@ ruby_stack_length(VALUE **p)
}
int
-ruby_stack_check(void)
+ruby_stack_check()
{
int ret;
@@ -545,34 +523,37 @@ static VALUE *mark_stack_ptr;
static int mark_stack_overflow;
static void
-init_mark_stack(void)
+init_mark_stack()
{
mark_stack_overflow = 0;
mark_stack_ptr = mark_stack;
}
#define MARK_STACK_EMPTY (mark_stack_ptr == mark_stack)
-
+
static st_table *source_filenames;
char *
-rb_source_filename(const char *f)
+rb_source_filename(f)
+ const char *f;
{
- char *name;
+ st_data_t name;
- if (!st_lookup(source_filenames, (st_data_t)f, (st_data_t *)&name)) {
+ if (!st_lookup(source_filenames, (st_data_t)f, &name)) {
long len = strlen(f) + 1;
- char *ptr = name = ALLOC_N(char, len + 1);
+ char *ptr = ALLOC_N(char, len + 1);
+ name = (st_data_t)ptr;
*ptr++ = 0;
MEMCPY(ptr, f, char, len);
- st_add_direct(source_filenames, (st_data_t)ptr, (st_data_t)name);
+ st_add_direct(source_filenames, (st_data_t)ptr, name);
return ptr;
}
- return name + 1;
+ return (char *)name + 1;
}
static void
-mark_source_filename(char *f)
+mark_source_filename(f)
+ char *f;
{
if (f) {
f[-1] = 1;
@@ -580,7 +561,8 @@ mark_source_filename(char *f)
}
static int
-sweep_source_filename(char *key, char *value)
+sweep_source_filename(key, value)
+ char *key, *value;
{
if (*value) {
*value = 0;
@@ -592,11 +574,11 @@ sweep_source_filename(char *key, char *value)
}
}
-static void gc_mark(VALUE ptr, int lev);
-static void gc_mark_children(VALUE ptr, int lev);
+static void gc_mark _((VALUE ptr, int lev));
+static void gc_mark_children _((VALUE ptr, int lev));
static void
-gc_mark_all(void)
+gc_mark_all()
{
RVALUE *p, *pend;
int i;
@@ -615,7 +597,7 @@ gc_mark_all(void)
}
static void
-gc_mark_rest(void)
+gc_mark_rest()
{
VALUE tmp_arry[MARK_STACK_MAX];
VALUE *p;
@@ -624,14 +606,15 @@ gc_mark_rest(void)
MEMCPY(tmp_arry, mark_stack, VALUE, MARK_STACK_MAX);
init_mark_stack();
- while (p != tmp_arry){
+ while(p != tmp_arry){
p--;
gc_mark_children(*p, 0);
}
}
static inline int
-is_pointer_to_heap(void *ptr)
+is_pointer_to_heap(ptr)
+ void *ptr;
{
register RVALUE *p = RANY(ptr);
register RVALUE *heap_org;
@@ -650,7 +633,9 @@ is_pointer_to_heap(void *ptr)
}
static void
-mark_locations_array(register VALUE *x, register long n)
+mark_locations_array(x, n)
+ register VALUE *x;
+ register long n;
{
VALUE v;
while (n--) {
@@ -663,7 +648,8 @@ mark_locations_array(register VALUE *x, register long n)
}
void
-rb_gc_mark_locations(VALUE *start, VALUE *end)
+rb_gc_mark_locations(start, end)
+ VALUE *start, *end;
{
long n;
@@ -672,27 +658,36 @@ rb_gc_mark_locations(VALUE *start, VALUE *end)
}
static int
-mark_entry(ID key, VALUE value, int lev)
+mark_entry(key, value, lev)
+ ID key;
+ VALUE value;
+ int lev;
{
gc_mark(value, lev);
return ST_CONTINUE;
}
static void
-mark_tbl(st_table *tbl, int lev)
+mark_tbl(tbl, lev)
+ st_table *tbl;
+ int lev;
{
if (!tbl) return;
st_foreach(tbl, mark_entry, lev);
}
void
-rb_mark_tbl(st_table *tbl)
+rb_mark_tbl(tbl)
+ st_table *tbl;
{
mark_tbl(tbl, 0);
}
static int
-mark_keyvalue(VALUE key, VALUE value, int lev)
+mark_keyvalue(key, value, lev)
+ VALUE key;
+ VALUE value;
+ int lev;
{
gc_mark(key, lev);
gc_mark(value, lev);
@@ -700,20 +695,24 @@ mark_keyvalue(VALUE key, VALUE value, int lev)
}
static void
-mark_hash(st_table *tbl, int lev)
+mark_hash(tbl, lev)
+ st_table *tbl;
+ int lev;
{
if (!tbl) return;
st_foreach(tbl, mark_keyvalue, lev);
}
void
-rb_mark_hash(st_table *tbl)
+rb_mark_hash(tbl)
+ st_table *tbl;
{
mark_hash(tbl, 0);
}
void
-rb_gc_mark_maybe(VALUE obj)
+rb_gc_mark_maybe(obj)
+ VALUE obj;
{
if (is_pointer_to_heap((void *)obj)) {
gc_mark(obj, 0);
@@ -723,7 +722,9 @@ rb_gc_mark_maybe(VALUE obj)
#define GC_LEVEL_MAX 250
static void
-gc_mark(VALUE ptr, int lev)
+gc_mark(ptr, lev)
+ VALUE ptr;
+ int lev;
{
register RVALUE *obj;
@@ -749,13 +750,16 @@ gc_mark(VALUE ptr, int lev)
}
void
-rb_gc_mark(VALUE ptr)
+rb_gc_mark(ptr)
+ VALUE ptr;
{
gc_mark(ptr, 0);
}
static void
-gc_mark_children(VALUE ptr, int lev)
+gc_mark_children(ptr, lev)
+ VALUE ptr;
+ int lev;
{
register RVALUE *obj = RANY(ptr);
@@ -785,13 +789,12 @@ gc_mark_children(VALUE ptr, int lev)
case NODE_IF: /* 1,2,3 */
case NODE_FOR:
case NODE_ITER:
+ case NODE_CREF:
case NODE_WHEN:
case NODE_MASGN:
case NODE_RESCUE:
case NODE_RESBODY:
case NODE_CLASS:
- case NODE_ARGS:
- case NODE_BLOCK_PASS:
gc_mark((VALUE)obj->as.node.u2.node, lev);
/* fall through */
case NODE_BLOCK: /* 1,3 */
@@ -805,12 +808,12 @@ gc_mark_children(VALUE ptr, int lev)
case NODE_CALL:
case NODE_DEFS:
case NODE_OP_ASGN1:
- case NODE_CREF:
gc_mark((VALUE)obj->as.node.u1.node, lev);
/* fall through */
case NODE_SUPER: /* 3 */
case NODE_FCALL:
case NODE_DEFN:
+ case NODE_NEWLINE:
ptr = (VALUE)obj->as.node.u3.node;
goto again;
@@ -831,7 +834,7 @@ gc_mark_children(VALUE ptr, int lev)
case NODE_MODULE:
case NODE_ALIAS:
case NODE_VALIAS:
- case NODE_LAMBDA:
+ case NODE_ARGS:
gc_mark((VALUE)obj->as.node.u1.node, lev);
/* fall through */
case NODE_METHOD: /* 2 */
@@ -847,7 +850,6 @@ gc_mark_children(VALUE ptr, int lev)
case NODE_OPT_N:
case NODE_EVSTR:
case NODE_UNDEF:
- case NODE_POSTEXE:
ptr = (VALUE)obj->as.node.u2.node;
goto again;
@@ -864,10 +866,12 @@ gc_mark_children(VALUE ptr, int lev)
case NODE_COLON2:
case NODE_SPLAT:
case NODE_TO_ARY:
+ case NODE_SVALUE:
ptr = (VALUE)obj->as.node.u1.node;
goto again;
case NODE_SCOPE: /* 2,3 */
+ case NODE_BLOCK_PASS:
case NODE_CDECL:
gc_mark((VALUE)obj->as.node.u3.node, lev);
ptr = (VALUE)obj->as.node.u2.node;
@@ -890,9 +894,9 @@ gc_mark_children(VALUE ptr, int lev)
case NODE_NIL:
case NODE_TRUE:
case NODE_FALSE:
- case NODE_ERRINFO:
case NODE_ATTRSET:
case NODE_BLOCK_ARG:
+ case NODE_POSTEXE:
break;
case NODE_ALLOCA:
mark_locations_array((VALUE*)obj->as.node.u1.value,
@@ -930,8 +934,8 @@ gc_mark_children(VALUE ptr, int lev)
goto again;
}
else {
- long i, len = RARRAY_LEN(obj);
- VALUE *ptr = RARRAY_PTR(obj);
+ long i, len = obj->as.array.len;
+ VALUE *ptr = obj->as.array.ptr;
for (i=0; i < len; i++) {
gc_mark(*ptr++, lev);
@@ -946,8 +950,8 @@ gc_mark_children(VALUE ptr, int lev)
case T_STRING:
#define STR_ASSOC FL_USER3 /* copied from string.c */
- if (FL_TEST(obj, RSTRING_NOEMBED) && FL_ANY(obj, ELTS_SHARED|STR_ASSOC)) {
- ptr = obj->as.string.as.heap.aux.shared;
+ if (FL_TEST(obj, ELTS_SHARED|STR_ASSOC)) {
+ ptr = obj->as.string.aux.shared;
goto again;
}
break;
@@ -964,11 +968,10 @@ gc_mark_children(VALUE ptr, int lev)
case T_REGEXP:
case T_FLOAT:
case T_BIGNUM:
- case T_BLOCK:
+ case T_BLKTAG:
break;
case T_MATCH:
- gc_mark(obj->as.match.regexp, lev);
if (obj->as.match.str) {
ptr = obj->as.match.str;
goto again;
@@ -993,8 +996,8 @@ gc_mark_children(VALUE ptr, int lev)
case T_STRUCT:
{
- long len = RSTRUCT_LEN(obj);
- VALUE *ptr = RSTRUCT_PTR(obj);
+ long len = obj->as.rstruct.len;
+ VALUE *ptr = obj->as.rstruct.ptr;
while (len--) {
gc_mark(*ptr++, lev);
@@ -1003,16 +1006,17 @@ gc_mark_children(VALUE ptr, int lev)
break;
default:
- rb_bug("rb_gc_mark(): unknown data type 0x%lx(%p) %s",
+ rb_bug("rb_gc_mark(): unknown data type 0x%lx(0x%lx) %s",
obj->as.basic.flags & T_MASK, obj,
is_pointer_to_heap(obj) ? "corrupted object" : "non object");
}
}
-static void obj_free(VALUE);
+static void obj_free _((VALUE));
static void
-finalize_list(RVALUE *p)
+finalize_list(p)
+ RVALUE *p;
{
while (p) {
RVALUE *tmp = p->as.free.next;
@@ -1027,7 +1031,7 @@ finalize_list(RVALUE *p)
}
static void
-free_unused_heaps(void)
+free_unused_heaps()
{
int i, j;
@@ -1048,7 +1052,7 @@ free_unused_heaps(void)
void rb_gc_abort_threads(void);
static void
-gc_sweep(void)
+gc_sweep()
{
RVALUE *p, *pend, *final_list;
int freed = 0;
@@ -1063,6 +1067,19 @@ gc_sweep(void)
if (free_min < FREE_MIN)
free_min = FREE_MIN;
+ if (ruby_in_compile && ruby_parser_stack_on_heap()) {
+ /* should not reclaim nodes during compilation
+ if yacc's semantic stack is not allocated on machine stack */
+ for (i = 0; i < heaps_used; i++) {
+ p = heaps[i].slot; pend = p + heaps[i].limit;
+ while (p < pend) {
+ if (!(p->as.basic.flags&FL_MARK) && BUILTIN_TYPE(p) == T_NODE)
+ gc_mark((VALUE)p, 0);
+ p++;
+ }
+ }
+ }
+
mark_source_filename(ruby_sourcefile);
if (source_filenames) {
st_foreach(source_filenames, sweep_source_filename, 0);
@@ -1130,13 +1147,15 @@ gc_sweep(void)
/* clear finalization list */
if (final_list) {
deferred_final_list = final_list;
+ rb_thread_pending = 1;
return;
}
free_unused_heaps();
}
void
-rb_gc_force_recycle(VALUE p)
+rb_gc_force_recycle(p)
+ VALUE p;
{
RANY(p)->as.free.flags = 0;
RANY(p)->as.free.next = freelist;
@@ -1144,7 +1163,8 @@ rb_gc_force_recycle(VALUE p)
}
static void
-obj_free(VALUE obj)
+obj_free(obj)
+ VALUE obj;
{
switch (RANY(obj)->as.basic.flags & T_MASK) {
case T_NIL:
@@ -1174,10 +1194,14 @@ obj_free(VALUE obj)
}
break;
case T_STRING:
- rb_str_free(obj);
+ if (RANY(obj)->as.string.ptr && !FL_TEST(obj, ELTS_SHARED)) {
+ RUBY_CRITICAL(free(RANY(obj)->as.string.ptr));
+ }
break;
case T_ARRAY:
- rb_ary_free(obj);
+ if (RANY(obj)->as.array.ptr && !FL_TEST(obj, ELTS_SHARED)) {
+ RUBY_CRITICAL(free(RANY(obj)->as.array.ptr));
+ }
break;
case T_HASH:
if (RANY(obj)->as.hash.tbl) {
@@ -1186,7 +1210,7 @@ obj_free(VALUE obj)
break;
case T_REGEXP:
if (RANY(obj)->as.regexp.ptr) {
- onig_free(RANY(obj)->as.regexp.ptr);
+ re_free_pattern(RANY(obj)->as.regexp.ptr);
}
if (RANY(obj)->as.regexp.str) {
RUBY_CRITICAL(free(RANY(obj)->as.regexp.str));
@@ -1204,13 +1228,14 @@ obj_free(VALUE obj)
break;
case T_MATCH:
if (RANY(obj)->as.match.regs) {
- onig_region_free(RANY(obj)->as.match.regs, 0);
+ re_free_registers(RANY(obj)->as.match.regs);
RUBY_CRITICAL(free(RANY(obj)->as.match.regs));
}
break;
case T_FILE:
if (RANY(obj)->as.file.fptr) {
rb_io_fptr_finalize(RANY(obj)->as.file.fptr);
+ RUBY_CRITICAL(free(RANY(obj)->as.file.fptr));
}
break;
case T_ICLASS:
@@ -1219,7 +1244,7 @@ obj_free(VALUE obj)
case T_FLOAT:
case T_VARMAP:
- case T_BLOCK:
+ case T_BLKTAG:
break;
case T_BIGNUM:
@@ -1244,7 +1269,7 @@ obj_free(VALUE obj)
if (RANY(obj)->as.scope.local_vars &&
RANY(obj)->as.scope.flags != SCOPE_ALLOCA) {
VALUE *vars = RANY(obj)->as.scope.local_vars-1;
- if (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));
@@ -1252,20 +1277,20 @@ obj_free(VALUE obj)
break;
case T_STRUCT:
- if (RBASIC(obj)->flags & RSTRUCT_EMBED_LEN_MASK == 0 &&
- RANY(obj)->as.rstruct.as.heap.ptr) {
- RUBY_CRITICAL(free(RANY(obj)->as.rstruct.as.heap.ptr));
+ if (RANY(obj)->as.rstruct.ptr) {
+ RUBY_CRITICAL(free(RANY(obj)->as.rstruct.ptr));
}
break;
default:
- rb_bug("gc_sweep(): unknown data type 0x%lx(%p)",
- RANY(obj)->as.basic.flags & T_MASK, (void*)obj);
+ rb_bug("gc_sweep(): unknown data type 0x%lx(0x%lx)",
+ RANY(obj)->as.basic.flags & T_MASK, obj);
}
}
void
-rb_gc_mark_frame(struct FRAME *frame)
+rb_gc_mark_frame(frame)
+ struct FRAME *frame;
{
gc_mark((VALUE)frame->node, 0);
}
@@ -1308,15 +1333,14 @@ int rb_setjmp (rb_jmp_buf);
#endif /* __human68k__ or DJGPP */
#endif /* __GNUC__ */
-static int
-garbage_collect(void)
+static void
+garbage_collect()
{
struct gc_list *list;
struct FRAME * volatile frame; /* gcc 2.7.2.3 -O2 bug?? */
jmp_buf save_regs_gc_mark;
SET_STACK_END;
- if (!heaps) return Qfalse;
#ifdef HAVE_NATIVETHREAD
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on rb_gc()");
@@ -1326,8 +1350,9 @@ garbage_collect(void)
if (!freelist) {
add_heap();
}
- return Qtrue;
+ return;
}
+ if (during_gc) return;
during_gc++;
init_mark_stack();
@@ -1366,7 +1391,7 @@ garbage_collect(void)
rb_gc_mark_locations(rb_gc_stack_start, (VALUE*)STACK_END + 1);
#endif
#ifdef __ia64
- /* mark backing store (flushed register stack) */
+ /* mark backing store (flushed register window on the stack) */
/* the basic idea from guile GC code */
rb_gc_mark_locations(rb_gc_register_stack_start, (VALUE*)rb_ia64_bsp());
#endif
@@ -1375,7 +1400,6 @@ garbage_collect(void)
(VALUE*)((char*)rb_gc_stack_start + 2));
#endif
rb_gc_mark_threads();
- rb_gc_mark_symbols();
/* mark protected global variables */
for (list = global_List; list; list = list->next) {
@@ -1406,12 +1430,10 @@ garbage_collect(void)
} while (!MARK_STACK_EMPTY);
gc_sweep();
-
- return Qtrue;
}
void
-rb_gc(void)
+rb_gc()
{
garbage_collect();
rb_gc_finalize_deferred();
@@ -1428,22 +1450,24 @@ rb_gc(void)
*/
VALUE
-rb_gc_start(void)
+rb_gc_start()
{
rb_gc();
return Qnil;
}
void
-ruby_set_stack_size(size_t size)
+ruby_set_stack_size(size)
+ size_t size;
{
#ifndef STACK_LEVEL_MAX
- STACK_LEVEL_MAX = size/sizeof(VALUE);
+ STACK_LEVEL_MAX = size / sizeof(VALUE);
#endif
}
void
-Init_stack(VALUE *addr)
+Init_stack(addr)
+ VALUE *addr;
{
#ifdef __ia64
if (rb_gc_register_stack_start == 0) {
@@ -1480,7 +1504,7 @@ Init_stack(VALUE *addr)
rb_gc_stack_start = STACK_END_ADDRESS;
}
#else
- if (!addr) addr = (VALUE *)&addr;
+ if (!addr) addr = (void *)&addr;
STACK_UPPER(&addr, addr, ++addr);
if (rb_gc_stack_start) {
if (STACK_UPPER(&addr,
@@ -1525,14 +1549,14 @@ void ruby_init_stack(VALUE *addr
#endif
#ifdef HAVE_GETRLIMIT
{
- struct rlimit rlim;
+ struct rlimit rlim;
- if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
- unsigned int space = rlim.rlim_cur/5;
+ if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
+ unsigned int space = rlim.rlim_cur/5;
- if (space > 1024*1024) space = 1024*1024;
- STACK_LEVEL_MAX = (rlim.rlim_cur - space) / sizeof(VALUE);
- }
+ if (space > 1024*1024) space = 1024*1024;
+ STACK_LEVEL_MAX = (rlim.rlim_cur - space) / sizeof(VALUE);
+ }
}
#elif defined _WIN32
{
@@ -1582,7 +1606,7 @@ void ruby_init_stack(VALUE *addr
*/
void
-Init_heap(void)
+Init_heap()
{
if (!rb_gc_stack_start) {
Init_stack(0);
@@ -1591,39 +1615,8 @@ Init_heap(void)
}
static VALUE
-os_live_obj(void)
-{
- 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(VALUE of)
+os_obj_of(of)
+ VALUE of;
{
int i;
int n = 0;
@@ -1634,7 +1627,8 @@ os_obj_of(VALUE of)
p = heaps[i].slot; pend = p + heaps[i].limit;
for (;p < pend; p++) {
if (p->as.basic.flags) {
- switch (TYPE(p)) {
+ switch (BUILTIN_TYPE(p)) {
+ case T_NONE:
case T_ICLASS:
case T_VARMAP:
case T_SCOPE:
@@ -1644,7 +1638,7 @@ os_obj_of(VALUE of)
if (FL_TEST(p, FL_SINGLETON)) continue;
default:
if (!p->as.basic.klass) continue;
- if (rb_obj_is_kind_of((VALUE)p, of)) {
+ if (!of || rb_obj_is_kind_of((VALUE)p, of)) {
rb_yield((VALUE)p);
n++;
}
@@ -1690,17 +1684,17 @@ os_obj_of(VALUE of)
*/
static VALUE
-os_each_obj(int argc, VALUE *argv)
+os_each_obj(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE of;
rb_secure(4);
if (rb_scan_args(argc, argv, "01", &of) == 0) {
- return os_live_obj();
- }
- else {
- return os_obj_of(of);
+ of = 0;
}
+ return os_obj_of(of);
}
static VALUE finalizers;
@@ -1709,7 +1703,8 @@ static VALUE finalizers;
*/
static VALUE
-add_final(VALUE os, VALUE block)
+add_final(os, block)
+ VALUE os, block;
{
rb_warn("ObjectSpace::add_finalizer is deprecated; use define_finalizer");
if (!rb_respond_to(block, rb_intern("call"))) {
@@ -1724,7 +1719,8 @@ add_final(VALUE os, VALUE block)
* deprecated
*/
static VALUE
-rm_final(VALUE os, VALUE block)
+rm_final(os, block)
+ VALUE os, block;
{
rb_warn("ObjectSpace::remove_finalizer is deprecated; use undefine_finalizer");
rb_ary_delete(finalizers, block);
@@ -1735,7 +1731,7 @@ rm_final(VALUE os, VALUE block)
* deprecated
*/
static VALUE
-finals(void)
+finals()
{
rb_warn("ObjectSpace::finalizers is deprecated");
return finalizers;
@@ -1746,7 +1742,8 @@ finals(void)
*/
static VALUE
-call_final(VALUE os, VALUE obj)
+call_final(os, obj)
+ VALUE os, obj;
{
rb_warn("ObjectSpace::call_finalizer is deprecated; use define_finalizer");
need_call_final = 1;
@@ -1763,7 +1760,8 @@ call_final(VALUE os, VALUE obj)
*/
static VALUE
-undefine_final(VALUE os, VALUE obj)
+undefine_final(os, obj)
+ VALUE os, obj;
{
if (finalizer_table) {
st_delete(finalizer_table, (st_data_t*)&obj, 0);
@@ -1781,7 +1779,10 @@ undefine_final(VALUE os, VALUE obj)
*/
static VALUE
-define_final(int argc, VALUE *argv, VALUE os)
+define_final(argc, argv, os)
+ int argc;
+ VALUE *argv;
+ VALUE os;
{
VALUE obj, block, table;
@@ -1811,7 +1812,8 @@ define_final(int argc, VALUE *argv, VALUE os)
}
void
-rb_gc_copy_finalizer(VALUE dest, VALUE obj)
+rb_gc_copy_finalizer(dest, obj)
+ VALUE dest, obj;
{
VALUE table;
@@ -1820,18 +1822,20 @@ rb_gc_copy_finalizer(VALUE dest, VALUE obj)
if (st_lookup(finalizer_table, obj, &table)) {
st_insert(finalizer_table, dest, table);
}
- FL_SET(dest, FL_FINALIZE);
+ RBASIC(dest)->flags |= FL_FINALIZE;
}
static VALUE
-run_single_final(VALUE *args)
+run_single_final(args)
+ VALUE *args;
{
rb_eval_cmd(args[0], args[1], (int)args[2]);
return Qnil;
}
static void
-run_final(VALUE obj)
+run_final(obj)
+ VALUE obj;
{
long i;
int status, critical_save = rb_thread_critical;
@@ -1841,45 +1845,41 @@ run_final(VALUE obj)
rb_thread_critical = Qtrue;
args[1] = 0;
args[2] = (VALUE)ruby_safe_level;
- for (i=0; i<RARRAY_LEN(finalizers); i++) {
- args[0] = RARRAY_PTR(finalizers)[i];
+ for (i=0; i<RARRAY(finalizers)->len; i++) {
+ args[0] = RARRAY(finalizers)->ptr[i];
if (!args[1]) args[1] = rb_ary_new3(1, objid);
- rb_protect((VALUE(*)(VALUE))run_single_final, (VALUE)args, &status);
+ rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status);
}
if (finalizer_table && st_delete(finalizer_table, (st_data_t*)&obj, &table)) {
- for (i=0; i<RARRAY_LEN(table); i++) {
- VALUE final = RARRAY_PTR(table)[i];
- args[0] = RARRAY_PTR(final)[1];
+ for (i=0; i<RARRAY(table)->len; i++) {
+ VALUE final = RARRAY(table)->ptr[i];
+ args[0] = RARRAY(final)->ptr[1];
if (!args[1]) args[1] = rb_ary_new3(1, objid);
- args[2] = FIX2INT(RARRAY_PTR(final)[0]);
- rb_protect((VALUE(*)(VALUE))run_single_final, (VALUE)args, &status);
+ args[2] = FIX2INT(RARRAY(final)->ptr[0]);
+ rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status);
}
}
rb_thread_critical = critical_save;
}
void
-rb_gc_finalize_deferred(void)
+rb_gc_finalize_deferred()
{
RVALUE *p = deferred_final_list;
- during_gc++;
deferred_final_list = 0;
if (p) {
finalize_list(p);
+ free_unused_heaps();
}
- free_unused_heaps();
- during_gc = 0;
}
void
-rb_gc_call_finalizer_at_exit(void)
+rb_gc_call_finalizer_at_exit()
{
RVALUE *p, *pend;
int i;
- /* finalizers are part of garbage collection */
- during_gc++;
/* run finalizers */
if (need_call_final) {
p = deferred_final_list;
@@ -1902,8 +1902,7 @@ rb_gc_call_finalizer_at_exit(void)
p = heaps[i].slot; pend = p + heaps[i].limit;
while (p < pend) {
if (BUILTIN_TYPE(p) == T_DATA &&
- DATA_PTR(p) && RANY(p)->as.data.dfree &&
- RANY(p)->as.basic.klass != rb_cThread) {
+ DATA_PTR(p) && RANY(p)->as.data.dfree) {
p->as.free.flags = 0;
if ((long)RANY(p)->as.data.dfree == -1) {
RUBY_CRITICAL(free(DATA_PTR(p)));
@@ -1913,14 +1912,12 @@ rb_gc_call_finalizer_at_exit(void)
}
}
else if (BUILTIN_TYPE(p) == T_FILE) {
- if (rb_io_fptr_finalize(RANY(p)->as.file.fptr)) {
- p->as.free.flags = 0;
- }
+ p->as.free.flags = 0;
+ rb_io_fptr_finalize(RANY(p)->as.file.fptr);
}
p++;
}
}
- during_gc = 0;
}
/*
@@ -1937,20 +1934,14 @@ rb_gc_call_finalizer_at_exit(void)
*/
static VALUE
-id2ref(VALUE obj, VALUE objid)
+id2ref(obj, objid)
+ VALUE obj, objid;
{
-#if SIZEOF_LONG == SIZEOF_VOIDP
-#define NUM2PTR(x) NUM2ULONG(x)
-#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
-#define NUM2PTR(x) NUM2ULL(x)
-#endif
- VALUE ptr;
- void *p0;
+ unsigned long ptr, p0;
+ int type;
rb_secure(4);
- ptr = NUM2PTR(objid);
- p0 = (void *)ptr;
-
+ p0 = ptr = NUM2ULONG(objid);
if (ptr == Qtrue) return Qtrue;
if (ptr == Qfalse) return Qfalse;
if (ptr == Qnil) return Qnil;
@@ -1964,11 +1955,12 @@ id2ref(VALUE obj, VALUE objid)
return ID2SYM(symid);
}
- if (!is_pointer_to_heap((void *)ptr)|| BUILTIN_TYPE(ptr) >= T_BLOCK) {
- rb_raise(rb_eRangeError, "%p is not id value", p0);
+ if (!is_pointer_to_heap((void *)ptr)||
+ (type = BUILTIN_TYPE(ptr)) >= T_BLKTAG || type == T_ICLASS) {
+ rb_raise(rb_eRangeError, "0x%lx is not id value", p0);
}
if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0) {
- rb_raise(rb_eRangeError, "%p is recycled object", p0);
+ rb_raise(rb_eRangeError, "0x%lx is recycled object", p0);
}
return (VALUE)ptr;
}
@@ -2031,6 +2023,9 @@ rb_obj_id(VALUE obj)
* 24 if 32-bit, double is 8-byte aligned
* 40 if 64-bit
*/
+ if (TYPE(obj) == T_SYMBOL) {
+ return (SYM2ID(obj) * sizeof(RVALUE) + (4 << 2)) | FIXNUM_FLAG;
+ }
if (SPECIAL_CONST_P(obj)) {
return LONG2NUM((long)obj);
}
@@ -2044,7 +2039,7 @@ rb_obj_id(VALUE obj)
*/
void
-Init_GC(void)
+Init_GC()
{
VALUE rb_mObSpace;
@@ -2052,8 +2047,6 @@ Init_GC(void)
rb_define_singleton_method(rb_mGC, "start", rb_gc_start, 0);
rb_define_singleton_method(rb_mGC, "enable", rb_gc_enable, 0);
rb_define_singleton_method(rb_mGC, "disable", rb_gc_disable, 0);
- rb_define_singleton_method(rb_mGC, "stress", gc_stress_get, 0);
- rb_define_singleton_method(rb_mGC, "stress=", gc_stress_set, 1);
rb_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0);
rb_mObSpace = rb_define_module("ObjectSpace");
@@ -2077,9 +2070,12 @@ Init_GC(void)
source_filenames = st_init_strtable();
rb_global_variable(&nomem_error);
- nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory");
+ 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);
- rb_define_method(rb_cBasicObject, "__id__", rb_obj_id, 0);
- rb_define_method(rb_cBasicObject, "object_id", rb_obj_id, 0);
rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
+ rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0);
+ rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0);
}
diff --git a/hash.c b/hash.c
index 5f578fa299..557e3c8b5a 100644
--- a/hash.c
+++ b/hash.c
@@ -24,8 +24,19 @@
#define HASH_DELETED FL_USER1
#define HASH_PROC_DEFAULT FL_USER2
+static void
+rb_hash_modify(hash)
+ VALUE hash;
+{
+ if (!RHASH(hash)->tbl) rb_raise(rb_eTypeError, "uninitialized Hash");
+ if (OBJ_FROZEN(hash)) rb_error_frozen("hash");
+ if (!OBJ_TAINTED(hash) && rb_safe_level() >= 4)
+ rb_raise(rb_eSecurityError, "Insecure: can't modify hash");
+}
+
VALUE
-rb_hash_freeze(VALUE hash)
+rb_hash_freeze(hash)
+ VALUE hash;
{
return rb_obj_freeze(hash);
}
@@ -33,16 +44,18 @@ rb_hash_freeze(VALUE hash)
VALUE rb_cHash;
static VALUE envtbl;
-static ID id_hash, id_yield, id_default;
+static ID id_hash, id_call, id_default;
static VALUE
-eql(VALUE *args)
+eql(args)
+ VALUE *args;
{
return (VALUE)rb_eql(args[0], args[1]);
}
static int
-rb_any_cmp(VALUE a, VALUE b)
+rb_any_cmp(a, b)
+ VALUE a, b;
{
VALUE args[2];
@@ -65,13 +78,15 @@ rb_any_cmp(VALUE a, VALUE b)
}
VALUE
-rb_hash(VALUE obj)
+rb_hash(obj)
+ VALUE obj;
{
return rb_funcall(obj, id_hash, 0);
}
static int
-rb_any_hash(VALUE a)
+rb_any_hash(a)
+ VALUE a;
{
VALUE hval;
@@ -106,7 +121,9 @@ struct foreach_safe_arg {
};
static int
-foreach_safe_i(st_data_t key, st_data_t value, struct foreach_safe_arg *arg)
+foreach_safe_i(key, value, arg)
+ st_data_t key, value;
+ struct foreach_safe_arg *arg;
{
int status;
@@ -119,7 +136,10 @@ foreach_safe_i(st_data_t key, st_data_t value, struct foreach_safe_arg *arg)
}
void
-st_foreach_safe(st_table *table, int (*func)(ANYARGS), st_data_t a)
+st_foreach_safe(table, func, a)
+ st_table *table;
+ int (*func)();
+ st_data_t a;
{
struct foreach_safe_arg arg;
@@ -138,12 +158,14 @@ struct hash_foreach_arg {
};
static int
-hash_foreach_iter(VALUE key, VALUE value, struct hash_foreach_arg *arg)
+hash_foreach_iter(key, value, arg)
+ VALUE key, value;
+ struct hash_foreach_arg *arg;
{
int status;
st_table *tbl;
- tbl = RHASH(arg->hash)->tbl;
+ tbl = RHASH(arg->hash)->tbl;
if (key == Qundef) return ST_CONTINUE;
status = (*arg->func)(key, value, arg->arg);
if (RHASH(arg->hash)->tbl != tbl) {
@@ -151,18 +173,19 @@ hash_foreach_iter(VALUE key, VALUE value, struct hash_foreach_arg *arg)
}
switch (status) {
case ST_DELETE:
- st_delete_safe(tbl, (st_data_t*)&key, 0, Qundef);
+ st_delete_safe(tbl, (st_data_t*)&key, 0, Qundef);
FL_SET(arg->hash, HASH_DELETED);
case ST_CONTINUE:
- break;
+ break;
case ST_STOP:
- return ST_STOP;
+ return ST_STOP;
}
return ST_CHECK;
}
static VALUE
-hash_foreach_ensure(VALUE hash)
+hash_foreach_ensure(hash)
+ VALUE hash;
{
RHASH(hash)->iter_lev--;
@@ -176,7 +199,8 @@ hash_foreach_ensure(VALUE hash)
}
static VALUE
-hash_foreach_call(struct hash_foreach_arg *arg)
+hash_foreach_call(arg)
+ struct hash_foreach_arg *arg;
{
if (st_foreach(RHASH(arg->hash)->tbl, hash_foreach_iter, (st_data_t)arg)) {
rb_raise(rb_eRuntimeError, "hash modified during iteration");
@@ -185,7 +209,10 @@ hash_foreach_call(struct hash_foreach_arg *arg)
}
void
-rb_hash_foreach(VALUE hash, int (*func)(ANYARGS), VALUE farg)
+rb_hash_foreach(hash, func, farg)
+ VALUE hash;
+ int (*func)();
+ VALUE farg;
{
struct hash_foreach_arg arg;
@@ -196,8 +223,11 @@ rb_hash_foreach(VALUE hash, int (*func)(ANYARGS), VALUE farg)
rb_ensure(hash_foreach_call, (VALUE)&arg, hash_foreach_ensure, hash);
}
+static VALUE hash_alloc0 _((VALUE));
+static VALUE hash_alloc _((VALUE));
static VALUE
-hash_alloc0(VALUE klass)
+hash_alloc0(klass)
+ VALUE klass;
{
NEWOBJ(hash, struct RHash);
OBJSETUP(hash, klass, T_HASH);
@@ -208,7 +238,8 @@ hash_alloc0(VALUE klass)
}
static VALUE
-hash_alloc(VALUE klass)
+hash_alloc(klass)
+ VALUE klass;
{
VALUE hash = hash_alloc0(klass);
@@ -218,20 +249,11 @@ hash_alloc(VALUE klass)
}
VALUE
-rb_hash_new(void)
+rb_hash_new()
{
return hash_alloc(rb_cHash);
}
-static void
-rb_hash_modify(VALUE hash)
-{
- if (!RHASH(hash)->tbl) rb_raise(rb_eTypeError, "uninitialized Hash");
- if (OBJ_FROZEN(hash)) rb_error_frozen("hash");
- if (!OBJ_TAINTED(hash) && rb_safe_level() >= 4)
- rb_raise(rb_eSecurityError, "Insecure: can't modify hash");
-}
-
/*
* call-seq:
* Hash.new => hash
@@ -268,7 +290,10 @@ rb_hash_modify(VALUE hash)
*/
static VALUE
-rb_hash_initialize(int argc, VALUE *argv, VALUE hash)
+rb_hash_initialize(argc, argv, hash)
+ int argc;
+ VALUE *argv;
+ VALUE hash;
{
VALUE ifnone;
@@ -302,7 +327,10 @@ rb_hash_initialize(int argc, VALUE *argv, VALUE hash)
*/
static VALUE
-rb_hash_s_create(int argc, VALUE *argv, VALUE klass)
+rb_hash_s_create(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE hash;
int i;
@@ -327,13 +355,16 @@ rb_hash_s_create(int argc, VALUE *argv, VALUE klass)
}
static VALUE
-to_hash(VALUE hash)
+to_hash(hash)
+ VALUE hash;
{
return rb_convert_type(hash, T_HASH, "Hash", "to_hash");
}
static int
-rb_hash_rehash_i(VALUE key, VALUE value, st_table *tbl)
+rb_hash_rehash_i(key, value, tbl)
+ VALUE key, value;
+ st_table *tbl;
{
if (key != Qundef) st_insert(tbl, key, value);
return ST_CONTINUE;
@@ -347,7 +378,7 @@ rb_hash_rehash_i(VALUE key, VALUE value, st_table *tbl)
* values of key objects have changed since they were inserted, this
* method will reindex <i>hsh</i>. If <code>Hash#rehash</code> is
* called while an iterator is traversing the hash, an
- * <code>RuntimeError</code> will be raised in the iterator.
+ * <code>IndexError</code> will be raised in the iterator.
*
* a = [ "a", "b" ]
* c = [ "c", "d" ]
@@ -360,15 +391,13 @@ rb_hash_rehash_i(VALUE key, VALUE value, st_table *tbl)
*/
static VALUE
-rb_hash_rehash(VALUE hash)
+rb_hash_rehash(hash)
+ VALUE hash;
{
st_table *tbl;
- if (RHASH(hash)->iter_lev > 0) {
- rb_raise(rb_eRuntimeError, "rehash during iteration");
- }
rb_hash_modify(hash);
- tbl = st_init_table_with_size(RHASH(hash)->tbl->type, RHASH(hash)->tbl->num_entries);
+ tbl = st_init_table_with_size(&objhash, RHASH(hash)->tbl->num_entries);
rb_hash_foreach(hash, rb_hash_rehash_i, (st_data_t)tbl);
st_free_table(RHASH(hash)->tbl);
RHASH(hash)->tbl = tbl;
@@ -391,7 +420,8 @@ rb_hash_rehash(VALUE hash)
*/
VALUE
-rb_hash_aref(VALUE hash, VALUE key)
+rb_hash_aref(hash, key)
+ VALUE hash, key;
{
VALUE val;
@@ -408,7 +438,7 @@ rb_hash_aref(VALUE hash, VALUE key)
*
* Returns a value from the hash for the given key. If the key can't be
* found, there are several options: With no other arguments, it will
- * raise an <code>KeyError</code> exception; if <i>default</i> is
+ * raise an <code>IndexError</code> exception; if <i>default</i> is
* given, then that will be returned; if the optional code block is
* specified, then that will be run and its result returned.
*
@@ -425,13 +455,16 @@ rb_hash_aref(VALUE hash, VALUE key)
*
* <em>produces:</em>
*
- * prog.rb:2:in `fetch': key not found (KeyError)
+ * prog.rb:2:in `fetch': key not found (IndexError)
* from prog.rb:2
*
*/
static VALUE
-rb_hash_fetch(int argc, VALUE *argv, VALUE hash)
+rb_hash_fetch(argc, argv, hash)
+ int argc;
+ VALUE *argv;
+ VALUE hash;
{
VALUE key, if_none;
VALUE val;
@@ -446,7 +479,7 @@ rb_hash_fetch(int argc, VALUE *argv, VALUE hash)
if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
if (block_given) return rb_yield(key);
if (argc == 1) {
- rb_raise(rb_eKeyError, "key not found");
+ rb_raise(rb_eIndexError, "key not found");
}
return if_none;
}
@@ -475,14 +508,17 @@ rb_hash_fetch(int argc, VALUE *argv, VALUE hash)
*/
static VALUE
-rb_hash_default(int argc, VALUE *argv, VALUE hash)
+rb_hash_default(argc, argv, hash)
+ int argc;
+ VALUE *argv;
+ VALUE hash;
{
VALUE key;
rb_scan_args(argc, argv, "01", &key);
if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
if (argc == 0) return Qnil;
- return rb_funcall(RHASH(hash)->ifnone, id_yield, 2, hash, key);
+ return rb_funcall(RHASH(hash)->ifnone, id_call, 2, hash, key);
}
return RHASH(hash)->ifnone;
}
@@ -508,7 +544,8 @@ rb_hash_default(int argc, VALUE *argv, VALUE hash)
*/
static VALUE
-rb_hash_set_default(VALUE hash, VALUE ifnone)
+rb_hash_set_default(hash, ifnone)
+ VALUE hash, ifnone;
{
rb_hash_modify(hash);
RHASH(hash)->ifnone = ifnone;
@@ -532,7 +569,8 @@ rb_hash_set_default(VALUE hash, VALUE ifnone)
static VALUE
-rb_hash_default_proc(VALUE hash)
+rb_hash_default_proc(hash)
+ VALUE hash;
{
if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
return RHASH(hash)->ifnone;
@@ -541,7 +579,9 @@ rb_hash_default_proc(VALUE hash)
}
static int
-key_i(VALUE key, VALUE value, VALUE *args)
+index_i(key, value, args)
+ VALUE key, value;
+ VALUE *args;
{
if (rb_equal(value, args[0])) {
args[1] = key;
@@ -550,37 +590,75 @@ key_i(VALUE key, VALUE value, 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.key(value) => key
+ * hsh.index(value) => key
*
* Returns the key for a given value. If not found, returns <code>nil</code>.
*
* h = { "a" => 100, "b" => 200 }
- * h.key(200) #=> "b"
- * h.key(999) #=> nil
+ * h.index(200) #=> "b"
+ * h.index(999) #=> nil
*
*/
static VALUE
-rb_hash_key(VALUE hash, VALUE value)
+rb_hash_index(hash, value)
+ VALUE hash, value;
{
VALUE args[2];
args[0] = value;
args[1] = Qnil;
- rb_hash_foreach(hash, key_i, (st_data_t)args);
+ rb_hash_foreach(hash, index_i, (st_data_t)args);
return args[1];
}
-/* :nodoc: */
+/*
+ * call-seq:
+ * hsh.indexes(key, ...) => array
+ * hsh.indices(key, ...) => array
+ *
+ * Deprecated in favor of <code>Hash#select</code>.
+ *
+ */
+
static VALUE
-rb_hash_index(VALUE hash, VALUE value)
+rb_hash_indexes(argc, argv, hash)
+ int argc;
+ VALUE *argv;
+ VALUE hash;
{
- rb_warn("Hash#index is deprecated; use Hash#key");
- return rb_hash_key(hash, value);
+ VALUE indexes;
+ int i;
+
+ rb_warn("Hash#%s is deprecated; use Hash#values_at",
+ rb_id2name(rb_frame_last_func()));
+ indexes = rb_ary_new2(argc);
+ for (i=0; i<argc; i++) {
+ RARRAY(indexes)->ptr[i] = rb_hash_aref(hash, argv[i]);
+ RARRAY(indexes)->len++;
+ }
+ return indexes;
}
/*
@@ -602,19 +680,14 @@ rb_hash_index(VALUE hash, VALUE value)
*/
VALUE
-rb_hash_delete(VALUE hash, VALUE key)
+rb_hash_delete(hash, key)
+ VALUE hash, key;
{
VALUE val;
rb_hash_modify(hash);
- 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;
+ val = rb_hash_delete_key(hash, key);
+ if (val != Qundef) return val;
if (rb_block_given_p()) {
return rb_yield(key);
}
@@ -622,22 +695,33 @@ rb_hash_delete(VALUE hash, VALUE key)
}
struct shift_var {
- int stop;
VALUE key;
VALUE val;
};
static int
-shift_i(VALUE key, VALUE value, struct shift_var *var)
+shift_i(key, value, var)
+ VALUE key, value;
+ struct shift_var *var;
{
if (key == Qundef) return ST_CONTINUE;
- if (var->stop) return ST_STOP;
- var->stop = 1;
+ if (var->key != Qundef) return ST_STOP;
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
@@ -652,19 +736,31 @@ shift_i(VALUE key, VALUE value, struct shift_var *var)
*/
static VALUE
-rb_hash_shift(VALUE hash)
+rb_hash_shift(hash)
+ VALUE hash;
{
struct shift_var var;
rb_hash_modify(hash);
- var.stop = 0;
- rb_hash_foreach(hash, shift_i, (st_data_t)&var);
+ 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);
+ }
- if (var.stop) {
+ if (var.key != Qundef) {
return rb_assoc_new(var.key, var.val);
}
else if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
- return rb_funcall(RHASH(hash)->ifnone, id_yield, 2, hash, Qnil);
+ return rb_funcall(RHASH(hash)->ifnone, id_call, 2, hash, Qnil);
}
else {
return RHASH(hash)->ifnone;
@@ -672,11 +768,12 @@ rb_hash_shift(VALUE hash)
}
static int
-delete_if_i(VALUE key, VALUE value, VALUE hash)
+delete_if_i(key, value, hash)
+ VALUE key, value, hash;
{
if (key == Qundef) return ST_CONTINUE;
if (RTEST(rb_yield_values(2, key, value))) {
- rb_hash_delete(hash, key);
+ rb_hash_delete_key(hash, key);
}
return ST_CONTINUE;
}
@@ -694,7 +791,8 @@ delete_if_i(VALUE key, VALUE value, VALUE hash)
*/
VALUE
-rb_hash_delete_if(VALUE hash)
+rb_hash_delete_if(hash)
+ VALUE hash;
{
rb_hash_modify(hash);
rb_hash_foreach(hash, delete_if_i, hash);
@@ -710,7 +808,8 @@ rb_hash_delete_if(VALUE hash)
*/
VALUE
-rb_hash_reject_bang(VALUE hash)
+rb_hash_reject_bang(hash)
+ VALUE hash;
{
int n = RHASH(hash)->tbl->num_entries;
rb_hash_delete_if(hash);
@@ -729,13 +828,15 @@ rb_hash_reject_bang(VALUE hash)
*/
static VALUE
-rb_hash_reject(VALUE hash)
+rb_hash_reject(hash)
+ VALUE hash;
{
return rb_hash_delete_if(rb_obj_dup(hash));
}
static int
-select_i(VALUE key, VALUE value, VALUE result)
+select_i(key, value, result)
+ VALUE key, value, result;
{
if (key == Qundef) return ST_CONTINUE;
if (RTEST(rb_yield_values(2, key, value)))
@@ -755,9 +856,12 @@ select_i(VALUE key, VALUE value, VALUE result)
*/
VALUE
-rb_hash_values_at(int argc, VALUE *argv, VALUE hash)
+rb_hash_values_at(argc, argv, hash)
+ int argc;
+ VALUE *argv;
+ VALUE hash;
{
- VALUE result = rb_ary_new2(argc);
+ VALUE result = rb_ary_new();
long i;
for (i=0; i<argc; i++) {
@@ -780,18 +884,24 @@ rb_hash_values_at(int argc, VALUE *argv, VALUE hash)
*/
VALUE
-rb_hash_select(VALUE hash)
+rb_hash_select(argc, argv, hash)
+ int argc;
+ VALUE *argv;
+ VALUE hash;
{
VALUE result;
- RETURN_ENUMERATOR(hash, 0, 0);
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
+ }
result = rb_ary_new();
rb_hash_foreach(hash, select_i, result);
return result;
}
static int
-clear_i(VALUE key, VALUE value, VALUE dummy)
+clear_i(key, value, dummy)
+ VALUE key, value, dummy;
{
return ST_DELETE;
}
@@ -808,7 +918,8 @@ clear_i(VALUE key, VALUE value, VALUE dummy)
*/
static VALUE
-rb_hash_clear(VALUE hash)
+rb_hash_clear(hash)
+ VALUE hash;
{
rb_hash_modify(hash);
if (RHASH(hash)->tbl->num_entries > 0) {
@@ -837,7 +948,8 @@ rb_hash_clear(VALUE hash)
*/
VALUE
-rb_hash_aset(VALUE hash, VALUE key, VALUE val)
+rb_hash_aset(hash, key, val)
+ VALUE hash, key, val;
{
rb_hash_modify(hash);
if (TYPE(key) != T_STRING || st_lookup(RHASH(hash)->tbl, key, 0)) {
@@ -850,7 +962,8 @@ rb_hash_aset(VALUE hash, VALUE key, VALUE val)
}
static int
-replace_i(VALUE key, VALUE val, VALUE hash)
+replace_i(key, val, hash)
+ VALUE key, val, hash;
{
if (key != Qundef) {
rb_hash_aset(hash, key, val);
@@ -872,7 +985,8 @@ replace_i(VALUE key, VALUE val, VALUE hash)
*/
static VALUE
-rb_hash_replace(VALUE hash, VALUE hash2)
+rb_hash_replace(hash, hash2)
+ VALUE hash, hash2;
{
hash2 = to_hash(hash2);
if (hash == hash2) return hash;
@@ -903,7 +1017,8 @@ rb_hash_replace(VALUE hash, VALUE hash2)
*/
static VALUE
-rb_hash_size(VALUE hash)
+rb_hash_size(hash)
+ VALUE hash;
{
return INT2FIX(RHASH(hash)->tbl->num_entries);
}
@@ -920,7 +1035,8 @@ rb_hash_size(VALUE hash)
*/
static VALUE
-rb_hash_empty_p(VALUE hash)
+rb_hash_empty_p(hash)
+ VALUE hash;
{
if (RHASH(hash)->tbl->num_entries == 0)
return Qtrue;
@@ -928,7 +1044,8 @@ rb_hash_empty_p(VALUE hash)
}
static int
-each_value_i(VALUE key, VALUE value)
+each_value_i(key, value)
+ VALUE key, value;
{
if (key == Qundef) return ST_CONTINUE;
rb_yield(value);
@@ -952,15 +1069,16 @@ each_value_i(VALUE key, VALUE value)
*/
static VALUE
-rb_hash_each_value(VALUE hash)
+rb_hash_each_value(hash)
+ VALUE hash;
{
- RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_value_i, 0);
return hash;
}
static int
-each_key_i(VALUE key, VALUE value)
+each_key_i(key, value)
+ VALUE key, value;
{
if (key == Qundef) return ST_CONTINUE;
rb_yield(key);
@@ -983,18 +1101,19 @@ each_key_i(VALUE key, VALUE value)
* b
*/
static VALUE
-rb_hash_each_key(VALUE hash)
+rb_hash_each_key(hash)
+ VALUE hash;
{
- RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_key_i, 0);
return hash;
}
static int
-each_pair_i(VALUE key, VALUE value)
+each_pair_i(key, value)
+ VALUE key, value;
{
if (key == Qundef) return ST_CONTINUE;
- rb_yield(rb_assoc_new(key, value));
+ rb_yield_values(2, key, value);
return ST_CONTINUE;
}
@@ -1002,11 +1121,11 @@ each_pair_i(VALUE key, VALUE value)
* call-seq:
* hsh.each_pair {| key_value_array | block } -> hsh
*
- * Calls <i>block</i> once for each key in <i>hsh</i>, passing the
- * key and value to the block as a two-element array.
+ * Calls <i>block</i> once for each key in <i>hsh</i>, passing the key
+ * and value as parameters.
*
* h = { "a" => 100, "b" => 200 }
- * h.each_pair {|(key, value)| puts "#{key} is #{value}" }
+ * h.each_pair {|key, value| puts "#{key} is #{value}" }
*
* <em>produces:</em>
*
@@ -1016,18 +1135,19 @@ each_pair_i(VALUE key, VALUE value)
*/
static VALUE
-rb_hash_each_pair(VALUE hash)
+rb_hash_each_pair(hash)
+ VALUE hash;
{
- RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_pair_i, 0);
return hash;
}
static int
-each_i(VALUE key, VALUE value)
+each_i(key, value)
+ VALUE key, value;
{
if (key == Qundef) return ST_CONTINUE;
- rb_yield_values(2, key, value);
+ rb_yield(rb_assoc_new(key, value));
return ST_CONTINUE;
}
@@ -1035,9 +1155,11 @@ each_i(VALUE key, VALUE value)
* call-seq:
* hsh.each {| key, value | block } -> hsh
*
- * Calls <i>block</i> once for each key in <i>hsh</i>, passing the key-value
- * pair as parameters. Also see <code>Hash#each_pair</code>, which
- * passes the key and value to the block as a two-element array.
+ * Calls <i>block</i> once for each key in <i>hsh</i>, passing the key
+ * and value to the block as a two-element array. Because of the assignment
+ * semantics of block parameters, these elements will be split out if the
+ * block has two formal parameters. Also see <code>Hash.each_pair</code>, which
+ * will be marginally more efficient for blocks with two parameters.
*
* h = { "a" => 100, "b" => 200 }
* h.each {|key, value| puts "#{key} is #{value}" }
@@ -1050,15 +1172,16 @@ each_i(VALUE key, VALUE value)
*/
static VALUE
-rb_hash_each(VALUE hash)
+rb_hash_each(hash)
+ VALUE hash;
{
- RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_i, 0);
return hash;
}
static int
-to_a_i(VALUE key, VALUE value, VALUE ary)
+to_a_i(key, value, ary)
+ VALUE key, value, ary;
{
if (key == Qundef) return ST_CONTINUE;
rb_ary_push(ary, rb_assoc_new(key, value));
@@ -1077,7 +1200,8 @@ to_a_i(VALUE key, VALUE value, VALUE ary)
*/
static VALUE
-rb_hash_to_a(VALUE hash)
+rb_hash_to_a(hash)
+ VALUE hash;
{
VALUE ary;
@@ -1104,7 +1228,8 @@ rb_hash_to_a(VALUE hash)
*/
static VALUE
-rb_hash_sort(VALUE hash)
+rb_hash_sort(hash)
+ VALUE hash;
{
VALUE entries = rb_hash_to_a(hash);
rb_ary_sort_bang(entries);
@@ -1112,12 +1237,13 @@ rb_hash_sort(VALUE hash)
}
static int
-inspect_i(VALUE key, VALUE value, VALUE str)
+inspect_i(key, value, str)
+ VALUE key, value, str;
{
VALUE str2;
if (key == Qundef) return ST_CONTINUE;
- if (RSTRING_LEN(str) > 1) {
+ if (RSTRING(str)->len > 1) {
rb_str_cat2(str, ", ");
}
str2 = rb_inspect(key);
@@ -1132,11 +1258,11 @@ inspect_i(VALUE key, VALUE value, VALUE str)
}
static VALUE
-inspect_hash(VALUE hash, VALUE dummy, int recur)
+inspect_hash(hash)
+ VALUE hash;
{
VALUE str;
- if (recur) return rb_str_new2("{...}");
str = rb_str_buf_new2("{");
rb_hash_foreach(hash, inspect_i, str);
rb_str_buf_cat2(str, "}");
@@ -1147,21 +1273,47 @@ inspect_hash(VALUE hash, VALUE dummy, int recur)
/*
* call-seq:
- * hsh.to_s => string
* hsh.inspect => string
*
* Return the contents of this hash as a string.
- *
- * h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
- * h.to_s #=> "{\"a\"=>100, \"c\"=>300, \"d\"=>400}"
*/
static VALUE
-rb_hash_inspect(VALUE hash)
+rb_hash_inspect(hash)
+ VALUE hash;
{
if (RHASH(hash)->tbl == 0 || RHASH(hash)->tbl->num_entries == 0)
return rb_str_new2("{}");
- return rb_exec_recursive(inspect_hash, hash, 0);
+ if (rb_inspecting_p(hash)) return rb_str_new2("{...}");
+ return rb_protect_inspect(inspect_hash, hash, 0);
+}
+
+static VALUE
+to_s_hash(hash)
+ VALUE hash;
+{
+ return rb_ary_to_s(rb_hash_to_a(hash));
+}
+
+/*
+ * call-seq:
+ * hsh.to_s => string
+ *
+ * Converts <i>hsh</i> to a string by converting the hash to an array
+ * of <code>[</code> <i>key, value</i> <code>]</code> pairs and then
+ * converting that array to a string using <code>Array#join</code> with
+ * the default separator.
+ *
+ * h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
+ * h.to_s #=> "a100c300d400"
+ */
+
+static VALUE
+rb_hash_to_s(hash)
+ VALUE hash;
+{
+ if (rb_inspecting_p(hash)) return rb_str_new2("{...}");
+ return rb_protect_inspect(to_s_hash, hash, 0);
}
/*
@@ -1172,13 +1324,15 @@ rb_hash_inspect(VALUE hash)
*/
static VALUE
-rb_hash_to_hash(VALUE hash)
+rb_hash_to_hash(hash)
+ VALUE hash;
{
return hash;
}
static int
-keys_i(VALUE key, VALUE value, VALUE ary)
+keys_i(key, value, ary)
+ VALUE key, value, ary;
{
if (key == Qundef) return ST_CONTINUE;
rb_ary_push(ary, key);
@@ -1198,7 +1352,8 @@ keys_i(VALUE key, VALUE value, VALUE ary)
*/
static VALUE
-rb_hash_keys(VALUE hash)
+rb_hash_keys(hash)
+ VALUE hash;
{
VALUE ary;
@@ -1209,7 +1364,8 @@ rb_hash_keys(VALUE hash)
}
static int
-values_i(VALUE key, VALUE value, VALUE ary)
+values_i(key, value, ary)
+ VALUE key, value, ary;
{
if (key == Qundef) return ST_CONTINUE;
rb_ary_push(ary, value);
@@ -1229,7 +1385,8 @@ values_i(VALUE key, VALUE value, VALUE ary)
*/
static VALUE
-rb_hash_values(VALUE hash)
+rb_hash_values(hash)
+ VALUE hash;
{
VALUE ary;
@@ -1255,7 +1412,9 @@ rb_hash_values(VALUE hash)
*/
static VALUE
-rb_hash_has_key(VALUE hash, VALUE key)
+rb_hash_has_key(hash, key)
+ VALUE hash;
+ VALUE key;
{
if (st_lookup(RHASH(hash)->tbl, key, 0)) {
return Qtrue;
@@ -1264,7 +1423,8 @@ rb_hash_has_key(VALUE hash, VALUE key)
}
static int
-rb_hash_search_value(VALUE key, VALUE value, VALUE *data)
+rb_hash_search_value(key, value, data)
+ VALUE key, value, *data;
{
if (key == Qundef) return ST_CONTINUE;
if (rb_equal(value, data[1])) {
@@ -1288,7 +1448,9 @@ rb_hash_search_value(VALUE key, VALUE value, VALUE *data)
*/
static VALUE
-rb_hash_has_value(VALUE hash, VALUE val)
+rb_hash_has_value(hash, val)
+ VALUE hash;
+ VALUE val;
{
VALUE data[2];
@@ -1304,24 +1466,9 @@ struct equal_data {
};
static int
-eql_i(VALUE key, VALUE val1, struct equal_data *data)
-{
- VALUE val2;
-
- if (key == Qundef) return ST_CONTINUE;
- if (!st_lookup(data->tbl, key, &val2)) {
- data->result = Qfalse;
- return ST_STOP;
- }
- if (!rb_eql(val1, val2)) {
- data->result = Qfalse;
- return ST_STOP;
- }
- return ST_CONTINUE;
-}
-
-static int
-equal_i(VALUE key, VALUE val1, struct equal_data *data)
+equal_i(key, val1, data)
+ VALUE key, val1;
+ struct equal_data *data;
{
VALUE val2;
@@ -1338,7 +1485,9 @@ equal_i(VALUE key, VALUE val1, struct equal_data *data)
}
static VALUE
-hash_equal(VALUE hash1, VALUE hash2, int eql)
+hash_equal(hash1, hash2, eql)
+ VALUE hash1, hash2;
+ int eql; /* compare default value if true */
{
struct equal_data data;
@@ -1351,15 +1500,15 @@ hash_equal(VALUE hash1, VALUE hash2, int eql)
}
if (RHASH(hash1)->tbl->num_entries != RHASH(hash2)->tbl->num_entries)
return Qfalse;
-#if 0
- if (!(rb_equal(RHASH(hash1)->ifnone, RHASH(hash2)->ifnone) &&
- FL_TEST(hash1, HASH_PROC_DEFAULT) == FL_TEST(hash2, HASH_PROC_DEFAULT)))
- return Qfalse;
-#endif
+ if (eql) {
+ if (!(rb_equal(RHASH(hash1)->ifnone, RHASH(hash2)->ifnone) &&
+ FL_TEST(hash1, HASH_PROC_DEFAULT) == FL_TEST(hash2, HASH_PROC_DEFAULT)))
+ return Qfalse;
+ }
data.tbl = RHASH(hash2)->tbl;
data.result = Qtrue;
- rb_hash_foreach(hash1, eql ? eql_i : equal_i, (st_data_t)&data);
+ rb_hash_foreach(hash1, equal_i, (st_data_t)&data);
return data.result;
}
@@ -1384,63 +1533,16 @@ hash_equal(VALUE hash1, VALUE hash2, int eql)
*/
static VALUE
-rb_hash_equal(VALUE hash1, VALUE hash2)
-{
- return hash_equal(hash1, hash2, Qfalse);
-}
-
-/*
- * call-seq:
- * hash.eql?(other) -> true or false
- *
- * Returns <code>true</code> if <i>hash</i> and <i>other</i> are
- * both hashes with the same content.
- */
-
-static VALUE
-rb_hash_eql(VALUE hash1, VALUE hash2)
+rb_hash_equal(hash1, hash2)
+ VALUE hash1, hash2;
{
return hash_equal(hash1, hash2, Qfalse);
}
static int
-hash_i(VALUE key, VALUE val, int *hval)
-{
- if (key == Qundef) return ST_CONTINUE;
- *hval ^= rb_hash(key);
- *hval ^= rb_hash(val);
- return ST_CONTINUE;
-}
-
-static VALUE
-recursive_hash(VALUE hash, VALUE dummy, int recur)
-{
- int hval;
-
- if (recur) {
- return LONG2FIX(0);
- }
- hval = RHASH(hash)->tbl->num_entries;
- rb_hash_foreach(hash, hash_i, (st_data_t)&hval);
- return INT2FIX(hval);
-}
-
-/*
- * call-seq:
- * array.hash -> fixnum
- *
- * Compute a hash-code for this array. Two arrays with the same content
- * will have the same hash code (and will compare using <code>eql?</code>).
- */
-
-static VALUE
-rb_hash_hash(VALUE hash)
-{
- return rb_exec_recursive(recursive_hash, hash, 0);
-}
-
-static int
-rb_hash_invert_i(VALUE key, VALUE value, VALUE hash)
+rb_hash_invert_i(key, value, hash)
+ VALUE key, value;
+ VALUE hash;
{
if (key == Qundef) return ST_CONTINUE;
rb_hash_aset(hash, value, key);
@@ -1460,7 +1562,8 @@ rb_hash_invert_i(VALUE key, VALUE value, VALUE hash)
*/
static VALUE
-rb_hash_invert(VALUE hash)
+rb_hash_invert(hash)
+ VALUE hash;
{
VALUE h = rb_hash_new();
@@ -1469,7 +1572,9 @@ rb_hash_invert(VALUE hash)
}
static int
-rb_hash_update_i(VALUE key, VALUE value, VALUE hash)
+rb_hash_update_i(key, value, hash)
+ VALUE key, value;
+ VALUE hash;
{
if (key == Qundef) return ST_CONTINUE;
rb_hash_aset(hash, key, value);
@@ -1477,7 +1582,9 @@ rb_hash_update_i(VALUE key, VALUE value, VALUE hash)
}
static int
-rb_hash_update_block_i(VALUE key, VALUE value, VALUE hash)
+rb_hash_update_block_i(key, value, hash)
+ VALUE key, value;
+ VALUE hash;
{
if (key == Qundef) return ST_CONTINUE;
if (rb_hash_has_key(hash, key)) {
@@ -1494,21 +1601,17 @@ rb_hash_update_block_i(VALUE key, VALUE value, VALUE hash)
* hsh.merge!(other_hash){|key, oldval, newval| block} => hsh
* hsh.update(other_hash){|key, oldval, newval| block} => hsh
*
- * Adds the contents of <i>other_hash</i> to <i>hsh</i>. If no
- * block is specified entries with duplicate keys are overwritten
- * with the values from <i>other_hash</i>, otherwise the value
- * of each duplicate key is detemined by calling the block with
- * the key, its value in <i>hsh</i> and its value in <i>other_hash</i>.
+ * Adds the contents of <i>other_hash</i> to <i>hsh</i>, overwriting
+ * entries with duplicate keys with those from <i>other_hash</i>.
*
* h1 = { "a" => 100, "b" => 200 }
* h2 = { "b" => 254, "c" => 300 }
* h1.merge!(h2) #=> {"a"=>100, "b"=>254, "c"=>300}
- * h1.merge!(h2) { |key, v1, v2| v1 }
- * #=> {"a"=>100, "b"=>200, "c"=>300}
*/
static VALUE
-rb_hash_update(VALUE hash1, VALUE hash2)
+rb_hash_update(hash1, hash2)
+ VALUE hash1, hash2;
{
hash2 = to_hash(hash2);
if (rb_block_given_p()) {
@@ -1537,59 +1640,12 @@ rb_hash_update(VALUE hash1, VALUE hash2)
*/
static VALUE
-rb_hash_merge(VALUE hash1, VALUE hash2)
+rb_hash_merge(hash1, hash2)
+ VALUE hash1, hash2;
{
return rb_hash_update(rb_obj_dup(hash1), hash2);
}
-static struct st_hash_type identhash = {
- st_numcmp,
- st_numhash,
-};
-
-/*
- * call-seq:
- * hsh.compare_by_identity => hsh
- *
- * Makes <i>hsh</i> to compare its keys by their identity, i.e. it
- * will consider exact same objects as same keys.
- *
- * h1 = { "a" => 100, "b" => 200, :c => "c" }
- * h1["a"] #=> 100
- * h1.compare_by_identity
- * h1.compare_by_identity? #=> true
- * h1["a"] #=> nil # different objects.
- * h1[:c] #=> "c" # same symbols are all same.
- *
- */
-
-static VALUE
-rb_hash_compare_by_id(VALUE hash)
-{
- rb_hash_modify(hash);
- RHASH(hash)->tbl->type = &identhash;
- rb_hash_rehash(hash);
- return hash;
-}
-
-/*
- * call-seq:
- * hsh.compare_by_identity? => true or false
- *
- * Returns <code>true</code> if <i>hsh</i> will compare its keys by
- * their identity. Also see <code>Hash#compare_by_identity</code>.
- *
- */
-
-static VALUE
-rb_hash_compare_by_id_p(VALUE hash)
-{
- if (RHASH(hash)->tbl->type == &identhash) {
- return Qtrue;
- }
- return Qfalse;
-}
-
static int path_tainted = -1;
static char **origenviron;
@@ -1611,7 +1667,9 @@ extern char **environ;
#endif
static VALUE
-env_str_new(const char *ptr, long len)
+env_str_new(ptr, len)
+ const char *ptr;
+ long len;
{
VALUE str = rb_tainted_str_new(ptr, len);
@@ -1620,21 +1678,23 @@ env_str_new(const char *ptr, long len)
}
static VALUE
-env_str_new2(const char *ptr)
+env_str_new2(ptr)
+ const char *ptr;
{
if (!ptr) return Qnil;
return env_str_new(ptr, strlen(ptr));
}
static VALUE
-env_delete(VALUE obj, VALUE name)
+env_delete(obj, name)
+ VALUE obj, name;
{
char *nam, *val;
rb_secure(4);
SafeStringValue(name);
- nam = RSTRING_PTR(name);
- if (strlen(nam) != RSTRING_LEN(name)) {
+ nam = RSTRING(name)->ptr;
+ if (strlen(nam) != RSTRING(name)->len) {
rb_raise(rb_eArgError, "bad environment variable name");
}
val = getenv(nam);
@@ -1656,7 +1716,8 @@ env_delete(VALUE obj, VALUE name)
}
static VALUE
-env_delete_m(VALUE obj, VALUE name)
+env_delete_m(obj, name)
+ VALUE obj, name;
{
VALUE val;
@@ -1666,14 +1727,14 @@ env_delete_m(VALUE obj, VALUE name)
}
static VALUE
-rb_f_getenv(VALUE obj, VALUE name)
+rb_f_getenv(obj, name)
+ VALUE obj, name;
{
char *nam, *env;
- rb_secure(4);
- SafeStringValue(name);
- nam = RSTRING_PTR(name);
- if (strlen(nam) != RSTRING_LEN(name)) {
+ StringValue(name);
+ nam = RSTRING(name)->ptr;
+ if (strlen(nam) != RSTRING(name)->len) {
rb_raise(rb_eArgError, "bad environment variable name");
}
env = getenv(nam);
@@ -1695,28 +1756,29 @@ rb_f_getenv(VALUE obj, VALUE name)
}
static VALUE
-env_fetch(int argc, VALUE *argv)
+env_fetch(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE key, if_none;
long block_given;
char *nam, *env;
- rb_secure(4);
rb_scan_args(argc, argv, "11", &key, &if_none);
block_given = rb_block_given_p();
if (block_given && argc == 2) {
rb_warn("block supersedes default value argument");
}
- SafeStringValue(key);
- nam = RSTRING_PTR(key);
- if (strlen(nam) != RSTRING_LEN(key)) {
+ StringValue(key);
+ nam = RSTRING(key)->ptr;
+ if (strlen(nam) != RSTRING(key)->len) {
rb_raise(rb_eArgError, "bad environment variable name");
}
env = getenv(nam);
if (!env) {
if (block_given) return rb_yield(key);
if (argc == 1) {
- rb_raise(rb_eKeyError, "key not found");
+ rb_raise(rb_eIndexError, "key not found");
}
return if_none;
}
@@ -1730,13 +1792,14 @@ env_fetch(int argc, VALUE *argv)
}
static void
-path_tainted_p(char *path)
+path_tainted_p(path)
+ char *path;
{
path_tainted = rb_path_check(path)?0:1;
}
int
-rb_env_path_tainted(void)
+rb_env_path_tainted()
{
if (path_tainted < 0) {
path_tainted_p(getenv(PATH_ENV));
@@ -1744,9 +1807,9 @@ rb_env_path_tainted(void)
return path_tainted;
}
-#if !defined(_WIN32) && !(defined(HAVE_SETENV) && defined(HAVE_UNSETENV))
static int
-envix(const char *nam)
+envix(nam)
+ const char *nam;
{
register int i, len = strlen(nam);
char **env;
@@ -1765,10 +1828,11 @@ envix(const char *nam)
FREE_ENVIRON(environ);
return i;
}
-#endif
void
-ruby_setenv(const char *name, const char *value)
+ruby_setenv(name, value)
+ const char *name;
+ const char *value;
{
#if defined(_WIN32)
/* The sane way to deal with the environment.
@@ -1848,13 +1912,15 @@ ruby_setenv(const char *name, const char *value)
}
void
-ruby_unsetenv(const char *name)
+ruby_unsetenv(name)
+ const char *name;
{
ruby_setenv(name, 0);
}
static VALUE
-env_aset(VALUE obj, VALUE nm, VALUE val)
+env_aset(obj, nm, val)
+ VALUE obj, nm, val;
{
char *name, *value;
@@ -1863,15 +1929,17 @@ env_aset(VALUE obj, VALUE nm, VALUE val)
}
if (NIL_P(val)) {
- rb_raise(rb_eTypeError, "cannot assign nil; use Hash#delete instead");
+ env_delete(obj, nm);
+ return Qnil;
}
+
StringValue(nm);
StringValue(val);
- name = RSTRING_PTR(nm);
- value = RSTRING_PTR(val);
- if (strlen(name) != RSTRING_LEN(nm))
+ name = RSTRING(nm)->ptr;
+ value = RSTRING(val)->ptr;
+ if (strlen(name) != RSTRING(nm)->len)
rb_raise(rb_eArgError, "bad environment variable name");
- if (strlen(value) != RSTRING_LEN(val))
+ if (strlen(value) != RSTRING(val)->len)
rb_raise(rb_eArgError, "bad environment variable value");
ruby_setenv(name, value);
@@ -1893,13 +1961,11 @@ env_aset(VALUE obj, VALUE nm, VALUE val)
}
static VALUE
-env_keys(void)
+env_keys()
{
char **env;
- VALUE ary;
+ VALUE ary = rb_ary_new();
- rb_secure(4);
- ary = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -1913,28 +1979,24 @@ env_keys(void)
}
static VALUE
-env_each_key(VALUE ehash)
+env_each_key(ehash)
+ VALUE ehash;
{
- VALUE keys;
+ VALUE keys = env_keys();
long i;
- RETURN_ENUMERATOR(ehash, 0, 0);
- rb_secure(4);
- keys = env_keys();
- for (i=0; i<RARRAY_LEN(keys); i++) {
- rb_yield(RARRAY_PTR(keys)[i]);
+ for (i=0; i<RARRAY(keys)->len; i++) {
+ rb_yield(RARRAY(keys)->ptr[i]);
}
return ehash;
}
static VALUE
-env_values(void)
+env_values()
{
- VALUE ary;
char **env;
+ VALUE ary = rb_ary_new();
- rb_secure(4);
- ary = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -1948,29 +2010,27 @@ env_values(void)
}
static VALUE
-env_each_value(VALUE ehash)
+env_each_value(ehash)
+ VALUE ehash;
{
VALUE values = env_values();
long i;
- RETURN_ENUMERATOR(ehash, 0, 0);
- rb_secure(4);
- values = env_values();
- for (i=0; i<RARRAY_LEN(values); i++) {
- rb_yield(RARRAY_PTR(values)[i]);
+ for (i=0; i<RARRAY(values)->len; i++) {
+ rb_yield(RARRAY(values)->ptr[i]);
}
return ehash;
}
static VALUE
-env_each_i(VALUE ehash, int values)
+env_each_i(ehash, values)
+ VALUE ehash;
+ int values;
{
char **env;
- VALUE ary;
+ VALUE ary = rb_ary_new();
long i;
- rb_secure(4);
- ary = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -1982,33 +2042,33 @@ env_each_i(VALUE ehash, int values)
}
FREE_ENVIRON(environ);
- for (i=0; i<RARRAY_LEN(ary); i+=2) {
+ for (i=0; i<RARRAY(ary)->len; i+=2) {
if (values) {
- rb_yield_values(2, RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]);
+ rb_yield_values(2, RARRAY(ary)->ptr[i], RARRAY(ary)->ptr[i+1]);
}
else {
- rb_yield(rb_assoc_new(RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]));
+ rb_yield(rb_assoc_new(RARRAY(ary)->ptr[i], RARRAY(ary)->ptr[i+1]));
}
}
return ehash;
}
static VALUE
-env_each(VALUE ehash)
+env_each(ehash)
+ VALUE ehash;
{
- RETURN_ENUMERATOR(ehash, 0, 0);
- return env_each_i(ehash, Qtrue);
+ return env_each_i(ehash, Qfalse);
}
static VALUE
-env_each_pair(VALUE ehash)
+env_each_pair(ehash)
+ VALUE ehash;
{
- RETURN_ENUMERATOR(ehash, 0, 0);
- return env_each_i(ehash, Qfalse);
+ return env_each_i(ehash, Qtrue);
}
static VALUE
-env_reject_bang(void)
+env_reject_bang()
{
volatile VALUE keys;
long i;
@@ -2016,12 +2076,13 @@ env_reject_bang(void)
rb_secure(4);
keys = env_keys();
- for (i=0; i<RARRAY_LEN(keys); i++) {
- VALUE val = rb_f_getenv(Qnil, RARRAY_PTR(keys)[i]);
+
+ for (i=0; i<RARRAY(keys)->len; i++) {
+ VALUE val = rb_f_getenv(Qnil, RARRAY(keys)->ptr[i]);
if (!NIL_P(val)) {
- if (RTEST(rb_yield_values(2, RARRAY_PTR(keys)[i], val))) {
- FL_UNSET(RARRAY_PTR(keys)[i], FL_TAINT);
- env_delete(Qnil, RARRAY_PTR(keys)[i]);
+ if (RTEST(rb_yield_values(2, RARRAY(keys)->ptr[i], val))) {
+ FL_UNSET(RARRAY(keys)->ptr[i], FL_TAINT);
+ env_delete(Qnil, RARRAY(keys)->ptr[i]);
del++;
}
}
@@ -2031,20 +2092,20 @@ env_reject_bang(void)
}
static VALUE
-env_delete_if(void)
+env_delete_if()
{
env_reject_bang();
return envtbl;
}
static VALUE
-env_values_at(int argc, VALUE *argv)
+env_values_at(argc, argv)
+ int argc;
+ VALUE *argv;
{
- VALUE result;
+ VALUE result = rb_ary_new();
long i;
- rb_secure(4);
- result = rb_ary_new();
for (i=0; i<argc; i++) {
rb_ary_push(result, rb_f_getenv(Qnil, argv[i]));
}
@@ -2052,13 +2113,16 @@ env_values_at(int argc, VALUE *argv)
}
static VALUE
-env_select(VALUE ehash)
+env_select(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE result;
char **env;
- RETURN_ENUMERATOR(ehash, 0, 0);
- rb_secure(4);
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
+ }
result = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
@@ -2078,36 +2142,36 @@ env_select(VALUE ehash)
}
static VALUE
-env_clear(void)
+env_clear()
{
volatile VALUE keys;
long i;
rb_secure(4);
keys = env_keys();
- for (i=0; i<RARRAY_LEN(keys); i++) {
- VALUE val = rb_f_getenv(Qnil, RARRAY_PTR(keys)[i]);
+
+ for (i=0; i<RARRAY(keys)->len; i++) {
+ VALUE val = rb_f_getenv(Qnil, RARRAY(keys)->ptr[i]);
if (!NIL_P(val)) {
- env_delete(Qnil, RARRAY_PTR(keys)[i]);
+ env_delete(Qnil, RARRAY(keys)->ptr[i]);
}
}
return envtbl;
}
static VALUE
-env_to_s(void)
+env_to_s()
{
return rb_str_new2("ENV");
}
static VALUE
-env_inspect(void)
+env_inspect()
{
char **env;
- VALUE str, i;
+ VALUE str = rb_str_buf_new2("{");
+ VALUE i;
- rb_secure(4);
- str = rb_str_buf_new2("{");
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -2132,13 +2196,11 @@ env_inspect(void)
}
static VALUE
-env_to_a(void)
+env_to_a()
{
char **env;
- VALUE ary;
+ VALUE ary = rb_ary_new();
- rb_secure(4);
- ary = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -2153,18 +2215,17 @@ env_to_a(void)
}
static VALUE
-env_none(void)
+env_none()
{
return Qnil;
}
static VALUE
-env_size(void)
+env_size()
{
int i;
char **env;
- rb_secure(4);
env = GET_ENVIRON(environ);
for(i=0; env[i]; i++)
;
@@ -2173,11 +2234,10 @@ env_size(void)
}
static VALUE
-env_empty_p(void)
+env_empty_p()
{
char **env;
- rb_secure(4);
env = GET_ENVIRON(environ);
if (env[0] == 0) {
FREE_ENVIRON(environ);
@@ -2188,31 +2248,31 @@ env_empty_p(void)
}
static VALUE
-env_has_key(VALUE env, VALUE key)
+env_has_key(env, key)
+ VALUE env, key;
{
char *s;
- rb_secure(4);
s = StringValuePtr(key);
- if (strlen(s) != RSTRING_LEN(key))
+ if (strlen(s) != RSTRING(key)->len)
rb_raise(rb_eArgError, "bad environment variable name");
if (getenv(s)) return Qtrue;
return Qfalse;
}
static VALUE
-env_has_value(VALUE dmy, VALUE value)
+env_has_value(dmy, value)
+ VALUE dmy, value;
{
char **env;
- rb_secure(4);
if (TYPE(value) != T_STRING) return Qfalse;
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (s++) {
long len = strlen(s);
- if (RSTRING_LEN(value) == len && strncmp(s, RSTRING_PTR(value), len) == 0) {
+ if (RSTRING(value)->len == len && strncmp(s, RSTRING(value)->ptr, len) == 0) {
FREE_ENVIRON(environ);
return Qtrue;
}
@@ -2224,19 +2284,19 @@ env_has_value(VALUE dmy, VALUE value)
}
static VALUE
-env_key(VALUE dmy, VALUE value)
+env_index(dmy, value)
+ VALUE dmy, value;
{
char **env;
VALUE str;
- rb_secure(4);
StringValue(value);
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (s++) {
long len = strlen(s);
- if (RSTRING_LEN(value) == len && strncmp(s, RSTRING_PTR(value), len) == 0) {
+ if (RSTRING(value)->len == len && strncmp(s, RSTRING(value)->ptr, len) == 0) {
str = env_str_new(*env, s-*env-1);
FREE_ENVIRON(environ);
return str;
@@ -2249,20 +2309,35 @@ env_key(VALUE dmy, VALUE value)
}
static VALUE
-env_index(VALUE dmy, VALUE value)
+env_indexes(argc, argv)
+ int argc;
+ VALUE *argv;
{
- rb_warn("ENV.index is deprecated; use ENV.key");
- return env_key(dmy, value);
+ int i;
+ VALUE indexes = rb_ary_new2(argc);
+
+ rb_warn("ENV.%s is deprecated; use ENV.values_at",
+ rb_id2name(rb_frame_last_func()));
+ for (i=0;i<argc;i++) {
+ VALUE tmp = rb_check_string_type(argv[i]);
+ if (NIL_P(tmp)) {
+ RARRAY(indexes)->ptr[i] = Qnil;
+ }
+ else {
+ RARRAY(indexes)->ptr[i] = env_str_new2(getenv(RSTRING(tmp)->ptr));
+ }
+ RARRAY(indexes)->len = i+1;
+ }
+
+ return indexes;
}
static VALUE
-env_to_hash(void)
+env_to_hash()
{
char **env;
- VALUE hash;
+ VALUE hash = rb_hash_new();
- rb_secure(4);
- hash = rb_hash_new();
env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
@@ -2277,23 +2352,22 @@ env_to_hash(void)
}
static VALUE
-env_reject(void)
+env_reject()
{
return rb_hash_delete_if(env_to_hash());
}
static VALUE
-env_shift(void)
+env_shift()
{
char **env;
- rb_secure(4);
env = GET_ENVIRON(environ);
if (*env) {
char *s = strchr(*env, '=');
if (s) {
VALUE key = env_str_new(*env, s-*env);
- VALUE val = env_str_new2(getenv(RSTRING_PTR(key)));
+ VALUE val = env_str_new2(getenv(RSTRING(key)->ptr));
env_delete(Qnil, key);
return rb_assoc_new(key, val);
}
@@ -2303,13 +2377,14 @@ env_shift(void)
}
static VALUE
-env_invert(void)
+env_invert()
{
return rb_hash_invert(env_to_hash());
}
static int
-env_replace_i(VALUE key, VALUE val, VALUE keys)
+env_replace_i(key, val, keys)
+ VALUE key, val, keys;
{
if (key != Qundef) {
env_aset(Qnil, key, val);
@@ -2321,25 +2396,25 @@ env_replace_i(VALUE key, VALUE val, VALUE keys)
}
static VALUE
-env_replace(VALUE env, VALUE hash)
+env_replace(env, hash)
+ VALUE env, hash;
{
- volatile VALUE keys;
+ volatile VALUE keys = env_keys();
long i;
- rb_secure(4);
- keys = env_keys();
if (env == hash) return env;
hash = to_hash(hash);
rb_hash_foreach(hash, env_replace_i, keys);
- for (i=0; i<RARRAY_LEN(keys); i++) {
- env_delete(env, RARRAY_PTR(keys)[i]);
+ for (i=0; i<RARRAY(keys)->len; i++) {
+ env_delete(env, RARRAY(keys)->ptr[i]);
}
return env;
}
static int
-env_update_i(VALUE key, VALUE val)
+env_update_i(key, val)
+ VALUE key, val;
{
if (key != Qundef) {
if (rb_block_given_p()) {
@@ -2351,9 +2426,9 @@ env_update_i(VALUE key, VALUE val)
}
static VALUE
-env_update(VALUE env, VALUE hash)
+env_update(env, hash)
+ VALUE env, hash;
{
- rb_secure(4);
if (env == hash) return env;
hash = to_hash(hash);
rb_hash_foreach(hash, env_update_i, 0);
@@ -2370,14 +2445,46 @@ env_update(VALUE env, VALUE hash)
* Hashes have a <em>default value</em> that is returned when accessing
* keys that do not exist in the hash. By default, that value is
* <code>nil</code>.
- *
+ *
+ * <code>Hash</code> uses <code>key.eql?</code> to test keys for equality.
+ * If you need to use instances of your own classes as keys in a <code>Hash</code>,
+ * it is recommended that you define both the <code>eql?</code> and <code>hash</code>
+ * methods. The <code>hash</code> method must have the property that
+ * <code>a.eql?(b)</code> implies <code>a.hash == b.hash</code>.
+ *
+ * class MyClass
+ * attr_reader :str
+ * def initialize(str)
+ * @str = str
+ * end
+ * def eql?(o)
+ * o.is_a?(MyClass) && str == o.str
+ * end
+ * def hash
+ * @str.hash
+ * end
+ * end
+ *
+ * a = MyClass.new("some string")
+ * b = MyClass.new("some string")
+ * a.eql? b #=> true
+ *
+ * h = {}
+ *
+ * h[a] = 1
+ * h[a] #=> 1
+ * h[b] #=> 1
+ *
+ * h[b] = 2
+ * h[a] #=> 2
+ * h[b] #=> 2
*/
void
-Init_Hash(void)
+Init_Hash()
{
id_hash = rb_intern("hash");
- id_yield = rb_intern("yield");
+ id_call = rb_intern("call");
id_default = rb_intern("default");
rb_cHash = rb_define_class("Hash", rb_cObject);
@@ -2392,21 +2499,20 @@ Init_Hash(void)
rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 0);
rb_define_method(rb_cHash,"to_a", rb_hash_to_a, 0);
- rb_define_method(rb_cHash,"to_s", rb_hash_inspect, 0);
+ rb_define_method(rb_cHash,"to_s", rb_hash_to_s, 0);
rb_define_method(rb_cHash,"inspect", rb_hash_inspect, 0);
rb_define_method(rb_cHash,"==", rb_hash_equal, 1);
rb_define_method(rb_cHash,"[]", rb_hash_aref, 1);
- rb_define_method(rb_cHash,"hash", rb_hash_hash, 0);
- rb_define_method(rb_cHash,"eql?", rb_hash_eql, 1);
rb_define_method(rb_cHash,"fetch", rb_hash_fetch, -1);
rb_define_method(rb_cHash,"[]=", rb_hash_aset, 2);
rb_define_method(rb_cHash,"store", rb_hash_aset, 2);
rb_define_method(rb_cHash,"default", rb_hash_default, -1);
rb_define_method(rb_cHash,"default=", rb_hash_set_default, 1);
rb_define_method(rb_cHash,"default_proc", rb_hash_default_proc, 0);
- rb_define_method(rb_cHash,"key", rb_hash_key, 1);
rb_define_method(rb_cHash,"index", rb_hash_index, 1);
+ rb_define_method(rb_cHash,"indexes", rb_hash_indexes, -1);
+ rb_define_method(rb_cHash,"indices", rb_hash_indexes, -1);
rb_define_method(rb_cHash,"size", rb_hash_size, 0);
rb_define_method(rb_cHash,"length", rb_hash_size, 0);
rb_define_method(rb_cHash,"empty?", rb_hash_empty_p, 0);
@@ -2424,7 +2530,7 @@ Init_Hash(void)
rb_define_method(rb_cHash,"shift", rb_hash_shift, 0);
rb_define_method(rb_cHash,"delete", rb_hash_delete, 1);
rb_define_method(rb_cHash,"delete_if", rb_hash_delete_if, 0);
- rb_define_method(rb_cHash,"select", rb_hash_select, 0);
+ rb_define_method(rb_cHash,"select", rb_hash_select, -1);
rb_define_method(rb_cHash,"reject", rb_hash_reject, 0);
rb_define_method(rb_cHash,"reject!", rb_hash_reject_bang, 0);
rb_define_method(rb_cHash,"clear", rb_hash_clear, 0);
@@ -2441,9 +2547,6 @@ Init_Hash(void)
rb_define_method(rb_cHash,"key?", rb_hash_has_key, 1);
rb_define_method(rb_cHash,"value?", rb_hash_has_value, 1);
- rb_define_method(rb_cHash,"compare_by_identity", rb_hash_compare_by_id, 0);
- rb_define_method(rb_cHash,"compare_by_identity?", rb_hash_compare_by_id_p, 0);
-
#ifndef __MACOS__ /* environment variables nothing on MacOS. */
origenviron = environ;
envtbl = rb_obj_alloc(rb_cObject);
@@ -2462,7 +2565,7 @@ Init_Hash(void)
rb_define_singleton_method(envtbl,"clear", env_clear, 0);
rb_define_singleton_method(envtbl,"reject", env_reject, 0);
rb_define_singleton_method(envtbl,"reject!", env_reject_bang, 0);
- rb_define_singleton_method(envtbl,"select", env_select, 0);
+ rb_define_singleton_method(envtbl,"select", env_select, -1);
rb_define_singleton_method(envtbl,"shift", env_shift, 0);
rb_define_singleton_method(envtbl,"invert", env_invert, 0);
rb_define_singleton_method(envtbl,"replace", env_replace, 1);
@@ -2471,8 +2574,9 @@ Init_Hash(void)
rb_define_singleton_method(envtbl,"rehash", env_none, 0);
rb_define_singleton_method(envtbl,"to_a", env_to_a, 0);
rb_define_singleton_method(envtbl,"to_s", env_to_s, 0);
- rb_define_singleton_method(envtbl,"key", env_key, 1);
rb_define_singleton_method(envtbl,"index", env_index, 1);
+ rb_define_singleton_method(envtbl,"indexes", env_indexes, -1);
+ rb_define_singleton_method(envtbl,"indices", env_indexes, -1);
rb_define_singleton_method(envtbl,"size", env_size, 0);
rb_define_singleton_method(envtbl,"length", env_size, 0);
rb_define_singleton_method(envtbl,"empty?", env_empty_p, 0);
diff --git a/inits.c b/inits.c
index 186e3c1626..052573a443 100644
--- a/inits.c
+++ b/inits.c
@@ -12,43 +12,42 @@
#include "ruby.h"
-void Init_Array(void);
-void Init_Bignum(void);
-void Init_Binding(void);
-void Init_Comparable(void);
-void Init_Dir(void);
-void Init_Enumerable(void);
-void Init_Enumerator(void);
-void Init_Exception(void);
-void Init_syserr(void);
-void Init_eval(void);
-void Init_load(void);
-void Init_Proc(void);
-void Init_Thread(void);
-void Init_File(void);
-void Init_GC(void);
-void Init_Hash(void);
-void Init_IO(void);
-void Init_Math(void);
-void Init_marshal(void);
-void Init_Numeric(void);
-void Init_Object(void);
-void Init_pack(void);
-void Init_Precision(void);
-void Init_sym(void);
-void Init_process(void);
-void Init_Random(void);
-void Init_Range(void);
-void Init_Regexp(void);
-void Init_signal(void);
-void Init_String(void);
-void Init_Struct(void);
-void Init_Time(void);
-void Init_var_tables(void);
-void Init_version(void);
+void Init_Array _((void));
+void Init_Bignum _((void));
+void Init_Binding _((void));
+void Init_Comparable _((void));
+void Init_Dir _((void));
+void Init_Enumerable _((void));
+void Init_Exception _((void));
+void Init_syserr _((void));
+void Init_eval _((void));
+void Init_load _((void));
+void Init_Proc _((void));
+void Init_Thread _((void));
+void Init_File _((void));
+void Init_GC _((void));
+void Init_Hash _((void));
+void Init_IO _((void));
+void Init_Math _((void));
+void Init_marshal _((void));
+void Init_Numeric _((void));
+void Init_Object _((void));
+void Init_pack _((void));
+void Init_Precision _((void));
+void Init_sym _((void));
+void Init_process _((void));
+void Init_Random _((void));
+void Init_Range _((void));
+void Init_Regexp _((void));
+void Init_signal _((void));
+void Init_String _((void));
+void Init_Struct _((void));
+void Init_Time _((void));
+void Init_var_tables _((void));
+void Init_version _((void));
void
-rb_call_inits(void)
+rb_call_inits()
{
Init_sym();
Init_var_tables();
@@ -81,6 +80,5 @@ rb_call_inits(void)
Init_Math();
Init_GC();
Init_marshal();
- Init_Enumerator();
Init_version();
}
diff --git a/instruby.rb b/instruby.rb
index 5548fa1f96..a5606e8452 100644..100755
--- a/instruby.rb
+++ b/instruby.rb
@@ -49,7 +49,7 @@ def parse_args()
$mflags.unshift(*rest) unless rest.empty?
def $mflags.set?(flag)
- grep(/\A-(?!-).*#{'%s' % flag}/i) { return true }
+ grep(/\A-(?!-).*#{'%c' % flag}/i) { return true }
false
end
def $mflags.defined?(var)
diff --git a/intern.h b/intern.h
index b2b3339c4e..b251a83f0b 100644
--- a/intern.h
+++ b/intern.h
@@ -12,16 +12,6 @@
**********************************************************************/
-#ifndef RUBY_INTERN_H
-#define RUBY_INTERN_H 1
-
-#ifdef HAVE_STDARG_PROTOTYPES
-# include <stdarg.h>
-#else
-# include <varargs.h>
-#endif
-#include <st.h>
-
/*
* Functions and variables that are used by more than one source file of
* the kernel.
@@ -30,300 +20,252 @@
#define ID_ALLOCATOR 1
/* array.c */
-void rb_mem_clear(register VALUE*, register long);
-VALUE rb_assoc_new(VALUE, VALUE);
-VALUE rb_check_array_type(VALUE);
-VALUE rb_ary_new(void);
-VALUE rb_ary_new2(long);
-VALUE rb_ary_new3(long,...);
-VALUE rb_ary_new4(long, const VALUE *);
-void rb_ary_free(VALUE);
-VALUE rb_ary_freeze(VALUE);
-VALUE rb_ary_aref(int, VALUE*, VALUE);
-void rb_ary_store(VALUE, long, VALUE);
-VALUE rb_ary_dup(VALUE);
-VALUE rb_ary_to_ary(VALUE);
-VALUE rb_ary_to_s(VALUE);
-VALUE rb_ary_push(VALUE, VALUE);
-VALUE rb_ary_pop(VALUE);
-VALUE rb_ary_shift(VALUE);
-VALUE rb_ary_unshift(VALUE, VALUE);
-VALUE rb_ary_entry(VALUE, long);
-VALUE rb_ary_each(VALUE);
-VALUE rb_ary_join(VALUE, VALUE);
-VALUE rb_ary_print_on(VALUE, VALUE);
-VALUE rb_ary_reverse(VALUE);
-VALUE rb_ary_sort(VALUE);
-VALUE rb_ary_sort_bang(VALUE);
-VALUE rb_ary_delete(VALUE, VALUE);
-VALUE rb_ary_delete_at(VALUE, long);
-VALUE rb_ary_clear(VALUE);
-VALUE rb_ary_plus(VALUE, VALUE);
-VALUE rb_ary_concat(VALUE, VALUE);
-VALUE rb_ary_assoc(VALUE, VALUE);
-VALUE rb_ary_rassoc(VALUE, VALUE);
-VALUE rb_ary_includes(VALUE, VALUE);
-VALUE rb_ary_cmp(VALUE, VALUE);
-VALUE rb_check_array_value(VALUE);
-VALUE rb_get_values_at(VALUE, long, int, VALUE*, VALUE(*)(VALUE,long));
+void rb_mem_clear _((register VALUE*, register long));
+VALUE rb_assoc_new _((VALUE, VALUE));
+VALUE rb_check_array_type _((VALUE));
+VALUE rb_ary_new _((void));
+VALUE rb_ary_new2 _((long));
+VALUE rb_ary_new3 __((long,...));
+VALUE rb_ary_new4 _((long, const VALUE *));
+VALUE rb_ary_freeze _((VALUE));
+VALUE rb_ary_aref _((int, VALUE*, VALUE));
+void rb_ary_store _((VALUE, long, VALUE));
+VALUE rb_ary_dup _((VALUE));
+VALUE rb_ary_to_ary _((VALUE));
+VALUE rb_ary_to_s _((VALUE));
+VALUE rb_ary_push _((VALUE, VALUE));
+VALUE rb_ary_pop _((VALUE));
+VALUE rb_ary_shift _((VALUE));
+VALUE rb_ary_unshift _((VALUE, VALUE));
+VALUE rb_ary_entry _((VALUE, long));
+VALUE rb_ary_each _((VALUE));
+VALUE rb_ary_join _((VALUE, VALUE));
+VALUE rb_ary_print_on _((VALUE, VALUE));
+VALUE rb_ary_reverse _((VALUE));
+VALUE rb_ary_sort _((VALUE));
+VALUE rb_ary_sort_bang _((VALUE));
+VALUE rb_ary_delete _((VALUE, VALUE));
+VALUE rb_ary_delete_at _((VALUE, long));
+VALUE rb_ary_clear _((VALUE));
+VALUE rb_ary_plus _((VALUE, VALUE));
+VALUE rb_ary_concat _((VALUE, VALUE));
+VALUE rb_ary_assoc _((VALUE, VALUE));
+VALUE rb_ary_rassoc _((VALUE, VALUE));
+VALUE rb_ary_includes _((VALUE, VALUE));
+VALUE rb_ary_cmp _((VALUE, VALUE));
+VALUE rb_protect_inspect _((VALUE(*)(ANYARGS),VALUE,VALUE));
+VALUE rb_inspecting_p _((VALUE));
+VALUE rb_check_array_value _((VALUE));
+VALUE rb_values_at _((VALUE, long, int, VALUE*, VALUE(*) _((VALUE,long))));
/* bignum.c */
-VALUE rb_big_clone(VALUE);
-void rb_big_2comp(VALUE);
-VALUE rb_big_norm(VALUE);
-VALUE rb_uint2big(VALUE);
-VALUE rb_int2big(SIGNED_VALUE);
-VALUE rb_uint2inum(VALUE);
-VALUE rb_int2inum(SIGNED_VALUE);
-VALUE rb_cstr_to_inum(const char*, int, int);
-VALUE rb_str_to_inum(VALUE, int, int);
-VALUE rb_cstr2inum(const char*, int);
-VALUE rb_str2inum(VALUE, int);
-VALUE rb_big2str(VALUE, int);
-VALUE rb_big2str0(VALUE, int, int);
-SIGNED_VALUE rb_big2long(VALUE);
+VALUE rb_big_clone _((VALUE));
+void rb_big_2comp _((VALUE));
+VALUE rb_big_norm _((VALUE));
+VALUE rb_uint2big _((unsigned long));
+VALUE rb_int2big _((long));
+VALUE rb_uint2inum _((unsigned long));
+VALUE rb_int2inum _((long));
+VALUE rb_cstr_to_inum _((const char*, int, int));
+VALUE rb_str_to_inum _((VALUE, int, int));
+VALUE rb_cstr2inum _((const char*, int));
+VALUE rb_str2inum _((VALUE, int));
+VALUE rb_big2str _((VALUE, int));
+VALUE rb_big2str0 _((VALUE, int, int));
+long rb_big2long _((VALUE));
#define rb_big2int(x) rb_big2long(x)
-VALUE rb_big2ulong(VALUE);
+unsigned long rb_big2ulong _((VALUE));
#define rb_big2uint(x) rb_big2ulong(x)
#if HAVE_LONG_LONG
-VALUE rb_ll2inum(LONG_LONG);
-VALUE rb_ull2inum(unsigned LONG_LONG);
-LONG_LONG rb_big2ll(VALUE);
-unsigned LONG_LONG rb_big2ull(VALUE);
+VALUE rb_ll2inum _((LONG_LONG));
+VALUE rb_ull2inum _((unsigned LONG_LONG));
+LONG_LONG rb_big2ll _((VALUE));
+unsigned LONG_LONG rb_big2ull _((VALUE));
#endif /* HAVE_LONG_LONG */
-void rb_quad_pack(char*,VALUE);
-VALUE rb_quad_unpack(const char*,int);
-VALUE rb_dbl2big(double);
-double rb_big2dbl(VALUE);
-VALUE rb_big_cmp(VALUE, VALUE);
-VALUE rb_big_eq(VALUE, VALUE);
-VALUE rb_big_plus(VALUE, VALUE);
-VALUE rb_big_minus(VALUE, VALUE);
-VALUE rb_big_mul(VALUE, VALUE);
-VALUE rb_big_div(VALUE, VALUE);
-VALUE rb_big_modulo(VALUE, VALUE);
-VALUE rb_big_divmod(VALUE, VALUE);
-VALUE rb_big_pow(VALUE, VALUE);
-VALUE rb_big_and(VALUE, VALUE);
-VALUE rb_big_or(VALUE, VALUE);
-VALUE rb_big_xor(VALUE, VALUE);
-VALUE rb_big_lshift(VALUE, VALUE);
+void rb_quad_pack _((char*,VALUE));
+VALUE rb_quad_unpack _((const char*,int));
+VALUE rb_dbl2big _((double));
+double rb_big2dbl _((VALUE));
+VALUE rb_big_plus _((VALUE, VALUE));
+VALUE rb_big_minus _((VALUE, VALUE));
+VALUE rb_big_mul _((VALUE, VALUE));
+VALUE rb_big_divmod _((VALUE, VALUE));
+VALUE rb_big_pow _((VALUE, VALUE));
+VALUE rb_big_and _((VALUE, VALUE));
+VALUE rb_big_or _((VALUE, VALUE));
+VALUE rb_big_xor _((VALUE, VALUE));
+VALUE rb_big_lshift _((VALUE, VALUE));
+VALUE rb_big_rand _((VALUE, double*));
/* class.c */
-VALUE rb_class_boot(VALUE);
-VALUE rb_class_new(VALUE);
-VALUE rb_mod_init_copy(VALUE, VALUE);
-VALUE rb_class_init_copy(VALUE, VALUE);
-VALUE rb_singleton_class_clone(VALUE);
-void rb_singleton_class_attached(VALUE,VALUE);
-VALUE rb_make_metaclass(VALUE, VALUE);
-void rb_check_inheritable(VALUE);
-VALUE rb_class_inherited(VALUE, VALUE);
-VALUE rb_define_class_id(ID, VALUE);
-VALUE rb_module_new(void);
-VALUE rb_define_module_id(ID);
-VALUE rb_mod_included_modules(VALUE);
-VALUE rb_mod_include_p(VALUE, VALUE);
-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_class_private_instance_methods(int, VALUE*, VALUE);
-VALUE rb_class_local_methods(VALUE);
-VALUE rb_obj_singleton_methods(int, VALUE*, VALUE);
-void rb_define_method_id(VALUE, ID, VALUE (*)(ANYARGS), int);
-void rb_frozen_class_p(VALUE);
-void rb_undef(VALUE, ID);
-void rb_define_protected_method(VALUE, const char*, VALUE (*)(ANYARGS), int);
-void rb_define_private_method(VALUE, const char*, VALUE (*)(ANYARGS), int);
-void rb_define_singleton_method(VALUE, const char*, VALUE(*)(ANYARGS), int);
-VALUE rb_singleton_class(VALUE);
+VALUE rb_class_boot _((VALUE));
+VALUE rb_class_new _((VALUE));
+VALUE rb_mod_init_copy _((VALUE, VALUE));
+VALUE rb_class_init_copy _((VALUE, VALUE));
+VALUE rb_singleton_class_clone _((VALUE));
+void rb_singleton_class_attached _((VALUE,VALUE));
+VALUE rb_make_metaclass _((VALUE, VALUE));
+void rb_check_inheritable _((VALUE));
+VALUE rb_class_inherited _((VALUE, VALUE));
+VALUE rb_define_class_id _((ID, VALUE));
+VALUE rb_module_new _((void));
+VALUE rb_define_module_id _((ID));
+VALUE rb_mod_included_modules _((VALUE));
+VALUE rb_mod_include_p _((VALUE, VALUE));
+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));
+void rb_frozen_class_p _((VALUE));
+void rb_undef _((VALUE, ID));
+void rb_define_protected_method _((VALUE, const char*, VALUE (*)(ANYARGS), int));
+void rb_define_private_method _((VALUE, const char*, VALUE (*)(ANYARGS), int));
+void rb_define_singleton_method _((VALUE, const char*, VALUE(*)(ANYARGS), int));
+VALUE rb_singleton_class _((VALUE));
/* compar.c */
-int rb_cmpint(VALUE, VALUE, VALUE);
-NORETURN(void rb_cmperr(VALUE, VALUE));
+int rb_cmpint _((VALUE, VALUE, VALUE));
+NORETURN(void rb_cmperr _((VALUE, VALUE)));
/* enum.c */
-/* enumerator.c */
-VALUE rb_enumeratorize(VALUE, VALUE, int, VALUE *);
-#define RETURN_ENUMERATOR(obj, argc, argv) do { \
- if (!rb_block_given_p()) \
- return rb_enumeratorize(obj, ID2SYM(rb_frame_this_func()), \
- argc, argv); \
- } while (0)
/* error.c */
RUBY_EXTERN int ruby_nerrs;
-VALUE rb_exc_new(VALUE, const char*, long);
-VALUE rb_exc_new2(VALUE, const char*);
-VALUE rb_exc_new3(VALUE, VALUE);
-PRINTF_ARGS(NORETURN(void rb_loaderror(const char*, ...)), 1, 2);
-PRINTF_ARGS(NORETURN(void rb_name_error(ID, const char*, ...)), 2, 3);
-NORETURN(void rb_invalid_str(const char*, const char*));
-PRINTF_ARGS(void rb_compile_error(const char*, ...), 1, 2);
-PRINTF_ARGS(void rb_compile_error_append(const char*, ...), 1, 2);
-NORETURN(void rb_load_fail(const char*));
-NORETURN(void rb_error_frozen(const char*));
-void rb_check_frozen(VALUE);
+VALUE rb_exc_new _((VALUE, const char*, long));
+VALUE rb_exc_new2 _((VALUE, const char*));
+VALUE rb_exc_new3 _((VALUE, VALUE));
+NORETURN(void rb_loaderror __((const char*, ...)));
+NORETURN(void rb_name_error __((ID, const char*, ...)));
+NORETURN(void rb_invalid_str _((const char*, const char*)));
+void rb_compile_error __((const char*, ...));
+void rb_compile_error_append __((const char*, ...));
+NORETURN(void rb_load_fail _((const char*)));
+NORETURN(void rb_error_frozen _((const char*)));
+void rb_check_frozen _((VALUE));
/* eval.c */
-#if defined(NFDBITS) && defined(HAVE_RB_FD_INIT)
-typedef struct {
- int maxfd;
- fd_set *fdset;
-} rb_fdset_t;
-
-void rb_fd_init(volatile rb_fdset_t *);
-void rb_fd_term(rb_fdset_t *);
-void rb_fd_zero(rb_fdset_t *);
-void rb_fd_set(int, rb_fdset_t *);
-void rb_fd_clr(int, rb_fdset_t *);
-int rb_fd_isset(int, const rb_fdset_t *);
-void rb_fd_copy(rb_fdset_t *, const fd_set *, int);
-int rb_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *);
-
-#define rb_fd_ptr(f) ((f)->fdset)
-#define rb_fd_max(f) ((f)->maxfd)
-
-#else
-
-typedef fd_set rb_fdset_t;
-#define rb_fd_zero(f) FD_ZERO(f)
-#define rb_fd_set(n, f) FD_SET(n, f)
-#define rb_fd_clr(n, f) FD_CLR(n, f)
-#define rb_fd_isset(n, f) FD_ISSET(n, f)
-#define rb_fd_copy(d, s, n) (*(d) = *(s))
-#define rb_fd_ptr(f) (f)
-#define rb_fd_init(f) FD_ZERO(f)
-#define rb_fd_term(f) (f)
-#define rb_fd_max(f) FD_SETSIZE
-#define rb_fd_select(n, rfds, wfds, efds, timeout) select(n, rfds, wfds, efds, timeout)
-
-#endif
-
RUBY_EXTERN struct RNode *ruby_current_node;
-void ruby_set_current_source(void);
-NORETURN(void rb_exc_raise(VALUE));
-NORETURN(void rb_exc_fatal(VALUE));
-VALUE rb_f_exit(int,VALUE*);
-VALUE rb_f_abort(int,VALUE*);
-void rb_remove_method(VALUE, const char*);
+void ruby_set_current_source _((void));
+NORETURN(void rb_exc_raise _((VALUE)));
+NORETURN(void rb_exc_fatal _((VALUE)));
+VALUE rb_f_exit _((int,VALUE*));
+VALUE rb_f_abort _((int,VALUE*));
+void rb_remove_method _((VALUE, const char*));
#define rb_disable_super(klass, name) ((void)0)
#define rb_enable_super(klass, name) ((void)0)
#define HAVE_RB_DEFINE_ALLOC_FUNC 1
-void rb_define_alloc_func(VALUE, VALUE (*)(VALUE));
-void rb_undef_alloc_func(VALUE);
-void rb_clear_cache(void);
-void rb_clear_cache_by_class(VALUE);
-void rb_alias(VALUE, ID, ID);
-void rb_attr(VALUE,ID,int,int,int);
-int rb_method_boundp(VALUE, ID, int);
-VALUE rb_dvar_defined(ID);
-VALUE rb_dvar_curr(ID);
-VALUE rb_dvar_ref(ID);
-void rb_dvar_asgn(ID, VALUE);
-void rb_dvar_push(ID, VALUE);
-VALUE *rb_svar(int);
-VALUE rb_eval_cmd(VALUE, VALUE, int);
-int rb_obj_respond_to(VALUE, ID, int);
-int rb_respond_to(VALUE, ID);
-void rb_interrupt(void);
-VALUE rb_apply(VALUE, ID, VALUE);
-void rb_backtrace(void);
-ID rb_frame_this_func(void);
-VALUE rb_obj_instance_eval(int, VALUE*, VALUE);
-VALUE rb_obj_instance_exec(int, VALUE*, VALUE);
-VALUE rb_mod_module_eval(int, VALUE*, VALUE);
-VALUE rb_mod_module_exec(int, VALUE*, VALUE);
-void rb_load(VALUE, int);
-void rb_load_protect(VALUE, int, int*);
-NORETURN(void rb_jump_tag(int));
-int rb_provided(const char*);
-void rb_provide(const char*);
-VALUE rb_f_require(VALUE, VALUE);
-VALUE rb_require_safe(VALUE, int);
-void rb_obj_call_init(VALUE, int, VALUE*);
-VALUE rb_class_new_instance(int, VALUE*, VALUE);
-VALUE rb_block_proc(void);
-VALUE rb_f_lambda(void);
-VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE);
-VALUE rb_proc_call(VALUE, VALUE);
-int rb_proc_arity(VALUE);
-VALUE rb_obj_method(VALUE, VALUE);
-VALUE rb_method_call(int, VALUE*, VALUE);
-int rb_mod_method_arity(VALUE, ID);
-int rb_obj_method_arity(VALUE, ID);
-VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*);
-void rb_set_end_proc(void (*)(VALUE), VALUE);
-void rb_mark_end_proc(void);
-void rb_exec_end_proc(void);
-void ruby_finalize(void);
-NORETURN(void ruby_stop(int));
-int ruby_cleanup(int);
-int ruby_exec(void);
-void rb_gc_mark_threads(void);
-void rb_thread_start_timer(void);
-void rb_thread_stop_timer(void);
-void rb_thread_schedule(void);
-void rb_thread_wait_fd(int);
-int rb_thread_fd_writable(int);
-void rb_thread_fd_close(int);
-int rb_thread_alone(void);
-void rb_thread_polling(void);
-void rb_thread_sleep(int);
-void rb_thread_sleep_forever(void);
-VALUE rb_thread_stop(void);
-VALUE rb_thread_wakeup(VALUE);
-VALUE rb_thread_run(VALUE);
-VALUE rb_thread_kill(VALUE);
-VALUE rb_thread_create(VALUE (*)(ANYARGS), void*);
-void rb_thread_interrupt(void);
-void rb_thread_trap_eval(VALUE, int, int);
-void rb_thread_signal_raise(const char*); /* should pass literal */
-void rb_thread_signal_exit(void);
-int rb_thread_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
-void rb_thread_wait_for(struct timeval);
-VALUE rb_thread_current(void);
-VALUE rb_thread_main(void);
-VALUE rb_thread_local_aref(VALUE, ID);
-VALUE rb_thread_local_aset(VALUE, ID, VALUE);
-void rb_thread_atfork(void);
-VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE);
+void rb_define_alloc_func _((VALUE, VALUE (*)(VALUE)));
+void rb_undef_alloc_func _((VALUE));
+void rb_clear_cache _((void));
+void rb_clear_cache_by_class _((VALUE));
+void rb_alias _((VALUE, ID, ID));
+void rb_attr _((VALUE,ID,int,int,int));
+int rb_method_boundp _((VALUE, ID, int));
+VALUE rb_dvar_defined _((ID));
+VALUE rb_dvar_curr _((ID));
+VALUE rb_dvar_ref _((ID));
+void rb_dvar_asgn _((ID, VALUE));
+void rb_dvar_push _((ID, VALUE));
+VALUE *rb_svar _((int));
+VALUE rb_eval_cmd _((VALUE, VALUE, int));
+int rb_obj_respond_to _((VALUE, ID, int));
+int rb_respond_to _((VALUE, ID));
+void rb_interrupt _((void));
+VALUE rb_apply _((VALUE, ID, VALUE));
+void rb_backtrace _((void));
+ID rb_frame_last_func _((void));
+VALUE rb_obj_instance_eval _((int, VALUE*, VALUE));
+VALUE rb_mod_module_eval _((int, VALUE*, VALUE));
+void rb_load _((VALUE, int));
+void rb_load_protect _((VALUE, int, int*));
+NORETURN(void rb_jump_tag _((int)));
+int rb_provided _((const char*));
+void rb_provide _((const char*));
+VALUE rb_f_require _((VALUE, VALUE));
+VALUE rb_require_safe _((VALUE, int));
+void rb_obj_call_init _((VALUE, int, VALUE*));
+VALUE rb_class_new_instance _((int, VALUE*, VALUE));
+VALUE rb_block_proc _((void));
+VALUE rb_f_lambda _((void));
+VALUE rb_proc_new _((VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE));
+VALUE rb_protect _((VALUE (*)(VALUE), VALUE, int*));
+void rb_set_end_proc _((void (*)(VALUE), VALUE));
+void rb_mark_end_proc _((void));
+void rb_exec_end_proc _((void));
+void ruby_finalize _((void));
+NORETURN(void ruby_stop _((int)));
+int ruby_cleanup _((int));
+int ruby_exec _((void));
+void rb_gc_mark_threads _((void));
+void rb_thread_start_timer _((void));
+void rb_thread_stop_timer _((void));
+void rb_thread_schedule _((void));
+void rb_thread_wait_fd _((int));
+int rb_thread_fd_writable _((int));
+void rb_thread_fd_close _((int));
+int rb_thread_alone _((void));
+void rb_thread_polling _((void));
+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));
+void rb_thread_signal_raise _((int));
+void rb_thread_signal_exit _((void));
+int rb_thread_select _((int, fd_set *, fd_set *, fd_set *, struct timeval *));
+void rb_thread_wait_for _((struct timeval));
+VALUE rb_thread_current _((void));
+VALUE rb_thread_main _((void));
+VALUE rb_thread_local_aref _((VALUE, ID));
+VALUE rb_thread_local_aset _((VALUE, ID, VALUE));
+void rb_thread_atfork _((void));
+VALUE rb_funcall_rescue __((VALUE, ID, int, ...));
/* file.c */
-VALUE rb_file_s_expand_path(int, VALUE *);
-VALUE rb_file_expand_path(VALUE, VALUE);
-void rb_file_const(const char*, VALUE);
-int rb_find_file_ext(VALUE*, const char* const*);
-VALUE rb_find_file(VALUE);
-char *rb_path_next(const char *);
-char *rb_path_skip_prefix(const char *);
-char *rb_path_last_separator(const char *);
-char *rb_path_end(const char *);
+VALUE rb_file_s_expand_path _((int, VALUE *));
+VALUE rb_file_expand_path _((VALUE, VALUE));
+void rb_file_const _((const char*, VALUE));
+int rb_find_file_ext _((VALUE*, const char* const*));
+VALUE rb_find_file _((VALUE));
+char *rb_path_next _((const char *));
+char *rb_path_skip_prefix _((const char *));
+char *rb_path_last_separator _((const char *));
+char *rb_path_end _((const char *));
+VALUE rb_file_directory_p _((VALUE,VALUE));
/* gc.c */
-void ruby_set_stack_size(size_t);
-NORETURN(void rb_memerror(void));
-int ruby_stack_check(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_hash(struct st_table*);
-void rb_gc_mark_maybe(VALUE);
-void rb_gc_mark(VALUE);
-void rb_gc_force_recycle(VALUE);
-void rb_gc(void);
-void rb_gc_copy_finalizer(VALUE,VALUE);
-void rb_gc_finalize_deferred(void);
-void rb_gc_call_finalizer_at_exit(void);
-VALUE rb_gc_enable(void);
-VALUE rb_gc_disable(void);
-VALUE rb_gc_start(void);
+NORETURN(void rb_memerror __((void)));
+int ruby_stack_check _((void));
+int ruby_stack_length _((VALUE**));
+int rb_during_gc _((void));
+char *rb_source_filename _((const char*));
+void rb_gc_mark_locations _((VALUE*, VALUE*));
+void rb_mark_tbl _((struct st_table*));
+void rb_mark_hash _((struct st_table*));
+void rb_gc_mark_maybe _((VALUE));
+void rb_gc_mark _((VALUE));
+void rb_gc_force_recycle _((VALUE));
+void rb_gc _((void));
+void rb_gc_copy_finalizer _((VALUE,VALUE));
+void rb_gc_finalize_deferred _((void));
+void rb_gc_call_finalizer_at_exit _((void));
+VALUE rb_gc_enable _((void));
+VALUE rb_gc_disable _((void));
+VALUE rb_gc_start _((void));
/* hash.c */
-void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t);
-void rb_hash_foreach(VALUE, int (*)(ANYARGS), VALUE);
-VALUE rb_hash(VALUE);
-VALUE rb_hash_new(void);
-VALUE rb_hash_freeze(VALUE);
-VALUE rb_hash_aref(VALUE, VALUE);
-VALUE rb_hash_aset(VALUE, VALUE, VALUE);
-VALUE rb_hash_delete_if(VALUE);
-VALUE rb_hash_delete(VALUE,VALUE);
-int rb_path_check(const char*);
-int rb_env_path_tainted(void);
+void st_foreach_safe _((struct st_table *, int (*)(ANYARGS), unsigned long));
+void rb_hash_foreach _((VALUE, int (*)(ANYARGS), VALUE));
+VALUE rb_hash _((VALUE));
+VALUE rb_hash_new _((void));
+VALUE rb_hash_freeze _((VALUE));
+VALUE rb_hash_aref _((VALUE, VALUE));
+VALUE rb_hash_aset _((VALUE, VALUE, VALUE));
+VALUE rb_hash_delete_if _((VALUE));
+VALUE rb_hash_delete _((VALUE,VALUE));
+int rb_path_check _((char*));
+int rb_env_path_tainted _((void));
/* io.c */
#define rb_defout rb_stdout
RUBY_EXTERN VALUE rb_fs;
@@ -331,261 +273,238 @@ RUBY_EXTERN VALUE rb_output_fs;
RUBY_EXTERN VALUE rb_rs;
RUBY_EXTERN VALUE rb_default_rs;
RUBY_EXTERN VALUE rb_output_rs;
-VALUE rb_io_write(VALUE, VALUE);
-VALUE rb_io_gets(VALUE);
-VALUE rb_io_getc(VALUE);
-VALUE rb_io_ungetc(VALUE, VALUE);
-VALUE rb_io_close(VALUE);
-VALUE rb_io_flush(VALUE);
-VALUE rb_io_eof(VALUE);
-VALUE rb_io_binmode(VALUE);
-VALUE rb_io_addstr(VALUE, VALUE);
-VALUE rb_io_printf(int, VALUE*, VALUE);
-VALUE rb_io_print(int, VALUE*, VALUE);
-VALUE rb_io_puts(int, VALUE*, VALUE);
-VALUE rb_file_open(const char*, const char*);
-VALUE rb_gets(void);
-void rb_write_error(const char*);
-void rb_write_error2(const char*, long);
+VALUE rb_io_write _((VALUE, VALUE));
+VALUE rb_io_gets _((VALUE));
+VALUE rb_io_getc _((VALUE));
+VALUE rb_io_ungetc _((VALUE, VALUE));
+VALUE rb_io_close _((VALUE));
+VALUE rb_io_eof _((VALUE));
+VALUE rb_io_binmode _((VALUE));
+VALUE rb_io_addstr _((VALUE, VALUE));
+VALUE rb_io_printf _((int, VALUE*, VALUE));
+VALUE rb_io_print _((int, VALUE*, VALUE));
+VALUE rb_io_puts _((int, VALUE*, VALUE));
+VALUE rb_file_open _((const char*, const char*));
+VALUE rb_gets _((void));
+void rb_write_error _((const char*));
+void rb_write_error2 _((const char*, long));
/* marshal.c */
-VALUE rb_marshal_dump(VALUE, VALUE);
-VALUE rb_marshal_load(VALUE);
+VALUE rb_marshal_dump _((VALUE, VALUE));
+VALUE rb_marshal_load _((VALUE));
/* numeric.c */
-void rb_num_zerodiv(void);
-VALUE rb_num_coerce_bin(VALUE, VALUE);
-VALUE rb_num_coerce_cmp(VALUE, VALUE);
-VALUE rb_num_coerce_relop(VALUE, VALUE);
-VALUE rb_float_new(double);
-VALUE rb_num2fix(VALUE);
-VALUE rb_fix2str(VALUE, int);
-VALUE rb_dbl_cmp(double, double);
+void rb_num_zerodiv _((void));
+VALUE rb_num_coerce_bin _((VALUE, VALUE));
+VALUE rb_num_coerce_cmp _((VALUE, VALUE));
+VALUE rb_num_coerce_relop _((VALUE, VALUE));
+VALUE rb_float_new _((double));
+VALUE rb_num2fix _((VALUE));
+VALUE rb_fix2str _((VALUE, int));
+VALUE rb_dbl_cmp _((double, double));
/* object.c */
-int rb_eql(VALUE, VALUE);
-VALUE rb_any_to_s(VALUE);
-VALUE rb_inspect(VALUE);
-VALUE rb_obj_is_instance_of(VALUE, VALUE);
-VALUE rb_obj_is_kind_of(VALUE, VALUE);
-VALUE rb_obj_alloc(VALUE);
-VALUE rb_obj_clone(VALUE);
-VALUE rb_obj_dup(VALUE);
-VALUE rb_obj_init_copy(VALUE,VALUE);
-VALUE rb_obj_taint(VALUE);
-VALUE rb_obj_tainted(VALUE);
-VALUE rb_obj_untaint(VALUE);
-VALUE rb_obj_freeze(VALUE);
-VALUE rb_obj_id(VALUE);
-VALUE rb_obj_class(VALUE);
-VALUE rb_class_real(VALUE);
-VALUE rb_class_inherited_p(VALUE, VALUE);
-VALUE rb_convert_type(VALUE,int,const char*,const char*);
-VALUE rb_check_convert_type(VALUE,int,const char*,const char*);
-VALUE rb_check_to_integer(VALUE, const char *);
-VALUE rb_to_int(VALUE);
-VALUE rb_Integer(VALUE);
-VALUE rb_Float(VALUE);
-VALUE rb_String(VALUE);
-VALUE rb_Array(VALUE);
-double rb_cstr_to_dbl(const char*, int);
-double rb_str_to_dbl(VALUE, int);
+int rb_eql _((VALUE, VALUE));
+VALUE rb_any_to_s _((VALUE));
+VALUE rb_inspect _((VALUE));
+VALUE rb_obj_is_instance_of _((VALUE, VALUE));
+VALUE rb_obj_is_kind_of _((VALUE, VALUE));
+VALUE rb_obj_alloc _((VALUE));
+VALUE rb_obj_clone _((VALUE));
+VALUE rb_obj_dup _((VALUE));
+VALUE rb_obj_init_copy _((VALUE,VALUE));
+VALUE rb_obj_taint _((VALUE));
+VALUE rb_obj_tainted _((VALUE));
+VALUE rb_obj_untaint _((VALUE));
+VALUE rb_obj_freeze _((VALUE));
+VALUE rb_obj_id _((VALUE));
+VALUE rb_obj_class _((VALUE));
+VALUE rb_class_real _((VALUE));
+VALUE rb_class_inherited_p _((VALUE, VALUE));
+VALUE rb_convert_type _((VALUE,int,const char*,const char*));
+VALUE rb_check_convert_type _((VALUE,int,const char*,const char*));
+VALUE rb_to_int _((VALUE));
+VALUE rb_Integer _((VALUE));
+VALUE rb_Float _((VALUE));
+VALUE rb_String _((VALUE));
+VALUE rb_Array _((VALUE));
+double rb_cstr_to_dbl _((const char*, int));
+double rb_str_to_dbl _((VALUE, int));
/* parse.y */
RUBY_EXTERN int ruby_sourceline;
RUBY_EXTERN char *ruby_sourcefile;
-ID rb_id_attrset(ID);
-void rb_gc_mark_parser(void);
-int rb_is_const_id(ID);
-int rb_is_instance_id(ID);
-int rb_is_class_id(ID);
-int rb_is_local_id(ID);
-int rb_is_junk_id(ID);
-int rb_symname_p(const char*);
-int rb_sym_interned_p(VALUE);
-void rb_gc_mark_symbols(void);
-VALUE rb_backref_get(void);
-void rb_backref_set(VALUE);
-VALUE rb_lastline_get(void);
-void rb_lastline_set(VALUE);
-VALUE rb_sym_all_symbols(void);
+int ruby_yyparse _((void));
+ID rb_id_attrset _((ID));
+void rb_parser_append_print _((void));
+void rb_parser_while_loop _((int, int));
+int ruby_parser_stack_on_heap _((void));
+void rb_gc_mark_parser _((void));
+int rb_is_const_id _((ID));
+int rb_is_instance_id _((ID));
+int rb_is_class_id _((ID));
+int rb_is_local_id _((ID));
+int rb_is_junk_id _((ID));
+int rb_symname_p _((const char*));
+int rb_sym_interned_p _((VALUE));
+VALUE rb_backref_get _((void));
+void rb_backref_set _((VALUE));
+VALUE rb_lastline_get _((void));
+void rb_lastline_set _((VALUE));
+VALUE rb_sym_all_symbols _((void));
/* process.c */
-struct rb_exec_arg {
- int argc;
- VALUE *argv;
- const char *prog;
-};
-int rb_proc_exec_n(int, VALUE*, const char*);
-int rb_proc_exec(const char*);
-VALUE rb_check_argv(int, VALUE*);
-int rb_exec(const struct rb_exec_arg*);
-int rb_fork(int*, int (*)(void*), void*);
-VALUE rb_f_exec(int,VALUE*);
-int rb_waitpid(int,int*,int);
-void rb_syswait(int);
-int rb_spawn(int, VALUE*);
-VALUE rb_proc_times(VALUE);
-VALUE rb_detach_process(int);
+int rb_proc_exec _((const char*));
+VALUE rb_f_exec _((int,VALUE*));
+int rb_waitpid _((int,int*,int));
+void rb_syswait _((int));
+VALUE rb_proc_times _((VALUE));
+VALUE rb_detach_process _((int));
/* range.c */
-VALUE rb_range_new(VALUE, VALUE, int);
-VALUE rb_range_beg_len(VALUE, long*, long*, long, int);
-VALUE rb_length_by_each(VALUE);
-/* random.c */
-unsigned long genrand_int32(void);
-double genrand_real(void);
+VALUE rb_range_new _((VALUE, VALUE, int));
+VALUE rb_range_beg_len _((VALUE, long*, long*, long, int));
+VALUE rb_length_by_each _((VALUE));
/* re.c */
-int rb_memcmp(const void*,const void*,long);
-int rb_memcicmp(const void*,const void*,long);
-long rb_memsearch(const void*,long,const void*,long);
-VALUE rb_reg_nth_defined(int, VALUE);
-VALUE rb_reg_nth_match(int, VALUE);
-VALUE rb_reg_last_match(VALUE);
-VALUE rb_reg_match_pre(VALUE);
-VALUE rb_reg_match_post(VALUE);
-VALUE rb_reg_match_last(VALUE);
-VALUE rb_reg_new(const char*, long, int);
-VALUE rb_reg_compile(const char*, long, int);
-VALUE rb_reg_match(VALUE, VALUE);
-VALUE rb_reg_match2(VALUE);
-int rb_reg_options(VALUE);
-void rb_set_kcode(const char*);
-const char* rb_get_kcode(void);
+int rb_memcmp _((const void*,const void*,long));
+int rb_memcicmp _((const void*,const void*,long));
+long rb_memsearch _((const void*,long,const void*,long));
+VALUE rb_reg_nth_defined _((int, VALUE));
+VALUE rb_reg_nth_match _((int, VALUE));
+VALUE rb_reg_last_match _((VALUE));
+VALUE rb_reg_match_pre _((VALUE));
+VALUE rb_reg_match_post _((VALUE));
+VALUE rb_reg_match_last _((VALUE));
+VALUE rb_reg_new _((const char*, long, int));
+VALUE rb_reg_match _((VALUE, VALUE));
+VALUE rb_reg_match2 _((VALUE));
+int rb_reg_options _((VALUE));
+void rb_set_kcode _((const char*));
+const char* rb_get_kcode _((void));
+void rb_kcode_set_option _((VALUE));
+void rb_kcode_reset_option _((void));
/* ruby.c */
RUBY_EXTERN VALUE rb_argv;
RUBY_EXTERN VALUE rb_argv0;
-void rb_load_file(const char*);
-void ruby_script(const char*);
-void ruby_prog_init(void);
-void ruby_set_argv(int, char**);
-void ruby_process_options(int, char**);
-void ruby_load_script(void);
-void ruby_init_loadpath(void);
-void ruby_incpush(const char*);
+void rb_load_file _((const char*));
+void ruby_script _((const char*));
+void ruby_prog_init _((void));
+void ruby_set_argv _((int, char**));
+void ruby_process_options _((int, char**));
+void ruby_load_script _((void));
+void ruby_init_loadpath _((void));
+void ruby_incpush _((const char*));
/* signal.c */
-VALUE rb_f_kill(int, VALUE*);
-void rb_gc_mark_trap_list(void);
+VALUE rb_f_kill _((int, VALUE*));
+void rb_gc_mark_trap_list _((void));
#ifdef POSIX_SIGNAL
#define posix_signal ruby_posix_signal
-void posix_signal(int, RETSIGTYPE (*)(int));
-#ifdef HAVE_NATIVETHREAD
-#define posix_nativethread_signal ruby_posix_nativethread_signal
-void posix_nativethread_signal(int, RETSIGTYPE (*)(int));
-#endif
+void posix_signal _((int, RETSIGTYPE (*)(int)));
#endif
-void rb_trap_exit(void);
-void rb_trap_exec(void);
-const char *ruby_signal_name(int);
+void rb_trap_exit _((void));
+void rb_trap_exec _((void));
+const char *ruby_signal_name _((int));
+void ruby_default_signal _((int));
/* sprintf.c */
-VALUE rb_f_sprintf(int, const VALUE*);
-PRINTF_ARGS(VALUE rb_sprintf(const char*, ...), 1, 2);
-VALUE rb_vsprintf(const char*, va_list);
-VALUE rb_str_format(int, const VALUE *, VALUE);
+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*);
-VALUE rb_str_new3(VALUE);
-VALUE rb_str_new4(VALUE);
-VALUE rb_str_new5(VALUE, const char*, long);
-VALUE rb_tainted_str_new(const char*, long);
-VALUE rb_tainted_str_new2(const char*);
-VALUE rb_str_buf_new(long);
-VALUE rb_str_buf_new2(const char*);
-void rb_str_free(VALUE);
-VALUE rb_str_buf_append(VALUE, VALUE);
-VALUE rb_str_buf_cat(VALUE, const char*, long);
-VALUE rb_str_buf_cat2(VALUE, const char*);
-VALUE rb_obj_as_string(VALUE);
-VALUE rb_check_string_type(VALUE);
-VALUE rb_str_dup(VALUE);
-VALUE rb_str_locktmp(VALUE);
-VALUE rb_str_unlocktmp(VALUE);
-VALUE rb_str_dup_frozen(VALUE);
-VALUE rb_str_plus(VALUE, VALUE);
-VALUE rb_str_times(VALUE, VALUE);
-VALUE rb_str_substr(VALUE, long, long);
-void rb_str_modify(VALUE);
-VALUE rb_str_freeze(VALUE);
-void rb_str_set_len(VALUE, long);
-VALUE rb_str_resize(VALUE, long);
-VALUE rb_str_cat(VALUE, const char*, long);
-VALUE rb_str_cat2(VALUE, const char*);
-VALUE rb_str_append(VALUE, VALUE);
-VALUE rb_str_concat(VALUE, VALUE);
-int rb_memhash(const void *ptr, long len);
-int rb_str_hash(VALUE);
-int rb_str_cmp(VALUE, VALUE);
-VALUE rb_str_upto(VALUE, VALUE, int);
-void rb_str_update(VALUE, long, long, VALUE);
-VALUE rb_str_inspect(VALUE);
-VALUE rb_str_dump(VALUE);
-VALUE rb_str_split(VALUE, const char*);
-void rb_str_associate(VALUE, VALUE);
-VALUE rb_str_associated(VALUE);
-void rb_str_setter(VALUE, ID, VALUE*);
-VALUE rb_str_intern(VALUE);
+VALUE rb_str_new _((const char*, long));
+VALUE rb_str_new2 _((const char*));
+VALUE rb_str_new3 _((VALUE));
+VALUE rb_str_new4 _((VALUE));
+VALUE rb_str_new5 _((VALUE, const char*, long));
+VALUE rb_tainted_str_new _((const char*, long));
+VALUE rb_tainted_str_new2 _((const char*));
+VALUE rb_str_buf_new _((long));
+VALUE rb_str_buf_new2 _((const char*));
+VALUE rb_str_buf_append _((VALUE, VALUE));
+VALUE rb_str_buf_cat _((VALUE, const char*, long));
+VALUE rb_str_buf_cat2 _((VALUE, const char*));
+VALUE rb_obj_as_string _((VALUE));
+VALUE rb_check_string_type _((VALUE));
+VALUE rb_str_dup _((VALUE));
+VALUE rb_str_locktmp _((VALUE));
+VALUE rb_str_unlocktmp _((VALUE));
+VALUE rb_str_dup_frozen _((VALUE));
+VALUE rb_str_plus _((VALUE, VALUE));
+VALUE rb_str_times _((VALUE, VALUE));
+VALUE rb_str_substr _((VALUE, long, long));
+void rb_str_modify _((VALUE));
+VALUE rb_str_freeze _((VALUE));
+VALUE rb_str_resize _((VALUE, long));
+VALUE rb_str_cat _((VALUE, const char*, long));
+VALUE rb_str_cat2 _((VALUE, const char*));
+VALUE rb_str_append _((VALUE, VALUE));
+VALUE rb_str_concat _((VALUE, VALUE));
+int rb_str_hash _((VALUE));
+int rb_str_cmp _((VALUE, VALUE));
+VALUE rb_str_upto _((VALUE, VALUE, int));
+void rb_str_update _((VALUE, long, long, VALUE));
+VALUE rb_str_inspect _((VALUE));
+VALUE rb_str_dump _((VALUE));
+VALUE rb_str_split _((VALUE, const char*));
+void rb_str_associate _((VALUE, VALUE));
+VALUE rb_str_associated _((VALUE));
+void rb_str_setter _((VALUE, ID, VALUE*));
+VALUE rb_str_intern _((VALUE));
/* struct.c */
-VALUE rb_struct_new(VALUE, ...);
-VALUE rb_struct_define(const char*, ...);
-VALUE rb_struct_alloc(VALUE, VALUE);
-VALUE rb_struct_aref(VALUE, VALUE);
-VALUE rb_struct_aset(VALUE, VALUE, VALUE);
-VALUE rb_struct_getmember(VALUE, ID);
-VALUE rb_struct_iv_get(VALUE, const char*);
-VALUE rb_struct_s_members(VALUE);
-VALUE rb_struct_members(VALUE);
+VALUE rb_struct_new __((VALUE, ...));
+VALUE rb_struct_define __((const char*, ...));
+VALUE rb_struct_alloc _((VALUE, VALUE));
+VALUE rb_struct_aref _((VALUE, VALUE));
+VALUE rb_struct_aset _((VALUE, VALUE, VALUE));
+VALUE rb_struct_getmember _((VALUE, ID));
+VALUE rb_struct_iv_get _((VALUE, char*));
+VALUE rb_struct_s_members _((VALUE));
+VALUE rb_struct_members _((VALUE));
/* time.c */
-VALUE rb_time_new(time_t, time_t);
+VALUE rb_time_new _((time_t, time_t));
/* variable.c */
-VALUE rb_mod_name(VALUE);
-VALUE rb_class_path(VALUE);
-void rb_set_class_path(VALUE, VALUE, const char*);
-VALUE rb_path2class(const char*);
-void rb_name_class(VALUE, ID);
-VALUE rb_class_name(VALUE);
-void rb_autoload(VALUE, ID, const char*);
-VALUE rb_autoload_load(VALUE, ID);
-VALUE rb_autoload_p(VALUE, ID);
-void rb_gc_mark_global_tbl(void);
-VALUE rb_f_trace_var(int, VALUE*);
-VALUE rb_f_untrace_var(int, VALUE*);
-VALUE rb_f_global_variables(void);
-void rb_alias_variable(ID, ID);
-struct st_table* rb_generic_ivar_table(VALUE);
-void rb_copy_generic_ivar(VALUE,VALUE);
-void rb_mark_generic_ivar(VALUE);
-void rb_mark_generic_ivar_tbl(void);
-void rb_free_generic_ivar(VALUE);
-VALUE rb_ivar_get(VALUE, ID);
-VALUE rb_ivar_set(VALUE, ID, VALUE);
-VALUE rb_ivar_defined(VALUE, ID);
-VALUE rb_iv_set(VALUE, const char*, VALUE);
-VALUE rb_iv_get(VALUE, const char*);
-VALUE rb_attr_get(VALUE, ID);
-VALUE rb_obj_instance_variables(VALUE);
-VALUE rb_obj_remove_instance_variable(VALUE, VALUE);
-void *rb_mod_const_at(VALUE, void*);
-void *rb_mod_const_of(VALUE, void*);
-VALUE rb_const_list(void*);
-VALUE rb_mod_constants(VALUE);
-VALUE rb_mod_remove_const(VALUE, VALUE);
-int rb_const_defined(VALUE, ID);
-int rb_const_defined_at(VALUE, ID);
-int rb_const_defined_from(VALUE, ID);
-int rb_const_defined_fallback(VALUE, ID, struct RNode *);
-VALUE rb_const_get(VALUE, ID);
-VALUE rb_const_get_at(VALUE, ID);
-VALUE rb_const_get_from(VALUE, ID);
-VALUE rb_const_get_fallback(VALUE, ID, struct RNode *);
-void rb_const_set(VALUE, ID, VALUE);
-VALUE rb_mod_constants(VALUE);
-VALUE rb_mod_const_missing(VALUE,VALUE);
-VALUE rb_cvar_defined(VALUE, ID);
+VALUE rb_mod_name _((VALUE));
+VALUE rb_class_path _((VALUE));
+void rb_set_class_path _((VALUE, VALUE, const char*));
+VALUE rb_path2class _((const char*));
+void rb_name_class _((VALUE, ID));
+VALUE rb_class_name _((VALUE));
+void rb_autoload _((VALUE, ID, const char*));
+VALUE rb_autoload_load _((VALUE, ID));
+VALUE rb_autoload_p _((VALUE, ID));
+void rb_gc_mark_global_tbl _((void));
+VALUE rb_f_trace_var _((int, VALUE*));
+VALUE rb_f_untrace_var _((int, VALUE*));
+VALUE rb_f_global_variables _((void));
+void rb_alias_variable _((ID, ID));
+struct st_table* rb_generic_ivar_table _((VALUE));
+void rb_copy_generic_ivar _((VALUE,VALUE));
+void rb_mark_generic_ivar _((VALUE));
+void rb_mark_generic_ivar_tbl _((void));
+void rb_free_generic_ivar _((VALUE));
+VALUE rb_ivar_get _((VALUE, ID));
+VALUE rb_ivar_set _((VALUE, ID, VALUE));
+VALUE rb_ivar_defined _((VALUE, ID));
+VALUE rb_iv_set _((VALUE, const char*, VALUE));
+VALUE rb_iv_get _((VALUE, const char*));
+VALUE rb_attr_get _((VALUE, ID));
+VALUE rb_obj_instance_variables _((VALUE));
+VALUE rb_obj_remove_instance_variable _((VALUE, VALUE));
+void *rb_mod_const_at _((VALUE, void*));
+void *rb_mod_const_of _((VALUE, void*));
+VALUE rb_const_list _((void*));
+VALUE rb_mod_constants _((VALUE));
+VALUE rb_mod_remove_const _((VALUE, VALUE));
+int rb_const_defined _((VALUE, ID));
+int rb_const_defined_at _((VALUE, ID));
+int rb_const_defined_from _((VALUE, ID));
+VALUE rb_const_get _((VALUE, ID));
+VALUE rb_const_get_at _((VALUE, ID));
+VALUE rb_const_get_from _((VALUE, ID));
+void rb_const_set _((VALUE, ID, VALUE));
+VALUE rb_mod_constants _((VALUE));
+VALUE rb_mod_const_missing _((VALUE,VALUE));
+VALUE rb_cvar_defined _((VALUE, ID));
#define RB_CVAR_SET_4ARGS 1
-void rb_cvar_set(VALUE, ID, VALUE, int);
-VALUE rb_cvar_get(VALUE, ID);
-void rb_cv_set(VALUE, const char*, VALUE);
-VALUE rb_cv_get(VALUE, const char*);
-void rb_define_class_variable(VALUE, const char*, VALUE);
-VALUE rb_mod_class_variables(VALUE);
-VALUE rb_mod_remove_cvar(VALUE, VALUE);
+void rb_cvar_set _((VALUE, ID, VALUE, int));
+VALUE rb_cvar_get _((VALUE, ID));
+void rb_cv_set _((VALUE, const char*, VALUE));
+VALUE rb_cv_get _((VALUE, const char*));
+void rb_define_class_variable _((VALUE, const char*, VALUE));
+VALUE rb_mod_class_variables _((VALUE));
+VALUE rb_mod_remove_cvar _((VALUE, VALUE));
/* version.c */
-void ruby_show_version(void);
-void ruby_show_copyright(void);
-
-#endif /* RUBY_INTERN_H */
+void ruby_show_version _((void));
+void ruby_show_copyright _((void));
diff --git a/io.c b/io.c
index a78259ba51..d031625ce4 100644
--- a/io.c
+++ b/io.c
@@ -12,21 +12,18 @@
**********************************************************************/
+#if defined(__VMS)
+#define _XOPEN_SOURCE
+#define _POSIX_C_SOURCE 2
+#endif
+
#include "ruby.h"
#include "rubyio.h"
#include "rubysig.h"
+#include "env.h"
#include <ctype.h>
#include <errno.h>
-#include <sys/types.h>
-#if !defined(_WIN32) && !defined(__DJGPP__)
-# if defined(__BEOS__)
-# include <net/socket.h>
-# else
-# include <sys/socket.h>
-# endif
-#endif
-
#if defined(MSDOS) || defined(__BOW__) || defined(__CYGWIN__) || defined(_WIN32) || defined(__human68k__) || defined(__EMX__) || defined(__BEOS__)
# define NO_SAFE_RENAME
#endif
@@ -56,6 +53,12 @@
#if !HAVE_OFF_T && !defined(off_t)
# define off_t long
#endif
+#if !HAVE_FSEEKO && !defined(fseeko)
+# define fseeko fseek
+#endif
+#if !HAVE_FTELLO && !defined(ftello)
+# define ftello ftell
+#endif
#include <sys/stat.h>
@@ -69,16 +72,16 @@
#endif
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
#ifdef HAVE_SYSCALL_H
#include <syscall.h>
#elif defined HAVE_SYS_SYSCALL_H
#include <sys/syscall.h>
#endif
-extern void Init_File(void);
+#include <unistd.h>
+#endif
+
+extern void Init_File _((void));
#ifdef __BEOS__
# ifndef NOFILE
@@ -120,11 +123,11 @@ VALUE rb_default_rs;
static VALUE argf;
-static ID id_write, id_read, id_getc, id_flush;
+static ID id_write, id_read, id_getc;
extern char *ruby_inplace_mode;
-struct timeval rb_time_interval(VALUE);
+struct timeval rb_time_interval _((VALUE));
static VALUE filename, current_file;
static int gets_lineno;
@@ -133,77 +136,80 @@ static VALUE lineno = INT2FIX(0);
#ifdef _STDIO_USES_IOSTREAM /* GNU libc */
# ifdef _IO_fpos_t
-# define STDIO_READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
+# define READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
+# define READ_DATA_PENDING_COUNT(fp) ((fp)->_IO_read_end - (fp)->_IO_read_ptr)
+# define READ_DATA_PENDING_PTR(fp) ((fp)->_IO_read_ptr)
# else
-# define STDIO_READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
+# define READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
+# define READ_DATA_PENDING_COUNT(fp) ((fp)->_egptr - (fp)->_gptr)
+# define READ_DATA_PENDING_PTR(fp) ((fp)->_gptr)
# endif
+#elif defined(_LP64) && (defined(__sun__) || defined(__sun))
+typedef struct _FILE64 {
+ unsigned char *_ptr; /* next character from/to here in buffer */
+ unsigned char *_base; /* the buffer */
+ unsigned char *_end; /* the end of the buffer */
+ ssize_t _cnt; /* number of available characters in buffer */
+ int _file; /* UNIX System file descriptor */
+ unsigned int _flag; /* the state of the stream */
+ char __fill[80]; /* filler to bring size to 128 bytes */
+} FILE64;
+# define READ_DATA_PENDING(fp) (((FILE64*)(fp))->_cnt > 0)
+# define READ_DATA_PENDING_COUNT(fp) (((FILE64*)(fp))->_cnt)
+# define READ_DATA_PENDING_PTR(fp) ((char *)((FILE64*)(fp))->_ptr)
#elif defined(FILE_COUNT)
-# define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
+# define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
+# define READ_DATA_PENDING_COUNT(fp) ((fp)->FILE_COUNT)
#elif defined(FILE_READEND)
-# define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_READPTR < (fp)->FILE_READEND)
+# define READ_DATA_PENDING(fp) ((fp)->FILE_READPTR < (fp)->FILE_READEND)
+# define READ_DATA_PENDING_COUNT(fp) ((fp)->FILE_READEND - (fp)->FILE_READPTR)
#elif defined(__BEOS__)
-# define STDIO_READ_DATA_PENDING(fp) (fp->_state._eof == 0)
+# define READ_DATA_PENDING(fp) (fp->_state._eof == 0)
#elif defined(__VMS)
-# define STDIO_READ_DATA_PENDING(fp) (((unsigned int)(*(fp))->_cnt) > 0)
+# define READ_DATA_PENDING_COUNT(fp) ((unsigned int)(*(fp))->_cnt)
+# define READ_DATA_PENDING(fp) (((unsigned int)(*(fp))->_cnt) > 0)
+# define READ_DATA_BUFFERED(fp) 0
+#elif defined(__DragonFly__)
+/* FILE is an incomplete struct type since DragonFly BSD 1.4.0 */
+# define READ_DATA_PENDING(fp) (((struct __FILE_public *)(fp))->_r > 0)
+# define READ_DATA_PENDING_COUNT(fp) (((struct __FILE_public *)(fp))->_r)
#else
-# define STDIO_READ_DATA_PENDING(fp) (!feof(fp))
+/* requires systems own version of the ReadDataPending() */
+extern int ReadDataPending();
+# define READ_DATA_PENDING(fp) (!feof(fp))
+# define READ_DATA_BUFFERED(fp) 0
+#endif
+#ifndef READ_DATA_BUFFERED
+# define READ_DATA_BUFFERED(fp) READ_DATA_PENDING(fp)
#endif
-#if defined(__VMS)
-#define fopen(file_spec, mode) fopen(file_spec, mode, "rfm=stmlf")
-#define open(file_spec, flags, mode) open(file_spec, flags, mode, "rfm=stmlf")
+#ifndef READ_DATA_PENDING_PTR
+# ifdef FILE_READPTR
+# define READ_DATA_PENDING_PTR(fp) ((char *)(fp)->FILE_READPTR)
+# endif
#endif
-#define READ_DATA_PENDING(fptr) ((fptr)->rbuf_len)
-#define READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf_len)
-#define READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf+(fptr)->rbuf_off)
-#define READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr)
+#if defined __DJGPP__
+# undef READ_DATA_PENDING_COUNT
+# undef READ_DATA_PENDING_PTR
+#endif
-#define READ_CHECK(fptr) do {\
- if (!READ_DATA_PENDING(fptr)) {\
- rb_thread_wait_fd((fptr)->fd);\
- rb_io_check_closed(fptr);\
+#define READ_CHECK(fp) do {\
+ if (!READ_DATA_PENDING(fp)) {\
+ rb_thread_wait_fd(fileno(fp));\
+ rb_io_check_closed(fptr);\
}\
} while(0)
-#ifndef S_ISSOCK
-# ifdef _S_ISSOCK
-# define S_ISSOCK(m) _S_ISSOCK(m)
-# else
-# ifdef _S_IFSOCK
-# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
-# else
-# ifdef S_IFSOCK
-# define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
-# endif
-# endif
-# endif
-#endif
-
-#if defined(_WIN32)
-#define is_socket(fd, path) rb_w32_is_socket(fd)
-#elif !defined(S_ISSOCK)
-#define is_socket(fd, path) 0
-#define shutdown(a,b) 0
-#else
-static int
-is_socket(int fd, const char *path)
-{
- struct stat sbuf;
- if (fstat(fd, &sbuf) < 0)
- rb_sys_fail(path);
- return S_ISSOCK(sbuf.st_mode);
-}
-#endif
-
void
-rb_eof_error(void)
+rb_eof_error()
{
rb_raise(rb_eEOFError, "end of file reached");
}
VALUE
-rb_io_taint_check(VALUE io)
+rb_io_taint_check(io)
+ VALUE io;
{
if (!OBJ_TAINTED(io) && rb_safe_level() >= 4)
rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
@@ -212,7 +218,8 @@ rb_io_taint_check(VALUE io)
}
void
-rb_io_check_initialized(OpenFile *fptr)
+rb_io_check_initialized(fptr)
+ OpenFile *fptr;
{
if (!fptr) {
rb_raise(rb_eIOError, "uninitialized stream");
@@ -220,80 +227,30 @@ rb_io_check_initialized(OpenFile *fptr)
}
void
-rb_io_check_closed(OpenFile *fptr)
+rb_io_check_closed(fptr)
+ OpenFile *fptr;
{
rb_io_check_initialized(fptr);
- if (fptr->fd < 0) {
+ if (!fptr->f && !fptr->f2) {
rb_raise(rb_eIOError, "closed stream");
}
}
-static int io_fflush(OpenFile *);
-
-static VALUE
-rb_io_get_io(VALUE io)
-{
- return rb_convert_type(io, T_FILE, "IO", "to_io");
-}
-
-static VALUE
-rb_io_check_io(VALUE io)
-{
- return rb_check_convert_type(io, T_FILE, "IO", "to_io");
-}
-
-static void
-io_unread(OpenFile *fptr)
-{
- off_t r;
- rb_io_check_closed(fptr);
- if (fptr->rbuf_len == 0 || fptr->mode & FMODE_DUPLEX)
- return;
- /* xxx: target position may be negative if buffer is filled by ungetc */
- r = lseek(fptr->fd, -fptr->rbuf_len, SEEK_CUR);
- if (r < 0) {
- if (errno == ESPIPE)
- fptr->mode |= FMODE_DUPLEX;
- return;
- }
- fptr->rbuf_off = 0;
- fptr->rbuf_len = 0;
- return;
-}
-
-static int
-io_ungetc(int c, OpenFile *fptr)
-{
- if (fptr->rbuf == NULL) {
- fptr->rbuf_off = 0;
- fptr->rbuf_len = 0;
- fptr->rbuf_capa = 8192;
- fptr->rbuf = ALLOC_N(char, fptr->rbuf_capa);
- }
- if (c < 0 || fptr->rbuf_len == fptr->rbuf_capa) {
- return -1;
- }
- if (fptr->rbuf_off == 0) {
- if (fptr->rbuf_len)
- MEMMOVE(fptr->rbuf+1, fptr->rbuf, char, fptr->rbuf_len);
- fptr->rbuf_off = 1;
- }
- fptr->rbuf_off--;
- fptr->rbuf_len++;
- fptr->rbuf[fptr->rbuf_off] = c;
- return c;
-}
+static void io_fflush _((FILE *, OpenFile *));
static OpenFile *
-flush_before_seek(OpenFile *fptr)
+flush_before_seek(fptr)
+ OpenFile *fptr;
{
- io_fflush(fptr);
- io_unread(fptr);
+ if (fptr->mode & FMODE_WBUF) {
+ io_fflush(GetWriteFile(fptr), fptr);
+ }
+ errno = 0;
return fptr;
}
-#define io_seek(fptr, ofs, whence) lseek(flush_before_seek(fptr)->fd, ofs, whence)
-#define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
+#define io_seek(fptr, ofs, whence) fseeko(flush_before_seek(fptr)->f, ofs, whence)
+#define io_tell(fptr) ftello(flush_before_seek(fptr)->f)
#ifndef SEEK_CUR
# define SEEK_SET 0
@@ -304,66 +261,65 @@ flush_before_seek(OpenFile *fptr)
#define FMODE_SYNCWRITE (FMODE_SYNC|FMODE_WRITABLE)
void
-rb_io_check_readable(OpenFile *fptr)
+rb_io_check_readable(fptr)
+ OpenFile *fptr;
{
rb_io_check_closed(fptr);
if (!(fptr->mode & FMODE_READABLE)) {
rb_raise(rb_eIOError, "not opened for reading");
}
- if (fptr->wbuf_len) {
- io_fflush(fptr);
+#ifdef NEED_IO_SEEK_BETWEEN_RW
+ if (((fptr->mode & FMODE_WBUF) ||
+ (fptr->mode & (FMODE_SYNCWRITE|FMODE_RBUF)) == FMODE_SYNCWRITE) &&
+ !feof(fptr->f) &&
+ !fptr->f2) {
+ io_seek(fptr, 0, SEEK_CUR);
}
+#endif
+ fptr->mode |= FMODE_RBUF;
}
void
-rb_io_check_writable(OpenFile *fptr)
+rb_io_check_writable(fptr)
+ OpenFile *fptr;
{
rb_io_check_closed(fptr);
if (!(fptr->mode & FMODE_WRITABLE)) {
rb_raise(rb_eIOError, "not opened for writing");
}
- if (fptr->rbuf_len) {
- io_unread(fptr);
+ if ((fptr->mode & FMODE_RBUF) && !feof(fptr->f) && !fptr->f2) {
+ io_seek(fptr, 0, SEEK_CUR);
+ }
+ if (!fptr->f2) {
+ fptr->mode &= ~FMODE_RBUF;
}
}
int
-rb_read_pending(FILE *fp)
-{
- return STDIO_READ_DATA_PENDING(fp);
-}
-
-int
-rb_io_read_pending(OpenFile *fptr)
+rb_read_pending(fp)
+ FILE *fp;
{
- return READ_DATA_PENDING(fptr);
+ return READ_DATA_PENDING(fp);
}
void
-rb_read_check(FILE *fp)
+rb_read_check(fp)
+ FILE *fp;
{
- if (!STDIO_READ_DATA_PENDING(fp)) {
+ if (!READ_DATA_PENDING(fp)) {
rb_thread_wait_fd(fileno(fp));
}
}
-void
-rb_io_read_check(OpenFile *fptr)
-{
- if (!READ_DATA_PENDING(fptr)) {
- rb_thread_wait_fd(fptr->fd);
- }
- return;
-}
-
static int
-ruby_dup(int orig)
+ruby_dup(orig)
+ int orig;
{
int fd;
fd = dup(orig);
if (fd < 0) {
- if (errno == EMFILE || errno == ENFILE) {
+ if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
rb_gc();
fd = dup(orig);
}
@@ -374,8 +330,10 @@ ruby_dup(int orig)
return fd;
}
+static VALUE io_alloc _((VALUE));
static VALUE
-io_alloc(VALUE klass)
+io_alloc(klass)
+ VALUE klass;
{
NEWOBJ(io, struct RFile);
OBJSETUP(io, klass, T_FILE);
@@ -385,88 +343,32 @@ io_alloc(VALUE klass)
return (VALUE)io;
}
-#ifndef S_ISREG
-# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
-#endif
-
-static int
-wsplit_p(OpenFile *fptr)
-{
- int r;
- if (!(fptr->mode & FMODE_WSPLIT_INITIALIZED)) {
- struct stat buf;
- if (fstat(fptr->fd, &buf) == 0 &&
- !S_ISREG(buf.st_mode)
-#if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
- && (r = fcntl(fptr->fd, F_GETFL)) != -1 &&
- !(r & O_NONBLOCK)
-#endif
- ) {
- fptr->mode |= FMODE_WSPLIT;
- }
- fptr->mode |= FMODE_WSPLIT_INITIALIZED;
- }
- return fptr->mode & FMODE_WSPLIT;
-}
-
-static int
-io_fflush(OpenFile *fptr)
+static void
+io_fflush(f, fptr)
+ FILE *f;
+ OpenFile *fptr;
{
- int r, l;
- int wbuf_off, wbuf_len;
+ int n;
- rb_io_check_closed(fptr);
- if (fptr->wbuf_len == 0)
- return 0;
- if (!rb_thread_fd_writable(fptr->fd)) {
+ if (!rb_thread_fd_writable(fileno(f))) {
rb_io_check_closed(fptr);
}
- retry:
- if (fptr->wbuf_len == 0)
- return 0;
- wbuf_off = fptr->wbuf_off;
- wbuf_len = fptr->wbuf_len;
- l = fptr->wbuf_len;
- if (PIPE_BUF < l &&
- !rb_thread_critical &&
- !rb_thread_alone() &&
- wsplit_p(fptr)) {
- l = PIPE_BUF;
- }
- TRAP_BEG;
- r = write(fptr->fd, fptr->wbuf+fptr->wbuf_off, l);
- TRAP_END; /* xxx: signal handler may modify wbuf */
- if (r == fptr->wbuf_len) {
- fptr->wbuf_off = 0;
- fptr->wbuf_len = 0;
- return 0;
- }
- if (0 <= r) {
- fptr->wbuf_off = (wbuf_off += r);
- fptr->wbuf_len = (wbuf_len -= r);
- errno = EAGAIN;
- }
- if (rb_io_wait_writable(fptr->fd)) {
- rb_io_check_closed(fptr);
- goto retry;
+ for (;;) {
+ TRAP_BEG;
+ n = fflush(f);
+ TRAP_END;
+ if (n != EOF) break;
+ if (!rb_io_wait_writable(fileno(f)))
+ rb_sys_fail(fptr->path);
}
- return -1;
+ fptr->mode &= ~FMODE_WBUF;
}
-#ifdef HAVE_RB_FD_INIT
-static VALUE
-wait_readable(VALUE p)
-{
- rb_fdset_t *rfds = (rb_fdset_t *)p;
-
- return rb_thread_select(rb_fd_max(rfds), rb_fd_ptr(rfds), NULL, NULL, NULL);
-}
-#endif
-
int
-rb_io_wait_readable(int f)
+rb_io_wait_readable(f)
+ int f;
{
- rb_fdset_t rfds;
+ fd_set rfds;
switch (errno) {
case EINTR:
@@ -480,14 +382,9 @@ rb_io_wait_readable(int f)
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EWOULDBLOCK:
#endif
- rb_fd_init(&rfds);
- rb_fd_set(f, &rfds);
-#ifdef HAVE_RB_FD_INIT
- rb_ensure(wait_readable, (VALUE)&rfds,
- (VALUE (*)(VALUE))rb_fd_term, (VALUE)&rfds);
-#else
+ FD_ZERO(&rfds);
+ FD_SET(f, &rfds);
rb_thread_select(f + 1, &rfds, NULL, NULL, NULL);
-#endif
return Qtrue;
default:
@@ -495,20 +392,11 @@ rb_io_wait_readable(int f)
}
}
-#ifdef HAVE_RB_FD_INIT
-static VALUE
-wait_writable(VALUE p)
-{
- rb_fdset_t *wfds = (rb_fdset_t *)p;
-
- return rb_thread_select(rb_fd_max(wfds), NULL, rb_fd_ptr(wfds), NULL, NULL);
-}
-#endif
-
int
-rb_io_wait_writable(int f)
+rb_io_wait_writable(f)
+ int f;
{
- rb_fdset_t wfds;
+ fd_set wfds;
switch (errno) {
case EINTR:
@@ -522,14 +410,9 @@ rb_io_wait_writable(int f)
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EWOULDBLOCK:
#endif
- rb_fd_init(&wfds);
- rb_fd_set(f, &wfds);
-#ifdef HAVE_RB_FD_INIT
- rb_ensure(wait_writable, (VALUE)&wfds,
- (VALUE (*)(VALUE))rb_fd_term, (VALUE)&wfds);
-#else
+ FD_ZERO(&wfds);
+ FD_SET(f, &wfds);
rb_thread_select(f + 1, NULL, &wfds, NULL, NULL);
-#endif
return Qtrue;
default:
@@ -537,40 +420,45 @@ rb_io_wait_writable(int f)
}
}
+#ifndef S_ISREG
+# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
+#endif
+
+static int
+wsplit_p(OpenFile *fptr)
+{
+ FILE *f = GetWriteFile(fptr);
+ int r;
+ if (!(fptr->mode & FMODE_WSPLIT_INITIALIZED)) {
+ struct stat buf;
+ if (fstat(fileno(f), &buf) == 0 &&
+ !S_ISREG(buf.st_mode)
+#if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
+ && (r = fcntl(fileno(f), F_GETFL)) != -1 &&
+ !(r & O_NONBLOCK)
+#endif
+ ) {
+ fptr->mode |= FMODE_WSPLIT;
+ }
+ fptr->mode |= FMODE_WSPLIT_INITIALIZED;
+ }
+ return fptr->mode & FMODE_WSPLIT;
+}
+
/* writing functions */
static long
-io_fwrite(VALUE str, OpenFile *fptr)
+io_fwrite(str, fptr)
+ VALUE str;
+ OpenFile *fptr;
{
long len, n, r, l, offset = 0;
+ FILE *f = GetWriteFile(fptr);
- len = RSTRING_LEN(str);
+ len = RSTRING(str)->len;
if ((n = len) <= 0) return n;
- if (fptr->wbuf == NULL && !(fptr->mode & FMODE_SYNC)) {
- fptr->wbuf_off = 0;
- fptr->wbuf_len = 0;
- fptr->wbuf_capa = 8192;
- fptr->wbuf = ALLOC_N(char, fptr->wbuf_capa);
- }
- if ((fptr->mode & FMODE_SYNC) ||
- (fptr->wbuf && fptr->wbuf_capa <= fptr->wbuf_len + len) ||
- ((fptr->mode & FMODE_TTY) && memchr(RSTRING_PTR(str)+offset, '\n', len))) {
- /* xxx: use writev to avoid double write if available */
- if (fptr->wbuf_len && fptr->wbuf_len+len <= fptr->wbuf_capa) {
- if (fptr->wbuf_capa < fptr->wbuf_off+fptr->wbuf_len+len) {
- MEMMOVE(fptr->wbuf, fptr->wbuf+fptr->wbuf_off, char, fptr->wbuf_len);
- fptr->wbuf_off = 0;
- }
- MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, RSTRING_PTR(str)+offset, char, len);
- fptr->wbuf_len += len;
- n = 0;
- }
- if (io_fflush(fptr) < 0)
- return -1L;
- if (n == 0)
- return len;
- /* avoid context switch between "a" and "\n" in STDERR.puts "a".
- [ruby-dev:25080] */
- if (fptr->stdio_file != stderr && !rb_thread_fd_writable(fptr->fd)) {
+ if (fptr->mode & FMODE_SYNC) {
+ io_fflush(f, fptr);
+ if (!rb_thread_fd_writable(fileno(f))) {
rb_io_check_closed(fptr);
}
retry:
@@ -582,39 +470,69 @@ io_fwrite(VALUE str, OpenFile *fptr)
l = PIPE_BUF;
}
TRAP_BEG;
- r = write(fptr->fd, RSTRING_PTR(str)+offset, l);
- TRAP_END; /* xxx: signal handler may modify given string. */
+ r = write(fileno(f), RSTRING(str)->ptr+offset, l);
+ TRAP_END;
if (r == n) return len;
if (0 <= r) {
offset += r;
n -= r;
errno = EAGAIN;
}
- if (rb_io_wait_writable(fptr->fd)) {
+ if (rb_io_wait_writable(fileno(f))) {
rb_io_check_closed(fptr);
- if (offset < RSTRING_LEN(str))
+ if (offset < RSTRING(str)->len)
goto retry;
}
return -1L;
}
-
- if (fptr->wbuf_off) {
- if (fptr->wbuf_len)
- MEMMOVE(fptr->wbuf, fptr->wbuf+fptr->wbuf_off, char, fptr->wbuf_len);
- fptr->wbuf_off = 0;
+#if defined(__human68k__) || defined(__vms)
+ do {
+ if (fputc(RSTRING(str)->ptr[offset++], f) == EOF) {
+ if (ferror(f)) return -1L;
+ break;
+ }
+ } while (--n > 0);
+#else
+ while (errno = 0, offset += (r = fwrite(RSTRING(str)->ptr+offset, 1, n, f)), (n -= r) > 0) {
+ if (ferror(f)
+#if defined __BORLANDC__
+ || errno
+#endif
+ ) {
+#ifdef __hpux
+ if (!errno) errno = EAGAIN;
+#elif defined(_WIN32) && !defined(__BORLANDC__)
+ /* workaround for MSVCRT's bug */
+ if (!errno) {
+ if (GetLastError() == ERROR_NO_DATA)
+ errno = EPIPE;
+ else
+ errno = EBADF;
+ }
+#endif
+ if (rb_io_wait_writable(fileno(f))) {
+ rb_io_check_closed(fptr);
+ clearerr(f);
+ if (offset < RSTRING(str)->len)
+ continue;
+ }
+ return -1L;
+ }
}
- MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, RSTRING_PTR(str)+offset, char, len);
- fptr->wbuf_len += len;
- return len;
+#endif
+ return len - n;
}
long
-rb_io_fwrite(const char *ptr, long len, FILE *f)
+rb_io_fwrite(ptr, len, f)
+ const char *ptr;
+ long len;
+ FILE *f;
{
OpenFile of;
- of.fd = fileno(f);
- of.stdio_file = f;
+ of.f = f;
+ of.f2 = NULL;
of.mode = FMODE_WRITABLE;
of.path = NULL;
return io_fwrite(rb_str_new(ptr, len), &of);
@@ -623,49 +541,53 @@ rb_io_fwrite(const char *ptr, long len, FILE *f)
/*
* call-seq:
* ios.write(string) => integer
- *
+ *
* Writes the given string to <em>ios</em>. The stream must be opened
* for writing. If the argument is not a string, it will be converted
* to a string using <code>to_s</code>. Returns the number of bytes
* written.
- *
+ *
* count = $stdout.write( "This is a test\n" )
* puts "That was #{count} bytes of data"
- *
+ *
* <em>produces:</em>
- *
+ *
* This is a test
* That was 15 bytes of data
*/
static VALUE
-io_write(VALUE io, VALUE str)
+io_write(io, str)
+ VALUE io, str;
{
OpenFile *fptr;
long n;
- VALUE tmp;
rb_secure(4);
- str = rb_obj_as_string(str);
- tmp = rb_io_check_io(io);
- if (NIL_P(tmp)) {
+ if (TYPE(str) != T_STRING)
+ str = rb_obj_as_string(str);
+
+ if (TYPE(io) != T_FILE) {
/* port is not IO, call write method for it. */
return rb_funcall(io, id_write, 1, str);
}
- io = tmp;
- if (RSTRING_LEN(str) == 0) return INT2FIX(0);
+ if (RSTRING(str)->len == 0) return INT2FIX(0);
GetOpenFile(io, fptr);
rb_io_check_writable(fptr);
n = io_fwrite(str, fptr);
if (n == -1L) rb_sys_fail(fptr->path);
+ if (!(fptr->mode & FMODE_SYNC)) {
+ fptr->mode |= FMODE_WBUF;
+ }
return LONG2FIX(n);
}
VALUE
-rb_io_write(VALUE io, VALUE str)
+rb_io_write(io, str)
+ VALUE io, str;
{
return rb_funcall(io, id_write, 1, str);
}
@@ -673,21 +595,21 @@ rb_io_write(VALUE io, VALUE str)
/*
* call-seq:
* ios << obj => ios
- *
+ *
* String Output---Writes <i>obj</i> to <em>ios</em>.
* <i>obj</i> will be converted to a string using
* <code>to_s</code>.
- *
+ *
* $stdout << "Hello " << "world!\n"
- *
+ *
* <em>produces:</em>
- *
+ *
* Hello world!
*/
-
VALUE
-rb_io_addstr(VALUE io, VALUE str)
+rb_io_addstr(io, str)
+ VALUE io, str;
{
rb_io_write(io, str);
return io;
@@ -696,36 +618,31 @@ rb_io_addstr(VALUE io, VALUE str)
/*
* call-seq:
* ios.flush => ios
- *
+ *
* Flushes any buffered data within <em>ios</em> to the underlying
* operating system (note that this is Ruby internal buffering only;
* the OS may buffer the data as well).
- *
+ *
* $stdout.print "no newline"
* $stdout.flush
- *
+ *
* <em>produces:</em>
- *
+ *
* no newline
*/
-VALUE
-rb_io_flush(VALUE io)
+static VALUE
+rb_io_flush(io)
+ VALUE io;
{
OpenFile *fptr;
-
- if (TYPE(io) != T_FILE) {
- return rb_funcall(io, id_flush, 0);
- }
+ FILE *f;
GetOpenFile(io, fptr);
+ rb_io_check_writable(fptr);
+ f = GetWriteFile(fptr);
- if (fptr->mode & FMODE_WRITABLE) {
- io_fflush(fptr);
- }
- if (fptr->mode & FMODE_READABLE) {
- io_unread(fptr);
- }
+ io_fflush(f, fptr);
return io;
}
@@ -734,9 +651,9 @@ rb_io_flush(VALUE io)
* call-seq:
* ios.pos => integer
* ios.tell => integer
- *
+ *
* Returns the current offset (in bytes) of <em>ios</em>.
- *
+ *
* f = File.new("testfile")
* f.pos #=> 0
* f.gets #=> "This is line one\n"
@@ -744,19 +661,22 @@ rb_io_flush(VALUE io)
*/
static VALUE
-rb_io_tell(VALUE io)
+rb_io_tell(io)
+ VALUE io;
{
OpenFile *fptr;
off_t pos;
GetOpenFile(io, fptr);
pos = io_tell(fptr);
- if (pos < 0) rb_sys_fail(fptr->path);
+ if (pos < 0 && errno) rb_sys_fail(fptr->path);
return OFFT2NUM(pos);
}
static VALUE
-rb_io_seek(VALUE io, VALUE offset, int whence)
+rb_io_seek(io, offset, whence)
+ VALUE io, offset;
+ int whence;
{
OpenFile *fptr;
off_t pos;
@@ -764,7 +684,8 @@ rb_io_seek(VALUE io, VALUE offset, int whence)
pos = NUM2OFFT(offset);
GetOpenFile(io, fptr);
pos = io_seek(fptr, pos, whence);
- if (pos < 0) rb_sys_fail(fptr->path);
+ if (pos < 0 && errno) rb_sys_fail(fptr->path);
+ clearerr(fptr->f);
return INT2FIX(0);
}
@@ -772,26 +693,29 @@ rb_io_seek(VALUE io, VALUE offset, int whence)
/*
* call-seq:
* ios.seek(amount, whence=SEEK_SET) -> 0
- *
+ *
* Seeks to a given offset <i>anInteger</i> in the stream according to
* the value of <i>whence</i>:
*
* IO::SEEK_CUR | Seeks to _amount_ plus current position
* --------------+----------------------------------------------------
- * IO::SEEK_END | Seeks to _amount_ plus end of stream (you probably
+ * IO::SEEK_END | Seeks to _amount_ plus end of stream (you probably
* | want a negative value for _amount_)
* --------------+----------------------------------------------------
* IO::SEEK_SET | Seeks to the absolute location given by _amount_
*
* Example:
- *
+ *
* f = File.new("testfile")
* f.seek(-13, IO::SEEK_END) #=> 0
* f.readline #=> "And so on...\n"
*/
static VALUE
-rb_io_seek_m(int argc, VALUE *argv, VALUE io)
+rb_io_seek_m(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE offset, ptrname;
int whence = SEEK_SET;
@@ -806,16 +730,17 @@ rb_io_seek_m(int argc, VALUE *argv, VALUE io)
/*
* call-seq:
* ios.pos = integer => integer
- *
+ *
* Seeks to the given position (in bytes) in <em>ios</em>.
- *
+ *
* f = File.new("testfile")
* f.pos = 17
* f.gets #=> "This is line two\n"
*/
static VALUE
-rb_io_set_pos(VALUE io, VALUE offset)
+rb_io_set_pos(io, offset)
+ VALUE io, offset;
{
OpenFile *fptr;
off_t pos;
@@ -823,7 +748,8 @@ rb_io_set_pos(VALUE io, VALUE offset)
pos = NUM2OFFT(offset);
GetOpenFile(io, fptr);
pos = io_seek(fptr, pos, SEEK_SET);
- if (pos < 0) rb_sys_fail(fptr->path);
+ if (pos != 0) rb_sys_fail(fptr->path);
+ clearerr(fptr->f);
return OFFT2NUM(pos);
}
@@ -831,10 +757,10 @@ rb_io_set_pos(VALUE io, VALUE offset)
/*
* call-seq:
* ios.rewind => 0
- *
+ *
* Positions <em>ios</em> to the beginning of input, resetting
* <code>lineno</code> to zero.
- *
+ *
* f = File.new("testfile")
* f.readline #=> "This is line one\n"
* f.rewind #=> 0
@@ -843,12 +769,14 @@ rb_io_set_pos(VALUE io, VALUE offset)
*/
static VALUE
-rb_io_rewind(VALUE io)
+rb_io_rewind(io)
+ VALUE io;
{
OpenFile *fptr;
GetOpenFile(io, fptr);
- if (io_seek(fptr, 0L, 0) < 0) rb_sys_fail(fptr->path);
+ if (io_seek(fptr, 0L, 0) != 0) rb_sys_fail(fptr->path);
+ clearerr(fptr->f);
if (io == current_file) {
gets_lineno -= fptr->lineno;
}
@@ -857,43 +785,6 @@ rb_io_rewind(VALUE io)
return INT2FIX(0);
}
-static int
-io_getc(OpenFile *fptr)
-{
- int r;
- if (fptr->fd == 0 && (fptr->mode & FMODE_TTY) && TYPE(rb_stdout) == T_FILE) {
- OpenFile *ofp;
- GetOpenFile(rb_stdout, ofp);
- if (ofp->mode & FMODE_TTY) {
- rb_io_flush(rb_stdout);
- }
- }
- if (fptr->rbuf == NULL) {
- fptr->rbuf_off = 0;
- fptr->rbuf_len = 0;
- fptr->rbuf_capa = 8192;
- fptr->rbuf = ALLOC_N(char, fptr->rbuf_capa);
- }
- if (fptr->rbuf_len == 0) {
- retry:
- TRAP_BEG;
- r = read(fptr->fd, fptr->rbuf, fptr->rbuf_capa);
- TRAP_END; /* xxx: signal handler may modify rbuf */
- if (r < 0) {
- if (rb_io_wait_readable(fptr->fd))
- goto retry;
- rb_sys_fail(fptr->path);
- }
- fptr->rbuf_off = 0;
- fptr->rbuf_len = r;
- if (r == 0)
- return -1; /* EOF */
- }
- fptr->rbuf_off++;
- fptr->rbuf_len--;
- return (unsigned char)fptr->rbuf[fptr->rbuf_off-1];
-}
-
/*
* call-seq:
* ios.eof => true or false
@@ -927,7 +818,8 @@ io_getc(OpenFile *fptr)
*/
VALUE
-rb_io_eof(VALUE io)
+rb_io_eof(io)
+ VALUE io;
{
OpenFile *fptr;
int ch;
@@ -935,32 +827,39 @@ rb_io_eof(VALUE io)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
- if (READ_DATA_PENDING(fptr)) return Qfalse;
- READ_CHECK(fptr);
- ch = io_getc(fptr);
+ if (feof(fptr->f)) return Qtrue;
+ if (READ_DATA_PENDING(fptr->f)) return Qfalse;
+ READ_CHECK(fptr->f);
+ clearerr(fptr->f);
+ TRAP_BEG;
+ ch = getc(fptr->f);
+ TRAP_END;
if (ch != EOF) {
- io_ungetc(ch, fptr);
+ ungetc(ch, fptr->f);
return Qfalse;
}
+ rb_io_check_closed(fptr);
+ clearerr(fptr->f);
return Qtrue;
}
/*
* call-seq:
* ios.sync => true or false
- *
+ *
* Returns the current ``sync mode'' of <em>ios</em>. When sync mode is
* true, all output is immediately flushed to the underlying operating
* system and is not buffered by Ruby internally. See also
* <code>IO#fsync</code>.
- *
+ *
* f = File.new("testfile")
* f.sync #=> false
*/
static VALUE
-rb_io_sync(VALUE io)
+rb_io_sync(io)
+ VALUE io;
{
OpenFile *fptr;
@@ -971,20 +870,21 @@ rb_io_sync(VALUE io)
/*
* call-seq:
* ios.sync = boolean => boolean
- *
+ *
* Sets the ``sync mode'' to <code>true</code> or <code>false</code>.
* When sync mode is true, all output is immediately flushed to the
* underlying operating system and is not buffered internally. Returns
* the new state. See also <code>IO#fsync</code>.
- *
+ *
* f = File.new("testfile")
* f.sync = true
- *
+ *
* <em>(produces no output)</em>
*/
static VALUE
-rb_io_set_sync(VALUE io, VALUE mode)
+rb_io_set_sync(io, mode)
+ VALUE io, mode;
{
OpenFile *fptr;
@@ -1001,7 +901,7 @@ rb_io_set_sync(VALUE io, VALUE mode)
/*
* call-seq:
* ios.fsync => 0 or nil
- *
+ *
* Immediately writes all buffered data in <em>ios</em> to disk.
* Returns <code>nil</code> if the underlying operating system does not
* support <em>fsync(2)</em>. Note that <code>fsync</code> differs from
@@ -1011,15 +911,18 @@ rb_io_set_sync(VALUE io, VALUE mode)
*/
static VALUE
-rb_io_fsync(VALUE io)
+rb_io_fsync(io)
+ VALUE io;
{
#ifdef HAVE_FSYNC
OpenFile *fptr;
+ FILE *f;
GetOpenFile(io, fptr);
+ f = GetWriteFile(fptr);
- io_fflush(fptr);
- if (fsync(fptr->fd) < 0)
+ io_fflush(f, fptr);
+ if (fsync(fileno(f)) < 0)
rb_sys_fail(fptr->path);
return INT2FIX(0);
#else
@@ -1032,48 +935,49 @@ rb_io_fsync(VALUE io)
* call-seq:
* ios.fileno => fixnum
* ios.to_i => fixnum
- *
+ *
* Returns an integer representing the numeric file descriptor for
* <em>ios</em>.
- *
+ *
* $stdin.fileno #=> 0
* $stdout.fileno #=> 1
*/
static VALUE
-rb_io_fileno(VALUE io)
+rb_io_fileno(io)
+ VALUE io;
{
OpenFile *fptr;
int fd;
GetOpenFile(io, fptr);
- fd = fptr->fd;
+ fd = fileno(fptr->f);
return INT2FIX(fd);
}
-
/*
* call-seq:
* ios.pid => fixnum
- *
+ *
* Returns the process ID of a child process associated with
* <em>ios</em>. This will be set by <code>IO::popen</code>.
- *
+ *
* pipe = IO.popen("-")
* if pipe
* $stderr.puts "In parent, child pid is #{pipe.pid}"
* else
* $stderr.puts "In child, pid is #{$$}"
* end
- *
+ *
* <em>produces:</em>
- *
+ *
* In child, pid is 26209
* In parent, child pid is 26209
*/
static VALUE
-rb_io_pid(VALUE io)
+rb_io_pid(io)
+ VALUE io;
{
OpenFile *fptr;
@@ -1083,7 +987,6 @@ rb_io_pid(VALUE io)
return INT2FIX(fptr->pid);
}
-
/*
* call-seq:
* ios.inspect => string
@@ -1092,123 +995,164 @@ rb_io_pid(VALUE io)
*/
static VALUE
-rb_io_inspect(VALUE obj)
+rb_io_inspect(obj)
+ VALUE obj;
{
OpenFile *fptr;
- char *cname;
- const char *st = "";
+ char *buf, *cname, *st = "";
+ long len;
fptr = RFILE(rb_io_taint_check(obj))->fptr;
if (!fptr || !fptr->path) return rb_any_to_s(obj);
cname = rb_obj_classname(obj);
- if (fptr->fd < 0) {
+ len = strlen(cname) + strlen(fptr->path) + 5;
+ if (!(fptr->f || fptr->f2)) {
st = " (closed)";
+ len += 9;
}
- return rb_sprintf("#<%s:%s%s>", cname, fptr->path, st);
+ buf = ALLOCA_N(char, len);
+ snprintf(buf, len, "#<%s:%s%s>", cname, fptr->path, st);
+ return rb_str_new2(buf);
}
/*
* call-seq:
* ios.to_io -> ios
- *
+ *
* Returns <em>ios</em>.
*/
static VALUE
-rb_io_to_io(VALUE io)
+rb_io_to_io(io)
+ VALUE io;
{
return io;
}
/* reading functions */
static long
-read_buffered_data(char *ptr, long len, OpenFile *fptr)
+read_buffered_data(ptr, len, f)
+ char *ptr;
+ long len;
+ FILE *f;
{
long n;
- n = READ_DATA_PENDING_COUNT(fptr);
+#ifdef READ_DATA_PENDING_COUNT
+ n = READ_DATA_PENDING_COUNT(f);
if (n <= 0) return 0;
if (n > len) n = len;
- MEMMOVE(ptr, fptr->rbuf+fptr->rbuf_off, char, n);
- fptr->rbuf_off += n;
- fptr->rbuf_len -= n;
+ return fread(ptr, 1, n, f);
+#else
+ int c;
+
+ for (n = 0; n < len && READ_DATA_PENDING(f) && (c = getc(f)) != EOF; ++n) {
+ *ptr++ = c;
+ }
return n;
+#endif
}
static long
-io_fread(VALUE str, long offset, OpenFile *fptr)
+io_fread(ptr, len, fptr)
+ char *ptr;
+ long len;
+ OpenFile *fptr;
{
- long len = RSTRING_LEN(str) - offset;
long n = len;
int c;
+ int saved_errno;
while (n > 0) {
- c = read_buffered_data(RSTRING_PTR(str)+offset, n, fptr);
- if (c > 0) {
- offset += c;
- if ((n -= c) <= 0) break;
- }
- rb_thread_wait_fd(fptr->fd);
- rb_io_check_closed(fptr);
- c = io_getc(fptr);
- if (c < 0) {
+ c = read_buffered_data(ptr, n, fptr->f);
+ if (c < 0) goto eof;
+ if (c > 0) {
+ ptr += c;
+ if ((n -= c) <= 0) break;
+ }
+ rb_thread_wait_fd(fileno(fptr->f));
+ rb_io_check_closed(fptr);
+ clearerr(fptr->f);
+ TRAP_BEG;
+ c = getc(fptr->f);
+ TRAP_END;
+ if (c == EOF) {
+ eof:
+ if (ferror(fptr->f)) {
+ switch (errno) {
+ case EINTR:
+#if defined(ERESTART)
+ case ERESTART:
+#endif
+ clearerr(fptr->f);
+ continue;
+ case EAGAIN:
+#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
+ case EWOULDBLOCK:
+#endif
+ if (len > n) {
+ clearerr(fptr->f);
+ }
+ saved_errno = errno;
+ rb_warning("nonblocking IO#read is obsolete; use IO#readpartial or IO#sysread");
+ errno = saved_errno;
+ }
+ if (len == n) return 0;
+ }
break;
}
- RSTRING_PTR(str)[offset++] = c;
- if (offset > RSTRING_LEN(str)) break;
+ *ptr++ = c;
n--;
}
return len - n;
}
long
-rb_io_fread(char *ptr, long len, FILE *f)
+rb_io_fread(ptr, len, f)
+ char *ptr;
+ long len;
+ FILE *f;
{
OpenFile of;
- VALUE str;
- long n;
- of.fd = fileno(f);
- of.stdio_file = f;
- of.mode = FMODE_READABLE;
- str = rb_str_new(ptr, len);
- n = io_fread(str, 0, &of);
- MEMCPY(ptr, RSTRING_PTR(str), char, n);
- return n;
+ of.f = f;
+ of.f2 = NULL;
+ return io_fread(ptr, len, &of);
}
#define SMALLBUF 100
static long
-remain_size(OpenFile *fptr)
+remain_size(fptr)
+ OpenFile *fptr;
{
struct stat st;
- off_t siz = READ_DATA_PENDING_COUNT(fptr);
+ off_t siz = BUFSIZ;
off_t pos;
- if (fstat(fptr->fd, &st) == 0 && S_ISREG(st.st_mode)
+ if (feof(fptr->f)) return 0;
+ if (fstat(fileno(fptr->f), &st) == 0 && S_ISREG(st.st_mode)
#ifdef __BEOS__
&& (st.st_dev > 3)
#endif
)
{
- io_fflush(fptr);
- pos = lseek(fptr->fd, 0, SEEK_CUR);
+ pos = io_tell(fptr);
if (st.st_size >= pos && pos >= 0) {
- siz += st.st_size - pos + 1;
+ siz = st.st_size - pos + 1;
if (siz > LONG_MAX) {
rb_raise(rb_eIOError, "file too big for single read");
}
}
}
- else {
- siz += BUFSIZ;
- }
return (long)siz;
}
static VALUE
-read_all(OpenFile *fptr, long siz, VALUE str)
+read_all(fptr, siz, str)
+ OpenFile *fptr;
+ long siz;
+ VALUE str;
{
long bytes = 0;
long n;
@@ -1221,10 +1165,15 @@ read_all(OpenFile *fptr, long siz, VALUE str)
rb_str_resize(str, siz);
}
for (;;) {
- READ_CHECK(fptr);
- n = io_fread(str, bytes, fptr);
+ rb_str_locktmp(str);
+ READ_CHECK(fptr->f);
+ n = io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr);
+ rb_str_unlocktmp(str);
if (n == 0 && bytes == 0) {
- break;
+ if (!fptr->f) break;
+ if (feof(fptr->f)) break;
+ if (!ferror(fptr->f)) break;
+ rb_sys_fail(fptr->path);
}
bytes += n;
if (bytes < siz) break;
@@ -1241,7 +1190,7 @@ void rb_io_set_nonblock(OpenFile *fptr)
{
int flags;
#ifdef F_GETFL
- flags = fcntl(fptr->fd, F_GETFL);
+ flags = fcntl(fileno(fptr->f), F_GETFL);
if (flags == -1) {
rb_sys_fail(fptr->path);
}
@@ -1250,10 +1199,26 @@ void rb_io_set_nonblock(OpenFile *fptr)
#endif
if ((flags & O_NONBLOCK) == 0) {
flags |= O_NONBLOCK;
- if (fcntl(fptr->fd, F_SETFL, flags) == -1) {
+ if (fcntl(fileno(fptr->f), F_SETFL, flags) == -1) {
rb_sys_fail(fptr->path);
}
}
+ if (fptr->f2) {
+#ifdef F_GETFL
+ flags = fcntl(fileno(fptr->f2), F_GETFL);
+ if (flags == -1) {
+ rb_sys_fail(fptr->path);
+ }
+#else
+ flags = 0;
+#endif
+ if ((flags & O_NONBLOCK) == 0) {
+ flags |= O_NONBLOCK;
+ if (fcntl(fileno(fptr->f2), F_SETFL, flags) == -1) {
+ rb_sys_fail(fptr->path);
+ }
+ }
+ }
}
static VALUE
@@ -1266,15 +1231,15 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
rb_scan_args(argc, argv, "11", &length, &str);
if ((len = NUM2LONG(length)) < 0) {
- rb_raise(rb_eArgError, "negative length %ld given", len);
+ rb_raise(rb_eArgError, "negative length %ld given", len);
}
if (NIL_P(str)) {
- str = rb_str_new(0, len);
+ str = rb_str_new(0, len);
}
else {
- StringValue(str);
- rb_str_modify(str);
+ StringValue(str);
+ rb_str_modify(str);
rb_str_resize(str, len);
}
OBJ_TAINT(str);
@@ -1283,29 +1248,30 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
rb_io_check_readable(fptr);
if (len == 0)
- return str;
+ return str;
- if (!nonblock)
- READ_CHECK(fptr);
- if (RSTRING_LEN(str) != len) {
+ if (!nonblock) {
+ READ_CHECK(fptr->f);
+ }
+ if (RSTRING(str)->len != len) {
modified:
- rb_raise(rb_eRuntimeError, "buffer string modified");
+ rb_raise(rb_eRuntimeError, "buffer string modified");
}
- n = read_buffered_data(RSTRING_PTR(str), len, fptr);
+ n = read_buffered_data(RSTRING(str)->ptr, len, fptr->f);
if (n <= 0) {
again:
- if (RSTRING_LEN(str) != len) goto modified;
+ if (RSTRING(str)->len != len) goto modified;
if (nonblock) {
rb_io_set_nonblock(fptr);
- n = read(fptr->fd, RSTRING_PTR(str), len);
+ n = read(fileno(fptr->f), RSTRING(str)->ptr, len);
}
else {
TRAP_BEG;
- n = read(fptr->fd, RSTRING_PTR(str), len);
+ n = read(fileno(fptr->f), RSTRING(str)->ptr, len);
TRAP_END;
}
if (n < 0) {
- if (!nonblock && rb_io_wait_readable(fptr->fd))
+ if (!nonblock && rb_io_wait_readable(fileno(fptr->f)))
goto again;
rb_sys_fail(fptr->path);
}
@@ -1436,14 +1402,13 @@ io_read_nonblock(int argc, VALUE *argv, VALUE io)
* The result may also be smaller than string.length (partial write).
* The caller should care such errors and partial write.
*
- * If the write buffer is not empty, it is flushed at first.
- *
*/
static VALUE
rb_io_write_nonblock(VALUE io, VALUE str)
{
OpenFile *fptr;
+ FILE *f;
long n;
rb_secure(4);
@@ -1453,10 +1418,10 @@ rb_io_write_nonblock(VALUE io, VALUE str)
GetOpenFile(io, fptr);
rb_io_check_writable(fptr);
- io_fflush(fptr);
+ f = GetWriteFile(fptr);
rb_io_set_nonblock(fptr);
- n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
+ n = write(fileno(f), RSTRING(str)->ptr, RSTRING(str)->len);
if (n == -1) rb_sys_fail(fptr->path);
@@ -1479,14 +1444,15 @@ rb_io_write_nonblock(VALUE io, VALUE str)
* <code><i>ios</i>.read(nil)</code> returns <code>""</code>.
* <code><i>ios</i>.read(<i>positive-integer</i>)</code> returns nil.
*
- * <code><i>ios</i>.read(0)</code> returns <code>""</code>.
- *
* f = File.new("testfile")
* f.read(16) #=> "This is line one"
*/
static VALUE
-io_read(int argc, VALUE *argv, VALUE io)
+io_read(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
OpenFile *fptr;
long n, len;
@@ -1516,50 +1482,69 @@ io_read(int argc, VALUE *argv, VALUE io)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
+ if (feof(fptr->f)) return Qnil;
if (len == 0) return str;
- READ_CHECK(fptr);
- if (RSTRING_LEN(str) != len) {
+ rb_str_locktmp(str);
+ READ_CHECK(fptr->f);
+ if (RSTRING(str)->len != len) {
rb_raise(rb_eRuntimeError, "buffer string modified");
}
- n = io_fread(str, 0, fptr);
+ n = io_fread(RSTRING(str)->ptr, len, fptr);
+ rb_str_unlocktmp(str);
if (n == 0) {
- if (fptr->fd < 0) return Qnil;
- rb_str_resize(str, 0);
- return Qnil;
+ if (!fptr->f) return Qnil;
+ if (feof(fptr->f)) {
+ rb_str_resize(str, 0);
+ return Qnil;
+ }
+ if (len > 0) rb_sys_fail(fptr->path);
}
rb_str_resize(str, n);
+ RSTRING(str)->len = n;
+ RSTRING(str)->ptr[n] = '\0';
OBJ_TAINT(str);
return str;
}
static int
-appendline(OpenFile *fptr, int delim, VALUE *strp)
+appendline(fptr, delim, strp)
+ OpenFile *fptr;
+ int delim;
+ VALUE *strp;
{
+ FILE *f = fptr->f;
VALUE str = *strp;
int c = EOF;
+#ifndef READ_DATA_PENDING_PTR
+ char buf[8192];
+ char *bp = buf, *bpe = buf + sizeof buf - 3;
+ int update = Qfalse;
+#endif
do {
- long pending = READ_DATA_PENDING_COUNT(fptr);
+#ifdef READ_DATA_PENDING_PTR
+ long pending = READ_DATA_PENDING_COUNT(f);
if (pending > 0) {
- const char *p = READ_DATA_PENDING_PTR(fptr);
+ const char *p = READ_DATA_PENDING_PTR(f);
const char *e = memchr(p, delim, pending);
long last = 0, len = (c != EOF);
if (e) pending = e - p + 1;
len += pending;
if (!NIL_P(str)) {
- last = RSTRING_LEN(str);
+ last = RSTRING(str)->len;
rb_str_resize(str, last + len);
}
else {
*strp = str = rb_str_buf_new(len);
- rb_str_set_len(str, len);
+ RSTRING(str)->len = len;
+ RSTRING(str)->ptr[len] = '\0';
}
if (c != EOF) {
- RSTRING_PTR(str)[last++] = c;
+ RSTRING(str)->ptr[last++] = c;
}
- read_buffered_data(RSTRING_PTR(str) + last, pending, fptr); /* must not fail */
+ fread(RSTRING(str)->ptr + last, 1, pending, f); /* must not fail */
if (e) return delim;
}
else if (c != EOF) {
@@ -1569,18 +1554,51 @@ appendline(OpenFile *fptr, int delim, VALUE *strp)
}
else {
*strp = str = rb_str_buf_new(1);
- rb_str_resize(str, 1);
- RSTRING_PTR(str)[0] = c;
+ RSTRING(str)->ptr[RSTRING(str)->len++] = c;
}
}
- rb_thread_wait_fd(fptr->fd);
+ rb_thread_wait_fd(fileno(f));
rb_io_check_closed(fptr);
- c = io_getc(fptr);
- if (c < 0) {
+#else
+ READ_CHECK(f);
+#endif
+ clearerr(f);
+ TRAP_BEG;
+ c = getc(f);
+ TRAP_END;
+ if (c == EOF) {
+ if (ferror(f)) {
+ clearerr(f);
+ if (!rb_io_wait_readable(fileno(f)))
+ rb_sys_fail(fptr->path);
+ continue;
+ }
+#ifdef READ_DATA_PENDING_PTR
return c;
+#endif
}
+#ifndef READ_DATA_PENDING_PTR
+ if (c == EOF || (*bp++ = c) == delim || bp == bpe) {
+ int cnt = bp - buf;
+
+ if (cnt > 0) {
+ if (!NIL_P(str))
+ rb_str_cat(str, buf, cnt);
+ else
+ *strp = str = rb_str_new(buf, cnt);
+ }
+ if (c == EOF) {
+ if (update)
+ return (int)RSTRING(str)->ptr[RSTRING(str)->len-1];
+ return c;
+ }
+ bp = buf;
+ }
+ update = Qtrue;
+#endif
} while (c != delim);
+#ifdef READ_DATA_PENDING_PTR
{
char ch = c;
if (!NIL_P(str)) {
@@ -1590,33 +1608,44 @@ appendline(OpenFile *fptr, int delim, VALUE *strp)
*strp = str = rb_str_new(&ch, 1);
}
}
+#endif
return c;
}
static inline int
-swallow(OpenFile *fptr, int term)
+swallow(fptr, term)
+ OpenFile *fptr;
+ int term;
{
+ FILE *f = fptr->f;
int c;
do {
+#ifdef READ_DATA_PENDING_PTR
long cnt;
- while ((cnt = READ_DATA_PENDING_COUNT(fptr)) > 0) {
+ while ((cnt = READ_DATA_PENDING_COUNT(f)) > 0) {
char buf[1024];
- const char *p = READ_DATA_PENDING_PTR(fptr);
+ const char *p = READ_DATA_PENDING_PTR(f);
int i;
if (cnt > sizeof buf) cnt = sizeof buf;
if (*p != term) return Qtrue;
i = cnt;
while (--i && *++p == term);
- if (!read_buffered_data(buf, cnt - i, fptr)) /* must not fail */
+ if (!fread(buf, 1, cnt - i, f)) /* must not fail */
rb_sys_fail(fptr->path);
}
- rb_thread_wait_fd(fptr->fd);
+ rb_thread_wait_fd(fileno(f));
rb_io_check_closed(fptr);
- c = io_getc(fptr);
+#else
+ READ_CHECK(f);
+#endif
+ clearerr(f);
+ TRAP_BEG;
+ c = getc(f);
+ TRAP_END;
if (c != term) {
- io_ungetc(c, fptr);
+ ungetc(c, f);
return Qtrue;
}
} while (c != EOF);
@@ -1624,7 +1653,9 @@ swallow(OpenFile *fptr, int term)
}
static VALUE
-rb_io_getline_fast(OpenFile *fptr, unsigned char delim)
+rb_io_getline_fast(fptr, delim)
+ OpenFile *fptr;
+ unsigned char delim;
{
VALUE str = Qnil;
int c;
@@ -1641,15 +1672,21 @@ rb_io_getline_fast(OpenFile *fptr, unsigned char delim)
}
static int
-rscheck(const char *rsptr, long rslen, VALUE rs)
+rscheck(rsptr, rslen, rs)
+ char *rsptr;
+ long rslen;
+ VALUE rs;
{
- if (RSTRING_PTR(rs) != rsptr && RSTRING_LEN(rs) != rslen)
+ if (RSTRING(rs)->ptr != rsptr && RSTRING(rs)->len != rslen)
rb_raise(rb_eRuntimeError, "rs modified");
- return 0;
+ return 1;
}
+static VALUE rb_io_getline(VALUE rs, VALUE io);
+
static VALUE
-rb_io_getline(VALUE rs, VALUE io)
+rb_io_getline(rs, io)
+ VALUE rs, io;
{
VALUE str = Qnil;
OpenFile *fptr;
@@ -1658,18 +1695,18 @@ rb_io_getline(VALUE rs, VALUE io)
rb_io_check_readable(fptr);
if (NIL_P(rs)) {
str = read_all(fptr, 0, Qnil);
- if (RSTRING_LEN(str) == 0) return Qnil;
+ if (RSTRING(str)->len == 0) return Qnil;
}
else if (rs == rb_default_rs) {
return rb_io_getline_fast(fptr, '\n');
}
else {
int c, newline;
- const char *rsptr;
+ char *rsptr;
long rslen;
int rspara = 0;
- rslen = RSTRING_LEN(rs);
+ rslen = RSTRING(rs)->len;
if (rslen == 0) {
rsptr = "\n\n";
rslen = 2;
@@ -1677,21 +1714,17 @@ rb_io_getline(VALUE rs, VALUE io)
swallow(fptr, '\n');
}
else if (rslen == 1) {
- return rb_io_getline_fast(fptr, (unsigned char)RSTRING_PTR(rs)[0]);
+ return rb_io_getline_fast(fptr, (unsigned char)RSTRING(rs)->ptr[0]);
}
else {
- rsptr = RSTRING_PTR(rs);
+ rsptr = RSTRING(rs)->ptr;
}
newline = rsptr[rslen - 1];
- while ((c = appendline(fptr, newline, &str)) != EOF) {
- if (c == newline) {
- if (RSTRING_LEN(str) < rslen) continue;
- if (!rspara) rscheck(rsptr, rslen, rs);
- if (memcmp(RSTRING_PTR(str) + RSTRING_LEN(str) - rslen,
- rsptr, rslen) == 0) break;
- }
- }
+ while ((c = appendline(fptr, newline, &str)) != EOF &&
+ (c != newline || RSTRING(str)->len < rslen ||
+ ((rspara || rscheck(rsptr,rslen,rs)) && 0) ||
+ memcmp(RSTRING(str)->ptr+RSTRING(str)->len-rslen,rsptr,rslen)));
if (rspara) {
if (c != EOF) {
@@ -1710,7 +1743,8 @@ rb_io_getline(VALUE rs, VALUE io)
}
VALUE
-rb_io_gets(VALUE io)
+rb_io_gets(io)
+ VALUE io;
{
OpenFile *fptr;
@@ -1722,7 +1756,7 @@ rb_io_gets(VALUE io)
/*
* call-seq:
* ios.gets(sep_string=$/) => string or nil
- *
+ *
* Reads the next ``line'' from the I/O stream; lines are separated by
* <i>sep_string</i>. A separator of <code>nil</code> reads the entire
* contents, and a zero-length separator reads the input a paragraph at
@@ -1731,13 +1765,16 @@ rb_io_gets(VALUE io)
* will be raised. The line read in will be returned and also assigned
* to <code>$_</code>. Returns <code>nil</code> if called at end of
* file.
- *
+ *
* File.new("testfile").gets #=> "This is line one\n"
* $_ #=> "This is line one\n"
*/
static VALUE
-rb_io_gets_m(int argc, VALUE *argv, VALUE io)
+rb_io_gets_m(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE rs, str;
@@ -1757,14 +1794,14 @@ rb_io_gets_m(int argc, VALUE *argv, VALUE io)
/*
* call-seq:
* ios.lineno => integer
- *
+ *
* Returns the current line number in <em>ios</em>. The stream must be
* opened for reading. <code>lineno</code> counts the number of times
* <code>gets</code> is called, rather than the number of newlines
* encountered. The two values will differ if <code>gets</code> is
* called with a separator other than newline. See also the
* <code>$.</code> variable.
- *
+ *
* f = File.new("testfile")
* f.lineno #=> 0
* f.gets #=> "This is line one\n"
@@ -1774,7 +1811,8 @@ rb_io_gets_m(int argc, VALUE *argv, VALUE io)
*/
static VALUE
-rb_io_lineno(VALUE io)
+rb_io_lineno(io)
+ VALUE io;
{
OpenFile *fptr;
@@ -1786,10 +1824,10 @@ rb_io_lineno(VALUE io)
/*
* call-seq:
* ios.lineno = integer => integer
- *
+ *
* Manually sets the current line number to the given value.
* <code>$.</code> is updated only on the next read.
- *
+ *
* f = File.new("testfile")
* f.gets #=> "This is line one\n"
* $. #=> 1
@@ -1801,7 +1839,8 @@ rb_io_lineno(VALUE io)
*/
static VALUE
-rb_io_set_lineno(VALUE io, VALUE lineno)
+rb_io_set_lineno(io, lineno)
+ VALUE io, lineno;
{
OpenFile *fptr;
@@ -1812,14 +1851,18 @@ rb_io_set_lineno(VALUE io, VALUE lineno)
}
static void
-lineno_setter(VALUE val, ID id, VALUE *var)
+lineno_setter(val, id, var)
+ VALUE val;
+ ID id;
+ VALUE *var;
{
gets_lineno = NUM2INT(val);
*var = INT2FIX(gets_lineno);
}
static VALUE
-argf_set_lineno(VALUE argf, VALUE val)
+argf_set_lineno(argf, val)
+ VALUE argf, val;
{
gets_lineno = NUM2INT(val);
lineno = INT2FIX(gets_lineno);
@@ -1827,7 +1870,7 @@ argf_set_lineno(VALUE argf, VALUE val)
}
static VALUE
-argf_lineno(void)
+argf_lineno()
{
return lineno;
}
@@ -1835,13 +1878,16 @@ argf_lineno(void)
/*
* call-seq:
* ios.readline(sep_string=$/) => string
- *
+ *
* Reads a line as with <code>IO#gets</code>, but raises an
* <code>EOFError</code> on end of file.
*/
static VALUE
-rb_io_readline(int argc, VALUE *argv, VALUE io)
+rb_io_readline(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE line = rb_io_gets_m(argc, argv, io);
@@ -1854,20 +1900,23 @@ rb_io_readline(int argc, VALUE *argv, VALUE io)
/*
* call-seq:
* ios.readlines(sep_string=$/) => array
- *
+ *
* Reads all of the lines in <em>ios</em>, and returns them in
* <i>anArray</i>. Lines are separated by the optional
* <i>sep_string</i>. If <i>sep_string</i> is <code>nil</code>, the
* rest of the stream is returned as a single record.
* The stream must be opened for reading or an
* <code>IOError</code> will be raised.
- *
+ *
* f = File.new("testfile")
* f.readlines[0] #=> "This is line one\n"
*/
static VALUE
-rb_io_readlines(int argc, VALUE *argv, VALUE io)
+rb_io_readlines(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE line, ary;
VALUE rs;
@@ -1890,16 +1939,16 @@ rb_io_readlines(int argc, VALUE *argv, VALUE io)
* call-seq:
* ios.each(sep_string=$/) {|line| block } => ios
* ios.each_line(sep_string=$/) {|line| block } => ios
- *
+ *
* Executes the block for every line in <em>ios</em>, where lines are
* separated by <i>sep_string</i>. <em>ios</em> must be opened for
* reading or an <code>IOError</code> will be raised.
- *
+ *
* f = File.new("testfile")
* f.each {|line| puts "#{f.lineno}: #{line}" }
- *
+ *
* <em>produces:</em>
- *
+ *
* 1: This is line one
* 2: This is line two
* 3: This is line three
@@ -1907,12 +1956,14 @@ rb_io_readlines(int argc, VALUE *argv, VALUE io)
*/
static VALUE
-rb_io_each_line(int argc, VALUE *argv, VALUE io)
+rb_io_each_line(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE str;
VALUE rs;
- RETURN_ENUMERATOR(io, argc, argv);
if (argc == 0) {
rs = rb_rs;
}
@@ -1928,12 +1979,12 @@ rb_io_each_line(int argc, VALUE *argv, VALUE io)
/*
* call-seq:
- * ios.each_byte {|byte| block } => ios
- *
+ * ios.each_byte {|byte| block } => nil
+ *
* Calls the given block once for each byte (0..255) in <em>ios</em>,
* passing the byte as an argument. The stream must be opened for
* reading or an <code>IOError</code> will be raised.
- *
+ *
* f = File.new("testfile")
* checksum = 0
* f.each_byte {|x| checksum ^= x } #=> #<File:testfile>
@@ -1941,115 +1992,91 @@ rb_io_each_line(int argc, VALUE *argv, VALUE io)
*/
static VALUE
-rb_io_each_byte(VALUE io)
+rb_io_each_byte(io)
+ VALUE io;
{
OpenFile *fptr;
+ FILE *f;
int c;
- RETURN_ENUMERATOR(io, 0, 0);
GetOpenFile(io, fptr);
for (;;) {
rb_io_check_readable(fptr);
- READ_CHECK(fptr);
- c = io_getc(fptr);
- if (c < 0) {
+ f = fptr->f;
+ READ_CHECK(f);
+ clearerr(f);
+ TRAP_BEG;
+ c = getc(f);
+ TRAP_END;
+ if (c == EOF) {
+ if (ferror(f)) {
+ clearerr(f);
+ if (!rb_io_wait_readable(fileno(f)))
+ rb_sys_fail(fptr->path);
+ continue;
+ }
break;
}
rb_yield(INT2FIX(c & 0xff));
}
+ if (ferror(f)) rb_sys_fail(fptr->path);
return io;
}
/*
* call-seq:
- * str.lines(separator=$/) => anEnumerator
- *
- * Returns an enumerator that gives each line in the string.
- *
- * "foo\nbar\n".lines.to_a #=> ["foo\n", "bar\n"]
- * "foo\nb ar".lines.sort #=> ["b ar", "foo\n"]
- */
-
-static VALUE
-rb_io_lines(int argc, VALUE *argv, VALUE str)
-{
- return rb_enumeratorize(str, ID2SYM(rb_intern("each_line")), argc, argv);
-}
-
-/*
- * call-seq:
- * str.bytes => anEnumerator
+ * ios.getc => fixnum or nil
*
- * Returns an enumerator that gives each byte in the string.
- *
- * "hello".bytes.to_a #=> [104, 101, 108, 108, 111]
- */
-
-static VALUE
-rb_io_bytes(VALUE str)
-{
- return rb_enumeratorize(str, ID2SYM(rb_intern("each_byte")), 0, 0);
-}
-
-VALUE
-rb_io_getc(VALUE io)
-{
- OpenFile *fptr;
- int c;
-
- GetOpenFile(io, fptr);
- rb_io_check_readable(fptr);
-
- READ_CHECK(fptr);
- c = io_getc(fptr);
-
- if (c < 0) {
- return Qnil;
- }
- return INT2FIX(c & 0xff);
-}
-
-/*
- * call-seq:
- * ios.getc => string or nil
- *
- * Reads a one-character string from <em>ios</em>. Returns
+ * Gets the next 8-bit byte (0..255) from <em>ios</em>. Returns
* <code>nil</code> if called at end of file.
- *
+ *
* f = File.new("testfile")
- * f.getc #=> "8"
- * f.getc #=> "1"
+ * f.getc #=> 84
+ * f.getc #=> 104
*/
VALUE
-rb_io_getc_m(VALUE io)
+rb_io_getc(io)
+ VALUE io;
{
- char ch;
OpenFile *fptr;
+ FILE *f;
int c;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
+ f = fptr->f;
- READ_CHECK(fptr);
- c = io_getc(fptr);
+ retry:
+ READ_CHECK(f);
+ clearerr(f);
+ TRAP_BEG;
+ c = getc(f);
+ TRAP_END;
- if (c < 0) {
+ if (c == EOF) {
+ if (ferror(f)) {
+ clearerr(f);
+ if (!rb_io_wait_readable(fileno(f)))
+ rb_sys_fail(fptr->path);
+ goto retry;
+ }
return Qnil;
}
- ch = c & 0xff;
- return rb_str_new(&ch, 1);
+ return INT2FIX(c & 0xff);
}
int
-rb_getc(FILE *f)
+rb_getc(f)
+ FILE *f;
{
int c;
- if (!STDIO_READ_DATA_PENDING(f)) {
+ if (!READ_DATA_PENDING(f)) {
rb_thread_wait_fd(fileno(f));
}
+ clearerr(f);
TRAP_BEG;
c = getc(f);
TRAP_END;
@@ -2059,16 +2086,17 @@ rb_getc(FILE *f)
/*
* call-seq:
- * ios.readchar => string
- *
+ * ios.readchar => fixnum
+ *
* Reads a character as with <code>IO#getc</code>, but raises an
* <code>EOFError</code> on end of file.
*/
static VALUE
-rb_io_readchar(VALUE io)
+rb_io_readchar(io)
+ VALUE io;
{
- VALUE c = rb_io_getc_m(io);
+ VALUE c = rb_io_getc(io);
if (NIL_P(c)) {
rb_eof_error();
@@ -2078,40 +2106,33 @@ rb_io_readchar(VALUE io)
/*
* call-seq:
- * ios.ungetc(string) => nil
- *
+ * ios.ungetc(integer) => nil
+ *
* Pushes back one character (passed as a parameter) onto <em>ios</em>,
* such that a subsequent buffered read will return it. Only one character
* may be pushed back before a subsequent read operation (that is,
* you will be able to read only the last of several characters that have been pushed
* back). Has no effect with unbuffered reads (such as <code>IO#sysread</code>).
- *
+ *
* f = File.new("testfile") #=> #<File:testfile>
- * c = f.getc #=> "8"
+ * c = f.getc #=> 84
* f.ungetc(c) #=> nil
- * f.getc #=> "8"
+ * f.getc #=> 84
*/
VALUE
-rb_io_ungetc(VALUE io, VALUE c)
+rb_io_ungetc(io, c)
+ VALUE io, c;
{
OpenFile *fptr;
- int cc;
+ int cc = NUM2INT(c);
GetOpenFile(io, fptr);
+ if (!(fptr->mode & FMODE_RBUF))
+ rb_raise(rb_eIOError, "unread stream");
rb_io_check_readable(fptr);
- if (NIL_P(c)) return Qnil;
- if (FIXNUM_P(c)) {
- cc = FIX2INT(c);
- }
- else {
- SafeStringValue(c);
- if (RSTRING_LEN(c) > 1) {
- rb_warn("IO#ungetc pushes back only one byte");
- }
- cc = (unsigned char)RSTRING_PTR(c)[0];
- }
- if (io_ungetc(cc, fptr) == EOF && cc != EOF) {
+
+ if (ungetc(cc, fptr->f) == EOF && cc != EOF) {
rb_raise(rb_eIOError, "ungetc failed");
}
return Qnil;
@@ -2121,60 +2142,75 @@ rb_io_ungetc(VALUE io, VALUE c)
* call-seq:
* ios.isatty => true or false
* ios.tty? => true or false
- *
+ *
* Returns <code>true</code> if <em>ios</em> is associated with a
* terminal device (tty), <code>false</code> otherwise.
- *
+ *
* File.new("testfile").isatty #=> false
* File.new("/dev/tty").isatty #=> true
*/
static VALUE
-rb_io_isatty(VALUE io)
+rb_io_isatty(io)
+ VALUE io;
{
OpenFile *fptr;
GetOpenFile(io, fptr);
- if (isatty(fptr->fd) == 0)
+ if (isatty(fileno(fptr->f)) == 0)
return Qfalse;
return Qtrue;
}
-#define FMODE_PREP (1<<16)
-#define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
-#define PREP_STDIO_NAME(f) ((f)->path)
-
static void
-fptr_finalize(OpenFile *fptr, int noraise)
+fptr_finalize(fptr, noraise)
+ OpenFile *fptr;
+ int noraise;
{
- if (fptr->wbuf_len) {
- io_fflush(fptr);
- }
- if (IS_PREP_STDIO(fptr) ||
- fptr->fd <= 2) {
- return;
- }
- if (fptr->stdio_file) {
- if (fclose(fptr->stdio_file) < 0 && !noraise) {
- /* fptr->stdio_file is deallocated anyway */
- fptr->stdio_file = 0;
- fptr->fd = -1;
- rb_sys_fail(fptr->path);
- }
+ int n1 = 0, n2 = 0, f1, f2 = -1;
+
+ errno = 0;
+ if (fptr->f2) {
+ f2 = fileno(fptr->f2);
+ while (n2 = 0, fflush(fptr->f2) < 0) {
+ n2 = errno;
+ if (!rb_io_wait_writable(f2)) {
+ break;
+ }
+ if (!fptr->f2) break;
+ }
+ if (fclose(fptr->f2) < 0 && n2 == 0) {
+ n2 = errno;
+ }
+ fptr->f2 = 0;
+ }
+ if (fptr->f) {
+ f1 = fileno(fptr->f);
+ if ((f2 == -1) && (fptr->mode & FMODE_WBUF)) {
+ while (n1 = 0, fflush(fptr->f) < 0) {
+ n1 = errno;
+ if (!rb_io_wait_writable(f1)) break;
+ if (!fptr->f) break;
+ }
+ }
+ if (fclose(fptr->f) < 0 && n1 == 0) {
+ n1 = errno;
+ }
+ fptr->f = 0;
+ if (n1 == EBADF && f1 == f2) {
+ n1 = 0;
+ }
}
- else if (0 <= fptr->fd) {
- if (close(fptr->fd) < 0 && !noraise) {
- /* fptr->fd is still not closed */
- rb_sys_fail(fptr->path);
- }
+ if (!noraise && (n1 || n2)) {
+ errno = (n1 ? n1 : n2);
+ rb_sys_fail(fptr->path);
}
- fptr->fd = -1;
- fptr->stdio_file = 0;
- fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE);
}
static void
-rb_io_fptr_cleanup(OpenFile *fptr, int noraise)
+rb_io_fptr_cleanup(fptr, noraise)
+ OpenFile *fptr;
+ int noraise;
{
if (fptr->finalize) {
(*fptr->finalize)(fptr, noraise);
@@ -2184,42 +2220,41 @@ rb_io_fptr_cleanup(OpenFile *fptr, int noraise)
}
}
-int
-rb_io_fptr_finalize(OpenFile *fptr)
+void
+rb_io_fptr_finalize(fptr)
+ OpenFile *fptr;
{
- if (!fptr) return 0;
- if (fptr->refcnt <= 0 || --fptr->refcnt) return 0;
+ if (!fptr) return;
if (fptr->path) {
free(fptr->path);
- fptr->path = 0;
}
- if (0 <= fptr->fd)
- rb_io_fptr_cleanup(fptr, Qtrue);
- if (fptr->rbuf) {
- free(fptr->rbuf);
- fptr->rbuf = 0;
- }
- if (fptr->wbuf) {
- free(fptr->wbuf);
- fptr->wbuf = 0;
- }
- free(fptr);
- return 1;
+ if (!fptr->f && !fptr->f2) return;
+ if (fileno(fptr->f) < 3) return;
+
+ rb_io_fptr_cleanup(fptr, Qtrue);
}
VALUE
-rb_io_close(VALUE io)
+rb_io_close(io)
+ VALUE io;
{
OpenFile *fptr;
- int fd;
+ int fd, fd2;
fptr = RFILE(io)->fptr;
if (!fptr) return Qnil;
- if (fptr->fd < 0) return Qnil;
+ if (fptr->f2) {
+ fd2 = fileno(fptr->f2);
+ }
+ else {
+ if (!fptr->f) return Qnil;
+ fd2 = -1;
+ }
- fd = fptr->fd;
+ fd = fileno(fptr->f);
rb_io_fptr_cleanup(fptr, Qfalse);
rb_thread_fd_close(fd);
+ if (fd2 >= 0) rb_thread_fd_close(fd2);
if (fptr->pid) {
rb_syswait(fptr->pid);
@@ -2232,7 +2267,7 @@ rb_io_close(VALUE io)
/*
* call-seq:
* ios.close => nil
- *
+ *
* Closes <em>ios</em> and flushes any pending writes to the operating
* system. The stream is unavailable for any further data operations;
* an <code>IOError</code> is raised if such an attempt is made. I/O
@@ -2244,7 +2279,8 @@ rb_io_close(VALUE io)
*/
static VALUE
-rb_io_close_m(VALUE io)
+rb_io_close_m(io)
+ VALUE io;
{
if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
rb_raise(rb_eSecurityError, "Insecure: can't close");
@@ -2255,13 +2291,15 @@ rb_io_close_m(VALUE io)
}
static VALUE
-io_call_close(VALUE io)
+io_call_close(io)
+ VALUE io;
{
return rb_funcall(io, rb_intern("close"), 0, 0);
}
static VALUE
-io_close(VALUE io)
+io_close(io)
+ VALUE io;
{
return rb_rescue(io_call_close, io, 0, 0);
}
@@ -2269,11 +2307,11 @@ io_close(VALUE io)
/*
* call-seq:
* ios.closed? => true or false
- *
+ *
* Returns <code>true</code> if <em>ios</em> is completely closed (for
* duplex streams, both reader and writer), <code>false</code>
* otherwise.
- *
+ *
* f = File.new("testfile")
* f.close #=> nil
* f.closed? #=> true
@@ -2284,122 +2322,123 @@ io_close(VALUE io)
* f.closed? #=> true
*/
-
static VALUE
-rb_io_closed(VALUE io)
+rb_io_closed(io)
+ VALUE io;
{
OpenFile *fptr;
fptr = RFILE(io)->fptr;
rb_io_check_initialized(fptr);
- return 0 <= fptr->fd ? Qfalse : Qtrue;
+ return (fptr->f || fptr->f2)?Qfalse:Qtrue;
}
/*
* call-seq:
* ios.close_read => nil
- *
+ *
* Closes the read end of a duplex I/O stream (i.e., one that contains
* both a read and a write stream, such as a pipe). Will raise an
* <code>IOError</code> if the stream is not duplexed.
- *
+ *
* f = IO.popen("/bin/sh","r+")
* f.close_read
* f.readlines
- *
+ *
* <em>produces:</em>
- *
+ *
* prog.rb:3:in `readlines': not opened for reading (IOError)
* from prog.rb:3
*/
static VALUE
-rb_io_close_read(VALUE io)
+rb_io_close_read(io)
+ VALUE io;
{
OpenFile *fptr;
+ int n;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
rb_raise(rb_eSecurityError, "Insecure: can't close");
}
GetOpenFile(io, fptr);
- if (is_socket(fptr->fd, fptr->path)) {
-#ifndef SHUT_RD
-# define SHUT_RD 0
-#endif
- if (shutdown(fptr->fd, SHUT_RD) < 0)
- rb_sys_fail(fptr->path);
- fptr->mode &= ~FMODE_READABLE;
- if (!(fptr->mode & FMODE_WRITABLE))
- return rb_io_close(io);
- return Qnil;
- }
- if (fptr->mode & FMODE_WRITABLE) {
+ if (fptr->f2 == 0 && (fptr->mode & FMODE_WRITABLE)) {
rb_raise(rb_eIOError, "closing non-duplex IO for reading");
}
- return rb_io_close(io);
+ if (fptr->f2 == 0) {
+ return rb_io_close(io);
+ }
+ n = fclose(fptr->f);
+ fptr->mode &= ~FMODE_READABLE;
+ fptr->f = fptr->f2;
+ fptr->f2 = 0;
+ if (n != 0) rb_sys_fail(fptr->path);
+
+ return Qnil;
}
/*
* call-seq:
* ios.close_write => nil
- *
+ *
* Closes the write end of a duplex I/O stream (i.e., one that contains
* both a read and a write stream, such as a pipe). Will raise an
* <code>IOError</code> if the stream is not duplexed.
- *
+ *
* f = IO.popen("/bin/sh","r+")
* f.close_write
* f.print "nowhere"
- *
+ *
* <em>produces:</em>
- *
+ *
* prog.rb:3:in `write': not opened for writing (IOError)
* from prog.rb:3:in `print'
* from prog.rb:3
*/
static VALUE
-rb_io_close_write(VALUE io)
+rb_io_close_write(io)
+ VALUE io;
{
OpenFile *fptr;
+ int n;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
rb_raise(rb_eSecurityError, "Insecure: can't close");
}
GetOpenFile(io, fptr);
- if (is_socket(fptr->fd, fptr->path)) {
-#ifndef SHUT_WR
-# define SHUT_WR 1
-#endif
- if (shutdown(fptr->fd, SHUT_WR) < 0)
- rb_sys_fail(fptr->path);
- fptr->mode &= ~FMODE_WRITABLE;
- if (!(fptr->mode & FMODE_READABLE))
- return rb_io_close(io);
- return Qnil;
- }
-
- if (fptr->mode & FMODE_READABLE) {
+ if (fptr->f2 == 0 && (fptr->mode & FMODE_READABLE)) {
rb_raise(rb_eIOError, "closing non-duplex IO for writing");
}
- return rb_io_close(io);
+ if (fptr->f2 == 0) {
+ return rb_io_close(io);
+ }
+ n = fclose(fptr->f2);
+ fptr->f2 = 0;
+ fptr->mode &= ~FMODE_WRITABLE;
+ if (n != 0) rb_sys_fail(fptr->path);
+
+ return Qnil;
}
/*
* call-seq:
* ios.sysseek(offset, whence=SEEK_SET) => integer
- *
+ *
* Seeks to a given <i>offset</i> in the stream according to the value
* of <i>whence</i> (see <code>IO#seek</code> for values of
* <i>whence</i>). Returns the new offset into the file.
- *
+ *
* f = File.new("testfile")
* f.sysseek(-13, IO::SEEK_END) #=> 53
* f.sysread(10) #=> "And so on."
*/
static VALUE
-rb_io_sysseek(int argc, VALUE *argv, VALUE io)
+rb_io_sysseek(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE offset, ptrname;
int whence = SEEK_SET;
@@ -2411,14 +2450,15 @@ rb_io_sysseek(int argc, VALUE *argv, VALUE io)
}
pos = NUM2OFFT(offset);
GetOpenFile(io, fptr);
- if ((fptr->mode & FMODE_READABLE) && READ_DATA_BUFFERED(fptr)) {
+ if ((fptr->mode & FMODE_READABLE) && READ_DATA_BUFFERED(fptr->f)) {
rb_raise(rb_eIOError, "sysseek for buffered IO");
}
- if ((fptr->mode & FMODE_WRITABLE) && fptr->wbuf_len) {
+ if ((fptr->mode & FMODE_WRITABLE) && (fptr->mode & FMODE_WBUF)) {
rb_warn("sysseek for buffered IO");
}
- pos = lseek(fptr->fd, pos, whence);
+ pos = lseek(fileno(fptr->f), pos, whence);
if (pos == -1) rb_sys_fail(fptr->path);
+ clearerr(fptr->f);
return OFFT2NUM(pos);
}
@@ -2426,20 +2466,22 @@ rb_io_sysseek(int argc, VALUE *argv, VALUE io)
/*
* call-seq:
* ios.syswrite(string) => integer
- *
+ *
* Writes the given string to <em>ios</em> using a low-level write.
* Returns the number of bytes written. Do not mix with other methods
* that write to <em>ios</em> or you may get unpredictable results.
* Raises <code>SystemCallError</code> on error.
- *
+ *
* f = File.new("out", "w")
* f.syswrite("ABCDEF") #=> 6
*/
static VALUE
-rb_io_syswrite(VALUE io, VALUE str)
+rb_io_syswrite(io, str)
+ VALUE io, str;
{
OpenFile *fptr;
+ FILE *f;
long n;
rb_secure(4);
@@ -2448,15 +2490,16 @@ rb_io_syswrite(VALUE io, VALUE str)
GetOpenFile(io, fptr);
rb_io_check_writable(fptr);
+ f = GetWriteFile(fptr);
- if (fptr->wbuf_len) {
+ if (fptr->mode & FMODE_WBUF) {
rb_warn("syswrite for buffered IO");
}
- if (!rb_thread_fd_writable(fptr->fd)) {
+ if (!rb_thread_fd_writable(fileno(f))) {
rb_io_check_closed(fptr);
}
TRAP_BEG;
- n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
+ n = write(fileno(f), RSTRING(str)->ptr, RSTRING(str)->len);
TRAP_END;
if (n == -1) rb_sys_fail(fptr->path);
@@ -2466,22 +2509,23 @@ rb_io_syswrite(VALUE io, VALUE str)
/*
* call-seq:
- * ios.sysread(integer[, outbuf]) => string
- *
+ * ios.sysread(integer ) => string
+ *
* Reads <i>integer</i> bytes from <em>ios</em> using a low-level
* read and returns them as a string. Do not mix with other methods
* that read from <em>ios</em> or you may get unpredictable results.
- * If the optional <i>outbuf</i> argument is present, it must reference
- * a String, which will receive the data.
* Raises <code>SystemCallError</code> on error and
* <code>EOFError</code> at end of file.
- *
+ *
* f = File.new("testfile")
* f.sysread(16) #=> "This is line one"
*/
static VALUE
-rb_io_sysread(int argc, VALUE *argv, VALUE io)
+rb_io_sysread(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE len, str;
OpenFile *fptr;
@@ -2503,28 +2547,31 @@ rb_io_sysread(int argc, VALUE *argv, VALUE io)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
- if (READ_DATA_BUFFERED(fptr)) {
+ if (READ_DATA_BUFFERED(fptr->f)) {
rb_raise(rb_eIOError, "sysread for buffered IO");
}
+ rb_str_locktmp(str);
- n = fptr->fd;
- rb_thread_wait_fd(fptr->fd);
+ n = fileno(fptr->f);
+ rb_thread_wait_fd(fileno(fptr->f));
rb_io_check_closed(fptr);
- if (RSTRING_LEN(str) != ilen) {
+ if (RSTRING(str)->len != ilen) {
rb_raise(rb_eRuntimeError, "buffer string modified");
}
TRAP_BEG;
- n = read(fptr->fd, RSTRING_PTR(str), ilen);
+ n = read(fileno(fptr->f), RSTRING(str)->ptr, ilen);
TRAP_END;
+ rb_str_unlocktmp(str);
if (n == -1) {
rb_sys_fail(fptr->path);
}
- rb_str_set_len(str, n);
+ rb_str_resize(str, n);
if (n == 0 && ilen > 0) {
rb_eof_error();
}
- rb_str_resize(str, n);
+ RSTRING(str)->len = n;
+ RSTRING(str)->ptr[n] = '\0';
OBJ_TAINT(str);
return str;
@@ -2533,32 +2580,40 @@ rb_io_sysread(int argc, VALUE *argv, VALUE io)
/*
* call-seq:
* ios.binmode => ios
- *
+ *
* Puts <em>ios</em> into binary mode. This is useful only in
* MS-DOS/Windows environments. Once a stream is in binary mode, it
* cannot be reset to nonbinary mode.
*/
VALUE
-rb_io_binmode(VALUE io)
+rb_io_binmode(io)
+ VALUE io;
{
#if defined(_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__EMX__)
OpenFile *fptr;
GetOpenFile(io, fptr);
- if (!(fptr->mode & FMODE_BINMODE) && READ_DATA_BUFFERED(fptr)) {
- rb_raise(rb_eIOError, "buffer already filled with text-mode content");
- }
- if (0 <= fptr->fd && setmode(fptr->fd, O_BINARY) == -1)
+#ifdef __human68k__
+ if (fptr->f)
+ fmode(fptr->f, _IOBIN);
+ if (fptr->f2)
+ fmode(fptr->f2, _IOBIN);
+#else
+ if (fptr->f && setmode(fileno(fptr->f), O_BINARY) == -1)
rb_sys_fail(fptr->path);
+ if (fptr->f2 && setmode(fileno(fptr->f2), O_BINARY) == -1)
+ rb_sys_fail(fptr->path);
+#endif
fptr->mode |= FMODE_BINMODE;
#endif
return io;
}
-static const char*
-rb_io_flags_mode(int flags)
+char*
+rb_io_flags_mode(flags)
+ int flags;
{
#ifdef O_BINARY
# define MODE_BINMODE(a,b) ((flags & FMODE_BINMODE) ? (b) : (a))
@@ -2587,7 +2642,8 @@ rb_io_flags_mode(int flags)
}
int
-rb_io_mode_flags(const char *mode)
+rb_io_mode_flags(mode)
+ const char *mode;
{
int flags = 0;
const char *m = mode;
@@ -2624,7 +2680,8 @@ rb_io_mode_flags(const char *mode)
}
int
-rb_io_modenum_flags(int mode)
+rb_io_modenum_flags(mode)
+ int mode;
{
int flags = 0;
@@ -2656,7 +2713,8 @@ rb_io_modenum_flags(int mode)
}
static int
-rb_io_mode_modenum(const char *mode)
+rb_io_mode_modenum(mode)
+ const char *mode;
{
int flags = 0;
const char *m = mode;
@@ -2696,8 +2754,9 @@ rb_io_mode_modenum(const char *mode)
#define MODENUM_MAX 4
-static const char*
-rb_io_modenum_mode(int flags)
+static char*
+rb_io_modenum_mode(flags)
+ int flags;
{
#ifdef O_BINARY
# define MODE_BINARY(a,b) ((flags & O_BINARY) ? (b) : (a))
@@ -2723,7 +2782,10 @@ rb_io_modenum_mode(int flags)
}
static int
-rb_sysopen(char *fname, int flags, unsigned int mode)
+rb_sysopen(fname, flags, mode)
+ char *fname;
+ int flags;
+ unsigned int mode;
{
int fd;
@@ -2741,7 +2803,9 @@ rb_sysopen(char *fname, int flags, unsigned int mode)
}
FILE *
-rb_fopen(const char *fname, const char *mode)
+rb_fopen(fname, mode)
+ const char *fname;
+ const char *mode;
{
FILE *file;
@@ -2760,13 +2824,15 @@ rb_fopen(const char *fname, const char *mode)
rb_warn("setvbuf() can't be honoured for %s", fname);
#endif
#ifdef __human68k__
- setmode(fileno(file), O_TEXT);
+ fmode(file, _IOTEXT);
#endif
return file;
}
FILE *
-rb_fdopen(int fd, const char *mode)
+rb_fdopen(fd, mode)
+ int fd;
+ const char *mode;
{
FILE *file;
@@ -2775,11 +2841,11 @@ rb_fdopen(int fd, const char *mode)
#endif
file = fdopen(fd, mode);
if (!file) {
- if (
#if defined(sun)
- errno == 0 ||
+ if (errno == 0 || errno == EMFILE || errno == ENFILE) {
+#else
+ if (errno == EMFILE || errno == ENFILE) {
#endif
- errno == EMFILE || errno == ENFILE) {
rb_gc();
#if defined(sun)
errno = 0;
@@ -2789,14 +2855,14 @@ rb_fdopen(int fd, const char *mode)
if (!file) {
#ifdef _WIN32
if (errno == 0) errno = EINVAL;
-#elif defined(sun)
+#endif
+#if defined(sun)
if (errno == 0) errno = EMFILE;
#endif
rb_sys_fail(0);
}
}
- /* xxx: should be _IONBF? A buffer in FILE may have trouble. */
#ifdef USE_SETVBUF
if (setvbuf(file, NULL, _IOFBF, 0) != 0)
rb_warn("setvbuf() can't be honoured (fd=%d)", fd);
@@ -2804,62 +2870,67 @@ rb_fdopen(int fd, const char *mode)
return file;
}
-static void
-io_check_tty(OpenFile *fptr)
-{
- if (isatty(fptr->fd))
- fptr->mode |= FMODE_TTY|FMODE_DUPLEX;
-}
-
static VALUE
-rb_file_open_internal(VALUE io, const char *fname, const char *mode)
+rb_file_open_internal(io, fname, mode)
+ VALUE io;
+ const char *fname, *mode;
{
OpenFile *fptr;
MakeOpenFile(io, fptr);
+
fptr->mode = rb_io_mode_flags(mode);
fptr->path = strdup(fname);
- fptr->fd = rb_sysopen(fptr->path, rb_io_mode_modenum(rb_io_flags_mode(fptr->mode)), 0666);
- io_check_tty(fptr);
+ fptr->f = rb_fopen(fptr->path, rb_io_flags_mode(fptr->mode));
return io;
}
VALUE
-rb_file_open(const char *fname, const char *mode)
+rb_file_open(fname, mode)
+ const char *fname, *mode;
{
return rb_file_open_internal(io_alloc(rb_cFile), fname, mode);
}
static VALUE
-rb_file_sysopen_internal(VALUE io, const char *fname, int flags, int mode)
+rb_file_sysopen_internal(io, fname, flags, mode)
+ VALUE io;
+ char *fname;
+ int flags, mode;
{
OpenFile *fptr;
+ int fd;
+ char *m;
MakeOpenFile(io, fptr);
fptr->path = strdup(fname);
+ m = rb_io_modenum_mode(flags);
fptr->mode = rb_io_modenum_flags(flags);
- fptr->fd = rb_sysopen(fptr->path, flags, mode);
- io_check_tty(fptr);
+ fd = rb_sysopen(fptr->path, flags, mode);
+ fptr->f = rb_fdopen(fd, m);
return io;
}
VALUE
-rb_file_sysopen(const char *fname, int flags, int mode)
+rb_file_sysopen(fname, flags, mode)
+ const char *fname;
+ int flags, mode;
{
return rb_file_sysopen_internal(io_alloc(rb_cFile), fname, flags, mode);
}
-#if defined(__CYGWIN__) || !defined(HAVE_FORK)
+#if defined (_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__VMS)
static struct pipe_list {
OpenFile *fptr;
struct pipe_list *next;
} *pipe_list;
static void
-pipe_add_fptr(OpenFile *fptr)
+pipe_add_fptr(fptr)
+ OpenFile *fptr;
{
struct pipe_list *list;
@@ -2870,7 +2941,8 @@ pipe_add_fptr(OpenFile *fptr)
}
static void
-pipe_del_fptr(OpenFile *fptr)
+pipe_del_fptr(fptr)
+ OpenFile *fptr;
{
struct pipe_list *list = pipe_list;
struct pipe_list *tmp;
@@ -2893,7 +2965,7 @@ pipe_del_fptr(OpenFile *fptr)
}
static void
-pipe_atexit(void)
+pipe_atexit _((void))
{
struct pipe_list *list = pipe_list;
struct pipe_list *tmp;
@@ -2905,17 +2977,23 @@ pipe_atexit(void)
}
}
+static void pipe_finalize _((OpenFile *fptr,int));
+
static void
-pipe_finalize(OpenFile *fptr, int noraise)
+pipe_finalize(fptr, noraise)
+ OpenFile *fptr;
+ int noraise;
{
-#if !defined(HAVE_FORK) && !defined(_WIN32)
+#if !defined (__CYGWIN__) && !defined(_WIN32)
extern VALUE rb_last_status;
int status;
- if (fptr->stdio_file) {
- status = pclose(fptr->stdio_file);
+ if (fptr->f) {
+ status = pclose(fptr->f);
}
- fptr->fd = -1;
- fptr->stdio_file = 0;
+ if (fptr->f2) {
+ status = pclose(fptr->f2);
+ }
+ fptr->f = fptr->f2 = 0;
#if defined DJGPP
status <<= 8;
#endif
@@ -2928,260 +3006,248 @@ pipe_finalize(OpenFile *fptr, int noraise)
#endif
void
-rb_io_synchronized(OpenFile *fptr)
+rb_io_synchronized(fptr)
+ OpenFile *fptr;
{
fptr->mode |= FMODE_SYNC;
}
void
-rb_io_unbuffered(OpenFile *fptr)
+rb_io_unbuffered(fptr)
+ OpenFile *fptr;
{
rb_io_synchronized(fptr);
}
-struct popen_arg {
- struct rb_exec_arg exec;
- int modef;
- int pair[2];
-};
-
-static void
-popen_redirect(struct popen_arg *p)
-{
- if ((p->modef & FMODE_READABLE) && (p->modef & FMODE_WRITABLE)) {
- close(p->pair[0]);
- dup2(p->pair[1], 0);
- dup2(p->pair[1], 1);
- if (2 <= p->pair[1])
- close(p->pair[1]);
- }
- else if (p->modef & FMODE_READABLE) {
- close(p->pair[0]);
- if (p->pair[1] != 1) {
- dup2(p->pair[1], 1);
- close(p->pair[1]);
- }
- }
- else {
- close(p->pair[1]);
- if (p->pair[0] != 0) {
- dup2(p->pair[0], 0);
- close(p->pair[0]);
- }
- }
-}
-
-#ifdef HAVE_FORK
-static int
-popen_exec(void *pp)
-{
- struct popen_arg *p = (struct popen_arg*)pp;
- int fd;
-
- popen_redirect(p);
- for (fd = 3; fd < NOFILE; fd++) {
- close(fd);
- }
- return rb_exec(&p->exec);
-}
-#endif
+static VALUE pipe_open(VALUE pstr, char *pname, char *mode);
static VALUE
-pipe_open(int argc, VALUE *argv, const char *mode)
+pipe_open(pstr, pname, mode)
+ VALUE pstr;
+ char *pname, *mode;
{
int modef = rb_io_mode_flags(mode);
- int pid = 0;
OpenFile *fptr;
- VALUE port, prog;
-#if defined(HAVE_FORK) && defined(HAVE_SOCKETPAIR)
- int status;
- struct popen_arg arg;
- volatile int doexec;
-#elif defined(_WIN32)
- int openmode = rb_io_mode_modenum(mode);
- char *exename = NULL;
+#if defined(DJGPP) || defined(__human68k__) || defined(__VMS)
+ FILE *f;
+#else
+ int pid;
+#ifdef _WIN32
+ FILE *fpr, *fpw;
+#else
+ int pr[2], pw[2];
#endif
- char *cmd;
- FILE *fp = 0;
- int fd = -1;
+#endif
+ volatile int doexec;
- prog = rb_check_argv(argc, argv);
- if (!prog) {
- if (argc == 1) argc = 0;
- prog = argv[0];
- }
+ if (!pname) pname = StringValueCStr(pstr);
+ doexec = (strcmp("-", pname) != 0);
-#if defined(HAVE_FORK) && defined(HAVE_SOCKETPAIR)
- cmd = StringValueCStr(prog);
- doexec = (strcmp("-", cmd) != 0);
+#if defined(DJGPP) || defined(__human68k__) || defined(__VMS) || defined(_WIN32)
if (!doexec) {
- fflush(stdin); /* is it really needed? */
- rb_io_flush(rb_stdout);
- rb_io_flush(rb_stderr);
- }
- arg.modef = modef;
- arg.pair[0] = arg.pair[1] = -1;
- if ((modef & FMODE_READABLE) && (modef & FMODE_WRITABLE)) {
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, arg.pair) < 0)
- rb_sys_fail(cmd);
- }
- else if (modef & FMODE_READABLE) {
- if (pipe(arg.pair) < 0)
- rb_sys_fail(cmd);
- }
- else if (modef & FMODE_WRITABLE) {
- if (pipe(arg.pair) < 0)
- rb_sys_fail(cmd);
+ 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);
else {
- rb_sys_fail(cmd);
+ VALUE port = io_alloc(rb_cIO);
+
+ MakeOpenFile(port, fptr);
+ fptr->finalize = pipe_finalize;
+ fptr->mode = modef;
+
+ pipe_add_fptr(fptr);
+ if (modef & FMODE_READABLE) fptr->f = f;
+ if (modef & FMODE_WRITABLE) {
+ if (fptr->f) fptr->f2 = f;
+ else fptr->f = f;
+ rb_io_synchronized(fptr);
+ }
+ return (VALUE)port;
}
- if (doexec) {
- arg.exec.argc = argc;
- arg.exec.argv = argv;
- arg.exec.prog = cmd;
- pid = rb_fork(&status, popen_exec, &arg);
+#else
+#ifdef _WIN32
+retry:
+ pid = pipe_exec(pname, rb_io_mode_modenum(mode), &fpr, &fpw);
+ if (pid == -1) { /* exec failed */
+ if (errno == EAGAIN) {
+ rb_thread_sleep(1);
+ goto retry;
+ }
+ rb_sys_fail(pname);
}
else {
- pid = rb_fork(&status, 0, 0);
- if (pid == 0) { /* child */
- popen_redirect(&arg);
- rb_io_synchronized(RFILE(orig_stdout)->fptr);
- rb_io_synchronized(RFILE(orig_stderr)->fptr);
- return Qnil;
+ VALUE port = io_alloc(rb_cIO);
+
+ MakeOpenFile(port, fptr);
+ fptr->mode = modef;
+ fptr->mode |= FMODE_SYNC;
+ fptr->pid = pid;
+
+ if (modef & FMODE_READABLE) {
+ fptr->f = fpr;
+ }
+ if (modef & FMODE_WRITABLE) {
+ if (fptr->f) fptr->f2 = fpw;
+ else fptr->f = fpw;
}
+ fptr->finalize = pipe_finalize;
+ pipe_add_fptr(fptr);
+ return (VALUE)port;
}
+#else
+ if (((modef & FMODE_READABLE) && pipe(pr) == -1) ||
+ ((modef & FMODE_WRITABLE) && pipe(pw) == -1))
+ rb_sys_fail(pname);
- /* parent */
- if (pid == -1) {
- int e = errno;
- close(arg.pair[0]);
- close(arg.pair[1]);
- errno = e;
- rb_sys_fail(cmd);
- }
- if ((modef & FMODE_READABLE) && (modef & FMODE_WRITABLE)) {
- close(arg.pair[1]);
- fd = arg.pair[0];
- }
- else if (modef & FMODE_READABLE) {
- close(arg.pair[1]);
- fd = arg.pair[0];
- }
- else {
- close(arg.pair[0]);
- fd = arg.pair[1];
+ if (!doexec) {
+ fflush(stdin); /* is it really needed? */
+ fflush(stdout);
+ fflush(stderr);
}
-#elif defined(_WIN32)
- if (argc) {
- char **args = ALLOCA_N(char *, argc+1);
- int i;
- for (i = 0; i < argc; ++i) {
- args[i] = RSTRING_PTR(argv[i]);
+ retry:
+ switch ((pid = fork())) {
+ case 0: /* child */
+ if (modef & FMODE_READABLE) {
+ close(pr[0]);
+ if (pr[1] != 1) {
+ dup2(pr[1], 1);
+ close(pr[1]);
+ }
}
- args[i] = NULL;
- cmd = ALLOCA_N(char, rb_w32_argv_size(args));
- rb_w32_join_argv(cmd, args);
- exename = RSTRING_PTR(prog);
- }
- else {
- cmd = StringValueCStr(prog);
- }
- while ((pid = rb_w32_pipe_exec(cmd, exename, openmode, &fd)) == -1) {
- /* exec failed */
- switch (errno) {
- case EAGAIN:
-#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
+ if (modef & FMODE_WRITABLE) {
+ close(pw[1]);
+ if (pw[0] != 0) {
+ dup2(pw[0], 0);
+ close(pw[0]);
+ }
+ }
+
+ if (doexec) {
+ int fd;
+
+ for (fd = 3; fd < NOFILE; fd++)
+ close(fd);
+ rb_proc_exec(pname);
+ fprintf(stderr, "%s:%d: command not found: %s\n",
+ ruby_sourcefile, ruby_sourceline, pname);
+ _exit(127);
+ }
+ rb_io_synchronized(RFILE(orig_stdout)->fptr);
+ rb_io_synchronized(RFILE(orig_stderr)->fptr);
+ return Qnil;
+
+ case -1: /* fork failed */
+ if (errno == EAGAIN) {
rb_thread_sleep(1);
- break;
- default:
- rb_sys_fail(RSTRING_PTR(prog));
- break;
+ goto retry;
}
- }
-#else
- if (argc)
- prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
- fp = popen(StringValueCStr(prog), mode);
- if (!fp) rb_sys_fail(RSTRING_PTR(prog));
- fd = fileno(fp);
-#endif
+ else {
+ int e = errno;
+ if ((modef & FMODE_READABLE)) {
+ close(pr[0]);
+ close(pr[1]);
+ }
+ if ((modef & FMODE_WRITABLE)) {
+ close(pw[0]);
+ close(pw[1]);
+ }
+ errno = e;
+ rb_sys_fail(pname);
+ }
+ break;
- port = io_alloc(rb_cIO);
- MakeOpenFile(port, fptr);
- fptr->fd = fd;
- fptr->stdio_file = fp;
- fptr->mode = modef | FMODE_SYNC|FMODE_DUPLEX;
- fptr->pid = pid;
+ default: /* parent */
+ if (pid < 0) rb_sys_fail(pname);
+ else {
+ VALUE port = io_alloc(rb_cIO);
-#if defined (__CYGWIN__) || !defined(HAVE_FORK)
- fptr->finalize = pipe_finalize;
- pipe_add_fptr(fptr);
+ MakeOpenFile(port, fptr);
+ fptr->mode = modef;
+ fptr->mode |= FMODE_SYNC;
+ fptr->pid = pid;
+
+ if (modef & FMODE_READABLE) {
+ close(pr[1]);
+ fptr->f = rb_fdopen(pr[0], "r");
+ }
+ if (modef & FMODE_WRITABLE) {
+ FILE *f = rb_fdopen(pw[1], "w");
+
+ close(pw[0]);
+ if (fptr->f) fptr->f2 = f;
+ else fptr->f = f;
+ }
+#if defined (__CYGWIN__)
+ fptr->finalize = pipe_finalize;
+ pipe_add_fptr(fptr);
+#endif
+ return port;
+ }
+ }
+#endif
#endif
- return port;
}
/*
* call-seq:
- * IO.popen(cmd, mode="r") => io
- * IO.popen(cmd, mode="r") {|io| block } => obj
- *
- * Runs the specified command as a subprocess; the subprocess's
+ * IO.popen(cmd_string, mode="r" ) => io
+ * IO.popen(cmd_string, mode="r" ) {|io| block } => obj
+ *
+ * Runs the specified command string as a subprocess; the subprocess's
* standard input and output will be connected to the returned
- * <code>IO</code> object. If _cmd_ is a +String+
+ * <code>IO</code> object. If <i>cmd_string</i> starts with a
* ``<code>-</code>'', then a new instance of Ruby is started as the
- * subprocess. If <i>cmd</i> is an +Array+ of +String+, then it will
- * be used as the subprocess's +argv+ bypassing a shell. The default
- * mode for the new file object is ``r'', but <i>mode</i> may be set
- * to any of the modes listed in the description for class IO.
- *
- * Raises exceptions which <code>IO::pipe</code> and
- * <code>Kernel::system</code> raise.
- *
+ * subprocess. The default mode for the new file object is ``r'', but
+ * <i>mode</i> may be set to any of the modes listed in the description
+ * for class IO.
+ *
* If a block is given, Ruby will run the command as a child connected
* to Ruby with a pipe. Ruby's end of the pipe will be passed as a
* parameter to the block.
* At the end of block, Ruby close the pipe and sets <code>$?</code>.
* In this case <code>IO::popen</code> returns
* the value of the block.
- *
- * If a block is given with a _cmd_ of ``<code>-</code>'',
+ *
+ * If a block is given with a <i>cmd_string</i> of ``<code>-</code>'',
* the block will be run in two separate processes: once in the parent,
* and once in a child. The parent process will be passed the pipe
* object as a parameter to the block, the child version of the block
* will be passed <code>nil</code>, and the child's standard in and
* standard out will be connected to the parent through the pipe. Not
* available on all platforms.
- *
+ *
* f = IO.popen("uname")
* p f.readlines
* puts "Parent is #{Process.pid}"
- * IO.popen("date") { |f| puts f.gets }
+ * IO.popen ("date") { |f| puts f.gets }
* IO.popen("-") {|f| $stderr.puts "#{Process.pid} is here, f is #{f}"}
* p $?
- * IO.popen(%w"sed -e s|^|<foo>| -e s&$&;zot;&", "r+") {|f|
- * f.puts "bar"; f.close_write; puts f.gets
- * }
- *
+ *
* <em>produces:</em>
- *
+ *
* ["Linux\n"]
* Parent is 26166
* Wed Apr 9 08:53:52 CDT 2003
* 26169 is here, f is
* 26166 is here, f is #<IO:0x401b3d44>
* #<Process::Status: pid=26166,exited(0)>
- * <foo>bar;zot;
*/
static VALUE
-rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
+rb_io_s_popen(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
- const char *mode;
- VALUE pname, pmode, port, tmp;
+ char *mode;
+ VALUE pname, pmode, port;
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
mode = "r";
@@ -3190,26 +3256,16 @@ rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
mode = rb_io_modenum_mode(FIX2INT(pmode));
}
else {
- mode = rb_io_flags_mode(rb_io_mode_flags(StringValuePtr(pmode)));
- }
- tmp = rb_check_array_type(pname);
- if (!NIL_P(tmp)) {
- VALUE *argv = ALLOCA_N(VALUE, RARRAY_LEN(tmp));
-
- MEMCPY(argv, RARRAY_PTR(tmp), VALUE, RARRAY_LEN(tmp));
- port = pipe_open(RARRAY_LEN(tmp), argv, mode);
- pname = tmp;
- }
- else {
- SafeStringValue(pname);
- port = pipe_open(1, &pname, mode);
+ mode = rb_io_flags_mode(rb_io_mode_flags(StringValueCStr(pmode)));
}
+ SafeStringValue(pname);
+ port = pipe_open(pname, 0, mode);
if (NIL_P(port)) {
/* child */
if (rb_block_given_p()) {
rb_yield(Qnil);
- rb_io_flush(rb_stdout);
- rb_io_flush(rb_stderr);
+ fflush(stdout);
+ fflush(stderr);
_exit(0);
}
return Qnil;
@@ -3222,30 +3278,35 @@ rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
}
static VALUE
-rb_open_file(int argc, VALUE *argv, VALUE io)
+rb_open_file(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE fname, vmode, perm;
- const char *mode;
- int flags, fmode;
+ char *path, *mode;
+ int flags;
+ unsigned int fmode;
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
- FilePathValue(fname);
+ SafeStringValue(fname);
+ path = StringValueCStr(fname);
if (FIXNUM_P(vmode) || !NIL_P(perm)) {
if (FIXNUM_P(vmode)) {
flags = FIX2INT(vmode);
}
else {
SafeStringValue(vmode);
- flags = rb_io_mode_modenum(RSTRING_PTR(vmode));
+ flags = rb_io_mode_modenum(RSTRING(vmode)->ptr);
}
- fmode = NIL_P(perm) ? 0666 : NUM2INT(perm);
+ fmode = NIL_P(perm) ? 0666 : NUM2UINT(perm);
- rb_file_sysopen_internal(io, RSTRING_PTR(fname), flags, fmode);
+ rb_file_sysopen_internal(io, path, flags, fmode);
}
else {
- mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode);
- rb_file_open_internal(io, RSTRING_PTR(fname), mode);
+ mode = NIL_P(vmode) ? "r" : StringValueCStr(vmode);
+ rb_file_open_internal(io, path, mode);
}
return io;
}
@@ -3254,17 +3315,20 @@ rb_open_file(int argc, VALUE *argv, VALUE io)
* call-seq:
* IO.open(fd, mode_string="r" ) => io
* IO.open(fd, mode_string="r" ) {|io| block } => obj
- *
+ *
* With no associated block, <code>open</code> is a synonym for
* <code>IO::new</code>. If the optional code block is given, it will
* be passed <i>io</i> as an argument, and the IO object will
* automatically be closed when the block terminates. In this instance,
* <code>IO::open</code> returns the value of the block.
- *
+ *
*/
static VALUE
-rb_io_s_open(int argc, VALUE *argv, VALUE klass)
+rb_io_s_open(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE io = rb_class_new_instance(argc, argv, klass);
@@ -3278,35 +3342,38 @@ rb_io_s_open(int argc, VALUE *argv, VALUE klass)
/*
* call-seq:
* IO.sysopen(path, [mode, [perm]]) => fixnum
- *
+ *
* Opens the given path, returning the underlying file descriptor as a
* <code>Fixnum</code>.
- *
+ *
* IO.sysopen("testfile") #=> 3
- *
+ *
*/
static VALUE
-rb_io_s_sysopen(int argc, VALUE *argv)
+rb_io_s_sysopen(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE fname, vmode, perm;
- int flags, fmode, fd;
+ int flags, fd;
+ unsigned int fmode;
char *path;
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
- FilePathValue(fname);
+ SafeStringValue(fname);
if (NIL_P(vmode)) flags = O_RDONLY;
else if (FIXNUM_P(vmode)) flags = FIX2INT(vmode);
else {
SafeStringValue(vmode);
- flags = rb_io_mode_modenum(RSTRING_PTR(vmode));
+ flags = rb_io_mode_modenum(RSTRING(vmode)->ptr);
}
if (NIL_P(perm)) fmode = 0666;
- else fmode = NUM2INT(perm);
+ else fmode = NUM2UINT(perm);
- path = ALLOCA_N(char, strlen(RSTRING_PTR(fname))+1);
- strcpy(path, RSTRING_PTR(fname));
+ path = ALLOCA_N(char, strlen(RSTRING(fname)->ptr)+1);
+ strcpy(path, RSTRING(fname)->ptr);
fd = rb_sysopen(path, flags, fmode);
return INT2NUM(fd);
}
@@ -3315,21 +3382,21 @@ rb_io_s_sysopen(int argc, VALUE *argv)
* call-seq:
* open(path [, mode [, perm]] ) => io or nil
* open(path [, mode [, perm]] ) {|io| block } => obj
- *
+ *
* Creates an <code>IO</code> object connected to the given stream,
* file, or subprocess.
- *
+ *
* If <i>path</i> does not start with a pipe character
* (``<code>|</code>''), treat it as the name of a file to open using
* the specified mode (defaulting to ``<code>r</code>''). (See the table
* of valid modes on page 331.) If a file is being created, its initial
* permissions may be set using the integer third parameter.
- *
+ *
* If a block is specified, it will be invoked with the
* <code>File</code> object as a parameter, and the file will be
* automatically closed when the block terminates. The call
* returns the value of the block.
- *
+ *
* If <i>path</i> starts with a pipe character, a subprocess is
* created, connected to the caller by a pair of pipes. The returned
* <code>IO</code> object may be used to write to the standard input
@@ -3345,27 +3412,27 @@ rb_io_s_sysopen(int argc, VALUE *argv)
* will be connected to the child's <code>$stdin</code> and
* <code>$stdout</code>. The subprocess will be terminated at the end
* of the block.
- *
+ *
* open("testfile") do |f|
* print f.gets
* end
- *
+ *
* <em>produces:</em>
- *
+ *
* This is line one
- *
+ *
* Open a subprocess and read its output:
- *
+ *
* cmd = open("|date")
* print cmd.gets
* cmd.close
- *
+ *
* <em>produces:</em>
- *
+ *
* Wed Apr 9 08:56:31 CDT 2003
- *
+ *
* Open a subprocess running the same Ruby program:
- *
+ *
* f = open("|-", "w+")
* if f == nil
* puts "in Child"
@@ -3373,13 +3440,13 @@ rb_io_s_sysopen(int argc, VALUE *argv)
* else
* puts "Got: #{f.gets}"
* end
- *
+ *
* <em>produces:</em>
- *
+ *
* Got: in Child
- *
+ *
* Open a subprocess using a block to receive the I/O object:
- *
+ *
* open("|-") do |f|
* if f == nil
* puts "in Child"
@@ -3387,47 +3454,36 @@ rb_io_s_sysopen(int argc, VALUE *argv)
* puts "Got: #{f.gets}"
* end
* end
- *
+ *
* <em>produces:</em>
- *
+ *
* Got: in Child
*/
static VALUE
-rb_f_open(int argc, VALUE *argv)
+rb_f_open(argc, argv)
+ int argc;
+ VALUE *argv;
{
if (argc >= 1) {
- ID to_open = rb_intern("to_open");
-
- if (rb_respond_to(argv[0], to_open)) {
- VALUE io = rb_funcall2(argv[0], to_open, argc-1, argv+1);
+ char *str = StringValuePtr(argv[0]);
- if (rb_block_given_p()) {
- return rb_ensure(rb_yield, io, io_close, io);
- }
- return io;
- }
- else {
- VALUE tmp = rb_check_string_type(argv[0]);
- if (!NIL_P(tmp)) {
- char *str = StringValuePtr(tmp);
- if (str && str[0] == '|') {
- argv[0] = rb_str_new(str+1, RSTRING_LEN(tmp)-1);
- OBJ_INFECT(argv[0], tmp);
- return rb_io_s_popen(argc, argv, rb_cIO);
- }
- }
+ if (str[0] == '|') {
+ VALUE tmp = rb_str_new(str+1, RSTRING(argv[0])->len-1);
+ OBJ_INFECT(tmp, argv[0]);
+ argv[0] = tmp;
+ return rb_io_s_popen(argc, argv, rb_cIO);
}
}
return rb_io_s_open(argc, argv, rb_cFile);
}
static VALUE
-rb_io_open(const char *fname, const char *mode)
+rb_io_open(fname, mode)
+ char *fname, *mode;
{
if (fname[0] == '|') {
- VALUE cmd = rb_str_new2(fname+1);
- return pipe_open(1, &cmd, mode);
+ return pipe_open(0, fname+1, mode);
}
else {
return rb_file_open(fname, mode);
@@ -3435,9 +3491,40 @@ rb_io_open(const char *fname, const char *mode)
}
static VALUE
-io_reopen(VALUE io, VALUE nfile)
+rb_io_get_io(io)
+ VALUE io;
+{
+ return rb_convert_type(io, T_FILE, "IO", "to_io");
+}
+
+static VALUE
+rb_io_check_io(io)
+ VALUE io;
+{
+ return rb_check_convert_type(io, T_FILE, "IO", "to_io");
+}
+
+static char*
+rb_io_mode_string(fptr)
+ OpenFile *fptr;
+{
+ switch (fptr->mode & FMODE_READWRITE) {
+ case FMODE_READABLE:
+ default:
+ return "r";
+ case FMODE_WRITABLE:
+ return "w";
+ case FMODE_READWRITE:
+ return "r+";
+ }
+}
+
+static VALUE
+io_reopen(io, nfile)
+ VALUE io, nfile;
{
OpenFile *fptr, *orig;
+ char *mode;
int fd, fd2;
off_t pos = 0;
@@ -3449,29 +3536,21 @@ io_reopen(VALUE io, VALUE nfile)
GetOpenFile(nfile, orig);
if (fptr == orig) return io;
-#if !defined __CYGWIN__
- if (IS_PREP_STDIO(fptr)) {
- if (((fptr->mode & FMODE_READWRITE) & (orig->mode & FMODE_READWRITE)) !=
- (fptr->mode & FMODE_READWRITE)) {
- rb_raise(rb_eArgError,
- "%s can't change access mode from \"%s\" to \"%s\"",
- PREP_STDIO_NAME(fptr), rb_io_flags_mode(fptr->mode),
- rb_io_flags_mode(orig->mode));
- }
- }
-#endif
if (orig->mode & FMODE_READABLE) {
pos = io_tell(orig);
}
- if (orig->mode & FMODE_WRITABLE) {
- io_fflush(orig);
+ if (orig->f2) {
+ io_fflush(orig->f2, orig);
+ }
+ else if (orig->mode & FMODE_WRITABLE) {
+ io_fflush(orig->f, orig);
}
if (fptr->mode & FMODE_WRITABLE) {
- io_fflush(fptr);
+ io_fflush(GetWriteFile(fptr), fptr);
}
/* copy OpenFile structure */
- fptr->mode = orig->mode | (fptr->mode & FMODE_PREP);
+ fptr->mode = orig->mode;
fptr->pid = orig->pid;
fptr->lineno = orig->lineno;
if (fptr->path) free(fptr->path);
@@ -3479,37 +3558,54 @@ io_reopen(VALUE io, VALUE nfile)
else fptr->path = 0;
fptr->finalize = orig->finalize;
- fd = fptr->fd;
- fd2 = orig->fd;
+ mode = rb_io_mode_string(fptr);
+ fd = fileno(fptr->f);
+ fd2 = fileno(orig->f);
if (fd != fd2) {
-#if !defined __CYGWIN__
- if (IS_PREP_STDIO(fptr)) {
+ if (fptr->f == stdin || fptr->f == stdout || fptr->f == stderr) {
+ clearerr(fptr->f);
/* need to keep stdio objects */
if (dup2(fd2, fd) < 0)
rb_sys_fail(orig->path);
}
else {
-#endif
- if (fptr->stdio_file)
- fclose(fptr->stdio_file);
- else
- close(fptr->fd);
- fptr->stdio_file = 0;
- fptr->fd = -1;
+ FILE *f2 = fptr->f2;
+ int m = fptr->mode;
+ fclose(fptr->f);
+ fptr->f = f2;
+ fptr->f2 = NULL;
+ fptr->mode &= (m & FMODE_READABLE) ? ~FMODE_READABLE : ~FMODE_WRITABLE;
if (dup2(fd2, fd) < 0)
rb_sys_fail(orig->path);
- fptr->fd = fd;
-#if !defined __CYGWIN__
+ if (f2) {
+ fptr->f = rb_fdopen(fd, "r");
+ fptr->f2 = f2;
+ }
+ else {
+ fptr->f = rb_fdopen(fd, mode);
+ }
+ fptr->mode = m;
}
-#endif
rb_thread_fd_close(fd);
if ((orig->mode & FMODE_READABLE) && pos >= 0) {
- if (io_seek(fptr, pos, SEEK_SET) < 0) {
- rb_sys_fail(fptr->path);
- }
- if (io_seek(orig, pos, SEEK_SET) < 0) {
+ io_seek(fptr, pos, SEEK_SET);
+ io_seek(orig, pos, SEEK_SET);
+ }
+ }
+
+ if (fptr->f2 && fd != fileno(fptr->f2)) {
+ fd = fileno(fptr->f2);
+ if (!orig->f2) {
+ fclose(fptr->f2);
+ rb_thread_fd_close(fd);
+ fptr->f2 = 0;
+ }
+ else if (fd != (fd2 = fileno(orig->f2))) {
+ fclose(fptr->f2);
+ rb_thread_fd_close(fd);
+ if (dup2(fd2, fd) < 0)
rb_sys_fail(orig->path);
- }
+ fptr->f2 = rb_fdopen(fd, "w");
}
}
@@ -3523,13 +3619,13 @@ io_reopen(VALUE io, VALUE nfile)
/*
* call-seq:
- * ios.reopen(other_IO) => ios
+ * ios.reopen(other_IO) => ios
* ios.reopen(path, mode_str) => ios
- *
+ *
* Reassociates <em>ios</em> with the I/O stream given in
* <i>other_IO</i> or to a new stream opened on <i>path</i>. This may
* dynamically change the actual class of this stream.
- *
+ *
* f1 = File.new("testfile")
* f2 = File.new("testfile")
* f2.readlines[0] #=> "This is line one\n"
@@ -3538,10 +3634,13 @@ io_reopen(VALUE io, VALUE nfile)
*/
static VALUE
-rb_io_reopen(int argc, VALUE *argv, VALUE file)
+rb_io_reopen(argc, argv, file)
+ int argc;
+ VALUE *argv;
+ VALUE file;
{
VALUE fname, nmode;
- const char *mode;
+ char *mode;
OpenFile *fptr;
rb_secure(4);
@@ -3552,7 +3651,7 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file)
}
}
- FilePathValue(fname);
+ SafeStringValue(fname);
rb_io_taint_check(file);
fptr = RFILE(file)->fptr;
if (!fptr) {
@@ -3561,16 +3660,7 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file)
}
if (!NIL_P(nmode)) {
- int flags = rb_io_mode_flags(StringValuePtr(nmode));
- if (IS_PREP_STDIO(fptr) &&
- ((fptr->mode & FMODE_READWRITE) & (flags & FMODE_READWRITE)) !=
- (fptr->mode & FMODE_READWRITE)) {
- rb_raise(rb_eArgError,
- "%s can't change access mode from \"%s\" to \"%s\"",
- PREP_STDIO_NAME(fptr), rb_io_flags_mode(fptr->mode),
- rb_io_flags_mode(flags));
- }
- fptr->mode = flags;
+ fptr->mode = rb_io_mode_flags(StringValueCStr(nmode));
}
if (fptr->path) {
@@ -3578,33 +3668,29 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file)
fptr->path = 0;
}
- fptr->path = strdup(RSTRING_PTR(fname));
+ fptr->path = strdup(StringValueCStr(fname));
mode = rb_io_flags_mode(fptr->mode);
- if (fptr->fd < 0) {
- fptr->fd = rb_sysopen(fptr->path, rb_io_mode_modenum(mode), 0666);
- fptr->stdio_file = 0;
+ if (!fptr->f) {
+ fptr->f = rb_fopen(fptr->path, mode);
+ if (fptr->f2) {
+ fclose(fptr->f2);
+ fptr->f2 = 0;
+ }
return file;
}
- if (fptr->mode & FMODE_WRITABLE) {
- io_fflush(fptr);
+ if (freopen(fptr->path, mode, fptr->f) == 0) {
+ rb_sys_fail(fptr->path);
}
-
- if (fptr->stdio_file) {
- if (freopen(RSTRING_PTR(fname), mode, fptr->stdio_file) == 0) {
- rb_sys_fail(fptr->path);
- }
- fptr->fd = fileno(fptr->stdio_file);
#ifdef USE_SETVBUF
- if (setvbuf(fptr->stdio_file, NULL, _IOFBF, 0) != 0)
- rb_warn("setvbuf() can't be honoured for %s", RSTRING_PTR(fname));
+ if (setvbuf(fptr->f, NULL, _IOFBF, 0) != 0)
+ rb_warn("setvbuf() can't be honoured for %s", fptr->path);
#endif
- }
- else {
- if (close(fptr->fd) < 0)
- rb_sys_fail(fptr->path);
- fptr->fd = -1;
- fptr->fd = rb_sysopen(fptr->path, rb_io_mode_modenum(mode), 0666);
+
+ if (fptr->f2) {
+ if (freopen(fptr->path, "w", fptr->f2) == 0) {
+ rb_sys_fail(fptr->path);
+ }
}
return file;
@@ -3612,28 +3698,57 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file)
/* :nodoc: */
static VALUE
-rb_io_init_copy(VALUE dest, VALUE io)
+rb_io_init_copy(dest, io)
+ VALUE dest, io;
{
OpenFile *fptr, *orig;
int fd;
+ char *mode;
io = rb_io_get_io(io);
if (dest == io) return dest;
GetOpenFile(io, orig);
MakeOpenFile(dest, fptr);
- rb_io_flush(io);
+ if (orig->f2) {
+ io_fflush(orig->f2, orig);
+ fseeko(orig->f, 0L, SEEK_CUR);
+ }
+ else if (orig->mode & FMODE_WRITABLE) {
+ io_fflush(orig->f, orig);
+ }
+ else {
+ fseeko(orig->f, 0L, SEEK_CUR);
+ }
/* copy OpenFile structure */
- fptr->mode = orig->mode & ~FMODE_PREP;
+ fptr->mode = orig->mode;
fptr->pid = orig->pid;
fptr->lineno = orig->lineno;
if (orig->path) fptr->path = strdup(orig->path);
fptr->finalize = orig->finalize;
- fd = ruby_dup(orig->fd);
- fptr->fd = fd;
- io_seek(fptr, io_tell(orig), SEEK_SET);
+ switch (fptr->mode & FMODE_READWRITE) {
+ case FMODE_READABLE:
+ default:
+ mode = "r"; break;
+ case FMODE_WRITABLE:
+ mode = "w"; break;
+ case FMODE_READWRITE:
+ if (orig->f2) mode = "r";
+ else mode = "r+";
+ break;
+ }
+ fd = ruby_dup(fileno(orig->f));
+ fptr->f = rb_fdopen(fd, mode);
+ fseeko(fptr->f, ftello(orig->f), SEEK_SET);
+ if (orig->f2) {
+ if (fileno(orig->f) != fileno(orig->f2)) {
+ fd = ruby_dup(fileno(orig->f2));
+ }
+ fptr->f2 = rb_fdopen(fd, "w");
+ fseeko(fptr->f2, ftello(orig->f2), SEEK_SET);
+ }
if (fptr->mode & FMODE_BINMODE) {
rb_io_binmode(dest);
}
@@ -3644,14 +3759,17 @@ rb_io_init_copy(VALUE dest, VALUE io)
/*
* call-seq:
* ios.printf(format_string [, obj, ...] ) => nil
- *
+ *
* Formats and writes to <em>ios</em>, converting parameters under
* control of the format string. See <code>Kernel#sprintf</code>
* for details.
*/
VALUE
-rb_io_printf(int argc, VALUE *argv, VALUE out)
+rb_io_printf(argc, argv, out)
+ int argc;
+ VALUE argv[];
+ VALUE out;
{
rb_io_write(out, rb_f_sprintf(argc, argv));
return Qnil;
@@ -3661,7 +3779,7 @@ rb_io_printf(int argc, VALUE *argv, VALUE out)
* call-seq:
* printf(io, string [, obj ... ] ) => nil
* printf(string [, obj ... ] ) => nil
- *
+ *
* Equivalent to:
* io.write(sprintf(string, obj, ...)
* or
@@ -3669,7 +3787,9 @@ rb_io_printf(int argc, VALUE *argv, VALUE out)
*/
static VALUE
-rb_f_printf(int argc, VALUE *argv)
+rb_f_printf(argc, argv)
+ int argc;
+ VALUE argv[];
{
VALUE out;
@@ -3691,7 +3811,7 @@ rb_f_printf(int argc, VALUE *argv)
* call-seq:
* ios.print() => nil
* ios.print(obj, ...) => nil
- *
+ *
* Writes the given object(s) to <em>ios</em>. The stream must be
* opened for writing. If the output record separator (<code>$\\</code>)
* is not <code>nil</code>, it will be appended to the output. If no
@@ -3699,16 +3819,19 @@ rb_f_printf(int argc, VALUE *argv)
* strings will be converted by calling their <code>to_s</code> method.
* With no argument, prints the contents of the variable <code>$_</code>.
* Returns <code>nil</code>.
- *
+ *
* $stdout.print("This is ", 100, " percent.\n")
- *
+ *
* <em>produces:</em>
- *
+ *
* This is 100 percent.
*/
VALUE
-rb_io_print(int argc, VALUE *argv, VALUE out)
+rb_io_print(argc, argv, out)
+ int argc;
+ VALUE *argv;
+ VALUE out;
{
int i;
VALUE line;
@@ -3720,12 +3843,19 @@ rb_io_print(int argc, VALUE *argv, VALUE out)
argv = &line;
}
for (i=0; i<argc; i++) {
- rb_io_write(out, argv[i]);
- if (!NIL_P(rb_output_fs)) {
+ if (!NIL_P(rb_output_fs) && i>0) {
rb_io_write(out, rb_output_fs);
}
+ switch (TYPE(argv[i])) {
+ case T_NIL:
+ rb_io_write(out, rb_str_new2("nil"));
+ break;
+ default:
+ rb_io_write(out, argv[i]);
+ break;
+ }
}
- if (argc > 0 && !NIL_P(rb_output_rs)) {
+ if (!NIL_P(rb_output_rs)) {
rb_io_write(out, rb_output_rs);
}
@@ -3735,7 +3865,7 @@ rb_io_print(int argc, VALUE *argv, VALUE out)
/*
* call-seq:
* print(obj, ...) => nil
- *
+ *
* Prints each object in turn to <code>$stdout</code>. If the output
* field separator (<code>$,</code>) is not +nil+, its
* contents will appear between each field. If the output record
@@ -3743,20 +3873,22 @@ rb_io_print(int argc, VALUE *argv, VALUE out)
* appended to the output. If no arguments are given, prints
* <code>$_</code>. Objects that aren't strings will be converted by
* calling their <code>to_s</code> method.
- *
+ *
* print "cat", [1,2,3], 99, "\n"
* $, = ", "
* $\ = "\n"
* print "cat", [1,2,3], 99
- *
+ *
* <em>produces:</em>
- *
+ *
* cat12399
* cat, 1, 2, 3, 99
*/
static VALUE
-rb_f_print(int argc, VALUE *argv)
+rb_f_print(argc, argv)
+ int argc;
+ VALUE *argv;
{
rb_io_print(argc, argv, rb_stdout);
return Qnil;
@@ -3765,21 +3897,22 @@ rb_f_print(int argc, VALUE *argv)
/*
* call-seq:
* ios.putc(obj) => obj
- *
+ *
* If <i>obj</i> is <code>Numeric</code>, write the character whose
* code is <i>obj</i>, otherwise write the first character of the
* string representation of <i>obj</i> to <em>ios</em>.
- *
+ *
* $stdout.putc "A"
* $stdout.putc 65
- *
+ *
* <em>produces:</em>
- *
+ *
* AA
*/
static VALUE
-rb_io_putc(VALUE io, VALUE ch)
+rb_io_putc(io, ch)
+ VALUE io, ch;
{
char c = NUM2CHR(ch);
@@ -3790,27 +3923,29 @@ rb_io_putc(VALUE io, VALUE ch)
/*
* call-seq:
* putc(int) => int
- *
+ *
* Equivalent to:
*
* $stdout.putc(int)
*/
static VALUE
-rb_f_putc(VALUE recv, VALUE ch)
+rb_f_putc(recv, ch)
+ VALUE recv, ch;
{
return rb_io_putc(rb_stdout, ch);
}
static VALUE
-io_puts_ary(VALUE ary, VALUE out, int recur)
+io_puts_ary(ary, out)
+ VALUE ary, out;
{
VALUE tmp;
long i;
- for (i=0; i<RARRAY_LEN(ary); i++) {
- tmp = RARRAY_PTR(ary)[i];
- if (recur) {
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ tmp = RARRAY(ary)->ptr[i];
+ if (rb_inspecting_p(tmp)) {
tmp = rb_str_new2("[...]");
}
rb_io_puts(1, &tmp, out);
@@ -3821,17 +3956,17 @@ io_puts_ary(VALUE ary, VALUE out, int recur)
/*
* call-seq:
* ios.puts(obj, ...) => nil
- *
+ *
* Writes the given objects to <em>ios</em> as with
* <code>IO#print</code>. Writes a record separator (typically a
* newline) after any that do not already end with a newline sequence.
* If called with an array argument, writes each element on a new line.
* If called without arguments, outputs a single record separator.
- *
+ *
* $stdout.puts("this", "is", "a", "test")
- *
+ *
* <em>produces:</em>
- *
+ *
* this
* is
* a
@@ -3839,7 +3974,10 @@ io_puts_ary(VALUE ary, VALUE out, int recur)
*/
VALUE
-rb_io_puts(int argc, VALUE *argv, VALUE out)
+rb_io_puts(argc, argv, out)
+ int argc;
+ VALUE *argv;
+ VALUE out;
{
int i;
VALUE line;
@@ -3850,15 +3988,20 @@ rb_io_puts(int argc, VALUE *argv, VALUE out)
return Qnil;
}
for (i=0; i<argc; i++) {
- line = rb_check_array_type(argv[i]);
- if (!NIL_P(line)) {
- rb_exec_recursive(io_puts_ary, line, out);
- continue;
+ if (NIL_P(argv[i])) {
+ line = rb_str_new2("nil");
+ }
+ else {
+ line = rb_check_array_type(argv[i]);
+ if (!NIL_P(line)) {
+ rb_protect_inspect(io_puts_ary, line, out);
+ continue;
+ }
+ line = rb_obj_as_string(argv[i]);
}
- line = rb_obj_as_string(argv[i]);
rb_io_write(out, line);
- if (RSTRING_LEN(line) == 0 ||
- RSTRING_PTR(line)[RSTRING_LEN(line)-1] != '\n') {
+ if (RSTRING(line)->len == 0 ||
+ RSTRING(line)->ptr[RSTRING(line)->len-1] != '\n') {
rb_io_write(out, rb_default_rs);
}
}
@@ -3869,21 +4012,24 @@ rb_io_puts(int argc, VALUE *argv, VALUE out)
/*
* call-seq:
* puts(obj, ...) => nil
- *
- * Equivalent to
+ *
+ * Equivalent to
*
* $stdout.puts(obj, ...)
*/
static VALUE
-rb_f_puts(int argc, VALUE *argv)
+rb_f_puts(argc, argv)
+ int argc;
+ VALUE *argv;
{
rb_io_puts(argc, argv, rb_stdout);
return Qnil;
}
void
-rb_p(VALUE obj) /* for debug print within C code */
+rb_p(obj) /* for debug print within C code */
+ VALUE obj;
{
rb_io_write(rb_stdout, rb_obj_as_string(rb_inspect(obj)));
rb_io_write(rb_stdout, rb_default_rs);
@@ -3892,22 +4038,24 @@ rb_p(VALUE obj) /* for debug print within C code */
/*
* call-seq:
* p(obj, ...) => nil
- *
+ *
* For each object, directly writes
* _obj_.+inspect+ followed by the current output
* record separator to the program's standard output.
- *
+ *
* S = Struct.new(:name, :state)
* s = S['dave', 'TX']
* p s
- *
+ *
* <em>produces:</em>
- *
+ *
* #<S name="dave", state="TX">
*/
static VALUE
-rb_f_p(int argc, VALUE *argv)
+rb_f_p(argc, argv)
+ int argc;
+ VALUE *argv;
{
int i;
@@ -3923,28 +4071,31 @@ rb_f_p(int argc, VALUE *argv)
/*
* call-seq:
* obj.display(port=$>) => nil
- *
+ *
* Prints <i>obj</i> on the given port (default <code>$></code>).
* Equivalent to:
- *
+ *
* def display(port=$>)
* port.write self
* end
- *
+ *
* For example:
- *
+ *
* 1.display
* "cat".display
* [ 4, 5, 6 ].display
* puts
- *
+ *
* <em>produces:</em>
- *
+ *
* 1cat456
*/
static VALUE
-rb_obj_display(int argc, VALUE *argv, VALUE self)
+rb_obj_display(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
VALUE out;
@@ -3958,24 +4109,25 @@ rb_obj_display(int argc, VALUE *argv, VALUE self)
}
void
-rb_write_error2(const char *mesg, long len)
+rb_write_error2(mesg, len)
+ const char *mesg;
+ long len;
{
- if (rb_stderr == orig_stderr || RFILE(orig_stderr)->fptr->fd < 0) {
- fwrite(mesg, sizeof(char), len, stderr);
- }
- else {
- rb_io_write(rb_stderr, rb_str_new(mesg, len));
- }
+ rb_io_write(rb_stderr, rb_str_new(mesg, len));
}
void
-rb_write_error(const char *mesg)
+rb_write_error(mesg)
+ const char *mesg;
{
rb_write_error2(mesg, strlen(mesg));
}
static void
-must_respond_to(ID mid, VALUE val, ID id)
+must_respond_to(mid, val, id)
+ ID mid;
+ VALUE val;
+ ID id;
{
if (!rb_respond_to(val, mid)) {
rb_raise(rb_eTypeError, "%s must have %s method, %s given",
@@ -3985,155 +4137,129 @@ must_respond_to(ID mid, VALUE val, ID id)
}
static void
-stdout_setter(VALUE val, ID id, VALUE *variable)
+stdout_setter(val, id, variable)
+ VALUE val;
+ ID id;
+ VALUE *variable;
{
must_respond_to(id_write, val, id);
*variable = val;
}
static void
-defout_setter(VALUE val, ID id, VALUE *variable)
+defout_setter(val, id, variable)
+ VALUE val;
+ ID id;
+ VALUE *variable;
{
stdout_setter(val, id, variable);
rb_warn("$defout is obsolete; use $stdout instead");
}
static void
-deferr_setter(VALUE val, ID id, VALUE *variable)
+deferr_setter(val, id, variable)
+ VALUE val;
+ ID id;
+ VALUE *variable;
{
stdout_setter(val, id, variable);
rb_warn("$deferr is obsolete; use $stderr instead");
}
static VALUE
-prep_io(int fd, int mode, VALUE klass, const char *path)
+prep_stdio(f, mode, klass)
+ FILE *f;
+ int mode;
+ VALUE klass;
{
OpenFile *fp;
VALUE io = io_alloc(klass);
MakeOpenFile(io, fp);
- fp->fd = fd;
#ifdef __CYGWIN__
- if (!isatty(fd)) {
+ if (!isatty(fileno(f))) {
mode |= O_BINARY;
- setmode(fd, O_BINARY);
+ setmode(fileno(f), O_BINARY);
}
#endif
+ fp->f = f;
fp->mode = mode;
- io_check_tty(fp);
- if (path) fp->path = strdup(path);
return io;
}
-static VALUE
-prep_stdio(FILE *f, int mode, VALUE klass, const char *path)
+static void
+prep_path(io, path)
+ VALUE io;
+ char *path;
{
OpenFile *fptr;
- VALUE io = prep_io(fileno(f), mode|FMODE_PREP, klass, path);
GetOpenFile(io, fptr);
- fptr->stdio_file = f;
-
- return io;
-}
-
-FILE *rb_io_stdio_file(OpenFile *fptr)
-{
- if (!fptr->stdio_file) {
- fptr->stdio_file = rb_fdopen(fptr->fd, rb_io_flags_mode(fptr->mode));
- }
- return fptr->stdio_file;
+ if (fptr->path) rb_bug("illegal prep_path() call");
+ fptr->path = strdup(path);
}
/*
* call-seq:
* IO.new(fd, mode) => io
- *
+ *
* Returns a new <code>IO</code> object (a stream) for the given
- * <code>IO</code> object or integer file descriptor and mode
- * string. See also <code>IO#fileno</code> and
- * <code>IO::for_fd</code>.
- *
- * puts IO.new($stdout).fileno # => 1
- *
+ * integer file descriptor and mode string. See also
+ * <code>IO#fileno</code> and <code>IO::for_fd</code>.
+ *
* a = IO.new(2,"w") # '2' is standard error
* $stderr.puts "Hello"
* a.puts "World"
- *
+ *
* <em>produces:</em>
- *
+ *
* Hello
* World
*/
static VALUE
-rb_io_initialize(int argc, VALUE *argv, VALUE io)
+rb_io_initialize(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
- VALUE fnum, mode, orig;
- OpenFile *fp, *ofp = NULL;
- int fd, flags, fmode;
+ VALUE fnum, mode;
+ OpenFile *fp;
+ int fd, flags;
rb_secure(4);
rb_scan_args(argc, argv, "11", &fnum, &mode);
+ fd = NUM2INT(fnum);
if (argc == 2) {
if (FIXNUM_P(mode)) {
flags = FIX2LONG(mode);
}
else {
SafeStringValue(mode);
- flags = rb_io_mode_modenum(RSTRING_PTR(mode));
+ flags = rb_io_mode_modenum(StringValueCStr(mode));
}
}
- orig = rb_io_check_io(fnum);
- if (NIL_P(orig)) {
- fd = NUM2INT(fnum);
- if (argc != 2) {
+ else {
#if defined(HAVE_FCNTL) && defined(F_GETFL)
- flags = fcntl(fd, F_GETFL);
- if (flags == -1) rb_sys_fail(0);
+ flags = fcntl(fd, F_GETFL);
+ if (flags == -1) rb_sys_fail(0);
#else
- flags = O_RDONLY;
+ flags = O_RDONLY;
#endif
- }
- MakeOpenFile(io, fp);
- fp->fd = fd;
- fp->mode = rb_io_modenum_flags(flags);
- io_check_tty(fp);
- }
- else if (RFILE(io)->fptr) {
- rb_raise(rb_eRuntimeError, "reinitializing IO");
- }
- else {
- GetOpenFile(orig, ofp);
- if (ofp->refcnt == LONG_MAX) {
- VALUE s = rb_inspect(orig);
- rb_raise(rb_eIOError, "too many shared IO for %s", StringValuePtr(s));
- }
- if (argc == 2) {
- fmode = rb_io_modenum_flags(flags);
- if ((ofp->mode ^ fmode) & (FMODE_READWRITE|FMODE_BINMODE)) {
- if (FIXNUM_P(mode)) {
- rb_raise(rb_eArgError, "incompatible mode 0%o", flags);
- }
- else {
- rb_raise(rb_eArgError, "incompatible mode \"%s\"", RSTRING_PTR(mode));
- }
- }
- }
- ofp->refcnt++;
- RFILE(io)->fptr = ofp;
}
+ MakeOpenFile(io, fp);
+ fp->mode = rb_io_modenum_flags(flags);
+ fp->f = rb_fdopen(fd, rb_io_modenum_mode(flags));
return io;
}
-
/*
* call-seq:
* File.new(filename, mode="r") => file
* File.new(filename [, mode [, perm]]) => file
- *
+ *
* Opens the file named by _filename_ according to
* _mode_ (default is ``r'') and returns a new
@@ -4151,7 +4277,10 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
*/
static VALUE
-rb_file_initialize(int argc, VALUE *argv, VALUE io)
+rb_file_initialize(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
if (RFILE(io)->fptr) {
rb_raise(rb_eRuntimeError, "reinitializing File");
@@ -4172,23 +4301,26 @@ rb_file_initialize(int argc, VALUE *argv, VALUE io)
/*
* call-seq:
* IO.new(fd, mode_string) => io
- *
+ *
* Returns a new <code>IO</code> object (a stream) for the given
* integer file descriptor and mode string. See also
* <code>IO#fileno</code> and <code>IO::for_fd</code>.
- *
+ *
* a = IO.new(2,"w") # '2' is standard error
* $stderr.puts "Hello"
* a.puts "World"
- *
+ *
* <em>produces:</em>
- *
+ *
* Hello
* World
*/
static VALUE
-rb_io_s_new(int argc, VALUE *argv, VALUE klass)
+rb_io_s_new(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
if (rb_block_given_p()) {
char *cname = rb_class2name(klass);
@@ -4199,17 +4331,19 @@ rb_io_s_new(int argc, VALUE *argv, VALUE klass)
return rb_class_new_instance(argc, argv, klass);
}
-
/*
* call-seq:
* IO.for_fd(fd, mode) => io
- *
+ *
* Synonym for <code>IO::new</code>.
- *
+ *
*/
static VALUE
-rb_io_s_for_fd(int argc, VALUE *argv, VALUE klass)
+rb_io_s_for_fd(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE io = rb_obj_alloc(klass);
rb_io_initialize(argc, argv, io);
@@ -4221,7 +4355,7 @@ static int binmode = 0;
static VALUE
argf_forward(int argc, VALUE *argv)
{
- return rb_funcall3(current_file, rb_frame_this_func(), argc, argv);
+ return rb_funcall3(current_file, ruby_frame->last_func, argc, argv);
}
#define ARGF_FORWARD(argc, argv) do {\
@@ -4234,7 +4368,8 @@ argf_forward(int argc, VALUE *argv)
} while (0)
static void
-argf_close(VALUE file)
+argf_close(file)
+ VALUE file;
{
if (TYPE(file) == T_FILE)
rb_io_close(file);
@@ -4243,7 +4378,7 @@ argf_close(VALUE file)
}
static int
-next_argv(void)
+next_argv()
{
extern VALUE rb_argv;
char *fn;
@@ -4257,7 +4392,7 @@ next_argv(void)
}
if (init_p == 0) {
- if (RARRAY_LEN(rb_argv) > 0) {
+ if (RARRAY(rb_argv)->len > 0) {
next_p = 1;
}
else {
@@ -4270,9 +4405,9 @@ next_argv(void)
if (next_p == 1) {
next_p = 0;
retry:
- if (RARRAY_LEN(rb_argv) > 0) {
+ if (RARRAY(rb_argv)->len > 0) {
filename = rb_ary_shift(rb_argv);
- fn = StringValuePtr(filename);
+ fn = StringValueCStr(filename);
if (strlen(fn) == 1 && fn[0] == '-') {
current_file = rb_stdin;
if (ruby_inplace_mode) {
@@ -4281,17 +4416,17 @@ next_argv(void)
}
}
else {
- int fr = rb_sysopen(fn, O_RDONLY, 0);
+ FILE *fr = rb_fopen(fn, "r");
if (ruby_inplace_mode) {
struct stat st, st2;
VALUE str;
- int fw;
+ FILE *fw;
if (TYPE(rb_stdout) == T_FILE && rb_stdout != orig_stdout) {
rb_io_close(rb_stdout);
}
- fstat(fr, &st);
+ fstat(fileno(fr), &st);
if (*ruby_inplace_mode) {
str = rb_str_new2(fn);
#ifdef NO_LONG_FNAME
@@ -4300,15 +4435,15 @@ next_argv(void)
rb_str_cat2(str, ruby_inplace_mode);
#endif
#ifdef NO_SAFE_RENAME
- (void)close(fr);
- (void)unlink(RSTRING_PTR(str));
- (void)rename(fn, RSTRING_PTR(str));
- fr = rb_sysopen(RSTRING_PTR(str), O_RDONLY, 0);
+ (void)fclose(fr);
+ (void)unlink(RSTRING(str)->ptr);
+ (void)rename(fn, RSTRING(str)->ptr);
+ fr = rb_fopen(RSTRING(str)->ptr, "r");
#else
- if (rename(fn, RSTRING_PTR(str)) < 0) {
+ if (rename(fn, RSTRING(str)->ptr) < 0) {
rb_warn("Can't rename %s to %s: %s, skipping file",
- fn, RSTRING_PTR(str), strerror(errno));
- close(fr);
+ fn, RSTRING(str)->ptr, strerror(errno));
+ fclose(fr);
goto retry;
}
#endif
@@ -4320,27 +4455,29 @@ next_argv(void)
if (unlink(fn) < 0) {
rb_warn("Can't remove %s: %s, skipping file",
fn, strerror(errno));
- close(fr);
+ fclose(fr);
goto retry;
}
#endif
}
- fw = rb_sysopen(fn, O_WRONLY|O_CREAT|O_TRUNC, 0666);
+ fw = rb_fopen(fn, "w");
#ifndef NO_SAFE_RENAME
- fstat(fw, &st2);
+ fstat(fileno(fw), &st2);
#ifdef HAVE_FCHMOD
- fchmod(fw, st.st_mode);
+ fchmod(fileno(fw), st.st_mode);
#else
chmod(fn, st.st_mode);
#endif
if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
- fchown(fw, st.st_uid, st.st_gid);
+ fchown(fileno(fw), st.st_uid, st.st_gid);
}
#endif
- rb_stdout = prep_io(fw, FMODE_WRITABLE, rb_cFile, fn);
+ rb_stdout = prep_stdio(fw, FMODE_WRITABLE, rb_cFile);
+ prep_path(rb_stdout, fn);
if (stdout_binmode) rb_io_binmode(rb_stdout);
}
- current_file = prep_io(fr, FMODE_READABLE, rb_cFile, fn);
+ current_file = prep_stdio(fr, FMODE_READABLE, rb_cFile);
+ prep_path(current_file, fn);
}
if (binmode) rb_io_binmode(current_file);
}
@@ -4361,7 +4498,9 @@ next_argv(void)
}
static VALUE
-argf_getline(int argc, VALUE *argv)
+argf_getline(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE line;
@@ -4397,7 +4536,7 @@ argf_getline(int argc, VALUE *argv)
/*
* call-seq:
* gets(separator=$/) => string or nil
- *
+ *
* Returns (and assigns to <code>$_</code>) the next line from the list
* of files in +ARGV+ (or <code>$*</code>), or from standard
* input if no files are present on the command line. Returns
@@ -4408,23 +4547,25 @@ argf_getline(int argc, VALUE *argv)
* at a time, where paragraphs are divided by two consecutive newlines.
* If multiple filenames are present in +ARGV+,
* +gets(nil)+ will read the contents one file at a time.
- *
+ *
* ARGV << "testfile"
* print while gets
- *
+ *
* <em>produces:</em>
- *
+ *
* This is line one
* This is line two
* This is line three
* And so on...
- *
+ *
* The style of programming using <code>$_</code> as an implicit
* parameter is gradually losing favor in the Ruby community.
*/
static VALUE
-rb_f_gets(int argc, VALUE *argv)
+rb_f_gets(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE line;
@@ -4440,7 +4581,7 @@ rb_f_gets(int argc, VALUE *argv)
}
VALUE
-rb_gets(void)
+rb_gets()
{
VALUE line;
@@ -4468,13 +4609,15 @@ rb_gets(void)
/*
* call-seq:
* readline(separator=$/) => string
- *
+ *
* Equivalent to <code>Kernel::gets</code>, except
* +readline+ raises +EOFError+ at end of file.
*/
static VALUE
-rb_f_readline(int argc, VALUE *argv)
+rb_f_readline(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE line;
@@ -4491,8 +4634,9 @@ rb_f_readline(int argc, VALUE *argv)
/*
* obsolete
*/
+
static VALUE
-rb_f_getc(void)
+rb_f_getc()
{
rb_warn("getc is obsolete; use STDIN.getc instead");
if (TYPE(rb_stdin) != T_FILE) {
@@ -4504,13 +4648,15 @@ rb_f_getc(void)
/*
* call-seq:
* readlines(separator=$/) => array
- *
+ *
* Returns an array containing the lines returned by calling
* <code>Kernel.gets(<i>separator</i>)</code> until the end of file.
*/
static VALUE
-rb_f_readlines(int argc, VALUE *argv)
+rb_f_readlines(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE line, ary;
@@ -4526,11 +4672,11 @@ rb_f_readlines(int argc, VALUE *argv)
/*
* call-seq:
* `cmd` => string
- *
+ *
* Returns the standard output of running _cmd_ in a subshell.
* The built-in syntax <code>%x{...}</code> uses
* this method. Sets <code>$?</code> to the process status.
- *
+ *
* `date` #=> "Wed Apr 9 08:56:30 CDT 2003\n"
* `ls testdir`.split[1] #=> "main.rb"
* `echo oops && exit 99` #=> "oops\n"
@@ -4538,14 +4684,15 @@ rb_f_readlines(int argc, VALUE *argv)
*/
static VALUE
-rb_f_backquote(VALUE obj, VALUE str)
+rb_f_backquote(obj, str)
+ VALUE obj, str;
{
volatile VALUE port;
VALUE result;
OpenFile *fptr;
SafeStringValue(str);
- port = pipe_open(1, &str, "r");
+ port = pipe_open(str, 0, "r");
if (NIL_P(port)) return rb_str_new(0,0);
GetOpenFile(port, fptr);
@@ -4559,58 +4706,93 @@ rb_f_backquote(VALUE obj, VALUE str)
#include <sys/select.h>
#endif
+/*
+ * call-seq:
+ * IO.select(read_array
+ * [, write_array
+ * [, error_array
+ * [, timeout]]] ) => array or nil
+ *
+ * See <code>Kernel#select</code>.
+ */
+
static VALUE
-select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fdset_t *fds)
+rb_f_select(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
- VALUE res, list;
+ VALUE read, write, except, timeout, res, list;
+ fd_set rset, wset, eset, pset;
fd_set *rp, *wp, *ep;
+ struct timeval *tp, timerec;
OpenFile *fptr;
long i;
int max = 0, n;
int interrupt_flag = 0;
int pending = 0;
- struct timeval timerec;
+ rb_scan_args(argc, argv, "13", &read, &write, &except, &timeout);
+ if (NIL_P(timeout)) {
+ tp = 0;
+ }
+ else {
+ timerec = rb_time_interval(timeout);
+ tp = &timerec;
+ }
+
+ FD_ZERO(&pset);
if (!NIL_P(read)) {
Check_Type(read, T_ARRAY);
- for (i=0; i<RARRAY_LEN(read); i++) {
- GetOpenFile(rb_io_get_io(RARRAY_PTR(read)[i]), fptr);
- rb_fd_set(fptr->fd, &fds[0]);
- if (READ_DATA_PENDING(fptr)) { /* check for buffered data */
+ rp = &rset;
+ FD_ZERO(rp);
+ for (i=0; i<RARRAY(read)->len; i++) {
+ GetOpenFile(rb_io_get_io(RARRAY(read)->ptr[i]), fptr);
+ FD_SET(fileno(fptr->f), rp);
+ if (READ_DATA_PENDING(fptr->f)) { /* check for buffered data */
pending++;
- rb_fd_set(fptr->fd, &fds[3]);
+ FD_SET(fileno(fptr->f), &pset);
}
- if (max < fptr->fd) max = fptr->fd;
+ if (max < fileno(fptr->f)) max = fileno(fptr->f);
}
if (pending) { /* no blocking if there's buffered data */
timerec.tv_sec = timerec.tv_usec = 0;
tp = &timerec;
}
- rp = rb_fd_ptr(&fds[0]);
}
else
rp = 0;
if (!NIL_P(write)) {
Check_Type(write, T_ARRAY);
- for (i=0; i<RARRAY_LEN(write); i++) {
- GetOpenFile(rb_io_get_io(RARRAY_PTR(write)[i]), fptr);
- rb_fd_set(fptr->fd, &fds[1]);
- if (max < fptr->fd) max = fptr->fd;
+ wp = &wset;
+ FD_ZERO(wp);
+ for (i=0; i<RARRAY(write)->len; i++) {
+ GetOpenFile(rb_io_get_io(RARRAY(write)->ptr[i]), fptr);
+ FD_SET(fileno(fptr->f), wp);
+ if (max < fileno(fptr->f)) max = fileno(fptr->f);
+ if (fptr->f2) {
+ FD_SET(fileno(fptr->f2), wp);
+ if (max < fileno(fptr->f2)) max = fileno(fptr->f2);
+ }
}
- wp = rb_fd_ptr(&fds[1]);
}
else
wp = 0;
if (!NIL_P(except)) {
Check_Type(except, T_ARRAY);
- for (i=0; i<RARRAY_LEN(except); i++) {
- GetOpenFile(rb_io_get_io(RARRAY_PTR(except)[i]), fptr);
- rb_fd_set(fptr->fd, &fds[2]);
- if (max < fptr->fd) max = fptr->fd;
+ ep = &eset;
+ FD_ZERO(ep);
+ for (i=0; i<RARRAY(except)->len; i++) {
+ GetOpenFile(rb_io_get_io(RARRAY(except)->ptr[i]), fptr);
+ FD_SET(fileno(fptr->f), ep);
+ if (max < fileno(fptr->f)) max = fileno(fptr->f);
+ if (fptr->f2) {
+ FD_SET(fileno(fptr->f2), ep);
+ if (max < fileno(fptr->f2)) max = fileno(fptr->f2);
+ }
}
- ep = rb_fd_ptr(&fds[2]);
}
else {
ep = 0;
@@ -4631,31 +4813,37 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
if (interrupt_flag == 0) {
if (rp) {
- list = RARRAY_PTR(res)[0];
- for (i=0; i< RARRAY_LEN(read); i++) {
- GetOpenFile(rb_io_get_io(RARRAY_PTR(read)[i]), fptr);
- if (rb_fd_isset(fptr->fd, &fds[0]) ||
- rb_fd_isset(fptr->fd, &fds[3])) {
+ list = RARRAY(res)->ptr[0];
+ for (i=0; i< RARRAY(read)->len; i++) {
+ GetOpenFile(rb_io_get_io(RARRAY(read)->ptr[i]), fptr);
+ if (FD_ISSET(fileno(fptr->f), rp)
+ || FD_ISSET(fileno(fptr->f), &pset)) {
rb_ary_push(list, rb_ary_entry(read, i));
}
}
}
if (wp) {
- list = RARRAY_PTR(res)[1];
- for (i=0; i< RARRAY_LEN(write); i++) {
- GetOpenFile(rb_io_get_io(RARRAY_PTR(write)[i]), fptr);
- if (rb_fd_isset(fptr->fd, &fds[1])) {
+ list = RARRAY(res)->ptr[1];
+ for (i=0; i< RARRAY(write)->len; i++) {
+ GetOpenFile(rb_io_get_io(RARRAY(write)->ptr[i]), fptr);
+ if (FD_ISSET(fileno(fptr->f), wp)) {
+ rb_ary_push(list, rb_ary_entry(write, i));
+ }
+ else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), wp)) {
rb_ary_push(list, rb_ary_entry(write, i));
}
}
}
if (ep) {
- list = RARRAY_PTR(res)[2];
- for (i=0; i< RARRAY_LEN(except); i++) {
- GetOpenFile(rb_io_get_io(RARRAY_PTR(except)[i]), fptr);
- if (rb_fd_isset(fptr->fd, &fds[2])) {
+ list = RARRAY(res)->ptr[2];
+ for (i=0; i< RARRAY(except)->len; i++) {
+ GetOpenFile(rb_io_get_io(RARRAY(except)->ptr[i]), fptr);
+ if (FD_ISSET(fileno(fptr->f), ep)) {
+ rb_ary_push(list, rb_ary_entry(except, i));
+ }
+ else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), ep)) {
rb_ary_push(list, rb_ary_entry(except, i));
}
}
@@ -4665,75 +4853,11 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
return res; /* returns an empty array on interrupt */
}
-struct select_args {
- VALUE read, write, except;
- struct timeval *timeout;
- rb_fdset_t fdsets[4];
-};
-
-#ifdef HAVE_RB_FD_INIT
-static VALUE
-select_call(VALUE arg)
-{
- struct select_args *p = (struct select_args *)arg;
-
- return select_internal(p->read, p->write, p->except, p->timeout, p->fdsets);
-}
-
-static VALUE
-select_end(VALUE arg)
-{
- struct select_args *p = (struct select_args *)arg;
- int i;
-
- for (i = 0; i < sizeof(p->fdsets) / sizeof(p->fdsets[0]); ++i)
- rb_fd_term(&p->fdsets[i]);
- return Qnil;
-}
-#endif
-
-/*
- * call-seq:
- * IO.select(read_array
- * [, write_array
- * [, error_array
- * [, timeout]]] ) => array or nil
- *
- * See <code>Kernel#select</code>.
- */
-
-static VALUE
-rb_f_select(int argc, VALUE *argv, VALUE obj)
-{
- VALUE timeout;
- struct select_args args;
- struct timeval timerec;
- int i;
-
- rb_scan_args(argc, argv, "13", &args.read, &args.write, &args.except, &timeout);
- if (NIL_P(timeout)) {
- args.timeout = 0;
- }
- else {
- timerec = rb_time_interval(timeout);
- args.timeout = &timerec;
- }
-
- for (i = 0; i < sizeof(args.fdsets) / sizeof(args.fdsets[0]); ++i)
- rb_fd_init(&args.fdsets[i]);
-
-#ifdef HAVE_RB_FD_INIT
- return rb_ensure(select_call, (VALUE)&args, select_end, (VALUE)&args);
-#else
- return select_internal(args.read, args.write, args.except,
- args.timeout, args.fdsets);
-#endif
-
-}
-
#if !defined(MSDOS) && !defined(__human68k__)
static int
-io_cntl(int fd, int cmd, long narg, int io_p)
+io_cntl(fd, cmd, narg, io_p)
+ int fd, cmd, io_p;
+ long narg;
{
int retval;
@@ -4758,7 +4882,9 @@ io_cntl(int fd, int cmd, long narg, int io_p)
#endif
static VALUE
-rb_io_ctl(VALUE io, VALUE req, VALUE arg, int io_p)
+rb_io_ctl(io, req, arg, io_p)
+ VALUE io, req, arg;
+ int io_p;
{
#if !defined(MSDOS) && !defined(__human68k__)
int cmd = NUM2ULONG(req);
@@ -4798,23 +4924,28 @@ rb_io_ctl(VALUE io, VALUE req, VALUE arg, int io_p)
#endif
rb_str_modify(arg);
- if (len <= RSTRING_LEN(arg)) {
- len = RSTRING_LEN(arg);
+ if (len <= RSTRING(arg)->len) {
+ len = RSTRING(arg)->len;
}
- if (RSTRING_LEN(arg) < len) {
+ if (RSTRING(arg)->len < len) {
rb_str_resize(arg, len+1);
}
- RSTRING_PTR(arg)[len] = 17; /* a little sanity check here */
- narg = (long)RSTRING_PTR(arg);
+ RSTRING(arg)->ptr[len] = 17; /* a little sanity check here */
+ narg = (long)RSTRING(arg)->ptr;
}
}
GetOpenFile(io, fptr);
- retval = io_cntl(fptr->fd, cmd, narg, io_p);
+ retval = io_cntl(fileno(fptr->f), cmd, narg, io_p);
if (retval < 0) rb_sys_fail(fptr->path);
- if (TYPE(arg) == T_STRING && RSTRING_PTR(arg)[len] != 17) {
+ if (TYPE(arg) == T_STRING && RSTRING(arg)->ptr[len] != 17) {
rb_raise(rb_eArgError, "return value overflowed string");
}
+ if (fptr->f2 && fileno(fptr->f) != fileno(fptr->f2)) {
+ /* call on f2 too; ignore result */
+ io_cntl(fileno(fptr->f2), cmd, narg, io_p);
+ }
+
if (!io_p && cmd == F_SETFL) {
if (narg & O_NONBLOCK) {
fptr->mode |= FMODE_WSPLIT_INITIALIZED;
@@ -4832,11 +4963,10 @@ rb_io_ctl(VALUE io, VALUE req, VALUE arg, int io_p)
#endif
}
-
/*
* call-seq:
* ios.ioctl(integer_cmd, arg) => integer
- *
+ *
* Provides a mechanism for issuing low-level commands to control or
* query I/O devices. Arguments and results are platform dependent. If
* <i>arg</i> is a number, its value is passed directly. If it is a
@@ -4846,7 +4976,10 @@ rb_io_ctl(VALUE io, VALUE req, VALUE arg, int io_p)
*/
static VALUE
-rb_io_ioctl(int argc, VALUE *argv, VALUE io)
+rb_io_ioctl(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE req, arg;
@@ -4857,7 +4990,7 @@ rb_io_ioctl(int argc, VALUE *argv, VALUE io)
/*
* call-seq:
* ios.fcntl(integer_cmd, arg) => integer
- *
+ *
* Provides a mechanism for issuing low-level commands to control or
* query file-oriented I/O streams. Arguments and results are platform
* dependent. If <i>arg</i> is a number, its value is passed
@@ -4868,7 +5001,10 @@ rb_io_ioctl(int argc, VALUE *argv, VALUE io)
*/
static VALUE
-rb_io_fcntl(int argc, VALUE *argv, VALUE io)
+rb_io_fcntl(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
#ifdef HAVE_FCNTL
VALUE req, arg;
@@ -4884,7 +5020,7 @@ rb_io_fcntl(int argc, VALUE *argv, VALUE io)
/*
* call-seq:
* syscall(fixnum [, args...]) => integer
- *
+ *
* Calls the operating system function identified by _fixnum_,
* passing in the arguments, which must be either +String+
* objects, or +Integer+ objects that ultimately fit within
@@ -4892,16 +5028,18 @@ rb_io_fcntl(int argc, VALUE *argv, VALUE io)
* on the Atari-ST). The function identified by _fixnum_ is system
* dependent. On some Unix systems, the numbers may be obtained from a
* header file called <code>syscall.h</code>.
- *
+ *
* syscall 4, 1, "hello\n", 6 # '4' is write(2) on our box
- *
+ *
* <em>produces:</em>
- *
+ *
* hello
*/
static VALUE
-rb_f_syscall(int argc, VALUE *argv)
+rb_f_syscall(argc, argv)
+ int argc;
+ VALUE *argv;
{
#if defined(HAVE_SYSCALL) && !defined(__CHECKER__)
#ifdef atarist
@@ -4921,6 +5059,8 @@ rb_f_syscall(int argc, VALUE *argv)
rb_secure(2);
if (argc == 0)
rb_raise(rb_eArgError, "too few arguments for syscall");
+ if (argc > sizeof(arg) / sizeof(arg[0]))
+ rb_raise(rb_eArgError, "too many arguments for syscall");
arg[0] = NUM2LONG(argv[0]); argv++;
while (items--) {
VALUE v = rb_check_string_type(*argv);
@@ -4928,7 +5068,7 @@ rb_f_syscall(int argc, VALUE *argv)
if (!NIL_P(v)) {
StringValue(v);
rb_str_modify(v);
- arg[i] = (unsigned long)RSTRING_PTR(v);
+ arg[i] = (unsigned long)StringValueCStr(v);
}
else {
arg[i] = (unsigned long)NUM2LONG(*argv);
@@ -4999,8 +5139,10 @@ rb_f_syscall(int argc, VALUE *argv)
#endif
}
+static VALUE io_new_instance _((VALUE));
static VALUE
-io_new_instance(VALUE args)
+io_new_instance(args)
+ VALUE args;
{
return rb_class_new_instance(2, (VALUE*)args+1, *(VALUE*)args);
}
@@ -5008,21 +5150,21 @@ io_new_instance(VALUE args)
/*
* call-seq:
* IO.pipe -> array
- *
+ *
* Creates a pair of pipe endpoints (connected to each other) and
* returns them as a two-element array of <code>IO</code> objects:
* <code>[</code> <i>read_file</i>, <i>write_file</i> <code>]</code>. Not
* available on all platforms.
- *
+ *
* In the example below, the two processes close the ends of the pipe
* that they are not using. This is not just a cosmetic nicety. The
* read end of a pipe will not generate an end of file condition if
* there are any writers with the pipe still open. In the case of the
* parent process, the <code>rd.read</code> will never return if it
* does not first issue a <code>wr.close</code>.
- *
+ *
* rd, wr = IO.pipe
- *
+ *
* if fork
* wr.close
* puts "Parent got: <#{rd.read}>"
@@ -5034,21 +5176,26 @@ io_new_instance(VALUE args)
* wr.write "Hi Dad"
* wr.close
* end
- *
+ *
* <em>produces:</em>
- *
+ *
* Sending message to parent
* Parent got: <Hi Dad>
*/
static VALUE
-rb_io_s_pipe(VALUE klass)
+rb_io_s_pipe(klass)
+ VALUE klass;
{
#ifndef __human68k__
int pipes[2], state;
VALUE r, w, args[3];
+#ifdef _WIN32
+ if (_pipe(pipes, 1024, O_BINARY) == -1)
+#else
if (pipe(pipes) == -1)
+#endif
rb_sys_fail(0);
args[0] = klass;
@@ -5084,7 +5231,8 @@ struct foreach_arg {
};
static VALUE
-io_s_foreach(struct foreach_arg *arg)
+io_s_foreach(arg)
+ struct foreach_arg *arg;
{
VALUE str;
@@ -5097,43 +5245,46 @@ io_s_foreach(struct foreach_arg *arg)
/*
* call-seq:
* IO.foreach(name, sep_string=$/) {|line| block } => nil
- *
+ *
* Executes the block for every line in the named I/O port, where lines
* are separated by <em>sep_string</em>.
- *
+ *
* IO.foreach("testfile") {|x| print "GOT ", x }
- *
+ *
* <em>produces:</em>
- *
+ *
* GOT This is line one
* GOT This is line two
* GOT This is line three
* GOT And so on...
- */
+ */
static VALUE
-rb_io_s_foreach(int argc, VALUE *argv, VALUE self)
+rb_io_s_foreach(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE fname;
struct foreach_arg arg;
- RETURN_ENUMERATOR(self, argc, argv);
rb_scan_args(argc, argv, "11", &fname, &arg.sep);
- FilePathValue(fname);
+ SafeStringValue(fname);
+
if (argc == 1) {
arg.sep = rb_default_rs;
}
else if (!NIL_P(arg.sep)) {
StringValue(arg.sep);
}
- arg.io = rb_io_open(RSTRING_PTR(fname), "r");
+ arg.io = rb_io_open(StringValueCStr(fname), "r");
if (NIL_P(arg.io)) return Qnil;
return rb_ensure(io_s_foreach, (VALUE)&arg, rb_io_close, arg.io);
}
static VALUE
-io_s_readlines(struct foreach_arg *arg)
+io_s_readlines(arg)
+ struct foreach_arg *arg;
{
return rb_io_readlines(arg->argc, &arg->sep, arg->io);
}
@@ -5141,32 +5292,37 @@ io_s_readlines(struct foreach_arg *arg)
/*
* call-seq:
* IO.readlines(name, sep_string=$/) => array
- *
+ *
* Reads the entire file specified by <i>name</i> as individual
* lines, and returns those lines in an array. Lines are separated by
* <i>sep_string</i>.
- *
+ *
* a = IO.readlines("testfile")
* a[0] #=> "This is line one\n"
- *
+ *
*/
static VALUE
-rb_io_s_readlines(int argc, VALUE *argv, VALUE io)
+rb_io_s_readlines(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE fname;
struct foreach_arg arg;
rb_scan_args(argc, argv, "11", &fname, &arg.sep);
- FilePathValue(fname);
+ SafeStringValue(fname);
+
arg.argc = argc - 1;
- arg.io = rb_io_open(RSTRING_PTR(fname), "r");
+ arg.io = rb_io_open(StringValueCStr(fname), "r");
if (NIL_P(arg.io)) return Qnil;
return rb_ensure(io_s_readlines, (VALUE)&arg, rb_io_close, arg.io);
}
static VALUE
-io_s_read(struct foreach_arg *arg)
+io_s_read(arg)
+ struct foreach_arg *arg;
{
return io_read(arg->argc, &arg->sep, arg->io);
}
@@ -5174,26 +5330,30 @@ io_s_read(struct foreach_arg *arg)
/*
* call-seq:
* IO.read(name, [length [, offset]] ) => string
- *
+ *
* Opens the file, optionally seeks to the given offset, then returns
* <i>length</i> bytes (defaulting to the rest of the file).
* <code>read</code> ensures the file is closed before returning.
- *
+ *
* IO.read("testfile") #=> "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
* IO.read("testfile", 20) #=> "This is line one\nThi"
* IO.read("testfile", 20, 10) #=> "ne one\nThis is line "
*/
static VALUE
-rb_io_s_read(int argc, VALUE *argv, VALUE io)
+rb_io_s_read(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
{
VALUE fname, offset;
struct foreach_arg arg;
rb_scan_args(argc, argv, "12", &fname, &arg.sep, &offset);
- FilePathValue(fname);
+ SafeStringValue(fname);
+
arg.argc = argc ? 1 : 0;
- arg.io = rb_io_open(RSTRING_PTR(fname), "r");
+ arg.io = rb_io_open(StringValueCStr(fname), "r");
if (NIL_P(arg.io)) return Qnil;
if (!NIL_P(offset)) {
rb_io_seek(arg.io, offset, SEEK_SET);
@@ -5202,7 +5362,7 @@ rb_io_s_read(int argc, VALUE *argv, VALUE io)
}
static VALUE
-argf_tell(void)
+argf_tell()
{
if (!next_argv()) {
rb_raise(rb_eArgError, "no stream to tell");
@@ -5212,7 +5372,10 @@ argf_tell(void)
}
static VALUE
-argf_seek_m(int argc, VALUE *argv, VALUE self)
+argf_seek_m(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
if (!next_argv()) {
rb_raise(rb_eArgError, "no stream to seek");
@@ -5222,7 +5385,8 @@ argf_seek_m(int argc, VALUE *argv, VALUE self)
}
static VALUE
-argf_set_pos(VALUE self, VALUE offset)
+argf_set_pos(self, offset)
+ VALUE self, offset;
{
if (!next_argv()) {
rb_raise(rb_eArgError, "no stream to set position");
@@ -5232,7 +5396,7 @@ argf_set_pos(VALUE self, VALUE offset)
}
static VALUE
-argf_rewind(void)
+argf_rewind()
{
if (!next_argv()) {
rb_raise(rb_eArgError, "no stream to rewind");
@@ -5242,7 +5406,7 @@ argf_rewind(void)
}
static VALUE
-argf_fileno(void)
+argf_fileno()
{
if (!next_argv()) {
rb_raise(rb_eArgError, "no stream");
@@ -5252,7 +5416,7 @@ argf_fileno(void)
}
static VALUE
-argf_to_io(void)
+argf_to_io()
{
next_argv();
ARGF_FORWARD(0, 0);
@@ -5260,7 +5424,7 @@ argf_to_io(void)
}
static VALUE
-argf_eof(void)
+argf_eof()
{
if (current_file) {
if (init_p == 0) return Qtrue;
@@ -5273,7 +5437,9 @@ argf_eof(void)
}
static VALUE
-argf_read(int argc, VALUE *argv)
+argf_read(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE tmp, str, length;
long len = 0;
@@ -5308,8 +5474,8 @@ argf_read(int argc, VALUE *argv)
}
}
else if (argc >= 1) {
- if (RSTRING_LEN(str) < len) {
- len -= RSTRING_LEN(str);
+ if (RSTRING(str)->len < len) {
+ len -= RSTRING(str)->len;
argv[0] = INT2NUM(len);
goto retry;
}
@@ -5318,73 +5484,29 @@ argf_read(int argc, VALUE *argv)
}
static VALUE
-argf_readpartial_rescue(VALUE dummy)
-{
- return Qnil;
-}
-
-static VALUE
-argf_readpartial(int argc, VALUE *argv)
+argf_getc()
{
- VALUE tmp, str, length;
-
- rb_scan_args(argc, argv, "11", &length, &str);
- if (!NIL_P(str)) {
- StringValue(str);
- argv[1] = str;
- }
-
- if (!next_argv()) {
- rb_str_resize(str, 0);
- rb_eof_error();
- }
- if (TYPE(current_file) != T_FILE) {
- tmp = rb_rescue2(argf_forward, (VALUE)argv,
- argf_readpartial_rescue, (VALUE)Qnil,
- rb_eEOFError, (VALUE)0);
- }
- else {
- tmp = io_getpartial(argc, argv, current_file, 0);
- }
- if (NIL_P(tmp)) {
- if (next_p == -1) {
- rb_eof_error();
- }
- argf_close(current_file);
- next_p = 1;
- if (RARRAY_LEN(rb_argv) == 0)
- rb_eof_error();
- if (NIL_P(str))
- str = rb_str_new(NULL, 0);
- return str;
- }
- return tmp;
-}
-
-static VALUE
-argf_getc(void)
-{
- VALUE ch;
+ VALUE byte;
retry:
if (!next_argv()) return Qnil;
if (TYPE(current_file) != T_FILE) {
- ch = rb_funcall3(current_file, rb_intern("getc"), 0, 0);
+ byte = rb_funcall3(current_file, rb_intern("getc"), 0, 0);
}
else {
- ch = rb_io_getc_m(current_file);
+ byte = rb_io_getc(current_file);
}
- if (NIL_P(ch) && next_p != -1) {
+ if (NIL_P(byte) && next_p != -1) {
argf_close(current_file);
next_p = 1;
goto retry;
}
- return ch;
+ return byte;
}
static VALUE
-argf_readchar(void)
+argf_readchar()
{
VALUE c;
@@ -5397,16 +5519,17 @@ argf_readchar(void)
}
static VALUE
-argf_each_line(int argc, VALUE *argv, VALUE self)
+argf_each_line(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE str;
- RETURN_ENUMERATOR(self, argc, argv);
if (!next_argv()) return Qnil;
if (TYPE(current_file) != T_FILE) {
for (;;) {
if (!next_argv()) return argf;
- rb_block_call(current_file, rb_intern("each"), 0, 0, rb_yield, 0);
+ rb_iterate(rb_each, current_file, rb_yield, 0);
next_p = 1;
}
}
@@ -5417,11 +5540,10 @@ argf_each_line(int argc, VALUE *argv, VALUE self)
}
static VALUE
-argf_each_byte(VALUE self)
+argf_each_byte()
{
VALUE byte;
- RETURN_ENUMERATOR(self, 0, 0);
while (!NIL_P(byte = argf_getc())) {
rb_yield(byte);
}
@@ -5429,21 +5551,21 @@ argf_each_byte(VALUE self)
}
static VALUE
-argf_filename(void)
+argf_filename()
{
next_argv();
return filename;
}
static VALUE
-argf_file(void)
+argf_file()
{
next_argv();
return current_file;
}
static VALUE
-argf_binmode(void)
+argf_binmode()
{
binmode = 1;
next_argv();
@@ -5453,7 +5575,7 @@ argf_binmode(void)
}
static VALUE
-argf_skip(void)
+argf_skip()
{
if (next_p != -1) {
argf_close(current_file);
@@ -5463,7 +5585,7 @@ argf_skip(void)
}
static VALUE
-argf_close_m(void)
+argf_close_m()
{
next_argv();
argf_close(current_file);
@@ -5475,7 +5597,7 @@ argf_close_m(void)
}
static VALUE
-argf_closed(void)
+argf_closed()
{
next_argv();
ARGF_FORWARD(0, 0);
@@ -5483,20 +5605,21 @@ argf_closed(void)
}
static VALUE
-argf_to_s(void)
+argf_to_s()
{
return rb_str_new2("ARGF");
}
static VALUE
-opt_i_get(void)
+opt_i_get()
{
if (!ruby_inplace_mode) return Qnil;
return rb_str_new2(ruby_inplace_mode);
}
static void
-opt_i_set(VALUE val)
+opt_i_set(val)
+ VALUE val;
{
if (!RTEST(val)) {
if (ruby_inplace_mode) free(ruby_inplace_mode);
@@ -5506,45 +5629,45 @@ opt_i_set(VALUE val)
StringValue(val);
if (ruby_inplace_mode) free(ruby_inplace_mode);
ruby_inplace_mode = 0;
- ruby_inplace_mode = strdup(RSTRING_PTR(val));
+ ruby_inplace_mode = strdup(StringValueCStr(val));
}
/*
* Class <code>IO</code> is the basis for all input and output in Ruby.
* An I/O stream may be <em>duplexed</em> (that is, bidirectional), and
* so may use more than one native operating system stream.
- *
+ *
* Many of the examples in this section use class <code>File</code>,
* the only standard subclass of <code>IO</code>. The two classes are
* closely associated.
- *
+ *
* As used in this section, <em>portname</em> may take any of the
* following forms.
- *
+ *
* * A plain string represents a filename suitable for the underlying
* operating system.
- *
+ *
* * A string starting with ``<code>|</code>'' indicates a subprocess.
* The remainder of the string following the ``<code>|</code>'' is
* invoked as a process with appropriate input/output channels
* connected to it.
- *
+ *
* * A string equal to ``<code>|-</code>'' will create another Ruby
* instance as a subprocess.
- *
+ *
* Ruby will convert pathnames between different operating system
* conventions if possible. For instance, on a Windows system the
* filename ``<code>/gumby/ruby/test.rb</code>'' will be opened as
* ``<code>\gumby\ruby\test.rb</code>''. When specifying a
* Windows-style filename in a Ruby string, remember to escape the
* backslashes:
- *
+ *
* "c:\\gumby\\ruby\\test.rb"
- *
+ *
* Our examples here will use the Unix-style forward slashes;
* <code>File::SEPARATOR</code> can be used to get the
* platform-specific separator character.
- *
+ *
* I/O ports may be opened in any one of several different modes, which
* are shown in this section as <em>mode</em>. The mode may
* either be a Fixnum or a String. If numeric, it should be
@@ -5561,7 +5684,7 @@ opt_i_set(VALUE val)
* -----+--------------------------------------------------------
* "r+" | Read-write, starts at beginning of file.
* -----+--------------------------------------------------------
- * "w" | Write-only, truncates existing file
+ * "w" | Write-only, truncates existing file
* | to zero length or creates a new file for writing.
* -----+--------------------------------------------------------
* "w+" | Read-write, truncates existing file to zero length
@@ -5571,10 +5694,10 @@ opt_i_set(VALUE val)
* | otherwise creates a new file for writing.
* -----+--------------------------------------------------------
* "a+" | Read-write, starts at end of file if file exists,
- * | otherwise creates a new file for reading and
+ * | otherwise creates a new file for reading and
* | writing.
* -----+--------------------------------------------------------
- * "b" | (DOS/Windows only) Binary file mode (may appear with
+ * "b" | (DOS/Windows only) Binary file mode (may appear with
* | any of the key letters listed above).
*
*
@@ -5586,9 +5709,9 @@ opt_i_set(VALUE val)
*/
void
-Init_IO(void)
+Init_IO()
{
-#ifdef __CYGWIN__
+#ifdef __CYGWIN__
#include <sys/cygwin.h>
static struct __cygwin_perfile pf[] =
{
@@ -5607,7 +5730,6 @@ Init_IO(void)
id_write = rb_intern("write");
id_read = rb_intern("read");
id_getc = rb_intern("getc");
- id_flush = rb_intern("flush");
rb_define_global_function("syscall", rb_f_syscall, -1);
@@ -5670,8 +5792,6 @@ Init_IO(void)
rb_define_method(rb_cIO, "each", rb_io_each_line, -1);
rb_define_method(rb_cIO, "each_line", rb_io_each_line, -1);
rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0);
- rb_define_method(rb_cIO, "lines", rb_io_lines, -1);
- rb_define_method(rb_cIO, "bytes", rb_io_bytes, 0);
rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1);
@@ -5696,7 +5816,7 @@ Init_IO(void)
rb_define_method(rb_cIO, "write", io_write, 1);
rb_define_method(rb_cIO, "gets", rb_io_gets_m, -1);
rb_define_method(rb_cIO, "readline", rb_io_readline, -1);
- rb_define_method(rb_cIO, "getc", rb_io_getc_m, 0);
+ rb_define_method(rb_cIO, "getc", rb_io_getc, 0);
rb_define_method(rb_cIO, "readchar", rb_io_readchar, 0);
rb_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1);
rb_define_method(rb_cIO, "<<", rb_io_addstr, 1);
@@ -5728,11 +5848,11 @@ Init_IO(void)
rb_define_method(rb_cIO, "inspect", rb_io_inspect, 0);
rb_define_variable("$stdin", &rb_stdin);
- rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO, "<STDIN>");
+ rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO);
rb_define_hooked_variable("$stdout", &rb_stdout, 0, stdout_setter);
- rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO, "<STDOUT>");
+ rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO);
rb_define_hooked_variable("$stderr", &rb_stderr, 0, stdout_setter);
- rb_stderr = prep_stdio(stderr, FMODE_WRITABLE|FMODE_SYNC, rb_cIO, "<STDERR>");
+ rb_stderr = prep_stdio(stderr, FMODE_WRITABLE, rb_cIO);
rb_define_hooked_variable("$>", &rb_stdout, 0, stdout_setter);
orig_stdout = rb_stdout;
rb_deferr = orig_stderr = rb_stderr;
@@ -5761,7 +5881,6 @@ Init_IO(void)
rb_define_singleton_method(argf, "each_byte", argf_each_byte, 0);
rb_define_singleton_method(argf, "read", argf_read, -1);
- rb_define_singleton_method(argf, "readpartial", argf_readpartial, -1);
rb_define_singleton_method(argf, "readlines", rb_f_readlines, -1);
rb_define_singleton_method(argf, "to_a", rb_f_readlines, -1);
rb_define_singleton_method(argf, "gets", rb_f_gets, -1);
diff --git a/keywords b/keywords
index f306d8dd94..04be992857 100644
--- a/keywords
+++ b/keywords
@@ -1,47 +1,42 @@
-struct kwtable {char *name; int id[2]; enum lex_state_e state;};
-const struct kwtable *rb_reserved_word _((const char *, unsigned int));
-#ifndef RIPPER
-
+struct kwtable {char *name; int id[2]; enum lex_state state;};
%%
-__LINE__, {keyword__LINE__, keyword__LINE__}, EXPR_END
-__FILE__, {keyword__FILE__, keyword__FILE__}, EXPR_END
-BEGIN, {keyword_BEGIN, keyword_BEGIN}, EXPR_END
-END, {keyword_END, keyword_END}, EXPR_END
-alias, {keyword_alias, keyword_alias}, EXPR_FNAME
-and, {keyword_and, keyword_and}, EXPR_VALUE
-begin, {keyword_begin, keyword_begin}, EXPR_BEG
-break, {keyword_break, keyword_break}, EXPR_MID
-case, {keyword_case, keyword_case}, EXPR_VALUE
-class, {keyword_class, keyword_class}, EXPR_CLASS
-def, {keyword_def, keyword_def}, EXPR_FNAME
-defined?, {keyword_defined, keyword_defined}, EXPR_ARG
-do, {keyword_do, keyword_do}, EXPR_BEG
-else, {keyword_else, keyword_else}, EXPR_BEG
-elsif, {keyword_elsif, keyword_elsif}, EXPR_VALUE
-end, {keyword_end, keyword_end}, EXPR_END
-ensure, {keyword_ensure, keyword_ensure}, EXPR_BEG
-false, {keyword_false, keyword_false}, EXPR_END
-for, {keyword_for, keyword_for}, EXPR_VALUE
-if, {keyword_if, modifier_if}, EXPR_VALUE
-in, {keyword_in, keyword_in}, EXPR_VALUE
-module, {keyword_module, keyword_module}, EXPR_VALUE
-next, {keyword_next, keyword_next}, EXPR_MID
-nil, {keyword_nil, keyword_nil}, EXPR_END
-not, {keyword_not, keyword_not}, EXPR_VALUE
-or, {keyword_or, keyword_or}, EXPR_VALUE
-redo, {keyword_redo, keyword_redo}, EXPR_END
-rescue, {keyword_rescue, modifier_rescue}, EXPR_MID
-retry, {keyword_retry, keyword_retry}, EXPR_END
-return, {keyword_return, keyword_return}, EXPR_MID
-self, {keyword_self, keyword_self}, EXPR_END
-super, {keyword_super, keyword_super}, EXPR_ARG
-then, {keyword_then, keyword_then}, EXPR_BEG
-true, {keyword_true, keyword_true}, EXPR_END
-undef, {keyword_undef, keyword_undef}, EXPR_FNAME
-unless, {keyword_unless, modifier_unless}, EXPR_VALUE
-until, {keyword_until, modifier_until}, EXPR_VALUE
-when, {keyword_when, keyword_when}, EXPR_VALUE
-while, {keyword_while, modifier_while}, EXPR_VALUE
-yield, {keyword_yield, keyword_yield}, EXPR_ARG
-%%
-#endif
+__LINE__, {k__LINE__, k__LINE__}, EXPR_END
+__FILE__, {k__FILE__, k__FILE__}, EXPR_END
+BEGIN, {klBEGIN, klBEGIN}, EXPR_END
+END, {klEND, klEND}, EXPR_END
+alias, {kALIAS, kALIAS}, EXPR_FNAME
+and, {kAND, kAND}, EXPR_BEG
+begin, {kBEGIN, kBEGIN}, EXPR_BEG
+break, {kBREAK, kBREAK}, EXPR_MID
+case, {kCASE, kCASE}, EXPR_BEG
+class, {kCLASS, kCLASS}, EXPR_CLASS
+def, {kDEF, kDEF}, EXPR_FNAME
+defined?, {kDEFINED, kDEFINED}, EXPR_ARG
+do, {kDO, kDO}, EXPR_BEG
+else, {kELSE, kELSE}, EXPR_BEG
+elsif, {kELSIF, kELSIF}, EXPR_BEG
+end, {kEND, kEND}, EXPR_END
+ensure, {kENSURE, kENSURE}, EXPR_BEG
+false, {kFALSE, kFALSE}, EXPR_END
+for, {kFOR, kFOR}, EXPR_BEG
+if, {kIF, kIF_MOD}, EXPR_BEG
+in, {kIN, kIN}, EXPR_BEG
+module, {kMODULE, kMODULE}, EXPR_BEG
+next, {kNEXT, kNEXT}, EXPR_MID
+nil, {kNIL, kNIL}, EXPR_END
+not, {kNOT, kNOT}, EXPR_BEG
+or, {kOR, kOR}, EXPR_BEG
+redo, {kREDO, kREDO}, EXPR_END
+rescue, {kRESCUE, kRESCUE_MOD}, EXPR_MID
+retry, {kRETRY, kRETRY}, EXPR_END
+return, {kRETURN, kRETURN}, EXPR_MID
+self, {kSELF, kSELF}, EXPR_END
+super, {kSUPER, kSUPER}, EXPR_ARG
+then, {kTHEN, kTHEN}, EXPR_BEG
+true, {kTRUE, kTRUE}, EXPR_END
+undef, {kUNDEF, kUNDEF}, EXPR_FNAME
+unless, {kUNLESS, kUNLESS_MOD}, EXPR_BEG
+until, {kUNTIL, kUNTIL_MOD}, EXPR_BEG
+when, {kWHEN, kWHEN}, EXPR_BEG
+while, {kWHILE, kWHILE_MOD}, EXPR_BEG
+yield, {kYIELD, kYIELD}, EXPR_ARG
diff --git a/lex.c b/lex.c
index 5412455357..79d9448dae 100644
--- a/lex.c
+++ b/lex.c
@@ -1,44 +1,13 @@
-/* C code produced by gperf version 3.0.1 */
-/* Command-line: gperf -C -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' keywords */
-
-#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
- && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
- && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
- && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
- && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
- && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
- && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
- && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
- && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
- && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
- && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
- && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
- && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
- && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
- && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
- && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
- && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
- && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
- && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
- && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
- && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
- && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
- && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
-/* The character set is not based on ISO-646. */
-error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
-#endif
-
-#line 1 "keywords"
-struct kwtable {char *name; int id[2]; enum lex_state_e state;};
-const struct kwtable *rb_reserved_word _((const char *, unsigned int));
-#ifndef RIPPER
+/* C code produced by gperf version 2.7.2 */
+/* Command-line: gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' ./keywords */
+struct kwtable {char *name; int id[2]; enum lex_state state;};
#define TOTAL_KEYWORDS 40
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 8
#define MIN_HASH_VALUE 6
-#define MAX_HASH_VALUE 50
-/* maximum key range = 45, duplicates = 0 */
+#define MAX_HASH_VALUE 55
+/* maximum key range = 50, duplicates = 0 */
#ifdef __GNUC__
__inline
@@ -52,42 +21,42 @@ hash (str, len)
register const char *str;
register unsigned int len;
{
- static const unsigned char asso_values[] =
+ static unsigned char asso_values[] =
{
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 23, 51, 51, 13, 51, 1, 1,
- 11, 12, 51, 51, 51, 51, 10, 51, 12, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 11, 51, 13, 1, 26,
- 4, 1, 8, 28, 51, 23, 51, 1, 1, 27,
- 5, 19, 21, 51, 8, 3, 3, 11, 51, 21,
- 24, 16, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
- 51, 51, 51, 51, 51, 51
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 11, 56, 56, 36, 56, 1, 37,
+ 31, 1, 56, 56, 56, 56, 29, 56, 1, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 1, 56, 32, 1, 2,
+ 1, 1, 4, 23, 56, 17, 56, 20, 9, 2,
+ 9, 26, 14, 56, 5, 1, 1, 16, 56, 21,
+ 20, 9, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56
};
register int hval = len;
switch (hval)
{
default:
+ case 3:
hval += asso_values[(unsigned char)str[2]];
- /*FALLTHROUGH*/
case 2:
case 1:
hval += asso_values[(unsigned char)str[0]];
@@ -99,97 +68,56 @@ hash (str, len)
#ifdef __GNUC__
__inline
#endif
-const struct kwtable *
+struct kwtable *
rb_reserved_word (str, len)
register const char *str;
register unsigned int len;
{
- static const struct kwtable wordlist[] =
+ static struct kwtable wordlist[] =
{
{""}, {""}, {""}, {""}, {""}, {""},
-#line 9 "keywords"
- {"END", {keyword_END, keyword_END}, EXPR_END},
+ {"end", {kEND, kEND}, EXPR_END},
+ {"else", {kELSE, kELSE}, EXPR_BEG},
+ {"case", {kCASE, kCASE}, EXPR_BEG},
+ {"ensure", {kENSURE, kENSURE}, EXPR_BEG},
+ {"module", {kMODULE, kMODULE}, EXPR_BEG},
+ {"elsif", {kELSIF, kELSIF}, EXPR_BEG},
+ {"def", {kDEF, kDEF}, EXPR_FNAME},
+ {"rescue", {kRESCUE, kRESCUE_MOD}, EXPR_MID},
+ {"not", {kNOT, kNOT}, EXPR_BEG},
+ {"then", {kTHEN, kTHEN}, EXPR_BEG},
+ {"yield", {kYIELD, kYIELD}, EXPR_ARG},
+ {"for", {kFOR, kFOR}, EXPR_BEG},
+ {"self", {kSELF, kSELF}, EXPR_END},
+ {"false", {kFALSE, kFALSE}, EXPR_END},
+ {"retry", {kRETRY, kRETRY}, EXPR_END},
+ {"return", {kRETURN, kRETURN}, EXPR_MID},
+ {"true", {kTRUE, kTRUE}, EXPR_END},
+ {"if", {kIF, kIF_MOD}, EXPR_BEG},
+ {"defined?", {kDEFINED, kDEFINED}, EXPR_ARG},
+ {"super", {kSUPER, kSUPER}, EXPR_ARG},
+ {"undef", {kUNDEF, kUNDEF}, EXPR_FNAME},
+ {"break", {kBREAK, kBREAK}, EXPR_MID},
+ {"in", {kIN, kIN}, EXPR_BEG},
+ {"do", {kDO, kDO}, EXPR_BEG},
+ {"nil", {kNIL, kNIL}, EXPR_END},
+ {"until", {kUNTIL, kUNTIL_MOD}, EXPR_BEG},
+ {"unless", {kUNLESS, kUNLESS_MOD}, EXPR_BEG},
+ {"or", {kOR, kOR}, EXPR_BEG},
+ {"next", {kNEXT, kNEXT}, EXPR_MID},
+ {"when", {kWHEN, kWHEN}, EXPR_BEG},
+ {"redo", {kREDO, kREDO}, EXPR_END},
+ {"and", {kAND, kAND}, EXPR_BEG},
+ {"begin", {kBEGIN, kBEGIN}, EXPR_BEG},
+ {"__LINE__", {k__LINE__, k__LINE__}, EXPR_END},
+ {"class", {kCLASS, kCLASS}, EXPR_CLASS},
+ {"__FILE__", {k__FILE__, k__FILE__}, EXPR_END},
+ {"END", {klEND, klEND}, EXPR_END},
+ {"BEGIN", {klBEGIN, klBEGIN}, EXPR_END},
+ {"while", {kWHILE, kWHILE_MOD}, EXPR_BEG},
+ {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""},
-#line 13 "keywords"
- {"break", {keyword_break, keyword_break}, EXPR_MID},
-#line 19 "keywords"
- {"else", {keyword_else, keyword_else}, EXPR_BEG},
-#line 29 "keywords"
- {"nil", {keyword_nil, keyword_nil}, EXPR_END},
-#line 22 "keywords"
- {"ensure", {keyword_ensure, keyword_ensure}, EXPR_BEG},
-#line 21 "keywords"
- {"end", {keyword_end, keyword_end}, EXPR_END},
-#line 38 "keywords"
- {"then", {keyword_then, keyword_then}, EXPR_BEG},
-#line 30 "keywords"
- {"not", {keyword_not, keyword_not}, EXPR_VALUE},
-#line 23 "keywords"
- {"false", {keyword_false, keyword_false}, EXPR_END},
-#line 36 "keywords"
- {"self", {keyword_self, keyword_self}, EXPR_END},
-#line 20 "keywords"
- {"elsif", {keyword_elsif, keyword_elsif}, EXPR_VALUE},
-#line 33 "keywords"
- {"rescue", {keyword_rescue, modifier_rescue}, EXPR_MID},
-#line 39 "keywords"
- {"true", {keyword_true, keyword_true}, EXPR_END},
-#line 42 "keywords"
- {"until", {keyword_until, modifier_until}, EXPR_VALUE},
-#line 41 "keywords"
- {"unless", {keyword_unless, modifier_unless}, EXPR_VALUE},
-#line 35 "keywords"
- {"return", {keyword_return, keyword_return}, EXPR_MID},
-#line 16 "keywords"
- {"def", {keyword_def, keyword_def}, EXPR_FNAME},
-#line 11 "keywords"
- {"and", {keyword_and, keyword_and}, EXPR_VALUE},
-#line 18 "keywords"
- {"do", {keyword_do, keyword_do}, EXPR_BEG},
-#line 45 "keywords"
- {"yield", {keyword_yield, keyword_yield}, EXPR_ARG},
-#line 24 "keywords"
- {"for", {keyword_for, keyword_for}, EXPR_VALUE},
-#line 40 "keywords"
- {"undef", {keyword_undef, keyword_undef}, EXPR_FNAME},
-#line 31 "keywords"
- {"or", {keyword_or, keyword_or}, EXPR_VALUE},
-#line 26 "keywords"
- {"in", {keyword_in, keyword_in}, EXPR_VALUE},
-#line 43 "keywords"
- {"when", {keyword_when, keyword_when}, EXPR_VALUE},
-#line 34 "keywords"
- {"retry", {keyword_retry, keyword_retry}, EXPR_END},
-#line 25 "keywords"
- {"if", {keyword_if, modifier_if}, EXPR_VALUE},
-#line 14 "keywords"
- {"case", {keyword_case, keyword_case}, EXPR_VALUE},
-#line 32 "keywords"
- {"redo", {keyword_redo, keyword_redo}, EXPR_END},
-#line 28 "keywords"
- {"next", {keyword_next, keyword_next}, EXPR_MID},
-#line 37 "keywords"
- {"super", {keyword_super, keyword_super}, EXPR_ARG},
-#line 27 "keywords"
- {"module", {keyword_module, keyword_module}, EXPR_VALUE},
-#line 12 "keywords"
- {"begin", {keyword_begin, keyword_begin}, EXPR_BEG},
-#line 6 "keywords"
- {"__LINE__", {keyword__LINE__, keyword__LINE__}, EXPR_END},
-#line 7 "keywords"
- {"__FILE__", {keyword__FILE__, keyword__FILE__}, EXPR_END},
-#line 8 "keywords"
- {"BEGIN", {keyword_BEGIN, keyword_BEGIN}, EXPR_END},
-#line 17 "keywords"
- {"defined?", {keyword_defined, keyword_defined}, EXPR_ARG},
-#line 10 "keywords"
- {"alias", {keyword_alias, keyword_alias}, EXPR_FNAME},
- {""}, {""},
-#line 15 "keywords"
- {"class", {keyword_class, keyword_class}, EXPR_CLASS},
- {""}, {""},
-#line 44 "keywords"
- {"while", {keyword_while, modifier_while}, EXPR_VALUE}
+ {"alias", {kALIAS, kALIAS}, EXPR_FNAME}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
@@ -206,6 +134,3 @@ rb_reserved_word (str, len)
}
return 0;
}
-#line 46 "keywords"
-
-#endif
diff --git a/lib/.document b/lib/.document
index a3ce8989fc..2159be8360 100644
--- a/lib/.document
+++ b/lib/.document
@@ -8,11 +8,13 @@
English.rb
Env.rb
+README
abbrev.rb
base64.rb
benchmark.rb
cgi
cgi.rb
+cgi-lib.rb
complex.rb
csv.rb
date
@@ -22,6 +24,7 @@ debug.rb
delegate.rb
drb
drb.rb
+e2mmap.rb
erb.rb
eregex.rb
fileutils.rb
@@ -35,6 +38,7 @@ getopts.rb
gserver.rb
importenv.rb
ipaddr.rb
+irb
irb.rb
jcode.rb
logger.rb
diff --git a/lib/README b/lib/README
index 19d6309166..d60c5cb1e9 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 suppor
+complex.rb complex number support
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 b551032d90..8628d611b2 100644
--- a/lib/base64.rb
+++ b/lib/base64.rb
@@ -102,7 +102,7 @@ module Base64
#
# require 'base64'
# data = "Now is the time for all good coders\nto learn Ruby"
- # puts Base64.b64encode(data)
+ # Base64.b64encode(data)
#
# <i>Generates:</i>
#
@@ -110,7 +110,7 @@ module Base64
# UnVieQ==
def b64encode(bin, len = 60)
- encode64(bin).scan(/.{1,#{len}}/o) do
+ encode64(bin).scan(/.{1,#{len}}/) do
print $&, "\n"
end
end
@@ -119,16 +119,13 @@ module Base64
module Deprecated # :nodoc:
include Base64
- def _deprecated_base64(*args)
- m0, m1 = caller(0)
- m = m0[/\`(.*?)\'\z/, 1]
- warn("#{m1}: #{m} is deprecated; use Base64.#{m} instead")
- super
- end
- dep = instance_method(:_deprecated_base64)
- remove_method(:_deprecated_base64)
for m in Base64.private_instance_methods(false)
- define_method(m, dep)
+ module_eval %{
+ def #{m}(*args)
+ warn("\#{caller(1)[0]}: #{m} is deprecated; use Base64.#{m} instead")
+ super
+ end
+ }
end
end
end
diff --git a/lib/benchmark.rb b/lib/benchmark.rb
index 36e593518f..6ab0755613 100644
--- a/lib/benchmark.rb
+++ b/lib/benchmark.rb
@@ -304,7 +304,10 @@ module Benchmark
# Returns the elapsed real time used to execute the given block.
#
def realtime(&blk) # :yield:
- Benchmark::measure(&blk).real
+ r0 = Time.now
+ yield
+ r1 = Time.now
+ r1.to_f - r0.to_f
end
@@ -330,7 +333,7 @@ module Benchmark
# Registers the given label and block pair in the job list.
#
def item(label = "", &blk) # :yield:
- raise ArgmentError, "no block" unless block_given?
+ raise ArgumentError, "no block" unless block_given?
label.concat ' '
w = label.length
@width = w if @width < w
diff --git a/lib/cgi-lib.rb b/lib/cgi-lib.rb
new file mode 100644
index 0000000000..d6b60d66cc
--- /dev/null
+++ b/lib/cgi-lib.rb
@@ -0,0 +1,272 @@
+warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: cgi-lib is deprecated after Ruby 1.8.1; use cgi instead"
+
+=begin
+
+= simple CGI support library
+
+= example
+
+== get form values
+
+ require "cgi-lib.rb"
+ query = CGI.new
+ query['field'] # <== value of 'field'
+ query.keys # <== array of fields
+
+and query has Hash class methods
+
+
+== get cookie values
+
+ require "cgi-lib.rb"
+ query = CGI.new
+ query.cookie['name'] # <== cookie value of 'name'
+ query.cookie.keys # <== all cookie names
+
+and query.cookie has Hash class methods
+
+
+== print HTTP header and HTML string to $>
+
+ require "cgi-lib.rb"
+ CGI::print{
+ CGI::tag("HTML"){
+ CGI::tag("HEAD"){ CGI::tag("TITLE"){"TITLE"} } +
+ CGI::tag("BODY"){
+ CGI::tag("FORM", {"ACTION"=>"test.rb", "METHOD"=>"POST"}){
+ CGI::tag("INPUT", {"TYPE"=>"submit", "VALUE"=>"submit"})
+ } +
+ CGI::tag("HR")
+ }
+ }
+ }
+
+
+== make raw cookie string
+
+ require "cgi-lib.rb"
+ cookie1 = CGI::cookie({'name' => 'name',
+ 'value' => 'value',
+ 'path' => 'path', # optional
+ 'domain' => 'domain', # optional
+ 'expires' => Time.now, # optional
+ 'secure' => true # optional
+ })
+
+ CGI::print("Content-Type: text/html", cookie1, cookie2){ "string" }
+
+
+== print HTTP header and string to $>
+
+ require "cgi-lib.rb"
+ CGI::print{ "string" }
+ # == CGI::print("Content-Type: text/html"){ "string" }
+ CGI::print("Content-Type: text/html", cookie1, cookie2){ "string" }
+
+
+=== NPH (no-parse-header) mode
+
+ require "cgi-lib.rb"
+ CGI::print("nph"){ "string" }
+ # == CGI::print("nph", "Content-Type: text/html"){ "string" }
+ CGI::print("nph", "Content-Type: text/html", cookie1, cookie2){ "string" }
+
+
+== make HTML tag string
+
+ require "cgi-lib.rb"
+ CGI::tag("element", {"attribute_name"=>"attribute_value"}){"content"}
+
+
+== make HTTP header string
+
+ require "cgi-lib.rb"
+ CGI::header # == CGI::header("Content-Type: text/html")
+ CGI::header("Content-Type: text/html", cookie1, cookie2)
+
+
+=== NPH (no-parse-header) mode
+
+ CGI::header("nph") # == CGI::header("nph", "Content-Type: text/html")
+ CGI::header("nph", "Content-Type: text/html", cookie1, cookie2)
+
+
+== escape url encode
+
+ require "cgi-lib.rb"
+ url_encoded_string = CGI::escape("string")
+
+
+== unescape url encoded
+
+ require "cgi-lib.rb"
+ string = CGI::unescape("url encoded string")
+
+
+== escape HTML &"<>
+
+ require "cgi-lib.rb"
+ CGI::escapeHTML("string")
+
+
+=end
+
+require "delegate"
+
+class CGI < SimpleDelegator
+
+ CR = "\015"
+ LF = "\012"
+ EOL = CR + LF
+
+ RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
+ RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
+
+ # make rfc1123 date string
+ def CGI::rfc1123_date(time)
+ t = time.clone.gmtime
+ return format("%s, %.2d %s %d %.2d:%.2d:%.2d GMT",
+ RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
+ t.hour, t.min, t.sec)
+ end
+
+ # escape url encode
+ def CGI::escape(str)
+ str.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
+ end
+
+ # unescape url encoded
+ def CGI::unescape(str)
+ str.gsub(/\+/, ' ').gsub(/%([0-9a-fA-F]{2})/){ [$1.hex].pack("c") }
+ end
+
+ # escape HTML
+ def CGI::escapeHTML(str)
+ str.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
+ end
+
+ # offline mode. read name=value pairs on standard input.
+ def read_from_cmdline
+ require "shellwords.rb"
+ words = Shellwords.shellwords(
+ if not ARGV.empty?
+ ARGV.join(' ')
+ else
+ STDERR.print "(offline mode: enter name=value pairs on standard input)\n" if STDIN.tty?
+ readlines.join(' ').gsub(/\n/, '')
+ end.gsub(/\\=/, '%3D').gsub(/\\&/, '%26'))
+
+ if words.find{|x| x =~ /=/} then words.join('&') else words.join('+') end
+ end
+
+ def initialize(input = $stdin)
+
+ @inputs = {}
+ @cookie = {}
+
+ case ENV['REQUEST_METHOD']
+ when "GET"
+ ENV['QUERY_STRING'] or ""
+ when "POST"
+ input.read(Integer(ENV['CONTENT_LENGTH'])) or ""
+ else
+ read_from_cmdline
+ end.split(/[&;]/).each do |x|
+ key, val = x.split(/=/,2).collect{|x|CGI::unescape(x)}
+ if @inputs.include?(key)
+ @inputs[key] += "\0" + (val or "")
+ else
+ @inputs[key] = (val or "")
+ end
+ end
+
+ super(@inputs)
+
+ if ENV.has_key?('HTTP_COOKIE') or ENV.has_key?('COOKIE')
+ (ENV['HTTP_COOKIE'] or ENV['COOKIE']).split(/; /).each do |x|
+ key, val = x.split(/=/,2)
+ key = CGI::unescape(key)
+ val = val.split(/&/).collect{|x|CGI::unescape(x)}.join("\0")
+ if @cookie.include?(key)
+ @cookie[key] += "\0" + val
+ else
+ @cookie[key] = val
+ end
+ end
+ end
+ end
+
+ attr("inputs")
+ attr("cookie")
+
+ # make HTML tag string
+ def CGI::tag(element, attributes = {})
+ "<" + escapeHTML(element) + attributes.collect{|name, value|
+ " " + escapeHTML(name) + '="' + escapeHTML(value) + '"'
+ }.to_s + ">" +
+ (iterator? ? yield.to_s + "</" + escapeHTML(element) + ">" : "")
+ end
+
+ # make raw cookie string
+ def CGI::cookie(options)
+ "Set-Cookie: " + options['name'] + '=' + escape(options['value']) +
+ (options['domain'] ? '; domain=' + options['domain'] : '') +
+ (options['path'] ? '; path=' + options['path'] : '') +
+ (options['expires'] ? '; expires=' + rfc1123_date(options['expires']) : '') +
+ (options['secure'] ? '; secure' : '')
+ end
+
+ # make HTTP header string
+ def CGI::header(*options)
+ if defined?(MOD_RUBY)
+ options.each{|option|
+ option.sub(/(.*?): (.*)/){
+ Apache::request.headers_out[$1] = $2
+ }
+ }
+ Apache::request.send_http_header
+ ''
+ else
+ if options.delete("nph") or (ENV['SERVER_SOFTWARE'] =~ /IIS/)
+ [(ENV['SERVER_PROTOCOL'] or "HTTP/1.0") + " 200 OK",
+ "Date: " + rfc1123_date(Time.now),
+ "Server: " + (ENV['SERVER_SOFTWARE'] or ""),
+ "Connection: close"] +
+ (options.empty? ? ["Content-Type: text/html"] : options)
+ else
+ options.empty? ? ["Content-Type: text/html"] : options
+ end.join(EOL) + EOL + EOL
+ end
+ end
+
+ # print HTTP header and string to $>
+ def CGI::print(*options)
+ $>.print CGI::header(*options) + yield.to_s
+ end
+
+ # print message to $>
+ def CGI::message(message, title = "", header = ["Content-Type: text/html"])
+ if message.kind_of?(Hash)
+ title = message['title']
+ header = message['header']
+ message = message['body']
+ end
+ CGI::print(*header){
+ CGI::tag("HTML"){
+ CGI::tag("HEAD"){ CGI.tag("TITLE"){ title } } +
+ CGI::tag("BODY"){ message }
+ }
+ }
+ true
+ end
+
+ # print error message to $> and exit
+ def CGI::error
+ CGI::message({'title'=>'ERROR', 'body'=>
+ CGI::tag("PRE"){
+ "ERROR: " + CGI::tag("STRONG"){ escapeHTML($!.to_s) } + "\n" + escapeHTML($@.join("\n"))
+ }
+ })
+ exit
+ end
+end
diff --git a/lib/cgi.rb b/lib/cgi.rb
index 8fc7061eca..bf64d5a54c 100644
--- a/lib/cgi.rb
+++ b/lib/cgi.rb
@@ -367,13 +367,13 @@ class CGI
# CGI::unescapeHTML("Usage: foo &quot;bar&quot; &lt;baz&gt;")
# # => "Usage: foo \"bar\" <baz>"
def CGI::unescapeHTML(string)
- string.gsub(/&(.*?);/n) do
+ string.gsub(/&(amp|quot|gt|lt|\#[0-9]+|\#x[0-9A-Fa-f]+);/n) do
match = $1.dup
case match
- when /\Aamp\z/ni then '&'
- when /\Aquot\z/ni then '"'
- when /\Agt\z/ni then '>'
- when /\Alt\z/ni then '<'
+ when 'amp' then '&'
+ when 'quot' then '"'
+ when 'gt' then '>'
+ when 'lt' then '<'
when /\A#0*(\d+)\z/n then
if Integer($1) < 256
Integer($1).chr
@@ -399,12 +399,7 @@ class CGI
end
end
end
- def CGI::escape_html(str)
- escapeHTML(str)
- end
- def CGI::unescape_html(str)
- unescapeHTML(str)
- end
+
# Escape only the tags of certain HTML elements in +string+.
#
@@ -450,12 +445,7 @@ class CGI
string
end
end
- def CGI::escape_element(str)
- escapeElement(str)
- end
- def CGI::unescape_element(str)
- unescapeElement(str)
- end
+
# Format a +Time+ object as a String using the format specified by RFC 1123.
#
@@ -566,7 +556,8 @@ class CGI
end
options.delete("nph") if defined?(MOD_RUBY)
- if options.delete("nph") or /IIS/n.match(env_table['SERVER_SOFTWARE'])
+ if options.delete("nph") or
+ (/IIS\/(\d+)/n.match(env_table['SERVER_SOFTWARE']) and $1.to_i < 5)
buf += (env_table["SERVER_PROTOCOL"] or "HTTP/1.0") + " " +
(HTTP_STATUS[options["status"]] or options["status"] or "200 OK") +
EOL +
@@ -718,13 +709,13 @@ class CGI
require "nkf"
case options["charset"]
when /iso-2022-jp/ni
- content = NKF::nkf('-j -m0 -x', content)
+ content = NKF::nkf('-m0 -x -j', content)
options["language"] = "ja" unless options.has_key?("language")
when /euc-jp/ni
- content = NKF::nkf('-e -m0 -x', content)
+ content = NKF::nkf('-m0 -x -e', content)
options["language"] = "ja" unless options.has_key?("language")
when /shift_jis/ni
- content = NKF::nkf('-s -m0 -x', content)
+ content = NKF::nkf('-m0 -x -s', content)
options["language"] = "ja" unless options.has_key?("language")
end
end
@@ -962,11 +953,11 @@ class CGI
end
# Get the cookies as a hash of cookie-name=>Cookie pairs.
- attr_accessor :cookies
+ attr_accessor("cookies")
# Get the parameters as a hash of name=>values pairs, where
# values is an Array.
- attr_reader :params
+ attr("params")
# Set all the parameters.
def params=(hash)
@@ -977,6 +968,7 @@ class CGI
def read_multipart(boundary, content_length)
params = Hash.new([])
boundary = "--" + boundary
+ quoted_boundary = Regexp.quote(boundary, "n")
buf = ""
bufsize = 10 * 1024
boundary_end=""
@@ -994,9 +986,22 @@ class CGI
loop do
head = nil
- body = MorphingBody.new
+ if 10240 < content_length
+ require "tempfile"
+ body = Tempfile.new("CGI")
+ else
+ begin
+ require "stringio"
+ body = StringIO.new
+ rescue LoadError
+ require "tempfile"
+ body = Tempfile.new("CGI")
+ end
+ end
+ body.binmode if defined? body.binmode
+
+ until head and /#{quoted_boundary}(?:#{EOL}|--)/n.match(buf)
- until head and /#{boundary}(?:#{EOL}|--)/n.match(buf)
if (not head) and /#{EOL}#{EOL}/n.match(buf)
buf = buf.sub(/\A((?:.|\n)*?#{EOL})#{EOL}/n) do
head = $1.dup
@@ -1022,27 +1027,26 @@ class CGI
content_length -= c.size
end
- buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{boundary}([\r\n]{1,2}|--)/n) do
+ buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{quoted_boundary}([\r\n]{1,2}|--)/n) do
body.print $1
if "--" == $2
content_length = -1
end
- boundary_end = $2.dup
+ boundary_end = $2.dup
""
end
- p body
body.rewind
- /Content-Disposition:.* filename="?([^\";]*)"?/ni.match(head)
- filename = ($1 or "")
+ /Content-Disposition:.* filename=(?:"((?:\\.|[^\"])*)"|([^;\s]*))/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
(not /MSIE/ni.match(env_table['HTTP_USER_AGENT']))
filename = CGI::unescape(filename)
end
- /Content-Type: (.*)/ni.match(head)
+ /Content-Type: ([^\s]*)/ni.match(head)
content_type = ($1 or "")
(class << body; self; end).class_eval do
@@ -1051,8 +1055,8 @@ class CGI
define_method(:content_type) {content_type.dup.taint}
end
- /Content-Disposition:.* name="?([^\";]*)"?/ni.match(head)
- name = ($1 || "").dup
+ /Content-Disposition:.* name="?([^\";\s]*)"?/ni.match(head)
+ name = $1.dup
if params.has_key?(name)
params[name].push(body)
@@ -1060,7 +1064,7 @@ class CGI
params[name] = [body]
end
break if buf.size == 0
- break if content_length === -1
+ break if content_length == -1
end
raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/
@@ -1093,59 +1097,6 @@ class CGI
end
private :read_from_cmdline
- # A wrapper class to use a StringIO object as the body and switch
- # to a TempFile when the passed threshold is passed.
- class MorphingBody
- begin
- require "stringio"
- @@small_buffer = lambda{StringIO.new}
- rescue LoadError
- require "tempfile"
- @@small_buffer = lambda{
- n = Tempfile.new("CGI")
- n.binmode
- n
- }
- end
-
- def initialize(morph_threshold = 10240)
- @threshold = morph_threshold
- @body = @@small_buffer.call
- @cur_size = 0
- @morph_check = true
- end
-
- def print(data)
- if @morph_check && (@cur_size + data.size > @threshold)
- convert_body
- end
- @body.print data
- end
- def rewind
- @body.rewind
- end
- def path
- @body.path
- end
-
- # returns the true body object.
- def extract
- @body
- end
-
- private
- def convert_body
- new_body = TempFile.new("CGI")
- new_body.binmode if defined? @body.binmode
- new_body.binmode if defined? new_body.binmode
-
- @body.rewind
- new_body.print @body.read
- @body = new_body
- @morph_check = false
- end
- end
-
# Initialize the data from the query.
#
# Handles multipart forms (in particular, forms that involve file uploads).
@@ -1212,6 +1163,7 @@ 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
@@ -1306,7 +1258,7 @@ class CGI
else
'="' + CGI::escapeHTML(value) + '"'
end
- }.join + ">"
+ }.to_s + ">"
END
s.sub!(/\Z/, " +") << append if append
s
@@ -1529,7 +1481,7 @@ class CGI
value[value.size - 1]
end
end
- }.join
+ }.to_s
end
@@ -1609,7 +1561,7 @@ class CGI
if @output_hidden
body += @output_hidden.collect{|k,v|
"<INPUT TYPE=\"HIDDEN\" NAME=\"#{k}\" VALUE=\"#{v}\">"
- }.join
+ }.to_s
end
super(attributes){body}
end
@@ -1907,7 +1859,7 @@ class CGI
}
end
end
- }.join
+ }.to_s
}
end
@@ -1984,7 +1936,7 @@ class CGI
value[value.size - 1]
end
end
- }.join
+ }.to_s
end
# Generate a reset button Input element, as a String.
@@ -2314,15 +2266,15 @@ class CGI
Apache.request.setup_cgi_env
end
- (class << self; self; end).class_eval do
- const_set(:CGI_PARAMS, [1])
- const_set(:CGI_COOKIES, [2])
- end
-
extend QueryExtension
@multipart = false
-
- initialize_query() # set @params, @cookies
+ if defined?(CGI_PARAMS)
+ warn "do not use CGI_PARAMS and CGI_COOKIES"
+ @params = CGI_PARAMS.dup
+ @cookies = CGI_COOKIES.dup
+ else
+ initialize_query() # set @params, @cookies
+ end
@output_cookies = nil
@output_hidden = nil
diff --git a/lib/cgi/.document b/lib/cgi/.document
index 4153f97aa5..107f2f317c 100644
--- a/lib/cgi/.document
+++ b/lib/cgi/.document
@@ -1 +1,2 @@
-session.rb \ No newline at end of file
+session.rb
+
diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb
index d2a1be4aab..5568b28dce 100644
--- a/lib/cgi/session.rb
+++ b/lib/cgi/session.rb
@@ -183,7 +183,7 @@ class CGI
md5.update(String($$))
md5.update('foobar')
@new_session = true
- md5.hexdigest[0,16]
+ md5.hexdigest
end
private :create_new_id
@@ -359,7 +359,7 @@ class CGI
# on Unix systems).
# prefix:: the prefix to add to the session id when generating
# the filename for this session's FileStore file.
- # Defaults to "cgi_sid_".
+ # Defaults to the empty string.
# suffix:: the prefix to add to the session id when generating
# the filename for this session's FileStore file.
# Defaults to the empty string.
@@ -368,7 +368,7 @@ class CGI
# not exist, or opened if it does.
def initialize(session, option={})
dir = option['tmpdir'] || Dir::tmpdir
- prefix = option['prefix'] || 'cgi_sid_'
+ prefix = option['prefix'] || ''
suffix = option['suffix'] || ''
id = session.session_id
require 'digest/md5'
@@ -391,8 +391,9 @@ 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)
@@ -400,6 +401,7 @@ class CGI
end
ensure
f.close unless f.nil?
+ lockf.close if lockf
end
end
@hash
@@ -409,13 +411,17 @@ class CGI
def update
return unless @hash
begin
- f = File.open(@path, File::CREAT|File::TRUNC|File::RDWR, 0600)
- f.flock File::LOCK_EX
+ 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)
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 unless f.nil?
+ f.close if f and !f.closed?
+ lockf.close if lockf
end
end
@@ -426,6 +432,8 @@ 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
@@ -480,42 +488,5 @@ class CGI
GLOBAL_HASH_TABLE.delete(@session_id)
end
end
-
- # Dummy session storage class.
- #
- # Implements session storage place holder. No actual storage
- # will be done.
- class NullStore
- # Create a new NullStore instance.
- #
- # +session+ is the session this instance is associated with.
- # +option+ is a list of initialisation options. None are
- # currently recognised.
- def initialize(session, option=nil)
- end
-
- # Restore (empty) session state.
- def restore
- {}
- end
-
- # Update session state.
- #
- # A no-op.
- def update
- end
-
- # Close session storage.
- #
- # A no-op.
- def close
- end
-
- # Delete the session state.
- #
- # A no-op.
- def delete
- end
- end
end
end
diff --git a/lib/cgi/session/pstore.rb b/lib/cgi/session/pstore.rb
index 9a16a66b15..bd93d0a6ff 100644
--- a/lib/cgi/session/pstore.rb
+++ b/lib/cgi/session/pstore.rb
@@ -70,7 +70,7 @@ class CGI
def restore
unless @hash
@p.transaction do
- @hash = @p['hash'] || {}
+ @hash = @p['hash'] || {}
end
end
@hash
diff --git a/lib/complex.rb b/lib/complex.rb
index 516bbbfd89..9300f391e8 100644
--- a/lib/complex.rb
+++ b/lib/complex.rb
@@ -103,10 +103,6 @@ class Complex < Numeric
undef step
- def scalar?
- false
- end
-
def Complex.generic?(other) # :nodoc:
other.kind_of?(Integer) or
other.kind_of?(Float) or
@@ -309,8 +305,13 @@ class Complex < Numeric
Complex(@real, -@image)
end
alias conj conjugate
-
- undef <=>
+
+ #
+ # Compares the absolute values of the two numbers.
+ #
+ def <=> (other)
+ self.abs <=> other.abs
+ end
#
# Test for numerical equality (<tt>a == a + 0<i>i</i></tt>).
@@ -400,10 +401,10 @@ class Complex < Numeric
I = Complex(0,1)
# The real part of a complex number.
- attr_reader :real
+ attr :real
# The imaginary part of a complex number.
- attr_reader :image
+ attr :image
alias imag image
end
diff --git a/lib/csv.rb b/lib/csv.rb
index 536ed8af58..f6c12fa285 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -11,6 +11,21 @@
class CSV
class IllegalFormatError < RuntimeError; end
+ # deprecated
+ class Cell < String
+ def initialize(data = "", is_null = false)
+ super(is_null ? "" : data)
+ end
+
+ def data
+ to_s
+ end
+ end
+
+ # deprecated
+ class Row < Array
+ end
+
# Open a CSV formatted file for reading or writing.
#
# For reading.
@@ -98,6 +113,11 @@ class CSV
# Parse lines from given string or stream. Return rows as an Array of Arrays.
def CSV.parse(str_or_readable, fs = nil, rs = nil, &block)
+ if File.exist?(str_or_readable)
+ STDERR.puts("CSV.parse(filename) is deprecated." +
+ " Use CSV.open(filename, 'r') instead.")
+ return open_reader(str_or_readable, 'r', fs, rs, &block)
+ end
if block
CSV::Reader.parse(str_or_readable, fs, rs) do |row|
yield(row)
@@ -326,7 +346,7 @@ class CSV
rs_str = rs || "\n"
rs_size = rs_str.size
fs_idx = rs_idx = 0
- cell = ''
+ cell = Cell.new
state = :ST_START
quoted = cr = false
c = nil
@@ -599,7 +619,7 @@ class CSV
@rs = rs
@dev = CSV::IOBuf.new(@io)
@idx = 0
- if @dev[0, 3] == "\xef\xbb\xbf"
+ if @dev[0] == 0xef and @dev[1] == 0xbb and @dev[2] == 0xbf
@idx += 3
end
@close_on_terminate = false
diff --git a/lib/date.rb b/lib/date.rb
index bbfa5dc106..0dfe1bb06e 100644
--- a/lib/date.rb
+++ b/lib/date.rb
@@ -6,7 +6,7 @@
# Documentation: William Webber <william@williamwebber.com>
#
#--
-# $Id: date.rb,v 2.29 2006-11-05 18:21:29+09 tadf Exp $
+# $Id: date.rb,v 2.33 2007-12-22 14:41:34+09 tadf Exp $
#++
#
# == Overview
@@ -14,7 +14,7 @@
# This file provides two classes for working with
# dates and times.
#
-# The first class, Date, represents dates.
+# The first class, Date, represents dates.
# It works with years, months, weeks, and days.
# See the Date class documentation for more details.
#
@@ -80,7 +80,7 @@
# The standard civil year is 365 days long. However, the
# solar year is fractionally longer than this. To account
# for this, a *leap* *year* is occasionally inserted. This
-# is a year with 366 days, the extra day falling on February 29.
+# is a year with 366 days, the extra day falling on February 29.
# In the early days of the civil calendar, every fourth
# year without exception was a leap year. This way of
# reckoning leap years is the *Julian* *Calendar*.
@@ -148,7 +148,7 @@
# of time zones. Time zones are represented as an offset
# from UTC, as a fraction of a day. This offset is the
# how much local time is later (or earlier) than UTC.
-# UTC offset 0 is centred on England (also known as GMT).
+# UTC offset 0 is centred on England (also known as GMT).
# As you travel east, the offset increases until you
# reach the dateline in the middle of the Pacific Ocean;
# as you travel west, the offset decreases. This offset
@@ -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}.freeze
+ xs.each{|x| x.freeze unless x.nil?}.freeze
end
class Infinity < Numeric # :nodoc:
@@ -275,8 +275,8 @@ class Date
def <=> (other)
case other
- when Infinity; d <=> other.d
- when Numeric; d
+ when Infinity; return d <=> other.d
+ when Numeric; return d
else
begin
l, r = other.coerce(self)
@@ -323,6 +323,7 @@ class Date
# the answer is true; or it may a number representing the Day of
# Calendar Reform. Date::ENGLAND and Date::ITALY are two possible such
# days.
+
def self.julian? (jd, sg)
case sg
when Numeric
@@ -341,7 +342,7 @@ class Date
#
# The reverse of self.os? See the documentation for that method for
# more details.
- def self.gregorian? (jd, sg) not julian?(jd, sg) end
+ def self.gregorian? (jd, sg) !julian?(jd, sg) end
def self.fix_style(jd, sg) # :nodoc:
if julian?(jd, sg)
@@ -351,6 +352,29 @@ class Date
private_class_method :fix_style
+ # Convert an Ordinal Date to a Julian Day Number.
+ #
+ # +y+ and +d+ are the year and day-of-year to convert.
+ # +sg+ specifies the Day of Calendar Reform.
+ #
+ # Returns the corresponding Julian Day Number.
+ def self.ordinal_to_jd(y, d, sg=GREGORIAN)
+ civil_to_jd(y, 1, d, sg)
+ end
+
+ # Convert a Julian Day Number to an Ordinal Date.
+ #
+ # +jd+ is the Julian Day Number to convert.
+ # +sg+ specifies the Day of Calendar Reform.
+ #
+ # Returns the corresponding Ordinal Date as
+ # [year, day_of_year]
+ def self.jd_to_ordinal(jd, sg=GREGORIAN)
+ y = jd_to_civil(jd, sg)[0]
+ doy = jd - civil_to_jd(y - 1, 12, 31, fix_style(jd, sg))
+ return y, doy
+ end
+
# Convert a Civil Date to a Julian Day Number.
# +y+, +m+, and +d+ are the year, month, and day of the
# month. +sg+ specifies the Day of Calendar Reform.
@@ -400,27 +424,16 @@ class Date
return y, m, dom
end
- # Convert a Julian Day Number to an Ordinal Date.
- #
- # +jd+ is the Julian Day Number to convert.
- # +sg+ specifies the Day of Calendar Reform.
- #
- # Returns the corresponding Ordinal Date as
- # [year, day_of_year]
- def self.jd_to_ordinal(jd, sg=GREGORIAN)
- y = jd_to_civil(jd, sg)[0]
- doy = jd - civil_to_jd(y - 1, 12, 31, fix_style(jd, sg))
- return y, doy
- end
-
- # Convert an Ordinal Date to a Julian Day Number.
+ # Convert a Commercial Date to a Julian Day Number.
#
- # +y+ and +d+ are the year and day-of-year to convert.
+ # +y+, +w+, and +d+ are the (commercial) year, week of the year,
+ # and day of the week of the Commercial Date to convert.
# +sg+ specifies the Day of Calendar Reform.
- #
- # Returns the corresponding Julian Day Number.
- def self.ordinal_to_jd(y, d, sg=GREGORIAN)
- civil_to_jd(y, 1, d, sg)
+ def self.commercial_to_jd(y, w, d, ns=GREGORIAN)
+ jd = civil_to_jd(y, 1, 4, ns)
+ (jd - (((jd - 1) + 1) % 7)) +
+ 7 * (w - 1) +
+ (d - 1)
end
# Convert a Julian Day Number to a Commercial Date
@@ -436,39 +449,29 @@ class Date
y = if jd >= commercial_to_jd(a + 1, 1, 1, ns) then a + 1 else a end
w = 1 + ((jd - commercial_to_jd(y, 1, 1, ns)) / 7).floor
d = (jd + 1) % 7
- if d.zero? then d = 7 end
+ d = 7 if d == 0
return y, w, d
end
- # Convert a Commercial Date to a Julian Day Number.
- #
- # +y+, +w+, and +d+ are the (commercial) year, week of the year,
- # and day of the week of the Commercial Date to convert.
- # +sg+ specifies the Day of Calendar Reform.
- def self.commercial_to_jd(y, w, d, ns=GREGORIAN)
- jd = civil_to_jd(y, 1, 4, ns)
- (jd - (((jd - 1) + 1) % 7)) +
- 7 * (w - 1) +
- (d - 1)
+ def self.weeknum_to_jd(y, w, d, f=0, ns=GREGORIAN) # :nodoc:
+ a = civil_to_jd(y, 1, 1, ns) + 6
+ (a - ((a - f) + 1) % 7 - 7) + 7 * w + d
end
- def self.jd_to_weeknum(jd, k=0, sg=GREGORIAN) # :nodoc:
+ def self.jd_to_weeknum(jd, f=0, sg=GREGORIAN) # :nodoc:
ns = fix_style(jd, sg)
y, m, d = jd_to_civil(jd, ns)
a = civil_to_jd(y, 1, 1, ns) + 6
- w, d = (jd - (a - ((a - k) + 1) % 7) + 7).divmod(7)
+ w, d = (jd - (a - ((a - f) + 1) % 7) + 7).divmod(7)
return y, w, d
end
- def self.weeknum_to_jd(y, w, d, k=0, ns=GREGORIAN) # :nodoc:
- a = civil_to_jd(y, 1, 1, ns) + 6
- (a - ((a - k) + 1) % 7 - 7) + 7 * w + d
- end
+ private_class_method :weeknum_to_jd, :jd_to_weeknum
# Convert an Astronomical Julian Day Number to a (civil) Julian
# Day Number.
#
- # +ajd+ is the Astronomical Julian Day Number to convert.
+ # +ajd+ is the Astronomical Julian Day Number to convert.
# +of+ is the offset from UTC as a fraction of a day (defaults to 0).
#
# Returns the (civil) Julian Day Number as [day_number,
@@ -479,7 +482,7 @@ class Date
# Day Number.
#
# +jd+ is the Julian Day Number to convert, and +fr+ is a
- # fractional day.
+ # fractional day.
# +of+ is the offset from UTC as a fraction of a day (defaults to 0).
#
# Returns the Astronomical Julian Day Number as a single
@@ -539,10 +542,10 @@ class Date
#
# All years divisible by 4 are leap years in the Gregorian calendar,
# except for years divisible by 100 and not by 400.
- def self.gregorian_leap? (y) y % 4 == 0 and y % 100 != 0 or y % 400 == 0 end
+ def self.gregorian_leap? (y) y % 4 == 0 && y % 100 != 0 || y % 400 == 0 end
class << self; alias_method :leap?, :gregorian_leap? end
- class << self; alias_method :new0, :new end
+ class << self; alias_method :new!, :new end
# Is +jd+ a valid Julian Day Number?
#
@@ -550,16 +553,6 @@ class Date
# Julian Day Number.
def self.valid_jd? (jd, sg=ITALY) jd end
- # Create a new Date object from a Julian Day Number.
- #
- # +jd+ is the Julian Day Number; if not specified, it defaults to
- # 0.
- # +sg+ specifies the Day of Calendar Reform.
- def self.jd(jd=0, sg=ITALY)
- jd = valid_jd?(jd, sg)
- new0(jd_to_ajd(jd, 0, 0), 0, sg)
- end
-
# Do the year +y+ and day-of-year +d+ make a valid Ordinal Date?
# Returns the corresponding Julian Day Number if they do, or
# nil if they don't.
@@ -568,7 +561,7 @@ class Date
# from the end of the year (-1 being the last day of the year).
# No year wraparound is performed, however, so valid values of
# +d+ are -365 .. -1, 1 .. 365 on a non-leap-year,
- # -366 .. -1, 1 .. 366 on a leap year.
+ # -366 .. -1, 1 .. 366 on a leap year.
# A date falling in the period skipped in the Day of Calendar Reform
# adjustment is not valid.
#
@@ -587,23 +580,6 @@ class Date
jd
end
- # Create a new Date object from an Ordinal Date, specified
- # by year +y+ and day-of-year +d+. +d+ can be negative,
- # in which it counts backwards from the end of the year.
- # No year wraparound is performed, however. An invalid
- # value for +d+ results in an ArgumentError being raised.
- #
- # +y+ defaults to -4712, and +d+ to 1; this is Julian Day
- # Number day 0.
- #
- # +sg+ specifies the Day of Calendar Reform.
- def self.ordinal(y=-4712, d=1, sg=ITALY)
- unless jd = valid_ordinal?(y, d, sg)
- raise ArgumentError, 'invalid date'
- end
- new0(jd_to_ajd(jd, 0, 0), 0, sg)
- end
-
# Do year +y+, month +m+, and day-of-month +d+ make a
# valid Civil Date? Returns the corresponding Julian
# Day Number if they do, nil if they don't.
@@ -636,28 +612,6 @@ class Date
class << self; alias_method :valid_date?, :valid_civil? end
- # Create a new Date object for the Civil Date specified by
- # year +y+, month +m+, and day-of-month +d+.
- #
- # +m+ and +d+ can be negative, in which case they count
- # backwards from the end of the year and the end of the
- # month respectively. No wraparound is performed, however,
- # and invalid values cause an ArgumentError to be raised.
- # can be negative
- #
- # +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is
- # Julian Day Number day 0.
- #
- # +sg+ specifies the Day of Calendar Reform.
- def self.civil(y=-4712, m=1, d=1, sg=ITALY)
- unless jd = valid_civil?(y, m, d, sg)
- raise ArgumentError, 'invalid date'
- end
- new0(jd_to_ajd(jd, 0, 0), 0, sg)
- end
-
- class << self; alias_method :new, :civil end
-
# Do year +y+, week-of-year +w+, and day-of-week +d+ make a
# valid Commercial Date? Returns the corresponding Julian
# Day Number if they do, nil if they don't.
@@ -677,7 +631,10 @@ class Date
d += 8
end
if w < 0
- w = jd_to_commercial(commercial_to_jd(y + 1, 1, 1) + w * 7)[1]
+ ny, nw, nd =
+ jd_to_commercial(commercial_to_jd(y + 1, 1, 1) + w * 7)
+ return unless ny == y
+ w = nw
end
jd = commercial_to_jd(y, w, d)
return unless gregorian?(jd, sg)
@@ -685,6 +642,95 @@ class Date
jd
end
+ def self.valid_weeknum? (y, w, d, f, sg=ITALY) # :nodoc:
+ if d < 0
+ d += 7
+ end
+ if w < 0
+ ny, nw, nd, nf =
+ jd_to_weeknum(weeknum_to_jd(y + 1, 1, f, f) + w * 7, f)
+ return unless ny == y
+ w = nw
+ end
+ jd = weeknum_to_jd(y, w, d, f)
+ return unless gregorian?(jd, sg)
+ return unless [y, w, d] == jd_to_weeknum(jd, f)
+ jd
+ end
+
+ private_class_method :valid_weeknum?
+
+ # Do hour +h+, minute +min+, and second +s+ constitute a valid time?
+ #
+ # If they do, returns their value as a fraction of a day. If not,
+ # returns nil.
+ #
+ # The 24-hour clock is used. Negative values of +h+, +min+, and
+ # +sec+ are treating as counting backwards from the end of the
+ # next larger unit (e.g. a +min+ of -2 is treated as 58). No
+ # wraparound is performed.
+ def self.valid_time? (h, min, s)
+ h += 24 if h < 0
+ min += 60 if min < 0
+ s += 60 if s < 0
+ return unless ((0..23) === h &&
+ (0..59) === min &&
+ (0..59) === s) ||
+ (24 == h &&
+ 0 == min &&
+ 0 == s)
+ time_to_day_fraction(h, min, s)
+ end
+
+ # Create a new Date object from a Julian Day Number.
+ #
+ # +jd+ is the Julian Day Number; if not specified, it defaults to
+ # 0.
+ # +sg+ specifies the Day of Calendar Reform.
+ def self.jd(jd=0, sg=ITALY)
+ jd = valid_jd?(jd, sg)
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
+ end
+
+ # Create a new Date object from an Ordinal Date, specified
+ # by year +y+ and day-of-year +d+. +d+ can be negative,
+ # in which it counts backwards from the end of the year.
+ # No year wraparound is performed, however. An invalid
+ # value for +d+ results in an ArgumentError being raised.
+ #
+ # +y+ defaults to -4712, and +d+ to 1; this is Julian Day
+ # Number day 0.
+ #
+ # +sg+ specifies the Day of Calendar Reform.
+ def self.ordinal(y=-4712, d=1, sg=ITALY)
+ unless jd = valid_ordinal?(y, d, sg)
+ raise ArgumentError, 'invalid date'
+ end
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
+ end
+
+ # Create a new Date object for the Civil Date specified by
+ # year +y+, month +m+, and day-of-month +d+.
+ #
+ # +m+ and +d+ can be negative, in which case they count
+ # backwards from the end of the year and the end of the
+ # month respectively. No wraparound is performed, however,
+ # and invalid values cause an ArgumentError to be raised.
+ # can be negative
+ #
+ # +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is
+ # Julian Day Number day 0.
+ #
+ # +sg+ specifies the Day of Calendar Reform.
+ def self.civil(y=-4712, m=1, d=1, sg=ITALY)
+ unless jd = valid_civil?(y, m, d, sg)
+ raise ArgumentError, 'invalid date'
+ end
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
+ end
+
+ class << self; alias_method :new, :civil end
+
# Create a new Date object for the Commercial Date specified by
# year +y+, week-of-year +w+, and day-of-week +d+.
#
@@ -703,24 +749,19 @@ class Date
unless jd = valid_commercial?(y, w, d, sg)
raise ArgumentError, 'invalid date'
end
- new0(jd_to_ajd(jd, 0, 0), 0, sg)
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
end
- def self.valid_weeknum? (y, w, d, k, sg=ITALY) # :nodoc:
- if d < 0
- d += 7
- end
- if w < 0
- w = jd_to_weeknum(weeknum_to_jd(y + 1, 1, k, k) + w * 7, k)[1]
+ def self.weeknum(y=1582, w=41, d=5, f=0, sg=ITALY) # :nodoc:
+ unless jd = valid_weeknum?(y, w, d, f, sg)
+ raise ArgumentError, 'invalid date'
end
- jd = weeknum_to_jd(y, w, d, k)
- return unless [y, w, d] == jd_to_weeknum(jd, k)
- jd
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
end
- private_class_method :valid_weeknum?
+ private_class_method :weeknum
- def self.rewrite_hash(elem) # :nodoc:
+ def self.rewrite_frags(elem) # :nodoc:
elem ||= {}
if seconds = elem[:seconds]
d, fr = seconds.divmod(86400)
@@ -738,7 +779,9 @@ class Date
elem
end
- def self.complete_hash(elem) # :nodoc:
+ private_class_method :rewrite_frags
+
+ def self.complete_frags(elem) # :nodoc:
i = 0
g = [[:time, [:hour, :min, :sec]],
[nil, [:jd]],
@@ -767,14 +810,14 @@ class Date
when :civil
g[1].each do |e|
break if elem[e]
- elem[e] = d.__send!(e)
+ elem[e] = d.__send__(e)
end
elem[:mon] ||= 1
elem[:mday] ||= 1
when :commercial
g[1].each do |e|
break if elem[e]
- elem[e] = d.__send!(e)
+ elem[e] = d.__send__(e)
end
elem[:cweek] ||= 1
elem[:cwday] ||= 1
@@ -783,14 +826,14 @@ class Date
when :wnum0
g[1].each do |e|
break if elem[e]
- elem[e] = d.__send!(e)
+ elem[e] = d.__send__(e)
end
elem[:wnum0] ||= 0
elem[:wday] ||= 0
when :wnum1
g[1].each do |e|
break if elem[e]
- elem[e] = d.__send!(e)
+ elem[e] = d.__send__(e)
end
elem[:wnum1] ||= 0
elem[:wday] ||= 0
@@ -812,7 +855,9 @@ class Date
elem
end
- def self.valid_date_with_hash?(elem, sg) # :nodoc:
+ private_class_method :complete_frags
+
+ def self.valid_date_frags?(elem, sg) # :nodoc:
catch :jd do
a = elem.values_at(:jd)
if a.all?
@@ -870,17 +915,25 @@ class Date
end
end
- def self.new_with_hash(elem, sg) # :nodoc:
- elem = rewrite_hash(elem)
- elem = complete_hash(elem)
- unless jd = valid_date_with_hash?(elem, sg)
+ private_class_method :valid_date_frags?
+
+ def self.valid_time_frags? (elem) # :nodoc:
+ h, min, s = elem.values_at(:hour, :min, :sec)
+ valid_time?(h, min, s)
+ end
+
+ private_class_method :valid_time_frags?
+
+ def self.new_by_frags(elem, sg) # :nodoc:
+ elem = rewrite_frags(elem)
+ elem = complete_frags(elem)
+ unless jd = valid_date_frags?(elem, sg)
raise ArgumentError, 'invalid date'
end
- new0(jd_to_ajd(jd, 0, 0), 0, sg)
+ new!(jd_to_ajd(jd, 0, 0), 0, sg)
end
- private_class_method :rewrite_hash, :complete_hash,
- :valid_date_with_hash?, :new_with_hash
+ private_class_method :new_by_frags
# Create a new Date object by parsing from a String
# according to a specified format.
@@ -899,13 +952,13 @@ class Date
# parsed.
def self.strptime(str='-4712-01-01', fmt='%F', sg=ITALY)
elem = _strptime(str, fmt)
- new_with_hash(elem, sg)
+ new_by_frags(elem, sg)
end
# Create a new Date object by parsing from a String,
# without specifying the format.
#
- # +str+ is a String holding a date representation.
+ # +str+ is a String holding a date representation.
# +comp+ specifies whether to interpret 2-digit years
# as 19XX (>= 69) or 20XX (< 69); the default is not to.
# The method will attempt to parse a date from the String
@@ -919,7 +972,7 @@ class Date
# +sg+ specifies the Day of Calendar Reform.
def self.parse(str='-4712-01-01', comp=false, sg=ITALY)
elem = _parse(str, comp)
- new_with_hash(elem, sg)
+ new_by_frags(elem, sg)
end
class << self
@@ -940,7 +993,7 @@ class Date
end
- # *NOTE* this is the documentation for the method new0(). If
+ # *NOTE* this is the documentation for the method new!(). If
# you are reading this as the documentation for new(), that is
# because rdoc doesn't fully support the aliasing of the
# initialize() method.
@@ -993,8 +1046,8 @@ class Date
# Get the date as a Commercial Date, [year, week_of_year, day_of_week]
def commercial() self.class.jd_to_commercial(jd, @sg) end # :nodoc:
- def weeknum0() self.class.jd_to_weeknum(jd, 0, @sg) end # :nodoc:
- def weeknum1() self.class.jd_to_weeknum(jd, 1, @sg) end # :nodoc:
+ def weeknum0() self.class.__send__(:jd_to_weeknum, jd, 0, @sg) end # :nodoc:
+ def weeknum1() self.class.__send__(:jd_to_weeknum, jd, 1, @sg) end # :nodoc:
once :civil, :ordinal, :commercial, :weeknum0, :weeknum1
private :civil, :ordinal, :commercial, :weeknum0, :weeknum1
@@ -1039,7 +1092,8 @@ class Date
# Get the second of this date.
def sec() time[2] end
- # Get the fraction-of-a-second of this date.
+ # Get the fraction-of-a-second of this date. The unit is in days.
+ # I do NOT recommend you to use this method.
def sec_fraction() time[3] end
private :hour, :min, :sec, :sec_fraction
@@ -1071,11 +1125,11 @@ class Date
define_method(n.downcase + '?'){mon == i}
end
end
-=end
DAYNAMES.each_with_index do |n, i|
define_method(n.downcase + '?'){wday == i}
end
+=end
# Is the current date old-style (Julian Calendar)?
def julian? () self.class.julian?(jd, @sg) end
@@ -1105,7 +1159,7 @@ class Date
def start() @sg end
# Create a copy of this Date object using a new Day of Calendar Reform.
- def new_start(sg=self.class::ITALY) self.class.new0(@ajd, @of, sg) end
+ def new_start(sg=self.class::ITALY) self.class.new!(@ajd, @of, sg) end
# Create a copy of this Date object that uses the Italian/Catholic
# Day of Calendar Reform.
@@ -1129,7 +1183,7 @@ class Date
if String === of
of = (self.class.zone_to_diff(of) || 0).to_r/86400
end
- self.class.new0(@ajd, of, @sg)
+ self.class.new!(@ajd, of, @sg)
end
private :offset, :new_offset
@@ -1145,7 +1199,7 @@ class Date
# particular, two Dates cannot be added to each other.
def + (n)
case n
- when Numeric; return self.class.new0(@ajd + n, @of, @sg)
+ when Numeric; return self.class.new!(@ajd + n, @of, @sg)
end
raise TypeError, 'expected numeric'
end
@@ -1160,7 +1214,7 @@ class Date
# If +x+ is neither Numeric nor a Date, a TypeError is raised.
def - (x)
case x
- when Numeric; return self.class.new0(@ajd - x, @of, @sg)
+ when Numeric; return self.class.new!(@ajd - x, @of, @sg)
when Date; return @ajd - x.ajd
end
raise TypeError, 'expected numeric or date'
@@ -1200,7 +1254,9 @@ class Date
end
def next_day(n=1) self + n end
- def prev_day(n=1) self - n end
+# def prev_day(n=1) self - n end
+
+ private :next_day
# Return a new Date one day after this one.
def next() next_day end
@@ -1215,7 +1271,7 @@ class Date
# of the returned Date will be the last day of the target month.
def >> (n)
y, m = (year * 12 + (mon - 1) + n).divmod(12)
- m, = (m + 1).divmod(1)
+ m, = (m + 1) .divmod(1)
d = mday
d -= 1 until jd2 = self.class.valid_civil?(y, m, d, fix_style)
self + (jd2 - jd)
@@ -1229,22 +1285,26 @@ class Date
# of the returned Date will be the last day of the target month.
def << (n) self >> -n end
+=begin
def next_month(n=1) self >> n end
def prev_month(n=1) self << n end
def next_year(n=1) self >> n * 12 end
def prev_year(n=1) self << n * 12 end
+=end
- require 'enumerator'
+# require 'enumerator'
# Step the current date forward +step+ days at a
# time (or backward, if +step+ is negative) until
# we reach +limit+ (inclusive), yielding the resultant
# date at each step.
def step(limit, step=1) # :yield: date
+=begin
unless block_given?
return to_enum(:step, limit, step)
end
+=end
da = self
op = %w(- <= >=)[step <=> 0]
while da.__send__(op, limit)
@@ -1269,7 +1329,7 @@ class Date
# Is this Date equal to +other+?
#
# +other+ must both be a Date object, and represent the same date.
- def eql? (other) Date === other and self == other end
+ def eql? (other) Date === other && self == other end
# Calculate a hash value for this date.
def hash() @ajd.hash end
@@ -1285,7 +1345,7 @@ class Date
# Dump to Marshal format.
def _dump(limit) Marshal.dump([@ajd, @of, @sg], -1) end
-# def self._load(str) new0(*Marshal.load(str)) end
+# def self._load(str) new!(*Marshal.load(str)) end
# Load from Marshall format.
def self._load(str)
@@ -1297,7 +1357,7 @@ class Date
else
ajd, of, sg = a
end
- new0(ajd, of, sg)
+ new!(ajd, of, sg)
end
end
@@ -1332,7 +1392,8 @@ end
# === sec_fraction()
#
# Get the fraction of a second of the time. This is returned as
-# a +Rational+.
+# a +Rational+. The unit is in days.
+# I do NOT recommend you to use this method.
#
# === zone()
#
@@ -1352,35 +1413,6 @@ end
#
class DateTime < Date
- # Do hour +h+, minute +min+, and second +s+ constitute a valid time?
- #
- # If they do, returns their value as a fraction of a day. If not,
- # returns nil.
- #
- # The 24-hour clock is used. Negative values of +h+, +min+, and
- # +sec+ are treating as counting backwards from the end of the
- # next larger unit (e.g. a +min+ of -2 is treated as 58). No
- # wraparound is performed.
- def self.valid_time? (h, min, s)
- h += 24 if h < 0
- min += 60 if min < 0
- s += 60 if s < 0
- return unless ((0..23) === h and
- (0..59) === min and
- (0..59) === s) or
- (24 == h and
- 0 == min and
- 0 == s)
- time_to_day_fraction(h, min, s)
- end
-
- def self.valid_time_with_hash? (elem) # :nodoc:
- h, min, s = elem.values_at(:hour, :min, :sec)
- valid_time?(h, min, s)
- end
-
- private_class_method :valid_time_with_hash?
-
# Create a new DateTime object corresponding to the specified
# Julian Day Number +jd+ and hour +h+, minute +min+, second +s+.
#
@@ -1395,14 +1427,14 @@ class DateTime < Date
#
# All day/time values default to 0.
def self.jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY)
- unless (jd = valid_jd?(jd, sg)) and
+ unless (jd = valid_jd?(jd, sg)) &&
(fr = valid_time?(h, min, s))
raise ArgumentError, 'invalid date'
end
if String === of
of = (zone_to_diff(of) || 0).to_r/86400
end
- new0(jd_to_ajd(jd, fr, of), of, sg)
+ new!(jd_to_ajd(jd, fr, of), of, sg)
end
# Create a new DateTime object corresponding to the specified
@@ -1420,14 +1452,14 @@ class DateTime < Date
# +y+ defaults to -4712, and +d+ to 1; this is Julian Day Number
# day 0. The time values default to 0.
def self.ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
- unless (jd = valid_ordinal?(y, d, sg)) and
+ unless (jd = valid_ordinal?(y, d, sg)) &&
(fr = valid_time?(h, min, s))
raise ArgumentError, 'invalid date'
end
if String === of
of = (zone_to_diff(of) || 0).to_r/86400
end
- new0(jd_to_ajd(jd, fr, of), of, sg)
+ new!(jd_to_ajd(jd, fr, of), of, sg)
end
# Create a new DateTime object corresponding to the specified
@@ -1445,14 +1477,14 @@ class DateTime < Date
# +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is Julian Day
# Number day 0. The time values default to 0.
def self.civil(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
- unless (jd = valid_civil?(y, m, d, sg)) and
+ unless (jd = valid_civil?(y, m, d, sg)) &&
(fr = valid_time?(h, min, s))
raise ArgumentError, 'invalid date'
end
if String === of
of = (zone_to_diff(of) || 0).to_r/86400
end
- new0(jd_to_ajd(jd, fr, of), of, sg)
+ new!(jd_to_ajd(jd, fr, of), of, sg)
end
class << self; alias_method :new, :civil end
@@ -1473,31 +1505,44 @@ class DateTime < Date
# Calendar Reform for Italy and the Catholic countries.
# The time values default to 0.
def self.commercial(y=1582, w=41, d=5, h=0, min=0, s=0, of=0, sg=ITALY)
- unless (jd = valid_commercial?(y, w, d, sg)) and
+ unless (jd = valid_commercial?(y, w, d, sg)) &&
(fr = valid_time?(h, min, s))
raise ArgumentError, 'invalid date'
end
if String === of
of = (zone_to_diff(of) || 0).to_r/86400
end
- new0(jd_to_ajd(jd, fr, of), of, sg)
+ new!(jd_to_ajd(jd, fr, of), of, sg)
end
- def self.new_with_hash(elem, sg) # :nodoc:
- elem = rewrite_hash(elem)
- elem = complete_hash(elem)
- unless (jd = valid_date_with_hash?(elem, sg)) and
- (fr = valid_time_with_hash?(elem))
+ def self.weeknum(y=1582, w=41, d=5, f=0, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
+ unless (jd = valid_weeknum?(y, w, d, f, sg)) &&
+ (fr = valid_time?(h, min, s))
+ raise ArgumentError, 'invalid date'
+ end
+ if String === of
+ of = (zone_to_diff(of) || 0).to_r/86400
+ end
+ new!(jd_to_ajd(jd, fr, of), of, sg)
+ end
+
+ private_class_method :weeknum
+
+ def self.new_by_frags(elem, sg) # :nodoc:
+ elem = rewrite_frags(elem)
+ elem = complete_frags(elem)
+ unless (jd = valid_date_frags?(elem, sg)) &&
+ (fr = valid_time_frags?(elem))
raise ArgumentError, 'invalid date'
end
sf = (elem[:sec_fraction] || 0)
fr += sf/86400
of = (elem[:offset] || 0)
of = of.to_r/86400
- new0(jd_to_ajd(jd, fr, of), of, sg)
+ new!(jd_to_ajd(jd, fr, of), of, sg)
end
- private_class_method :new_with_hash
+ private_class_method :new_by_frags
# Create a new DateTime object by parsing from a String
# according to a specified format.
@@ -1515,13 +1560,13 @@ class DateTime < Date
# parsed.
def self.strptime(str='-4712-01-01T00:00:00+00:00', fmt='%FT%T%z', sg=ITALY)
elem = _strptime(str, fmt)
- new_with_hash(elem, sg)
+ new_by_frags(elem, sg)
end
# Create a new DateTime object by parsing from a String,
# without specifying the format.
#
- # +str+ is a String holding a date-time representation.
+ # +str+ is a String holding a date-time representation.
# +comp+ specifies whether to interpret 2-digit years
# as 19XX (>= 69) or 20XX (< 69); the default is not to.
# The method will attempt to parse a date-time from the String
@@ -1535,7 +1580,7 @@ class DateTime < Date
# +sg+ specifies the Day of Calendar Reform.
def self.parse(str='-4712-01-01T00:00:00+00:00', comp=false, sg=ITALY)
elem = _parse(str, comp)
- new_with_hash(elem, sg)
+ new_by_frags(elem, sg)
end
public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset
@@ -1544,11 +1589,11 @@ end
class Time
- def to_time() getlocal end
+# def to_time() getlocal end
def to_date
jd = Date.civil_to_jd(year, mon, mday, Date::ITALY)
- Date.new0(Date.jd_to_ajd(jd, 0, 0), 0, Date::ITALY)
+ Date.new!(Date.jd_to_ajd(jd, 0, 0), 0, Date::ITALY)
end
def to_datetime
@@ -1556,26 +1601,30 @@ class Time
fr = DateTime.time_to_day_fraction(hour, min, [sec, 59].min) +
usec.to_r/86400000000
of = utc_offset.to_r/86400
- DateTime.new0(DateTime.jd_to_ajd(jd, fr, of), of, DateTime::ITALY)
+ DateTime.new!(DateTime.jd_to_ajd(jd, fr, of), of, DateTime::ITALY)
end
+ private :to_date, :to_datetime
+
end
class Date
+=begin
def to_time() Time.local(year, mon, mday) end
def to_date() self end
- def to_datetime() DateTime.new0(self.class.jd_to_ajd(jd, 0, 0), @of, @sg) end
+ def to_datetime() DateTime.new!(self.class.jd_to_ajd(jd, 0, 0), @of, @sg) end
+=end
# Create a new Date object representing today.
#
# +sg+ specifies the Day of Calendar Reform.
- def self.today(sg=ITALY) Time.now.to_date .new_start(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) Time.now.to_datetime.new_start(sg) end
+ def self.now (sg=ITALY) Time.now.__send__(:to_datetime).new_start(sg) end
private_class_method :now
@@ -1583,6 +1632,7 @@ end
class DateTime < Date
+=begin
def to_time
d = new_offset(0)
d.instance_eval do
@@ -1592,8 +1642,9 @@ class DateTime < Date
getlocal
end
- def to_date() Date.new0(self.class.jd_to_ajd(jd, 0, 0), 0, @sg) end
+ def to_date() Date.new!(self.class.jd_to_ajd(jd, 0, 0), 0, @sg) end
def to_datetime() self end
+=end
private_class_method :today
public_class_method :now
@@ -1609,6 +1660,7 @@ class Date
%w(exist3? valid_date?),
%w(exist? valid_date?),
%w(existw? valid_commercial?),
+ %w(new0 new!),
%w(new1 jd),
%w(new2 ordinal),
%w(new3 new),
diff --git a/lib/date/format.rb b/lib/date/format.rb
index 14726b081c..6b082af40b 100644
--- a/lib/date/format.rb
+++ b/lib/date/format.rb
@@ -1,5 +1,5 @@
-# format.rb: Written by Tadayoshi Funaba 1999-2006
-# $Id: format.rb,v 2.28 2006-10-25 06:45:12+09 tadf Exp $
+# format.rb: Written by Tadayoshi Funaba 1999-2007
+# $Id: format.rb,v 2.30 2007-01-07 09:16:24+09 tadf Exp $
require 'rational'
@@ -96,23 +96,23 @@ class Date
class Bag # :nodoc:
+ def initialize
+ @elem = {}
+ end
+
def method_missing(t, *args, &block)
t = t.to_s
set = t.chomp!('=')
- t = '@' + t
+ t = t.intern
if set
- instance_variable_set(t, *args)
+ @elem[t] = args[0]
else
- if instance_variables.include?(t)
- instance_variable_get(t)
- end
+ @elem[t]
end
end
def to_hash
- instance_variables.
- select{|n| !instance_variable_get(n).nil?}.grep(/\A@[^_]/).
- inject({}){|r, n| r[n[1..-1].intern] = instance_variable_get(n); r}
+ @elem.reject{|k, v| /\A_/ =~ k.to_s || v.nil?}
end
end
@@ -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))).round, 3, f)
+ emit_n((sec_fraction / (1.to_r/86400/(10**3))).floor, 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))).round, 9, f)
+ emit_n((sec_fraction / (1.to_r/86400/(10**9))).floor, 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)
@@ -1078,6 +1078,8 @@ class DateTime < Date
super() + iso8601_timediv(n)
end
+ def rfc3339(n=0) iso8601(n) end
+
def jisx0301(n=0)
super() + iso8601_timediv(n)
end
diff --git a/lib/delegate.rb b/lib/delegate.rb
index a961cbaad3..ee5fe8d7fe 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -115,99 +115,77 @@
# implementation, see SimpleDelegator.
#
class Delegator
- preserved = ["__id__", "object_id", "__send__", "__send", "__send!", "respond_to?", "send", "funcall"]
- instance_methods.each do |m|
- next if preserved.include?(m)
- undef_method m
- end
- module MethodDelegation
- #
- # Pass in the _obj_ to delegate method calls to. All methods supported by
- # _obj_ will be delegated to.
- #
- def initialize(obj)
- __setobj__(obj)
+ #
+ # Pass in the _obj_ to delegate method calls to. All methods supported by
+ # _obj_ will be delegated to.
+ #
+ def initialize(obj)
+ preserved = ::Kernel.public_instance_methods(false)
+ preserved -= ["to_s","to_a","inspect","==","=~","==="]
+ for t in self.class.ancestors
+ preserved |= t.public_instance_methods(false)
+ preserved |= t.private_instance_methods(false)
+ preserved |= t.protected_instance_methods(false)
+ break if t == Delegator
end
-
- # Handles the magic of delegation through \_\_getobj\_\_.
- def method_missing(m, *args, &block)
+ preserved << "singleton_method_added"
+ for method in obj.methods
+ next if preserved.include? method
begin
- target = self.__getobj__
- unless target.respond_to?(m)
- super(m, *args, &block)
- else
- target.__send(m, *args, &block)
- end
- rescue Exception
- $@.delete_if{|s| /^#{__FILE__}:\d+:in `method_missing'$/ =~ s} #`
- ::Kernel::raise
+ eval <<-EOS
+ def self.#{method}(*args, &block)
+ begin
+ __getobj__.__send__(:#{method}, *args, &block)
+ rescue Exception
+ $@.delete_if{|s| /:in `__getobj__'$/ =~ s} #`
+ $@.delete_if{|s| /^\\(eval\\):/ =~ s}
+ Kernel::raise
+ end
+ end
+ EOS
+ rescue SyntaxError
+ raise NameError, "invalid identifier %s" % method, caller(4)
end
end
+ end
+ alias initialize_methods initialize
- #
- # Checks for a method provided by this the delegate object by fowarding the
- # call through \_\_getobj\_\_.
- #
- def respond_to?(m)
- return true if super
- return self.__getobj__.respond_to?(m)
- end
-
- #
- # Returns true if two objects are considered same.
- #
- def ==(obj)
- return true if obj.equal?(self)
- self.__getobj__ == obj
- end
-
- #
- # Returns true only if two objects are identical.
- #
- def equal?(obj)
- self.object_id == obj.object_id
- end
-
- #
- # This method must be overridden by subclasses and should return the object
- # method calls are being delegated to.
- #
- def __getobj__
- raise NotImplementedError, "need to define `__getobj__'"
+ # Handles the magic of delegation through \_\_getobj\_\_.
+ def method_missing(m, *args)
+ target = self.__getobj__
+ unless target.respond_to?(m)
+ super(m, *args)
end
+ target.__send__(m, *args)
+ end
- #
- # This method must be overridden by subclasses and change the object delegate
- # to _obj_.
- #
- def __setobj__(obj)
- raise NotImplementedError, "need to define `__setobj__'"
- end
+ #
+ # Checks for a method provided by this the delegate object by fowarding the
+ # call through \_\_getobj\_\_.
+ #
+ def respond_to?(m, include_private = false)
+ return true if super
+ return self.__getobj__.respond_to?(m, include_private)
+ end
- # Serialization support for the object returned by \_\_getobj\_\_.
- def marshal_dump
- __getobj__
- end
- # Reinitializes delegation from a serialized object.
- def marshal_load(obj)
- __setobj__(obj)
- end
+ #
+ # This method must be overridden by subclasses and should return the object
+ # method calls are being delegated to.
+ #
+ def __getobj__
+ raise NotImplementedError, "need to define `__getobj__'"
+ end
- # Clone support for the object returned by \_\_getobj\_\_.
- def clone
- new = super
- new.__setobj__(__getobj__.clone)
- new
- end
- # Duplication support for the object returned by \_\_getobj\_\_.
- def dup
- new = super
- new.__setobj__(__getobj__.dup)
- new
- end
+ # Serialization support for the object returned by \_\_getobj\_\_.
+ def marshal_dump
+ __getobj__
+ end
+ # Reinitializes delegation from a serialized object.
+ def marshal_load(obj)
+ initialize_methods(obj)
+ __setobj__(obj)
end
- include MethodDelegation
end
#
@@ -217,6 +195,13 @@ end
# \_\_setobj\_\_ .
#
class SimpleDelegator<Delegator
+
+ # Pass in the _obj_ you would like to delegate method calls to.
+ def initialize(obj)
+ super
+ @_sd_obj = obj
+ end
+
# Returns the current object method calls are being delegated to.
def __getobj__
@_sd_obj
@@ -240,6 +225,19 @@ class SimpleDelegator<Delegator
raise ArgumentError, "cannot delegate to self" if self.equal?(obj)
@_sd_obj = obj
end
+
+ # Clone support for the object returned by \_\_getobj\_\_.
+ def clone
+ new = super
+ new.__setobj__(__getobj__.clone)
+ new
+ end
+ # Duplication support for the object returned by \_\_getobj\_\_.
+ def dup
+ new = super
+ new.__setobj__(__getobj__.clone)
+ new
+ end
end
# :stopdoc:
@@ -261,13 +259,22 @@ SimpleDelegater = SimpleDelegator
def DelegateClass(superclass)
klass = Class.new
methods = superclass.public_instance_methods(true)
- methods -= [
- :__id__, :object_id, :__send__, :__send, :__send!, :respond_to?, :send, :funcall,
- :==, :equal?, :initialize, :method_missing, :__getobj__, :__setobj__,
- :clone, :dup, :marshal_dump, :marshal_load,
- ]
+ methods -= ::Kernel.public_instance_methods(false)
+ methods |= ["to_s","to_a","inspect","==","=~","==="]
klass.module_eval {
- include Delegator::MethodDelegation
+ def initialize(obj) # :nodoc:
+ @_dc_obj = obj
+ end
+ def method_missing(m, *args) # :nodoc:
+ unless @_dc_obj.respond_to?(m)
+ super(m, *args)
+ end
+ @_dc_obj.__send__(m, *args)
+ end
+ def respond_to?(m, include_private = false) # :nodoc:
+ return true if super
+ return @_dc_obj.respond_to?(m, include_private)
+ end
def __getobj__ # :nodoc:
@_dc_obj
end
@@ -275,13 +282,23 @@ def DelegateClass(superclass)
raise ArgumentError, "cannot delegate to self" if self.equal?(obj)
@_dc_obj = obj
end
+ def clone # :nodoc:
+ new = super
+ new.__setobj__(__getobj__.clone)
+ new
+ end
+ def dup # :nodoc:
+ new = super
+ new.__setobj__(__getobj__.clone)
+ new
+ end
}
for method in methods
begin
- klass.module_eval <<-EOS, __FILE__, __LINE__+1
+ klass.module_eval <<-EOS
def #{method}(*args, &block)
begin
- @_dc_obj.__send(:#{method}, *args, &block)
+ @_dc_obj.__send__(:#{method}, *args, &block)
rescue
$@[0,2] = nil
raise
@@ -308,23 +325,15 @@ if __FILE__ == $0
p ary.class
ary.push 25
p ary
- ary.push 42
- ary.each {|x| p x}
foo = Object.new
def foo.test
25
end
- def foo.iter
- yield self
- end
def foo.error
raise 'this is OK'
end
foo2 = SimpleDelegator.new(foo)
- p foo2
- foo2.instance_eval{print "foo\n"}
p foo.test == foo2.test # => true
- p foo2.iter{[55,true]} # => true
foo2.error # raise error!
end
diff --git a/lib/drb/acl.rb b/lib/drb/acl.rb
index aa86dbe70f..861c8a514d 100644
--- a/lib/drb/acl.rb
+++ b/lib/drb/acl.rb
@@ -13,6 +13,8 @@ class ACL
def initialize(str)
if str == '*' or str == 'all'
@pat = [:all]
+ elsif str.include?('*')
+ @pat = [:name, dot_pat(str)]
else
begin
@pat = [:ip, IPAddr.new(str)]
diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb
index 9690469e0c..25fbb3f788 100644
--- a/lib/drb/drb.rb
+++ b/lib/drb/drb.rb
@@ -6,9 +6,9 @@
# Copyright (c) 1999-2003 Masatoshi SEKI. You can redistribute it and/or
# modify it under the same terms as Ruby.
#
-# Author: Masatoshi SEKI
+# Author:: Masatoshi SEKI
#
-# Documentation: William Webber (william@williamwebber.com)
+# Documentation:: William Webber (william@williamwebber.com)
#
# == Overview
#
@@ -832,7 +832,7 @@ module DRb
begin
Socket::gethostbyname(host)[0]
rescue
- host
+ 'localhost'
end
end
@@ -972,7 +972,7 @@ module DRb
def initialize(option)
@option = option.to_s
end
- attr_reader :option
+ attr :option
def to_s; @option; end
def ==(other)
@@ -1496,7 +1496,7 @@ module DRb
if $SAFE < @safe_level
info = Thread.current['DRb']
if @block
- @result = Thread.new {
+ @result = Thread.new {
Thread.current['DRb'] = info
$SAFE = @safe_level
perform_with_block
@@ -1516,7 +1516,7 @@ module DRb
end
end
@succ = true
- if @msg_id == :to_ary
+ if @msg_id == :to_ary && @result.class == Array
@result = DRbArray.new(@result)
end
return @succ, @result
@@ -1552,7 +1552,7 @@ module DRb
end
ary.collect(&@obj)[0]
else
- @obj.funcall(@msg_id, *@argv)
+ @obj.__send__(@msg_id, *@argv)
end
end
diff --git a/lib/drb/extservm.rb b/lib/drb/extservm.rb
index 2715c5e9fe..7066f84c65 100644
--- a/lib/drb/extservm.rb
+++ b/lib/drb/extservm.rb
@@ -86,8 +86,11 @@ module DRb
@servers[name] = false
end
uri = @uri || DRb.uri
- Process.detach(Process.spawn("#{command} #{uri} #{name}"))
- true
+ if RUBY_PLATFORM =~ /mswin32/ && /NT/ =~ ENV["OS"]
+ system(%Q'cmd /c start "ruby" /b #{command} #{uri} #{name}')
+ else
+ system("#{command} #{uri} #{name} &")
+ end
end
end
end
diff --git a/lib/drb/invokemethod.rb b/lib/drb/invokemethod.rb
index 2bcd12f5f5..412b2ab9b5 100644
--- a/lib/drb/invokemethod.rb
+++ b/lib/drb/invokemethod.rb
@@ -9,7 +9,7 @@ module DRb
end
block_value = @block.call(*x)
end
-
+
def perform_with_block
@obj.__send__(@msg_id, *@argv) do |*x|
jump_error = nil
diff --git a/lib/drb/observer.rb b/lib/drb/observer.rb
index f2c3455e57..e7f1668c52 100644
--- a/lib/drb/observer.rb
+++ b/lib/drb/observer.rb
@@ -6,17 +6,16 @@ module DRb
def notify_observers(*arg)
if defined? @observer_state and @observer_state
- if defined? @observer_peers
- @observer_peers.delete_if do |k, v|
- begin
- k.send(v, *arg)
- false
- rescue
- true
- end
- end
- end
- @observer_state = false
+ if defined? @observer_peers
+ for i in @observer_peers.dup
+ begin
+ i.update(*arg)
+ rescue
+ delete_observer(i)
+ end
+ end
+ end
+ @observer_state = false
end
end
end
diff --git a/lib/drb/ssl.rb b/lib/drb/ssl.rb
index 1a0ac92960..58d6b7d1e0 100644
--- a/lib/drb/ssl.rb
+++ b/lib/drb/ssl.rb
@@ -180,7 +180,6 @@ module DRb
ssl = @config.accept(soc)
self.class.new(uri, ssl, @config, true)
rescue OpenSSL::SSL::SSLError
- soc.close
warn("#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})") if @config[:verbose]
retry
end
diff --git a/lib/drb/unix.rb b/lib/drb/unix.rb
index 989ec57eed..57feed8301 100644
--- a/lib/drb/unix.rb
+++ b/lib/drb/unix.rb
@@ -88,7 +88,7 @@ module DRb
public
def close
return unless @socket
- path = @socket.path
+ path = @socket.path if @server_mode
@socket.close
File.unlink(path) if @server_mode
@socket = nil
diff --git a/lib/e2mmap.rb b/lib/e2mmap.rb
index 00d4f83eb8..3e2604af5d 100644
--- a/lib/e2mmap.rb
+++ b/lib/e2mmap.rb
@@ -48,6 +48,8 @@
# Foo.Fail ExistingExceptionClass, arg...
#
#
+fail "Use Ruby 1.1" if VERSION < "1.1"
+
module Exception2MessageMapper
@RCS_ID='-$Id: e2mmap.rb,v 1.10 1999/02/17 12:33:17 keiju Exp keiju $-'
diff --git a/lib/erb.rb b/lib/erb.rb
index 02c96db83d..d7c72b4988 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -304,11 +304,11 @@ class ERB
def scan(&block)
@stag = nil
if @percent
- @src.each_line do |line|
+ @src.each do |line|
percent_line(line, &block)
end
else
- @src.each_line do |line|
+ @src.each do |line|
@scan_line.call(line, &block)
end
end
@@ -365,21 +365,22 @@ class ERB
end
end
- ExplicitTrimRegexp = /(^[ \t]*<%-)|(-%>\n?\z)|(<%-)|(-%>)|(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>)|(\n)/
def explicit_trim_line(line)
- 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
+ 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
end
ERB_STAG = %w(<%= <%# <%)
@@ -392,7 +393,7 @@ class ERB
class SimpleScanner < Scanner # :nodoc:
def scan
- @src.each_line do |line|
+ @src.each do |line|
line.split(SplitRegexp).each do |token|
next if token.empty?
yield(token)
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index 976b838838..3fdb6cbfe6 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -212,11 +212,11 @@ module FileUtils
stack.push path
path = File.dirname(path)
end
- stack.reverse_each do |dir|
+ stack.reverse_each do |path|
begin
- fu_mkdir dir, options[:mode]
+ fu_mkdir path, options[:mode]
rescue SystemCallError => err
- raise unless File.directory?(dir)
+ raise unless File.directory?(path)
end
end
end
@@ -418,6 +418,7 @@ module FileUtils
fu_check_options options, OPT_TABLE['cp_r']
fu_output_message "cp -r#{options[:preserve] ? 'p' : ''}#{options[:remove_destination] ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
return if options[:noop]
+ options[:dereference_root] = true unless options.key?(:dereference_root)
fu_each_src_dest(src, dest) do |s, d|
copy_entry s, d, options[:preserve], options[:dereference_root], options[:remove_destination]
end
@@ -504,7 +505,11 @@ module FileUtils
File.rename s, d
rescue Errno::EXDEV
copy_entry s, d, true
- File.unlink s
+ if options[:secure]
+ remove_entry_secure s, options[:force]
+ else
+ remove_entry s, options[:force]
+ end
end
rescue SystemCallError
raise unless options[:force]
@@ -517,7 +522,7 @@ module FileUtils
module_function :move
OPT_TABLE['mv'] =
- OPT_TABLE['move'] = [:force, :noop, :verbose]
+ OPT_TABLE['move'] = [:force, :noop, :verbose, :secure]
def rename_cannot_overwrite_file? #:nodoc:
/djgpp|cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
@@ -681,7 +686,7 @@ module FileUtils
end
# is a directory.
parent_st = File.stat(File.dirname(fullpath))
- unless parent_st.world_writable?
+ unless fu_world_writable?(parent_st)
remove_entry path, force
return
end
@@ -719,6 +724,11 @@ module FileUtils
end
module_function :remove_entry_secure
+ def fu_world_writable?(st)
+ (st.mode & 0002) != 0
+ end
+ private_module_function :fu_world_writable?
+
def fu_have_symlink? #:nodoc
File.symlink nil, nil
rescue NotImplementedError
@@ -1007,22 +1017,29 @@ module FileUtils
def touch(list, options = {})
fu_check_options options, OPT_TABLE['touch']
list = fu_list(list)
- fu_output_message "touch #{list.join ' '}" if options[:verbose]
+ created = nocreate = options[:nocreate]
+ t = options[:mtime]
+ if options[:verbose]
+ fu_output_message "touch #{nocreate ? ' -c' : ''}#{t ? t.strftime(' -t %Y%m%d%H%M.%S') : ''}#{list.join ' '}"
+ end
return if options[:noop]
- t = Time.now
list.each do |path|
+ created = nocreate
begin
File.utime(t, t, path)
rescue Errno::ENOENT
+ raise if created
File.open(path, 'a') {
;
}
+ created = true
+ retry if t
end
end
end
module_function :touch
- OPT_TABLE['touch'] = [:noop, :verbose]
+ OPT_TABLE['touch'] = [:noop, :verbose, :mtime, :nocreate]
private
@@ -1086,7 +1103,7 @@ module FileUtils
def path
if @path
- File.path(@path)
+ @path.to_str
else
join(@prefix, @rel)
end
@@ -1361,14 +1378,14 @@ module FileUtils
end
def join(dir, base)
- return File.path(dir) if not base or base == '.'
- return File.path(base) if not dir or dir == '.'
+ return dir.to_str if not base or base == '.'
+ return base.to_str if not dir or dir == '.'
File.join(dir, base)
end
end # class Entry_
def fu_list(arg) #:nodoc:
- [arg].flatten.map {|path| File.path(path) }
+ [arg].flatten.map {|path| path.to_str }
end
private_module_function :fu_list
@@ -1383,15 +1400,15 @@ module FileUtils
def fu_each_src_dest0(src, dest) #:nodoc:
if src.is_a?(Array)
src.each do |s|
- s = File.path(s)
+ s = s.to_str
yield s, File.join(dest, File.basename(s))
end
else
- src = File.path(src)
+ src = src.to_str
if File.directory?(dest)
yield src, File.join(dest, File.basename(src))
else
- yield src, File.path(dest)
+ yield src, dest.to_str
end
end
end
@@ -1492,8 +1509,8 @@ module FileUtils
OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt) }
end
- METHODS = singleton_methods() - [:private_module_function,
- :commands, :options, :have_option?, :options_of, :collect_method]
+ METHODS = singleton_methods() - %w( private_module_function
+ commands options have_option? options_of collect_method )
#
# This module has all methods of FileUtils module, but it outputs messages
diff --git a/lib/find.rb b/lib/find.rb
index 06ac9e2c0c..0d22dd62d6 100644
--- a/lib/find.rb
+++ b/lib/find.rb
@@ -33,7 +33,7 @@ module Find
# See the +Find+ module documentation for an example.
#
def find(*paths) # :yield: path
- paths.collect!{|d| raise Errno::ENOENT unless File.exist?(d); d.dup}
+ paths.collect!{|d| d.dup}
while file = paths.shift
catch(:prune) do
yield file.dup.taint
@@ -57,7 +57,7 @@ module Find
d.close
end
end
- rescue Errno::ENOENT, Errno::EACCES
+ rescue Errno::ENOENT, Errno::EACCES
end
end
end
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index 1889f44109..b6344cd4f6 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -1,18 +1,17 @@
+# = forwardable - Support for the Delegation Pattern
#
-# forwardable.rb -
-# $Release Version: 1.1$
-# $Revision$
-# $Date$
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
-# original definition by delegator.rb
-# Revised by Daniel J. Berger with suggestions from Florian Gross.
+# $Release Version: 1.1$
+# $Revision$
+# $Date$
+# by Keiju ISHITSUKA(keiju@ishitsuka.com)
#
-# Documentation by James Edward Gray II and Gavin Sinclair
+# Documentation by James Edward Gray II and Gavin Sinclair
#
# == Introduction
#
# This library allows you delegate method calls to an object, on a method by
-# method basis.
+# method basis. You can use Forwardable to setup this delegation at the class
+# level, or SingleForwardable to handle it at the object level.
#
# == Notes
#
@@ -71,10 +70,10 @@
# Ruby
# nil
#
-# Forwardable can be used to setup delegation at the object level as well.
+# === SingleForwardable
#
# printer = String.new
-# printer.extend Forwardable # prepare object for delegation
+# printer.extend SingleForwardable # prepare object for delegation
# printer.def_delegator "STDOUT", "puts" # add delegation for STDOUT.puts()
# printer.puts "Howdy!"
#
@@ -104,31 +103,15 @@
# # extend Forwardable, but we did that above
# def_delegators :@records, :size, :<<, :map
# end
-# f = Foo.new
-# f.printf ...
-# f.gets
-# f.content_at(1)
#
# Also see the example at forwardable.rb.
-
+#
module Forwardable
- FORWARDABLE_VERSION = "1.0.0"
-
- # Takes a hash as its argument. The key is a symbol or an array of
- # symbols. These symbols correspond to method names. The value is
- # the accessor to which the methods will be delegated.
- #
- # :call-seq:
- # delegate method => accessor
- # delegate [method, method, ...] => accessor
- #
- def delegate(hash)
- hash.each{ |methods, accessor|
- methods = methods.to_s unless methods.respond_to?(:each)
- methods.each{ |method|
- def_instance_delegator(accessor, method)
- }
- }
+
+ @debug = nil
+ class<<self
+ # force Forwardable to show up in stack backtraces of delegated methods
+ attr_accessor :debug
end
#
@@ -142,12 +125,12 @@ module Forwardable
# def_delegator :@records, :<<
# def_delegator :@records, :map
#
+ # See the examples at Forwardable and forwardable.rb.
+ #
def def_instance_delegators(accessor, *methods)
- methods.delete("__send__")
- methods.delete("__id__")
- methods.each{ |method|
+ for method in methods
def_instance_delegator(accessor, method)
- }
+ end
end
#
@@ -155,24 +138,81 @@ module Forwardable
# the method of the same name in _obj_). If _new_name_ is
# provided, it is used as the name for the delegate method.
#
+ # See the examples at Forwardable and forwardable.rb.
+ #
def def_instance_delegator(accessor, method, ali = method)
- str = %Q{
+ accessor = accessor.id2name if accessor.kind_of?(Integer)
+ method = method.id2name if method.kind_of?(Integer)
+ ali = ali.id2name if ali.kind_of?(Integer)
+
+ module_eval(<<-EOS, "(__FORWARDABLE__)", 1)
def #{ali}(*args, &block)
- #{accessor}.send(:#{method}, *args, &block)
+ begin
+ #{accessor}.__send__(:#{method}, *args, &block)
+ rescue Exception
+ $@.delete_if{|s| /^\\(__FORWARDABLE__\\):/ =~ s} unless Forwardable::debug
+ Kernel::raise
+ end
end
- }
-
- # If it's not a class or module, it's an instance
- begin
- module_eval(str)
- rescue
- instance_eval(str)
- end
+ EOS
end
alias def_delegators def_instance_delegators
alias def_delegator def_instance_delegator
end
-# compatibility
-SingleForwardable = Forwardable
+#
+# The SingleForwardable module provides delegation of specified
+# methods to a designated object, using the methods #def_delegator
+# and #def_delegators. This module is similar to Forwardable, but it works on
+# objects themselves, instead of their defining classes.
+#
+# Also see the example at forwardable.rb.
+#
+module SingleForwardable
+ #
+ # Shortcut for defining multiple delegator methods, but with no
+ # provision for using a different name. The following two code
+ # samples have the same effect:
+ #
+ # single_forwardable.def_delegators :@records, :size, :<<, :map
+ #
+ # single_forwardable.def_delegator :@records, :size
+ # single_forwardable.def_delegator :@records, :<<
+ # single_forwardable.def_delegator :@records, :map
+ #
+ # See the example at forwardable.rb.
+ #
+ def def_singleton_delegators(accessor, *methods)
+ for method in methods
+ def_singleton_delegator(accessor, method)
+ end
+ end
+
+ #
+ # Defines a method _method_ which delegates to _obj_ (i.e. it calls
+ # the method of the same name in _obj_). If _new_name_ is
+ # provided, it is used as the name for the delegate method.
+ #
+ # See the example at forwardable.rb.
+ #
+ def def_singleton_delegator(accessor, method, ali = method)
+ accessor = accessor.id2name if accessor.kind_of?(Integer)
+ method = method.id2name if method.kind_of?(Integer)
+ ali = ali.id2name if ali.kind_of?(Integer)
+
+ instance_eval(<<-EOS, "(__FORWARDABLE__)", 1)
+ def #{ali}(*args, &block)
+ begin
+ #{accessor}.__send__(:#{method}, *args,&block)
+ rescue Exception
+ $@.delete_if{|s| /^\\(__FORWARDABLE__\\):/ =~ s} unless Forwardable::debug
+ Kernel::raise
+ end
+ end
+ EOS
+ end
+
+ alias def_delegators def_singleton_delegators
+ alias def_delegator def_singleton_delegator
+end
diff --git a/lib/generator.rb b/lib/generator.rb
index c5282785b3..a010559b60 100644
--- a/lib/generator.rb
+++ b/lib/generator.rb
@@ -28,6 +28,9 @@
# Generator converts an internal iterator (i.e. an Enumerable object)
# to an external iterator.
#
+# Note that it is not very fast since it is implemented using
+# continuations, which are currently slow.
+#
# == Example
#
# require 'generator'
@@ -65,105 +68,99 @@ class Generator
# itself, and expected to call the +yield+ method for each element.
def initialize(enum = nil, &block)
if enum
- @block = proc{|g| enum.each{|value| g.yield value}}
+ @block = proc { |g|
+ enum.each { |x| g.yield x }
+ }
else
@block = block
end
+
@index = 0
@queue = []
- @main_thread = nil
- @loop_thread.kill if defined?(@loop_thread)
- @loop_thread = Thread.new do
- Thread.stop
- begin
- @block.call(self)
- rescue
- @main_thread.raise $!
- ensure
- @main_thread.wakeup
- end
+ @cont_next = @cont_yield = @cont_endp = nil
+
+ if @cont_next = callcc { |c| c }
+ @block.call(self)
+
+ @cont_endp.call(nil) if @cont_endp
end
- Thread.pass until @loop_thread.stop?
+
self
end
# Yields an element to the generator.
def yield(value)
- if Thread.current != @loop_thread
- raise "should be called in Generator.new{|g| ... }"
- end
- Thread.critical = true
- begin
+ if @cont_yield = callcc { |c| c }
@queue << value
- @main_thread.wakeup
- Thread.stop
- ensure
- Thread.critical = false
+ @cont_next.call(nil)
end
+
self
end
# Returns true if the generator has reached the end.
- def end?
- if @queue.empty?
- if @main_thread
- raise "should not be called in Generator.new{|g| ... }"
- end
- Thread.critical = true
- begin
- @main_thread = Thread.current
- @loop_thread.wakeup
- Thread.stop
- rescue ThreadError
- # ignore
- ensure
- @main_thread = nil
- Thread.critical = false
- end
+ def end?()
+ if @cont_endp = callcc { |c| c }
+ @cont_yield.nil? && @queue.empty?
+ else
+ @queue.empty?
end
- @queue.empty?
end
# Returns true if the generator has not reached the end yet.
- def next?
+ def next?()
!end?
end
# Returns the current index (position) counting from zero.
- def index
+ def index()
@index
end
# Returns the current index (position) counting from zero.
- def pos
+ def pos()
@index
end
# Returns the element at the current position and moves forward.
- def next
- raise EOFError.new("no more elements available") if end?
+ def next()
+ if end?
+ raise EOFError, "no more elements available"
+ end
+
+ if @cont_next = callcc { |c| c }
+ @cont_yield.call(nil) if @cont_yield
+ end
+
@index += 1
+
@queue.shift
end
# Returns the element at the current position.
- def current
- raise EOFError.new("no more elements available") if end?
+ def current()
+ if @queue.empty?
+ raise EOFError, "no more elements available"
+ end
+
@queue.first
end
# Rewinds the generator.
- def rewind
+ def rewind()
initialize(nil, &@block) if @index.nonzero?
+
self
end
# Rewinds the generator and enumerates the elements.
def each
rewind
+
until end?
yield self.next
end
+
self
end
end
diff --git a/lib/getoptlong.rb b/lib/getoptlong.rb
index 880883a981..4d004419b1 100644
--- a/lib/getoptlong.rb
+++ b/lib/getoptlong.rb
@@ -111,7 +111,7 @@ class GetoptLong
# Error types.
#
class Error < StandardError; end
- class AmbiguousOption < Error; end
+ class AmbigousOption < Error; end
class NeedlessArgument < Error; end
class MissingArgument < Error; end
class InvalidOption < Error; end
@@ -289,7 +289,14 @@ class GetoptLong
@canonical_names.clear
@argument_flags.clear
- arguments.each do |*arg|
+ arguments.each do |arg|
+ #
+ # Each argument must be an Array.
+ #
+ if !arg.is_a?(Array)
+ raise ArgumentError, "the option list contains non-Array argument"
+ end
+
#
# Find an argument flag and it set to `argument_flag'.
#
@@ -381,7 +388,7 @@ class GetoptLong
end
#
- # Set an error (a protected method).
+ # Set an error (protected).
#
def set_error(type, message)
$deferr.print("#{$0}: #{message}\n") if !@quiet
@@ -490,16 +497,16 @@ class GetoptLong
# The option `option_name' is not registered in `@canonical_names'.
# It may be an abbreviated.
#
- matches = []
+ match_count = 0
@canonical_names.each_key do |key|
if key.index(pattern) == 0
option_name = key
- matches << key
+ match_count += 1
end
end
- if 2 <= matches.length
- set_error(AmbiguousOption, "option `#{argument}' is ambiguous between #{matches.join(', ')}")
- elsif matches.length == 0
+ if 2 <= match_count
+ set_error(AmbigousOption, "option `#{argument}' is ambiguous")
+ elsif match_count == 0
set_error(InvalidOption, "unrecognized option `#{argument}'")
end
end
diff --git a/lib/getopts.rb b/lib/getopts.rb
index 4f39ca995a..7124269351 100644
--- a/lib/getopts.rb
+++ b/lib/getopts.rb
@@ -15,7 +15,7 @@
# rewritten by Akinori MUSHA <knu@ruby-lang.org>
#
-warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: getopts is deprecated after Ruby 1.8.1; use optparse instead" if caller[0]
+warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: getopts is deprecated after Ruby 1.8.1; use optparse instead" if caller[0] and $VERBOSE
$RCS_ID=%q$Header$
diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb
index cb15fb50dd..1801d9d86f 100644
--- a/lib/ipaddr.rb
+++ b/lib/ipaddr.rb
@@ -83,7 +83,7 @@ class IPAddr
IN6FORMAT = (["%.4x"] * 8).join(':')
# Returns the address family of this IP address.
- attr_reader :family
+ attr :family
# Creates a new ipaddr containing the given network byte ordered
# string form of an IP address.
@@ -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 1fb4397e68..7580e39d43 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -149,10 +149,15 @@ module IRB
line.untaint
@context.evaluate(line, line_no)
output_value if @context.echo?
- rescue StandardError, ScriptError, Abort
- $! = RuntimeError.new("unknown exception raised") unless $!
- print $!.class, ": ", $!, "\n"
- if $@[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && $!.class.to_s !~ /^IRB/
+ 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/
irb_bug = true
else
irb_bug = false
@@ -161,7 +166,7 @@ module IRB
messages = []
lasts = []
levels = 0
- for m in $@
+ for m in exc.backtrace
m = @context.workspace.filter_backtrace(m) unless irb_bug
if m
if messages.size < @context.back_trace_limit
@@ -183,8 +188,7 @@ module IRB
print "Maybe IRB bug!!\n" if irb_bug
end
if $SAFE > 2
- warn "Error: irb does not work for $SAFE level higher than 2"
- exit 1
+ abort "Error: irb does not work for $SAFE level higher than 2"
end
end
end
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index 0fd54ee806..db22ca639b 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -206,7 +206,7 @@ module IRB
begin
load rc_file
rescue LoadError, Errno::ENOENT
- rescue # StandardError, ScriptError
+ rescue
print "load error: #{rc_file}\n"
print $!.class, ": ", $!, "\n"
for err in $@[0, $@.size - 2]
@@ -233,7 +233,7 @@ module IRB
# enumerate possible rc-file base name generators
def IRB.rc_file_generators
if irbrc = ENV["IRBRC"]
- yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
+ yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
end
if home = ENV["HOME"]
yield proc{|rc| home+"/.irb#{rc}"}
@@ -250,7 +250,7 @@ module IRB
for m in @CONF[:LOAD_MODULES]
begin
require m
- rescue # StandardError, ScriptError
+ rescue
print $@[0], ":", $!.class, ": ", $!, "\n"
end
end
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index a0fa359d3a..bfb90fa59a 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -94,10 +94,8 @@ module IRB
end
def gets
- Readline.input = STDIN
- Readline.output = STDOUT
if l = readline(@prompt, false)
- HISTORY.push(l) if !l.empty?
+ HISTORY.push(l) if !l.empty?
@line[@line_no += 1] = l + "\n"
else
@eof = true
diff --git a/lib/irb/locale.rb b/lib/irb/locale.rb
index 4b6aba2bb9..5ed9f54507 100644
--- a/lib/irb/locale.rb
+++ b/lib/irb/locale.rb
@@ -71,7 +71,7 @@ module IRB
end
def puts(*opts)
- ary = opts.collect{|opt| String(opts)}
+ ary = opts.collect{|opt| String(opt)}
super(*ary)
end
@@ -153,8 +153,8 @@ module IRB
end
def search_file(path, file)
- if File.exists?(p1 = path + lc_path(file, "C"))
- if File.exists?(p2 = path + lc_path(file))
+ if File.exist?(p1 = path + lc_path(file, "C"))
+ if File.exist?(p2 = path + lc_path(file))
return p2
else
end
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index d8442f305b..ab584d5253 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -104,7 +104,6 @@ class RubyLex
@rests.push nil unless buf_input
end
c = @rests.shift
- return if c == nil
if @here_header
@here_readed.push c
else
@@ -235,6 +234,7 @@ class RubyLex
unless l = lex
throw :TERM_INPUT if @line == ''
else
+ #p l
@line.concat l
if @ltype or @continue or @indent > 0
next
diff --git a/lib/irb/ruby-token.rb b/lib/irb/ruby-token.rb
index 0a297d28fa..525d4df14c 100644
--- a/lib/irb/ruby-token.rb
+++ b/lib/irb/ruby-token.rb
@@ -29,7 +29,9 @@ module RubyToken
@line_no = line_no
@char_no = char_no
end
- attr :seek, :line_no, :char_no
+ attr :seek
+ attr :line_no
+ attr :char_no
end
class TkNode < Token
@@ -56,7 +58,7 @@ module RubyToken
end
class TkOp < Token
- attr_accessor :name
+ attr :name, true
end
class TkOPASGN < TkOp
diff --git a/lib/irb/slex.rb b/lib/irb/slex.rb
index 866bf30a5c..a6ea6fb473 100644
--- a/lib/irb/slex.rb
+++ b/lib/irb/slex.rb
@@ -245,6 +245,8 @@ module IRB
end
end
+SLex=IRB::SLex
+
if $0 == __FILE__
# Tracer.on
case $1
diff --git a/lib/jcode.rb b/lib/jcode.rb
index f486efd79c..78422f296f 100644
--- a/lib/jcode.rb
+++ b/lib/jcode.rb
@@ -79,12 +79,9 @@ class String
reg = end_regexp
if $KCODE != 'NONE' && self =~ reg
succ_table = SUCC[$KCODE[0,1].downcase]
- last1 = self[-1].ord
- last2 = self[-2].ord
begin
- last1 += succ_table[last1]
- last2 += 1 if last1 == 0
- self[-2..-1] = [last2, last1].pack("C*")
+ self[-1] += succ_table[self[-1]]
+ self[-2] += 1 if self[-1] == 0
end while self !~ reg
self
else
@@ -93,7 +90,8 @@ class String
end
def succ
- (str = self.dup).succ! or str
+ str = self.dup
+ str.succ! or str
end
private
@@ -191,15 +189,6 @@ class String
(str = self.dup).tr_s!(from,to) or str
end
- def reverse
- self.split(//).reverse.join
- end
-
- def reverse!
- self.replace(self.reverse)
- self
- end
-
def chop!
self.gsub!(/(?:.|\r?\n)\z/, '')
end
diff --git a/lib/logger.rb b/lib/logger.rb
index ffe0422a70..60e72424ad 100644
--- a/lib/logger.rb
+++ b/lib/logger.rb
@@ -143,7 +143,7 @@ require 'monitor'
# 2. Log4r (somewhat) compatible interface.
#
# logger.level = Logger::INFO
-#
+#
# DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
#
#
diff --git a/lib/mathn.rb b/lib/mathn.rb
index 84c0b4704d..a5a121c6c6 100644
--- a/lib/mathn.rb
+++ b/lib/mathn.rb
@@ -16,6 +16,24 @@ require "matrix.rb"
class Integer
+ def gcd2(int)
+ a = self.abs
+ b = int.abs
+ a, b = b, a if a < b
+
+ pd_a = a.prime_division
+ pd_b = b.prime_division
+
+ gcd = 1
+ for pair in pd_a
+ as = pd_b.assoc(pair[0])
+ if as
+ gcd *= as[0] ** [as[1], pair[1]].min
+ end
+ end
+ return gcd
+ end
+
def Integer.from_prime_division(pd)
value = 1
for prime, index in pd
@@ -50,54 +68,34 @@ end
class Prime
include Enumerable
- # These are included as class variables to cache them for later uses. If memory
- # usage is a problem, they can be put in Prime#initialize as instance variables.
- # There must be no primes between @@primes[-1] and @@next_to_check.
- @@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
- # @@next_to_check % 6 must be 1.
- @@next_to_check = 103 # @@primes[-1] - @@primes[-1] % 6 + 7
- @@ulticheck_index = 3 # @@primes.index(@@primes.reverse.find {|n|
- # n < Math.sqrt(@@next_to_check) })
- @@ulticheck_next_squared = 121 # @@primes[@@ulticheck_index + 1] ** 2
-
- class << self
- # Return the prime cache.
- def cache
- return @@primes
- end
- alias primes cache
- alias primes_so_far cache
- end
-
def initialize
- @index = -1
- end
-
- # Return primes given by this instance so far.
- def primes
- return @@primes[0, @index + 1]
+ @seed = 1
+ @primes = []
+ @counts = []
end
- alias primes_so_far primes
def succ
- @index += 1
- while @index >= @@primes.length
- # Only check for prime factors up to the square root of the potential primes,
- # but without the performance hit of an actual square root calculation.
- if @@next_to_check + 4 > @@ulticheck_next_squared
- @@ulticheck_index += 1
- @@ulticheck_next_squared = @@primes.at(@@ulticheck_index + 1) ** 2
+ i = -1
+ size = @primes.size
+ while i < size
+ if i == -1
+ @seed += 1
+ i += 1
+ else
+ while @seed > @counts[i]
+ @counts[i] += @primes[i]
+ end
+ if @seed != @counts[i]
+ i += 1
+ else
+ i = -1
+ end
end
- # Only check numbers congruent to one and five, modulo six. All others
- # are divisible by two or three. This also allows us to skip checking against
- # two and three.
- @@primes.push @@next_to_check if @@primes[2..@@ulticheck_index].find {|prime| @@next_to_check % prime == 0 }.nil?
- @@next_to_check += 4
- @@primes.push @@next_to_check if @@primes[2..@@ulticheck_index].find {|prime| @@next_to_check % prime == 0 }.nil?
- @@next_to_check += 2
end
- return @@primes[@index]
+ @primes.push @seed
+ @counts.push @seed + @seed
+ return @seed
end
alias next succ
@@ -109,19 +107,16 @@ class Prime
end
class Fixnum
- remove_method :/
alias / quo
end
class Bignum
- remove_method :/
alias / quo
end
class Rational
Unify = true
- remove_method :inspect
def inspect
format "%s/%s", numerator.inspect, denominator.inspect
end
@@ -235,7 +230,6 @@ class Rational
end
module Math
- remove_method(:sqrt)
def sqrt(a)
if a.kind_of?(Complex)
abs = sqrt(a.real*a.real + a.image*a.image)
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 2f70de419e..c62acdf9aa 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -1,9 +1,9 @@
#!/usr/local/bin/ruby
#--
# matrix.rb -
-# $Release Version: 1.0$
-# $Revision: 1.13 $
-# $Date: 2001/12/09 14:22:23 $
+# $Release Version: 1.0$
+# $Revision: 1.11 $
+# $Date: 1999/10/06 11:01:53 $
# Original Version from Smalltalk-80 version
# on July 23, 1985 at 8:37:17 am
# by Keiju ISHITSUKA
@@ -105,7 +105,7 @@ end
# * <tt> #inspect </tt>
#
class Matrix
- @RCS_ID='-$Id: matrix.rb,v 1.13 2001/12/09 14:22:23 keiju Exp keiju $-'
+ @RCS_ID='-$Id: matrix.rb,v 1.11 1999/10/06 11:01:53 keiju Exp keiju $-'
# extend Exception2MessageMapper
include ExceptionForMatrix
@@ -246,7 +246,7 @@ class Matrix
# use to general users.
#
def initialize(init_method, *argv)
- self.funcall(init_method, *argv)
+ self.send(init_method, *argv)
end
def init_rows(rows, copy)
@@ -265,15 +265,6 @@ class Matrix
def [](i, j)
@rows[i][j]
end
- alias element []
- alias component []
-
- def []=(i, j, v)
- @rows[i][j] = v
- end
- alias set_element []=
- alias set_component []=
- private :[]=, :set_element, :set_component
#
# Returns the number of rows.
@@ -329,7 +320,7 @@ class Matrix
#
# Returns a matrix that is the result of iteration of the given block over all
# elements of the matrix.
- # Matrix[ [1,2], [3,4] ].collect { |e| e**2 }
+ # Matrix[ [1,2], [3,4] ].collect { |i| i**2 }
# => 1 4
# 9 16
#
@@ -611,7 +602,7 @@ class Matrix
for i in 0 .. size
next if i == k
- q = a[i][k].quo(akk)
+ q = a[i][k] / akk
a[i][k] = 0
(k + 1).upto(size) do
@@ -626,11 +617,11 @@ class Matrix
(k + 1).upto(size) do
|j|
- a[k][j] = a[k][j].quo(akk)
+ a[k][j] /= akk
end
0.upto(size) do
|j|
- @rows[k][j] = @rows[k][j].quo(akk)
+ @rows[k][j] /= akk
end
end
self
@@ -677,13 +668,9 @@ class Matrix
#
# Returns the determinant of the matrix. If the matrix is not square, the
- # result is 0. This method's algorism is Gaussian elimination method
- # and using Numeric#quo(). Beware that using Float values, with their
- # usual lack of precision, can affect the value returned by this method. Use
- # Rational values or Matrix#det_e instead if this is important to you.
- #
+ # result is 0.
# Matrix[[7,6], [3,9]].determinant
- # => 63.0
+ # => 63
#
def determinant
return 0 unless square?
@@ -705,7 +692,7 @@ class Matrix
end
(k + 1).upto(size) do
|i|
- q = a[i][k].quo(akk)
+ q = a[i][k] / akk
(k + 1).upto(size) do
|j|
a[i][j] -= a[k][j] * q
@@ -716,56 +703,11 @@ class Matrix
det
end
alias det determinant
-
- #
- # Returns the determinant of the matrix. If the matrix is not square, the
- # result is 0. This method's algorism is Gaussian elimination method.
- # This method uses Euclidean algorism. If all elements are integer,
- # really exact value. But, if an element is a float, can't return
- # exact value.
- #
- # Matrix[[7,6], [3,9]].determinant
- # => 63
- #
- def determinant_e
- return 0 unless square?
-
- size = row_size - 1
- a = to_a
-
- det = 1
- k = 0
- begin
- if a[k][k].zero?
- i = k
- begin
- return 0 if (i += 1) > size
- end while a[i][k].zero?
- a[i], a[k] = a[k], a[i]
- det *= -1
- end
- (k + 1).upto(size) do |i|
- q = a[i][k] / a[k][k]
- k.upto(size) do |j|
- a[i][j] -= a[k][j] * q
- end
- unless a[i][k].zero?
- a[i], a[k] = a[k], a[i]
- det *= -1
- redo
- end
- end
- det *= a[k][k]
- end while (k += 1) <= size
- det
- end
- alias det_e determinant_e
-
- #
- # Returns the rank of the matrix. Beware that using Float values,
- # probably return faild value. Use Rational values or Matrix#rank_e
- # for getting exact result.
+
#
+ # Returns the rank of the matrix. Beware that using Float values, with their
+ # usual lack of precision, can affect the value returned by this method. Use
+ # Rational values instead if this is important to you.
# Matrix[[7,6], [3,9]].rank
# => 2
#
@@ -816,7 +758,7 @@ class Matrix
end
(k + 1).upto(a_row_size - 1) do
|i|
- q = a[i][k].quo(akk)
+ q = a[i][k] / akk
(k + 1).upto(a_column_size - 1) do
|j|
a[i][j] -= a[k][j] * q
@@ -828,41 +770,6 @@ class Matrix
end
#
- # Returns the rank of the matrix. This method uses Euclidean
- # algorism. If all elements are integer, really exact value. But, if
- # an element is a float, can't return exact value.
- #
- # Matrix[[7,6], [3,9]].rank
- # => 2
- #
- def rank_e
- a = to_a
- a_column_size = column_size
- a_row_size = row_size
- pi = 0
- (0 ... a_column_size).each do |j|
- if i = (pi ... a_row_size).find{|i0| !a[i0][j].zero?}
- if i != pi
- a[pi], a[i] = a[i], a[pi]
- end
- (pi + 1 ... a_row_size).each do |k|
- q = a[k][j] / a[pi][j]
- (pi ... a_column_size).each do |j0|
- a[k][j0] -= q * a[pi][j0]
- end
- if k > pi && !a[k][j].zero?
- a[k], a[pi] = a[pi], a[k]
- redo
- end
- end
- pi += 1
- end
- end
- pi
- end
-
-
- #
# Returns the trace (sum of diagonal elements) of the matrix.
# Matrix[[7,6], [3,9]].trace
# => 16
@@ -937,18 +844,6 @@ class Matrix
@rows.collect{|row| row.collect{|e| e}}
end
- def elements_to_f
- collect{|e| e.to_f}
- end
-
- def elements_to_i
- collect{|e| e.to_i}
- end
-
- def elements_to_r
- collect{|e| e.to_r}
- end
-
#--
# PRINTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#++
@@ -1027,10 +922,10 @@ class Matrix
when Vector
Scalar.Raise WrongArgType, other.class, "Numeric or Scalar or Matrix"
when Matrix
- self * other.inverse
+ self * _M.inverse
else
x, y = other.coerce(self)
- x.quo(y)
+ x / y
end
end
@@ -1139,15 +1034,6 @@ class Vector
def [](i)
@elements[i]
end
- alias element []
- alias component []
-
- def []=(i, v)
- @elements[i]= v
- end
- alias set_element []=
- alias set_component []=
- private :[]=, :set_element, :set_component
#
# Returns the number of elements in the vector.
@@ -1350,18 +1236,6 @@ class Vector
@elements.dup
end
- def elements_to_f
- collect{|e| e.to_f}
- end
-
- def elements_to_i
- collect{|e| e.to_i}
- end
-
- def elements_to_r
- collect{|e| e.to_r}
- end
-
#
# FIXME: describe Vector#coerce.
#
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index d24a407f9f..31f4878b8b 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -5,7 +5,7 @@ require 'rbconfig'
require 'fileutils'
require 'shellwords'
-CONFIG = RbConfig::MAKEFILE_CONFIG
+CONFIG = Config::MAKEFILE_CONFIG
ORIG_LIBPATH = ENV['LIB']
CXX_EXT = %w[cc cxx cpp]
@@ -108,16 +108,16 @@ end
def map_dir(dir, map = nil)
map ||= INSTALL_DIRS
- map.inject(dir) {|d, (orig, new)| d.gsub(orig, new)}
+ map.inject(dir) {|dir, (orig, new)| dir.gsub(orig, new)}
end
topdir = File.dirname(libdir = File.dirname(__FILE__))
extdir = File.expand_path("ext", topdir)
$extmk = File.expand_path($0)[0, extdir.size+1] == extdir+"/"
-if not $extmk and File.exist?(RbConfig::CONFIG["archdir"] + "/ruby.h")
- $hdrdir = $topdir = RbConfig::CONFIG["archdir"]
+if not $extmk and File.exist?(Config::CONFIG["archdir"] + "/ruby.h")
+ $hdrdir = $topdir = Config::CONFIG["archdir"]
elsif File.exist?(($top_srcdir ||= topdir) + "/ruby.h") and
- File.exist?(($topdir ||= RbConfig::CONFIG["topdir"]) + "/config.h")
+ File.exist?(($topdir ||= Config::CONFIG["topdir"]) + "/config.h")
$hdrdir = $top_srcdir
else
abort "can't find header files for ruby."
@@ -140,7 +140,7 @@ class Array
end
def rm_f(*files)
- FileUtils.rm_f(Dir[*files])
+ FileUtils.rm_f(Dir[files.join("\0")])
end
def modified?(target, times)
@@ -265,9 +265,8 @@ ensure
log_src(src)
end
-def link_command(ldflags, opt="", libpath=$LIBPATH)
- RbConfig::expand(TRY_LINK.dup,
- CONFIG.merge('hdrdir' => $hdrdir.quote,
+def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
+ conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote,
'src' => CONFTEST_C,
'INCFLAGS' => $INCFLAGS,
'CPPFLAGS' => $CPPFLAGS,
@@ -276,22 +275,30 @@ def link_command(ldflags, opt="", libpath=$LIBPATH)
'LDFLAGS' => "#$LDFLAGS #{ldflags}",
'LIBPATH' => libpathflag(libpath),
'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs",
- 'LIBS' => "#$LIBRUBYARG_STATIC #{opt} #$LIBS"))
+ 'LIBS' => "#$LIBRUBYARG_STATIC #{opt} #$LIBS")
+ Config::expand(TRY_LINK.dup, conf)
end
def cc_command(opt="")
- RbConfig::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}",
- CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote))
+ conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote)
+ Config::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}",
+ conf)
end
def cpp_command(outfile, opt="")
- RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}",
- CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote))
+ conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote)
+ Config::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}",
+ conf)
end
-def libpathflag(libpath=$LIBPATH)
+def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)
libpath.map{|x|
- (x == "$(topdir)" ? LIBPATHFLAG : LIBPATHFLAG+RPATHFLAG) % x.quote
+ case x
+ when "$(topdir)", /\A\./
+ LIBPATHFLAG
+ else
+ LIBPATHFLAG+RPATHFLAG
+ end % x.quote
}.join
end
@@ -431,7 +438,7 @@ def try_var(var, headers = nil, &b)
#{headers}
/*top*/
int main() { return 0; }
-int t() { const volatile void *volatile p; p = (void *)&#{var}; return 0; }
+int t() { const volatile void *volatile p; p = &(&#{var})[0]; return 0; }
SRC
end
@@ -485,7 +492,7 @@ end
def install_files(mfile, ifiles, map = nil, srcprefix = nil)
ifiles or return
srcprefix ||= '$(srcdir)'
- RbConfig::expand(srcdir = srcprefix.dup)
+ Config::expand(srcdir = srcprefix.dup)
dirs = []
path = Hash.new {|h, i| h[i] = dirs.push([i])[-1]}
ifiles.each do |files, dir, prefix|
@@ -501,8 +508,7 @@ def install_files(mfile, ifiles, map = nil, srcprefix = nil)
len = srcdir.size
end
f = nil
- Dir.glob(files) do |fx|
- f = fx
+ Dir.glob(files) do |f|
f[0..len] = "" if len
d = File.dirname(f)
d.sub!(prefix, "") if prefix
@@ -878,26 +884,21 @@ def find_executable(bin, path = nil)
end
end
-def arg_config(config, default=nil, &block)
- $arg_config << [config, default]
- defaults = []
- if default
- defaults << default
- elsif !block
- defaults << nil
- end
+def arg_config(config, *defaults, &block)
+ $arg_config << [config, *defaults]
+ defaults << nil if !block and defaults.empty?
$configure_args.fetch(config.tr('_', '-'), *defaults, &block)
end
-def with_config(config, default=nil)
+def with_config(config, *defaults)
config = config.sub(/^--with[-_]/, '')
val = arg_config("--with-"+config) do
if arg_config("--without-"+config)
false
elsif block_given?
- yield(config, default)
+ yield(config, *defaults)
else
- break default
+ break *defaults
end
end
case val
@@ -910,15 +911,15 @@ def with_config(config, default=nil)
end
end
-def enable_config(config, default=nil)
+def enable_config(config, *defaults)
if arg_config("--enable-"+config)
true
elsif arg_config("--disable-"+config)
false
elsif block_given?
- yield(config, default)
+ yield(config, *defaults)
else
- return default
+ return *defaults
end
end
@@ -968,11 +969,11 @@ def dir_config(target, idefault=nil, ldefault=nil)
idirs = idir ? Array === idir ? idir : idir.split(File::PATH_SEPARATOR) : []
if defaults
- idirs.concat(defaults.collect {|d| d + "/include"})
+ idirs.concat(defaults.collect {|dir| dir + "/include"})
idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR)
end
unless idirs.empty?
- idirs.collect! {|d| "-I" + d}
+ idirs.collect! {|dir| "-I" + dir}
idirs -= Shellwords.shellwords($CPPFLAGS)
unless idirs.empty?
$CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ")
@@ -981,7 +982,7 @@ def dir_config(target, idefault=nil, ldefault=nil)
ldirs = ldir ? Array === ldir ? ldir : ldir.split(File::PATH_SEPARATOR) : []
if defaults
- ldirs.concat(defaults.collect {|d| d + "/lib"})
+ ldirs.concat(defaults.collect {|dir| dir + "/lib"})
ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR)
end
$LIBPATH = ldirs | $LIBPATH
@@ -1043,7 +1044,6 @@ def configuration(srcdir)
CONFIG['PATH_SEPARATOR'] = ';'
end
end
- CONFIG["hdrdir"] ||= $hdrdir
mk << %{
SHELL = /bin/sh
@@ -1054,6 +1054,9 @@ 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
@@ -1075,7 +1078,6 @@ VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
extconf_h = $extconf_h ? "-DRUBY_EXTCONF_H=\\\"$(RUBY_EXTCONF_H)\\\" " : $defs.join(" ")<<" "
mk << %{
CC = #{CONFIG['CC']}
-CXX = #{CONFIG['CXX']}
LIBRUBY = #{CONFIG['LIBRUBY']}
LIBRUBY_A = #{CONFIG['LIBRUBY_A']}
LIBRUBYARG_SHARED = #$LIBRUBYARG_SHARED
@@ -1084,11 +1086,11 @@ 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
LDSHARED = #{CONFIG['LDSHARED']}
-LDSHAREDXX = #{config_string('LDSHAREDXX') || '$(LDSHARED)'}
AR = #{CONFIG['AR']}
EXEEXT = #{CONFIG['EXEEXT']}
@@ -1096,7 +1098,7 @@ RUBY_INSTALL_NAME = #{CONFIG['RUBY_INSTALL_NAME']}
RUBY_SO_NAME = #{CONFIG['RUBY_SO_NAME']}
arch = #{CONFIG['arch']}
sitearch = #{CONFIG['sitearch']}
-ruby_version = #{RbConfig::CONFIG['ruby_version']}
+ruby_version = #{Config::CONFIG['ruby_version']}
ruby = #{$ruby}
RUBY = $(ruby#{sep})
RM = #{config_string('RM') || '$(RUBY) -run -e rm -- -f'}
@@ -1108,7 +1110,7 @@ COPY = #{config_string('CP') || '@$(RUBY) -run -e cp -- -v'}
#### End of system configuration section. ####
-preload = #{defined?($preload) && $preload ? $preload.join(' ') : ''}
+preload = #{$preload ? $preload.join(' ') : ''}
}
if $nmake == ?b
mk.each do |x|
@@ -1151,7 +1153,7 @@ end
#
def create_makefile(target, srcprefix = nil)
$target = target
- libpath = $LIBPATH
+ libpath = $DEFLIBPATH|$LIBPATH
message "creating Makefile\n"
rm_f "conftest*"
if CONFIG["DLEXT"] == $OBJEXT
@@ -1169,7 +1171,7 @@ def create_makefile(target, srcprefix = nil)
end
srcprefix ||= '$(srcdir)'
- RbConfig::expand(srcdir = srcprefix.dup)
+ Config::expand(srcdir = srcprefix.dup)
if not $objs
$objs = []
@@ -1179,7 +1181,7 @@ def create_makefile(target, srcprefix = nil)
$objs.push(obj) unless $objs.index(obj)
end
elsif !(srcs = $srcs)
- srcs = $objs.collect {|o| o.sub(/\.o\z/, '.c')}
+ srcs = $objs.collect {|obj| obj.sub(/\.o\z/, '.c')}
end
$srcs = srcs
for i in $objs
@@ -1193,7 +1195,7 @@ def create_makefile(target, srcprefix = nil)
if File.exist?(File.join(srcdir, target + '.def'))
deffile = "$(srcdir)/$(TARGET).def"
unless EXPORT_PREFIX.empty?
- makedef = %{-pe "$_.sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"}
+ makedef = %{-pe "sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"}
end
else
makedef = %{-e "puts 'EXPORTS', '#{EXPORT_PREFIX}Init_$(TARGET)'"}
@@ -1206,18 +1208,14 @@ def create_makefile(target, srcprefix = nil)
end
origdef ||= ''
- if $extmk and not $extconf_h
- create_header
- end
-
libpath = libpathflag(libpath)
dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : ""
staticlib = target ? "$(TARGET).#$LIBEXT" : ""
mfile = open("Makefile", "wb")
- mfile.print(*configuration(srcprefix))
+ mfile.print configuration(srcprefix)
mfile.print "
-libpath = #{$LIBPATH.join(" ")}
+libpath = #{($DEFLIBPATH|$LIBPATH).join(" ")}
LIBPATH = #{libpath}
DEFFILE = #{deffile}
@@ -1237,7 +1235,7 @@ EXTSTATIC = #{$static || ""}
STATIC_LIB = #{staticlib unless $static.nil?}
#{!$extout && defined?($installed_list) ? "INSTALLED_LIST = #{$installed_list}\n" : ""}
"
- install_dirs.each {|*d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]}
+ install_dirs.each {|d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]}
n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET).'
mfile.print "
TARGET_SO = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB)
@@ -1284,7 +1282,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
dirs << dir
mfile.print "pre-install-rb#{sfx}: #{dir}\n"
end
- for f in files
+ files.each do |f|
dest = "#{dir}/#{File.basename(f)}"
mfile.print("install-rb#{sfx}: #{dest}\n")
mfile.print("#{dest}: #{f}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ")
@@ -1305,7 +1303,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
end
end
dirs.unshift(sodir) if target and !dirs.include?(sodir)
- dirs.each {|d| mfile.print "#{d}:\n\t$(MAKEDIRS) $@\n"}
+ dirs.each {|dir| mfile.print "#{dir}:\n\t$(MAKEDIRS) $@\n"}
mfile.print <<-SITEINSTALL
@@ -1339,9 +1337,6 @@ site-install-rb: install-rb
mfile.print "\t@-$(RM) $@\n"
mfile.print "\t@-$(MAKEDIRS) $(@D)\n" if $extout
link_so = LINK_SO.gsub(/^/, "\t")
- if srcs.any?(&%r"\.(?:#{CXX_EXT.join('|')})\z".method(:===))
- link_so = link_so.sub(/\bLDSHARED\b/, '\&XX')
- end
mfile.print link_so, "\n\n"
unless $static.nil?
mfile.print "$(STATIC_LIB): $(OBJS)\n\t"
@@ -1381,7 +1376,7 @@ site-install-rb: install-rb
implicit = [[m[1], m[2]], [m.post_match]]
next
elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line
- line.gsub!(%r"(?<=\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)", &RULE_SUBST.method(:%))
+ line.gsub!(%r"(\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2}
end
depout << line
end
@@ -1406,11 +1401,12 @@ site-install-rb: install-rb
unless suffixes.empty?
mfile.print ".SUFFIXES: .", suffixes.uniq.join(" ."), "\n\n"
end
- mfile.print(*depout.flatten)
+ mfile.print "$(OBJS): $(RUBY_EXTCONF_H)\n\n" if $extconf_h
+ mfile.print depout
else
headers = %w[ruby.h defines.h]
if RULE_SUBST
- headers.each {|h| h.sub!(/.*/, &RULE_SUBST.method(:%))}
+ headers.each {|h| h.sub!(/.*/) {|*m| RULE_SUBST % m}}
end
headers << $config_h if $config_h
headers << "$(RUBY_EXTCONF_H)" if $extconf_h
@@ -1440,19 +1436,22 @@ def init_mkmf(config = CONFIG)
$LIBRUBYARG = ""
$LIBRUBYARG_STATIC = config['LIBRUBYARG_STATIC']
$LIBRUBYARG_SHARED = config['LIBRUBYARG_SHARED']
- $LIBPATH = $extmk ? ["$(topdir)"] : CROSS_COMPILING ? [] : ["$(libdir)"]
+ $DEFLIBPATH = $extmk ? ["$(topdir)"] : CROSS_COMPILING ? [] : ["$(libdir)"]
+ $DEFLIBPATH.unshift(".")
+ $LIBPATH = []
$INSTALLFILES = nil
$objs = nil
$srcs = nil
$libs = ""
- if $enable_shared or RbConfig.expand(config["LIBRUBY"].dup) != RbConfig.expand(config["LIBRUBY_A"].dup)
+ if $enable_shared or Config.expand(config["LIBRUBY"].dup) != Config.expand(config["LIBRUBY_A"].dup)
$LIBRUBYARG = config['LIBRUBYARG']
end
$LOCAL_LIBS = ""
$cleanfiles = config_string('CLEANFILES') {|s| Shellwords.shellwords(s)} || []
+ $cleanfiles << "mkmf.log"
$distcleanfiles = config_string('DISTCLEANFILES') {|s| Shellwords.shellwords(s)} || []
$extout ||= nil
@@ -1489,20 +1488,20 @@ when $bccwin
$nmake = ?b if /Borland/i =~ `#{make} -h`
end
-RbConfig::CONFIG["srcdir"] = CONFIG["srcdir"] =
+Config::CONFIG["srcdir"] = CONFIG["srcdir"] =
$srcdir = arg_config("--srcdir", File.dirname($0))
$configure_args["--topsrcdir"] ||= $srcdir
if $curdir = arg_config("--curdir")
- RbConfig.expand(curdir = $curdir.dup)
+ Config.expand(curdir = $curdir.dup)
else
curdir = $curdir = "."
end
-unless File.expand_path(RbConfig::CONFIG["topdir"]) == File.expand_path(curdir)
+unless File.expand_path(Config::CONFIG["topdir"]) == File.expand_path(curdir)
CONFIG["topdir"] = $curdir
- RbConfig::CONFIG["topdir"] = curdir
+ Config::CONFIG["topdir"] = curdir
end
$configure_args["--topdir"] ||= $curdir
-$ruby = arg_config("--ruby", File.join(RbConfig::CONFIG["bindir"], CONFIG["ruby_install_name"]))
+$ruby = arg_config("--ruby", File.join(Config::CONFIG["bindir"], CONFIG["ruby_install_name"]))
split = Shellwords.method(:shellwords).to_proc
@@ -1515,7 +1514,7 @@ config_string('COMMON_MACROS') do |s|
end
end
config_string('COMMON_HEADERS') do |s|
- Shellwords.shellwords(s).each {|w| hdr << "#include <#{w}>"}
+ Shellwords.shellwords(s).each {|s| hdr << "#include <#{s}>"}
end
COMMON_HEADERS = hdr.join("\n")
COMMON_LIBS = config_string('COMMON_LIBS', &split) || []
@@ -1531,14 +1530,14 @@ LINK_SO = config_string('LINK_SO') ||
if CONFIG["DLEXT"] == $OBJEXT
"ld $(DLDFLAGS) -r -o $@ $(OBJS)\n"
else
- "$(LDSHARED) $(DLDFLAGS) $(LIBPATH) #{OUTFLAG}$@ " \
- "$(OBJS) $(LOCAL_LIBS) $(LIBS)"
+ "$(LDSHARED) #{OUTFLAG}$@ $(OBJS) " \
+ "$(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)"
end
LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L"%s"'
RPATHFLAG = config_string('RPATHFLAG') || ''
LIBARG = config_string('LIBARG') || '-l%s'
-sep = config_string('BUILD_FILE_SEPARATOR') {|s| ":/=#{s}" if sep != "/"} || ""
+sep = config_string('BUILD_FILE_SEPARATOR') {|sep| ":/=#{sep}" if sep != "/"} || ""
CLEANINGS = "
clean:
@-$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep})
diff --git a/lib/monitor.rb b/lib/monitor.rb
index f0e79d8fc8..4c146c8086 100644
--- a/lib/monitor.rb
+++ b/lib/monitor.rb
@@ -91,11 +91,11 @@ module MonitorMixin
# stopped. It will be resumed when a corresponding #signal
# occurs.
def wait(timeout = nil)
- @monitor.funcall(:mon_check_owner)
+ @monitor.instance_eval {mon_check_owner()}
timer = create_timer(timeout)
Thread.critical = true
- count = @monitor.funcall(:mon_exit_for_cond)
+ count = @monitor.instance_eval {mon_exit_for_cond()}
@waiters.push(Thread.current)
begin
@@ -105,14 +105,17 @@ module MonitorMixin
return false
ensure
Thread.critical = true
- if timer && timer.alive?
- Thread.kill(timer)
+ 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
end
- if @waiters.include?(Thread.current) # interrupted?
- @waiters.delete(Thread.current)
- end
- @monitor.funcall(:mon_enter_for_cond, count)
- Thread.critical = false
end
end
@@ -133,7 +136,7 @@ module MonitorMixin
# Wake up and run the next waiter
def signal
- @monitor.funcall(:mon_check_owner)
+ @monitor.instance_eval {mon_check_owner()}
Thread.critical = true
t = @waiters.shift
t.wakeup if t
@@ -143,7 +146,7 @@ module MonitorMixin
# Wake up all the waiters.
def broadcast
- @monitor.funcall(:mon_check_owner)
+ @monitor.instance_eval {mon_check_owner()}
Thread.critical = true
for t in @waiters
t.wakeup
@@ -181,7 +184,7 @@ module MonitorMixin
def self.extend_object(obj)
super(obj)
- obj.funcall(:mon_initialize)
+ obj.instance_eval {mon_initialize()}
end
#
@@ -210,6 +213,7 @@ module MonitorMixin
Thread.critical = true
mon_acquire(@mon_entering_queue)
@mon_count += 1
+ ensure
Thread.critical = false
end
@@ -299,8 +303,9 @@ module MonitorMixin
def mon_exit_for_cond
count = @mon_count
@mon_count = 0
- mon_release
return count
+ ensure
+ mon_release
end
end
diff --git a/lib/net/.document b/lib/net/.document
deleted file mode 100644
index 6332bb9e7e..0000000000
--- a/lib/net/.document
+++ /dev/null
@@ -1,8 +0,0 @@
-ftp.rb
-http.rb
-https.rb
-imap.rb
-pop.rb
-smtp.rb
-smtps.rb
-telnet.rb
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index fe244f0775..737a7ebca1 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -79,7 +79,7 @@ module Net
# :startdoc:
# When +true+, transfers are performed in binary mode. Default: +true+.
- attr_reader :binary
+ attr_accessor :binary
# When +true+, the connection is in passive mode. Default: +false+.
attr_accessor :passive
@@ -128,7 +128,7 @@ module Net
#
def initialize(host = nil, user = nil, passwd = nil, acct = nil)
super()
- @binary = false
+ @binary = true
@passive = false
@debug_mode = false
@resume = false
@@ -140,24 +140,6 @@ module Net
end
end
- def binary=(newmode)
- if newmode != @binary
- @binary = newmode
- @binary ? voidcmd("TYPE I") : voidcmd("TYPE A")
- end
- end
-
- def with_binary(newmode)
- oldmode = binary
- self.binary = newmode
- begin
- yield
- ensure
- self.binary = oldmode
- end
- end
- private :with_binary
-
# Obsolete
def return_code
$stderr.puts("warning: Net::FTP#return_code is obsolete and do nothing")
@@ -296,12 +278,9 @@ module Net
def sendport(host, port)
af = (@sock.peeraddr)[0]
if af == "AF_INET"
- hbytes = host.split(".")
- pbytes = [port / 256, port % 256]
- bytes = hbytes + pbytes
- cmd = "PORT " + bytes.join(",")
+ cmd = "PORT " + (host.split(".") + port.divmod(256)).join(",")
elsif af == "AF_INET6"
- cmd = "EPRT |2|" + host + "|" + sprintf("%d", port) + "|"
+ cmd = sprintf("EPRT |2|%s|%d|", host, port)
else
raise FTPProtoError, host
end
@@ -405,7 +384,6 @@ module Net
raise FTPReplyError, resp
end
@welcome = resp
- self.binary = true
end
#
@@ -416,16 +394,15 @@ module Net
#
def retrbinary(cmd, blocksize, rest_offset = nil) # :yield: data
synchronize do
- with_binary(true) do
- conn = transfercmd(cmd, rest_offset)
- loop do
- data = conn.read(blocksize)
- break if data == nil
- yield(data)
- end
- conn.close
- voidresp
- end
+ voidcmd("TYPE I")
+ conn = transfercmd(cmd, rest_offset)
+ loop do
+ data = conn.read(blocksize)
+ break if data == nil
+ yield(data)
+ end
+ conn.close
+ voidresp
end
end
@@ -437,21 +414,20 @@ module Net
#
def retrlines(cmd) # :yield: line
synchronize do
- with_binary(false) do
- conn = transfercmd(cmd)
- loop do
- line = conn.gets
- break if line == nil
- if line[-2, 2] == CRLF
- line = line[0 .. -3]
- elsif line[-1] == ?\n
- line = line[0 .. -2]
- end
- yield(line)
- end
- conn.close
- voidresp
- end
+ voidcmd("TYPE A")
+ conn = transfercmd(cmd)
+ loop do
+ line = conn.gets
+ break if line == nil
+ if line[-2, 2] == CRLF
+ line = line[0 .. -3]
+ elsif line[-1] == ?\n
+ line = line[0 .. -2]
+ end
+ yield(line)
+ end
+ conn.close
+ voidresp
end
end
@@ -466,17 +442,16 @@ module Net
file.seek(rest_offset, IO::SEEK_SET)
end
synchronize do
- with_binary(true) do
- conn = transfercmd(cmd, rest_offset)
- loop do
- buf = file.read(blocksize)
- break if buf == nil
- conn.write(buf)
- yield(buf) if block
- end
- conn.close
- voidresp
- end
+ voidcmd("TYPE I")
+ conn = transfercmd(cmd, rest_offset)
+ loop do
+ buf = file.read(blocksize)
+ break if buf == nil
+ conn.write(buf)
+ yield(buf) if block
+ end
+ conn.close
+ voidresp
end
end
@@ -488,79 +463,61 @@ module Net
#
def storlines(cmd, file, &block) # :yield: line
synchronize do
- with_binary(false) do
- conn = transfercmd(cmd)
- loop do
- buf = file.gets
- break if buf == nil
- if buf[-2, 2] != CRLF
- buf = buf.chomp + CRLF
- end
- conn.write(buf)
- yield(buf) if block
- end
- conn.close
- voidresp
- end
+ voidcmd("TYPE A")
+ conn = transfercmd(cmd)
+ loop do
+ buf = file.gets
+ break if buf == nil
+ if buf[-2, 2] != CRLF
+ buf = buf.chomp + CRLF
+ end
+ conn.write(buf)
+ yield(buf) if block
+ end
+ conn.close
+ voidresp
end
end
#
# Retrieves +remotefile+ in binary mode, storing the result in +localfile+.
- # If +localfile+ is nil, returns retrieved data.
# If a block is supplied, it is passed the retrieved data in +blocksize+
# chunks.
#
def getbinaryfile(remotefile, localfile = File.basename(remotefile),
- blocksize = DEFAULT_BLOCKSIZE) # :yield: data
- result = nil
- if localfile
- if @resume
- rest_offset = File.size?(localfile)
- f = open(localfile, "a")
- else
- rest_offset = nil
- f = open(localfile, "w")
- end
- elsif !block_given?
- result = ""
+ blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
+ if @resume
+ rest_offset = File.size?(localfile)
+ f = open(localfile, "a")
+ else
+ rest_offset = nil
+ f = open(localfile, "w")
end
begin
- f.binmode if localfile
+ f.binmode
retrbinary("RETR " + remotefile, blocksize, rest_offset) do |data|
- f.write(data) if localfile
- yield(data) if block_given?
- result.concat(data) if result
+ f.write(data)
+ yield(data) if block
end
- return result
ensure
- f.close if localfile
+ f.close
end
end
#
# Retrieves +remotefile+ in ASCII (text) mode, storing the result in
- # +localfile+.
- # If +localfile+ is nil, returns retrieved data.
- # If a block is supplied, it is passed the retrieved data one
+ # +localfile+. If a block is supplied, it is passed the retrieved data one
# line at a time.
#
- def gettextfile(remotefile, localfile = File.basename(remotefile)) # :yield: line
- result = nil
- if localfile
- f = open(localfile, "w")
- elsif !block_given?
- result = ""
- end
+ def gettextfile(remotefile, localfile = File.basename(remotefile), &block) # :yield: line
+ f = open(localfile, "w")
begin
retrlines("RETR " + remotefile) do |line|
- f.puts(line) if localfile
- yield(line) if block_given?
- result.concat(line + "\n") if result
+ f.puts(line)
+ yield(line) if block
end
- return result
ensure
- f.close if localfile
+ f.close
end
end
@@ -570,10 +527,10 @@ module Net
#
def get(remotefile, localfile = File.basename(remotefile),
blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
- if @binary
- getbinaryfile(remotefile, localfile, blocksize, &block)
- else
+ unless @binary
gettextfile(remotefile, localfile, &block)
+ else
+ getbinaryfile(remotefile, localfile, blocksize, &block)
end
end
@@ -622,10 +579,10 @@ module Net
#
def put(localfile, remotefile = File.basename(localfile),
blocksize = DEFAULT_BLOCKSIZE, &block)
- if @binary
- putbinaryfile(localfile, remotefile, blocksize, &block)
- else
+ unless @binary
puttextfile(localfile, remotefile, &block)
+ else
+ putbinaryfile(localfile, remotefile, blocksize, &block)
end
end
@@ -707,9 +664,9 @@ module Net
begin
voidcmd("CDUP")
return
- rescue FTPPermError
- if $![0, 3] != "500"
- raise FTPPermError, $!
+ rescue FTPPermError => e
+ if e.message[0, 3] != "500"
+ raise e
end
end
end
@@ -721,13 +678,12 @@ module Net
# Returns the size of the given (remote) filename.
#
def size(filename)
- with_binary(true) do
- resp = sendcmd("SIZE " + filename)
- if resp[0, 3] != "213"
- raise FTPReplyError, resp
- end
- return resp[3..-1].strip.to_i
+ voidcmd("TYPE I")
+ resp = sendcmd("SIZE " + filename)
+ if resp[0, 3] != "213"
+ raise FTPReplyError, resp
end
+ return resp[3..-1].strip.to_i
end
MDTM_REGEXP = /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/ # :nodoc:
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 46d95b27b4..7dd1f24d4c 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -584,6 +584,9 @@ 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/https.rb b/lib/net/https.rb
index fb329df43d..e296dbbed4 100644
--- a/lib/net/https.rb
+++ b/lib/net/https.rb
@@ -109,7 +109,8 @@ module Net
@use_ssl
end
- alias use_ssl use_ssl? # for backward compatibility
+ # For backward compatibility.
+ alias use_ssl use_ssl?
# Turn on/off SSL.
# This flag must be set before starting session.
@@ -160,7 +161,8 @@ module Net
@ssl_context.timeout = sec
end
- alias timeout= ssl_timeout= # for backward compatibility
+ # For backward compatibility
+ alias timeout= ssl_timeout=
def peer_cert
return nil if not use_ssl? or not @socket
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index d7c34ad961..6162ffa0d0 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -16,7 +16,6 @@
require "socket"
require "monitor"
require "digest/md5"
-require "strscan"
begin
require "openssl"
rescue LoadError
@@ -274,10 +273,8 @@ module Net
# is the type of authentication this authenticator supports
# (for instance, "LOGIN"). The +authenticator+ is an object
# which defines a process() method to handle authentication with
- # the server. See Net::IMAP::LoginAuthenticator,
- # Net::IMAP::CramMD5Authenticator, and Net::IMAP::DigestMD5Authenticator
- # for examples.
- #
+ # the server. See Net::IMAP::LoginAuthenticator and
+ # Net::IMAP::CramMD5Authenticator for examples.
#
# If +auth_type+ refers to an existing authenticator, it will be
# replaced by the new one.
@@ -287,7 +284,13 @@ module Net
# Disconnects from the server.
def disconnect
- @sock.shutdown unless @usessl
+ begin
+ # try to call SSL::SSLSocket#io.
+ @sock.io.shutdown
+ rescue NoMethodError
+ # @sock is not an SSL::SSLSocket.
+ @sock.shutdown
+ end
@receiver_thread.join
@sock.close
end
@@ -325,24 +328,6 @@ module Net
send_command("LOGOUT")
end
- # Sends a STARTTLS command to start TLS session.
- def starttls(ctx = nil)
- if @sock.kind_of?(OpenSSL::SSL::SSLSocket)
- raise RuntimeError, "already using SSL"
- end
- send_command("STARTTLS") do |resp|
- if resp.kind_of?(TaggedResponse) && resp.name == "OK"
- if ctx
- @sock = OpenSSL::SSL::SSLSocket.new(@sock, ctx)
- else
- @sock = OpenSSL::SSL::SSLSocket.new(@sock)
- end
- @sock.sync_close = true
- @sock.connect
- end
- end
- end
-
# Sends an AUTHENTICATE command to authenticate the client.
# The +auth_type+ parameter is a string that represents
# the authentication mechanism to be used. Currently Net::IMAP
@@ -849,7 +834,7 @@ module Net
if x > 0
base64.concat("=" * (4 - x))
end
- base64.unpack("m")[0].unpack("n*").pack("U*")
+ u16tou8(base64.unpack("m")[0])
end
}
end
@@ -860,7 +845,7 @@ module Net
if $1
"&-"
else
- base64 = [x.unpack("U*").pack("n*")].pack("m")
+ base64 = [u8tou16(x)].pack("m")
"&" + base64.delete("=\n").tr("/", ",") + "-"
end
}
@@ -917,14 +902,15 @@ module Net
end
@sock = SSLSocket.new(@sock, context)
@sock.connect # start ssl session.
+ @sock.post_connection_check(@host) if verify
else
@usessl = false
end
@responses = Hash.new([].freeze)
@tagged_responses = {}
@response_handlers = []
- @tagged_response_arrival = new_cond
- @continuation_request_arrival = new_cond
+ @response_arrival = new_cond
+ @continuation_request = nil
@logout_command_tag = nil
@debug_output_bol = true
@@ -955,7 +941,7 @@ module Net
case resp
when TaggedResponse
@tagged_responses[resp.tag] = resp
- @tagged_response_arrival.broadcast
+ @response_arrival.broadcast
if resp.tag == @logout_command_tag
return
end
@@ -970,7 +956,8 @@ module Net
raise ByeResponseError, resp.raw_data
end
when ContinuationRequest
- @continuation_request_arrival.signal
+ @continuation_request = resp
+ @response_arrival.broadcast
end
@response_handlers.each do |handler|
handler.call(resp)
@@ -982,10 +969,14 @@ module Net
end
end
- def get_tagged_response(tag, cmd)
+ def get_tagged_response(tag)
until @tagged_responses.key?(tag)
- @tagged_response_arrival.wait
+ @response_arrival.wait
end
+ return pick_up_tagged_response(tag)
+ end
+
+ def pick_up_tagged_response(tag)
resp = @tagged_responses.delete(tag)
case resp.name
when /\A(?:NO)\z/ni
@@ -1026,7 +1017,7 @@ module Net
def send_command(cmd, *args, &block)
synchronize do
- tag = generate_tag
+ tag = Thread.current[:net_imap_tag] = generate_tag
put_string(tag + " " + cmd)
args.each do |i|
put_string(" ")
@@ -1040,7 +1031,7 @@ module Net
add_response_handler(block)
end
begin
- return get_tagged_response(tag, cmd)
+ return get_tagged_response(tag)
ensure
if block
remove_response_handler(block)
@@ -1109,7 +1100,15 @@ module Net
def send_literal(str)
put_string("{" + str.length.to_s + "}" + CRLF)
- @continuation_request_arrival.wait
+ while @continuation_request.nil? &&
+ !@tagged_responses.key?(Thread.current[:net_imap_tag])
+ @response_arrival.wait
+ end
+ if @continuation_request.nil?
+ pick_up_tagged_response(Thread.current[:net_imap_tag])
+ raise ResponseError.new("expected continuation request")
+ end
+ @continuation_request = nil
put_string(str)
end
@@ -1225,9 +1224,128 @@ module Net
end
end
+ def self.u16tou8(s)
+ len = s.length
+ if len < 2
+ return ""
+ end
+ buf = ""
+ i = 0
+ while i < len
+ c = s[i] << 8 | s[i + 1]
+ i += 2
+ if c == 0xfeff
+ next
+ elsif c < 0x0080
+ buf.concat(c)
+ elsif c < 0x0800
+ b2 = c & 0x003f
+ b1 = c >> 6
+ buf.concat(b1 | 0xc0)
+ buf.concat(b2 | 0x80)
+ elsif c >= 0xdc00 && c < 0xe000
+ raise DataFormatError, "invalid surrogate detected"
+ elsif c >= 0xd800 && c < 0xdc00
+ if i + 2 > len
+ raise DataFormatError, "invalid surrogate detected"
+ end
+ low = s[i] << 8 | s[i + 1]
+ i += 2
+ if low < 0xdc00 || low > 0xdfff
+ raise DataFormatError, "invalid surrogate detected"
+ end
+ c = (((c & 0x03ff)) << 10 | (low & 0x03ff)) + 0x10000
+ b4 = c & 0x003f
+ b3 = (c >> 6) & 0x003f
+ b2 = (c >> 12) & 0x003f
+ b1 = c >> 18;
+ buf.concat(b1 | 0xf0)
+ buf.concat(b2 | 0x80)
+ buf.concat(b3 | 0x80)
+ buf.concat(b4 | 0x80)
+ else # 0x0800-0xffff
+ b3 = c & 0x003f
+ b2 = (c >> 6) & 0x003f
+ b1 = c >> 12
+ buf.concat(b1 | 0xe0)
+ buf.concat(b2 | 0x80)
+ buf.concat(b3 | 0x80)
+ end
+ end
+ return buf
+ end
+ private_class_method :u16tou8
+
+ def self.u8tou16(s)
+ len = s.length
+ buf = ""
+ i = 0
+ while i < len
+ c = s[i]
+ if (c & 0x80) == 0
+ buf.concat(0x00)
+ buf.concat(c)
+ i += 1
+ elsif (c & 0xe0) == 0xc0 &&
+ len >= 2 &&
+ (s[i + 1] & 0xc0) == 0x80
+ if c == 0xc0 || c == 0xc1
+ raise DataFormatError, format("non-shortest UTF-8 sequence (%02x)", c)
+ end
+ u = ((c & 0x1f) << 6) | (s[i + 1] & 0x3f)
+ buf.concat(u >> 8)
+ buf.concat(u & 0x00ff)
+ i += 2
+ elsif (c & 0xf0) == 0xe0 &&
+ i + 2 < len &&
+ (s[i + 1] & 0xc0) == 0x80 &&
+ (s[i + 2] & 0xc0) == 0x80
+ if c == 0xe0 && s[i + 1] < 0xa0
+ raise DataFormatError, format("non-shortest UTF-8 sequence (%02x)", c)
+ end
+ u = ((c & 0x0f) << 12) | ((s[i + 1] & 0x3f) << 6) | (s[i + 2] & 0x3f)
+ # surrogate chars
+ if u >= 0xd800 && u <= 0xdfff
+ raise DataFormatError, format("none-UTF-16 char detected (%04x)", u)
+ end
+ buf.concat(u >> 8)
+ buf.concat(u & 0x00ff)
+ i += 3
+ elsif (c & 0xf8) == 0xf0 &&
+ i + 3 < len &&
+ (s[i + 1] & 0xc0) == 0x80 &&
+ (s[i + 2] & 0xc0) == 0x80 &&
+ (s[i + 3] & 0xc0) == 0x80
+ if c == 0xf0 && s[i + 1] < 0x90
+ raise DataFormatError, format("non-shortest UTF-8 sequence (%02x)", c)
+ end
+ u = ((c & 0x07) << 18) | ((s[i + 1] & 0x3f) << 12) |
+ ((s[i + 2] & 0x3f) << 6) | (s[i + 3] & 0x3f)
+ if u < 0x10000
+ buf.concat(u >> 8)
+ buf.concat(u & 0x00ff)
+ elsif u < 0x110000
+ high = ((u - 0x10000) >> 10) | 0xd800
+ low = (u & 0x03ff) | 0xdc00
+ buf.concat(high >> 8)
+ buf.concat(high & 0x00ff)
+ buf.concat(low >> 8)
+ buf.concat(low & 0x00ff)
+ else
+ raise DataFormatError, format("none-UTF-16 char detected (%04x)", u)
+ end
+ i += 4
+ else
+ raise DataFormatError, format("illegal UTF-8 sequence (%02x)", c)
+ end
+ end
+ return buf
+ end
+ private_class_method :u8tou16
+
class RawData # :nodoc:
def send_data(imap)
- imap.funcall(:put_string, @data)
+ imap.send(:put_string, @data)
end
private
@@ -1239,7 +1357,7 @@ module Net
class Atom # :nodoc:
def send_data(imap)
- imap.funcall(:put_string, @data)
+ imap.send(:put_string, @data)
end
private
@@ -1251,7 +1369,7 @@ module Net
class QuotedString # :nodoc:
def send_data(imap)
- imap.funcall(:send_quoted_string, @data)
+ imap.send(:send_quoted_string, @data)
end
private
@@ -1263,7 +1381,7 @@ module Net
class Literal # :nodoc:
def send_data(imap)
- imap.funcall(:send_literal, @data)
+ imap.send(:send_literal, @data)
end
private
@@ -1275,7 +1393,7 @@ module Net
class MessageSet # :nodoc:
def send_data(imap)
- imap.funcall(:put_string, format_internal(@data))
+ imap.send(:put_string, format_internal(@data))
end
private
@@ -2944,7 +3062,7 @@ module Net
elsif $7
return Token.new(T_RPAR, $+)
else
- parse_error("[Net::IMAP BUG] BEG_REGEXP is invalid")
+ parse_error("[Net::IMAP BUG] DATA_REGEXP is invalid")
end
else
@str.index(/\S*/n, @pos)
@@ -2998,7 +3116,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.symbol
+ if @token
$stderr.printf("@token.symbol: %s\n", @token.symbol)
$stderr.printf("@token.value: %s\n", @token.value.inspect)
end
@@ -3033,22 +3151,6 @@ module Net
end
add_authenticator "LOGIN", LoginAuthenticator
- # Authenticator for the "PLAIN" authentication type. See
- # #authenticate().
- class PlainAuthenticator
- def process(data)
- return "\0#{@user}\0#{@password}"
- end
-
- private
-
- def initialize(user, password)
- @user = user
- @password = password
- end
- end
- add_authenticator "PLAIN", PlainAuthenticator
-
# Authenticator for the "CRAM-MD5" authentication type. See
# #authenticate().
class CramMD5Authenticator
@@ -3083,106 +3185,6 @@ module Net
end
add_authenticator "CRAM-MD5", CramMD5Authenticator
- # Authenticator for the "DIGEST-MD5" authentication type. See
- # #authenticate().
- class DigestMD5Authenticator
- def process(challenge)
- case @stage
- when STAGE_ONE
- @stage = STAGE_TWO
- sparams = {}
- c = StringScanner.new(challenge)
- while c.scan(/(?:\s*,)?\s*(\w+)=("(?:[^\\"]+|\\.)*"|[^,]+)\s*/)
- k, v = c[1], c[2]
- if v =~ /^"(.*)"$/
- v = $1
- if v =~ /,/
- v = v.split(',')
- end
- end
- sparams[k] = v
- end
-
- raise DataFormatError, "Bad Challenge: '#{challenge}'" unless c.rest.size == 0
- raise Error, "Server does not support auth (qop = #{sparams['qop'].join(',')})" unless sparams['qop'].include?("auth")
-
- response = {
- :nonce => sparams['nonce'],
- :username => @user,
- :realm => sparams['realm'],
- :cnonce => Digest::MD5.hexdigest("%.15f:%.15f:%d" % [Time.now.to_f, rand, Process.pid.to_s]),
- :'digest-uri' => 'imap/' + sparams['realm'],
- :qop => 'auth',
- :maxbuf => 65535,
- :nc => "%08d" % nc(sparams['nonce']),
- :charset => sparams['charset'],
- }
-
- response[:authzid] = @authname unless @authname.nil?
-
- # now, the real thing
- a0 = Digest::MD5.digest( [ response.values_at(:username, :realm), @password ].join(':') )
-
- a1 = [ a0, response.values_at(:nonce,:cnonce) ].join(':')
- a1 << ':' + response[:authzid] unless response[:authzid].nil?
-
- a2 = "AUTHENTICATE:" + response[:'digest-uri']
- a2 << ":00000000000000000000000000000000" if response[:qop] and response[:qop] =~ /^auth-(?:conf|int)$/
-
- response[:response] = Digest::MD5.hexdigest(
- [
- Digest::MD5.hexdigest(a1),
- response.values_at(:nonce, :nc, :cnonce, :qop),
- Digest::MD5.hexdigest(a2)
- ].join(':')
- )
-
- return response.keys.map { |k| qdval(k.to_s, response[k]) }.join(',')
- when STAGE_TWO
- @stage = nil
- # if at the second stage, return an empty string
- if challenge =~ /rspauth=/
- return ''
- else
- raise ResponseParseError, challenge
- end
- else
- raise ResponseParseError, challenge
- end
- end
-
- def initialize(user, password, authname = nil)
- @user, @password, @authname = user, password, authname
- @nc, @stage = {}, STAGE_ONE
- end
-
- private
-
- STAGE_ONE = :stage_one
- STAGE_TWO = :stage_two
-
- def nc(nonce)
- if @nc.has_key? nonce
- @nc[nonce] = @nc[nonce] + 1
- else
- @nc[nonce] = 1
- end
- return @nc[nonce]
- end
-
- # some reponses needs quoting
- def qdval(k, v)
- return if k.nil? or v.nil?
- if %w"username authzid realm nonce cnonce digest-uri qop".include? k
- v.gsub!(/([\\"])/, "\\\1")
- return '%s="%s"' % [k, v]
- else
- return '%s=%s' % [k, v]
- end
- end
- end
- add_authenticator "DIGEST-MD5", DigestMD5Authenticator
-
# Superclass of IMAP errors.
class Error < StandardError
end
diff --git a/lib/net/pop.rb b/lib/net/pop.rb
index f9d64aa8f5..6d1343eded 100644
--- a/lib/net/pop.rb
+++ b/lib/net/pop.rb
@@ -10,24 +10,18 @@
#
# This program is free software. You can re-distribute and/or
# modify this program under the same terms as Ruby itself,
-# Ruby Distribute License.
+# Ruby Distribute License or GNU General Public License.
#
-# NOTE: You can find Japanese version of this document at:
-# http://www.ruby-lang.org/ja/man/index.cgi?cmd=view;name=net%2Fpop.rb
+# NOTE: You can find Japanese version of this document in
+# the doc/net directory of the standard ruby interpreter package.
#
# $Id$
-#
+#
# See Net::POP3 for documentation.
#
require 'net/protocol'
require 'digest/md5'
-require 'timeout'
-
-begin
- require "openssl"
-rescue LoadError
-end
module Net
@@ -202,19 +196,10 @@ module Net
# Class Parameters
#
- def POP3.default_port
- default_pop3_port()
- end
-
# The default port for POP3 connections, port 110
- def POP3.default_pop3_port
+ def POP3.default_port
110
end
-
- # The default port for POP3S connections, port 995
- def POP3.default_pop3s_port
- 995
- end
def POP3.socket_type #:nodoc: obsolete
Net::InternetMessageIO
@@ -235,7 +220,7 @@ module Net
# ....
# end
#
- def POP3.APOP(isapop)
+ def POP3.APOP( isapop )
isapop ? APOP : POP3
end
@@ -259,9 +244,9 @@ module Net
# m.delete if $DELETE
# end
#
- def POP3.foreach(address, port = nil,
- account = nil, password = nil,
- isapop = false, &block) # :yields: message
+ def POP3.foreach( address, port = nil,
+ account = nil, password = nil,
+ isapop = false, &block ) # :yields: message
start(address, port, account, password, isapop) {|pop|
pop.each_mail(&block)
}
@@ -280,9 +265,9 @@ module Net
# file.write m.pop
# end
#
- def POP3.delete_all(address, port = nil,
- account = nil, password = nil,
- isapop = false, &block)
+ def POP3.delete_all( address, port = nil,
+ account = nil, password = nil,
+ isapop = false, &block )
start(address, port, account, password, isapop) {|pop|
pop.delete_all(&block)
}
@@ -302,16 +287,16 @@ module Net
# Net::POP3.auth_only('pop.example.com', 110,
# 'YourAccount', 'YourPassword', true)
#
- def POP3.auth_only(address, port = nil,
- account = nil, password = nil,
- isapop = false)
+ def POP3.auth_only( address, port = nil,
+ account = nil, password = nil,
+ isapop = false )
new(address, port, isapop).auth_only account, password
end
# Starts a pop3 session, attempts authentication, and quits.
# This method must not be called while POP3 session is opened.
# This method raises POPAuthenticationError if authentication fails.
- def auth_only(account, password)
+ def auth_only( account, password )
raise IOError, 'opening previously opened POP session' if started?
start(account, password) {
;
@@ -319,44 +304,6 @@ module Net
end
#
- # SSL
- #
-
- @use_ssl = false
- @verify = nil
- @certs = nil
-
- # Enable SSL for all new instances.
- # +verify+ is the type of verification to do on the Server Cert; Defaults
- # to OpenSSL::SSL::VERIFY_PEER.
- # +certs+ is a file or directory holding CA certs to use to verify the
- # server cert; Defaults to nil.
- def POP3.enable_ssl(verify = OpenSSL::SSL::VERIFY_PEER, certs = nil)
- @use_ssl = true
- @verify = verify
- @certs = certs
- end
-
- # Disable SSL for all new instances.
- def POP3.disable_ssl
- @use_ssl = nil
- @verify = nil
- @certs = nil
- end
-
- def POP3.use_ssl?
- @use_ssl
- end
-
- def POP3.verify
- @verify
- end
-
- def POP3.certs
- @certs
- end
-
- #
# Session management
#
@@ -376,30 +323,27 @@ module Net
# end
# end
#
- def POP3.start(address, port = nil,
- account = nil, password = nil,
- isapop = false, &block) # :yield: pop
+ def POP3.start( address, port = nil,
+ account = nil, password = nil,
+ isapop = false, &block ) # :yield: pop
new(address, port, isapop).start(account, password, &block)
end
-
+
# Creates a new POP3 object.
#
# +address+ is the hostname or ip address of your POP3 server.
#
- # The optional +port+ is the port to connect to.
+ # The optional +port+ is the port to connect to; it defaults to 110.
#
# The optional +isapop+ specifies whether this connection is going
# to use APOP authentication; it defaults to +false+.
#
# This method does *not* open the TCP connection.
- def initialize(addr, port = nil, isapop = false)
+ def initialize( addr, port = nil, isapop = false )
@address = addr
- @use_ssl = POP3.use_ssl?
- @port = port || (POP3.use_ssl? ? POP3.default_pop3s_port : POP3.default_pop3_port)
+ @port = port || self.class.default_port
@apop = isapop
- @certs = POP3.certs
- @verify = POP3.verify
-
+
@command = nil
@socket = nil
@started = false
@@ -417,32 +361,6 @@ module Net
@apop
end
- # does this instance use SSL?
- def use_ssl?
- @use_ssl
- end
-
- # Enables SSL for this instance. Must be called before the connection is
- # established to have any effect.
- # +verify+ is the type of verification to do on the Server Cert; Defaults
- # to OpenSSL::SSL::VERIFY_PEER.
- # +certs+ is a file or directory holding CA certs to use to verify the
- # server cert; Defaults to nil.
- # +port+ is port to establish the SSL connection on; Defaults to 995.
- def enable_ssl(verify = OpenSSL::SSL::VERIFY_PEER, certs = nil,
- port = POP3.default_pop3s_port)
- @use_ssl = true
- @verify = verify
- @certs = certs
- @port = port
- end
-
- def disable_ssl
- @use_ssl = false
- @verify = nil
- @certs = nil
- end
-
# Provide human-readable stringification of class state.
def inspect
"#<#{self.class} #{@address}:#{@port} open=#{@started}>"
@@ -461,7 +379,7 @@ module Net
# ....
# end
#
- def set_debug_output(arg)
+ def set_debug_output( arg )
@debug_output = arg
end
@@ -482,7 +400,7 @@ module Net
attr_reader :read_timeout
# Set the read timeout.
- def read_timeout=(sec)
+ def read_timeout=( sec )
@command.socket.read_timeout = sec if @command
@read_timeout = sec
end
@@ -500,8 +418,9 @@ module Net
# closes the session after block call finishes.
#
# This method raises a POPAuthenticationError if authentication fails.
- def start(account, password) # :yield: pop
+ def start( account, password ) # :yield: pop
raise IOError, 'POP session already started' if @started
+
if block_given?
begin
do_start account, password
@@ -515,29 +434,9 @@ module Net
end
end
- def do_start(account, password)
- s = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
- if use_ssl?
- raise 'openssl library not installed' unless defined?(OpenSSL)
- context = OpenSSL::SSL::SSLContext.new
- context.verify_mode = @verify
- if @certs
- if File.file?(@certs)
- context.ca_file = @certs
- elsif File.directory?(@certs)
- context.ca_path = @certs
- else
- raise ArgumentError, "certs path is not file/directory: #{@certs}"
- end
- end
- s = OpenSSL::SSL::SSLSocket.new(s, context)
- s.sync_close = true
- s.connect
- end
- @socket = InternetMessageIO.new(s)
- logging "POP session started: #{@address}:#{@port} (#{@apop ? 'APOP' : 'POP'})"
- @socket.read_timeout = @read_timeout
- @socket.debug_output = @debug_output
+ def do_start( account, password )
+ @socket = self.class.socket_type.old_open(@address, @port,
+ @open_timeout, @read_timeout, @debug_output)
on_connect
@command = POP3Command.new(@socket)
if apop?
@@ -547,12 +446,7 @@ module Net
end
@started = true
ensure
- # Authentication failed, clean up connection.
- unless @started
- s.close if s and not s.closed?
- @socket = nil
- @command = nil
- end
+ do_finish if not @started
end
private :do_start
@@ -568,6 +462,8 @@ module Net
def do_finish
@mails = nil
+ @n_mails = nil
+ @n_bytes = nil
@command.quit if @command
ensure
@started = false
@@ -630,7 +526,7 @@ module Net
# end
#
# This method raises a POPError if an error occurs.
- def each_mail(&block) # :yield: message
+ def each_mail( &block ) # :yield: message
mails().each(&block)
end
@@ -677,10 +573,6 @@ module Net
end
end
- def logging(msg)
- @debug_output << msg + "\n" if @debug_output
- end
-
end # class POP3
# class aliases
@@ -708,7 +600,7 @@ module Net
#
class POPMail
- def initialize(num, len, pop, cmd) #:nodoc:
+ def initialize( num, len, pop, cmd ) #:nodoc:
@number = num
@length = len
@pop = pop
@@ -787,7 +679,7 @@ module Net
# The optional +dest+ argument is obsolete.
#
# This method raises a POPError if an error occurs.
- def top(lines, dest = '')
+ def top( lines, dest = '' )
@command.top(@number, lines) do |chunk|
dest << chunk
end
@@ -799,7 +691,7 @@ module Net
# The optional +dest+ argument is obsolete.
#
# This method raises a POPError if an error occurs.
- def header(dest = '')
+ def header( dest = '' )
top(0, dest)
end
@@ -847,7 +739,7 @@ module Net
alias uidl unique_id
- def uid=(uid) #:nodoc: internal use only
+ def uid=( uid ) #:nodoc: internal use only (used from POP3#set_all_uids)
@uid = uid
end
@@ -856,7 +748,7 @@ module Net
class POP3Command #:nodoc: internal use only
- def initialize(sock)
+ def initialize( sock )
@socket = sock
@error_occured = false
res = check_response(critical { recv_response() })
@@ -867,14 +759,14 @@ module Net
"#<#{self.class} socket=#{@socket}>"
end
- def auth(account, password)
+ def auth( account, password )
check_response_auth(critical {
check_response_auth(get_response('USER %s', account))
get_response('PASS %s', password)
})
end
- def apop(account, password)
+ def apop( account, password )
raise POPAuthenticationError, 'not APOP server; cannot login' \
unless @apop_stamp
check_response_auth(critical {
@@ -905,28 +797,28 @@ module Net
end
def rset
- check_response(critical { get_response('RSET') })
+ check_response(critical { get_response 'RSET' })
end
- def top(num, lines = 0, &block)
+ def top( num, lines = 0, &block )
critical {
getok('TOP %d %d', num, lines)
@socket.each_message_chunk(&block)
}
end
- def retr(num, &block)
+ def retr( num, &block )
critical {
getok('RETR %d', num)
@socket.each_message_chunk(&block)
}
end
- def dele(num)
+ def dele( num )
check_response(critical { get_response('DELE %d', num) })
end
- def uidl(num = nil)
+ def uidl( num = nil )
if num
res = check_response(critical { get_response('UIDL %d', num) })
return res.split(/ /)[1]
@@ -949,12 +841,12 @@ module Net
private
- def getok(fmt, *fargs)
+ def getok( fmt, *fargs )
@socket.writeline sprintf(fmt, *fargs)
check_response(recv_response())
end
- def get_response(fmt, *fargs)
+ def get_response( fmt, *fargs )
@socket.writeline sprintf(fmt, *fargs)
recv_response()
end
@@ -963,13 +855,13 @@ module Net
@socket.readline
end
- def check_response(res)
- raise POPError, res unless /\A\+OK/i =~ res
+ def check_response( res )
+ raise POPError, res unless /\A\+OK/i === res
res
end
- def check_response_auth(res)
- raise POPAuthenticationError, res unless /\A\+OK/i =~ res
+ def check_response_auth( res )
+ raise POPAuthenticationError, res unless /\A\+OK/i === res
res
end
@@ -986,3 +878,4 @@ module Net
end # class POP3Command
end # module Net
+
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index 37b4269f29..d722fdcbd4 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -2,8 +2,8 @@
# = net/protocol.rb
#
#--
-# Copyright (c) 1999-2004 Yukihiro Matsumoto
-# Copyright (c) 1999-2004 Minero Aoki
+# Copyright (c) 1999-2005 Yukihiro Matsumoto
+# Copyright (c) 1999-2005 Minero Aoki
#
# written and maintained by Minero Aoki <aamine@loveruby.net>
#
@@ -200,6 +200,16 @@ module Net # :nodoc:
class InternetMessageIO < BufferedIO #:nodoc: internal use only
+ def InternetMessageIO.old_open(addr, port,
+ open_timeout = nil, read_timeout = nil, debug_output = nil)
+ debug_output << "opening connection to #{addr}...\n" if debug_output
+ s = timeout(open_timeout) { TCPsocket.new(addr, port) }
+ io = new(s)
+ io.read_timeout = read_timeout
+ io.debug_output = debug_output
+ io
+ end
+
def initialize(io)
super
@wbuf = nil
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index 29b7c0b71c..a4a2c52d58 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -1,18 +1,19 @@
# = net/smtp.rb
#
-# Copyright (c) 1999-2006 Yukihiro Matsumoto.
+# Copyright (c) 1999-2003 Yukihiro Matsumoto.
#
-# Copyright (c) 1999-2006 Minero Aoki.
+# Copyright (c) 1999-2003 Minero Aoki.
#
# Written & maintained by Minero Aoki <aamine@loveruby.net>.
#
# Documented by William Webber and Minero Aoki.
#
# This program is free software. You can re-distribute and/or
-# modify this program under the same terms as Ruby itself.
+# modify this program under the same terms as Ruby itself,
+# Ruby Distribute License or GNU General Public License.
#
-# NOTE: You can find Japanese version of this document at:
-# http://www.ruby-lang.org/ja/man/index.cgi?cmd=view;name=net%2Fsmtp.rb
+# NOTE: You can find Japanese version of this document in
+# the doc/net directory of the standard ruby interpreter package.
#
# $Id$
#
@@ -21,11 +22,6 @@
require 'net/protocol'
require 'digest/md5'
-require 'timeout'
-begin
- require 'openssl'
-rescue LoadError
-end
module Net
@@ -174,70 +170,6 @@ module Net
25
end
- # The default SMTP/SSL port, port 465.
- def SMTP.default_ssl_port
- 465
- end
-
- # The default SMTP/TLS (STARTTLS) port, port 587.
- def SMTP.default_tls_port
- 587
- end
-
- @ssl = false
- @tls = false
- @ssl_context = nil
-
- # Enables SMTP/SSL for all new objects.
- # +context+ is a OpenSSL::SSL::SSLContext object.
- def SMTP.enable_ssl(context = SMTP.default_ssl_context)
- raise 'openssl library not installed' unless defined?(OpenSSL)
- raise ArgumentError, "SSL and TLS is exclusive" if @tls
- @ssl = true
- @ssl_context = context
- end
-
- # Disables SMTP/SSL for all new objects.
- def SMTP.disable_ssl
- @ssl = false
- @ssl_context = nil
- end
-
- # true if new objects use SMTP/SSL.
- def SMTP.use_ssl?
- @ssl
- end
-
- # Enables SMTP/SSL for all new objects.
- # +context+ is a OpenSSL::SSL::Context object.
- def SMTP.enable_tls(context = SMTP.default_ssl_context)
- raise 'openssl library not installed' unless defined?(OpenSSL)
- raise ArgumentError, "SSL and TLS is exclusive" if @ssl
- @tls = false
- @ssl_context = context
- end
-
- # Disable SMTP/TLS for all new objects.
- def SMTP.disable_tls
- @tls = false
- @ssl_context = nil
- end
-
- # true if new objects use SMTP/TLS.
- def SMTP.use_tls?
- @tls
- end
-
- def SMTP.ssl_context
- @ssl_context
- end
-
- def SMTP.default_ssl_context
- ctx = OpenSSL::SSL::SSLContext.new
- ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
- ctx
- end
-
#
# Creates a new Net::SMTP object.
#
@@ -249,7 +181,7 @@ module Net
# SMTP.start instead of SMTP.new if you want to do everything
# at once. Otherwise, follow SMTP.new with SMTP#start.
#
- def initialize(address, port = nil)
+ def initialize( address, port = nil )
@address = address
@port = (port || SMTP.default_port)
@esmtp = true
@@ -259,18 +191,8 @@ module Net
@read_timeout = 60
@error_occured = false
@debug_output = nil
- if SMTP.use_ssl? or SMTP.use_tls?
- @ssl = true
- if SMTP.use_ssl?
- @ssl_mode = :ssl
- else
- @ssl_mode = :tls
- end
- @certs = SMTP.certs
- @verify = SMTP.verify
- end
end
-
+
# Provide human-readable stringification of class state.
def inspect
"#<#{self.class} #{@address}:#{@port} started=#{@started}>"
@@ -288,55 +210,12 @@ module Net
# object will automatically switch to plain SMTP mode and
# retry (but not vice versa).
#
- def esmtp=(bool)
+ def esmtp=( bool )
@esmtp = bool
end
alias esmtp esmtp?
- # true if this object uses SMTP/SSL.
- def use_ssl?
- @ssl
- end
-
- # true if this object uses SMTP/TLS
- def use_tls?
- @tls
- end
-
- # Enables SMTP/SSL for this object. Must be called before the
- # connection is established to have any effect.
- # +context+ is a OpenSSL::SSL::SSLContext object.
- def enable_ssl(context = SMTP.default_ssl_context)
- raise 'openssl library not installed' unless defined?(OpenSSL)
- raise ArgumentError, "SSL and TLS is exclusive" if @tls
- @ssl = true
- @ssl_context = context
- end
-
- # Disables SMTP/SSL for this object. Must be called before the
- # connection is established to have any effect.
- def disable_ssl
- @ssl = false
- @ssl_context = nil
- end
-
- # Enables SMTP/TLS (STARTTLS) for this object.
- # +context+ is a OpenSSL::SSL::SSLContext object.
- def enable_tls(context = SMTP.default_ssl_context)
- raise 'openssl library not installed' unless defined?(OpenSSL)
- raise ArgumentError, "SSL and TLS is exclusive" if @ssl
- @tls = true
- @ssl_context = context
- end
-
- # Disables SMTP/TLS (STARTTLS) for this object. Must be called
- # before the connection is established to have any effect.
- def disable_tls
- @ssl = false
- @ssl_context = nil
- end
-
# The address of the SMTP server to connect to.
attr_reader :address
@@ -355,7 +234,7 @@ module Net
# Set the number of seconds to wait until timing-out a read(2)
# call.
- def read_timeout=(sec)
+ def read_timeout=( sec )
@socket.read_timeout = sec if @socket
@read_timeout = sec
end
@@ -374,12 +253,10 @@ module Net
# ....
# end
#
- def debug_output=(arg)
+ def set_debug_output( arg )
@debug_output = arg
end
- alias set_debug_output debug_output=
-
#
# SMTP session control
#
@@ -497,80 +374,30 @@ module Net
user = nil, secret = nil, authtype = nil) # :yield: smtp
if block_given?
begin
- do_start helo, user, secret, authtype
+ do_start(helo, user, secret, authtype)
return yield(self)
ensure
do_finish
end
else
- do_start helo, user, secret, authtype
+ do_start(helo, user, secret, authtype)
return self
end
end
- # Finishes the SMTP session and closes TCP connection.
- # Raises IOError if not started.
- def finish
- raise IOError, 'not yet started' unless started?
- do_finish
- end
-
- private
-
- def do_start(helo_domain, user, secret, authtype)
+ def do_start( helodomain, user, secret, authtype )
raise IOError, 'SMTP session already started' if @started
- if user or secret
- check_auth_method authtype
- check_auth_args user, secret
- end
- s = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
- logging "Connection opened: #{@address}:#{@port}"
- if use_ssl?
- s = new_ssl_socket(s)
- s.connect
- logging "SMTP/SSL started"
- end
- @socket = new_internet_message_io(s)
- check_response(critical { recv_response() })
- do_helo helo_domain
- if use_tls?
- s = new_ssl_socket(s)
- starttls
- s.connect
- logging "SMTP/TLS started"
- @socket = new_internet_message_io(s)
- # helo response may be different after STARTTLS
- do_helo helo_domain
- end
- authenticate user, secret, authtype if user
- @started = true
- ensure
- unless @started
- # authentication failed, cancel connection.
- s.close if s and not s.closed?
- @socket = nil
- end
- end
+ check_auth_args user, secret, authtype if user or secret
- def new_internet_message_io(s)
- io = InternetMessageIO.new(s)
- io.read_timeout = @read_timeout
- io.debug_output = @debug_output
- io
- end
-
- def new_ssl_socket(s)
- s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
- s.sync_close = true
- s
- end
-
- def do_helo(helo_domain)
- begin
+ @socket = InternetMessageIO.old_open(@address, @port,
+ @open_timeout, @read_timeout,
+ @debug_output)
+ check_response(critical { recv_response() })
+ begin
if @esmtp
- ehlo helo_domain
+ ehlo helodomain
else
- helo helo_domain
+ helo helodomain
end
rescue ProtocolError
if @esmtp
@@ -580,6 +407,18 @@ module Net
end
raise
end
+ authenticate user, secret, authtype if user
+ @started = true
+ ensure
+ @socket.close if not @started and @socket and not @socket.closed?
+ end
+ private :do_start
+
+ # Finishes the SMTP session and closes TCP connection.
+ # Raises IOError if not started.
+ def finish
+ raise IOError, 'not yet started' unless started?
+ do_finish
end
def do_finish
@@ -590,9 +429,10 @@ module Net
@socket.close if @socket and not @socket.closed?
@socket = nil
end
+ private :do_finish
#
- # Message Sending
+ # message send
#
public
@@ -627,11 +467,10 @@ module Net
# * IOError
# * TimeoutError
#
- def send_message(msgstr, from_addr, *to_addrs)
- raise IOError, 'closed session' unless @socket
- mailfrom from_addr
- rcptto_list to_addrs
- data msgstr
+ def send_message( msgstr, from_addr, *to_addrs )
+ send0(from_addr, to_addrs.flatten) {
+ @socket.write_message msgstr
+ }
end
alias send_mail send_message
@@ -681,46 +520,72 @@ module Net
# * IOError
# * TimeoutError
#
- def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
- raise IOError, 'closed session' unless @socket
- mailfrom from_addr
- rcptto_list to_addrs
- data(&block)
+ def open_message_stream( from_addr, *to_addrs, &block ) # :yield: stream
+ send0(from_addr, to_addrs.flatten) {
+ @socket.write_message_by_block(&block)
+ }
end
alias ready open_message_stream # obsolete
+ private
+
+ def send0( from_addr, to_addrs )
+ raise IOError, 'closed session' unless @socket
+ raise ArgumentError, 'mail destination not given' if to_addrs.empty?
+ if $SAFE > 0
+ raise SecurityError, 'tainted from_addr' if from_addr.tainted?
+ to_addrs.each do |to|
+ raise SecurityError, 'tainted to_addr' if to.tainted?
+ end
+ end
+
+ mailfrom from_addr
+ to_addrs.each do |to|
+ rcptto to
+ end
+ res = critical {
+ check_response(get_response('DATA'), true)
+ yield
+ recv_response()
+ }
+ check_response(res)
+ end
+
#
- # Authentication
+ # auth
#
- public
+ private
+
+ def check_auth_args( user, secret, authtype )
+ raise ArgumentError, 'both user and secret are required'\
+ unless user and secret
+ auth_method = "auth_#{authtype || 'cram_md5'}"
+ raise ArgumentError, "wrong auth type #{authtype}"\
+ unless respond_to?(auth_method, true)
+ end
- def authenticate(user, secret, authtype)
- check_auth_method authtype
- check_auth_args user, secret
- funcall "auth_#{authtype || 'cram_md5'}", user, secret
+ def authenticate( user, secret, authtype )
+ __send__("auth_#{authtype || 'cram_md5'}", user, secret)
end
- def auth_plain(user, secret)
- check_auth_args user, secret
+ def auth_plain( user, secret )
res = critical { get_response('AUTH PLAIN %s',
base64_encode("\0#{user}\0#{secret}")) }
- raise SMTPAuthenticationError, res unless /\A2../ =~ res
+ raise SMTPAuthenticationError, res unless /\A2../ === res
end
- def auth_login(user, secret)
- check_auth_args user, secret
+ def auth_login( user, secret )
res = critical {
check_response(get_response('AUTH LOGIN'), true)
check_response(get_response(base64_encode(user)), true)
get_response(base64_encode(secret))
}
- raise SMTPAuthenticationError, res unless /\A2../ =~ res
+ raise SMTPAuthenticationError, res unless /\A2../ === res
end
- def auth_cram_md5(user, secret)
- check_auth_args user, secret
+ def auth_cram_md5( user, secret )
# CRAM-MD5: [RFC2195]
res = nil
critical {
@@ -731,38 +596,18 @@ module Net
isecret = secret + "\0" * (64 - secret.size)
osecret = isecret.dup
0.upto(63) do |i|
- c = isecret[i].ord ^ 0x36
- isecret[i] = c.chr
- c = osecret[i].ord ^ 0x5c
- osecret[i] = c.chr
+ isecret[i] ^= 0x36
+ osecret[i] ^= 0x5c
end
tmp = Digest::MD5.digest(isecret + challenge)
tmp = Digest::MD5.hexdigest(osecret + tmp)
res = get_response(base64_encode(user + ' ' + tmp))
}
- raise SMTPAuthenticationError, res unless /\A2../ =~ res
- end
-
- private
-
- def check_auth_method(type)
- mid = "auth_#{type || 'cram_md5'}"
- unless respond_to?(mid, true)
- raise ArgumentError, "wrong authentication type #{type}"
- end
+ raise SMTPAuthenticationError, res unless /\A2../ === res
end
- def check_auth_args(user, secret)
- unless user
- raise ArgumentError, 'SMTP-AUTH requested but missing user name'
- end
- unless secret
- raise ArgumentError, 'SMTP-AUTH requested but missing secret phrase'
- end
- end
-
- def base64_encode(str)
+ def base64_encode( str )
# expects "str" may not become too long
[str].pack('m').gsub(/\s+/, '')
end
@@ -771,90 +616,35 @@ module Net
# SMTP command dispatcher
#
- public
-
- def starttls
- getok('STARTTLS')
- end
+ private
- def helo(domain)
+ def helo( domain )
getok('HELO %s', domain)
end
- def ehlo(domain)
+ def ehlo( domain )
getok('EHLO %s', domain)
end
- def mailfrom(from_addr)
- if $SAFE > 0
- raise SecurityError, 'tainted from_addr' if from_addr.tainted?
- end
- getok('MAIL FROM:<%s>', from_addr)
- end
-
- def rcptto_list(to_addrs)
- raise ArgumentError, 'mail destination not given' if to_addrs.empty?
- to_addrs.flatten.each do |addr|
- rcptto addr
- end
+ def mailfrom( fromaddr )
+ getok('MAIL FROM:<%s>', fromaddr)
end
- def rcptto(to_addr)
- if $SAFE > 0
- raise SecurityError, 'tainted to_addr' if to.tainted?
- end
- getok('RCPT TO:<%s>', to_addr)
- end
-
- # This method sends a message.
- # If +msgstr+ is given, sends it as a message.
- # If block is given, yield a message writer stream.
- # You must write message before the block is closed.
- #
- # # Example 1 (by string)
- # smtp.data(<<EndMessage)
- # From: john@example.com
- # To: betty@example.com
- # Subject: I found a bug
- #
- # Check vm.c:58879.
- # EndMessage
- #
- # # Example 2 (by block)
- # smtp.data {|f|
- # f.puts "From: john@example.com"
- # f.puts "To: betty@example.com"
- # f.puts "Subject: I found a bug"
- # f.puts ""
- # f.puts "Check vm.c:58879."
- # }
- #
- def data(msgstr = nil, &block) #:yield: stream
- if msgstr and block
- raise ArgumentError, "message and block are exclusive"
- end
- unless msgstr or block
- raise ArgumentError, "message or block is required"
- end
- res = critical {
- check_response(get_response('DATA'), true)
- if msgstr
- @socket.write_message msgstr
- else
- @socket.write_message_by_block(&block)
- end
- recv_response()
- }
- check_response(res)
+ def rcptto( to )
+ getok('RCPT TO:<%s>', to)
end
def quit
getok('QUIT')
end
+ #
+ # row level library
+ #
+
private
- def getok(fmt, *args)
+ def getok( fmt, *args )
res = critical {
@socket.writeline sprintf(fmt, *args)
recv_response()
@@ -862,7 +652,7 @@ module Net
return check_response(res)
end
- def get_response(fmt, *args)
+ def get_response( fmt, *args )
@socket.writeline sprintf(fmt, *args)
recv_response()
end
@@ -877,28 +667,19 @@ module Net
res
end
- def check_response(res, allow_continue = false)
- case res
- when /\A2/
- return res
- when /\A3/
- unless allow_continue
- raise SMTPUnknownError,
- "got response 3xx but not DATA: #{res.inspect}"
- end
- return res
- when /\A4/
- raise SMTPServerBusy, res
- when /\A50/
- raise SMTPSyntaxError, res
- when /\A55/
- raise SMTPFatalError, res
- else
- raise SMTPUnknownError, res
- end
+ def check_response( res, allow_continue = false )
+ return res if /\A2/ === res
+ return res if allow_continue and /\A3/ === res
+ err = case res
+ when /\A4/ then SMTPServerBusy
+ when /\A50/ then SMTPSyntaxError
+ when /\A55/ then SMTPFatalError
+ else SMTPUnknownError
+ end
+ raise err, res
end
- def critical(&block)
+ def critical( &block )
return '200 dummy reply code' if @error_occured
begin
return yield()
@@ -908,12 +689,8 @@ module Net
end
end
- def logging(msg)
- @debug_output << msg + "\n" if @debug_output
- end
-
end # class SMTP
SMTPSession = SMTP
-end
+end # module Net
diff --git a/lib/net/telnet.rb b/lib/net/telnet.rb
index 16459d7c65..a55527f15e 100644
--- a/lib/net/telnet.rb
+++ b/lib/net/telnet.rb
@@ -438,9 +438,6 @@ module Net
# combine EOL into "\n"
string = string.gsub(/#{EOL}/no, "\n") unless @options["Binmode"]
- # remove NULL
- string = string.gsub(/#{NULL}/no, '') unless @options["Binmode"]
-
string.gsub(/#{IAC}(
[#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]|
[#{DO}#{DONT}#{WILL}#{WONT}]
@@ -562,7 +559,8 @@ 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)
+ elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no) ||
+ c.rindex(/\r\z/no)
buf = preprocess(c[0 ... pt])
rest = c[pt .. -1]
else
@@ -574,9 +572,15 @@ module Net
#
# We cannot use preprocess() on this data, because that
# method makes some Telnetmode-specific assumptions.
- buf = c
- buf.gsub!(/#{EOL}/no, "\n") unless @options["Binmode"]
+ buf = rest + c
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
@@ -708,7 +712,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 = /Password[: ]*\z/n
+ password_prompt = /[Pp]ass(?:word|phrase)[: ]*\z/n
if options.kind_of?(Hash)
username = options["Name"]
password = options["Password"]
diff --git a/lib/observer.rb b/lib/observer.rb
index 472a154395..64c7d81351 100644
--- a/lib/observer.rb
+++ b/lib/observer.rb
@@ -118,15 +118,14 @@ module Observable
#
# Add +observer+ as an observer on this object. +observer+ will now receive
- # notifications. The second optional argument specifies a method to notify
- # updates, of which default value is +update+.
+ # notifications.
#
- def add_observer(observer, func=:update)
- @observer_peers = {} unless defined? @observer_peers
- unless observer.respond_to? func
- raise NoMethodError, "observer does not respond to `#{func.to_s}'"
+ def add_observer(observer)
+ @observer_peers = [] unless defined? @observer_peers
+ unless observer.respond_to? :update
+ raise NoMethodError, "observer needs to respond to `update'"
end
- @observer_peers[observer] = func
+ @observer_peers.push observer
end
#
@@ -182,9 +181,9 @@ module Observable
def notify_observers(*arg)
if defined? @observer_state and @observer_state
if defined? @observer_peers
- @observer_peers.each { |k, v|
- k.send v, *arg
- }
+ for i in @observer_peers.dup
+ i.update(*arg)
+ end
end
@observer_state = false
end
diff --git a/lib/open-uri.rb b/lib/open-uri.rb
index 56c78f0468..0dae95b6e6 100644
--- a/lib/open-uri.rb
+++ b/lib/open-uri.rb
@@ -91,13 +91,9 @@ end
module OpenURI
Options = {
:proxy => true,
- :proxy_http_basic_authentication => true,
:progress_proc => true,
:content_length_proc => true,
:http_basic_authentication => true,
- :read_timeout => true,
- :ssl_ca_cert => nil,
- :ssl_verify_mode => nil,
}
def OpenURI.check_options(options) # :nodoc:
@@ -146,40 +142,16 @@ module OpenURI
end
def OpenURI.open_loop(uri, options) # :nodoc:
- proxy_opts = []
- proxy_opts << :proxy_http_basic_authentication if options.include? :proxy_http_basic_authentication
- proxy_opts << :proxy if options.include? :proxy
- proxy_opts.compact!
- if 1 < proxy_opts.length
- raise ArgumentError, "multiple proxy options specified"
- end
- case proxy_opts.first
- when :proxy_http_basic_authentication
- opt_proxy, proxy_user, proxy_pass = options.fetch(:proxy_http_basic_authentication)
- proxy_user = proxy_user.to_str
- proxy_pass = proxy_pass.to_str
- if opt_proxy == true
- raise ArgumentError.new("Invalid authenticated proxy option: #{options[:proxy_http_basic_authentication].inspect}")
- end
- when :proxy
- opt_proxy = options.fetch(:proxy)
- proxy_user = nil
- proxy_pass = nil
- when nil
- opt_proxy = true
- proxy_user = nil
- proxy_pass = nil
- end
- case opt_proxy
+ case opt_proxy = options.fetch(:proxy, true)
when true
- find_proxy = lambda {|u| pxy = u.find_proxy; pxy ? [pxy, nil, nil] : nil}
+ find_proxy = lambda {|u| u.find_proxy}
when nil, false
find_proxy = lambda {|u| nil}
when String
opt_proxy = URI.parse(opt_proxy)
- find_proxy = lambda {|u| [opt_proxy, proxy_user, proxy_pass]}
+ find_proxy = lambda {|u| opt_proxy}
when URI::Generic
- find_proxy = lambda {|u| [opt_proxy, proxy_user, proxy_pass]}
+ find_proxy = lambda {|u| opt_proxy}
else
raise ArgumentError.new("Invalid proxy option: #{opt_proxy}")
end
@@ -228,8 +200,7 @@ module OpenURI
def OpenURI.open_http(buf, target, proxy, options) # :nodoc:
if proxy
- proxy_uri, proxy_user, proxy_pass = proxy
- raise "Non-HTTP proxy URI: #{proxy_uri}" if proxy_uri.class != URI::HTTP
+ raise "Non-HTTP proxy URI: #{proxy}" if proxy.class != URI::HTTP
end
if target.userinfo && "1.9.0" <= RUBY_VERSION
@@ -237,67 +208,38 @@ module OpenURI
raise ArgumentError, "userinfo not supported. [RFC3986]"
end
- header = {}
- options.each {|k, v| header[k] = v if String === k }
-
require 'net/http'
klass = Net::HTTP
if URI::HTTP === target
# HTTP or HTTPS
if proxy
- if proxy_user && proxy_pass
- klass = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_user, proxy_pass)
- else
- klass = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port)
- end
+ klass = Net::HTTP::Proxy(proxy.host, proxy.port)
end
target_host = target.host
target_port = target.port
request_uri = target.request_uri
else
# FTP over HTTP proxy
- target_host = proxy_uri.host
- target_port = proxy_uri.port
+ target_host = proxy.host
+ target_port = proxy.port
request_uri = target.to_s
- if proxy_user && proxy_pass
- header["Proxy-Authorization"] = 'Basic ' + ["#{proxy_user}:#{proxy_pass}"].pack('m').delete("\r\n")
- end
end
http = klass.new(target_host, target_port)
if target.class == URI::HTTPS
require 'net/https'
http.use_ssl = true
- http.verify_mode = options[:ssl_verify_mode] || OpenSSL::SSL::VERIFY_PEER
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
store = OpenSSL::X509::Store.new
- if options[:ssl_ca_cert]
- if File.directory? options[:ssl_ca_cert]
- store.add_path options[:ssl_ca_cert]
- else
- store.add_file options[:ssl_ca_cert]
- end
- else
- store.set_default_paths
- end
store.set_default_paths
http.cert_store = store
end
- if options.include? :read_timeout
- http.read_timeout = options[:read_timeout]
- end
+
+ header = {}
+ options.each {|k, v| header[k] = v if String === k }
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]
@@ -518,21 +460,6 @@ module OpenURI
# When false or nil is given, the environment variables are ignored and
# connection will be made to a server directly.
#
- # [:proxy_http_basic_authentication]
- # Synopsis:
- # :proxy_http_basic_authentication => ["http://proxy.foo.com:8000/", "proxy-user", "proxy-password"]
- # :proxy_http_basic_authentication => [URI.parse("http://proxy.foo.com:8000/"), "proxy-user", "proxy-password"]
- #
- # If :proxy option is specified, the value should be an Array with 3 elements.
- # It should contain a proxy URI, a proxy user name and a proxy password.
- # The proxy URI should be a String, an URI or nil.
- # The proxy user name and password should be a String.
- #
- # If nil is given for the proxy URI, this option is just ignored.
- #
- # If :proxy and :proxy_http_basic_authentication is specified,
- # ArgumentError is raised.
- #
# [:http_basic_authentication]
# Synopsis:
# :http_basic_authentication=>[user, password]
@@ -584,26 +511,6 @@ module OpenURI
# pbar.set s if pbar
# }) {|f| ... }
#
- # [:read_timeout]
- # Synopsis:
- # :read_timeout=>nil (no timeout)
- # :read_timeout=>10 (10 second)
- #
- # :read_timeout option specifies a timeout of read for http connections.
- #
- # [:ssl_ca_cert]
- # Synopsis:
- # :ssl_ca_cert=>filename
- #
- # :ssl_ca_cert is used to specify CA certificate for SSL.
- # If it is given, default certificates are not used.
- #
- # [:ssl_verify_mode]
- # Synopsis:
- # :ssl_verify_mode=>mode
- #
- # :ssl_verify_mode is used to specify openssl verify mode.
- #
# OpenURI::OpenRead#open returns an IO like object if block is not given.
# Otherwise it yields the IO object and return the value of the block.
# The IO object is extended with OpenURI::Meta.
diff --git a/lib/optparse.rb b/lib/optparse.rb
index c4e9ad65d4..80b16fa18d 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -221,7 +221,7 @@ class OptionParser
def complete(key, icase = false, pat = nil)
pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'),
icase)
- canon, sw, cn = nil
+ canon, sw, k, v, cn = nil
candidates = []
each do |k, *v|
(if Regexp === k
@@ -349,7 +349,7 @@ class OptionParser
if conv
val = conv.call(*val)
else
- val = proc {|v| v}.call(*val)
+ val = proc {|val| val}.call(*val)
end
return arg, block, val
end
@@ -368,7 +368,7 @@ class OptionParser
# +indent+:: Prefix string indents all summarized lines.
#
def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
- sopts, lopts = [], [], nil
+ sopts, lopts, s = [], [], nil
@short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
@long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
return if sopts.empty? and lopts.empty? # completely hidden
@@ -379,14 +379,14 @@ class OptionParser
while s = lopts.shift
l = left[-1].length + s.length
l += arg.length if left.size == 1 && arg
- l < max or left << ''
+ l < max or sopts.empty? or left << ''
left[-1] << if left[-1].empty? then ' ' * 4 else ', ' end << s
end
left[0] << arg if arg
- mlen = left.collect {|ss| ss.length}.max.to_i
+ mlen = left.collect {|s| s.length}.max.to_i
while mlen > width and l = left.shift
- mlen = left.collect {|ss| ss.length}.max.to_i if l.length == mlen
+ mlen = left.collect {|s| s.length}.max.to_i if l.length == mlen
yield(indent + l)
end
@@ -398,8 +398,7 @@ class OptionParser
self
end
- # :nodoc:
- def add_banner(to)
+ def add_banner(to) # :nodoc:
unless @short or @long
s = desc.join
to << " [" + s + "]..." unless s.empty?
@@ -407,8 +406,7 @@ class OptionParser
to
end
- # :nodoc:
- def match_nonswitch?(str)
+ def match_nonswitch?(str) # :nodoc:
@pattern =~ str unless @short or @long
end
@@ -453,7 +451,7 @@ class OptionParser
raise MissingArgument if argv.empty?
arg = argv.shift
end
- conv_arg(*parse_arg(arg, &method(:raise)))
+ conv_arg(*parse_arg(arg) {|*exc| raise(*exc)})
end
end
@@ -557,6 +555,7 @@ class OptionParser
# +nlopts+:: Negated long style options list.
#
def update(sw, sopts, lopts, nsw = nil, nlopts = nil)
+ o = nil
sopts.each {|o| @short[o] = sw} if sopts
lopts.each {|o| @long[o] = sw} if lopts
nlopts.each {|o| @long[o] = nsw} if nsw and nlopts
@@ -642,8 +641,7 @@ class OptionParser
end
end
- # :nodoc:
- def add_banner(to)
+ def add_banner(to) # :nodoc:
list.each do |opt|
if opt.respond_to?(:add_banner)
opt.add_banner(to)
@@ -1062,6 +1060,7 @@ class OptionParser
default_style = Switch::NoArgument
default_pattern = nil
klass = nil
+ o = nil
n, q, a = nil
opts.each do |o|
@@ -1095,7 +1094,7 @@ class OptionParser
else
raise ArgumentError, "argument pattern given twice"
end
- o.each {|pat, *v| pattern[pat] = v.fetch(0) {pat}}
+ o.each {|(o, *v)| pattern[o] = v.fetch(0) {o}}
when Module
raise ArgumentError, "unsupported argument type: #{o}"
when *ArgumentStyle.keys
@@ -1242,10 +1241,9 @@ class OptionParser
parse_in_order(argv, &nonopt)
end
- # :nodoc:
- def parse_in_order(argv = default_argv, setter = nil, &nonopt)
- opt, arg, val, rest = nil
- nonopt ||= proc {|a| throw :terminate, a}
+ def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc:
+ opt, arg, sw, val, rest = nil
+ nonopt ||= proc {|arg| throw :terminate, arg}
argv.unshift(arg) if arg = catch(:terminate) {
while arg = argv.shift
case arg
@@ -1299,8 +1297,7 @@ class OptionParser
# non-option argument
else
catch(:prune) do
- visit(:each_option) do |sw0|
- sw = sw0
+ visit(:each_option) do |sw|
sw.block.call(arg) if Switch === sw and sw.match_nonswitch?(arg)
end
nonopt.call(arg)
@@ -1331,7 +1328,8 @@ class OptionParser
#
def permute!(argv = default_argv)
nonopts = []
- order!(argv, &nonopts.method(:<<))
+ arg = nil
+ order!(argv) {|arg| nonopts << arg}
argv[0, 0] = nonopts
argv
end
@@ -1408,6 +1406,7 @@ class OptionParser
# +block+.
#
def visit(id, *args, &block)
+ el = nil
@stack.reverse_each do |el|
el.send(id, *args, &block)
end
@@ -1440,7 +1439,7 @@ class OptionParser
search(typ, opt) {|sw| return [sw, opt]} # exact match or...
end
raise AmbiguousOption, catch(:ambiguous) {
- visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw}
+ visit(:complete, typ, opt, icase, *pat) {|opt, *sw| return sw}
raise InvalidOption, opt
}
end
@@ -1475,6 +1474,7 @@ class OptionParser
#
def environment(env = File.basename($0, '.*'))
env = ENV[env] || ENV[env.upcase] or return
+ require 'shellwords'
parse(*Shellwords.shellwords(env))
end
@@ -1559,7 +1559,7 @@ class OptionParser
#
accept(Array) do |s,|
if s
- s = s.split(',').collect {|ss| ss unless ss.empty?}
+ s = s.split(',').collect {|s| s unless s.empty?}
end
s
end
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index f3ed01524b..6af5bbdac0 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -70,10 +70,9 @@ class OpenStruct
def new_ostruct_member(name)
name = name.to_sym
unless self.respond_to?(name)
- class << self; self; end.class_eval do
- define_method(name) { @table[name] }
- define_method(:"#{name}=") { |x| @table[name] = x }
- end
+ meta = class << self; self; end
+ meta.send(:define_method, name) { @table[name] }
+ meta.send(:define_method, :"#{name}=") { |x| @table[name] = x }
end
end
diff --git a/lib/pp.rb b/lib/pp.rb
index 5e4f20cedf..8080d879f9 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -105,55 +105,41 @@ class PP < PrettyPrint
end
module PPMethods
- def guard_inspect_key
- if Thread.current[:__recursive_key__] == nil
- Thread.current[:__recursive_key__] = {}
- end
+ InspectKey = :__inspect_key__
- if Thread.current[:__recursive_key__][:inspect] == nil
- Thread.current[:__recursive_key__][:inspect] = []
+ def guard_inspect_key
+ if Thread.current[InspectKey] == nil
+ Thread.current[InspectKey] = []
end
- save = Thread.current[:__recursive_key__][:inspect]
+ save = Thread.current[InspectKey]
begin
- Thread.current[:__recursive_key__][:inspect] = []
+ Thread.current[InspectKey] = []
yield
ensure
- Thread.current[:__recursive_key__][:inspect] = save
+ Thread.current[InspectKey] = save
end
end
- def check_inspect_key(id)
- Thread.current[:__recursive_key__] &&
- Thread.current[:__recursive_key__][:inspect] &&
- Thread.current[:__recursive_key__][:inspect].include?(id)
- end
- def push_inspect_key(id)
- Thread.current[:__recursive_key__][:inspect] << id
- end
- def pop_inspect_key
- Thread.current[:__recursive_key__][:inspect].pop
- end
-
# Adds +obj+ to the pretty printing buffer
# using Object#pretty_print or Object#pretty_print_cycle.
#
# Object#pretty_print_cycle is used when +obj+ is already
# printed, a.k.a the object reference chain has a cycle.
def pp(obj)
- id = obj.object_id
-
- if check_inspect_key(id)
+ id = obj.__id__
+
+ if Thread.current[InspectKey].include? id
group {obj.pretty_print_cycle self}
return
end
begin
- push_inspect_key(id)
+ Thread.current[InspectKey] << id
group {obj.pretty_print self}
ensure
- pop_inspect_key unless PP.sharing_detection
+ Thread.current[InspectKey].pop unless PP.sharing_detection
end
end
@@ -164,23 +150,9 @@ class PP < PrettyPrint
group(1, '#<' + obj.class.name, '>', &block)
end
- if 0x100000000.class == Bignum
- # 32bit
- PointerMask = 0xffffffff
- else
- # 64bit
- PointerMask = 0xffffffffffffffff
- end
-
- case Object.new.inspect
- when /\A\#<Object:0x([0-9a-f]+)>\z/
- PointerFormat = "%0#{$1.length}x"
- else
- PointerFormat = "%x"
- end
-
def object_address_group(obj, &block)
- id = PointerFormat % (obj.object_id * 2 & PointerMask)
+ id = "%x" % (obj.__id__ * 2)
+ id.sub!(/\Af(?=[[:xdigit:]]{2}+\z)/, '') if id.sub!(/\A\.\./, '')
group(1, "\#<#{obj.class}:0x#{id}", '>', &block)
end
@@ -220,13 +192,13 @@ class PP < PrettyPrint
def seplist(list, sep=nil, iter_method=:each) # :yield: element
sep ||= lambda { comma_breakable }
first = true
- list.__send__(iter_method) {|v|
+ list.__send__(iter_method) {|*v|
if first
first = false
else
sep.call
end
- yield(v)
+ yield(*v)
}
end
diff --git a/lib/prettyprint.rb b/lib/prettyprint.rb
index 507a05e65c..315c422e9e 100644
--- a/lib/prettyprint.rb
+++ b/lib/prettyprint.rb
@@ -381,7 +381,7 @@ end
if __FILE__ == $0
require 'test/unit'
- class WadlerExample < Test::Unit::TestCase
+ class WadlerExample < Test::Unit::TestCase # :nodoc:
def setup
@tree = Tree.new("aaaa", Tree.new("bbbbb", Tree.new("ccc"),
Tree.new("dd")),
@@ -561,7 +561,7 @@ End
assert_equal(expected, tree_alt(50))
end
- class Tree
+ class Tree # :nodoc:
def initialize(string, *children)
@string = string
@children = children
@@ -618,7 +618,7 @@ End
end
end
- class StrictPrettyExample < Test::Unit::TestCase
+ class StrictPrettyExample < Test::Unit::TestCase # :nodoc:
def prog(width)
PrettyPrint.format('', width) {|q|
q.group {
@@ -763,7 +763,7 @@ End
end
- class TailGroup < Test::Unit::TestCase
+ class TailGroup < Test::Unit::TestCase # :nodoc:
def test_1
out = PrettyPrint.format('', 10) {|q|
q.group {
@@ -783,7 +783,7 @@ End
end
end
- class NonString < Test::Unit::TestCase
+ class NonString < Test::Unit::TestCase # :nodoc:
def format(width)
PrettyPrint.format([], width, 'newline', lambda {|n| "#{n} spaces"}) {|q|
q.text(3, 3)
@@ -802,7 +802,7 @@ End
end
- class Fill < Test::Unit::TestCase
+ class Fill < Test::Unit::TestCase # :nodoc:
def format(width)
PrettyPrint.format('', width) {|q|
q.group {
diff --git a/lib/profiler.rb b/lib/profiler.rb
index 1067106be4..9762fa1181 100644
--- a/lib/profiler.rb
+++ b/lib/profiler.rb
@@ -34,7 +34,7 @@ module_function
total = Process.times[0] - @@start
if total == 0 then total = 0.01 end
data = @@map.values
- data = data.sort_by{|x| x[2]}
+ data.sort!{|a,b| b[2] <=> a[2]}
sum = 0
f.printf " %% cumulative self self total\n"
f.printf " time seconds seconds calls ms/call ms/call name\n"
diff --git a/lib/rational.rb b/lib/rational.rb
index 5ed283cda0..ce754cfa3c 100644
--- a/lib/rational.rb
+++ b/lib/rational.rb
@@ -17,6 +17,7 @@
# See Rational for full documentation.
#
+
#
# Creates a Rational number (i.e. a fraction). +a+ and +b+ should be Integers:
#
@@ -445,6 +446,10 @@ class Integer
max
end
+ #
+ # Returns the <em>lowest common multiple</em> (LCM) of the two arguments
+ # (+self+ and +other+).
+ #
# Examples:
# 6.lcm 7 # -> 42
# 6.lcm 9 # -> 18
@@ -456,7 +461,7 @@ class Integer
(self.div(self.gcd(other)) * other).abs
end
end
-
+
#
# Returns the GCD _and_ the LCM (see #gcd and #lcm) of the two arguments
# (+self+ and +other+). This is more efficient than calculating them
diff --git a/lib/rdoc/markup/simple_markup/inline.rb b/lib/rdoc/markup/simple_markup/inline.rb
index 9ca5857358..d54fe1e667 100644
--- a/lib/rdoc/markup/simple_markup/inline.rb
+++ b/lib/rdoc/markup/simple_markup/inline.rb
@@ -295,7 +295,7 @@ module SM
# skip leading invisible text
i = 0
- i += 1 while i < str_len and @str[i] == "\0"
+ i += 1 while i < str_len and @str[i].zero?
start_pos = i
# then scan the string, chunking it on attribute changes
@@ -321,7 +321,7 @@ module SM
# move on, skipping any invisible characters
begin
i += 1
- end while i < str_len and @str[i] == "\0"
+ end while i < str_len and @str[i].zero?
end
# tidy up trailing text
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index 4dfe45169c..bea7e6bdcd 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\s+version(?:\s+gviz)?\s+(\d+)\.(\d+)/
+ if ver =~ /dot.+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 a1ea9a5da7..25fc66af3f 100644
--- a/lib/rdoc/parsers/parse_c.rb
+++ b/lib/rdoc/parsers/parse_c.rb
@@ -1,3 +1,78 @@
+# Classes and modules built in to the interpreter. We need
+# these to define superclasses of user objects
+
+require "rdoc/code_objects"
+require "rdoc/parsers/parserfactory"
+require "rdoc/options"
+require "rdoc/rdoc"
+
+module RDoc
+
+ ##
+ # Ruby's built-in classes.
+
+ KNOWN_CLASSES = {
+ "rb_cObject" => "Object",
+ "rb_cArray" => "Array",
+ "rb_cBignum" => "Bignum",
+ "rb_cClass" => "Class",
+ "rb_cDir" => "Dir",
+ "rb_cData" => "Data",
+ "rb_cFalseClass" => "FalseClass",
+ "rb_cFile" => "File",
+ "rb_cFixnum" => "Fixnum",
+ "rb_cFloat" => "Float",
+ "rb_cHash" => "Hash",
+ "rb_cInteger" => "Integer",
+ "rb_cIO" => "IO",
+ "rb_cModule" => "Module",
+ "rb_cNilClass" => "NilClass",
+ "rb_cNumeric" => "Numeric",
+ "rb_cProc" => "Proc",
+ "rb_cRange" => "Range",
+ "rb_cRegexp" => "Regexp",
+ "rb_cString" => "String",
+ "rb_cSymbol" => "Symbol",
+ "rb_cThread" => "Thread",
+ "rb_cTime" => "Time",
+ "rb_cTrueClass" => "TrueClass",
+ "rb_cStruct" => "Struct",
+ "rb_eException" => "Exception",
+ "rb_eStandardError" => "StandardError",
+ "rb_eSystemExit" => "SystemExit",
+ "rb_eInterrupt" => "Interrupt",
+ "rb_eSignal" => "Signal",
+ "rb_eFatal" => "Fatal",
+ "rb_eArgError" => "ArgError",
+ "rb_eEOFError" => "EOFError",
+ "rb_eIndexError" => "IndexError",
+ "rb_eRangeError" => "RangeError",
+ "rb_eIOError" => "IOError",
+ "rb_eRuntimeError" => "RuntimeError",
+ "rb_eSecurityError" => "SecurityError",
+ "rb_eSystemCallError" => "SystemCallError",
+ "rb_eTypeError" => "TypeError",
+ "rb_eZeroDivError" => "ZeroDivError",
+ "rb_eNotImpError" => "NotImpError",
+ "rb_eNoMemError" => "NoMemError",
+ "rb_eFloatDomainError" => "FloatDomainError",
+ "rb_eScriptError" => "ScriptError",
+ "rb_eNameError" => "NameError",
+ "rb_eSyntaxError" => "SyntaxError",
+ "rb_eLoadError" => "LoadError",
+
+ "rb_mKernel" => "Kernel",
+ "rb_mComparable" => "Comparable",
+ "rb_mEnumerable" => "Enumerable",
+ "rb_mPrecision" => "Precision",
+ "rb_mErrno" => "Errno",
+ "rb_mFileTest" => "FileTest",
+ "rb_mGC" => "GC",
+ "rb_mMath" => "Math",
+ "rb_mProcess" => "Process"
+ }
+
+ ##
# We attempt to parse C extension files. Basically we look for
# the standard patterns that you find in extensions: <tt>rb_define_class,
# rb_define_method</tt> and so on. We also try to find the corresponding
@@ -52,8 +127,8 @@
# when the <tt>Init_xxx</tt> method is not named after the class.
#
# [Document-method: <i>name</i>]
- # This comment documents the named method. Use when RDoc cannot outomatically
- # find the method from it's declaration
+ # This comment documents the named method. Use when RDoc cannot
+ # automatically find the method from it's declaration
#
# [call-seq: <i>text up to an empty line</i>]
# Because C source doesn't give descripive names to Ruby-level parameters,
@@ -89,87 +164,13 @@
# */
#
-
- # Classes and modules built in to the interpreter. We need
- # these to define superclasses of user objects
-
-require "rdoc/code_objects"
-require "rdoc/parsers/parserfactory"
-
-
-module RDoc
-
- KNOWN_CLASSES = {
- "rb_cObject" => "Object",
- "rb_cArray" => "Array",
- "rb_cBignum" => "Bignum",
- "rb_cClass" => "Class",
- "rb_cDir" => "Dir",
- "rb_cData" => "Data",
- "rb_cFalseClass" => "FalseClass",
- "rb_cFile" => "File",
- "rb_cFixnum" => "Fixnum",
- "rb_cFloat" => "Float",
- "rb_cHash" => "Hash",
- "rb_cInteger" => "Integer",
- "rb_cIO" => "IO",
- "rb_cModule" => "Module",
- "rb_cNilClass" => "NilClass",
- "rb_cNumeric" => "Numeric",
- "rb_cProc" => "Proc",
- "rb_cRange" => "Range",
- "rb_cRegexp" => "Regexp",
- "rb_cString" => "String",
- "rb_cSymbol" => "Symbol",
- "rb_cThread" => "Thread",
- "rb_cTime" => "Time",
- "rb_cTrueClass" => "TrueClass",
- "rb_cStruct" => "Struct",
- "rb_eException" => "Exception",
- "rb_eStandardError" => "StandardError",
- "rb_eSystemExit" => "SystemExit",
- "rb_eInterrupt" => "Interrupt",
- "rb_eSignal" => "Signal",
- "rb_eFatal" => "Fatal",
- "rb_eArgError" => "ArgError",
- "rb_eEOFError" => "EOFError",
- "rb_eIndexError" => "IndexError",
- "rb_eRangeError" => "RangeError",
- "rb_eIOError" => "IOError",
- "rb_eRuntimeError" => "RuntimeError",
- "rb_eSecurityError" => "SecurityError",
- "rb_eSystemCallError" => "SystemCallError",
- "rb_eTypeError" => "TypeError",
- "rb_eZeroDivError" => "ZeroDivError",
- "rb_eNotImpError" => "NotImpError",
- "rb_eNoMemError" => "NoMemError",
- "rb_eFloatDomainError" => "FloatDomainError",
- "rb_eScriptError" => "ScriptError",
- "rb_eNameError" => "NameError",
- "rb_eSyntaxError" => "SyntaxError",
- "rb_eLoadError" => "LoadError",
-
- "rb_mKernel" => "Kernel",
- "rb_mComparable" => "Comparable",
- "rb_mEnumerable" => "Enumerable",
- "rb_mPrecision" => "Precision",
- "rb_mErrno" => "Errno",
- "rb_mFileTest" => "FileTest",
- "rb_mGC" => "GC",
- "rb_mMath" => "Math",
- "rb_mProcess" => "Process"
-
- }
-
- # See rdoc/c_parse.rb
-
class C_Parser
+ attr_accessor :progress
extend ParserFactory
- parse_files_matching(/\.(c|cc|cpp|CC)$/)
+ parse_files_matching(/\.(?:([CcHh])\1?|c([+xp])\2|y)\z/)
- @@enclosure_classes = {}
@@known_bodies = {}
# prepare to parse a C file
@@ -218,8 +219,9 @@ module RDoc
comment.sub!(/\/?\*--.*/m, '')
end
- # remove lines that are commented out that might otherwise get
- # picked up when scanning for classes and methods
+ ##
+ # removes lines that are commented out that might otherwise get picked up
+ # when scanning for classes and methods
def remove_commented_out_lines
@body.gsub!(%r{//.*rb_define_}, '//')
@@ -231,7 +233,7 @@ module RDoc
parent_name = @known_classes[parent] || parent
if in_module
- enclosure = @classes[in_module] || @@enclosure_classes[in_module]
+ enclosure = @classes[in_module]
unless enclosure
if enclosure = @known_classes[in_module]
handle_class_module(in_module, (/^rb_m/ =~ in_module ? "module" : "class"),
@@ -259,20 +261,54 @@ module RDoc
find_class_comment(cm.full_name, cm)
@classes[var_name] = cm
- @@enclosure_classes[var_name] = cm
@known_classes[var_name] = cm.full_name
end
-
- ############################################################
+ ##
+ # Look for class or module documentation above Init_+class_name+(void),
+ # in a Document-class +class_name+ (or module) comment or above an
+ # rb_define_class (or module). If a comment is supplied above a matching
+ # Init_ and a rb_define_class the Init_ comment is used.
+ #
+ # /*
+ # * This is a comment for Foo
+ # */
+ # Init_Foo(void) {
+ # VALUE cFoo = rb_define_class("Foo", rb_cObject);
+ # }
+ #
+ # /*
+ # * Document-class: Foo
+ # * This is a comment for Foo
+ # */
+ # Init_foo(void) {
+ # VALUE cFoo = rb_define_class("Foo", rb_cObject);
+ # }
+ #
+ # /*
+ # * This is a comment for Foo
+ # */
+ # VALUE cFoo = rb_define_class("Foo", rb_cObject);
def find_class_comment(class_name, class_meth)
comment = nil
if @body =~ %r{((?>/\*.*?\*/\s+))
- (static\s+)?void\s+Init_#{class_name}\s*(?:_\(\s*)?\(\s*(?:void\s*)\)}xmi
+ (static\s+)?void\s+Init_#{class_name}\s*(?:_\(\s*)?\(\s*(?:void\s*)?\)}xmi
comment = $1
elsif @body =~ %r{Document-(class|module):\s#{class_name}\s*?\n((?>.*?\*/))}m
comment = $2
+ else
+ if @body =~ /rb_define_(class|module)/m then
+ class_name = class_name.split("::").last
+ comments = []
+ @body.split(/(\/\*.*?\*\/)\s*?\n/m).each_with_index do |chunk, index|
+ comments[index] = chunk
+ if chunk =~ /rb_define_(class|module).*?"(#{class_name})"/m then
+ comment = comments[index-1]
+ break
+ end
+ end
+ end
end
class_meth.comment = mangle_comment(comment) if comment
end
@@ -427,7 +463,16 @@ module RDoc
end
end
- ############################################################
+ ##
+ # Adds constant comments. By providing some_value: at the start ofthe
+ # comment you can override the C value of the comment to give a friendly
+ # definition.
+ #
+ # /* 300: The perfect score in bowling */
+ # rb_define_const(cFoo, "PERFECT", INT2FIX(300);
+ #
+ # Will override +INT2FIX(300)+ with the value +300+ in the output RDoc.
+ # Values may include quotes and escaped colons (\:).
def handle_constants(type, var_name, const_name, definition)
#@stats.num_constants += 1
@@ -444,14 +489,39 @@ module RDoc
comment = find_const_comment(type, const_name)
- con = Constant.new(const_name, definition, mangle_comment(comment))
+ # In the case of rb_define_const, the definition and comment are in
+ # "/* definition: comment */" form. The literal ':' and '\' characters
+ # can be escaped with a backslash.
+ if type.downcase == 'const' then
+ elements = mangle_comment(comment).split(':')
+ if elements.nil? or elements.empty? then
+ con = Constant.new(const_name, definition, mangle_comment(comment))
+ else
+ new_definition = elements[0..-2].join(':')
+ if new_definition.empty? then # Default to literal C definition
+ new_definition = definition
+ else
+ new_definition.gsub!("\:", ":")
+ new_definition.gsub!("\\", '\\')
+ end
+ new_definition.sub!(/\A(\s+)/, '')
+ new_comment = $1.nil? ? elements.last : "#{$1}#{elements.last.lstrip}"
+ con = Constant.new(const_name, new_definition,
+ mangle_comment(new_comment))
+ end
+ else
+ con = Constant.new(const_name, definition, mangle_comment(comment))
+ end
+
class_obj.add_constant(con)
end
- ###########################################################
+ ##
+ # Finds a comment matching +type+ and +const_name+ either above the
+ # comment or in the matching Document- section.
def find_const_comment(type, const_name)
- if @body =~ %r{((?>/\*.*?\*/\s+))
+ if @body =~ %r{((?>^\s*/\*.*?\*/\s+))
rb_define_#{type}\((?:\s*(\w+),)?\s*"#{const_name}"\s*,.*?\)\s*;}xmi
$1
elsif @body =~ %r{Document-(?:const|global|variable):\s#{const_name}\s*?\n((?>.*?\*/))}m
@@ -556,7 +626,7 @@ module RDoc
def find_body(meth_name, meth_obj, body, quiet = false)
case body
when %r{((?>/\*.*?\*/\s*))(?:static\s+)?VALUE\s+#{meth_name}
- \s*(\([^)]*\))\s*\{.*?^\}}xm
+ \s*(\(.*?\)).*?^}xm
comment, params = $1, $2
body_text = $&
@@ -612,13 +682,15 @@ module RDoc
end
- ##################################################
- #
- # If the comment block contains a section that looks like
+ ##
+ # If the comment block contains a section that looks like:
+ #
# call-seq:
# Array.new
# Array.new(10)
- # use it for the parameters
+ #
+ # use it for the parameters.
+
def find_modifiers(comment, meth_obj)
if comment.sub!(/:nodoc:\s*^\s*\*?\s*$/m, '') or
comment.sub!(/\A\/\*\s*:nodoc:\s*\*\/\Z/, '')
@@ -641,10 +713,11 @@ module RDoc
end
end
- ############################################################
-
- # Look for includes of the form
+ ##
+ # Look for includes of the form:
+ #
# rb_include_module(rb_cArray, rb_mEnumerable);
+
def do_includes
@body.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
if cls = @classes[c]
@@ -654,8 +727,7 @@ module RDoc
end
end
- ############################################################
-
+ ##
# Remove the /*'s and leading asterisks from C comments
def mangle_comment(comment)
@@ -688,7 +760,8 @@ module RDoc
end
end
- # Remove #ifdefs that would otherwise confuse us
+ ##
+ # Removes #ifdefs that would otherwise confuse us
def handle_ifdefs_in(body)
body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m) { $1 }
@@ -697,3 +770,4 @@ module RDoc
end
end
+
diff --git a/lib/rdoc/parsers/parse_rb.rb b/lib/rdoc/parsers/parse_rb.rb
index 8fe9da6ae8..750c483c15 100644
--- a/lib/rdoc/parsers/parse_rb.rb
+++ b/lib/rdoc/parsers/parse_rb.rb
@@ -466,10 +466,11 @@ class RubyLex
@exception_on_syntax_error = true
end
- attr_accessor :skip_space
- attr_accessor :read_auto_clean_up
- attr_accessor :exception_on_syntax_error
- attr_reader :indent
+ attr :skip_space, true
+ attr :read_auto_clean_up, true
+ attr :exception_on_syntax_error, true
+
+ attr :indent
# io functions
def line_no
@@ -586,7 +587,7 @@ class RubyLex
}
def lex_init()
- @OP = IRB::SLex.new
+ @OP = SLex.new
@OP.def_rules("\0", "\004", "\032") do |chars, io|
Token(TkEND_OF_SCRIPT).set_text(chars)
end
@@ -1476,12 +1477,8 @@ module RDoc
if tk.kind_of?(TkSYMBEG)
set_token_position(tk.line_no, tk.char_no)
tk1 = get_tk
- if tk1.kind_of?(TkId) || tk1.kind_of?(TkOp) || tk1.kind_of?(TkSTRING)
- if tk1.respond_to?(:name)
- tk = Token(TkSYMBOL).set_text(":" + tk1.name)
- else
- tk = Token(TkSYMBOL).set_text(":" + tk1.text)
- end
+ if tk1.kind_of?(TkId) || tk1.kind_of?(TkOp)
+ tk = Token(TkSYMBOL).set_text(":" + tk1.name)
# remove the identifier we just read (we're about to
# replace it with a symbol)
@token_listeners.each do |obj|
@@ -1549,10 +1546,15 @@ module RDoc
tk = get_tk
while tk.kind_of?(TkCOMMENT)
- if first_line && tk.text[0,2] == "#!"
+ if first_line && /\A#!/ =~ tk.text
+ skip_tkspace
+ tk = get_tk
+ elsif first_line && /\A#\s*-\*-/ =~ tk.text
+ first_line = false
skip_tkspace
tk = get_tk
else
+ first_line = false
res << tk.text << "\n"
tk = get_tk
if tk.kind_of? TkNL
@@ -1560,7 +1562,6 @@ module RDoc
tk = get_tk
end
end
- first_line = false
end
unget_tk(tk)
res
@@ -2337,7 +2338,7 @@ module RDoc
when "section"
context.set_current_section(param, comment)
- comment.clear
+ comment.replace("") # 1.8 doesn't support #clear
break
else
warn "Unrecognized directive '#{directive}'"
diff --git a/lib/rdoc/ri/ri_display.rb b/lib/rdoc/ri/ri_display.rb
index 8e5d07ee6c..67962fc2c1 100644
--- a/lib/rdoc/ri/ri_display.rb
+++ b/lib/rdoc/ri/ri_display.rb
@@ -236,7 +236,6 @@ class DefaultDisplay
@formatter.break_to_newline
end
end
-
######################################################################
def display_flow(flow)
diff --git a/lib/rdoc/ri/ri_paths.rb b/lib/rdoc/ri/ri_paths.rb
index 4a67e44ba5..32363bf70a 100644
--- a/lib/rdoc/ri/ri_paths.rb
+++ b/lib/rdoc/ri/ri_paths.rb
@@ -26,9 +26,9 @@ module RI
DOC_DIR = "doc/rdoc"
- version = RbConfig::CONFIG['ruby_version']
+ version = Config::CONFIG['ruby_version']
- base = File.join(RbConfig::CONFIG['datadir'], "ri", version)
+ base = File.join(Config::CONFIG['datadir'], "ri", version)
SYSDIR = File.join(base, "system")
SITEDIR = File.join(base, "site")
homedir = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
diff --git a/lib/rdoc/ri/ri_writer.rb b/lib/rdoc/ri/ri_writer.rb
index 032558ed1c..78c68e8409 100644
--- a/lib/rdoc/ri/ri_writer.rb
+++ b/lib/rdoc/ri/ri_writer.rb
@@ -13,7 +13,7 @@ module RI
# by %xx)
def RiWriter.internal_to_external(name)
- name.gsub(/\W/) { "%%%02x" % $&[0].ord }
+ name.gsub(/\W/) { sprintf("%%%02x", $&[0]) }
end
# And the reverse operation
diff --git a/lib/resolv-replace.rb b/lib/resolv-replace.rb
index 5d15b4577c..63d58cea27 100644
--- a/lib/resolv-replace.rb
+++ b/lib/resolv-replace.rb
@@ -23,7 +23,8 @@ end
class UDPSocket
alias original_resolv_bind bind
def bind(host, port)
- original_resolv_bind(IPSocket.getaddress(host), port)
+ host = IPSocket.getaddress(host) if host != ""
+ original_resolv_bind(host, port)
end
alias original_resolv_connect connect
diff --git a/lib/resolv.rb b/lib/resolv.rb
index deceeaba30..3f79ecc62c 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -1,106 +1,244 @@
+=begin
+= resolv library
+resolv.rb is a resolver library written in Ruby.
+Since it is written in Ruby, it is thread-aware.
+I.e. it can resolv many hostnames concurrently.
+
+It is possible to lookup various resources of DNS using DNS module directly.
+
+== example
+ p Resolv.getaddress("www.ruby-lang.org")
+ p Resolv.getname("210.251.121.214")
+
+ Resolv::DNS.open {|dns|
+ p dns.getresources("www.ruby-lang.org", Resolv::DNS::Resource::IN::A).collect {|r| r.address}
+ p dns.getresources("ruby-lang.org", Resolv::DNS::Resource::IN::MX).collect {|r| [r.exchange.to_s, r.preference]}
+ }
+
+== Resolv class
+
+=== class methods
+--- Resolv.getaddress(name)
+--- Resolv.getaddresses(name)
+--- Resolv.each_address(name) {|address| ...}
+ They lookups IP addresses of ((|name|)) which represents a hostname
+ as a string by default resolver.
+
+ getaddress returns first entry of lookupped addresses.
+ getaddresses returns lookupped addresses as an array.
+ each_address iterates over lookupped addresses.
+
+--- Resolv.getname(address)
+--- Resolv.getnames(address)
+--- Resolv.each_name(address) {|name| ...}
+ lookups hostnames of ((|address|)) which represents IP address as a string.
+
+ getname returns first entry of lookupped names.
+ getnames returns lookupped names as an array.
+ each_names iterates over lookupped names.
+
+== Resolv::Hosts class
+hostname resolver using /etc/hosts format.
+
+=== class methods
+--- Resolv::Hosts.new(hosts='/etc/hosts')
+
+=== methods
+--- Resolv::Hosts#getaddress(name)
+--- Resolv::Hosts#getaddresses(name)
+--- Resolv::Hosts#each_address(name) {|address| ...}
+ address lookup methods.
+
+--- Resolv::Hosts#getname(address)
+--- Resolv::Hosts#getnames(address)
+--- Resolv::Hosts#each_name(address) {|name| ...}
+ hostnames lookup methods.
+
+== Resolv::DNS class
+DNS stub resolver.
+
+=== class methods
+--- Resolv::DNS.new(config_info=nil)
+
+ ((|config_info|)) should be nil, a string or a hash.
+ If nil is given, /etc/resolv.conf and platform specific information is used.
+ If a string is given, it should be a filename which format is same as /etc/resolv.conf.
+ If a hash is given, it may contains information for nameserver, search and ndots as follows.
+
+ Resolv::DNS.new({:nameserver=>["210.251.121.21"], :search=>["ruby-lang.org"], :ndots=>1})
+
+--- Resolv::DNS.open(config_info=nil)
+--- Resolv::DNS.open(config_info=nil) {|dns| ...}
+
+=== methods
+--- Resolv::DNS#close
+
+--- Resolv::DNS#getaddress(name)
+--- Resolv::DNS#getaddresses(name)
+--- Resolv::DNS#each_address(name) {|address| ...}
+ address lookup methods.
+
+ ((|name|)) must be a instance of Resolv::DNS::Name or String. Lookupped
+ address is represented as an instance of Resolv::IPv4 or Resolv::IPv6.
+
+--- Resolv::DNS#getname(address)
+--- Resolv::DNS#getnames(address)
+--- Resolv::DNS#each_name(address) {|name| ...}
+ hostnames lookup methods.
+
+ ((|address|)) must be a instance of Resolv::IPv4, Resolv::IPv6 or String.
+ Lookupped name is represented as an instance of Resolv::DNS::Name.
+
+--- Resolv::DNS#getresource(name, typeclass)
+--- Resolv::DNS#getresources(name, typeclass)
+--- Resolv::DNS#each_resource(name, typeclass) {|resource| ...}
+ They lookup DNS resources of ((|name|)).
+ ((|name|)) must be a instance of Resolv::Name or String.
+
+ ((|typeclass|)) should be one of follows:
+ * Resolv::DNS::Resource::IN::ANY
+ * Resolv::DNS::Resource::IN::NS
+ * Resolv::DNS::Resource::IN::CNAME
+ * Resolv::DNS::Resource::IN::SOA
+ * Resolv::DNS::Resource::IN::HINFO
+ * Resolv::DNS::Resource::IN::MINFO
+ * Resolv::DNS::Resource::IN::MX
+ * Resolv::DNS::Resource::IN::TXT
+ * Resolv::DNS::Resource::IN::ANY
+ * Resolv::DNS::Resource::IN::A
+ * Resolv::DNS::Resource::IN::WKS
+ * Resolv::DNS::Resource::IN::PTR
+ * Resolv::DNS::Resource::IN::AAAA
+
+ Lookupped resource is represented as an instance of (a subclass of)
+ Resolv::DNS::Resource.
+ (Resolv::DNS::Resource::IN::A, etc.)
+
+== Resolv::DNS::Resource::IN::NS class
+--- name
+== Resolv::DNS::Resource::IN::CNAME class
+--- name
+== Resolv::DNS::Resource::IN::SOA class
+--- mname
+--- rname
+--- serial
+--- refresh
+--- retry
+--- expire
+--- minimum
+== Resolv::DNS::Resource::IN::HINFO class
+--- cpu
+--- os
+== Resolv::DNS::Resource::IN::MINFO class
+--- rmailbx
+--- emailbx
+== Resolv::DNS::Resource::IN::MX class
+--- preference
+--- exchange
+== Resolv::DNS::Resource::IN::TXT class
+--- data
+== Resolv::DNS::Resource::IN::A class
+--- address
+== Resolv::DNS::Resource::IN::WKS class
+--- address
+--- protocol
+--- bitmap
+== Resolv::DNS::Resource::IN::PTR class
+--- name
+== Resolv::DNS::Resource::IN::AAAA class
+--- address
+
+== Resolv::DNS::Name class
+
+=== class methods
+--- Resolv::DNS::Name.create(name)
+
+=== methods
+--- Resolv::DNS::Name#to_s
+
+== Resolv::DNS::Resource class
+
+== Resolv::IPv4 class
+=== class methods
+--- Resolv::IPv4.create(address)
+
+=== methods
+--- Resolv::IPv4#to_s
+--- Resolv::IPv4#to_name
+
+=== constants
+--- Resolv::IPv4::Regex
+ regular expression for IPv4 address.
+
+== Resolv::IPv6 class
+=== class methods
+--- Resolv::IPv6.create(address)
+
+=== methods
+--- Resolv::IPv6#to_s
+--- Resolv::IPv6#to_name
+
+=== constants
+--- Resolv::IPv6::Regex
+ regular expression for IPv6 address.
+
+== Bugs
+* NIS is not supported.
+* /etc/nsswitch.conf is not supported.
+* IPv6 is not supported.
+
+=end
+
require 'socket'
require 'fcntl'
require 'timeout'
require 'thread'
-# Resolv is a thread-aware DNS resolver library written in Ruby. Resolv can
-# handle multiple DNS requests concurrently without blocking. The ruby
-# interpreter.
-#
-# See also resolv-replace.rb to replace the libc resolver with # Resolv.
-#
-# Resolv can look up various DNS resources using the DNS module directly.
-#
-# Examples:
-#
-# p Resolv.getaddress "www.ruby-lang.org"
-# p Resolv.getname "210.251.121.214"
-#
-# Resolv::DNS.open do |dns|
-# ress = dns.getresources "www.ruby-lang.org", Resolv::DNS::Resource::IN::A
-# p ress.map { |r| r.address }
-# ress = dns.getresources "ruby-lang.org", Resolv::DNS::Resource::IN::MX
-# p ress.map { |r| [r.exchange.to_s, r.preference] }
-# end
-#
-#
-# == Bugs
-#
-# * NIS is not supported.
-# * /etc/nsswitch.conf is not supported.
-# * IPv6 is not supported.
+begin
+ require 'securerandom'
+rescue LoadError
+end
class Resolv
-
- ##
- # Looks up the first IP address for +name+.
-
def self.getaddress(name)
DefaultResolver.getaddress(name)
end
- ##
- # Looks up all IP address for +name+.
-
def self.getaddresses(name)
DefaultResolver.getaddresses(name)
end
- ##
- # Iterates over all IP addresses for +name+.
-
def self.each_address(name, &block)
DefaultResolver.each_address(name, &block)
end
- ##
- # Looks up the hostname of +address+.
-
def self.getname(address)
DefaultResolver.getname(address)
end
- ##
- # Looks up all hostnames for +address+.
-
def self.getnames(address)
DefaultResolver.getnames(address)
end
- ##
- # Iterates over all hostnames for +address+.
-
def self.each_name(address, &proc)
DefaultResolver.each_name(address, &proc)
end
- ##
- # Creates a new Resolv using +resolvers+.
-
def initialize(resolvers=[Hosts.new, DNS.new])
@resolvers = resolvers
end
- ##
- # Looks up the first IP address for +name+.
-
def getaddress(name)
each_address(name) {|address| return address}
raise ResolvError.new("no address for #{name}")
end
- ##
- # Looks up all IP address for +name+.
-
def getaddresses(name)
ret = []
each_address(name) {|address| ret << address}
return ret
end
- ##
- # Iterates over all IP addresses for +name+.
-
def each_address(name)
if AddressRegex =~ name
yield name
@@ -116,26 +254,17 @@ class Resolv
}
end
- ##
- # Looks up the hostname of +address+.
-
def getname(address)
each_name(address) {|name| return name}
raise ResolvError.new("no name for #{address}")
end
- ##
- # Looks up all hostnames for +address+.
-
def getnames(address)
ret = []
each_name(address) {|name| ret << name}
return ret
end
- ##
- # Iterates over all hostnames for +address+.
-
def each_name(address)
yielded = false
@resolvers.each {|r|
@@ -147,37 +276,27 @@ class Resolv
}
end
- ##
- # Indicates a failure to resolve a name or address.
-
- class ResolvError < StandardError; end
-
- ##
- # Indicates a timeout resolving a name or address.
-
- class ResolvTimeout < TimeoutError; end
+ class ResolvError < StandardError
+ end
- ##
- # DNS::Hosts is a hostname resolver that uses the system hosts file.
+ class ResolvTimeout < TimeoutError
+ end
class Hosts
- if /mswin32|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
+ if /mswin32|mingw|bccwin/ =~ RUBY_PLATFORM
require 'win32/resolv'
DefaultFileName = Win32::Resolv.get_hosts_path
else
DefaultFileName = '/etc/hosts'
end
- ##
- # Creates a new DNS::Hosts, using +filename+ for its data source.
-
def initialize(filename = DefaultFileName)
@filename = filename
@mutex = Mutex.new
@initialized = nil
end
- def lazy_initialize # :nodoc:
+ def lazy_initialize
@mutex.synchronize {
unless @initialized
@name2addr = {}
@@ -208,26 +327,17 @@ class Resolv
self
end
- ##
- # Gets the IP address of +name+ from the hosts file.
-
def getaddress(name)
each_address(name) {|address| return address}
raise ResolvError.new("#{@filename} has no name: #{name}")
end
- ##
- # Gets all IP addresses for +name+ from the hosts file.
-
def getaddresses(name)
ret = []
each_address(name) {|address| ret << address}
return ret
end
- ##
- # Iterates over all IP addresses for +name+ retrieved from the hosts file.
-
def each_address(name, &proc)
lazy_initialize
if @name2addr.include?(name)
@@ -235,26 +345,17 @@ class Resolv
end
end
- ##
- # Gets the hostname of +address+ from the hosts file.
-
def getname(address)
each_name(address) {|name| return name}
raise ResolvError.new("#{@filename} has no address: #{address}")
end
- ##
- # Gets all hostnames for +address+ from the hosts file.
-
def getnames(address)
ret = []
each_name(address) {|name| ret << name}
return ret
end
- ##
- # Iterates over all hostnames for +address+ retrived from the hosts file.
-
def each_name(address, &proc)
lazy_initialize
if @addr2name.include?(address)
@@ -263,39 +364,15 @@ class Resolv
end
end
- ##
- # Resolv::DNS is a DNS stub resolver.
- #
- # Information taken from the following places:
- #
- # * STD0013
- # * RFC 1035
- # * ftp://ftp.isi.edu/in-notes/iana/assignments/dns-parameters
- # * etc.
-
class DNS
-
- ##
- # Default DNS Port
+ # STD0013 (RFC 1035, etc.)
+ # ftp://ftp.isi.edu/in-notes/iana/assignments/dns-parameters
Port = 53
-
- ##
- # Default DNS UDP packet size
-
UDPSize = 512
- ##
- # Group of DNS resolver threads
-
DNSThreadGroup = ThreadGroup.new
- ##
- # Creates a new DNS resolver. See Resolv::DNS.new for argument details.
- #
- # Yields the created DNS resolver to the block, if given, otherwise
- # returns it.
-
def self.open(*args)
dns = new(*args)
return dns unless block_given?
@@ -306,121 +383,56 @@ class Resolv
end
end
- ##
- # Creates a new DNS resolver.
- #
- # +config_info+ can be:
- #
- # nil:: Uses /etc/resolv.conf.
- # String:: Path to a file using /etc/resolv.conf's format.
- # Hash:: Must contain :nameserver, :search and :ndots keys.
- #
- # Example:
- #
- # Resolv::DNS.new(:nameserver => ['210.251.121.21'],
- # :search => ['ruby-lang.org'],
- # :ndots => 1)
-
def initialize(config_info=nil)
@mutex = Mutex.new
@config = Config.new(config_info)
@initialized = nil
end
- def lazy_initialize # :nodoc:
+ def lazy_initialize
@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
}
self
end
- ##
- # Closes the DNS resolver.
-
def close
@mutex.synchronize {
if @initialized
- @requester.close if @requester
- @requester = nil
@initialized = false
end
}
end
- ##
- # Gets the IP address of +name+ from the DNS resolver.
- #
- # +name+ can be a Resolv::DNS::Name or a String. Retrieved address will
- # be a Resolv::IPv4 or Resolv::IPv6
-
def getaddress(name)
each_address(name) {|address| return address}
raise ResolvError.new("DNS result has no information for #{name}")
end
- ##
- # Gets all IP addresses for +name+ from the DNS resolver.
- #
- # +name+ can be a Resolv::DNS::Name or a String. Retrieved addresses will
- # be a Resolv::IPv4 or Resolv::IPv6
-
def getaddresses(name)
ret = []
each_address(name) {|address| ret << address}
return ret
end
- ##
- # Iterates over all IP addresses for +name+ retrieved from the DNS
- # resolver.
- #
- # +name+ can be a Resolv::DNS::Name or a String. Retrieved addresses will
- # be a Resolv::IPv4 or Resolv::IPv6
-
def each_address(name)
each_resource(name, Resource::IN::A) {|resource| yield resource.address}
end
- ##
- # Gets the hostname for +address+ from the DNS resolver.
- #
- # +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
- # name will be a Resolv::DNS::Name.
-
def getname(address)
each_name(address) {|name| return name}
raise ResolvError.new("DNS result has no information for #{address}")
end
- ##
- # Gets all hostnames for +address+ from the DNS resolver.
- #
- # +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
- # names will be Resolv::DNS::Name instances.
-
def getnames(address)
ret = []
each_name(address) {|name| ret << name}
return ret
end
- ##
- # Iterates over all hostnames for +address+ retrieved from the DNS
- # resolver.
- #
- # +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
- # names will be Resolv::DNS::Name instances.
-
def each_name(address)
case address
when Name
@@ -435,52 +447,20 @@ class Resolv
each_resource(ptr, Resource::IN::PTR) {|resource| yield resource.name}
end
- ##
- # Look up the +typeclass+ DNS resource of +name+.
- #
- # +name+ must be a Resolv::DNS::Name or a String.
- #
- # +typeclass+ should be one of the following:
- #
- # * Resolv::DNS::Resource::IN::A
- # * Resolv::DNS::Resource::IN::AAAA
- # * Resolv::DNS::Resource::IN::ANY
- # * Resolv::DNS::Resource::IN::ANY
- # * Resolv::DNS::Resource::IN::CNAME
- # * Resolv::DNS::Resource::IN::HINFO
- # * Resolv::DNS::Resource::IN::MINFO
- # * Resolv::DNS::Resource::IN::MX
- # * Resolv::DNS::Resource::IN::NS
- # * Resolv::DNS::Resource::IN::PTR
- # * Resolv::DNS::Resource::IN::SOA
- # * Resolv::DNS::Resource::IN::TXT
- # * Resolv::DNS::Resource::IN::WKS
- #
- # Returned resource is represented as a Resolv::DNS::Resource instance,
- # i.e. Resolv::DNS::Resource::IN::A.
-
def getresource(name, typeclass)
each_resource(name, typeclass) {|resource| return resource}
raise ResolvError.new("DNS result has no information for #{name}")
end
- ##
- # Looks up all +typeclass+ DNS resources for +name+. See #getresource for
- # argument details.
-
def getresources(name, typeclass)
ret = []
each_resource(name, typeclass) {|resource| ret << resource}
return ret
end
- ##
- # Iterates over all +typeclass+ DNS resources for +name+. See
- # #getresource for argument details.
-
def each_resource(name, typeclass, &proc)
lazy_initialize
- q = Queue.new
+ requester = make_requester
senders = {}
begin
@config.resolv(name) {|candidate, tout, nameserver|
@@ -489,11 +469,9 @@ class Resolv
msg.add_question(candidate, typeclass)
unless sender = senders[[candidate, nameserver]]
sender = senders[[candidate, nameserver]] =
- @requester.sender(msg, candidate, q, nameserver)
+ requester.sender(msg, candidate, nameserver)
end
- sender.send
- reply = reply_name = nil
- timeout(tout, ResolvTimeout) { reply, reply_name = q.pop }
+ reply, reply_name = requester.request(sender, tout)
case reply.rcode
when RCode::NoError
extract_resources(reply, reply_name, typeclass, &proc)
@@ -505,11 +483,19 @@ class Resolv
end
}
ensure
- @requester.delete(q)
+ requester.close
+ end
+ end
+
+ def make_requester # :nodoc:
+ if nameserver = @config.single?
+ Requester::ConnectedUDP.new(nameserver)
+ else
+ Requester::UnconnectedUDP.new
end
end
- def extract_resources(msg, name, typeclass) # :nodoc:
+ def extract_resources(msg, name, typeclass)
if typeclass < Resource::ANY
n0 = Name.create(name)
msg.each_answer {|n, ttl, data|
@@ -540,91 +526,144 @@ class Resolv
}
end
- class Requester # :nodoc:
- def initialize
- @senders = {}
+ 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 close
- thread, sock, @thread, @sock = @thread, @sock
+ 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
- if thread
- thread.kill
- thread.join
+ 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
- ensure
- sock.close if sock
end
+ }
+ end
+
+ def self.bind_random_port(udpsock) # :nodoc:
+ begin
+ port = rangerand(1024..65535)
+ udpsock.bind("", port)
+ rescue Errno::EADDRINUSE
+ retry
end
+ end
- 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}")
+ 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
+ end
end
+ return msg, s.data
+ end
+
+ def close
+ sock = @sock
+ @sock = nil
+ sock.close if sock
end
class Sender # :nodoc:
- def initialize(msg, data, sock, queue)
+ def initialize(msg, data, sock)
@msg = msg
@data = data
@sock = sock
- @queue = queue
- end
- attr_reader :queue
-
- def recv(msg)
- @queue.push([msg, @data])
end
end
- class UnconnectedUDP < Requester # :nodoc:
+ class UnconnectedUDP < Requester
def initialize
super()
@sock = UDPSocket.new
- @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
- }
- }
+ @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]]
end
- def sender(msg, data, queue, host, port=Port)
+ def sender(msg, data, host, port=Port)
service = [host, port]
- id = Thread.exclusive {
- @id[service] = (@id[service] + 1) & 0xffff
- }
+ id = DNS.allocate_request_id(host, port)
request = msg.encode
request[0,2] = [id].pack('n')
return @senders[[service, id]] =
- Sender.new(request, data, @sock, host, port, queue)
+ 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)
+ }
end
- class Sender < Requester::Sender # :nodoc:
- def initialize(msg, data, sock, host, port, queue)
- super(msg, data, sock, queue)
+ class Sender < Requester::Sender
+ def initialize(msg, data, sock, host, port)
+ super(msg, data, sock)
@host = host
@port = port
end
+ attr_reader :data
def send
@sock.send(@msg, 0, @host, @port)
@@ -632,107 +671,94 @@ class Resolv
end
end
- class ConnectedUDP < Requester # :nodoc:
+ class ConnectedUDP < Requester
def initialize(host, port=Port)
super()
@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, 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
- }
- }
+ @sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
+ end
+
+ def recv_reply
+ reply = @sock.recv(UDPSize)
+ return reply, nil
end
- def sender(msg, data, queue, host=@host, port=@port)
+ def sender(msg, data, host=@host, port=@port)
unless host == @host && port == @port
raise RequestError.new("host/port don't match: #{host}:#{port}")
end
- id = Thread.exclusive { @id = (@id + 1) & 0xffff }
+ id = DNS.allocate_request_id(@host, @port)
request = msg.encode
request[0,2] = [id].pack('n')
- return @senders[id] = Sender.new(request, data, @sock, queue)
+ return @senders[[nil,id]] = Sender.new(request, data, @sock)
end
- class Sender < Requester::Sender # :nodoc:
+ def close
+ super
+ @senders.each_key {|from, id|
+ DNS.free_request_id(@host, @port, id)
+ }
+ end
+
+ class Sender < Requester::Sender
def send
@sock.send(@msg, 0)
end
+ attr_reader :data
end
end
- class TCP < Requester # :nodoc:
+ class TCP < Requester
def initialize(host, port=Port)
super()
@host = host
@port = port
- @sock = TCPSocket.new
- @sock.connect(host, port)
- @sock.fcntl(Fcntl::F_SETFD, 1) if defined? Fcntl::F_SETFD
- @id = -1
+ @sock = TCPSocket.new(@host, @port)
+ @sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
@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 sender(msg, data, queue, host=@host, port=@port)
+ 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)
unless host == @host && port == @port
raise RequestError.new("host/port don't match: #{host}:#{port}")
end
- id = Thread.exclusive { @id = (@id + 1) & 0xffff }
+ id = DNS.allocate_request_id(@host, @port)
request = msg.encode
request[0,2] = [request.length, id].pack('nn')
- return @senders[id] = Sender.new(request, data, @sock, queue)
+ return @senders[[nil,id]] = Sender.new(request, data, @sock)
end
- class Sender < Requester::Sender # :nodoc:
+ class Sender < Requester::Sender
def send
@sock.print(@msg)
@sock.flush
end
+ attr_reader :data
end
- end
- ##
- # Indicates a problem with the DNS request.
+ def close
+ super
+ @senders.each_key {|from,id|
+ DNS.free_request_id(@host, @port, id)
+ }
+ end
+ end
class RequestError < StandardError
end
end
- class Config # :nodoc:
+ class Config
def initialize(config_info=nil)
@mutex = Mutex.new
@config_info = config_info
@@ -778,6 +804,7 @@ 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
@@ -902,20 +929,14 @@ class Resolv
end
end
- ##
- # Indicates no such domain was found.
-
class NXDomain < ResolvError
end
- ##
- # Indicates some other unhandled resolver error was encountered.
-
class OtherResolvError < ResolvError
end
end
- module OpCode # :nodoc:
+ module OpCode
Query = 0
IQuery = 1
Status = 2
@@ -923,7 +944,7 @@ class Resolv
Update = 5
end
- module RCode # :nodoc:
+ module RCode
NoError = 0
FormErr = 1
ServFail = 2
@@ -944,26 +965,20 @@ class Resolv
BADALG = 21
end
- ##
- # Indicates that the DNS response was unable to be decoded.
-
class DecodeError < StandardError
end
- ##
- # Indicates that the DNS request was unable to be encoded.
-
class EncodeError < StandardError
end
- module Label # :nodoc:
+ module Label
def self.split(arg)
labels = []
arg.scan(/[^\.]+/) {labels << Str.new($&)}
return labels
end
- class Str # :nodoc:
+ class Str
def initialize(string)
@string = string
@downcase = string.downcase
@@ -992,17 +1007,7 @@ class Resolv
end
end
- ##
- # A representation of a DNS name.
-
class Name
-
- ##
- # Creates a new DNS name from +arg+. +arg+ can be:
- #
- # Name:: returns +arg+.
- # String:: Creates a new Name.
-
def self.create(arg)
case arg
when Name
@@ -1014,33 +1019,26 @@ class Resolv
end
end
- def initialize(labels, absolute=true) # :nodoc:
+ def initialize(labels, absolute=true)
@labels = labels
@absolute = absolute
end
- def inspect # :nodoc:
+ def inspect
"#<#{self.class}: #{self.to_s}#{@absolute ? '.' : ''}>"
end
- ##
- # True if this name is absolute.
-
def absolute?
return @absolute
end
- def ==(other) # :nodoc:
+ def ==(other)
return false unless Name === other
return @labels == other.to_a && @absolute == other.absolute?
end
+ alias eql? ==
- alias eql? == # :nodoc:
-
- ##
- # Returns true if +other+ is a subdomain.
- #
- # Example:
+ # tests subdomain-of relation.
#
# domain = Resolv::DNS::Name.create("y.z")
# p Resolv::DNS::Name.create("w.x.y.z").subdomain_of?(domain) #=> true
@@ -1050,7 +1048,6 @@ class Resolv
# p Resolv::DNS::Name.create("x.y.z.").subdomain_of?(domain) #=> false
# p Resolv::DNS::Name.create("w.z").subdomain_of?(domain) #=> false
#
-
def subdomain_of?(other)
raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other
return false if @absolute != other.absolute?
@@ -1059,39 +1056,36 @@ class Resolv
return @labels[-other_len, other_len] == other.to_a
end
- def hash # :nodoc:
+ def hash
return @labels.hash ^ @absolute.hash
end
- def to_a # :nodoc:
+ def to_a
return @labels
end
- def length # :nodoc:
+ def length
return @labels.length
end
- def [](i) # :nodoc:
+ def [](i)
return @labels[i]
end
- ##
# returns the domain name as a string.
#
# The domain name doesn't have a trailing dot even if the name object is
# absolute.
#
- # Example:
- #
# p Resolv::DNS::Name.create("x.y.z.").to_s #=> "x.y.z"
# p Resolv::DNS::Name.create("x.y.z").to_s #=> "x.y.z"
-
+ #
def to_s
return @labels.join('.')
end
end
- class Message # :nodoc:
+ class Message
@@identifier = -1
def initialize(id = (@@identifier += 1) & 0xffff)
@@ -1204,7 +1198,7 @@ class Resolv
}.to_s
end
- class MessageEncoder # :nodoc:
+ class MessageEncoder
def initialize
@data = ''
@names = {}
@@ -1299,7 +1293,7 @@ class Resolv
return o
end
- class MessageDecoder # :nodoc:
+ class MessageDecoder
def initialize(data)
@data = data
@index = 0
@@ -1330,7 +1324,6 @@ class Resolv
def get_unpack(template)
len = 0
template.each_byte {|byte|
- byte = "%c" % byte
case byte
when ?c, ?C
len += 1
@@ -1349,7 +1342,7 @@ class Resolv
end
def get_string
- len = @data[@index].ord
+ len = @data[@index]
raise DecodeError.new("limit exceeded") if @limit < @index + 1 + len
d = @data[@index + 1, len]
@index += 1 + len
@@ -1372,7 +1365,7 @@ class Resolv
limit = @index if !limit || @index < limit
d = []
while true
- case @data[@index].ord
+ case @data[@index]
when 0
@index += 1
return d
@@ -1407,104 +1400,71 @@ class Resolv
name = self.get_name
type, klass, ttl = self.get_unpack('nnN')
typeclass = Resource.get_class(type, klass)
- res = self.get_length16 { typeclass.decode_rdata self }
- res.instance_variable_set :@ttl, ttl
- return name, ttl, res
+ return name, ttl, self.get_length16 {typeclass.decode_rdata(self)}
end
end
end
- ##
- # A DNS query abstract class.
-
class Query
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
raise EncodeError.new("#{self.class} is query.")
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
raise DecodeError.new("#{self.class} is query.")
end
end
- ##
- # A DNS resource abstract class.
-
class Resource < Query
+ ClassHash = {}
- ##
- # Remaining Time To Live for this Resource.
-
- attr_reader :ttl
-
- ClassHash = {} # :nodoc:
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
raise NotImplementedError.new
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
raise NotImplementedError.new
end
- def ==(other) # :nodoc:
- return false unless self.class == other.class
- s_ivars = self.instance_variables
- s_ivars.sort!
- s_ivars.delete "@ttl"
- o_ivars = other.instance_variables
- o_ivars.sort!
- o_ivars.delete "@ttl"
- return s_ivars == o_ivars &&
- s_ivars.collect {|name| self.instance_variable_get name} ==
- o_ivars.collect {|name| other.instance_variable_get name}
+ def ==(other)
+ return self.class == other.class &&
+ self.instance_variables == other.instance_variables &&
+ self.instance_variables.collect {|name| self.instance_eval name} ==
+ other.instance_variables.collect {|name| other.instance_eval name}
end
- def eql?(other) # :nodoc:
+ def eql?(other)
return self == other
end
- def hash # :nodoc:
+ def hash
h = 0
- vars = self.instance_variables
- vars.delete "@ttl"
- vars.each {|name|
- h ^= self.instance_variable_get(name).hash
+ self.instance_variables.each {|name|
+ h ^= self.instance_eval("#{name}.hash")
}
return h
end
- def self.get_class(type_value, class_value) # :nodoc:
+ def self.get_class(type_value, class_value)
return ClassHash[[type_value, class_value]] ||
Generic.create(type_value, class_value)
end
- ##
- # A generic resource abstract class.
-
class Generic < Resource
-
- ##
- # Creates a new generic resource.
-
def initialize(data)
@data = data
end
-
- ##
- # Data for this generic resource.
-
attr_reader :data
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_bytes(data)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
return self.new(msg.get_bytes)
end
- def self.create(type_value, class_value) # :nodoc:
+ def self.create(type_value, class_value)
c = Class.new(Generic)
c.const_set(:TypeValue, type_value)
c.const_set(:ClassValue, class_value)
@@ -1514,60 +1474,34 @@ class Resolv
end
end
- ##
- # Domain Name resource abstract class.
-
class DomainName < Resource
-
- ##
- # Creates a new DomainName from +name+.
-
def initialize(name)
@name = name
end
-
- ##
- # The name of this DomainName.
-
attr_reader :name
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_name(@name)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
return self.new(msg.get_name)
end
end
# Standard (class generic) RRs
-
- ClassValue = nil # :nodoc:
-
- ##
- # An authoritative name server.
+ ClassValue = nil
class NS < DomainName
- TypeValue = 2 # :nodoc:
+ TypeValue = 2
end
- ##
- # The canonical name for an alias.
-
class CNAME < DomainName
- TypeValue = 5 # :nodoc:
+ TypeValue = 5
end
- ##
- # Start Of Authority resource.
-
class SOA < Resource
-
- TypeValue = 6 # :nodoc:
-
- ##
- # Creates a new SOA record. See the attr documentation for the
- # details of each argument.
+ TypeValue = 6
def initialize(mname, rname, serial, refresh, retry_, expire, minimum)
@mname = mname
@@ -1578,52 +1512,15 @@ class Resolv
@expire = expire
@minimum = minimum
end
+ attr_reader :mname, :rname, :serial, :refresh, :retry, :expire, :minimum
- ##
- # Name of the host where the master zone file for this zone resides.
-
- attr_reader :mname
-
- ##
- # The person responsible for this domain name.
-
- attr_reader :rname
-
- ##
- # The version number of the zone file.
-
- attr_reader :serial
-
- ##
- # How often, in seconds, a secondary name server is to check for
- # updates from the primary name server.
-
- attr_reader :refresh
-
- ##
- # How often, in seconds, a secondary name server is to retry after a
- # failure to check for a refresh.
-
- attr_reader :retry
-
- ##
- # Time in seconds that a secondary name server is to use the data
- # before refreshing from the primary name server.
-
- attr_reader :expire
-
- ##
- # The minimum number of seconds to be used for TTL values in RRs.
-
- attr_reader :minimum
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_name(@mname)
msg.put_name(@rname)
msg.put_pack('NNNNN', @serial, @refresh, @retry, @expire, @minimum)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
mname = msg.get_name
rname = msg.get_name
serial, refresh, retry_, expire, minimum = msg.get_unpack('NNNNN')
@@ -1632,172 +1529,106 @@ class Resolv
end
end
- ##
- # A Pointer to another DNS name.
-
class PTR < DomainName
- TypeValue = 12 # :nodoc:
+ TypeValue = 12
end
- ##
- # Host Information resource.
-
class HINFO < Resource
-
- TypeValue = 13 # :nodoc:
-
- ##
- # Creates a new HINFO running +os+ on +cpu+.
+ TypeValue = 13
def initialize(cpu, os)
@cpu = cpu
@os = os
end
+ attr_reader :cpu, :os
- ##
- # CPU architecture for this resource.
-
- attr_reader :cpu
-
- ##
- # Operating system for this resource.
-
- attr_reader :os
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_string(@cpu)
msg.put_string(@os)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
cpu = msg.get_string
os = msg.get_string
return self.new(cpu, os)
end
end
- ##
- # Mailing list or mailbox information.
-
class MINFO < Resource
-
- TypeValue = 14 # :nodoc:
+ TypeValue = 14
def initialize(rmailbx, emailbx)
@rmailbx = rmailbx
@emailbx = emailbx
end
+ attr_reader :rmailbx, :emailbx
- ##
- # Domain name responsible for this mail list or mailbox.
-
- attr_reader :rmailbx
-
- ##
- # Mailbox to use for error messages related to the mail list or mailbox.
-
- attr_reader :emailbx
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_name(@rmailbx)
msg.put_name(@emailbx)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
rmailbx = msg.get_string
emailbx = msg.get_string
return self.new(rmailbx, emailbx)
end
end
- ##
- # Mail Exchanger resource.
-
class MX < Resource
-
- TypeValue= 15 # :nodoc:
-
- ##
- # Creates a new MX record with +preference+, accepting mail at
- # +exchange+.
+ TypeValue= 15
def initialize(preference, exchange)
@preference = preference
@exchange = exchange
end
+ attr_reader :preference, :exchange
- ##
- # The preference for this MX.
-
- attr_reader :preference
-
- ##
- # The host of this MX.
-
- attr_reader :exchange
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_pack('n', @preference)
msg.put_name(@exchange)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
preference, = msg.get_unpack('n')
exchange = msg.get_name
return self.new(preference, exchange)
end
end
- ##
- # Unstructured text resource.
-
class TXT < Resource
-
- TypeValue = 16 # :nodoc:
+ TypeValue = 16
def initialize(first_string, *rest_strings)
@strings = [first_string, *rest_strings]
end
-
- ##
- # Returns an Array of Strings for this TXT record.
-
attr_reader :strings
- ##
- # Returns the first string from +strings+.
-
def data
@strings[0]
end
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_string_list(@strings)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
strings = msg.get_string_list
return self.new(*strings)
end
end
- ##
- # A Query type requesting any RR.
-
class ANY < Query
- TypeValue = 255 # :nodoc:
+ TypeValue = 255
end
- ClassInsensitiveTypes = [ # :nodoc:
+ ClassInsensitiveTypes = [
NS, CNAME, SOA, PTR, HINFO, MINFO, MX, TXT, ANY
]
- ##
- # module IN contains ARPA Internet specific RRs.
-
+ # ARPA Internet specific RRs
module IN
-
- ClassValue = 1 # :nodoc:
+ ClassValue = 1
ClassInsensitiveTypes.each {|s|
c = Class.new(s)
@@ -1807,76 +1638,40 @@ class Resolv
self.const_set(s.name.sub(/.*::/, ''), c)
}
- ##
- # IPv4 Address resource
-
class A < Resource
- TypeValue = 1
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
-
- ##
- # Creates a new A for +address+.
+ ClassHash[[TypeValue = 1, ClassValue = ClassValue]] = self
def initialize(address)
@address = IPv4.create(address)
end
-
- ##
- # The Resolv::IPv4 address for this A.
-
attr_reader :address
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_bytes(@address.address)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
return self.new(IPv4.new(msg.get_bytes(4)))
end
end
- ##
- # Well Known Service resource.
-
class WKS < Resource
- TypeValue = 11
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
+ ClassHash[[TypeValue = 11, ClassValue = ClassValue]] = self
def initialize(address, protocol, bitmap)
@address = IPv4.create(address)
@protocol = protocol
@bitmap = bitmap
end
+ attr_reader :address, :protocol, :bitmap
- ##
- # The host these services run on.
-
- attr_reader :address
-
- ##
- # IP protocol number for these services.
-
- attr_reader :protocol
-
- ##
- # A bit map of enabled services on this host.
- #
- # If protocol is 6 (TCP) then the 26th bit corresponds to the SMTP
- # service (port 25). If this bit is set, then an SMTP server should
- # be listening on TCP port 25; if zero, SMTP service is not
- # supported.
-
- attr_reader :bitmap
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_bytes(@address.address)
msg.put_pack("n", @protocol)
msg.put_bytes(@bitmap)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
address = IPv4.new(msg.get_bytes(4))
protocol, = msg.get_unpack("n")
bitmap = msg.get_bytes
@@ -1884,51 +1679,55 @@ class Resolv
end
end
- ##
- # An IPv6 address record.
-
class AAAA < Resource
- TypeValue = 28
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
-
- ##
- # Creates a new AAAA for +address+.
+ ClassHash[[TypeValue = 28, ClassValue = ClassValue]] = self
def initialize(address)
@address = IPv6.create(address)
end
-
- ##
- # The Resolv::IPv6 address for this AAAA.
-
attr_reader :address
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_bytes(@address.address)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
return self.new(IPv6.new(msg.get_bytes(16)))
end
end
- ##
# SRV resource record defined in RFC 2782
#
# These records identify the hostname and port that a service is
# available at.
-
+ #
+ # The format is:
+ # _Service._Proto.Name TTL Class SRV Priority Weight Port Target
+ #
+ # The fields specific to SRV are defined in RFC 2782 as meaning:
+ # - +priority+ The priority of this target host. A client MUST attempt
+ # to contact the target host with the lowest-numbered priority it can
+ # reach; target hosts with the same priority SHOULD be tried in an
+ # order defined by the weight field. The range is 0-65535. Note that
+ # it is not widely implemented and should be set to zero.
+ #
+ # - +weight+ A server selection mechanism. The weight field specifies
+ # a relative weight for entries with the same priority. Larger weights
+ # SHOULD be given a proportionately higher probability of being
+ # selected. The range of this number is 0-65535. Domain administrators
+ # SHOULD use Weight 0 when there isn't any server selection to do, to
+ # make the RR easier to read for humans (less noisy). Note that it is
+ # not widely implemented and should be set to zero.
+ #
+ # - +port+ The port on this target host of this service. The range is 0-
+ # 65535.
+ #
+ # - +target+ The domain name of the target host. A target of "." means
+ # that the service is decidedly not available at this domain.
class SRV < Resource
- TypeValue = 33
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
+ ClassHash[[TypeValue = 33, ClassValue = ClassValue]] = self
# Create a SRV resource record.
- #
- # See the documentation for #priority, #weight, #port and #target
- # for +priority+, +weight+, +port and +target+ respectively.
-
def initialize(priority, weight, port, target)
@priority = priority.to_int
@weight = weight.to_int
@@ -1936,49 +1735,16 @@ class Resolv
@target = Name.create(target)
end
- # The priority of this target host.
- #
- # A client MUST attempt to contact the target host with the
- # lowest-numbered priority it can reach; target hosts with the same
- # priority SHOULD be tried in an order defined by the weight field.
- # The range is 0-65535. Note that it is not widely implemented and
- # should be set to zero.
+ attr_reader :priority, :weight, :port, :target
- attr_reader :priority
-
- # A server selection mechanism.
- #
- # The weight field specifies a relative weight for entries with the
- # same priority. Larger weights SHOULD be given a proportionately
- # higher probability of being selected. The range of this number is
- # 0-65535. Domain administrators SHOULD use Weight 0 when there
- # isn't any server selection to do, to make the RR easier to read
- # for humans (less noisy). Note that it is not widely implemented
- # and should be set to zero.
-
- attr_reader :weight
-
- # The port on this target host of this service.
- #
- # The range is 0-65535.
-
- attr_reader :port
-
- # The domain name of the target host.
- #
- # A target of "." means that the service is decidedly not available
- # at this domain.
-
- attr_reader :target
-
- def encode_rdata(msg) # :nodoc:
+ def encode_rdata(msg)
msg.put_pack("n", @priority)
msg.put_pack("n", @weight)
msg.put_pack("n", @port)
msg.put_name(@target)
end
- def self.decode_rdata(msg) # :nodoc:
+ def self.decode_rdata(msg)
priority, = msg.get_unpack("n")
weight, = msg.get_unpack("n")
port, = msg.get_unpack("n")
@@ -1986,18 +1752,12 @@ class Resolv
return self.new(priority, weight, port, target)
end
end
+
end
end
end
- ##
- # A Resolv::DNS IPv4 address.
-
class IPv4
-
- ##
- # Regular expression IPv4 addresses must match.
-
Regex = /\A(\d+)\.(\d+)\.(\d+)\.(\d+)\z/
def self.create(arg)
@@ -2018,102 +1778,68 @@ class Resolv
end
end
- def initialize(address) # :nodoc:
+ def initialize(address)
unless address.kind_of?(String) && address.length == 4
raise ArgumentError.new('IPv4 address must be 4 bytes')
end
@address = address
end
-
- ##
- # A String reperesentation of this IPv4 address.
-
- ##
- # The raw IPv4 address as a String.
-
attr_reader :address
- def to_s # :nodoc:
+ def to_s
return sprintf("%d.%d.%d.%d", *@address.unpack("CCCC"))
end
- def inspect # :nodoc:
+ def inspect
return "#<#{self.class} #{self.to_s}>"
end
- ##
- # Turns this IPv4 address into a Resolv::DNS::Name.
-
def to_name
return DNS::Name.create(
'%d.%d.%d.%d.in-addr.arpa.' % @address.unpack('CCCC').reverse)
end
- def ==(other) # :nodoc:
+ def ==(other)
return @address == other.address
end
- def eql?(other) # :nodoc:
+ def eql?(other)
return self == other
end
- def hash # :nodoc:
+ def hash
return @address.hash
end
end
- ##
- # A Resolv::DNS IPv6 address.
-
class IPv6
-
- ##
- # IPv6 address format a:b:c:d:e:f:g:h
Regex_8Hex = /\A
(?:[0-9A-Fa-f]{1,4}:){7}
[0-9A-Fa-f]{1,4}
\z/x
- ##
- # Compressed IPv6 address format a::b
-
Regex_CompressedHex = /\A
((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?) ::
((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)
\z/x
- ##
- # IPv4 mapped IPv6 address format a:b:c:d:e:f:w.x.y.z
-
Regex_6Hex4Dec = /\A
((?:[0-9A-Fa-f]{1,4}:){6,6})
(\d+)\.(\d+)\.(\d+)\.(\d+)
\z/x
- ##
- # Compressed IPv4 mapped IPv6 address format a::b:w.x.y.z
-
Regex_CompressedHex4Dec = /\A
((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?) ::
((?:[0-9A-Fa-f]{1,4}:)*)
(\d+)\.(\d+)\.(\d+)\.(\d+)
\z/x
- ##
- # A composite IPv6 address Regexp.
-
Regex = /
(?:#{Regex_8Hex}) |
(?:#{Regex_CompressedHex}) |
(?:#{Regex_6Hex4Dec}) |
(?:#{Regex_CompressedHex4Dec})/x
- ##
- # Creates a new IPv6 address from +arg+ which may be:
- #
- # IPv6:: returns +arg+.
- # String:: +arg+ must match one of the IPv6::Regex* constants
-
def self.create(arg)
case arg
when IPv6
@@ -2160,19 +1886,15 @@ class Resolv
end
end
- def initialize(address) # :nodoc:
+ def initialize(address)
unless address.kind_of?(String) && address.length == 16
raise ArgumentError.new('IPv6 address must be 16 bytes')
end
@address = address
end
-
- ##
- # The raw IPv6 address as a String.
-
attr_reader :address
- def to_s # :nodoc:
+ def to_s
address = sprintf("%X:%X:%X:%X:%X:%X:%X:%X", *@address.unpack("nnnnnnnn"))
unless address.sub!(/(^|:)0(:0)+(:|$)/, '::')
address.sub!(/(^|:)0(:|$)/, '::')
@@ -2180,42 +1902,29 @@ class Resolv
return address
end
- def inspect # :nodoc:
+ def inspect
return "#<#{self.class} #{self.to_s}>"
end
- ##
- # Turns this IPv6 address into a Resolv::DNS::Name.
- #--
- # ip6.arpa should be searched too. [RFC3152]
-
def to_name
+ # ip6.arpa should be searched too. [RFC3152]
return DNS::Name.new(
@address.unpack("H32")[0].split(//).reverse + ['ip6', 'int'])
end
- def ==(other) # :nodoc:
+ def ==(other)
return @address == other.address
end
- def eql?(other) # :nodoc:
+ def eql?(other)
return self == other
end
- def hash # :nodoc:
+ def hash
return @address.hash
end
end
- ##
- # Default resolver to use for Resolv class methods.
-
DefaultResolver = self.new
-
- ##
- # Address Regexp to use for matching IP addresses.
-
AddressRegex = /(?:#{IPv4::Regex})|(?:#{IPv6::Regex})/
-
end
-
diff --git a/lib/rexml/attribute.rb b/lib/rexml/attribute.rb
index a169148f32..89c1ada36c 100644
--- a/lib/rexml/attribute.rb
+++ b/lib/rexml/attribute.rb
@@ -18,25 +18,41 @@ 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( source )
+ # Attribute.new( attribute_to_clone, parent_element )
# 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
- @value = first.value
+ @unnormalized = first.value
if second.kind_of? Element
@element = second
else
@element = first.element
end
elsif first.kind_of? String
- @element = parent if parent.kind_of? Element
+ @element = parent
self.name = first
- @value = second.to_s
+ @normalized = second.to_s
else
raise "illegal argument #{first.class.name} to Attribute constructor"
end
@@ -72,7 +88,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
@@ -87,7 +103,11 @@ module REXML
# b = Attribute.new( "ns:x", "y" )
# b.to_string # -> "ns:x='y'"
def to_string
- "#@expanded_name='#{to_s().gsub(/'/, '&apos;')}'"
+ 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
end
# Returns the attribute value, with entities replaced
@@ -100,8 +120,9 @@ module REXML
doctype = doc.doctype if doc
end
+ @normalized = Text::normalize( @unnormalized, doctype )
@unnormalized = nil
- @normalized = Text::normalize( @value, doctype )
+ @normalized
end
# Returns the UNNORMALIZED value of this attribute. That is, entities
@@ -113,8 +134,9 @@ module REXML
doc = @element.document
doctype = doc.doctype if doc
end
+ @unnormalized = Text::unnormalize( @normalized, doctype )
@normalized = nil
- @unnormalized = Text::unnormalize( @value, doctype )
+ @unnormalized
end
# Returns a copy of this attribute
diff --git a/lib/rexml/cdata.rb b/lib/rexml/cdata.rb
index 046012ba61..efcb71160a 100644
--- a/lib/rexml/cdata.rb
+++ b/lib/rexml/cdata.rb
@@ -39,31 +39,26 @@ 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::
- # 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.
+ # The amount to indent this node by
# 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.
+ # Ignored
# 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.
+ # Ignored
#
# _Examples_
# c = CData.new( " Some text " )
# c.write( $stdout ) #-> <![CDATA[ Some text ]]>
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
- #indent( output, indent ) unless transitive
+ Kernel.warn( "#{self.class.name}.write is deprecated" )
+ indent( output, indent )
output << START
output << @string
output << STOP
diff --git a/lib/rexml/comment.rb b/lib/rexml/comment.rb
index a4fcb58c8d..2b9b4b89c9 100644
--- a/lib/rexml/comment.rb
+++ b/lib/rexml/comment.rb
@@ -34,6 +34,9 @@ module REXML
Comment.new self
end
+ # == DEPRECATED
+ # See REXML::Formatters
+ #
# output::
# Where to write the string
# indent::
@@ -45,6 +48,7 @@ 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 4a1ffb4336..05cd4ab331 100644
--- a/lib/rexml/doctype.rb
+++ b/lib/rexml/doctype.rb
@@ -98,38 +98,30 @@ module REXML
# output::
# Where to write the string
# indent::
- # An integer. If -1, no indenting will be used; otherwise, the
+ # An integer. If -1, no indentation will be used; otherwise, the
# indentation will be this number of spaces, and children will be
# indented an additional amount.
# 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.
+ # Ignored
# 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.
- #
+ # Ignored
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" if @long_name
- output << " #@uri" if @uri
+ output << " #{@long_name.inspect}" if @long_name
+ output << " #{@uri.inspect}" if @uri
unless @children.empty?
next_indent = indent + 1
output << ' ['
child = nil # speed
@children.each { |child|
output << "\n"
- child.write( output, next_indent )
+ f.write( child, output )
}
- #output << ' '*next_indent
output << "\n]"
end
output << STOP
@@ -219,8 +211,10 @@ module REXML
@string+'>'
end
+ # == DEPRECATED
+ # See REXML::Formatters
+ #
def write( output, indent )
- output << (' '*indent) if indent > 0
output << to_s
end
end
@@ -264,7 +258,6 @@ 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 619a844257..81e63c60f1 100644
--- a/lib/rexml/document.rb
+++ b/lib/rexml/document.rb
@@ -31,9 +31,6 @@ 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 = {} )
super()
@context = context
@@ -69,6 +66,7 @@ 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
@@ -142,42 +140,59 @@ 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.
- #
- #
- # 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]
+ # 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 )
end
- }
+ formatter.write( self, output )
end
diff --git a/lib/rexml/dtd/dtd.rb b/lib/rexml/dtd/dtd.rb
index 81119cfa9b..4f735d4812 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 << EleemntDecl.new( match )
+ contents << ElementDecl.new( match )
when AttlistDecl.PATTERN_RE
matchdata = $~
source = $'
diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb
index 435076420a..92612036a1 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
- Element.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,416 +126,410 @@ 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 |= 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)
- 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 )
+ 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>'
+ 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
@@ -552,166 +546,147 @@ module REXML
return path_elements.reverse.join( "/" )
end
- #################################################
- # Attributes #
- #################################################
-
- def attribute( name, namespace=nil )
- prefix = ''
- if namespace
- prefix = attributes.prefixes.each { |prefix|
- return "#{prefix}:" if namespace( prefix ) == namespace
- } || ''
- end
- attributes.get_attribute( "#{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 << " "
+ #################################################
+ # Attributes #
+ #################################################
+
+ 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 )
end
- 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
+ formatter.write( self, output )
+ end
+
+
+ private
def __to_xpath_helper node
rv = node.expanded_name.clone
if node.parent
@@ -726,528 +701,514 @@ 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
-
- # 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
+ # 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
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
- 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.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.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
+ 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
+
# 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.
@@ -1256,11 +1217,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 3a92080b13..a01763be99 100644
--- a/lib/rexml/encoding.rb
+++ b/lib/rexml/encoding.rb
@@ -24,20 +24,20 @@ module REXML
old_verbosity = $VERBOSE
begin
$VERBOSE = false
- enc = enc.nil? ? nil : enc.upcase
+ enc = enc.nil? ? nil : enc.upcase
return false if defined? @encoding and enc == @encoding
if enc and enc != UTF_8
- @encoding = enc
- raise ArgumentError, "Bad encoding name #@encoding" unless @encoding =~ /^[\w-]+$/
- @encoding.untaint
- enc_file = File.join( "rexml", "encodings", "#@encoding.rb" )
- begin
- require enc_file
- Encoding.apply(self, @encoding)
+ @encoding = enc
+ raise ArgumentError, "Bad encoding name #@encoding" unless @encoding =~ /^[\w-]+$/
+ @encoding.untaint
+ begin
+ require 'rexml/encodings/ICONV.rb'
+ Encoding.apply(self, "ICONV")
rescue LoadError, Exception
- begin
- require 'rexml/encodings/ICONV.rb'
- Encoding.apply(self, "ICONV")
+ begin
+ enc_file = File.join( "rexml", "encodings", "#@encoding.rb" )
+ require enc_file
+ Encoding.apply(self, @encoding)
rescue LoadError => err
puts err.message
raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv."
@@ -51,15 +51,20 @@ module REXML
ensure
$VERBOSE = old_verbosity
end
- true
+ true
end
def check_encoding str
# We have to recognize UTF-16, LSB UTF-16, and UTF-8
- 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
+ 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_8
end
end
diff --git a/lib/rexml/encodings/CP-1252.rb b/lib/rexml/encodings/CP-1252.rb
index 51179f119f..8675f9ff98 100644
--- a/lib/rexml/encodings/CP-1252.rb
+++ b/lib/rexml/encodings/CP-1252.rb
@@ -3,43 +3,49 @@
#
module REXML
module Encoding
- @@__REXML_encoding_methods = %q~
+ register( "CP-1252" ) do |o|
+ class << o
+ alias encode encode_cp1252
+ alias decode decode_cp1252
+ end
+ end
+
# Convert from UTF-8
- def encode content
+ def encode_cp1252(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
@@ -54,45 +60,44 @@ module REXML
end
# Convert to UTF-8
- def decode(str)
+ def decode_cp1252(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 ce565e7dd5..8dea0d38a4 100644
--- a/lib/rexml/encodings/ISO-8859-15.rb
+++ b/lib/rexml/encodings/ISO-8859-15.rb
@@ -3,33 +3,37 @@
#
module REXML
module Encoding
- @@__REXML_encoding_methods = %q~
+ register("ISO-8859-15") do |o|
+ alias encode to_iso_8859_15
+ alias decode from_iso_8859_15
+ end
+
# 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
@@ -50,20 +54,19 @@ 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 93c7877afd..9e0f4af20e 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 = '-Swm0'
- U8TOSJIS = '-Wsm0'
+ SJISTOU8 = '-Swm0x'
+ U8TOSJIS = '-Wsm0x'
def decode_sjis(str)
NKF.nkf(SJISTOU8, str)
diff --git a/lib/rexml/encodings/UNILE.rb b/lib/rexml/encodings/UNILE.rb
index 0560a08361..d054140c40 100644
--- a/lib/rexml/encodings/UNILE.rb
+++ b/lib/rexml/encodings/UNILE.rb
@@ -18,7 +18,7 @@ module REXML
def decode_unile(str)
array_enc=str.unpack('C*')
array_utf8 = []
- 2.step(array_enc.size-1, 2){|i|
+ 0.step(array_enc.size-1, 2){|i|
array_utf8 << (array_enc.at(i) + array_enc.at(i+1)*0x100)
}
array_utf8.pack('U*')
diff --git a/lib/rexml/entity.rb b/lib/rexml/entity.rb
index 4b88a3c553..ff2d45f39b 100644
--- a/lib/rexml/entity.rb
+++ b/lib/rexml/entity.rb
@@ -89,6 +89,12 @@ 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
new file mode 100644
index 0000000000..77381bdf84
--- /dev/null
+++ b/lib/rexml/formatters/default.rb
@@ -0,0 +1,109 @@
+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
new file mode 100644
index 0000000000..22b6d857cd
--- /dev/null
+++ b/lib/rexml/formatters/pretty.rb
@@ -0,0 +1,137 @@
+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[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
new file mode 100644
index 0000000000..1d80f21fbb
--- /dev/null
+++ b/lib/rexml/formatters/transitive.rb
@@ -0,0 +1,56 @@
+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 d741dbdab7..8293e9c5ac 100644
--- a/lib/rexml/functions.rb
+++ b/lib/rexml/functions.rb
@@ -117,16 +117,30 @@ module REXML
elsif defined? object.node_type
if object.node_type == :attribute
object.value
- elsif object.node_type == :element
- object.text
+ elsif object.node_type == :element || object.node_type == :document
+ string_value(object)
else
object.to_s
end
+ elsif object.nil?
+ return ""
else
object.to_s
end
end
+ def Functions::string_value( o )
+ rv = ""
+ o.children.each { |e|
+ if e.node_type == :text
+ rv << e.to_s
+ elsif e.node_type == :element
+ rv << string_value( e )
+ end
+ }
+ rv
+ end
+
# UNTESTED
def Functions::concat( *objects )
objects.join
@@ -139,7 +153,7 @@ module REXML
# Fixed by Mike Stok
def Functions::contains( string, test )
- string(string).include? string(test)
+ string(string).include?(string(test))
end
# Kouhei fixed this
@@ -325,8 +339,9 @@ module REXML
object.to_f
else
str = string( object )
- #puts "STRING OF #{object.inspect} = #{str}"
- if str =~ /^-?\.?\d/
+ # If XPath ever gets scientific notation...
+ #if str =~ /^\s*-?(\d*\.?\d+|\d+\.)([Ee]\d*)?\s*$/
+ if str =~ /^\s*-?(\d*\.?\d+|\d+\.)\s*$/
str.to_f
else
(0.0 / 0.0)
diff --git a/lib/rexml/instruction.rb b/lib/rexml/instruction.rb
index f24f7786f7..c16b894b4a 100644
--- a/lib/rexml/instruction.rb
+++ b/lib/rexml/instruction.rb
@@ -38,7 +38,11 @@ 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 e5dec72a9d..9780376829 100644
--- a/lib/rexml/node.rb
+++ b/lib/rexml/node.rb
@@ -1,4 +1,6 @@
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
@@ -18,10 +20,19 @@ module REXML
@parent[ ind - 1 ]
end
- def to_s indent=-1
- rv = ""
- write rv,indent
- rv
+ # 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
end
def indent to, ind
@@ -55,10 +66,8 @@ module REXML
return nil
end
- # Returns the index that +self+ has in its parent's elements array, so that
- # the following equation holds true:
- #
- # node == node.parent.elements[node.index_in_parent]
+ # Returns the position that +self+ holds in its parent's array, indexed
+ # from 1.
def index_in_parent
parent.index(self)+1
end
diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb
index c57ea58dc7..fc2354a67f 100644
--- a/lib/rexml/parsers/baseparser.rb
+++ b/lib/rexml/parsers/baseparser.rb
@@ -1,5 +1,7 @@
require 'rexml/parseexception'
+require 'rexml/undefinednamespaceexception'
require 'rexml/source'
+require 'set'
module REXML
module Parsers
@@ -24,7 +26,8 @@ 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}"
+ NAME_STR= "(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})"
+ UNAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
NAMECHAR = '[\-\w\d\.:]'
NAME = "([\\w:]#{NAMECHAR}*)"
@@ -35,7 +38,7 @@ module REXML
DOCTYPE_START = /\A\s*<!DOCTYPE\s/um
DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
- ATTRIBUTE_PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um
+ ATTRIBUTE_PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\4/um
COMMENT_START = /\A<!--/u
COMMENT_PATTERN = /<!--(.*?)-->/um
CDATA_START = /\A<!\[CDATA\[/u
@@ -45,7 +48,7 @@ module REXML
XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>/um
INSTRUCTION_START = /\A<\?/u
INSTRUCTION_PATTERN = /<\?(.*?)(\s+.*?)?\?>/um
- TAG_MATCH = /^<((?>#{NAME_STR}))\s*((?>\s+#{NAME_STR}\s*=\s*(["']).*?\3)*)\s*(\/)?>/um
+ TAG_MATCH = /^<((?>#{NAME_STR}))\s*((?>\s+#{UNAME_STR}\s*=\s*(["']).*?\5)*)\s*(\/)?>/um
CLOSE_MATCH = /^\s*<\/(#{NAME_STR})\s*>/um
VERSION = /\bversion\s*=\s*["'](.*?)['"]/um
@@ -53,7 +56,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
@@ -133,6 +136,7 @@ module REXML
@tags = []
@stack = []
@entities = []
+ @nsstack = []
end
def position
@@ -146,8 +150,6 @@ module REXML
# Returns true if there are no more events
def empty?
- #STDERR.puts "@source.empty? = #{@source.empty?}"
- #STDERR.puts "@stack.empty? = #{@stack.empty?}"
return (@source.empty? and @stack.empty?)
end
@@ -190,6 +192,7 @@ 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
@@ -215,14 +218,15 @@ 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("DOCTYPE is missing a name") if name.nil?
+ raise REXML::ParseException.new("DOCTYPE is missing a name") if name.nil?
pub_sys = $2.nil? ? nil : $2.strip
- long_name = $3.nil? ? nil : $3.strip
- uri = $4.nil? ? nil : $4.strip
+ long_name = $4.nil? ? nil : $4.strip
+ uri = $6.nil? ? nil : $6.strip
args = [ :start_doctype, name, pub_sys, long_name, uri ]
if close == ">"
@document_status = :after_doctype
@@ -290,6 +294,9 @@ 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 ]
@@ -314,6 +321,7 @@ 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 )
@@ -347,26 +355,52 @@ 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
- attrs = []
- if md[2].size > 0
- attrs = md[2].scan( ATTRIBUTE_PATTERN )
+ 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 )
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
- if md[4]
+ # 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]
@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
md = @source.match( TEXT_PATTERN, true )
if md[0].length == 0
- puts "EMPTY = #{empty?}"
- puts "BUFFER = \"#{@source.buffer}\""
@source.match( /(\s+)/, true )
end
#STDERR.puts "GOT #{md[1].inspect}" unless md[0].length == 0
@@ -375,6 +409,8 @@ 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 61a216cec1..e402eb7747 100644
--- a/lib/rexml/parsers/sax2parser.rb
+++ b/lib/rexml/parsers/sax2parser.rb
@@ -16,6 +16,10 @@ module REXML
@tag_stack = []
@entities = {}
end
+
+ def source
+ @parser.source
+ end
def add_listener( listener )
@parser.add_listener( listener )
@@ -90,6 +94,8 @@ 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
@@ -163,7 +169,7 @@ module REXML
when :entitydecl
@entities[ event[1] ] = event[2] if event.size == 3
handle( *event )
- when :processing_instruction, :comment, :doctype, :attlistdecl,
+ when :processing_instruction, :comment, :attlistdecl,
:elementdecl, :cdata, :notationdecl, :xmldecl
handle( *event )
end
diff --git a/lib/rexml/parsers/treeparser.rb b/lib/rexml/parsers/treeparser.rb
index 500a53f426..5c3e142ea7 100644
--- a/lib/rexml/parsers/treeparser.rb
+++ b/lib/rexml/parsers/treeparser.rb
@@ -1,4 +1,5 @@
require 'rexml/validation/validationexception'
+require 'rexml/undefinednamespaceexception'
module REXML
module Parsers
@@ -23,13 +24,13 @@ module REXML
case event[0]
when :end_document
unless tag_stack.empty?
- raise ParseException.new("No close tag for #{tag_stack.inspect}")
+ #raise ParseException.new("No close tag for #{tag_stack.inspect}")
+ raise ParseException.new("No close tag for #{@build_context.xpath}")
end
return
when :start_element
tag_stack.push(event[1])
- # find the observers for namespaces
- @build_context = @build_context.add_element( event[1], event[2] )
+ el = @build_context = @build_context.add_element( event[1], event[2] )
when :end_element
tag_stack.pop
@build_context = @build_context.parent
@@ -85,6 +86,8 @@ 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 6f5b21cd93..de2530e347 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 =~ /^[\/\.\@\[\w_*]/
+ rest = LocationPath(rest, n) if rest =~ /\A[\/\.\@\[\w_*]/
parsed.concat(n)
return rest
end
diff --git a/lib/rexml/rexml.rb b/lib/rexml/rexml.rb
index 68759ab3f8..8af1697e51 100644
--- a/lib/rexml/rexml.rb
+++ b/lib/rexml/rexml.rb
@@ -1,3 +1,4 @@
+# -*- 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,
@@ -10,8 +11,9 @@
#
# Main page:: http://www.germane-software.com/software/rexml
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
-# Version:: 3.1.5
-# Date:: 2006/250
+# Version:: 3.1.7.2
+# Date:: 2007/275
+# Revision:: $Revision$
#
# This API documentation can be downloaded from the REXML home page, or can
# be accessed online[http://www.germane-software.com/software/rexml_doc]
@@ -20,9 +22,10 @@
# or can be accessed
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
module REXML
- COPYRIGHT = "Copyright © 2001-2006 Sean Russell <ser@germane-software.com>"
- DATE = "2006/250"
- VERSION = "3.1.5"
+ COPYRIGHT = "Copyright \xC2\xA9 2001-2006 Sean Russell <ser@germane-software.com>"
+ VERSION = "3.1.7.2"
+ DATE = "2007/275"
+ REVISION = "$Revision$".gsub(/\$Revision:|\$/,'').strip
Copyright = COPYRIGHT
Version = VERSION
diff --git a/lib/rexml/sax2listener.rb b/lib/rexml/sax2listener.rb
index 9a992917e6..8db1389d06 100644
--- a/lib/rexml/sax2listener.rb
+++ b/lib/rexml/sax2listener.rb
@@ -70,7 +70,7 @@ module REXML
# ["open-hatch", "PUBLIC", "\"-//Textuality//TEXT Standard open-hatch boilerplate//EN\"", "\"http://www.textuality.com/boilerplate/OpenHatch.xml\""]
# <!ENTITY hatch-pic SYSTEM "../grafix/OpenHatch.gif" NDATA gif>
# ["hatch-pic", "SYSTEM", "\"../grafix/OpenHatch.gif\"", "\n\t\t\t\t\t\t\tNDATA gif", "gif"]
- def entitydecl content
+ def entitydecl name, decl
end
# <!NOTATION ...>
def notationdecl content
diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb
index 3b6e813baf..ce7a2c98b0 100644
--- a/lib/rexml/source.rb
+++ b/lib/rexml/source.rb
@@ -1,132 +1,140 @@
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#, slurp=true
+ # 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 "#{source.class} is not a valid input stream. It must walk \n"+
- "like either a String, IO, or Source."
+ raise "#{arg.class} is not a valid input stream. It must walk \n"+
+ "like either a String, an IO, or a 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
- def initialize(arg)
- @orig = @buffer = arg
- self.encoding = check_encoding( @buffer )
- @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
+ 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
+ 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
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)
- @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
@@ -134,88 +142,98 @@ module REXML
# if there is one. If there isn't one, the file MUST be UTF-8, as per
# the XML spec. If there is one, we can determine the encoding from
# it.
+ @buffer = ""
str = @source.read( 2 )
- if /\A(?:\xfe\xff|\xff\xfe)/n =~ str
- self.encoding = check_encoding( str )
- @line_break = encode( '>' )
+ 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 = ">"
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
- rescue
- @source = nil
- end
- end
- rv = super
- end
- rv.taint
- rv
- end
-
- def read
- begin
+ 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
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
@@ -227,7 +245,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 55bc9f50f8..9804aa710b 100644
--- a/lib/rexml/text.rb
+++ b/lib/rexml/text.rb
@@ -42,6 +42,7 @@ module REXML
# Use this field if you have entities defined for some text, and you don't
# want REXML to escape that text in output.
# Text.new( "<&", false, nil, false ) #-> "&lt;&amp;"
+ # Text.new( "&lt;&amp;", false, nil, false ) #-> "&amp;lt;&amp;amp;"
# Text.new( "<&", false, nil, true ) #-> Parse exception
# Text.new( "&lt;&amp;", false, nil, true ) #-> "&lt;&amp;"
# # Assume that the entity "s" is defined to be "sean"
@@ -172,17 +173,6 @@ module REXML
end
@unnormalized = Text::unnormalize( @string, doctype )
end
-
- def wrap(string, width, addnewline=false)
- # Recursivly wrap string at width.
- return string if string.length <= width
- place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
- if addnewline then
- return "\n" + string[0,place] + "\n" + wrap(string[place+1..-1], width)
- else
- return string[0,place] + "\n" + wrap(string[place+1..-1], width)
- end
- end
# Sets the contents of this text node. This expects the text to be
# unnormalized. It returns self.
@@ -198,28 +188,40 @@ module REXML
@raw = false
end
- def indent_text(string, level=1, style="\t", indentfirstline=true)
- return string if level < 0
- new_string = ''
- string.each { |line|
- indent_string = style * level
- new_line = (indent_string + line).sub(/[\s]+$/,'')
- new_string << new_line
- }
- new_string.strip! unless indentfirstline
- return new_string
+ def wrap(string, width, addnewline=false)
+ # Recursivly wrap string at width.
+ return string if string.length <= width
+ place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
+ if addnewline then
+ return "\n" + string[0,place] + "\n" + wrap(string[place+1..-1], width)
+ else
+ return string[0,place] + "\n" + wrap(string[place+1..-1], width)
+ end
end
+
+ def indent_text(string, level=1, style="\t", indentfirstline=true)
+ return string if level < 0
+ new_string = ''
+ string.each { |line|
+ indent_string = style * level
+ new_line = (indent_string + line).sub(/[\s]+$/,'')
+ new_string << new_line
+ }
+ new_string.strip! unless indentfirstline
+ return new_string
+ end
+ # == DEPRECATED
+ # See REXML::Formatters
+ #
def write( writer, indent=-1, transitive=false, ie_hack=false )
- 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)
+ 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
end
- s.squeeze!(" \n\t") if @parent and !@parent.whitespace
- end
- writer << s
+ formatter.write( self, writer )
end
# FIXME
@@ -286,9 +288,10 @@ module REXML
def Text::normalize( input, doctype=nil, entity_filter=nil )
copy = input
# Doing it like this rather than in a loop improves the speed
+ #copy = copy.gsub( EREFERENCE, '&amp;' )
+ copy = copy.gsub( "&", "&amp;" )
if doctype
# Replace all ampersands that aren't part of an entity
- copy = copy.gsub( EREFERENCE, '&amp;' )
doctype.entities.each_value do |entity|
copy = copy.gsub( entity.value,
"&#{entity.name};" ) if entity.value and
@@ -296,7 +299,6 @@ module REXML
end
else
# Replace all ampersands that aren't part of an entity
- copy = copy.gsub( EREFERENCE, '&amp;' )
DocType::DEFAULT_ENTITIES.each_value do |entity|
copy = copy.gsub(entity.value, "&#{entity.name};" )
end
diff --git a/lib/rexml/undefinednamespaceexception.rb b/lib/rexml/undefinednamespaceexception.rb
new file mode 100644
index 0000000000..8ebfdfd0a9
--- /dev/null
+++ b/lib/rexml/undefinednamespaceexception.rb
@@ -0,0 +1,8 @@
+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 b65604b762..427eb78cf8 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
+ attr_reader :writeencoding, :writethis
def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
@writethis = true
@@ -37,9 +37,14 @@ module REXML
XMLDecl.new(self)
end
- def write writer, indent=-1, transitive=false, ie_hack=false
+ # 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)
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 a813236e10..eb608fdb34 100644
--- a/lib/rexml/xpath_parser.rb
+++ b/lib/rexml/xpath_parser.rb
@@ -160,8 +160,13 @@ 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
+ path_stack.clear
+ return []
+ end
case (op = path_stack.shift)
when :document
nodeset = [ nodeset[0].root_node ]
@@ -235,9 +240,11 @@ module REXML
name = path_stack.shift
for element in nodeset
if element.node_type == :element
- #puts element.name
- attr = element.attribute( name, get_namespace(element, prefix) )
- new_nodeset << attr if attr
+ #puts "Element name = #{element.name}"
+ #puts "get_namespace( #{element.inspect}, #{prefix} ) = #{get_namespace(element, prefix)}"
+ attrib = element.attribute( name, get_namespace(element, prefix) )
+ #puts "attrib = #{attrib.inspect}"
+ new_nodeset << attrib if attrib
end
end
when :any
@@ -299,8 +306,10 @@ module REXML
#puts "Adding node #{node.inspect}" if result == (index+1)
new_nodeset << node if result == (index+1)
elsif result.instance_of? Array
- #puts "Adding node #{node.inspect}" if result.size > 0
- new_nodeset << node if result.size > 0
+ if result.size > 0 and result.inject(false) {|k,s| s or k}
+ #puts "Adding node #{node.inspect}" if result.size > 0
+ new_nodeset << node if result.size > 0
+ end
else
#puts "Adding node #{node.inspect}" if result
new_nodeset << node if result
@@ -343,7 +352,8 @@ module REXML
when :following_sibling
#puts "FOLLOWING_SIBLING 1: nodeset = #{nodeset}"
results = []
- for node in nodeset
+ nodeset.each do |node|
+ next if node.parent.nil?
all_siblings = node.parent.children
current_index = all_siblings.index( node )
following_siblings = all_siblings[ current_index+1 .. -1 ]
@@ -354,13 +364,14 @@ module REXML
when :preceding_sibling
results = []
- for node in nodeset
+ nodeset.each do |node|
+ next if node.parent.nil?
all_siblings = node.parent.children
current_index = all_siblings.index( node )
- preceding_siblings = all_siblings[ 0 .. current_index-1 ].reverse
- #results += expr( path_stack.dclone, preceding_siblings )
+ preceding_siblings = all_siblings[ 0, current_index ].reverse
+ results += preceding_siblings
end
- nodeset = preceding_siblings || []
+ nodeset = results
node_types = ELEMENTS
when :preceding
@@ -381,9 +392,25 @@ module REXML
node_types = ELEMENTS
when :namespace
- new_set = []
+ #puts "In :namespace"
+ new_nodeset = []
+ prefix = path_stack.shift
for node in nodeset
- new_nodeset << node.namespace if node.node_type == :element or node.node_type == :attribute
+ if (node.node_type == :element or node.node_type == :attribute)
+ if @namespaces
+ namespaces = @namespaces
+ elsif (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
+ end
end
nodeset = new_nodeset
@@ -404,6 +431,18 @@ module REXML
#puts "RES => #{res.inspect}"
return res
+ when :and
+ left = expr( path_stack.shift, nodeset.dup, context )
+ #puts "LEFT => #{left.inspect} (#{left.class.name})"
+ if left == false || left.nil? || !left.inject(false) {|a,b| a | b}
+ return []
+ end
+ right = expr( path_stack.shift, nodeset.dup, context )
+ #puts "RIGHT => #{right.inspect} (#{right.class.name})"
+ res = equality_relational_compare( left, op, right )
+ #puts "RES => #{res.inspect}"
+ return res
+
when :div
left = Functions::number(expr(path_stack.shift, nodeset, context)).to_f
right = Functions::number(expr(path_stack.shift, nodeset, context)).to_f
@@ -477,7 +516,7 @@ module REXML
# The next two methods are BAD MOJO!
# This is my achilles heel. If anybody thinks of a better
# way of doing this, be my guest. This really sucks, but
- # it took me three days to get it to work at all.
+ # it is a wonder it works at all.
# ########################################################
def descendant_or_self( path_stack, nodeset )
diff --git a/lib/rinda/.document b/lib/rinda/.document
deleted file mode 100644
index 598977af68..0000000000
--- a/lib/rinda/.document
+++ /dev/null
@@ -1,3 +0,0 @@
-rinda.rb
-ring.rb
-tuplespace.rb
diff --git a/lib/rinda/ring.rb b/lib/rinda/ring.rb
index 5b2d412451..ac8a716216 100644
--- a/lib/rinda/ring.rb
+++ b/lib/rinda/ring.rb
@@ -80,7 +80,7 @@ module Rinda
# address of the local TupleSpace.
def do_reply
- tuple = @ts.take([:lookup_ring, DRbObject])
+ tuple = @ts.take([:lookup_ring, nil])
Thread.new { tuple[1].call(@ts) rescue nil}
rescue
end
diff --git a/lib/rinda/tuplespace.rb b/lib/rinda/tuplespace.rb
index 73e79bb401..6d58a0fd15 100644
--- a/lib/rinda/tuplespace.rb
+++ b/lib/rinda/tuplespace.rb
@@ -404,7 +404,6 @@ 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|
@@ -414,6 +413,7 @@ 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,7 +439,6 @@ 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
@@ -452,6 +451,7 @@ 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,7 +476,6 @@ 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
@@ -484,6 +483,7 @@ 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,8 +566,11 @@ module Rinda
def start_keeper
return if @keeper && @keeper.alive?
@keeper = Thread.new do
- while need_keeper?
- keep_clean
+ while true
+ synchronize do
+ break unless need_keeper?
+ keep_clean
+ end
sleep(@period)
end
end
diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb
index f0060cbad5..69e01ddd57 100644
--- a/lib/rss/0.9.rb
+++ b/lib/rss/0.9.rb
@@ -9,7 +9,7 @@ module RSS
def self.append_features(klass)
super
- klass.install_must_call_validator('', nil)
+ klass.install_must_call_validator('', "")
end
end
@@ -17,16 +17,9 @@ module RSS
include RSS09
include RootElementMixin
- include XMLStyleSheetMixin
-
- [
- ["channel", nil],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
%w(channel).each do |name|
- install_have_child_element(name)
+ install_have_child_element(name, "", nil)
end
attr_accessor :rss_version, :version, :encoding, :standalone
@@ -58,31 +51,15 @@ module RSS
nil
end
end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent, ns_declarations) do |next_indent|
- [
- channel_element(false, next_indent),
- other_element(false, next_indent),
- ]
- end
- rv = convert(rv) if need_convert
- rv
- end
- private
- def children
- [@channel]
- end
-
- def _tags
- [
- [nil, 'channel'],
- ].delete_if do |uri, name|
- __send__(name).nil?
+ def setup_maker_elements(maker)
+ super
+ items.each do |item|
+ item.setup_maker(maker.items)
end
end
+ private
def _attrs
[
["version", true, "rss_version"],
@@ -94,119 +71,30 @@ module RSS
include RSS09
[
- ["title", nil],
- ["link", nil],
- ["description", nil],
- ["language", nil],
- ["copyright", "?"],
- ["managingEditor", "?"],
- ["webMaster", "?"],
- ["rating", "?"],
- ["docs", "?"],
- ].each do |name, occurs|
- install_text_element(name)
- install_model(name, occurs)
- end
-
- [
- ["pubDate", "?"],
- ["lastBuildDate", "?"],
- ].each do |name, occurs|
- install_date_element(name, 'rfc822')
- install_model(name, occurs)
+ ["title", nil, :text],
+ ["link", nil, :text],
+ ["description", nil, :text],
+ ["language", nil, :text],
+ ["copyright", "?", :text],
+ ["managingEditor", "?", :text],
+ ["webMaster", "?", :text],
+ ["rating", "?", :text],
+ ["pubDate", "?", :date, :rfc822],
+ ["lastBuildDate", "?", :date, :rfc822],
+ ["docs", "?", :text],
+ ["cloud", "?", :have_attribute],
+ ["skipDays", "?", :have_child],
+ ["skipHours", "?", :have_child],
+ ["image", nil, :have_child],
+ ["item", "*", :have_children],
+ ["textInput", "?", :have_child],
+ ].each do |name, occurs, type, *args|
+ __send__("install_#{type}_element", name, "", occurs, name, *args)
end
alias date pubDate
alias date= pubDate=
- [
- ["skipDays", "?"],
- ["skipHours", "?"],
- ["image", nil],
- ["textInput", "?"],
- ].each do |name, occurs|
- install_have_child_element(name)
- install_model(name, occurs)
- end
-
- [
- ["cloud", "?"]
- ].each do |name, occurs|
- install_have_attribute_element(name)
- install_model(name, occurs)
- end
-
- [
- ["item", "*"]
- ].each do |name, occurs|
- install_have_children_element(name)
- install_model(name, occurs)
- end
-
- def initialize()
- super()
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- title_element(false, next_indent),
- link_element(false, next_indent),
- description_element(false, next_indent),
- language_element(false, next_indent),
- copyright_element(false, next_indent),
- managingEditor_element(false, next_indent),
- webMaster_element(false, next_indent),
- rating_element(false, next_indent),
- pubDate_element(false, next_indent),
- lastBuildDate_element(false, next_indent),
- docs_element(false, next_indent),
- cloud_element(false, next_indent),
- skipDays_element(false, next_indent),
- skipHours_element(false, next_indent),
- image_element(false, next_indent),
- item_elements(false, next_indent),
- textInput_element(false, next_indent),
- other_element(false, next_indent),
- ]
- end
- rv = convert(rv) if need_convert
- rv
- end
-
private
- def children
- [@skipDays, @skipHours, @image, @textInput, @cloud, *@item]
- end
-
- def _tags
- rv = [
- "title",
- "link",
- "description",
- "language",
- "copyright",
- "managingEditor",
- "webMaster",
- "rating",
- "docs",
- "skipDays",
- "skipHours",
- "image",
- "textInput",
- "cloud",
- ].delete_if do |name|
- __send__(name).nil?
- end.collect do |elem|
- [nil, elem]
- end
-
- @item.each do
- rv << [nil, "item"]
- end
-
- rv
- end
-
def maker_target(maker)
maker.channel
end
@@ -237,29 +125,7 @@ module RSS
[
["day", "*"]
].each do |name, occurs|
- install_have_children_element(name)
- install_model(name, occurs)
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- day_elements(false, next_indent)
- ]
- end
- rv = convert(rv) if need_convert
- rv
- end
-
- private
- def children
- @day
- end
-
- def _tags
- @day.compact.collect do
- [nil, "day"]
- end
+ install_have_children_element(name, "", occurs)
end
class Day < Element
@@ -267,9 +133,13 @@ module RSS
content_setup
- def initialize(content=nil)
- super()
- self.content = content
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.content = args[0]
+ end
end
end
@@ -282,29 +152,7 @@ module RSS
[
["hour", "*"]
].each do |name, occurs|
- install_have_children_element(name)
- install_model(name, occurs)
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- hour_elements(false, next_indent)
- ]
- end
- rv = convert(rv) if need_convert
- rv
- end
-
- private
- def children
- @hour
- end
-
- def _tags
- @hour.compact.collect do
- [nil, "hour"]
- end
+ install_have_children_element(name, "", occurs)
end
class Hour < Element
@@ -312,9 +160,13 @@ module RSS
content_setup(:integer)
- def initialize(content=nil)
- super()
- self.content = content
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.content = args[0]
+ end
end
end
@@ -325,54 +177,31 @@ module RSS
include RSS09
%w(url title link).each do |name|
- install_text_element(name)
- install_model(name, nil)
+ install_text_element(name, "", nil)
end
[
["width", :integer],
["height", :integer],
["description"],
].each do |name, type|
- install_text_element(name, type)
- install_model(name, "?")
- end
-
- def initialize(url=nil, title=nil, link=nil, width=nil, height=nil,
- description=nil)
- super()
- self.url = url
- self.title = title
- self.link = link
- self.width = width
- self.height = height
- self.description = description
+ install_text_element(name, "", "?", name, type)
end
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- url_element(false, next_indent),
- title_element(false, next_indent),
- link_element(false, next_indent),
- width_element(false, next_indent),
- height_element(false, next_indent),
- description_element(false, next_indent),
- other_element(false, next_indent),
- ]
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.url = args[0]
+ self.title = args[1]
+ self.link = args[2]
+ self.width = args[3]
+ self.height = args[4]
+ self.description = args[5]
end
- rv = convert(rv) if need_convert
- rv
end
private
- def _tags
- %w(url title link width height description).delete_if do |name|
- __send__(name).nil?
- end.collect do |elem|
- [nil, elem]
- end
- end
-
def maker_target(maker)
maker.image
end
@@ -381,106 +210,47 @@ module RSS
class Cloud < Element
include RSS09
-
+
[
- ["domain", nil, true],
- ["port", nil, true, :integer],
- ["path", nil, true],
- ["registerProcedure", nil, true],
- ["protocol", nil, true],
+ ["domain", "", true],
+ ["port", "", true, :integer],
+ ["path", "", true],
+ ["registerProcedure", "", true],
+ ["protocol", "", true],
].each do |name, uri, required, type|
install_get_attribute(name, uri, required, type)
end
- def initialize(domain=nil, port=nil, path=nil, rp=nil, protocol=nil)
- super()
- self.domain = domain
- self.port = port
- self.path = path
- self.registerProcedure = rp
- self.protocol = protocol
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent)
- rv = convert(rv) if need_convert
- rv
- end
-
- private
- def _attrs
- %w(domain port path registerProcedure protocol).collect do |attr|
- [attr, true]
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.domain = args[0]
+ self.port = args[1]
+ self.path = args[2]
+ self.registerProcedure = args[3]
+ self.protocol = args[4]
end
end
-
end
class Item < Element
include RSS09
- %w(title link description).each do |name|
- install_text_element(name)
- end
-
- %w(source enclosure).each do |name|
- install_have_child_element(name)
- end
-
- [
- %w(category categories),
- ].each do |name, plural_name|
- install_have_children_element(name, plural_name)
- end
-
[
- ["title", '?'],
- ["link", '?'],
- ["description", '?'],
- ["category", '*'],
- ["source", '?'],
- ["enclosure", '?'],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- title_element(false, next_indent),
- link_element(false, next_indent),
- description_element(false, next_indent),
- category_elements(false, next_indent),
- source_element(false, next_indent),
- enclosure_element(false, next_indent),
- other_element(false, next_indent),
- ]
- end
- rv = convert(rv) if need_convert
- rv
+ ["title", '?', :text],
+ ["link", '?', :text],
+ ["description", '?', :text],
+ ["category", '*', :have_children, "categories"],
+ ["source", '?', :have_child],
+ ["enclosure", '?', :have_child],
+ ].each do |tag, occurs, type, *args|
+ __send__("install_#{type}_element", tag, "", occurs, tag, *args)
end
private
- def children
- [@source, @enclosure, *@category].compact
- end
-
- def _tags
- rv = %w(title link description author comments
- source enclosure).delete_if do |name|
- __send__(name).nil?
- end.collect do |name|
- [nil, name]
- end
-
- @category.each do
- rv << [nil, "category"]
- end
-
- rv
- end
-
def maker_target(items)
if items.respond_to?("items")
# For backward compatibility
@@ -500,31 +270,24 @@ module RSS
include RSS09
[
- ["url", nil, true]
+ ["url", "", true]
].each do |name, uri, required|
install_get_attribute(name, uri, required)
end
content_setup
- def initialize(url=nil, content=nil)
- super()
- self.url = url
- self.content = content
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.url = args[0]
+ self.content = args[1]
+ end
end
private
- def _tags
- []
- end
-
- def _attrs
- [
- ["url", true]
- ]
- end
-
-
def maker_target(item)
item.source
end
@@ -540,35 +303,25 @@ module RSS
include RSS09
[
- ["url", nil, true],
- ["length", nil, true, :integer],
- ["type", nil, true],
+ ["url", "", true],
+ ["length", "", true, :integer],
+ ["type", "", true],
].each do |name, uri, required, type|
install_get_attribute(name, uri, required, type)
end
- def initialize(url=nil, length=nil, type=nil)
- super()
- self.url = url
- self.length = length
- self.type = type
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent)
- rv = convert(rv) if need_convert
- rv
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.url = args[0]
+ self.length = args[1]
+ self.type = args[2]
+ end
end
private
- def _attrs
- [
- ["url", true],
- ["length", true],
- ["type", true],
- ]
- end
-
def maker_target(item)
item.enclosure
end
@@ -585,26 +338,24 @@ module RSS
include RSS09
[
- ["domain", nil, false]
+ ["domain", "", false]
].each do |name, uri, required|
install_get_attribute(name, uri, required)
end
content_setup
- def initialize(domain=nil, content=nil)
- super()
- self.domain = domain
- self.content = content
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.domain = args[0]
+ self.content = args[1]
+ end
end
private
- def _attrs
- [
- ["domain", false]
- ]
- end
-
def maker_target(item)
item.new_category
end
@@ -623,41 +374,22 @@ module RSS
include RSS09
%w(title description name link).each do |name|
- install_text_element(name)
- install_model(name, nil)
- end
-
- def initialize(title=nil, description=nil, name=nil, link=nil)
- super()
- self.title = title
- self.description = description
- self.name = name
- self.link = link
+ install_text_element(name, "", nil)
end
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- title_element(false, next_indent),
- description_element(false, next_indent),
- name_element(false, next_indent),
- link_element(false, next_indent),
- other_element(false, next_indent),
- ]
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.title = args[0]
+ self.description = args[1]
+ self.name = args[2]
+ self.link = args[3]
end
- rv = convert(rv) if need_convert
- rv
end
private
- def _tags
- %w(title description name link).each do |name|
- __send__(name).nil?
- end.collect do |elem|
- [nil, elem]
- end
- end
-
def maker_target(maker)
maker.textinput
end
@@ -668,20 +400,20 @@ module RSS
end
RSS09::ELEMENTS.each do |name|
- BaseListener.install_get_text_element(nil, name, "#{name}=")
+ BaseListener.install_get_text_element("", name, "#{name}=")
end
module ListenerMixin
private
def start_rss(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, nil)
+ check_ns(tag_name, prefix, ns, "")
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
@rss.do_validate = @do_validate
@rss.xml_stylesheets = @xml_stylesheets
@last_element = @rss
@proc_stack.push Proc.new { |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
+ @rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
}
end
diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb
index 36d6f5df87..a945434fbf 100644
--- a/lib/rss/1.0.rb
+++ b/lib/rss/1.0.rb
@@ -38,18 +38,13 @@ module RSS
[
["channel", nil],
["image", "?"],
- ["item", "+"],
+ ["item", "+", :children],
["textinput", "?"],
- ].each do |tag, occurs|
- install_model(tag, occurs)
+ ].each do |tag, occurs, type|
+ type ||= :child
+ __send__("install_have_#{type}_element", tag, ::RSS::URI, occurs)
end
- %w(channel image textinput).each do |name|
- install_have_child_element(name)
- end
-
- install_have_children_element("item")
-
attr_accessor :rss_version, :version, :encoding, :standalone
def initialize(version=nil, encoding=nil, standalone=nil)
@@ -59,41 +54,6 @@ module RSS
def full_name
tag_name_with_prefix(PREFIX)
end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent, ns_declarations) do |next_indent|
- [
- channel_element(false, next_indent),
- image_element(false, next_indent),
- item_elements(false, next_indent),
- textinput_element(false, next_indent),
- other_element(false, next_indent),
- ]
- end
- rv = convert(rv) if need_convert
- rv
- end
-
- private
- def rdf_validate(tags)
- _validate(tags, [])
- end
-
- def children
- [@channel, @image, @textinput, *@item]
- end
-
- def _tags
- rv = [
- [::RSS::URI, "channel"],
- [::RSS::URI, "image"],
- ].delete_if {|uri, name| __send__(name).nil?}
- @item.each do |item|
- rv << [::RSS::URI, "item"]
- end
- rv << [::RSS::URI, "textinput"] if @textinput
- rv
- end
class Li < Element
@@ -106,32 +66,23 @@ module RSS
end
[
- ["resource", [URI, nil], true]
+ ["resource", [URI, ""], true]
].each do |name, uri, required|
install_get_attribute(name, uri, required)
end
- def initialize(resource=nil)
- super()
- self.resource = resource
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.resource = args[0]
+ end
end
def full_name
tag_name_with_prefix(PREFIX)
end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent)
- rv = convert(rv) if need_convert
- rv
- end
-
- private
- def _attrs
- [
- ["resource", true]
- ]
- end
end
class Seq < Element
@@ -148,21 +99,15 @@ module RSS
@tag_name = 'Seq'
- install_have_children_element("li")
-
+ install_have_children_element("li", URI, "*")
install_must_call_validator('rdf', ::RSS::RDF::URI)
- def initialize(li=[])
- super()
- @li = li
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- tag(indent) do |next_indent|
- [
- li_elements(need_convert, next_indent),
- other_element(need_convert, next_indent),
- ]
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ @li = args[0] if args[0]
end
end
@@ -175,23 +120,6 @@ module RSS
target << li.resource
end
end
-
- private
- def children
- @li
- end
-
- def rdf_validate(tags)
- _validate(tags, [["li", '*']])
- end
-
- def _tags
- rv = []
- @li.each do |li|
- rv << [URI, "li"]
- end
- rv
- end
end
class Bag < Element
@@ -208,21 +136,15 @@ module RSS
@tag_name = 'Bag'
- install_have_children_element("li")
-
- install_must_call_validator('rdf', ::RSS::RDF::URI)
-
- def initialize(li=[])
- super()
- @li = li
- end
+ install_have_children_element("li", URI, "*")
+ install_must_call_validator('rdf', URI)
- def to_s(need_convert=true, indent=calc_indent)
- tag(indent) do |next_indent|
- [
- li_elements(need_convert, next_indent),
- other_element(need_convert, next_indent),
- ]
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ @li = args[0] if args[0]
end
end
@@ -235,23 +157,6 @@ module RSS
target << li.resource
end
end
-
- private
- def children
- @li
- end
-
- def rdf_validate(tags)
- _validate(tags, [["li", '*']])
- end
-
- def _tags
- rv = []
- @li.each do |li|
- rv << [URI, "li"]
- end
- rv
- end
end
class Channel < Element
@@ -269,73 +174,31 @@ module RSS
[
["about", URI, true]
].each do |name, uri, required|
- install_get_attribute(name, uri, required)
+ install_get_attribute(name, uri, required, nil, nil,
+ "#{PREFIX}:#{name}")
end
- %w(title link description).each do |name|
- install_text_element(name)
- end
-
- %w(image items textinput).each do |name|
- install_have_child_element(name)
- end
-
[
- ['title', nil],
- ['link', nil],
- ['description', nil],
- ['image', '?'],
- ['items', nil],
- ['textinput', '?'],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
-
- def initialize(about=nil)
- super()
- self.about = about
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- title_element(false, next_indent),
- link_element(false, next_indent),
- description_element(false, next_indent),
- image_element(false, next_indent),
- items_element(false, next_indent),
- textinput_element(false, next_indent),
- other_element(false, next_indent),
- ]
+ ['title', nil, :text],
+ ['link', nil, :text],
+ ['description', nil, :text],
+ ['image', '?', :have_child],
+ ['items', nil, :have_child],
+ ['textinput', '?', :have_child],
+ ].each do |tag, occurs, type|
+ __send__("install_#{type}_element", tag, ::RSS::URI, occurs)
+ end
+
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.about = args[0]
end
- rv = convert(rv) if need_convert
- rv
end
private
- def children
- [@image, @items, @textinput]
- end
-
- def _tags
- [
- [::RSS::URI, 'title'],
- [::RSS::URI, 'link'],
- [::RSS::URI, 'description'],
- [::RSS::URI, 'image'],
- [::RSS::URI, 'items'],
- [::RSS::URI, 'textinput'],
- ].delete_if do |uri, name|
- __send__(name).nil?
- end
- end
-
- def _attrs
- [
- ["#{PREFIX}:about", true, "about"]
- ]
- end
-
def maker_target(maker)
maker.channel
end
@@ -359,25 +222,17 @@ module RSS
[
["resource", URI, true]
].each do |name, uri, required|
- install_get_attribute(name, uri, required)
+ install_get_attribute(name, uri, required, nil, nil,
+ "#{PREFIX}:#{name}")
end
- def initialize(resource=nil)
- super()
- self.resource = resource
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent)
- rv = convert(rv) if need_convert
- rv
- end
-
- private
- def _attrs
- [
- ["#{PREFIX}:resource", true, "resource"]
- ]
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.resource = args[0]
+ end
end
end
@@ -396,25 +251,17 @@ module RSS
[
["resource", URI, true]
].each do |name, uri, required|
- install_get_attribute(name, uri, required)
+ install_get_attribute(name, uri, required, nil, nil,
+ "#{PREFIX}:#{name}")
end
- def initialize(resource=nil)
- super()
- self.resource = resource
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent)
- rv = convert(rv) if need_convert
- rv
- end
-
- private
- def _attrs
- [
- ["#{PREFIX}:resource", true, "resource"]
- ]
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.resource = args[0]
+ end
end
end
@@ -432,22 +279,17 @@ module RSS
end
- install_have_child_element("Seq")
+ install_have_child_element("Seq", URI, nil)
+ install_must_call_validator('rdf', URI)
- install_must_call_validator('rdf', ::RSS::RDF::URI)
-
- def initialize(seq=Seq.new)
- super()
- @Seq = seq
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- Seq_element(need_convert, next_indent),
- other_element(need_convert, next_indent),
- ]
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.Seq = args[0]
end
+ self.Seq ||= Seq.new
end
def resources
@@ -459,21 +301,6 @@ module RSS
[]
end
end
-
- private
- def children
- [@Seq]
- end
-
- def _tags
- rv = []
- rv << [URI, 'Seq'] unless @Seq.nil?
- rv
- end
-
- def rdf_validate(tags)
- _validate(tags, [["Seq", nil]])
- end
end
end
@@ -488,60 +315,28 @@ module RSS
end
end
-
+
[
["about", URI, true]
].each do |name, uri, required|
- install_get_attribute(name, uri, required)
+ install_get_attribute(name, uri, required, nil, nil,
+ "#{PREFIX}:#{name}")
end
%w(title url link).each do |name|
- install_text_element(name)
- end
-
- [
- ['title', nil],
- ['url', nil],
- ['link', nil],
- ].each do |tag, occurs|
- install_model(tag, occurs)
+ install_text_element(name, ::RSS::URI, nil)
end
- def initialize(about=nil)
- super()
- self.about = about
- end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- title_element(false, next_indent),
- url_element(false, next_indent),
- link_element(false, next_indent),
- other_element(false, next_indent),
- ]
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.about = args[0]
end
- rv = convert(rv) if need_convert
- rv
end
private
- def _tags
- [
- [::RSS::URI, 'title'],
- [::RSS::URI, 'url'],
- [::RSS::URI, 'link'],
- ].delete_if do |uri, name|
- __send__(name).nil?
- end
- end
-
- def _attrs
- [
- ["#{PREFIX}:about", true, "about"]
- ]
- end
-
def maker_target(maker)
maker.image
end
@@ -559,14 +354,12 @@ module RSS
end
+
[
["about", URI, true]
].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- %w(title link description).each do |name|
- install_text_element(name)
+ install_get_attribute(name, uri, required, nil, nil,
+ "#{PREFIX}:#{name}")
end
[
@@ -574,44 +367,19 @@ module RSS
["link", nil],
["description", "?"],
].each do |tag, occurs|
- install_model(tag, occurs)
- end
-
- def initialize(about=nil)
- super()
- self.about = about
+ install_text_element(tag, ::RSS::URI, occurs)
end
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- title_element(false, next_indent),
- link_element(false, next_indent),
- description_element(false, next_indent),
- other_element(false, next_indent),
- ]
- end
- rv = convert(rv) if need_convert
- rv
- end
-
- private
- def _tags
- [
- [::RSS::URI, 'title'],
- [::RSS::URI, 'link'],
- [::RSS::URI, 'description'],
- ].delete_if do |uri, name|
- __send__(name).nil?
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.about = args[0]
end
end
- def _attrs
- [
- ["#{PREFIX}:about", true, "about"]
- ]
- end
-
+ private
def maker_target(items)
if items.respond_to?("items")
# For backward compatibility
@@ -636,59 +404,24 @@ module RSS
[
["about", URI, true]
].each do |name, uri, required|
- install_get_attribute(name, uri, required)
+ install_get_attribute(name, uri, required, nil, nil,
+ "#{PREFIX}:#{name}")
end
%w(title description name link).each do |name|
- install_text_element(name)
- end
-
- [
- ["title", nil],
- ["description", nil],
- ["name", nil],
- ["link", nil],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
-
- def initialize(about=nil)
- super()
- self.about = about
+ install_text_element(name, ::RSS::URI, nil)
end
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- title_element(false, next_indent),
- description_element(false, next_indent),
- name_element(false, next_indent),
- link_element(false, next_indent),
- other_element(false, next_indent),
- ]
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.about = args[0]
end
- rv = convert(rv) if need_convert
- rv
end
private
- def _tags
- [
- [::RSS::URI, 'title'],
- [::RSS::URI, 'description'],
- [::RSS::URI, 'name'],
- [::RSS::URI, 'link'],
- ].delete_if do |uri, name|
- __send__(name).nil?
- end
- end
-
- def _attrs
- [
- ["#{PREFIX}:about", true, "about"]
- ]
- end
-
def maker_target(maker)
maker.textinput
end
@@ -710,7 +443,7 @@ module RSS
@rss.xml_stylesheets = @xml_stylesheets
@last_element = @rss
@proc_stack.push Proc.new { |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
+ @rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
}
end
end
diff --git a/lib/rss/2.0.rb b/lib/rss/2.0.rb
index 1c3c22ee70..44bdb4f1ae 100644
--- a/lib/rss/2.0.rb
+++ b/lib/rss/2.0.rb
@@ -10,52 +10,20 @@ module RSS
["generator"],
["ttl", :integer],
].each do |name, type|
- install_text_element(name, type)
- install_model(name, '?')
+ install_text_element(name, "", "?", name, type)
end
[
%w(category categories),
].each do |name, plural_name|
- install_have_children_element(name, plural_name)
- install_model(name, '*')
+ install_have_children_element(name, "", "*", name, plural_name)
end
-
+
[
["image", "?"],
["language", "?"],
].each do |name, occurs|
- install_model(name, occurs)
- end
-
- def other_element(need_convert, indent)
- rv = <<-EOT
-#{category_elements(need_convert, indent)}
-#{generator_element(need_convert, indent)}
-#{ttl_element(need_convert, indent)}
-EOT
- rv << super
- end
-
- private
- alias children09 children
- def children
- children09 + @category.compact
- end
-
- alias _tags09 _tags
- def _tags
- rv = %w(generator ttl).delete_if do |name|
- __send__(name).nil?
- end.collect do |elem|
- [nil, elem]
- end + _tags09
-
- @category.each do
- rv << [nil, "category"]
- end
-
- rv
+ install_model(name, "", occurs)
end
Category = Item::Category
@@ -66,15 +34,13 @@ EOT
["comments", "?"],
["author", "?"],
].each do |name, occurs|
- install_text_element(name)
- install_model(name, occurs)
+ install_text_element(name, "", occurs)
end
[
["pubDate", '?'],
].each do |name, occurs|
- install_date_element(name, 'rfc822')
- install_model(name, occurs)
+ install_date_element(name, "", occurs, name, 'rfc822')
end
alias date pubDate
alias date= pubDate=
@@ -82,37 +48,10 @@ EOT
[
["guid", '?'],
].each do |name, occurs|
- install_have_child_element(name)
- install_model(name, occurs)
- end
-
- def other_element(need_convert, indent)
- rv = [
- super,
- *%w(author comments pubDate guid).collect do |name|
- __send__("#{name}_element", false, indent)
- end
- ].reject do |value|
- /\A\s*\z/.match(value)
- end
- rv.join("\n")
+ install_have_child_element(name, "", occurs)
end
private
- alias children09 children
- def children
- children09 + [@guid].compact
- end
-
- alias _tags09 _tags
- def _tags
- %w(comments author pubDate guid).delete_if do |name|
- __send__(name).nil?
- end.collect do |elem|
- [nil, elem]
- end + _tags09
- end
-
alias _setup_maker_element setup_maker_element
def setup_maker_element(item)
_setup_maker_element(item)
@@ -124,17 +63,21 @@ EOT
include RSS09
[
- ["isPermaLink", nil, false, :boolean]
+ ["isPermaLink", "", false, :boolean]
].each do |name, uri, required, type|
install_get_attribute(name, uri, required, type)
end
content_setup
- def initialize(isPermaLink=nil, content=nil)
- super()
- self.isPermaLink = isPermaLink
- self.content = content
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.isPermaLink = args[0]
+ self.content = args[1]
+ end
end
alias_method :_PermaLink?, :PermaLink?
@@ -145,12 +88,6 @@ EOT
end
private
- def _attrs
- [
- ["isPermaLink", false]
- ]
- end
-
def maker_target(item)
item.guid
end
@@ -168,7 +105,7 @@ EOT
end
RSS09::ELEMENTS.each do |name|
- BaseListener.install_get_text_element(nil, name, "#{name}=")
+ BaseListener.install_get_text_element("", name, "#{name}=")
end
end
diff --git a/lib/rss/content.rb b/lib/rss/content.rb
index a732cec973..1b13f39fcf 100644
--- a/lib/rss/content.rb
+++ b/lib/rss/content.rb
@@ -15,28 +15,13 @@ module RSS
def self.append_features(klass)
super
-
- klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
- %w(encoded).each do |name|
- install_text_element("\#{CONTENT_PREFIX}_\#{name}")
- end
- EOC
- end
-
- def content_validate(tags)
- counter = {}
- ELEMENTS.each do |name|
- counter[name] = 0
- end
- tags.each do |tag|
- key = "#{CONTENT_PREFIX}_#{tag}"
- raise UnknownTagError.new(tag, CONTENT_URI) unless counter.has_key?(key)
- counter[key] += 1
- raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
+ klass.install_must_call_validator(CONTENT_PREFIX, CONTENT_URI)
+ %w(encoded).each do |name|
+ klass.install_text_element(name, CONTENT_URI, "?",
+ "#{CONTENT_PREFIX}_#{name}")
end
end
-
end
class RDF
diff --git a/lib/rss/converter.rb b/lib/rss/converter.rb
index 7ad79db318..d928c48223 100644
--- a/lib/rss/converter.rb
+++ b/lib/rss/converter.rb
@@ -66,7 +66,7 @@ module RSS
end
end
- def def_uconv_convert_if_can(meth, to_enc, from_enc)
+ def def_uconv_convert_if_can(meth, to_enc, from_enc, nkf_arg)
begin
require "uconv"
def_convert(1) do |value|
@@ -79,24 +79,27 @@ module RSS
EOC
end
rescue LoadError
- def_iconv_convert(to_enc, from_enc, 1)
+ require 'nkf'
+ def_convert(1) do |value|
+ "NKF.nkf(#{nkf_arg.dump}, #{value})"
+ end
end
end
def def_to_euc_jp_from_utf_8
- def_uconv_convert_if_can('u8toeuc', 'EUC-JP', 'UTF-8')
+ def_uconv_convert_if_can('u8toeuc', 'EUC-JP', 'UTF-8', '-We')
end
def def_to_utf_8_from_euc_jp
- def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP')
+ def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP', '-Ew')
end
def def_to_shift_jis_from_utf_8
- def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8')
+ def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8', '-Ws')
end
def def_to_utf_8_from_shift_jis
- def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS')
+ def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS', '-Sw')
end
def def_to_euc_jp_from_shift_jis
diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb
index 5571640bf2..8a4afd4dd9 100644
--- a/lib/rss/dublincore.rb
+++ b/lib/rss/dublincore.rb
@@ -17,10 +17,10 @@ module RSS
full_name = "#{DC_PREFIX}_#{name}"
full_plural_name = "#{DC_PREFIX}_#{plural}"
klass_name = "DublinCore#{Utils.to_class_name(name)}"
+ klass.install_must_call_validator(DC_PREFIX, DC_URI)
+ klass.install_have_children_element(name, DC_URI, "*",
+ full_name, full_plural_name)
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- install_have_children_element(#{full_name.dump},
- #{full_plural_name.dump})
-
remove_method :#{full_name}
remove_method :#{full_name}=
remove_method :set_#{full_name}
@@ -97,9 +97,13 @@ module RSS
alias_method(:value, :content)
alias_method(:value=, :content=)
- def initialize(content=nil)
- super()
- self.content = content
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.content = args[0]
+ end
end
def full_name
@@ -129,16 +133,6 @@ module RSS
end
EOC
end
-
- def dc_validate(tags)
- tags.each do |tag|
- key = "#{DC_PREFIX}_#{tag}"
- unless DublinCoreModel::ELEMENTS.include?(key)
- raise UnknownTagError.new(tag, DC_URI)
- end
- end
- end
-
end
# For backward compatibility
diff --git a/lib/rss/image.rb b/lib/rss/image.rb
index 9d3326efca..a9e9e9094e 100644
--- a/lib/rss/image.rb
+++ b/lib/rss/image.rb
@@ -17,9 +17,11 @@ module RSS
end
module ImageModelUtils
- def validate_one_tag_name(name, tags)
- invalid = tags.find {|tag| tag != name}
- raise UnknownTagError.new(invalid, IMAGE_URI) if invalid
+ def validate_one_tag_name(ignore_unknown_element, name, tags)
+ if !ignore_unknown_element
+ invalid = tags.find {|tag| tag != name}
+ raise UnknownTagError.new(invalid, IMAGE_URI) if invalid
+ end
raise TooMuchTagError.new(name, tag_name) if tags.size > 1
end
end
@@ -31,13 +33,11 @@ module RSS
def self.append_features(klass)
super
- klass.install_have_child_element("#{IMAGE_PREFIX}_item")
+ klass.install_have_child_element("item", IMAGE_URI, "?",
+ "#{IMAGE_PREFIX}_item")
+ klass.install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
end
- def image_validate(tags)
- validate_one_tag_name("item", tags)
- end
-
class ImageItem < Element
include RSS10
include DublinCoreModel
@@ -53,18 +53,22 @@ module RSS
IMAGE_URI
end
end
-
+
+ install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
+
[
["about", ::RSS::RDF::URI, true],
["resource", ::RSS::RDF::URI, false],
].each do |name, uri, required|
- install_get_attribute(name, uri, required)
+ install_get_attribute(name, uri, required, nil, nil,
+ "#{::RSS::RDF::PREFIX}:#{name}")
end
%w(width height).each do |tag|
full_name = "#{IMAGE_PREFIX}_#{tag}"
disp_name = "#{IMAGE_PREFIX}:#{tag}"
- install_text_element(full_name, :integer, disp_name)
+ install_text_element(tag, IMAGE_URI, "?",
+ full_name, :integer, disp_name)
BaseListener.install_get_text_element(IMAGE_URI, tag, "#{full_name}=")
end
@@ -73,43 +77,21 @@ module RSS
alias height= image_height=
alias height image_height
- def initialize(about=nil, resource=nil)
- super()
- self.about = about
- self.resource = resource
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.about = args[0]
+ self.resource = args[1]
+ end
end
def full_name
tag_name_with_prefix(IMAGE_PREFIX)
end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- other_element(false, next_indent),
- ]
- end
- rv = convert(rv) if need_convert
- rv
- end
private
- def _tags
- [
- [IMAGE_URI, 'width'],
- [IMAGE_URI, 'height'],
- ].delete_if do |uri, name|
- __send__(name).nil?
- end
- end
-
- def _attrs
- [
- ["#{::RSS::RDF::PREFIX}:about", true, "about"],
- ["#{::RSS::RDF::PREFIX}:resource", false, "resource"],
- ]
- end
-
def maker_target(target)
target.image_item
end
@@ -129,14 +111,12 @@ module RSS
super
unless klass.class == Module
- klass.install_have_child_element("#{IMAGE_PREFIX}_favicon")
+ klass.install_have_child_element("favicon", IMAGE_URI, "?",
+ "#{IMAGE_PREFIX}_favicon")
+ klass.install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
end
end
- def image_validate(tags)
- validate_one_tag_name("favicon", tags)
- end
-
class ImageFavicon < Element
include RSS10
include DublinCoreModel
@@ -152,12 +132,13 @@ module RSS
IMAGE_URI
end
end
-
+
[
- ["about", ::RSS::RDF::URI, true],
- ["size", IMAGE_URI, true],
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
+ ["about", ::RSS::RDF::URI, true, ::RSS::RDF::PREFIX],
+ ["size", IMAGE_URI, true, IMAGE_PREFIX],
+ ].each do |name, uri, required, prefix|
+ install_get_attribute(name, uri, required, nil, nil,
+ "#{prefix}:#{name}")
end
AVAILABLE_SIZES = %w(small medium large)
@@ -171,40 +152,27 @@ module RSS
raise NotAvailableValueError.new(full_name, new_value, attr_name)
end
end
- funcall(:_size=, new_value)
+ __send__(:_size=, new_value)
end
alias image_size= size=
alias image_size size
- def initialize(about=nil, size=nil)
- super()
- self.about = about
- self.size = size
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.about = args[0]
+ self.size = args[1]
+ end
end
def full_name
tag_name_with_prefix(IMAGE_PREFIX)
end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- other_element(false, next_indent),
- ]
- end
- rv = convert(rv) if need_convert
- rv
- end
private
- def _attrs
- [
- ["#{::RSS::RDF::PREFIX}:about", true, "about"],
- ["#{IMAGE_PREFIX}:size", true, "size"],
- ]
- end
-
def maker_target(target)
target.image_favicon
end
diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb
index 6d7dd557bf..2327dd98e4 100644
--- a/lib/rss/maker/base.rb
+++ b/lib/rss/maker/base.rb
@@ -207,7 +207,11 @@ EOC
def new_xml_stylesheet
xss = XMLStyleSheet.new(@maker)
@xml_stylesheets << xss
- xss
+ if block_given?
+ yield xss
+ else
+ xss
+ end
end
class XMLStyleSheet
@@ -281,8 +285,12 @@ EOC
def new_day
day = self.class::Day.new(@maker)
- @days << day
- day
+ @days << day
+ if block_given?
+ yield day
+ else
+ day
+ end
end
def current_element(rss)
@@ -311,8 +319,12 @@ EOC
def new_hour
hour = self.class::Hour.new(@maker)
- @hours << hour
- hour
+ @hours << hour
+ if block_given?
+ yield hour
+ else
+ hour
+ end
end
def current_element(rss)
@@ -356,7 +368,11 @@ EOC
def new_category
category = self.class::Category.new(@maker)
@categories << category
- category
+ if block_given?
+ yield category
+ else
+ category
+ end
end
class CategoryBase
@@ -414,8 +430,12 @@ EOC
def new_item
item = self.class::Item.new(@maker)
- @items << item
- item
+ @items << item
+ if block_given?
+ yield item
+ else
+ item
+ end
end
private
diff --git a/lib/rss/maker/dublincore.rb b/lib/rss/maker/dublincore.rb
index e038378329..0cf1255e82 100644
--- a/lib/rss/maker/dublincore.rb
+++ b/lib/rss/maker/dublincore.rb
@@ -53,7 +53,11 @@ EOC
def new_#{name}
#{name} = self.class::#{klass_name}.new(self)
@#{plural_name} << #{name}
- #{name}
+ if block_given?
+ yield #{name}
+ else
+ #{name}
+ end
end
def to_rss(rss, current)
diff --git a/lib/rss/maker/taxonomy.rb b/lib/rss/maker/taxonomy.rb
index 2e54ea66eb..f272996581 100644
--- a/lib/rss/maker/taxonomy.rb
+++ b/lib/rss/maker/taxonomy.rb
@@ -107,7 +107,11 @@ EOC
def new_taxo_topic
taxo_topic = self.class::TaxonomyTopic.new(self)
@taxo_topics << taxo_topic
- taxo_topic
+ if block_given?
+ yield taxo_topic
+ else
+ taxo_topic
+ end
end
def to_rss(rss, current)
diff --git a/lib/rss/maker/trackback.rb b/lib/rss/maker/trackback.rb
index 32254a040c..4ae6164f68 100644
--- a/lib/rss/maker/trackback.rb
+++ b/lib/rss/maker/trackback.rb
@@ -42,8 +42,12 @@ module RSS
def new_about
about = self.class::TrackBackAbout.new(@maker)
- @abouts << about
- about
+ @abouts << about
+ if block_given?
+ yield about
+ else
+ about
+ end
end
def to_rss(rss, current)
diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb
index e63e06e20d..033bc123aa 100644
--- a/lib/rss/parser.rb
+++ b/lib/rss/parser.rb
@@ -1,17 +1,5 @@
require "forwardable"
-begin
- require "open-uri"
-rescue LoadError
- require "uri"
-end
-unless Kernel.methods.include?("URI")
- module Kernel
- def URI(uri_str) # :doc:
- URI.parse(uri_str)
- end
- module_function :URI
- end
-end
+require "open-uri"
require "rss/rss"
@@ -19,6 +7,10 @@ module RSS
class NotWellFormedError < Error
attr_reader :line, :element
+
+ # Create a new NotWellFormedError for an error at +line+
+ # in +element+. If a block is given the return value of
+ # the block ends up in the error message.
def initialize(line=nil, element=nil)
message = "This is not well formed XML"
if element or line
@@ -33,15 +25,16 @@ module RSS
class XMLParserNotFound < Error
def initialize
- super("available XML parser does not found in " <<
+ super("available XML parser was not found in " <<
"#{AVAILABLE_PARSER_LIBRARIES.inspect}.")
end
end
class NotValidXMLParser < Error
def initialize(parser)
- super("#{parser} is not available XML parser. " <<
- "available XML parser is " <<
+ super("#{parser} is not an available XML parser. " <<
+ "Available XML parser"<<
+ (AVAILABLE_PARSERS.size > 1 ? "s are ": " is ") <<
"#{AVAILABLE_PARSERS.inspect}.")
end
end
@@ -67,6 +60,8 @@ module RSS
@@default_parser || AVAILABLE_PARSERS.first
end
+ # Set @@default_parser to new_value if it is one of the
+ # available parsers. Else raise NotValidXMLParser error.
def default_parser=(new_value)
if AVAILABLE_PARSERS.include?(new_value)
@@default_parser = new_value
@@ -75,7 +70,8 @@ module RSS
end
end
- def parse(rss, do_validate=true, ignore_unknown_element=true, parser_class=default_parser)
+ def parse(rss, do_validate=true, ignore_unknown_element=true,
+ parser_class=default_parser)
parser = new(rss, parser_class)
parser.do_validate = do_validate
parser.ignore_unknown_element = ignore_unknown_element
@@ -93,6 +89,10 @@ module RSS
end
private
+
+ # Try to get the XML associated with +rss+.
+ # Return +rss+ if it already looks like XML, or treat it as a URI,
+ # or a file to get the XML,
def normalize_rss(rss)
return rss if maybe_xml?(rss)
@@ -107,10 +107,13 @@ module RSS
end
end
+ # maybe_xml? tests if source is a string that looks like XML.
def maybe_xml?(source)
source.is_a?(String) and /</ =~ source
end
+ # Attempt to convert rss to a URI, but just return it if
+ # there's a ::URI::Error
def to_uri(rss)
return rss if rss.is_a?(::URI::Generic)
@@ -174,11 +177,7 @@ module RSS
@@registered_uris = {}
@@class_names = {}
- def install_setter(uri, tag_name, setter)
- @@setters[uri] ||= {}
- @@setters[uri][tag_name] = setter
- end
-
+ # return the setter for the uri, tag_name pair, or nil.
def setter(uri, tag_name)
begin
@@setters[uri][tag_name]
@@ -187,6 +186,8 @@ module RSS
end
end
+
+ # return the tag_names for setters associated with uri
def available_tags(uri)
begin
@@setters[uri].keys
@@ -195,20 +196,25 @@ module RSS
end
end
+ # register uri against this name.
def register_uri(uri, name)
@@registered_uris[name] ||= {}
@@registered_uris[name][uri] = nil
end
+ # test if this uri is registered against this name
def uri_registered?(uri, name)
@@registered_uris[name].has_key?(uri)
end
+ # record class_name for the supplied uri and tag_name
def install_class_name(uri, tag_name, class_name)
@@class_names[uri] ||= {}
@@class_names[uri][tag_name] = class_name
end
+ # retrieve class_name for the supplied uri and tag_name
+ # If it doesn't exist, capitalize the tag_name
def class_name(uri, tag_name)
begin
@@class_names[uri][tag_name]
@@ -227,20 +233,19 @@ module RSS
end
private
+ # set the setter for the uri, tag_name pair
+ def install_setter(uri, tag_name, setter)
+ @@setters[uri] ||= {}
+ @@setters[uri][tag_name] = setter
+ end
def def_get_text_element(uri, name, file, line)
register_uri(uri, name)
unless private_instance_methods(false).include?("start_#{name}")
module_eval(<<-EOT, file, line)
def start_#{name}(name, prefix, attrs, ns)
- uri = ns[prefix]
+ uri = _ns(ns, prefix)
if self.class.uri_registered?(uri, #{name.inspect})
- if @do_validate
- tags = self.class.available_tags(uri)
- unless tags.include?(name)
- raise UnknownTagError.new(name, uri)
- end
- end
start_get_text_element(name, prefix, ns, uri)
else
start_else_element(name, prefix, attrs, ns)
@@ -275,6 +280,7 @@ module RSS
@xml_stylesheets = []
end
+ # set instance vars for version, encoding, standalone
def xmldecl(version, encoding, standalone)
@version, @encoding, @standalone = version, encoding, standalone
end
@@ -303,7 +309,7 @@ module RSS
@ns_stack.push(ns)
prefix, local = split_name(name)
- @tag_stack.last.push([ns[prefix], local])
+ @tag_stack.last.push([_ns(ns, prefix), local])
@tag_stack.push([])
if respond_to?("start_#{local}", true)
__send__("start_#{local}", local, prefix, attrs, ns.dup)
@@ -329,8 +335,14 @@ module RSS
end
private
+ def _ns(ns, prefix)
+ ns.fetch(prefix, "")
+ end
CONTENT_PATTERN = /\s*([^=]+)=(["'])([^\2]+?)\2/
+ # Extract the first name="value" pair from content.
+ # Works with single quotes according to the constant
+ # CONTENT_PATTERN. Return a Hash.
def parse_pi_content(content)
params = {}
content.scan(CONTENT_PATTERN) do |name, quote, value|
@@ -340,20 +352,20 @@ module RSS
end
def start_else_element(local, prefix, attrs, ns)
- class_name = self.class.class_name(ns[prefix], local)
+ class_name = self.class.class_name(_ns(ns, prefix), local)
current_class = @last_element.class
if current_class.constants.include?(class_name)
next_class = current_class.const_get(class_name)
start_have_something_element(local, prefix, attrs, ns, next_class)
else
- if @ignore_unknown_element
+ if !@do_validate or @ignore_unknown_element
@proc_stack.push(nil)
else
parent = "ROOT ELEMENT???"
if current_class.tag_name
parent = current_class.tag_name
end
- raise NotExceptedTagError.new(local, parent)
+ raise NotExpectedTagError.new(local, _ns(ns, prefix), parent)
end
end
end
@@ -366,7 +378,7 @@ module RSS
def check_ns(tag_name, prefix, ns, require_uri)
if @do_validate
- if ns[prefix] == require_uri
+ if _ns(ns, prefix) == require_uri
#ns.delete(prefix)
else
raise NSError.new(tag_name, prefix, require_uri)
@@ -377,12 +389,12 @@ module RSS
def start_get_text_element(tag_name, prefix, ns, required_uri)
@proc_stack.push Proc.new {|text, tags|
setter = self.class.setter(required_uri, tag_name)
- setter ||= "#{tag_name}="
if @last_element.respond_to?(setter)
@last_element.__send__(setter, text.to_s)
else
- if @do_validate and not @ignore_unknown_element
- raise NotExceptedTagError.new(tag_name, @last_element.tag_name)
+ if @do_validate and !@ignore_unknown_element
+ raise NotExpectedTagError.new(tag_name, _ns(ns, prefix),
+ @last_element.tag_name)
end
end
}
@@ -392,14 +404,13 @@ module RSS
check_ns(tag_name, prefix, ns, klass.required_uri)
- args = []
-
- klass.get_attributes.each do |a_name, a_uri, required|
+ attributes = {}
+ klass.get_attributes.each do |a_name, a_uri, required, element_name|
if a_uri.is_a?(String) or !a_uri.respond_to?(:include?)
a_uri = [a_uri]
end
- unless a_uri == [nil]
+ unless a_uri == [""]
for prefix, uri in ns
if a_uri.include?(uri)
val = attrs["#{prefix}:#{a_name}"]
@@ -407,12 +418,12 @@ module RSS
end
end
end
- if val.nil? and a_uri.include?(nil)
+ if val.nil? and a_uri.include?("")
val = attrs[a_name]
end
if @do_validate and required and val.nil?
- unless a_uri.include?(nil)
+ unless a_uri.include?("")
for prefix, uri in ns
if a_uri.include?(uri)
a_name = "#{prefix}:#{a_name}"
@@ -422,18 +433,19 @@ module RSS
raise MissingAttributeError.new(tag_name, a_name)
end
- args << val
+ attributes[a_name] = val
end
previous = @last_element
- next_element = klass.new(*args)
- next_element.do_validate = @do_validate
- previous.funcall(:set_next_element, tag_name, next_element)
+ next_element = klass.new(@do_validate, attributes)
+ previous.instance_eval {set_next_element(tag_name, next_element)}
@last_element = next_element
@proc_stack.push Proc.new { |text, tags|
p(@last_element.class) if DEBUG
@last_element.content = text if klass.have_content?
- @last_element.validate_for_stream(tags) if @do_validate
+ if @do_validate
+ @last_element.validate_for_stream(tags, @ignore_unknown_element)
+ end
@last_element = previous
}
end
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index f424f16171..a06985af94 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -30,36 +30,6 @@ class Time
end
end
-module Enumerable
- unless instance_methods.include?("sort_by")
- def sort_by
- collect do |x|
- [yield(x), x]
- end.sort do |x, y|
- x[0] <=> y[0]
- end.collect! do |x|
- x[1]
- end
- end
- end
-end
-
-class Hash
- unless instance_methods.include?("merge")
- def merge(other)
- dup.update(other)
- end
- end
-end
-
-module Kernel
- unless methods.include?("funcall")
- def funcall(*args, &block)
- __send__(*args, &block)
- end
- end
-end
-
require "English"
require "rss/utils"
require "rss/converter"
@@ -116,13 +86,15 @@ module RSS
end
end
- class NotExceptedTagError < InvalidRSSError
- attr_reader :tag, :parent
- def initialize(tag, parent)
- @tag, @parent = tag, parent
- super("tag <#{tag}> is not expected in tag <#{parent}>")
+ class NotExpectedTagError < InvalidRSSError
+ attr_reader :tag, :uri, :parent
+ def initialize(tag, uri, parent)
+ @tag, @uri, @parent = tag, uri, parent
+ super("tag <{#{uri}}#{tag}> is not expected in tag <#{parent}>")
end
end
+ # For backward compatibility :X
+ NotExceptedTagError = NotExpectedTagError
class NotAvailableValueError < InvalidRSSError
attr_reader :tag, :value, :attribute
@@ -169,8 +141,10 @@ module RSS
include Utils
- def install_have_child_element(name)
+ def install_have_child_element(tag_name, uri, occurs, name=nil)
+ name ||= tag_name
add_need_initialize_variable(name)
+ install_model(tag_name, uri, occurs, name)
attr_accessor name
install_element(name) do |n, elem_name|
@@ -185,11 +159,13 @@ EOC
end
alias_method(:install_have_attribute_element, :install_have_child_element)
- def install_have_children_element(name, plural_name=nil)
+ def install_have_children_element(tag_name, uri, occurs, name=nil, plural_name=nil)
+ name ||= tag_name
plural_name ||= "#{name}s"
add_have_children_element(name, plural_name)
add_plural_form(name, plural_name)
-
+ install_model(tag_name, uri, occurs, plural_name)
+
def_children_accessor(name, plural_name)
install_element(name, "s") do |n, elem_name|
<<-EOC
@@ -203,9 +179,12 @@ EOC
end
end
- def install_text_element(name, type=nil, disp_name=name)
+ def install_text_element(tag_name, uri, occurs, name=nil, type=nil, disp_name=nil)
+ name ||= tag_name
+ disp_name ||= name
self::ELEMENTS << name
add_need_initialize_variable(name)
+ install_model(tag_name, uri, occurs, name)
def_corresponded_attr_writer name, type, disp_name
convert_attr_reader name
@@ -228,9 +207,13 @@ EOC
end
end
- def install_date_element(name, type, disp_name=name)
+ def install_date_element(tag_name, uri, occurs, name=nil, type=nil, disp_name=nil)
+ name ||= tag_name
+ type ||= :w3cdtf
+ disp_name ||= name
self::ELEMENTS << name
add_need_initialize_variable(name)
+ install_model(tag_name, uri, occurs, name)
# accessor
convert_attr_reader name
@@ -259,11 +242,13 @@ EOC
private
def install_element(name, postfix="")
elem_name = name.sub('_', ':')
+ method_name = "#{name}_element#{postfix}"
+ add_to_element_method(method_name)
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}_element#{postfix}(need_convert=true, indent='')
+ def #{method_name}(need_convert=true, indent='')
#{yield(name, elem_name)}
end
- private :#{name}_element#{postfix}
+ private :#{method_name}
EOC
end
@@ -407,23 +392,6 @@ EOC
alias_method(:set_#{accessor_name}, :#{accessor_name}=)
EOC
end
-
- def def_content_only_to_s
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def to_s(need_convert=true, indent=calc_indent)
- if @content
- rv = tag(indent) do |next_indent|
- h(@content)
- end
- rv = convert(rv) if need_convert
- rv
- else
- ""
- end
- end
-EOC
- end
-
end
class Element
@@ -434,9 +402,10 @@ EOC
INDENT = " "
MUST_CALL_VALIDATORS = {}
- MODEL = []
+ MODELS = []
GET_ATTRIBUTES = []
HAVE_CHILDREN_ELEMENTS = []
+ TO_ELEMENT_METHODS = []
NEED_INITIALIZE_VARIABLES = []
PLURAL_FORMS = {}
@@ -445,8 +414,8 @@ EOC
def must_call_validators
MUST_CALL_VALIDATORS
end
- def model
- MODEL
+ def models
+ MODELS
end
def get_attributes
GET_ATTRIBUTES
@@ -454,6 +423,9 @@ EOC
def have_children_elements
HAVE_CHILDREN_ELEMENTS
end
+ def to_element_methods
+ TO_ELEMENT_METHODS
+ end
def need_initialize_variables
NEED_INITIALIZE_VARIABLES
end
@@ -464,9 +436,10 @@ EOC
def inherited(klass)
klass.const_set("MUST_CALL_VALIDATORS", {})
- klass.const_set("MODEL", [])
+ klass.const_set("MODELS", [])
klass.const_set("GET_ATTRIBUTES", [])
klass.const_set("HAVE_CHILDREN_ELEMENTS", [])
+ klass.const_set("TO_ELEMENT_METHODS", [])
klass.const_set("NEED_INITIALIZE_VARIABLES", [])
klass.const_set("PLURAL_FORMS", {})
@@ -475,14 +448,13 @@ EOC
@tag_name = name.split(/::/).last
@tag_name[0,1] = @tag_name[0,1].downcase
- @indent_size = name.split(/::/).size - 2
@have_content = false
def self.must_call_validators
super.merge(MUST_CALL_VALIDATORS)
end
- def self.model
- MODEL + super
+ def self.models
+ MODELS + super
end
def self.get_attributes
GET_ATTRIBUTES + super
@@ -490,6 +462,9 @@ EOC
def self.have_children_elements
HAVE_CHILDREN_ELEMENTS + super
end
+ def self.to_element_methods
+ TO_ELEMENT_METHODS + super
+ end
def self.need_initialize_variables
NEED_INITIALIZE_VARIABLES + super
end
@@ -502,22 +477,27 @@ EOC
MUST_CALL_VALIDATORS[uri] = prefix
end
- def self.install_model(tag, occurs=nil)
- if m = MODEL.find {|t, o| t == tag}
- m[1] = occurs
+ def self.install_model(tag, uri, occurs=nil, getter=nil)
+ getter ||= tag
+ if m = MODELS.find {|t, u, o, g| t == tag and u == uri}
+ m[2] = occurs
else
- MODEL << [tag, occurs]
+ MODELS << [tag, uri, occurs, getter]
end
end
def self.install_get_attribute(name, uri, required=true,
- type=nil, disp_name=name)
+ type=nil, disp_name=nil,
+ element_name=nil)
+ disp_name ||= name
+ element_name ||= name
def_corresponded_attr_writer name, type, disp_name
convert_attr_reader name
if type == :boolean and /^is/ =~ name
alias_method "\#{$POSTMATCH}?", name
end
- GET_ATTRIBUTES << [name, uri, required]
+ GET_ATTRIBUTES << [name, uri, required, element_name]
+ add_need_initialize_variable(disp_name)
end
def self.def_corresponded_attr_writer(name, type=nil, disp_name=name)
@@ -528,6 +508,8 @@ EOC
positive_integer_writer name, disp_name
when :boolean
boolean_writer name, disp_name
+ when :w3cdtf, :rfc822, :rfc2822
+ date_writer name, type, disp_name
else
attr_writer name
end
@@ -536,7 +518,6 @@ EOC
def self.content_setup(type=nil)
def_corresponded_attr_writer "content", type
convert_attr_reader :content
- def_content_only_to_s
@have_content = true
end
@@ -548,6 +529,10 @@ EOC
HAVE_CHILDREN_ELEMENTS << [variable_name, plural_name]
end
+ def self.add_to_element_method(method_name)
+ TO_ELEMENT_METHODS << method_name
+ end
+
def self.add_need_initialize_variable(variable_name)
NEED_INITIALIZE_VARIABLES << variable_name
end
@@ -564,7 +549,7 @@ EOC
end
def required_uri
- nil
+ ""
end
def install_ns(prefix, uri)
@@ -577,19 +562,14 @@ EOC
def tag_name
@tag_name
end
-
- def indent_size
- @indent_size
- end
-
end
attr_accessor :do_validate
- def initialize(do_validate=true)
+ def initialize(do_validate=true, attrs={})
@converter = nil
@do_validate = do_validate
- initialize_variables
+ initialize_variables(attrs)
end
def tag_name
@@ -600,10 +580,6 @@ EOC
tag_name
end
- def indent_size
- self.class.indent_size
- end
-
def converter=(converter)
@converter = converter
targets = children.dup
@@ -623,14 +599,14 @@ EOC
end
end
- def validate
+ def validate(ignore_unknown_element=true)
validate_attribute
- __validate
+ __validate(ignore_unknown_element)
end
- def validate_for_stream(tags)
+ def validate_for_stream(tags, ignore_unknown_element=true)
validate_attribute
- __validate(tags, false)
+ __validate(ignore_unknown_element, tags, false)
end
def setup_maker(maker)
@@ -641,11 +617,37 @@ EOC
setup_maker_elements(target)
end
end
-
+
+ def to_s(need_convert=true, indent='')
+ if self.class.have_content?
+ return "" unless @content
+ rv = tag(indent) do |next_indent|
+ h(@content)
+ end
+ else
+ rv = tag(indent) do |next_indent|
+ self.class.to_element_methods.collect do |method_name|
+ __send__(method_name, false, next_indent)
+ end
+ end
+ end
+ rv = convert(rv) if need_convert
+ rv
+ end
+
private
- def initialize_variables
+ def initialize_variables(attrs)
+ normalized_attrs = {}
+ attrs.each do |key, value|
+ normalized_attrs[key.to_s] = value
+ end
self.class.need_initialize_variables.each do |variable_name|
- instance_eval("@#{variable_name} = nil")
+ value = normalized_attrs[variable_name.to_s]
+ if value
+ __send__("#{variable_name}=", value)
+ else
+ instance_eval("@#{variable_name} = nil")
+ end
end
initialize_have_children_elements
@content = "" if self.class.have_content?
@@ -657,13 +659,13 @@ EOC
end
end
- def tag(indent, additional_attrs=[], &block)
+ def tag(indent, additional_attrs={}, &block)
next_indent = indent + INDENT
attrs = collect_attrs
return "" if attrs.nil?
- attrs += additional_attrs
+ attrs.update(additional_attrs)
start_tag = make_start_tag(indent, next_indent, attrs)
if block
@@ -700,21 +702,24 @@ EOC
end
def collect_attrs
- _attrs.collect do |name, required, alias_name|
+ attrs = {}
+ _attrs.each do |name, required, alias_name|
value = __send__(alias_name || name)
return nil if required and value.nil?
- [name, value]
- end.reject do |name, value|
- value.nil?
+ next if value.nil?
+ return nil if attrs.has_key?(name)
+ attrs[name] = value
end
+ attrs
end
def tag_name_with_prefix(prefix)
"#{prefix}:#{tag_name}"
end
-
+
+ # For backward compatibility
def calc_indent
- INDENT * (self.class.indent_size)
+ ''
end
def maker_target(maker)
@@ -766,22 +771,41 @@ EOC
__send__("#{prefix}#{tag_name}=", next_element)
end
end
-
- # not String class children.
+
def children
- []
+ rv = []
+ self.class.models.each do |name, uri, occurs, getter|
+ value = __send__(getter)
+ next if value.nil?
+ value = [value] unless value.is_a?(Array)
+ value.each do |v|
+ rv << v if v.is_a?(Element)
+ end
+ end
+ rv
end
- # default #validate() argument.
def _tags
- []
+ rv = []
+ self.class.models.each do |name, uri, occurs, getter|
+ value = __send__(getter)
+ next if value.nil?
+ if value.is_a?(Array)
+ rv.concat([[uri, name]] * value.size)
+ else
+ rv << [uri, name]
+ end
+ end
+ rv
end
def _attrs
- []
+ self.class.get_attributes.collect do |name, uri, required, element_name|
+ [element_name, required, name]
+ end
end
- def __validate(tags=_tags, recursive=true)
+ def __validate(ignore_unknown_element, tags=_tags, recursive=true)
if recursive
children.compact.each do |child|
child.validate
@@ -790,14 +814,12 @@ EOC
must_call_validators = self.class.must_call_validators
tags = tag_filter(tags.dup)
p tags if DEBUG
- self.class::NSPOOL.each do |prefix, uri|
- if tags.has_key?(uri) and !must_call_validators.has_key?(uri)
- meth = "#{prefix}_validate"
- __send__(meth, tags[uri]) if respond_to?(meth, true)
- end
- end
must_call_validators.each do |uri, prefix|
- __send__("#{prefix}_validate", tags[uri])
+ _validate(ignore_unknown_element, tags[uri], uri)
+ meth = "#{prefix}_validate"
+ if respond_to?(meth, true)
+ __send__(meth, ignore_unknown_element, tags[uri], uri)
+ end
end
end
@@ -809,35 +831,25 @@ EOC
end
end
- def other_element(need_convert, indent='')
- rv = []
- private_methods.each do |meth|
- if /\A([^_]+)_[^_]+_elements?\z/ =~ meth and
- self.class::NSPOOL.has_key?($1)
- res = __send__(meth, need_convert, indent)
- rv << res if /\A\s*\z/ !~ res
- end
- end
- rv.join("\n")
- end
-
- def _validate(tags, model=self.class.model)
+ def _validate(ignore_unknown_element, tags, uri, models=self.class.models)
count = 1
do_redo = false
not_shift = false
tag = nil
- element_names = model.collect {|elem| elem[0]}
+ models = models.find_all {|model| model[1] == uri}
+ element_names = models.collect {|model| model[0]}
if tags
tags_size = tags.size
tags = tags.sort_by {|x| element_names.index(x) || tags_size}
end
- model.each_with_index do |elem, i|
+ models.each_with_index do |model, i|
+ name, model_uri, occurs, getter = model
if DEBUG
p "before"
p tags
- p elem
+ p model
end
if not_shift
@@ -851,41 +863,41 @@ EOC
p count
end
- case elem[1]
+ case occurs
when '?'
if count > 2
- raise TooMuchTagError.new(elem[0], tag_name)
+ raise TooMuchTagError.new(name, tag_name)
else
- if elem[0] == tag
+ if name == tag
do_redo = true
else
not_shift = true
end
end
when '*'
- if elem[0] == tag
+ if name == tag
do_redo = true
else
not_shift = true
end
when '+'
- if elem[0] == tag
+ if name == tag
do_redo = true
else
if count > 1
not_shift = true
else
- raise MissingTagError.new(elem[0], tag_name)
+ raise MissingTagError.new(name, tag_name)
end
end
else
- if elem[0] == tag
- if model[i+1] and model[i+1][0] != elem[0] and
- tags and tags.first == elem[0]
- raise TooMuchTagError.new(elem[0], tag_name)
+ if name == tag
+ if models[i+1] and models[i+1][0] != name and
+ tags and tags.first == name
+ raise TooMuchTagError.new(name, tag_name)
end
else
- raise MissingTagError.new(elem[0], tag_name)
+ raise MissingTagError.new(name, tag_name)
end
end
@@ -906,8 +918,8 @@ EOC
end
- if !tags.nil? and !tags.empty?
- raise NotExceptedTagError.new(tag, tag_name)
+ if !ignore_unknown_element and !tags.nil? and !tags.empty?
+ raise NotExpectedTagError.new(tags.first, uri, tag_name)
end
end
@@ -954,11 +966,22 @@ EOC
setup_maker_elements(maker)
end
-
+
+ def to_xml(version=nil, &block)
+ if version.nil? or version == @rss_version
+ to_s
+ else
+ RSS::Maker.make(version) do |maker|
+ setup_maker(maker)
+ block.call(maker) if block
+ end.to_s
+ end
+ end
+
private
- def tag(indent, attrs, &block)
+ def tag(indent, attrs={}, &block)
rv = xmldecl + xml_stylesheet_pi
- rv << super(indent, attrs, &block)
+ rv << super(indent, ns_declarations.merge(attrs), &block)
rv
end
@@ -973,10 +996,12 @@ EOC
end
def ns_declarations
+ decls = {}
self.class::NSPOOL.collect do |prefix, uri|
prefix = ":#{prefix}" unless prefix.empty?
- ["xmlns#{prefix}", uri]
+ decls["xmlns#{prefix}"] = uri
end
+ decls
end
def setup_maker_elements(maker)
diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb
index 8791ec24fc..93d35c89a7 100644
--- a/lib/rss/syndication.rb
+++ b/lib/rss/syndication.rb
@@ -15,18 +15,21 @@ module RSS
def self.append_features(klass)
super
-
- klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
+
+ klass.install_must_call_validator(SY_PREFIX, SY_URI)
+ klass.module_eval do
[
["updatePeriod"],
["updateFrequency", :positive_integer]
].each do |name, type|
- install_text_element("\#{SY_PREFIX}_\#{name}", type,
- "\#{SY_PREFIX}:\#{name}")
+ install_text_element(name, SY_URI, "?",
+ "#{SY_PREFIX}_#{name}", type,
+ "#{SY_PREFIX}:#{name}")
end
%w(updateBase).each do |name|
- install_date_element("\#{SY_PREFIX}_\#{name}", 'w3cdtf', name)
+ install_date_element(name, SY_URI, "?",
+ "#{SY_PREFIX}_#{name}", 'w3cdtf', name)
end
alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
@@ -35,20 +38,6 @@ module RSS
validate_sy_updatePeriod(new_value) if @do_validate
self._sy_updatePeriod = new_value
end
- EOC
- end
-
- def sy_validate(tags)
- counter = {}
- ELEMENTS.each do |name|
- counter[name] = 0
- end
-
- tags.each do |tag|
- key = "#{SY_PREFIX}_#{tag}"
- raise UnknownTagError.new(tag, SY_URI) unless counter.has_key?(key)
- counter[key] += 1
- raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
end
end
diff --git a/lib/rss/taxonomy.rb b/lib/rss/taxonomy.rb
index 52267133ff..8caa25e2a4 100644
--- a/lib/rss/taxonomy.rb
+++ b/lib/rss/taxonomy.rb
@@ -28,22 +28,10 @@ module RSS
def self.append_features(klass)
super
- var_name = "#{TAXO_PREFIX}_topics"
- klass.install_have_child_element(var_name)
- end
-
- def taxo_validate(tags)
- found_topics = false
- tags.each do |tag|
- if tag == "topics"
- if found_topics
- raise TooMuchTagError.new(tag, tag_name)
- else
- found_topics = true
- end
- else
- raise UnknownTagError.new(tag, TAXO_URI)
- end
+ klass.install_must_call_validator(TAXO_PREFIX, TAXO_URI)
+ %w(topics).each do |name|
+ klass.install_have_child_element(name, TAXO_URI, "?",
+ "#{TAXO_PREFIX}_#{name}")
end
end
@@ -64,13 +52,17 @@ module RSS
@tag_name = "topics"
- install_have_child_element("Bag")
-
- install_must_call_validator('rdf', ::RSS::RDF::URI)
+ install_have_child_element("Bag", RDF::URI, nil)
+ install_must_call_validator('rdf', RDF::URI)
- def initialize(bag=Bag.new)
- super()
- @Bag = bag
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.Bag = args[0]
+ end
+ self.Bag ||= Bag.new
end
def full_name
@@ -80,15 +72,6 @@ module RSS
def maker_target(target)
target.taxo_topics
end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- Bag_element(need_convert, next_indent),
- other_element(need_convert, next_indent),
- ]
- end
- end
def resources
if @Bag
@@ -99,21 +82,6 @@ module RSS
[]
end
end
-
- private
- def children
- [@Bag]
- end
-
- def _tags
- rv = []
- rv << [::RSS::RDF::URI, 'Bag'] unless @Bag.nil?
- rv
- end
-
- def rdf_validate(tags)
- _validate(tags, [["Bag", nil]])
- end
end
end
@@ -123,15 +91,7 @@ module RSS
def self.append_features(klass)
super
var_name = "#{TAXO_PREFIX}_topic"
- klass.install_have_children_element(var_name)
- end
-
- def taxo_validate(tags)
- tags.each do |tag|
- if tag != "topic"
- raise UnknownTagError.new(tag, TAXO_URI)
- end
- end
+ klass.install_have_children_element("topic", TAXO_URI, "*", var_name)
end
class TaxonomyTopic < Element
@@ -152,62 +112,26 @@ module RSS
@tag_name = "topic"
- install_get_attribute("about", ::RSS::RDF::URI, true)
- install_text_element("#{TAXO_PREFIX}_link")
+ install_get_attribute("about", ::RSS::RDF::URI, true, nil, nil,
+ "#{RDF::PREFIX}:about")
+ install_text_element("link", TAXO_URI, "?", "#{TAXO_PREFIX}_link")
- def initialize(about=nil)
- super()
- @about = about
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.about = args[0]
+ end
end
def full_name
tag_name_with_prefix(TAXO_PREFIX)
end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent) do |next_indent|
- [
- other_element(need_convert, next_indent),
- ]
- end
- end
-
- def taxo_validate(tags)
- elements = %w(link topics)
- counter = {}
-
- tags.each do |tag|
- if elements.include?(tag)
- counter[tag] ||= 0
- counter[tag] += 1
- raise TooMuchTagError.new(tag, tag_name) if counter[tag] > 1
- else
- raise UnknownTagError.new(tag, TAXO_URI)
- end
- end
- end
def maker_target(target)
target.new_taxo_topic
end
-
- private
- def children
- [@taxo_link, @taxo_topics]
- end
-
- def _attrs
- [
- ["#{RDF::PREFIX}:about", true, "about"]
- ]
- end
-
- def _tags
- rv = []
- rv << [TAXO_URI, "link"] unless @taxo_link.nil?
- rv << [TAXO_URI, "topics"] unless @taxo_topics.nil?
- rv
- end
end
end
diff --git a/lib/rss/trackback.rb b/lib/rss/trackback.rb
index ad6954f3f5..ee2491f332 100644
--- a/lib/rss/trackback.rb
+++ b/lib/rss/trackback.rb
@@ -11,28 +11,15 @@ module RSS
module TrackBackUtils
private
- def trackback_validate(tags)
- counter = {}
- %w(ping about).each do |name|
- counter["#{TRACKBACK_PREFIX}_#{name}"] = 0
- end
-
- tags.each do |tag|
- key = "#{TRACKBACK_PREFIX}_#{tag}"
- raise UnknownTagError.new(tag, TRACKBACK_URI) unless counter.has_key?(key)
- counter[key] += 1
- if tag != "about" and counter[key] > 1
- raise TooMuchTagError.new(tag, tag_name)
- end
- end
-
- if counter["#{TRACKBACK_PREFIX}_ping"].zero? and
- counter["#{TRACKBACK_PREFIX}_about"].nonzero?
+ def trackback_validate(ignore_unknown_element, tags, uri)
+ return if tags.nil?
+ if tags.find {|tag| tag == "about"} and
+ !tags.find {|tag| tag == "ping"}
raise MissingTagError.new("#{TRACKBACK_PREFIX}:ping", tag_name)
end
end
end
-
+
module BaseTrackBackModel
ELEMENTS = %w(ping about)
@@ -43,10 +30,11 @@ module RSS
unless klass.class == Module
klass.module_eval {include TrackBackUtils}
+ klass.install_must_call_validator(TRACKBACK_PREFIX, TRACKBACK_URI)
%w(ping).each do |name|
var_name = "#{TRACKBACK_PREFIX}_#{name}"
klass_name = "TrackBack#{Utils.to_class_name(name)}"
- klass.install_have_child_element(var_name)
+ klass.install_have_child_element(name, TRACKBACK_URI, "?", var_name)
klass.module_eval(<<-EOC, __FILE__, __LINE__)
remove_method :#{var_name}
def #{var_name}
@@ -63,7 +51,8 @@ module RSS
[%w(about s)].each do |name, postfix|
var_name = "#{TRACKBACK_PREFIX}_#{name}"
klass_name = "TrackBack#{Utils.to_class_name(name)}"
- klass.install_have_children_element(var_name)
+ klass.install_have_children_element(name, TRACKBACK_URI, "*",
+ var_name)
klass.module_eval(<<-EOC, __FILE__, __LINE__)
remove_method :#{var_name}
def #{var_name}(*args)
@@ -124,38 +113,28 @@ module RSS
end
@tag_name = "ping"
-
+
[
["resource", ::RSS::RDF::URI, true]
].each do |name, uri, required|
- install_get_attribute(name, uri, required)
+ install_get_attribute(name, uri, required, nil, nil,
+ "#{::RSS::RDF::PREFIX}:#{name}")
end
alias_method(:value, :resource)
alias_method(:value=, :resource=)
-
- def initialize(resource=nil)
- super()
- @resource = resource
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.resource = args[0]
+ end
end
def full_name
tag_name_with_prefix(TRACKBACK_PREFIX)
end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent)
- rv = convert(rv) if need_convert
- rv
- end
-
- private
- def _attrs
- [
- ["#{::RSS::RDF::PREFIX}:resource", true, "resource"],
- ]
- end
-
end
class TrackBackAbout < Element
@@ -174,38 +153,31 @@ module RSS
end
@tag_name = "about"
-
+
[
["resource", ::RSS::RDF::URI, true]
].each do |name, uri, required|
- install_get_attribute(name, uri, required)
+ install_get_attribute(name, uri, required, nil, nil,
+ "#{::RSS::RDF::PREFIX}:#{name}")
end
alias_method(:value, :resource)
alias_method(:value=, :resource=)
- def initialize(resource=nil)
- super()
- @resource = resource
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.resource = args[0]
+ end
end
def full_name
tag_name_with_prefix(TRACKBACK_PREFIX)
end
-
- def to_s(need_convert=true, indent=calc_indent)
- rv = tag(indent)
- rv = convert(rv) if need_convert
- rv
- end
private
- def _attrs
- [
- ["#{::RSS::RDF::PREFIX}:resource", true, "resource"],
- ]
- end
-
def maker_target(abouts)
abouts.new_about
end
@@ -243,9 +215,13 @@ module RSS
alias_method(:value, :content)
alias_method(:value=, :content=)
- def initialize(content=nil)
- super()
- @content = content
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.content = args[0]
+ end
end
def full_name
@@ -276,9 +252,13 @@ module RSS
alias_method(:value, :content)
alias_method(:value=, :content=)
- def initialize(content=nil)
- super()
- @content = content
+ def initialize(*args)
+ if Utils.element_initialize_arguments?(args)
+ super
+ else
+ super()
+ self.content = args[0]
+ end
end
def full_name
diff --git a/lib/rss/utils.rb b/lib/rss/utils.rb
index 0286becf00..b242a72292 100644
--- a/lib/rss/utils.rb
+++ b/lib/rss/utils.rb
@@ -1,8 +1,8 @@
module RSS
-
module Utils
-
module_function
+
+ # Convert a name_with_underscores to CamelCase.
def to_class_name(name)
name.split(/_/).collect do |part|
"#{part[0, 1].upcase}#{part[1..-1]}"
@@ -14,11 +14,14 @@ module RSS
[file, line.to_i]
end
+ # escape '&', '"', '<' and '>' for use in HTML.
def html_escape(s)
s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
end
alias h html_escape
+ # If +value+ is an instance of class +klass+, return it, else
+ # create a new instance of +klass+ with value +value+.
def new_with_value_if_need(klass, value)
if value.is_a?(klass)
value
@@ -26,6 +29,9 @@ module RSS
klass.new(value)
end
end
- end
+ def element_initialize_arguments?(args)
+ [true, false].include?(args[0]) and args[1].is_a?(Hash)
+ end
+ end
end
diff --git a/lib/runit/assert.rb b/lib/runit/assert.rb
index f18bb36127..c752b19a25 100644
--- a/lib/runit/assert.rb
+++ b/lib/runit/assert.rb
@@ -6,7 +6,8 @@ require 'test/unit/assertions'
require 'runit/error'
module RUNIT
- module AssertMixin
+ module Assert
+ include Test::Unit::Assertions
def setup_assert
end
@@ -69,8 +70,4 @@ module RUNIT
/assertions\.rb/.match(caller[1])
end
end
- module Assert
- include Test::Unit::Assertions
- include AssertMixin
- end
end
diff --git a/lib/runit/testcase.rb b/lib/runit/testcase.rb
index 9e05a58abe..4576cb8644 100644
--- a/lib/runit/testcase.rb
+++ b/lib/runit/testcase.rb
@@ -10,7 +10,7 @@ require 'test/unit/testcase'
module RUNIT
class TestCase < Test::Unit::TestCase
- include RUNIT::AssertMixin
+ include RUNIT::Assert
def self.suite
method_names = instance_methods(true)
diff --git a/lib/scanf.rb b/lib/scanf.rb
index 87b7e98eeb..2972bf9d60 100644
--- a/lib/scanf.rb
+++ b/lib/scanf.rb
@@ -1,6 +1,5 @@
# scanf for Ruby
#
-# $Release Version: 1.1.2 $
# $Revision$
# $Id$
# $Author$
@@ -467,11 +466,11 @@ module Scanf
end
def letter
- @spec_string[/%\*?\d*([a-z\[])/, 1]
+ /%\*?\d*([a-z\[])/.match(@spec_string).to_a[1]
end
def width
- w = @spec_string[/%\*?(\d+)/, 1]
+ w = /%\*?(\d+)/.match(@spec_string).to_a[1]
w && w.to_i
end
@@ -542,8 +541,7 @@ module Scanf
@string_left = str
@matched_count = 0
- @specs.each_with_index do |spec,i|
- @i=i
+ @specs.each_with_index do |spec,@i|
@last_spec_tried = spec
@last_match_tried = spec.match(@string_left)
break unless @last_match_tried
diff --git a/lib/set.rb b/lib/set.rb
index 66ffc898a1..d3f85f8422 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -101,6 +101,7 @@ class Set
if enum.class == self.class
@hash.replace(enum.instance_eval { @hash })
else
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
clear
enum.each { |o| add(o) }
end
@@ -227,7 +228,7 @@ class Set
# Deletes every element of the set for which block evaluates to
# true, and returns self.
def delete_if
- @hash.delete_if { |o,| yield(o) }
+ to_a.each { |o| @hash.delete(o) if yield(o) }
self
end
@@ -253,6 +254,7 @@ class Set
if enum.is_a?(Set)
@hash.update(enum.instance_eval { @hash })
else
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
enum.each { |o| add(o) }
end
@@ -262,6 +264,7 @@ class Set
# Deletes every element that appears in the given enumerable object
# and returns self.
def subtract(enum)
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
enum.each { |o| delete(o) }
self
end
@@ -269,6 +272,7 @@ class Set
# Returns a new set built by merging the set and the elements of the
# given enumerable object.
def |(enum)
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
dup.merge(enum)
end
alias + | ##
@@ -277,23 +281,26 @@ class Set
# Returns a new set built by duplicating the set, removing every
# element that appears in the given enumerable object.
def -(enum)
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
dup.subtract(enum)
end
alias difference - ##
- # Returns a new array containing elements common to the set and the
+ # Returns a new set containing elements common to the set and the
# given enumerable object.
def &(enum)
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
n = self.class.new
enum.each { |o| n.add(o) if include?(o) }
n
end
alias intersection & ##
- # Returns a new array containing elements exclusive between the set
+ # Returns a new set containing elements exclusive between the set
# and the given enumerable object. (set ^ enum) is equivalent to
# ((set | enum) - (set & enum)).
def ^(enum)
+ enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
n = Set.new(enum)
each { |o| if n.include?(o) then n.delete(o) else n.add(o) end }
n
@@ -479,7 +486,7 @@ class SortedSet < Set
def delete_if
n = @hash.size
- @hash.delete_if { |o,| yield(o) }
+ super
@keys = nil if @hash.size != n
self
end
@@ -491,6 +498,7 @@ class SortedSet < Set
def each
to_a.each { |o| yield(o) }
+ self
end
def to_a
@@ -567,6 +575,7 @@ end
# end
#
# def replace(enum)
+# enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
# clear
# enum.each { |o| add(o) }
#
@@ -574,6 +583,7 @@ end
# end
#
# def merge(enum)
+# enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
# enum.each { |o| add(o) }
#
# self
@@ -640,11 +650,12 @@ class TC_Set < Test::Unit::TestCase
Set.new([])
Set.new([1,2])
Set.new('a'..'c')
+ Set.new('XYZ')
}
- assert_raises(NoMethodError) {
+ assert_raises(ArgumentError) {
Set.new(false)
}
- assert_raises(NoMethodError) {
+ assert_raises(ArgumentError) {
Set.new(1)
}
assert_raises(ArgumentError) {
@@ -1151,11 +1162,33 @@ class TC_SortedSet < Test::Unit::TestCase
assert_equal([-10,-8,-6,-4,-2], s.to_a)
prev = nil
- s.each { |o| assert(prev < o) if prev; prev = o }
+ ret = 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.rb b/lib/shell.rb
index 9c6847c623..039f849ef5 100644
--- a/lib/shell.rb
+++ b/lib/shell.rb
@@ -31,7 +31,9 @@ class Shell
@verbose = true
class << Shell
- attr_accessor :cascade, :debug, :verbose
+ attr :cascade, true
+ attr :debug, true
+ attr :verbose, true
# alias cascade? cascade
alias debug? debug
@@ -96,8 +98,11 @@ class Shell
rehash
end
- attr_accessor :umask, :record_separator
- attr_accessor :verbose, :debug
+ attr :umask, true
+ attr :record_separator, true
+
+ attr :verbose, true
+ attr :debug, true
def debug=(val)
@debug = val
diff --git a/lib/shell/process-controller.rb b/lib/shell/process-controller.rb
index f74abfd686..8929805506 100644
--- a/lib/shell/process-controller.rb
+++ b/lib/shell/process-controller.rb
@@ -246,9 +246,11 @@ class Shell
redo
end
Thread.exclusive do
- terminate_job(command)
- @job_condition.signal
- command.notify "job(%id) finish.", @shell.debug?
+ @job_monitor.synchronize do
+ terminate_job(command)
+ @job_condition.signal
+ command.notify "job(%id) finish.", @shell.debug?
+ end
end
end
}
diff --git a/lib/shellwords.rb b/lib/shellwords.rb
index 04d0c4fff8..e87b9e656b 100644
--- a/lib/shellwords.rb
+++ b/lib/shellwords.rb
@@ -26,16 +26,32 @@ module Shellwords
# See the +Shellwords+ module documentation for an example.
#
def shellwords(line)
+ line = String.new(line) rescue
+ raise(ArgumentError, "Argument must be a string")
+ line.lstrip!
words = []
- field = ''
- line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do
- |word, sq, dq, esc, garbage, sep|
- raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage
- field << (word || sq || (dq || esc).gsub(/\\(?=.)/, ''))
- if sep
- words << field
- field = ''
+ until line.empty?
+ field = ''
+ loop do
+ if line.sub!(/\A"(([^"\\]|\\.)*)"/, '') then
+ snippet = $1.gsub(/\\(.)/, '\1')
+ elsif line =~ /\A"/ then
+ raise ArgumentError, "Unmatched double quote: #{line}"
+ elsif line.sub!(/\A'([^']*)'/, '') then
+ snippet = $1
+ elsif line =~ /\A'/ then
+ raise ArgumentError, "Unmatched single quote: #{line}"
+ elsif line.sub!(/\A\\(.)?/, '') then
+ snippet = $1 || '\\'
+ elsif line.sub!(/\A([^\s\\'"]+)/, '') then
+ snippet = $1
+ else
+ line.lstrip!
+ break
+ end
+ field.concat(snippet)
end
+ words.push(field)
end
words
end
diff --git a/lib/singleton.rb b/lib/singleton.rb
index 0ab8517275..31fb950378 100644
--- a/lib/singleton.rb
+++ b/lib/singleton.rb
@@ -70,8 +70,7 @@ 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/soap/baseData.rb b/lib/soap/baseData.rb
index 72a6e0723d..0e8b00d450 100644
--- a/lib/soap/baseData.rb
+++ b/lib/soap/baseData.rb
@@ -788,7 +788,7 @@ public
if ele.is_a?(Array)
deep_map(ele, &block)
else
- new_obj = yield(ele)
+ new_obj = block.call(ele)
new_obj.elename = ITEM_NAME
new_obj
end
diff --git a/lib/soap/generator.rb b/lib/soap/generator.rb
index d0c07b058a..f179555e1d 100644
--- a/lib/soap/generator.rb
+++ b/lib/soap/generator.rb
@@ -156,22 +156,16 @@ public
end
def encode_tag(elename, attrs = nil)
- if attrs.nil? or attrs.empty?
+ if !attrs or attrs.empty?
@buf << "\n#{ @indent }<#{ elename }>"
- return
- end
- ary = []
- attrs.each do |key, value|
- ary << %Q[#{ key }="#{ value }"] unless value.nil?
- end
- case ary.size
- when 0
- @buf << "\n#{ @indent }<#{ elename }>"
- when 1
- @buf << %Q[\n#{ @indent }<#{ elename } #{ ary[0] }>]
+ elsif attrs.size == 1
+ key, value = attrs.shift
+ @buf << %Q[\n#{ @indent }<#{ elename } #{ key }="#{ value }">]
else
@buf << "\n#{ @indent }<#{ elename } " <<
- ary.join("\n#{ @indent }#{ @indentstr * 2 }") <<
+ attrs.collect { |key, value|
+ %Q[#{ key }="#{ value }"]
+ }.join("\n#{ @indent }#{ @indentstr * 2 }") <<
'>'
end
end
diff --git a/lib/soap/mapping/registry.rb b/lib/soap/mapping/registry.rb
index a4183fea57..823e80666d 100644
--- a/lib/soap/mapping/registry.rb
+++ b/lib/soap/mapping/registry.rb
@@ -522,7 +522,7 @@ private
list = (class << obj; self; end).ancestors - obj.class.ancestors
unless list.empty?
node.extraattr[RubyExtendName] = list.collect { |c|
- unless c.name
+ if c.name.empty?
raise TypeError.new("singleton can't be dumped #{ obj }")
end
c.name
diff --git a/lib/soap/mapping/rubytypeFactory.rb b/lib/soap/mapping/rubytypeFactory.rb
index 4c629e10d6..61c21d8b20 100644
--- a/lib/soap/mapping/rubytypeFactory.rb
+++ b/lib/soap/mapping/rubytypeFactory.rb
@@ -38,14 +38,6 @@ class RubytypeFactory < Factory
def obj2soap(soap_class, obj, info, map)
param = nil
case obj
- when ::Symbol
- unless @allow_original_mapping
- return nil
- end
- param = SOAPStruct.new(TYPE_SYMBOL)
- mark_marshalled_obj(obj, param)
- param.add('id', SOAPString.new(obj.id2name))
- addiv2soapattr(param, obj, map)
when ::String
unless @allow_original_mapping
return nil
@@ -193,6 +185,14 @@ class RubytypeFactory < Factory
mark_marshalled_obj(obj, param)
param.add('name', SOAPString.new(obj.name))
addiv2soapattr(param, obj, map)
+ when ::Symbol
+ unless @allow_original_mapping
+ return nil
+ end
+ param = SOAPStruct.new(TYPE_SYMBOL)
+ mark_marshalled_obj(obj, param)
+ param.add('id', SOAPString.new(obj.id2name))
+ addiv2soapattr(param, obj, map)
when ::Struct
unless @allow_original_mapping
# treat it as an user defined class. [ruby-talk:104980]
@@ -262,7 +262,7 @@ private
end
def unknownobj2soap(soap_class, obj, info, map)
- unless obj.class.name
+ if obj.class.name.empty?
raise TypeError.new("can't dump anonymous class #{obj}")
end
singleton_class = class << obj; self; end
diff --git a/lib/soap/mimemessage.rb b/lib/soap/mimemessage.rb
index 4e151e320a..acb4322e11 100644
--- a/lib/soap/mimemessage.rb
+++ b/lib/soap/mimemessage.rb
@@ -49,7 +49,7 @@ class MIMEMessage
def parse(str)
header_cache = nil
- str.lines.each do |line|
+ str.each do |line|
case line
when /^\A[^\: \t]+:\s*.+$/
parse_line(header_cache) if header_cache
diff --git a/lib/soap/property.rb b/lib/soap/property.rb
index 51f2e82628..882dcc6e28 100644
--- a/lib/soap/property.rb
+++ b/lib/soap/property.rb
@@ -70,7 +70,7 @@ class Property
LINE_REGEXP = Regexp.new("^#{DEF_REGSRC}$")
def load(stream)
key_prefix = ""
- stream.lines.each_with_index do |line, lineno|
+ stream.each_with_index do |line, lineno|
line.sub!(/\r?\n\z/, '')
case line
when COMMENT_REGEXP
diff --git a/lib/soap/rpc/proxy.rb b/lib/soap/rpc/proxy.rb
index 0797c70884..7dfda62006 100644
--- a/lib/soap/rpc/proxy.rb
+++ b/lib/soap/rpc/proxy.rb
@@ -345,12 +345,7 @@ private
if @response_style == :rpc
response_rpc(body, mapping_registry, literal_mapping_registry, opt)
else
- ret = response_doc(body, mapping_registry, literal_mapping_registry, opt)
- if ret.size == 1
- ret[0]
- else
- ret
- end
+ response_doc(body, mapping_registry, literal_mapping_registry, opt)
end
end
@@ -444,9 +439,9 @@ private
def response_doc(body, mapping_registry, literal_mapping_registry, opt)
if @response_use == :encoded
- return response_doc_enc(body, mapping_registry, opt)
+ return *response_doc_enc(body, mapping_registry, opt)
else
- return response_doc_lit(body, literal_mapping_registry, opt)
+ return *response_doc_lit(body, literal_mapping_registry, opt)
end
end
diff --git a/lib/sync.rb b/lib/sync.rb
index 93474e1caa..79522ed885 100644
--- a/lib/sync.rb
+++ b/lib/sync.rb
@@ -40,7 +40,7 @@
#
unless defined? Thread
- raise "Thread not available for this ruby interpreter"
+ fail "Thread not available for this ruby interpreter"
end
module Sync_m
@@ -232,13 +232,13 @@ module Sync_m
end
end
- attr_accessor :sync_mode
+ attr :sync_mode, true
- attr_accessor :sync_waiting
- attr_accessor :sync_upgrade_waiting
- attr_accessor :sync_sh_locker
- attr_accessor :sync_ex_locker
- attr_accessor :sync_ex_count
+ attr :sync_waiting, true
+ attr :sync_upgrade_waiting, true
+ attr :sync_sh_locker, true
+ attr :sync_ex_locker, true
+ attr :sync_ex_count, true
private
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index a033a5b29e..b885444b15 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -81,12 +81,11 @@ class Tempfile < DelegateClass(File)
def _close # :nodoc:
@tmpfile.close if @tmpfile
- @tmpfile = nil
- @data[1] = nil if @data
- end
+ @data[1] = @tmpfile = nil
+ end
protected :_close
- #Closes the file. If the optional flag is true, unlinks the file
+ # Closes the file. If the optional flag is true, unlinks the file
# after closing.
#
# If you don't explicitly unlink the temporary file, the removal
@@ -104,7 +103,6 @@ class Tempfile < DelegateClass(File)
_close
@clean_proc.call
ObjectSpace.undefine_finalizer(self)
- @data = @tmpname = nil
end
# Unlinks the file. On UNIX-like systems, it is often a good idea
@@ -144,7 +142,7 @@ class Tempfile < DelegateClass(File)
class << self
def callback(data) # :nodoc:
pid = $$
- Proc.new {
+ lambda{
if pid == $$
path, tmpfile, cleanlist = *data
diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb
index 0d55b0b068..aa97799de8 100644
--- a/lib/test/unit/assertions.rb
+++ b/lib/test/unit/assertions.rb
@@ -5,8 +5,8 @@
require 'test/unit/assertionfailederror'
require 'test/unit/util/backtracefilter'
-module Test # :nodoc:
- module Unit # :nodoc:
+module Test
+ module Unit
##
# Test::Unit::Assertions contains the standard Test::Unit assertions.
@@ -480,13 +480,13 @@ EOT
# +arguments+ replaces the '?'s positionally in the template.
public
- def build_message(head, template=nil, *arguments) # :nodoc:
+ def build_message(head, template=nil, *arguments)
template &&= template.chomp
return AssertionMessage.new(head, template, arguments)
end
private
- def _wrap_assertion # :nodoc:
+ def _wrap_assertion
@_assertion_wrapped ||= false
unless (@_assertion_wrapped)
@_assertion_wrapped = true
diff --git a/lib/test/unit/autorunner.rb b/lib/test/unit/autorunner.rb
index dadf080d12..86c9b12940 100644
--- a/lib/test/unit/autorunner.rb
+++ b/lib/test/unit/autorunner.rb
@@ -81,6 +81,7 @@ module Test
@filters = []
@to_run = []
@output_level = UI::NORMAL
+ @workdir = nil
yield(self) if(block_given?)
end
diff --git a/lib/test/unit/collector/dir.rb b/lib/test/unit/collector/dir.rb
index 59c664dbb7..97c8d28481 100644
--- a/lib/test/unit/collector/dir.rb
+++ b/lib/test/unit/collector/dir.rb
@@ -91,7 +91,7 @@ module Test
end
find_test_cases(already_gathered).each{|t| add_suite(suites, t.suite)}
ensure
- $:.delete_at($:.index(dir)) if dir
+ $:.delete_at($:.rindex(dir)) if(dir)
end
def realdir(path)
diff --git a/lib/test/unit/collector/objectspace.rb b/lib/test/unit/collector/objectspace.rb
index a0f837e33e..d1127a981f 100644
--- a/lib/test/unit/collector/objectspace.rb
+++ b/lib/test/unit/collector/objectspace.rb
@@ -8,7 +8,7 @@ module Test
module Unit
module Collector
class ObjectSpace
- include Test::Unit::Collector
+ include Collector
NAME = 'collected from the ObjectSpace'
diff --git a/lib/test/unit/testcase.rb b/lib/test/unit/testcase.rb
index 017cd15b8c..f53b460c5d 100644
--- a/lib/test/unit/testcase.rb
+++ b/lib/test/unit/testcase.rb
@@ -37,7 +37,9 @@ module Test
# Creates a new instance of the fixture for running the
# test represented by test_method_name.
def initialize(test_method_name)
- unless(respond_to?(test_method_name) && method(test_method_name).arity == 0)
+ unless(respond_to?(test_method_name) and
+ (method(test_method_name).arity == 0 ||
+ method(test_method_name).arity == -1))
throw :invalid_test
end
@method_name = test_method_name
@@ -59,7 +61,7 @@ module Test
end
if (suite.empty?)
catch(:invalid_test) do
- suite << new(:default_test)
+ suite << new("default_test")
end
end
return suite
@@ -115,22 +117,22 @@ module Test
end
private :passed?
- def size # :nodoc:
+ def size
1
end
- def add_assertion # :nodoc:
+ def add_assertion
@_result.add_assertion
end
private :add_assertion
- def add_failure(message, all_locations=caller()) # :nodoc:
+ def add_failure(message, all_locations=caller())
@test_passed = false
@_result.add_failure(Failure.new(name, filter_backtrace(all_locations), message))
end
private :add_failure
- def add_error(exception) # :nodoc:
+ def add_error(exception)
@test_passed = false
@_result.add_error(Error.new(name, exception))
end
diff --git a/lib/test/unit/testresult.rb b/lib/test/unit/testresult.rb
index 3fe9b7c57f..e3a472ef7f 100644
--- a/lib/test/unit/testresult.rb
+++ b/lib/test/unit/testresult.rb
@@ -1,5 +1,4 @@
#--
-#
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.
diff --git a/lib/test/unit/ui/console/testrunner.rb b/lib/test/unit/ui/console/testrunner.rb
index 2bd01eefa8..6b600e319a 100644
--- a/lib/test/unit/ui/console/testrunner.rb
+++ b/lib/test/unit/ui/console/testrunner.rb
@@ -10,7 +10,7 @@ require 'test/unit/ui/testrunnerutilities'
module Test
module Unit
module UI
- module Console # :nodoc:
+ module Console
# Runs a Test::Unit::TestSuite on the console.
class TestRunner
@@ -42,7 +42,7 @@ module Test
end
private
- def setup_mediator # :nodoc:
+ def setup_mediator
@mediator = create_mediator(@suite)
suite_name = @suite.to_s
if ( @suite.kind_of?(Module) )
@@ -51,11 +51,11 @@ module Test
output("Loaded suite #{suite_name}")
end
- def create_mediator(suite) # :nodoc:
+ def create_mediator(suite)
return TestRunnerMediator.new(suite)
end
- def attach_to_mediator # :nodoc:
+ def attach_to_mediator
@mediator.add_listener(TestResult::FAULT, &method(:add_fault))
@mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
@mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
@@ -63,11 +63,11 @@ module Test
@mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
end
- def start_mediator # :nodoc:
+ def start_mediator
return @mediator.run_suite
end
- def add_fault(fault) # :nodoc:
+ def add_fault(fault)
@faults << fault
output_single(fault.single_character_display, PROGRESS_ONLY)
@already_outputted = true
@@ -90,8 +90,6 @@ module Test
end
def test_started(name)
- $0 += "\0#{name}"
- $0.sub!(/\0.*\z/, '')
output_single(name + ": ", VERBOSE)
end
diff --git a/lib/test/unit/ui/fox/testrunner.rb b/lib/test/unit/ui/fox/testrunner.rb
index 34a8ff1288..a23a450567 100644
--- a/lib/test/unit/ui/fox/testrunner.rb
+++ b/lib/test/unit/ui/fox/testrunner.rb
@@ -13,7 +13,7 @@ include Fox
module Test
module Unit
module UI
- module Fox # :nodoc:
+ module Fox
# Runs a Test::Unit::TestSuite in a Fox UI. Obviously,
# this one requires you to have Fox
@@ -49,7 +49,7 @@ module Test
@result
end
- def setup_mediator # :nodoc:
+ def setup_mediator
@mediator = TestRunnerMediator.new(@suite)
suite_name = @suite.to_s
if ( @suite.kind_of?(Module) )
@@ -58,7 +58,7 @@ module Test
@suite_name_entry.text = suite_name
end
- def attach_to_mediator # :nodoc:
+ def attach_to_mediator
@mediator.add_listener(TestRunnerMediator::RESET, &method(:reset_ui))
@mediator.add_listener(TestResult::FAULT, &method(:add_fault))
@mediator.add_listener(TestResult::CHANGED, &method(:result_changed))
@@ -67,7 +67,7 @@ module Test
@mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
end
- def start_ui # :nodoc:
+ def start_ui
@application.create
@window.show(PLACEMENT_SCREEN)
@application.addTimeout(1) do
@@ -76,11 +76,11 @@ module Test
@application.run
end
- def stop # :nodoc:
+ def stop
@application.exit(0)
end
- def reset_ui(count) # :nodoc:
+ def reset_ui(count)
@test_progress_bar.barColor = GREEN_STYLE
@test_progress_bar.total = count
@test_progress_bar.progress = 0
@@ -94,7 +94,7 @@ module Test
@fault_list.clearItems
end
- def add_fault(fault) # :nodoc:
+ def add_fault(fault)
if ( ! @red )
@test_progress_bar.barColor = RED_STYLE
@red = true
@@ -103,19 +103,19 @@ module Test
@fault_list.appendItem(item)
end
- def show_fault(fault) # :nodoc:
+ def show_fault(fault)
raw_show_fault(fault.long_display)
end
- def raw_show_fault(string) # :nodoc:
+ def raw_show_fault(string)
@detail_text.setText(string)
end
- def clear_fault # :nodoc:
+ def clear_fault
raw_show_fault("")
end
- def result_changed(result) # :nodoc:
+ def result_changed(result)
@test_progress_bar.progress = result.run_count
@test_count_label.text = result.run_count.to_s
@@ -128,7 +128,7 @@ module Test
@application.flush
end
- def started(result) # :nodoc:
+ def started(result)
@result = result
output_status("Started...")
end
@@ -146,7 +146,7 @@ module Test
@status_entry.repaint
end
- def setup_ui # :nodoc:
+ def setup_ui
@application = create_application
create_tooltip(@application)
@@ -180,7 +180,7 @@ module Test
@detail_text = create_text(detail_panel)
end
- def create_application # :nodoc:
+ def create_application
app = FXApp.new("TestRunner", "Test::Unit")
app.init([])
app
@@ -194,25 +194,25 @@ module Test
FXTooltip.new(app)
end
- def create_main_panel(parent) # :nodoc:
+ def create_main_panel(parent)
panel = FXVerticalFrame.new(parent, LAYOUT_FILL_X | LAYOUT_FILL_Y)
panel.vSpacing = 10
panel
end
- def create_suite_panel(parent) # :nodoc:
+ def create_suite_panel(parent)
FXHorizontalFrame.new(parent, LAYOUT_SIDE_LEFT | LAYOUT_FILL_X)
end
- def create_button(parent, text, action) # :nodoc:
+ def create_button(parent, text, action)
FXButton.new(parent, text).connect(SEL_COMMAND, &action)
end
- def create_progress_bar(parent) # :nodoc:
+ def create_progress_bar(parent)
FXProgressBar.new(parent, nil, 0, PROGRESSBAR_NORMAL | LAYOUT_FILL_X)
end
- def create_info_panel(parent) # :nodoc:
+ def create_info_panel(parent)
FXMatrix.new(parent, 1, MATRIX_BY_ROWS | LAYOUT_FILL_X)
end
@@ -220,11 +220,11 @@ module Test
FXLabel.new(parent, text, nil, JUSTIFY_CENTER_X | LAYOUT_FILL_COLUMN)
end
- def create_list_panel(parent) # :nodoc:
+ def create_list_panel(parent)
FXHorizontalFrame.new(parent, LAYOUT_FILL_X | FRAME_SUNKEN | FRAME_THICK)
end
- def create_fault_list(parent) # :nodoc:
+ def create_fault_list(parent)
list = FXList.new(parent, 10, nil, 0, LIST_SINGLESELECT | LAYOUT_FILL_X) #, 0, 0, 0, 150)
list.connect(SEL_COMMAND) do |sender, sel, ptr|
if sender.retrieveItem(sender.currentItem).selected?
@@ -236,22 +236,22 @@ module Test
list
end
- def create_detail_panel(parent) # :nodoc:
+ def create_detail_panel(parent)
FXHorizontalFrame.new(parent, LAYOUT_FILL_X | LAYOUT_FILL_Y | FRAME_SUNKEN | FRAME_THICK)
end
- def create_text(parent) # :nodoc:
+ def create_text(parent)
FXText.new(parent, nil, 0, TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y)
end
- def create_entry(parent) # :nodoc:
+ def create_entry(parent)
entry = FXTextField.new(parent, 30, nil, 0, TEXTFIELD_NORMAL | LAYOUT_SIDE_BOTTOM | LAYOUT_FILL_X)
entry.disable
entry
end
end
- class FaultListItem < FXListItem # :nodoc: all
+ class FaultListItem < FXListItem
attr_reader(:fault)
def initialize(fault)
super(fault.short_display)
diff --git a/lib/test/unit/ui/gtk/testrunner.rb b/lib/test/unit/ui/gtk/testrunner.rb
index c63cc6a39b..994328dc9b 100644
--- a/lib/test/unit/ui/gtk/testrunner.rb
+++ b/lib/test/unit/ui/gtk/testrunner.rb
@@ -11,7 +11,7 @@ require 'test/unit/ui/testrunnerutilities'
module Test
module Unit
module UI
- module GTK # :nodoc:
+ module GTK
# Runs a Test::Unit::TestSuite in a Gtk UI. Obviously,
# this one requires you to have Gtk
@@ -49,7 +49,7 @@ module Test
end
private
- def setup_mediator # :nodoc:
+ def setup_mediator
@mediator = TestRunnerMediator.new(@suite)
suite_name = @suite.to_s
if ( @suite.kind_of?(Module) )
@@ -58,7 +58,7 @@ module Test
suite_name_entry.set_text(suite_name)
end
- def attach_to_mediator # :nodoc:
+ def attach_to_mediator
run_button.signal_connect("clicked", nil, &method(:run_test))
@mediator.add_listener(TestRunnerMediator::RESET, &method(:reset_ui))
@mediator.add_listener(TestResult::FAULT, &method(:add_fault))
@@ -73,7 +73,7 @@ module Test
@runner.raise(@restart_signal)
end
- def start_ui # :nodoc:
+ def start_ui
@viewer.run
running = false
begin
@@ -93,11 +93,11 @@ module Test
end
end
- def stop(*) # :nodoc:
+ def stop(*)
Gtk.main_quit
end
- def reset_ui(count) # :nodoc:
+ def reset_ui(count)
test_progress_bar.set_style(green_style)
test_progress_bar.configure(0, 0, count)
@red = false
@@ -110,7 +110,7 @@ module Test
fault_list.remove_items(fault_list.children)
end
- def add_fault(fault) # :nodoc:
+ def add_fault(fault)
if ( ! @red )
test_progress_bar.set_style(red_style)
@red = true
@@ -120,27 +120,27 @@ module Test
fault_list.append_items([item])
end
- def show_fault(fault) # :nodoc:
+ def show_fault(fault)
raw_show_fault(fault.long_display)
end
- def raw_show_fault(string) # :nodoc:
+ def raw_show_fault(string)
fault_detail_label.set_text(string)
outer_detail_sub_panel.queue_resize
end
- def clear_fault # :nodoc:
+ def clear_fault
raw_show_fault("")
end
- def result_changed(result) # :nodoc:
+ def result_changed(result)
run_count_label.set_text(result.run_count.to_s)
assertion_count_label.set_text(result.assertion_count.to_s)
failure_count_label.set_text(result.failure_count.to_s)
error_count_label.set_text(result.error_count.to_s)
end
- def started(result) # :nodoc:
+ def started(result)
@result = result
output_status("Started...")
end
@@ -157,11 +157,11 @@ module Test
output_status("Finished in #{elapsed_time} seconds")
end
- def output_status(string) # :nodoc:
+ def output_status(string)
status_entry.set_text(string)
end
- def setup_ui # :nodoc:
+ def setup_ui
main_window.signal_connect("destroy", nil, &method(:stop))
main_window.show_all
fault_list.signal_connect("select-child", nil) {
@@ -174,7 +174,7 @@ module Test
@red = false
end
- def main_window # :nodoc:
+ def main_window
lazy_initialize(:main_window) {
@main_window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
@main_window.set_title("Test::Unit TestRunner")
@@ -185,7 +185,7 @@ module Test
}
end
- def main_panel # :nodoc:
+ def main_panel
lazy_initialize(:main_panel) {
@main_panel = Gtk::VBox.new(false, 0)
@main_panel.pack_start(suite_panel, false, false, 0)
@@ -197,7 +197,7 @@ module Test
}
end
- def suite_panel # :nodoc:
+ def suite_panel
lazy_initialize(:suite_panel) {
@suite_panel = Gtk::HBox.new(false, 10)
@suite_panel.border_width(10)
@@ -207,20 +207,20 @@ module Test
}
end
- def suite_name_entry # :nodoc:
+ def suite_name_entry
lazy_initialize(:suite_name_entry) {
@suite_name_entry = Gtk::Entry.new
@suite_name_entry.set_editable(false)
}
end
- def run_button # :nodoc:
+ def run_button
lazy_initialize(:run_button) {
@run_button = Gtk::Button.new("Run")
}
end
- def progress_panel # :nodoc:
+ def progress_panel
lazy_initialize(:progress_panel) {
@progress_panel = Gtk::HBox.new(false, 10)
@progress_panel.border_width(10)
@@ -228,7 +228,7 @@ module Test
}
end
- def test_progress_bar # :nodoc:
+ def test_progress_bar
lazy_initialize(:test_progress_bar) {
@test_progress_bar = EnhancedProgressBar.new
@test_progress_bar.set_usize(@test_progress_bar.allocation.width,
@@ -237,21 +237,21 @@ module Test
}
end
- def green_style # :nodoc:
+ def green_style
lazy_initialize(:green_style) {
@green_style = Gtk::Style.new
@green_style.set_bg(Gtk::STATE_PRELIGHT, 0x0000, 0xFFFF, 0x0000)
}
end
- def red_style # :nodoc:
+ def red_style
lazy_initialize(:red_style) {
@red_style = Gtk::Style.new
@red_style.set_bg(Gtk::STATE_PRELIGHT, 0xFFFF, 0x0000, 0x0000)
}
end
- def info_panel # :nodoc:
+ def info_panel
lazy_initialize(:info_panel) {
@info_panel = Gtk::HBox.new(false, 0)
@info_panel.border_width(10)
@@ -266,35 +266,35 @@ module Test
}
end
- def run_count_label # :nodoc:
+ def run_count_label
lazy_initialize(:run_count_label) {
@run_count_label = Gtk::Label.new("0")
@run_count_label.set_justify(Gtk::JUSTIFY_LEFT)
}
end
- def assertion_count_label # :nodoc:
+ def assertion_count_label
lazy_initialize(:assertion_count_label) {
@assertion_count_label = Gtk::Label.new("0")
@assertion_count_label.set_justify(Gtk::JUSTIFY_LEFT)
}
end
- def failure_count_label # :nodoc:
+ def failure_count_label
lazy_initialize(:failure_count_label) {
@failure_count_label = Gtk::Label.new("0")
@failure_count_label.set_justify(Gtk::JUSTIFY_LEFT)
}
end
- def error_count_label # :nodoc:
+ def error_count_label
lazy_initialize(:error_count_label) {
@error_count_label = Gtk::Label.new("0")
@error_count_label.set_justify(Gtk::JUSTIFY_LEFT)
}
end
- def list_panel # :nodoc:
+ def list_panel
lazy_initialize(:list_panel) {
@list_panel = Gtk::HBox.new
@list_panel.border_width(10)
@@ -302,7 +302,7 @@ module Test
}
end
- def list_scrolled_window # :nodoc:
+ def list_scrolled_window
lazy_initialize(:list_scrolled_window) {
@list_scrolled_window = Gtk::ScrolledWindow.new
@list_scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
@@ -311,13 +311,13 @@ module Test
}
end
- def fault_list # :nodoc:
+ def fault_list
lazy_initialize(:fault_list) {
@fault_list = Gtk::List.new
}
end
- def detail_panel # :nodoc:
+ def detail_panel
lazy_initialize(:detail_panel) {
@detail_panel = Gtk::HBox.new
@detail_panel.border_width(10)
@@ -325,7 +325,7 @@ module Test
}
end
- def detail_scrolled_window # :nodoc:
+ def detail_scrolled_window
lazy_initialize(:detail_scrolled_window) {
@detail_scrolled_window = Gtk::ScrolledWindow.new
@detail_scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
@@ -334,21 +334,21 @@ module Test
}
end
- def outer_detail_sub_panel # :nodoc:
+ def outer_detail_sub_panel
lazy_initialize(:outer_detail_sub_panel) {
@outer_detail_sub_panel = Gtk::VBox.new
@outer_detail_sub_panel.pack_start(inner_detail_sub_panel, false, false, 0)
}
end
- def inner_detail_sub_panel # :nodoc:
+ def inner_detail_sub_panel
lazy_initialize(:inner_detail_sub_panel) {
@inner_detail_sub_panel = Gtk::HBox.new
@inner_detail_sub_panel.pack_start(fault_detail_label, false, false, 0)
}
end
- def fault_detail_label # :nodoc:
+ def fault_detail_label
lazy_initialize(:fault_detail_label) {
@fault_detail_label = EnhancedLabel.new("")
style = Gtk::Style.new
@@ -362,7 +362,7 @@ module Test
}
end
- def status_panel # :nodoc:
+ def status_panel
lazy_initialize(:status_panel) {
@status_panel = Gtk::HBox.new
@status_panel.border_width(10)
@@ -370,14 +370,14 @@ module Test
}
end
- def status_entry # :nodoc:
+ def status_entry
lazy_initialize(:status_entry) {
@status_entry = Gtk::Entry.new
@status_entry.set_editable(false)
}
end
- def lazy_initialize(symbol) # :nodoc:
+ def lazy_initialize(symbol)
if (!instance_eval("defined?(@#{symbol.to_s})"))
yield
end
@@ -385,7 +385,7 @@ module Test
end
end
- class EnhancedProgressBar < Gtk::ProgressBar # :nodoc: all
+ class EnhancedProgressBar < Gtk::ProgressBar
def set_style(style)
super
hide
@@ -393,13 +393,13 @@ module Test
end
end
- class EnhancedLabel < Gtk::Label # :nodoc: all
+ class EnhancedLabel < Gtk::Label
def set_text(text)
super(text.gsub(/\n\t/, "\n" + (" " * 4)))
end
end
- class FaultListItem < Gtk::ListItem # :nodoc: all
+ class FaultListItem < Gtk::ListItem
attr_reader(:fault)
def initialize(fault)
super(fault.short_display)
diff --git a/lib/test/unit/ui/gtk2/testrunner.rb b/lib/test/unit/ui/gtk2/testrunner.rb
index 128424cf34..b05549c0e8 100644
--- a/lib/test/unit/ui/gtk2/testrunner.rb
+++ b/lib/test/unit/ui/gtk2/testrunner.rb
@@ -11,17 +11,17 @@ require "test/unit/ui/testrunnerutilities"
module Test
module Unit
module UI
- module GTK2 # :nodoc: all
+ module GTK2
Gtk.init
- class EnhancedLabel < Gtk::Label # :nodoc: all
+ class EnhancedLabel < Gtk::Label
def set_text(text)
super(text.gsub(/\n\t/, "\n "))
end
end
- class FaultList < Gtk::TreeView # :nodoc: all
+ class FaultList < Gtk::TreeView
def initialize
@faults = []
@model = Gtk::ListStore.new(String, String)
@@ -56,7 +56,7 @@ module Test
class TestRunner
extend TestRunnerUtilities
- def lazy_initialize(symbol) # :nodoc:
+ def lazy_initialize(symbol)
if !instance_eval("defined?(@#{symbol})") then
yield
end
@@ -64,7 +64,7 @@ module Test
end
private :lazy_initialize
- def status_entry # :nodoc:
+ def status_entry
lazy_initialize(:status_entry) do
@status_entry = Gtk::Entry.new
@status_entry.editable = false
@@ -72,7 +72,7 @@ module Test
end
private :status_entry
- def status_panel # :nodoc:
+ def status_panel
lazy_initialize(:status_panel) do
@status_panel = Gtk::HBox.new
@status_panel.border_width = 10
@@ -81,7 +81,7 @@ module Test
end
private :status_panel
- def fault_detail_label # :nodoc:
+ def fault_detail_label
lazy_initialize(:fault_detail_label) do
@fault_detail_label = EnhancedLabel.new("")
# style = Gtk::Style.new
@@ -95,7 +95,7 @@ module Test
end
private :fault_detail_label
- def inner_detail_sub_panel # :nodoc:
+ def inner_detail_sub_panel
lazy_initialize(:inner_detail_sub_panel) do
@inner_detail_sub_panel = Gtk::HBox.new
@inner_detail_sub_panel.pack_start(fault_detail_label, false, false, 0)
@@ -103,7 +103,7 @@ module Test
end
private :inner_detail_sub_panel
- def outer_detail_sub_panel # :nodoc:
+ def outer_detail_sub_panel
lazy_initialize(:outer_detail_sub_panel) do
@outer_detail_sub_panel = Gtk::VBox.new
@outer_detail_sub_panel.pack_start(inner_detail_sub_panel, false, false, 0)
@@ -111,7 +111,7 @@ module Test
end
private :outer_detail_sub_panel
- def detail_scrolled_window # :nodoc:
+ def detail_scrolled_window
lazy_initialize(:detail_scrolled_window) do
@detail_scrolled_window = Gtk::ScrolledWindow.new
@detail_scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
@@ -122,7 +122,7 @@ module Test
end
private :detail_scrolled_window
- def detail_panel # :nodoc:
+ def detail_panel
lazy_initialize(:detail_panel) do
@detail_panel = Gtk::HBox.new
@detail_panel.border_width = 10
@@ -131,14 +131,14 @@ module Test
end
private :detail_panel
- def fault_list # :nodoc:
+ def fault_list
lazy_initialize(:fault_list) do
@fault_list = FaultList.new
end
end
private :fault_list
- def list_scrolled_window # :nodoc:
+ def list_scrolled_window
lazy_initialize(:list_scrolled_window) do
@list_scrolled_window = Gtk::ScrolledWindow.new
@list_scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
@@ -149,7 +149,7 @@ module Test
end
private :list_scrolled_window
- def list_panel # :nodoc:
+ def list_panel
lazy_initialize(:list_panel) do
@list_panel = Gtk::HBox.new
@list_panel.border_width = 10
@@ -158,7 +158,7 @@ module Test
end
private :list_panel
- def error_count_label # :nodoc:
+ def error_count_label
lazy_initialize(:error_count_label) do
@error_count_label = Gtk::Label.new("0")
@error_count_label.justify = Gtk::JUSTIFY_LEFT
@@ -166,7 +166,7 @@ module Test
end
private :error_count_label
- def failure_count_label # :nodoc:
+ def failure_count_label
lazy_initialize(:failure_count_label) do
@failure_count_label = Gtk::Label.new("0")
@failure_count_label.justify = Gtk::JUSTIFY_LEFT
@@ -174,7 +174,7 @@ module Test
end
private :failure_count_label
- def assertion_count_label # :nodoc:
+ def assertion_count_label
lazy_initialize(:assertion_count_label) do
@assertion_count_label = Gtk::Label.new("0")
@assertion_count_label.justify = Gtk::JUSTIFY_LEFT
@@ -182,7 +182,7 @@ module Test
end
private :assertion_count_label
- def run_count_label # :nodoc:
+ def run_count_label
lazy_initialize(:run_count_label) do
@run_count_label = Gtk::Label.new("0")
@run_count_label.justify = Gtk::JUSTIFY_LEFT
@@ -190,7 +190,7 @@ module Test
end
private :run_count_label
- def info_panel # :nodoc:
+ def info_panel
lazy_initialize(:info_panel) do
@info_panel = Gtk::HBox.new(false, 0)
@info_panel.border_width = 10
@@ -206,7 +206,7 @@ module Test
end # def info_panel
private :info_panel
- def green_style # :nodoc:
+ def green_style
lazy_initialize(:green_style) do
@green_style = Gtk::Style.new
@green_style.set_bg(Gtk::STATE_PRELIGHT, 0x0000, 0xFFFF, 0x0000)
@@ -214,7 +214,7 @@ module Test
end # def green_style
private :green_style
- def red_style # :nodoc:
+ def red_style
lazy_initialize(:red_style) do
@red_style = Gtk::Style.new
@red_style.set_bg(Gtk::STATE_PRELIGHT, 0xFFFF, 0x0000, 0x0000)
@@ -222,7 +222,7 @@ module Test
end # def red_style
private :red_style
- def test_progress_bar # :nodoc:
+ def test_progress_bar
lazy_initialize(:test_progress_bar) {
@test_progress_bar = Gtk::ProgressBar.new
@test_progress_bar.fraction = 0.0
@@ -234,7 +234,7 @@ module Test
end # def test_progress_bar
private :test_progress_bar
- def progress_panel # :nodoc:
+ def progress_panel
lazy_initialize(:progress_panel) do
@progress_panel = Gtk::HBox.new(false, 10)
@progress_panel.border_width = 10
@@ -242,13 +242,13 @@ module Test
end
end # def progress_panel
- def run_button # :nodoc:
+ def run_button
lazy_initialize(:run_button) do
@run_button = Gtk::Button.new("Run")
end
end # def run_button
- def suite_name_entry # :nodoc:
+ def suite_name_entry
lazy_initialize(:suite_name_entry) do
@suite_name_entry = Gtk::Entry.new
@suite_name_entry.editable = false
@@ -256,7 +256,7 @@ module Test
end # def suite_name_entry
private :suite_name_entry
- def suite_panel # :nodoc:
+ def suite_panel
lazy_initialize(:suite_panel) do
@suite_panel = Gtk::HBox.new(false, 10)
@suite_panel.border_width = 10
@@ -267,7 +267,7 @@ module Test
end # def suite_panel
private :suite_panel
- def main_panel # :nodoc:
+ def main_panel
lazy_initialize(:main_panel) do
@main_panel = Gtk::VBox.new(false, 0)
@main_panel.pack_start(suite_panel, false, false, 0)
@@ -280,7 +280,7 @@ module Test
end # def main_panel
private :main_panel
- def main_window # :nodoc:
+ def main_window
lazy_initialize(:main_window) do
@main_window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
@main_window.set_title("Test::Unit TestRunner")
@@ -291,7 +291,7 @@ module Test
end # def main_window
private :main_window
- def setup_ui # :nodoc:
+ def setup_ui
main_window.signal_connect("destroy", nil) { stop }
main_window.show_all
fault_list.selection.signal_connect("changed", nil) do
@@ -305,33 +305,33 @@ module Test
end # def setup_ui
private :setup_ui
- def output_status(string) # :nodoc:
+ def output_status(string)
status_entry.set_text(string)
end # def output_status(string)
private :output_status
- def finished(elapsed_time) # :nodoc:
+ def finished(elapsed_time)
test_progress_bar.fraction = 1.0
output_status("Finished in #{elapsed_time} seconds")
end # def finished(elapsed_time)
private :finished
- def test_started(test_name) # :nodoc:
+ def test_started(test_name)
output_status("Running #{test_name}...")
end # def test_started(test_name)
private :test_started
- def started(result) # :nodoc:
+ def started(result)
@result = result
output_status("Started...")
end # def started(result)
private :started
- def test_finished(result) # :nodoc:
+ def test_finished(result)
test_progress_bar.fraction += 1.0 / @count
end # def test_finished(result)
- def result_changed(result) # :nodoc:
+ def result_changed(result)
run_count_label.label = result.run_count.to_s
assertion_count_label.label = result.assertion_count.to_s
failure_count_label.label = result.failure_count.to_s
@@ -339,23 +339,23 @@ module Test
end # def result_changed(result)
private :result_changed
- def clear_fault # :nodoc:
+ def clear_fault
raw_show_fault("")
end # def clear_fault
private :clear_fault
- def raw_show_fault(string) # :nodoc:
+ def raw_show_fault(string)
fault_detail_label.set_text(string)
outer_detail_sub_panel.queue_resize
end # def raw_show_fault(string)
private :raw_show_fault
- def show_fault(fault) # :nodoc:
+ def show_fault(fault)
raw_show_fault(fault.long_display)
end # def show_fault(fault)
private :show_fault
- def add_fault(fault) # :nodoc:
+ def add_fault(fault)
if not @red then
test_progress_bar.style = red_style
@red = true
@@ -364,7 +364,7 @@ module Test
end # def add_fault(fault)
private :add_fault
- def reset_ui(count) # :nodoc:
+ def reset_ui(count)
test_progress_bar.style = green_style
test_progress_bar.fraction = 0.0
@count = count + 1
@@ -379,7 +379,7 @@ module Test
end # def reset_ui(count)
private :reset_ui
- def stop # :nodoc:
+ def stop
Gtk.main_quit
end # def stop
private :stop
@@ -389,7 +389,7 @@ module Test
end
private :run_test
- def start_ui # :nodoc
+ def start_ui
@viewer.run
running = false
begin
diff --git a/lib/test/unit/ui/testrunnermediator.rb b/lib/test/unit/ui/testrunnermediator.rb
index 07bb462cc0..d34510d1c6 100644
--- a/lib/test/unit/ui/testrunnermediator.rb
+++ b/lib/test/unit/ui/testrunnermediator.rb
@@ -10,7 +10,7 @@ require 'test/unit/testresult'
module Test
module Unit
- module UI # :nodoc:
+ module UI
# Provides an interface to write any given UI against,
# hopefully making it easy to write new UIs.
diff --git a/lib/test/unit/ui/tk/testrunner.rb b/lib/test/unit/ui/tk/testrunner.rb
index 4521b8e258..4d05f2fb22 100644
--- a/lib/test/unit/ui/tk/testrunner.rb
+++ b/lib/test/unit/ui/tk/testrunner.rb
@@ -13,7 +13,7 @@ require 'test/unit/ui/testrunnerutilities'
module Test
module Unit
module UI
- module Tk # :nodoc:
+ module Tk
# Runs a Test::Unit::TestSuite in a Tk UI. Obviously,
# this one requires you to have Tk
@@ -52,7 +52,7 @@ module Test
end
private
- def setup_mediator # :nodoc:
+ def setup_mediator
@mediator = TestRunnerMediator.new(@suite)
suite_name = @suite.to_s
if ( @suite.kind_of?(Module) )
@@ -61,7 +61,7 @@ module Test
@suite_name_entry.value = suite_name
end
- def attach_to_mediator # :nodoc:
+ def attach_to_mediator
@run_button.command(method(:run_test))
@fault_list.bind('ButtonPress-1', proc{|y|
fault = @fault_detail_list[@fault_list.nearest(y)]
@@ -81,7 +81,7 @@ module Test
@runner.raise(@restart_signal)
end
- def start_ui # :nodoc:
+ def start_ui
@viewer.run
running = false
begin
@@ -101,11 +101,11 @@ module Test
end
end
- def stop # :nodoc:
+ def stop
::Tk.exit
end
- def reset_ui(count) # :nodoc:
+ def reset_ui(count)
@test_total_count = count.to_f
@test_progress_bar.configure('background'=>'green')
@test_progress_bar.place('relwidth'=>(count.zero? ? 0 : 0/count))
@@ -121,7 +121,7 @@ module Test
clear_fault
end
- def add_fault(fault) # :nodoc:
+ def add_fault(fault)
if ( ! @red )
@test_progress_bar.configure('background'=>'red')
@red = true
@@ -130,19 +130,19 @@ module Test
@fault_list.insert('end', fault.short_display)
end
- def show_fault(fault) # :nodoc:
+ def show_fault(fault)
raw_show_fault(fault.long_display)
end
- def raw_show_fault(string) # :nodoc:
+ def raw_show_fault(string)
@detail_text.value = string
end
- def clear_fault # :nodoc:
+ def clear_fault
raw_show_fault("")
end
- def result_changed(result) # :nodoc:
+ def result_changed(result)
@test_count_label.value = result.run_count
@test_progress_bar.place('relwidth'=>result.run_count/@test_total_count)
@assertion_count_label.value = result.assertion_count
@@ -150,7 +150,7 @@ module Test
@error_count_label.value = result.error_count
end
- def started(result) # :nodoc:
+ def started(result)
@result = result
output_status("Started...")
end
@@ -163,11 +163,11 @@ module Test
output_status("Finished in #{elapsed_time} seconds")
end
- def output_status(string) # :nodoc:
+ def output_status(string)
@status_entry.value = string
end
- def setup_ui # :nodoc:
+ def setup_ui
@status_entry = TkVariable.new
l = TkLabel.new(nil, 'textvariable'=>@status_entry, 'relief'=>'sunken')
l.pack('side'=>'bottom', 'fill'=>'x')
@@ -243,7 +243,7 @@ module Test
end
end
- def create_count_label(parent, label) # :nodoc:
+ def create_count_label(parent, label)
TkLabel.new(parent, 'text'=>label).pack('side'=>'left', 'expand'=>true)
v = TkVariable.new(0)
TkLabel.new(parent, 'textvariable'=>v).pack('side'=>'left', 'expand'=>true)
diff --git a/lib/test/unit/util/observable.rb b/lib/test/unit/util/observable.rb
index 924c10f24c..3567d34271 100644
--- a/lib/test/unit/util/observable.rb
+++ b/lib/test/unit/util/observable.rb
@@ -8,7 +8,7 @@ require 'test/unit/util/procwrapper'
module Test
module Unit
- module Util # :nodoc:
+ module Util
# This is a utility class that allows anything mixing
# it in to notify a set of listeners about interesting
@@ -80,7 +80,7 @@ module Test
end
private
- def channels # :nodoc:
+ def channels
@channels ||= {}
return @channels
end
diff --git a/lib/test/unit/util/procwrapper.rb b/lib/test/unit/util/procwrapper.rb
index 4d49a52a9d..ad7252186d 100644
--- a/lib/test/unit/util/procwrapper.rb
+++ b/lib/test/unit/util/procwrapper.rb
@@ -25,11 +25,11 @@ module Test
@hash = a_proc.inspect.sub(/^(#<#{a_proc.class}:)/){''}.sub(/(>)$/){''}.hex
end
- def hash # :nodoc:
+ def hash
return @hash
end
- def ==(other) # :nodoc:
+ def ==(other)
case(other)
when ProcWrapper
return @a_proc == other.to_proc
@@ -39,7 +39,7 @@ module Test
end
alias :eql? :==
- def to_proc # :nodoc:
+ def to_proc
return @a_proc
end
end
diff --git a/lib/thread.rb b/lib/thread.rb
index 5d4fedc73c..7df6a140f5 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -1,4 +1,8 @@
#
+# NOTE:
+# This file is overwritten by ext/thread/lib/thread.rb unless ruby
+# is configured with --disable-fastthread.
+#
# thread.rb - thread support classes
# $Date$
# by Yukihiro Matsumoto <matz@netlab.co.jp>
@@ -9,16 +13,7 @@
#
unless defined? Thread
- raise "Thread not available for this ruby interpreter"
-end
-
-unless defined? ThreadError
- class ThreadError<StandardError
- end
-end
-
-if $DEBUG
- Thread.abort_on_exception = true
+ fail "Thread not available for this ruby interpreter"
end
class Thread
@@ -73,7 +68,7 @@ class Mutex
# Returns +true+ if this lock is currently held by some thread.
#
def locked?
- @locked && true
+ @locked
end
#
@@ -84,7 +79,7 @@ class Mutex
result = false
Thread.critical = true
unless @locked
- @locked = Thread.current
+ @locked = true
result = true
end
Thread.critical = false
@@ -96,13 +91,10 @@ class Mutex
#
def lock
while (Thread.critical = true; @locked)
- if @locked == Thread.current
- raise ThreadError, "deadlock; recursive locking"
- end
@waiting.push Thread.current
Thread.stop
end
- @locked = Thread.current
+ @locked = true
Thread.critical = false
self
end
diff --git a/lib/time.rb b/lib/time.rb
index f7a08e947c..dbc25f4193 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -40,7 +40,7 @@
# $Id$
#
-require 'date/format'
+require 'parsedate'
#
# Implements the extensions to the Time class that are described in the
@@ -243,21 +243,6 @@ class Time
make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
end
- #
- # Parses +date+ using Date._strptime and converts it to a Time object.
- #
- # If a block is given, the year described in +date+ is converted by the
- # block. For example:
- #
- # Time.strptime(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}
- def strptime(date, format, now=Time.now)
- d = Date._strptime(date, format)
- raise ArgumentError, "invalid strptime format - `#{format}'" unless d
- year = d[:year]
- year = yield(year) if year && block_given?
- make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
- end
-
MonthValue = {
'JAN' => 1, 'FEB' => 2, 'MAR' => 3, 'APR' => 4, 'MAY' => 5, 'JUN' => 6,
'JUL' => 7, 'AUG' => 8, 'SEP' => 9, 'OCT' =>10, 'NOV' =>11, 'DEC' =>12
@@ -808,9 +793,5 @@ if __FILE__ == $0
def test_parse_fraction
assert_equal(500000, Time.parse("2000-01-01T00:00:00.5+00:00").tv_usec)
end
-
- def test_strptime
- assert_equal(Time.utc(2005, 8, 28, 06, 54, 20), Time.strptime("28/Aug/2005:06:54:20 +0000", "%d/%b/%Y:%T %z"))
- end
end
end
diff --git a/lib/timeout.rb b/lib/timeout.rb
index dc92964c0b..5a99c28092 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -32,8 +32,13 @@ 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+
@@ -44,9 +49,10 @@ 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, exception=Error)
+ def timeout(sec, klass = nil)
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 {
@@ -55,6 +61,17 @@ 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
@@ -72,7 +89,7 @@ end
# Defined for backwards compatibility with earlier versions of timeout.rb, see
# Timeout#timeout.
-def timeout(n, e=Timeout::Error, &block) # :nodoc:
+def timeout(n, e = nil, &block) # :nodoc:
Timeout::timeout(n, e, &block)
end
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
index 434d1bf053..7f9fd9a543 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -10,16 +10,23 @@ class Dir
begin
require 'Win32API'
+ CSIDL_LOCAL_APPDATA = 0x001c
max_pathlen = 260
windir = ' '*(max_pathlen+1)
begin
- getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
+ 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)
rescue RuntimeError
- getdir = Win32API.new('kernel32', 'GetWindowsDirectory', 'PL', 'L')
+ 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])
end
- len = getdir.call(windir, windir.size)
- windir = File.expand_path(windir[0, len])
- temp = File.join(windir, 'temp')
+ temp = File.join(windir.untaint, 'temp')
@@systmpdir = temp if File.directory?(temp) and File.writable?(temp)
rescue LoadError
end
@@ -39,7 +46,7 @@ class Dir
break
end
end
+ File.expand_path(tmp)
end
- File.expand_path(tmp)
end
end
diff --git a/lib/tracer.rb b/lib/tracer.rb
index 22f32bf222..71aa49c306 100644
--- a/lib/tracer.rb
+++ b/lib/tracer.rb
@@ -19,9 +19,9 @@ class Tracer
@stdout = STDOUT
@verbose = false
class << self
- attr_accessor :verbose
+ attr :verbose, true
alias verbose? verbose
- attr_accessor :stdout
+ attr :stdout, true
end
EVENT_SYMBOL = {
diff --git a/lib/uri/.document b/lib/uri/.document
deleted file mode 100644
index 214dd2e48f..0000000000
--- a/lib/uri/.document
+++ /dev/null
@@ -1,7 +0,0 @@
-common.rb
-ftp.rb
-generic.rb
-http.rb
-https.rb
-ldap.rb
-mailto.rb
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index f74f0eb2e1..af6aaf26fb 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/ftp.rb b/lib/uri/ftp.rb
index 3afdce01b4..26109e4d27 100644
--- a/lib/uri/ftp.rb
+++ b/lib/uri/ftp.rb
@@ -11,7 +11,7 @@ require 'uri/generic'
module URI
#
- # FTP URI syntax is defined by RFC1738 section 3.2.
+ # RFC1738 section 3.2.
#
class FTP < Generic
DEFAULT_PORT = 21
@@ -22,11 +22,12 @@ module URI
:path, :typecode
].freeze
#
- # Typecode is "a", "i" or "d".
- #
- # * "a" indicates a text file (the FTP command was ASCII)
- # * "i" indicates a binary file (FTP command IMAGE)
- # * "d" indicates the contents of a directory should be displayed
+ # Typecode is, "a", "i" or "d".
+ # As for "a" the text, as for "i" binary,
+ # as for "d" the directory is displayed.
+ # "A" with the text, as for "i" being binary,
+ # is because the respective data type was called ASCII and
+ # IMAGE with the protocol of FTP.
#
TYPECODE = ['a', 'i', 'd'].freeze
TYPECODE_PREFIX = ';type='.freeze
@@ -51,43 +52,11 @@ module URI
#
# == Description
#
- # Creates a new URI::FTP object from components, with syntax checking.
- #
- # The components accepted are +userinfo+, +host+, +port+, +path+ and
- # +typecode+.
- #
- # The components should be provided either as an Array, or as a Hash
- # with keys formed by preceding the component names with a colon.
- #
- # If an Array is used, the components must be passed in the order
- # [userinfo, host, port, path, typecode]
- #
- # If the path supplied is absolute, it will be escaped in order to
- # make it absolute in the URI. Examples:
- #
- # require 'uri'
- #
- # uri = URI::FTP.build(['user:password', 'ftp.example.com', nil,
- # '/path/file.> zip', 'i'])
- # puts uri.to_s -> ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=a
- #
- # uri2 = URI::FTP.build({:host => 'ftp.example.com',
- # :path => 'ruby/src'})
- # puts uri2.to_s -> ftp://ftp.example.com/ruby/src
+ # Creates a new URI::FTP object from components of URI::FTP with
+ # check. It is scheme, userinfo, host, port, path and typecode. It
+ # provided by an Array or a Hash. typecode is "a", "i" or "d".
#
def self.build(args)
-
- # Fix the incoming path to be generic URL syntax
- # FTP path -> URL path
- # foo/bar /foo/bar
- # /foo/bar /%2Ffoo/bar
- #
- if args.kind_of?(Array)
- args[3] = '/' + args[3].sub(/^\//, '%2F')
- else
- args[:path] = '/' + args[:path].sub(/^\//, '%2F')
- end
-
tmp = Util::make_components_hash(self, args)
if tmp[:typecode]
@@ -103,14 +72,16 @@ module URI
#
# == Description
#
- # Creates a new URI::FTP object from generic URL components with no
- # syntax checking.
+ # Create a new URI::FTP object from ``generic'' components with no
+ # check.
#
- # Unlike build(), this method does not escape the path component as
- # required by RFC1738; instead it is treated as per RFC2396.
+ # == Usage
#
- # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
- # +opaque+, +query+ and +fragment+, in that order.
+ # require 'uri'
+ # p ftp = URI.parse("ftp://ftp.ruby-lang.org/pub/ruby/;type=d")
+ # # => #<URI::FTP:0x201fad08 URL:ftp://ftp.ruby-lang.org/pub/ruby/;type=d>
+ # p ftp.typecode
+ # # => "d"
#
def initialize(*arg)
super(*arg)
@@ -159,27 +130,6 @@ module URI
return tmp
end
- # Returns the path from an FTP URI.
- #
- # RFC 1738 specifically states that the path for an FTP URI does not
- # include the / which separates the URI path from the URI host. Example:
- #
- # ftp://ftp.example.com/pub/ruby
- #
- # The above URI indicates that the client should connect to
- # ftp.example.com then cd pub/ruby from the initial login directory.
- #
- # If you want to cd to an absolute directory, you must include an
- # escaped / (%2F) in the path. Example:
- #
- # ftp://ftp.example.com/%2Fpub/ruby
- #
- # This method will then return "/pub/ruby"
- #
- def path
- return @path.sub(/^\//,'').sub(/^%2F/,'/')
- end
-
def to_s
save_path = nil
if @typecode
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index d166757fef..88b5078466 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -304,19 +304,19 @@ module URI
end
check_userinfo(*userinfo)
set_userinfo(*userinfo)
- userinfo
+ # returns userinfo
end
def user=(user)
check_user(user)
set_user(user)
- user
+ # returns user
end
def password=(password)
check_password(password)
set_password(password)
- password
+ # returns password
end
def set_userinfo(user, password = nil)
@@ -337,8 +337,8 @@ module URI
protected :set_user
def set_password(v)
- set_userinfo(@user, v)
- v
+ @password = v
+ # returns v
end
protected :set_password
@@ -356,7 +356,9 @@ module URI
private :escape_userpass
def userinfo
- if !@password
+ if @user.nil?
+ nil
+ elsif @password.nil?
@user
else
@user + ':' + @password
@@ -1101,8 +1103,9 @@ module URI
end
end
+ @@to_s = Kernel.instance_method(:to_s)
def inspect
- sprintf("#<%s:%#0x URL:%s>", self.class.to_s, self.object_id, self.to_s)
+ @@to_s.bind(self).call.sub!(/>\z/) {" URL:#{self}>"}
end
def coerce(oth)
diff --git a/lib/weakref.rb b/lib/weakref.rb
index b1c430523b..591819c948 100644
--- a/lib/weakref.rb
+++ b/lib/weakref.rb
@@ -23,8 +23,7 @@ class WeakRef<Delegator
@@id_map = {} # obj -> [ref,...]
@@id_rev_map = {} # ref -> obj
- @@final = lambda {|id|
- printf "final: %p\n", id
+ @@final = lambda{|id|
__old_status = Thread.critical
Thread.critical = true
begin
@@ -48,53 +47,54 @@ class WeakRef<Delegator
# Create a new WeakRef from +orig+.
def initialize(orig)
- @__id = orig.object_id
- printf "orig: %p\n", @__id
- ObjectSpace.define_finalizer orig, @@final
- ObjectSpace.define_finalizer self, @@final
- __old_status = Thread.critical
- begin
- Thread.critical = true
- @@id_map[@__id] = [] unless @@id_map[@__id]
- ensure
- Thread.critical = __old_status
- end
- @@id_map[@__id].push self.object_id
- @@id_rev_map[self.object_id] = @__id
super
+ __setobj__(orig)
end
# Return the object this WeakRef references. Raises RefError if the object
# has been garbage collected. The object returned is the object to which
# method calls are delegated (see Delegator).
def __getobj__
- unless @@id_rev_map[self.object_id] == @__id
- Kernel::raise RefError, "Illegal Reference - probably recycled", Kernel::caller(2)
+ unless @@id_rev_map[self.__id__] == @__id
+ raise RefError, "Illegal Reference - probably recycled", caller(2)
end
begin
ObjectSpace._id2ref(@__id)
rescue RangeError
- Kernel::raise RefError, "Illegal Reference - probably recycled", Kernel::caller(2)
+ raise RefError, "Illegal Reference - probably recycled", caller(2)
end
end
def __setobj__(obj)
+ @__id = obj.__id__
+ __old_status = Thread.critical
+ begin
+ Thread.critical = true
+ unless @@id_rev_map.key?(self)
+ ObjectSpace.define_finalizer obj, @@final
+ ObjectSpace.define_finalizer self, @@final
+ end
+ @@id_map[@__id] = [] unless @@id_map[@__id]
+ ensure
+ Thread.critical = __old_status
+ end
+ @@id_map[@__id].push self.__id__
+ @@id_rev_map[self.__id__] = @__id
end
# Returns true if the referenced object still exists, and false if it has
# been garbage collected.
def weakref_alive?
- @@id_rev_map[self.object_id] == @__id
+ @@id_rev_map[self.__id__] == @__id
end
end
if __FILE__ == $0
-# require 'thread'
+ require 'thread'
foo = Object.new
p foo.to_s # original's class
foo = WeakRef.new(foo)
p foo.to_s # should be same class
ObjectSpace.garbage_collect
- ObjectSpace.garbage_collect
p foo.to_s # should raise exception (recycled)
end
diff --git a/lib/webrick/cgi.rb b/lib/webrick/cgi.rb
index ff140ca84e..ff5f7a6102 100644
--- a/lib/webrick/cgi.rb
+++ b/lib/webrick/cgi.rb
@@ -166,19 +166,20 @@ module WEBrick
end
def setup_header
- @env.each{|key, value|
- case key
- when "CONTENT_TYPE", "CONTENT_LENGTH"
- add_header(key.gsub(/_/, "-"), value)
- when /^HTTP_(.*)/
- add_header($1.gsub(/_/, "-"), value)
+ add_header("CONTENT_TYPE", "Content-Type")
+ add_header("CONTENT_LENGTH", "Content-length")
+ @env.each_key{|name|
+ if /^HTTP_(.*)/ =~ name
+ add_header(name, $1.gsub(/_/, "-"))
end
}
end
- def add_header(hdrname, value)
- unless value.empty?
- @header_part << hdrname << ": " << value << CRLF
+ def add_header(envname, hdrname)
+ if value = @env[envname]
+ unless value.empty?
+ @header_part << hdrname << ": " << value << CRLF
+ end
end
end
diff --git a/lib/webrick/config.rb b/lib/webrick/config.rb
index 10db6e0944..5897b977d8 100644
--- a/lib/webrick/config.rb
+++ b/lib/webrick/config.rb
@@ -33,7 +33,6 @@ module WEBrick
:StartCallback => nil,
:StopCallback => nil,
:AcceptCallback => nil,
- :DoNotReverseLookup => nil,
}
# for HTTPServer, HTTPRequest, HTTPResponse ...
@@ -46,10 +45,9 @@ module WEBrick
:DirectoryIndex => ["index.html","index.htm","index.cgi","index.rhtml"],
:DocumentRoot => nil,
:DocumentRootOptions => { :FancyIndexing => true },
- :RequestCallback => nil,
+ :RequestHandler => nil,
+ :RequestCallback => nil, # alias of :RequestHandler
:ServerAlias => nil,
- :InputBufferSize => 65536, # input buffer size in reading request body
- :OutputBufferSize => 65536, # output buffer size in sending File or IO
# for HTTPProxyServer
:ProxyAuthProc => nil,
diff --git a/lib/webrick/httpauth/basicauth.rb b/lib/webrick/httpauth/basicauth.rb
index 210fb00bbe..e835361dc2 100644
--- a/lib/webrick/httpauth/basicauth.rb
+++ b/lib/webrick/httpauth/basicauth.rb
@@ -34,7 +34,7 @@ module WEBrick
unless basic_credentials = check_scheme(req)
challenge(req, res)
end
- userid, password = basic_credentials.unpack("m*")[0].split(":", 2)
+ userid, password = basic_credentials.unpack("m*")[0].split(":", 2)
password ||= ""
if userid.empty?
error("user id was not given.")
diff --git a/lib/webrick/httpauth/digestauth.rb b/lib/webrick/httpauth/digestauth.rb
index 2bc3e97817..318e0bf17f 100644
--- a/lib/webrick/httpauth/digestauth.rb
+++ b/lib/webrick/httpauth/digestauth.rb
@@ -330,7 +330,6 @@ module WEBrick
def hexdigest(*args)
@h.hexdigest(args.join(":"))
end
-
end
class ProxyDigestAuth < DigestAuth
diff --git a/lib/webrick/httpauth/htpasswd.rb b/lib/webrick/httpauth/htpasswd.rb
index 8a058861d3..40f9297b05 100644
--- a/lib/webrick/httpauth/htpasswd.rb
+++ b/lib/webrick/httpauth/htpasswd.rb
@@ -35,7 +35,7 @@ module WEBrick
case line
when %r!\A[^:]+:[a-zA-Z0-9./]{13}\z!
user, pass = line.split(":")
- when /:\$/, /:{SHA}/
+ when /:\$/, /:\{SHA\}/
raise NotImplementedError,
'MD5, SHA1 .htpasswd file not supported'
else
diff --git a/lib/webrick/httpproxy.rb b/lib/webrick/httpproxy.rb
index 8864620e12..14e3499775 100644
--- a/lib/webrick/httpproxy.rb
+++ b/lib/webrick/httpproxy.rb
@@ -24,8 +24,8 @@ module WEBrick
end
class HTTPProxyServer < HTTPServer
- def initialize(config={}, default=Config::HTTP)
- super(config, default)
+ def initialize(config)
+ super
c = @config
@via = "#{c[:HTTPVersion]} #{c[:ServerName]}:#{c[:Port]}"
end
diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb
index 2dca0655d6..1d32293a27 100644
--- a/lib/webrick/httprequest.rb
+++ b/lib/webrick/httprequest.rb
@@ -8,15 +8,19 @@
#
# $IPR: httprequest.rb,v 1.64 2003/07/13 17:18:22 gotoyuzo Exp $
+require 'timeout'
require 'uri'
+
require 'webrick/httpversion'
require 'webrick/httpstatus'
require 'webrick/httputils'
require 'webrick/cookie'
module WEBrick
+
class HTTPRequest
BODY_CONTAINABLE_METHODS = [ "POST", "PUT" ]
+ BUFSIZE = 1024*4
# Request line
attr_reader :request_line
@@ -40,7 +44,6 @@ module WEBrick
def initialize(config)
@config = config
- @buffer_size = @config[:InputBufferSize]
@logger = config[:Logger]
@request_line = @request_method =
@@ -240,7 +243,7 @@ module WEBrick
end
end
begin
- @header = HTTPUtils::parse_header(@raw_header.join)
+ @header = HTTPUtils::parse_header(@raw_header)
rescue => ex
raise HTTPStatus::BadRequest, ex.message
end
@@ -276,7 +279,7 @@ module WEBrick
elsif self['content-length'] || @remaining_size
@remaining_size ||= self['content-length'].to_i
while @remaining_size > 0
- sz = [@buffer_size, @remaining_size].min
+ sz = BUFSIZE < @remaining_size ? BUFSIZE : @remaining_size
break unless buf = read_data(socket, sz)
@remaining_size -= buf.size
block.call(buf)
@@ -304,7 +307,12 @@ module WEBrick
def read_chunked(socket, block)
chunk_size, = read_chunk_size(socket)
while chunk_size > 0
- data = read_data(socket, chunk_size) # read chunk-data
+ data = ""
+ while data.size < chunk_size
+ tmp = read_data(socket, chunk_size-data.size) # read chunk-data
+ break unless tmp
+ data << tmp
+ end
if data.nil? || data.size != chunk_size
raise BadRequest, "bad chunk data size."
end
@@ -319,7 +327,7 @@ module WEBrick
def _read_data(io, method, arg)
begin
- WEBrick::Utils.timeout(@config[:RequestTimeout]){
+ timeout(@config[:RequestTimeout]){
return io.__send__(method, arg)
}
rescue Errno::ECONNRESET
diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb
index b3f1abef88..d0f232d1e1 100644
--- a/lib/webrick/httpresponse.rb
+++ b/lib/webrick/httpresponse.rb
@@ -16,6 +16,8 @@ require 'webrick/httpstatus'
module WEBrick
class HTTPResponse
+ BUFSIZE = 1024*4
+
attr_reader :http_version, :status, :header
attr_reader :cookies
attr_accessor :reason_phrase
@@ -28,7 +30,6 @@ module WEBrick
def initialize(config)
@config = config
- @buffer_size = config[:OutputBufferSize]
@logger = config[:Logger]
@header = Hash.new
@status = HTTPStatus::RC_OK
@@ -257,7 +258,7 @@ module WEBrick
if @request_method == "HEAD"
# do nothing
elsif chunked?
- while buf = @body.read(@buffer_size)
+ while buf = @body.read(BUFSIZE)
next if buf.empty?
data = ""
data << format("%x", buf.size) << CRLF
@@ -281,7 +282,7 @@ module WEBrick
# do nothing
elsif chunked?
remain = body ? @body.size : 0
- while buf = @body[@sent_size, @buffer_size]
+ while buf = @body[@sent_size, BUFSIZE]
break if buf.empty?
data = ""
data << format("%x", buf.size) << CRLF
@@ -300,18 +301,18 @@ module WEBrick
def _send_file(output, input, offset, size)
while offset > 0
- sz = @buffer_size < size ? @buffer_size : size
+ sz = BUFSIZE < offset ? BUFSIZE : offset
buf = input.read(sz)
offset -= buf.size
end
if size == 0
- while buf = input.read(@buffer_size)
+ while buf = input.read(BUFSIZE)
_write_data(output, buf)
end
else
while size > 0
- sz = @buffer_size < size ? @buffer_size : size
+ sz = BUFSIZE < size ? BUFSIZE : size
buf = input.read(sz)
_write_data(output, buf)
size -= buf.size
diff --git a/lib/webrick/httpserver.rb b/lib/webrick/httpserver.rb
index 495be263b3..9edb0018f8 100644
--- a/lib/webrick/httpserver.rb
+++ b/lib/webrick/httpserver.rb
@@ -21,7 +21,7 @@ module WEBrick
class HTTPServer < ::WEBrick::GenericServer
def initialize(config={}, default=Config::HTTP)
- super(config, default)
+ super
@http_version = HTTPVersion::convert(@config[:HTTPVersion])
@mount_tab = MountTable.new
@@ -52,19 +52,14 @@ module WEBrick
timeout = 0 if @status != :Running
timeout -= 0.5
end
- raise HTTPStatus::EOFError if timeout <= 0
- raise HTTPStatus::EOFError if sock.eof?
+ raise HTTPStatus::EOFError if timeout <= 0 || sock.eof?
req.parse(sock)
res.request_method = req.request_method
res.request_uri = req.request_uri
res.request_http_version = req.http_version
res.keep_alive = req.keep_alive?
server = lookup_server(req) || self
- if callback = server[:RequestCallback]
- callback.call(req, res)
- elsif callback = server[:RequestHandler]
- msg = ":RequestHandler is deprecated, please use :RequestCallback"
- @logger.warn(msg)
+ if callback = server[:RequestCallback] || server[:RequestHandler]
callback.call(req, res)
end
server.service(req, res)
@@ -80,9 +75,7 @@ module WEBrick
res.set_error(ex, true)
ensure
if req.request_line
- if req.keep_alive? && res.keep_alive?
- req.fixup()
- end
+ req.fixup()
res.send_response(sock)
server.access_log(@config, req, res)
end
diff --git a/lib/webrick/httpservlet/abstract.rb b/lib/webrick/httpservlet/abstract.rb
index 03861e8fc7..5375c4622d 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 = req.path + "/"
+ location = WEBrick::HTTPUtils.escape_path(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 1069a68d58..006abd458e 100644
--- a/lib/webrick/httpservlet/cgi_runner.rb
+++ b/lib/webrick/httpservlet/cgi_runner.rb
@@ -39,7 +39,9 @@ dir = File::dirname(ENV["SCRIPT_FILENAME"])
Dir::chdir dir
if interpreter = ARGV[0]
- exec(interpreter, ENV["SCRIPT_FILENAME"])
+ argv = ARGV.dup
+ argv << ENV["SCRIPT_FILENAME"]
+ exec(*argv)
# NOTREACHED
end
exec ENV["SCRIPT_FILENAME"]
diff --git a/lib/webrick/httpservlet/cgihandler.rb b/lib/webrick/httpservlet/cgihandler.rb
index 214724f251..a35b59edb8 100644
--- a/lib/webrick/httpservlet/cgihandler.rb
+++ b/lib/webrick/httpservlet/cgihandler.rb
@@ -17,13 +17,13 @@ module WEBrick
module HTTPServlet
class CGIHandler < AbstractServlet
- Ruby = File::join(RbConfig::CONFIG['bindir'],
- RbConfig::CONFIG['ruby_install_name'])
- Ruby << RbConfig::CONFIG['EXEEXT']
- CGIRunner = "\"#{Ruby}\" \"#{WEBrick::Config::LIBDIR}/httpservlet/cgi_runner.rb\""
+ Ruby = File::join(::Config::CONFIG['bindir'],
+ ::Config::CONFIG['ruby_install_name'])
+ Ruby << ::Config::CONFIG['EXEEXT']
+ CGIRunner = "\"#{Ruby}\" \"#{Config::LIBDIR}/httpservlet/cgi_runner.rb\""
def initialize(server, name)
- super(server, name)
+ super
@script_filename = name
@tempdir = server[:TempDir]
@cgicmd = "#{CGIRunner} #{server[:CGIInterpreter]}"
diff --git a/lib/webrick/httpservlet/erbhandler.rb b/lib/webrick/httpservlet/erbhandler.rb
index 49792193ba..b9d5e65b65 100644
--- a/lib/webrick/httpservlet/erbhandler.rb
+++ b/lib/webrick/httpservlet/erbhandler.rb
@@ -17,7 +17,7 @@ module WEBrick
class ERBHandler < AbstractServlet
def initialize(server, name)
- super(server, name)
+ super
@script_filename = name
end
diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb
index ae30c436fe..24f59d7142 100644
--- a/lib/webrick/httpservlet/filehandler.rb
+++ b/lib/webrick/httpservlet/filehandler.rb
@@ -20,7 +20,7 @@ module WEBrick
class DefaultFileHandler < AbstractServlet
def initialize(server, local_path)
- super(server, local_path)
+ super
@local_path = local_path
end
@@ -163,6 +163,7 @@ module WEBrick
end
end
end
+ prevent_directory_traversal(req, res)
super(req, res)
end
@@ -198,10 +199,38 @@ 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)
+ handler = get_handler(req, res)
call_callback(:HandlerCallback, req, res)
h = handler.get_instance(@config, res.filename)
h.service(req, res)
@@ -211,9 +240,13 @@ module WEBrick
return false
end
- def get_handler(req)
- suffix1 = (/\.(\w+)$/ =~ req.script_name) && $1.downcase
- suffix2 = (/\.(\w+)\.[\w\-]+$/ =~ req.script_name) && $1.downcase
+ 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
handler_table = @options[:HandlerTable]
return handler_table[suffix1] || handler_table[suffix2] ||
HandlerTable[suffix1] || HandlerTable[suffix2] ||
@@ -226,15 +259,13 @@ 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?(res.filename + base)
+ break unless File.directory?(File.expand_path(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)
@@ -255,12 +286,10 @@ module WEBrick
end
def check_filename(req, res, name)
- @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
- }
+ if nondisclosure_name?(name) || windows_ambiguous_name?(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)
@@ -268,7 +297,8 @@ module WEBrick
base = base || tmp
req.path_info = path_info.join
req.script_name << base
- res.filename << base
+ res.filename = File.expand_path(res.filename + base)
+ check_filename(req, res, File.basename(res.filename))
end
def search_index_file(req, res)
@@ -308,9 +338,15 @@ 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)
+ if File.fnmatch(pattern, name, File::FNM_CASEFOLD)
return true
end
}
@@ -326,7 +362,8 @@ module WEBrick
list = Dir::entries(local_path).collect{|name|
next if name == "." || name == ".."
next if nondisclosure_name?(name)
- st = (File::stat(local_path + name) rescue nil)
+ next if windows_ambiguous_name?(name)
+ st = (File::stat(File.join(local_path, name)) rescue nil)
if st.nil?
[ name, nil, -1 ]
elsif st.directory?
@@ -366,7 +403,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 38a42b98f8..976d3e915e 100644
--- a/lib/webrick/httputils.rb
+++ b/lib/webrick/httputils.rb
@@ -23,16 +23,8 @@ module WEBrick
ret = path.dup
ret.gsub!(%r{/+}o, '/') # // => /
- 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
+ while ret.sub!(%r'/\.(?:/|\Z)', '/'); end # /. => /
+ while ret.sub!(%r'/(?!\.\./)[^/]+/\.\.(?:/|\Z)', '/'); end # /foo/.. => /foo
raise "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret
ret
@@ -90,7 +82,6 @@ module WEBrick
"tiff" => "image/tiff",
"txt" => "text/plain",
"xbm" => "image/x-xbitmap",
- "xhtml" => "text/html",
"xls" => "application/vnd.ms-excel",
"xml" => "text/xml",
"xpm" => "image/x-xpixmap",
@@ -127,7 +118,7 @@ module WEBrick
def parse_header(raw)
header = Hash.new([].freeze)
field = nil
- raw.lines.each{|line|
+ raw.each{|line|
case line
when /^([A-Za-z0-9!\#$%&'*+\-.^_`|~]+):\s*(.*?)\s*\z/om
field, value = $1, $2
@@ -155,8 +146,8 @@ module WEBrick
module_function :parse_header
def split_header_value(str)
- str.scan(/((?:"(?:\\.|[^"])+?"|[^",]+)+)
- (?:,\s*|\Z)/xn).collect{|v| v[0] }
+ str.scan(%r'\G((?:"(?:\\.|[^"])+?"|[^",]+)+)
+ (?:,\s*|\Z)'xn).flatten
end
module_function :split_header_value
@@ -295,7 +286,7 @@ module WEBrick
query = Hash.new
if str
str.split(/[&;]/).each{|x|
- next if x.empty?
+ next if x.empty?
key, val = x.split(/=/,2)
key = unescape_form(key)
val = unescape_form(val.to_s)
@@ -358,7 +349,7 @@ module WEBrick
def _make_regex(str) /([#{Regexp.escape(str)}])/n end
def _make_regex!(str) /([^#{Regexp.escape(str)}])/n end
- def _escape(str, regex) str.gsub(regex){ "%%%02X" % $1.ord } end
+ def _escape(str, regex) str.gsub(regex){ "%%%02X" % $1[0] } end
def _unescape(str, regex) str.gsub(regex){ $1.hex.chr } end
UNESCAPED = _make_regex(control+space+delims+unwise+nonascii)
diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb
index 3adbded5fa..16dbd46f98 100644
--- a/lib/webrick/server.rb
+++ b/lib/webrick/server.rb
@@ -10,6 +10,7 @@
require 'thread'
require 'socket'
+require 'timeout'
require 'webrick/config'
require 'webrick/log'
@@ -145,7 +146,7 @@ module WEBrick
begin
sock = svr.accept
sock.sync = true
- Utils::set_non_blocking(sock)
+ Utils::set_non_blocking(sock)
Utils::set_close_on_exec(sock)
rescue Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPROTO => ex
# TCP connection was established but RST segment was sent
diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb
index 4a447aaf85..cf9da6f2ce 100644
--- a/lib/webrick/utils.rb
+++ b/lib/webrick/utils.rb
@@ -96,80 +96,5 @@ module WEBrick
end
module_function :random_string
- ###########
-
- require "thread"
- require "timeout"
- require "singleton"
-
- class TimeoutHandler
- include Singleton
- TimeoutMutex = Mutex.new
-
- def TimeoutHandler.register(seconds, exception)
- TimeoutMutex.synchronize{
- instance.register(Thread.current, Time.now + seconds, exception)
- }
- end
-
- def TimeoutHandler.cancel(id)
- TimeoutMutex.synchronize{
- instance.cancel(Thread.current, id)
- }
- end
-
- def initialize
- @timeout_info = Hash.new
- Thread.start{
- while true
- now = Time.now
- @timeout_info.each{|thread, ary|
- ary.each{|info|
- time, exception = *info
- interrupt(thread, info.object_id, exception) if time < now
- }
- }
- sleep 0.5
- end
- }
- end
-
- def interrupt(thread, id, exception)
- TimeoutMutex.synchronize{
- if cancel(thread, id) && thread.alive?
- thread.raise(exception, "execution timeout")
- end
- }
- end
-
- def register(thread, time, exception)
- @timeout_info[thread] ||= Array.new
- @timeout_info[thread] << [time, exception]
- return @timeout_info[thread].last.object_id
- end
-
- def cancel(thread, id)
- if ary = @timeout_info[thread]
- ary.delete_if{|info| info.object_id == id }
- if ary.empty?
- @timeout_info.delete(thread)
- end
- return true
- end
- return false
- end
- end
-
- def timeout(seconds, exception=Timeout::Error)
- return yield if seconds.nil? or seconds.zero?
- raise ThreadError, "timeout within critical session" if Thread.critical
- id = TimeoutHandler.register(seconds, exception)
- begin
- yield(seconds)
- ensure
- TimeoutHandler.cancel(id)
- end
- end
- module_function :timeout
end
end
diff --git a/lib/xmlrpc/README.rdoc b/lib/xmlrpc/README.rdoc
deleted file mode 100644
index 221d675219..0000000000
--- a/lib/xmlrpc/README.rdoc
+++ /dev/null
@@ -1,300 +0,0 @@
-= XMLRPC for Ruby
-
-== Author and Copyright
-
-Copyright (C) 2001-2004 by Michael Neumann (mailto:mneumann@ntecs.de)
-
-Released under the same term of license as Ruby.
-
-== Overview
-
-XMLRPC is a lightweight protocol that enables remote procedure calls over
-HTTP. It is defined at http://www.xmlrpc.com.
-
-XMLRPC allows you to create simple distributed computing solutions that span
-computer languages. Its distinctive feature is its simplicity compared to
-other approaches like SOAP and CORBA.
-
-The Ruby standard library package 'xmlrpc' enables you to create a server that
-implements remote procedures and a client that calls them. Very little code
-is required to achieve either of these.
-
-== Example
-
-Try the following code. It calls a standard demonstration remote procedure.
-
- require 'xmlrpc/client'
- require 'pp'
-
- server = XMLRPC::Client.new2("http://xmlrpc-c.sourceforge.net/api/sample.php")
- result = server.call("sample.sumAndDifference", 5, 3)
- pp result
-
-== Documentation
-
-See http://www.ntecs.de/projects/xmlrpc4r. There is plenty of detail there to
-use the client and implement a server.
-
-== Features of XMLRPC for Ruby
-
-* Extensions
- * Introspection
- * multiCall
- * optionally nil values and integers larger than 32 Bit
-
-* Server
- * Standalone XML-RPC server
- * CGI-based (works with FastCGI)
- * Apache mod_ruby server
- * WEBrick servlet
-
-* Client
- * synchronous/asynchronous calls
- * Basic HTTP-401 Authentification
- * HTTPS protocol (SSL)
-
-* Parsers
- * NQXML (NQXMLStreamParser, NQXMLTreeParser)
- * Expat (XMLStreamParser, XMLTreeParser)
- * REXML (REXMLStreamParser)
- * xml-scan (XMLScanStreamParser)
- * Fastest parser is Expat's XMLStreamParser!
-
-* General
- * possible to choose between XMLParser module (Expat wrapper) and REXML/NQXML (pure Ruby) parsers
- * Marshalling Ruby objects to Hashs and reconstruct them later from a Hash
- * SandStorm component architecture Client interface
-
-== Howto
-
-=== Client
-
- require "xmlrpc/client"
-
- # Make an object to represent the XML-RPC server.
- server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
-
- # Call the remote server and get our result
- result = server.call("sample.sumAndDifference", 5, 3)
-
- sum = result["sum"]
- difference = result["difference"]
-
- puts "Sum: #{sum}, Difference: #{difference}"
-
-=== Client with XML-RPC fault-structure handling
-
-There are two possible ways, of handling a fault-structure:
-
-==== by catching a XMLRPC::FaultException exception
-
- require "xmlrpc/client"
-
- # Make an object to represent the XML-RPC server.
- server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
-
- begin
- # Call the remote server and get our result
- result = server.call("sample.sumAndDifference", 5, 3)
-
- sum = result["sum"]
- difference = result["difference"]
-
- puts "Sum: #{sum}, Difference: #{difference}"
-
- rescue XMLRPC::FaultException => e
- puts "Error: "
- puts e.faultCode
- puts e.faultString
- end
-
-==== by calling "call2" which returns a boolean
-
- require "xmlrpc/client"
-
- # Make an object to represent the XML-RPC server.
- server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
-
- # Call the remote server and get our result
- ok, result = server.call2("sample.sumAndDifference", 5, 3)
-
- if ok
- sum = result["sum"]
- difference = result["difference"]
-
- puts "Sum: #{sum}, Difference: #{difference}"
- else
- puts "Error: "
- puts result.faultCode
- puts result.faultString
- end
-
-=== Client using Proxy
-
-You can create a +Proxy+ object onto which you can call methods. This way it
-looks nicer. Both forms, _call_ and _call2_ are supported through _proxy_ and
-<i>proxy2</i>. You can additionally give arguments to the Proxy, which will be
-given to each XML-RPC call using that Proxy.
-
- require "xmlrpc/client"
-
- # Make an object to represent the XML-RPC server.
- server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
-
- # Create a Proxy object
- sample = server.proxy("sample")
-
- # Call the remote server and get our result
- result = sample.sumAndDifference(5,3)
-
- sum = result["sum"]
- difference = result["difference"]
-
- puts "Sum: #{sum}, Difference: #{difference}"
-
-=== CGI-based Server
-
-There are also two ways to define handler, the first is
-like C/PHP, the second like Java, of course both ways
-can be mixed:
-
-==== C/PHP-like (handler functions)
-
- require "xmlrpc/server"
-
- s = XMLRPC::CGIServer.new
-
- s.add_handler("sample.sumAndDifference") do |a,b|
- { "sum" => a + b, "difference" => a - b }
- end
-
- s.serve
-
-==== Java-like (handler classes)
-
- require "xmlrpc/server"
-
- s = XMLRPC::CGIServer.new
-
- class MyHandler
- def sumAndDifference(a, b)
- { "sum" => a + b, "difference" => a - b }
- end
- end
-
- # NOTE: Security Hole (read below)!!!
- s.add_handler("sample", MyHandler.new)
- s.serve
-
-
-To return a fault-structure you have to raise an FaultException e.g.:
-
- raise XMLRPC::FaultException.new(3, "division by Zero")
-
-===== Security Note
-
-From Brian Candler:
-
- Above code sample has an extremely nasty security hole, in that you can now call
- any method of 'MyHandler' remotely, including methods inherited from Object
- and Kernel! For example, in the client code, you can use
-
- puts server.call("sample.send","`","ls")
-
- (backtick being the method name for running system processes). Needless to
- say, 'ls' can be replaced with something else.
-
- The version which binds proc objects (or the version presented below in the next section)
- doesn't have this problem, but people may be tempted to use the second version because it's
- so nice and 'Rubyesque'. I think it needs a big red disclaimer.
-
-
-From Michael:
-
-A solution is to undef insecure methods or to use (({XMLRPC::iPIMethods})) as shown below:
-
- class MyHandler
- def sumAndDifference(a, b)
- { "sum" => a + b, "difference" => a - b }
- end
- end
-
- # ... server initialization ...
-
- s.add_handler(XMLRPC::iPIMethods("sample"), MyHandler.new)
-
- # ...
-
-This adds only public instance methods explicitly declared in class MyHandler
-(and not those inherited from any other class).
-
-==== With interface declarations
-
-Code sample from the book Ruby Developer's Guide:
-
- require "xmlrpc/server"
-
- class Num
- INTERFACE = XMLRPC::interface("num") {
- meth 'int add(int, int)', 'Add two numbers', 'add'
- meth 'int div(int, int)', 'Divide two numbers'
- }
-
- def add(a, b) a + b end
- def div(a, b) a / b end
- end
-
-
- s = XMLRPC::CGIServer.new
- s.add_handler(Num::INTERFACE, Num.new)
- s.serve
-
-=== Standalone server
-
-Same as CGI-based server, only that the line
-
- server = XMLRPC::CGIServer.new
-
-must be changed to
-
- server = XMLRPC::Server.new(8080)
-
-if you want a server listening on port 8080.
-The rest is the same.
-
-=== Choosing a different XML Parser or XML Writer
-
-The examples above all use the default parser (which is now since 1.8
-REXMLStreamParser) and a default XML writer. If you want to use a different
-XML parser, then you have to call the <i>set_parser</i> method of
-<tt>XMLRPC::Client</tt> instances or instances of subclasses of
-<tt>XMLRPC::BasicServer</tt> or by editing xmlrpc/config.rb.
-
-Client Example:
-
- # ...
- server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
- server.set_parser(XMLRPC::XMLParser::XMLParser.new)
- # ...
-
-Server Example:
-
- # ...
- s = XMLRPC::CGIServer.new
- s.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
- # ...
-
-or:
-
- # ...
- server = XMLRPC::Server.new(8080)
- server.set_parser(XMLRPC::XMLParser::NQXMLParser.new)
- # ...
-
-
-Note that XMLStreamParser is incredible faster (and uses less memory) than any
-other parser and scales well for large documents. For example for a 0.5 MB XML
-document with many tags, XMLStreamParser is ~350 (!) times faster than
-NQXMLTreeParser and still ~18 times as fast as XMLTreeParser.
-
-You can change the XML-writer by calling method <i>set_writer</i>.
diff --git a/lib/xmlrpc/client.rb b/lib/xmlrpc/client.rb
index dadd3279f2..726945ea39 100644
--- a/lib/xmlrpc/client.rb
+++ b/lib/xmlrpc/client.rb
@@ -530,6 +530,9 @@ 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)
@@ -549,16 +552,16 @@ module XMLRPC
ct = parse_content_type(resp["Content-Type"]).first
if ct != "text/xml"
if ct == "text/html"
- raise "Wrong content-type: \n#{data}"
+ raise "Wrong content-type (received '#{ct}' but expected 'text/xml'): \n#{data}"
else
- raise "Wrong content-type"
+ raise "Wrong content-type (received '#{ct}' but expected 'text/xml')"
end
end
expected = resp["Content-Length"] || "<unknown>"
if data.nil? or data.size == 0
raise "Wrong size. Was #{data.size}, should be #{expected}"
- elsif expected.to_i != data.size and resp["Transfer-Encoding"].nil?
+ elsif expected != "<unknown>" and expected.to_i != data.size and resp["Transfer-Encoding"].nil?
raise "Wrong size. Was #{data.size}, should be #{expected}"
end
diff --git a/lib/xmlrpc/create.rb b/lib/xmlrpc/create.rb
index 9a3df0d832..b5c94254a4 100644
--- a/lib/xmlrpc/create.rb
+++ b/lib/xmlrpc/create.rb
@@ -194,12 +194,12 @@ module XMLRPC
when TrueClass, FalseClass
@writer.tag("boolean", param ? "1" : "0")
- when Symbol
- @writer.tag("string", param.to_s)
-
when String
@writer.tag("string", param)
+ when Symbol
+ @writer.tag("string", param.to_s)
+
when NilClass
if Config::ENABLE_NIL_CREATE
@writer.ele("nil")
@@ -241,7 +241,7 @@ module XMLRPC
@writer.ele("data", *a)
)
- when Time, Date
+ when Time, Date, ::DateTime
@writer.tag("dateTime.iso8601", param.strftime("%Y%m%dT%H:%M:%S"))
when XMLRPC::DateTime
diff --git a/lib/xmlrpc/datetime.rb b/lib/xmlrpc/datetime.rb
index f66ef8963a..298263fe8a 100644
--- a/lib/xmlrpc/datetime.rb
+++ b/lib/xmlrpc/datetime.rb
@@ -127,7 +127,7 @@ class DateTime
end
def ==(o)
- self.to_a == Array(o) rescue false
+ Array(self) == Array(o)
end
end
diff --git a/lib/xmlrpc/parser.rb b/lib/xmlrpc/parser.rb
index d27d7c3827..6d10fde9d9 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.reverse) + ofs
+ utc = Time.utc(*a) + 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.reverse) + ofs
+ utc = Time.utc(*a) + 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 59a5869408..ca8d3b0a5b 100644
--- a/lib/xmlrpc/server.rb
+++ b/lib/xmlrpc/server.rb
@@ -639,11 +639,11 @@ class Server < WEBrickServlet
def serve
if RUBY_PLATFORM =~ /mingw|mswin32/
- signal = 1
+ signals = [1]
else
- signal = "HUP"
+ signals = %w[INT TERM HUP]
end
- trap(signal) { @server.shutdown }
+ signals.each { |signal| trap(signal) { @server.shutdown } }
@server.start
end
diff --git a/lib/xmlrpc/utils.rb b/lib/xmlrpc/utils.rb
index 85c6bba372..f0966fee40 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, *b
+ return a.strip.downcase, *b
end
end
diff --git a/lib/xsd/codegen/gensupport.rb b/lib/xsd/codegen/gensupport.rb
index 8c2bb0d901..1e85d3668f 100644
--- a/lib/xsd/codegen/gensupport.rb
+++ b/lib/xsd/codegen/gensupport.rb
@@ -129,22 +129,22 @@ module GenSupport
private
def trim_eol(str)
- str.lines.collect { |line|
+ str.collect { |line|
line.sub(/\r?\n\z/, "") + "\n"
}.join
end
def trim_indent(str)
indent = nil
- str = str.lines.collect { |line| untab(line) }.join
- str.each_line do |line|
+ str = str.collect { |line| untab(line) }.join
+ str.each do |line|
head = line.index(/\S/)
if !head.nil? and (indent.nil? or head < indent)
indent = head
end
end
return str unless indent
- str.lines.collect { |line|
+ str.collect { |line|
line.sub(/^ {0,#{indent}}/, "")
}.join
end
diff --git a/lib/yaml.rb b/lib/yaml.rb
index fe8335c8f0..a8da42a321 100644
--- a/lib/yaml.rb
+++ b/lib/yaml.rb
@@ -384,6 +384,10 @@ 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 d24f6172e9..5439903f42 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,v| k.transform == key.first }
+ v = @value.detect { |k,| 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 eebf027135..dc6bb3359f 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( object_id, opts ) do |out|
+ YAML::quick_emit( self, 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( object_id, opts ) do |out|
+ YAML::quick_emit( self, 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( object_id, opts ) do |out|
+ YAML::quick_emit( self, 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( object_id, opts ) do |out|
+ YAML::quick_emit( self, 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( object_id, opts ) do |out|
+ YAML::quick_emit( self, 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? ? object_id : nil, opts ) do |out|
+ YAML::quick_emit( is_complex_yaml? ? self : 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( object_id, opts ) do |out|
+ YAML::quick_emit( self, 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( object_id, opts ) do |out|
+ YAML::quick_emit( self, 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( object_id, opts ) do |out|
+ YAML::quick_emit( self, 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 05113f216d..3871c628fe 100644
--- a/lib/yaml/types.rb
+++ b/lib/yaml/types.rb
@@ -10,7 +10,6 @@ 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
@@ -28,7 +27,6 @@ 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
@@ -47,7 +45,7 @@ module YAML
class Object
def self.tag_subclasses?; false; end
def to_yaml( opts = {} )
- YAML::quick_emit( object_id, opts ) do |out|
+ YAML::quick_emit( self, 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 )
@@ -125,7 +123,7 @@ module YAML
true
end
def to_yaml( opts = {} )
- YAML::quick_emit( self.object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
self.each do |v|
seq.add( Hash[ *v ] )
@@ -175,7 +173,7 @@ module YAML
true
end
def to_yaml( opts = {} )
- YAML::quick_emit( self.object_id, opts ) do |out|
+ YAML::quick_emit( self, opts ) do |out|
out.seq( taguri, to_yaml_style ) do |seq|
self.each do |v|
seq.add( Hash[ *v ] )
diff --git a/main.c b/main.c
index e815c9b210..bee9a4b15b 100644
--- a/main.c
+++ b/main.c
@@ -10,9 +10,16 @@
**********************************************************************/
-#undef RUBY_EXPORT
#include "ruby.h"
+#ifdef __human68k__
+int _stacksize = 262144;
+#endif
+
+#if defined __MINGW32__
+int _CRT_glob = 0;
+#endif
+
#if defined(__MACOS__) && defined(__MWERKS__)
#include <console.h>
#endif
@@ -23,12 +30,10 @@ static void objcdummyfunction( void ) { objc_msgSend(); }
#endif
int
-main(int argc, char **argv, char **envp)
+main(argc, argv, envp)
+ int argc;
+ char **argv, **envp;
{
-#ifdef RUBY_GC_STRESS
- RUBY_EXTERN int gc_stress;
- gc_stress = getenv("RUBY_GC_STRESS") != NULL;
-#endif
#ifdef _WIN32
NtInitialize(&argc, &argv);
#endif
diff --git a/marshal.c b/marshal.c
index 950a1b31d1..be5326e0a2 100644
--- a/marshal.c
+++ b/marshal.c
@@ -31,7 +31,9 @@
#define SHORTLEN(x) (x)
#else
static int
-shortlen(long len, BDIGIT *ds)
+shortlen(len, ds)
+ long len;
+ BDIGIT *ds;
{
BDIGIT num;
int offset = 0;
@@ -79,9 +81,19 @@ shortlen(long len, BDIGIT *ds)
#define TYPE_LINK '@'
static ID s_dump, s_load, s_mdump, s_mload;
-static ID s_dump_data, s_load_data, s_alloc;
+static ID s_dump_data, s_load_data, s_alloc, s_call;
static ID s_getc, s_read, s_write, s_binmode;
+static void
+reentrant_check(obj, sym)
+ VALUE obj;
+ ID sym;
+{
+ if (obj && RBASIC(obj)->klass) {
+ rb_raise(rb_eRuntimeError, "%s reentered", rb_id2name(sym));
+ }
+}
+
struct dump_arg {
VALUE obj;
VALUE str, dest;
@@ -97,10 +109,11 @@ struct dump_call_arg {
};
static VALUE
-class2path(VALUE klass)
+class2path(klass)
+ VALUE klass;
{
VALUE path = rb_class_path(klass);
- char *n = RSTRING_PTR(path);
+ char *n = RSTRING(path)->ptr;
if (n[0] == '#') {
rb_raise(rb_eTypeError, "can't dump anonymous %s %s",
@@ -113,14 +126,17 @@ class2path(VALUE klass)
return path;
}
-static void w_long(long, struct dump_arg*);
+static void w_long _((long, struct dump_arg*));
static void
-w_nbyte(const char *s, int n, struct dump_arg *arg)
+w_nbyte(s, n, arg)
+ char *s;
+ int n;
+ struct dump_arg *arg;
{
VALUE buf = arg->str;
rb_str_buf_cat(buf, s, n);
- if (arg->dest && RSTRING_LEN(buf) >= BUFSIZ) {
+ if (arg->dest && RSTRING(buf)->len >= BUFSIZ) {
if (arg->taint) OBJ_TAINT(buf);
rb_io_write(arg->dest, buf);
rb_str_resize(buf, 0);
@@ -128,27 +144,36 @@ w_nbyte(const char *s, int n, struct dump_arg *arg)
}
static void
-w_byte(char c, struct dump_arg *arg)
+w_byte(c, arg)
+ char c;
+ struct dump_arg *arg;
{
w_nbyte(&c, 1, arg);
}
static void
-w_bytes(const char *s, int n, struct dump_arg *arg)
+w_bytes(s, n, arg)
+ char *s;
+ int n;
+ struct dump_arg *arg;
{
w_long(n, arg);
w_nbyte(s, n, arg);
}
static void
-w_short(int x, struct dump_arg *arg)
+w_short(x, arg)
+ int x;
+ struct dump_arg *arg;
{
w_byte((x >> 0) & 0xff, arg);
w_byte((x >> 8) & 0xff, arg);
}
static void
-w_long(long x, struct dump_arg *arg)
+w_long(x, arg)
+ long x;
+ struct dump_arg *arg;
{
char buf[sizeof(long)+1];
int i, len = 0;
@@ -204,7 +229,9 @@ w_long(long x, struct dump_arg *arg)
#endif
static int
-save_mantissa(double d, char *buf)
+save_mantissa(d, buf)
+ double d;
+ char *buf;
{
int e, i = 0;
unsigned long m;
@@ -233,7 +260,10 @@ save_mantissa(double d, char *buf)
}
static double
-load_mantissa(double d, const char *buf, int len)
+load_mantissa(d, buf, len)
+ double d;
+ const char *buf;
+ int len;
{
if (--len > 0 && !*buf++) { /* binary mantissa mark */
int e, s = d < 0, dig = 0;
@@ -274,7 +304,9 @@ load_mantissa(double d, const char *buf, int len)
#endif
static void
-w_float(double d, struct dump_arg *arg)
+w_float(d, arg)
+ double d;
+ struct dump_arg *arg;
{
char buf[100];
@@ -302,9 +334,11 @@ w_float(double d, struct dump_arg *arg)
}
static void
-w_symbol(ID id, struct dump_arg *arg)
+w_symbol(id, arg)
+ ID id;
+ struct dump_arg *arg;
{
- const char *sym = rb_id2name(id);
+ char *sym = rb_id2name(id);
st_data_t num;
if (st_lookup(arg->symbols, id, &num)) {
@@ -319,7 +353,9 @@ w_symbol(ID id, struct dump_arg *arg)
}
static void
-w_unique(const char *s, struct dump_arg *arg)
+w_unique(s, arg)
+ char *s;
+ struct dump_arg *arg;
{
if (s[0] == '#') {
rb_raise(rb_eTypeError, "can't dump anonymous class %s", s);
@@ -327,10 +363,12 @@ w_unique(const char *s, struct dump_arg *arg)
w_symbol(rb_intern(s), arg);
}
-static void w_object(VALUE,struct dump_arg*,int);
+static void w_object _((VALUE,struct dump_arg*,int));
static int
-hash_each(VALUE key, VALUE value, struct dump_call_arg *arg)
+hash_each(key, value, arg)
+ VALUE key, value;
+ struct dump_call_arg *arg;
{
w_object(key, arg->arg, arg->limit);
w_object(value, arg->arg, arg->limit);
@@ -338,12 +376,15 @@ hash_each(VALUE key, VALUE value, struct dump_call_arg *arg)
}
static void
-w_extended(VALUE klass, struct dump_arg *arg, int check)
+w_extended(klass, arg, check)
+ VALUE klass;
+ struct dump_arg *arg;
+ int check;
{
char *path;
- if (FL_TEST(klass, FL_SINGLETON)) {
- if (check && RCLASS(klass)->m_tbl->num_entries ||
+ if (check && FL_TEST(klass, FL_SINGLETON)) {
+ if (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");
}
@@ -358,19 +399,25 @@ w_extended(VALUE klass, struct dump_arg *arg, int check)
}
static void
-w_class(char type, VALUE obj, struct dump_arg *arg, int check)
+w_class(type, obj, arg, check)
+ int type;
+ VALUE obj;
+ struct dump_arg *arg;
+ int check;
{
char *path;
VALUE klass = CLASS_OF(obj);
w_extended(klass, arg, check);
w_byte(type, arg);
- path = RSTRING_PTR(class2path(rb_class_real(klass)));
+ path = RSTRING(class2path(rb_class_real(klass)))->ptr;
w_unique(path, arg);
}
static void
-w_uclass(VALUE obj, VALUE base_klass, struct dump_arg *arg)
+w_uclass(obj, base_klass, arg)
+ VALUE obj, base_klass;
+ struct dump_arg *arg;
{
VALUE klass = CLASS_OF(obj);
@@ -378,12 +425,15 @@ w_uclass(VALUE obj, VALUE base_klass, struct dump_arg *arg)
klass = rb_class_real(klass);
if (klass != base_klass) {
w_byte(TYPE_UCLASS, arg);
- w_unique(RSTRING_PTR(class2path(klass)), arg);
+ w_unique(RSTRING(class2path(klass))->ptr, arg);
}
}
static int
-w_obj_each(ID id, VALUE value, struct dump_call_arg *arg)
+w_obj_each(id, value, arg)
+ ID id;
+ VALUE value;
+ struct dump_call_arg *arg;
{
w_symbol(id, arg->arg);
w_object(value, arg->arg, arg->limit);
@@ -391,7 +441,9 @@ w_obj_each(ID id, VALUE value, struct dump_call_arg *arg)
}
static void
-w_ivar(st_table *tbl, struct dump_call_arg *arg)
+w_ivar(tbl, arg)
+ st_table *tbl;
+ struct dump_call_arg *arg;
{
if (tbl) {
w_long(tbl->num_entries, arg->arg);
@@ -403,7 +455,10 @@ w_ivar(st_table *tbl, struct dump_call_arg *arg)
}
static void
-w_object(VALUE obj, struct dump_arg *arg, int limit)
+w_object(obj, arg, limit)
+ VALUE obj;
+ struct dump_arg *arg;
+ int limit;
{
struct dump_call_arg c_arg;
st_table *ivtbl = 0;
@@ -423,7 +478,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
return;
}
- if (ivtbl = rb_generic_ivar_table(obj)) {
+ if ((ivtbl = rb_generic_ivar_table(obj)) != 0) {
w_byte(TYPE_IVAR, arg);
}
if (obj == Qnil) {
@@ -457,9 +512,10 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
st_add_direct(arg->data, obj, arg->data->num_entries);
if (rb_respond_to(obj, s_mdump)) {
- VALUE v;
+ volatile VALUE v;
v = rb_funcall(obj, s_mdump, 0, 0);
+ reentrant_check(arg->str, s_mdump);
w_class(TYPE_USRMARSHAL, obj, arg, Qfalse);
w_object(v, arg, limit);
if (ivtbl) w_ivar(0, &c_arg);
@@ -469,6 +525,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
VALUE v;
v = rb_funcall(obj, s_dump, 1, INT2NUM(limit));
+ reentrant_check(arg->str, s_dump);
if (TYPE(v) != T_STRING) {
rb_raise(rb_eTypeError, "_dump() must return string");
}
@@ -476,7 +533,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
w_byte(TYPE_IVAR, arg);
}
w_class(TYPE_USERDEF, obj, arg, Qfalse);
- w_bytes(RSTRING_PTR(v), RSTRING_LEN(v), arg);
+ w_bytes(RSTRING(v)->ptr, RSTRING(v)->len, arg);
if (ivtbl) {
w_ivar(ivtbl, &c_arg);
}
@@ -491,7 +548,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
w_byte(TYPE_CLASS, arg);
{
VALUE path = class2path(obj);
- w_bytes(RSTRING_PTR(path), RSTRING_LEN(path), arg);
+ w_bytes(RSTRING(path)->ptr, RSTRING(path)->len, arg);
}
break;
@@ -499,7 +556,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
w_byte(TYPE_MODULE, arg);
{
VALUE path = class2path(obj);
- w_bytes(RSTRING_PTR(path), RSTRING_LEN(path), arg);
+ w_bytes(RSTRING(path)->ptr, RSTRING(path)->len, arg);
}
break;
@@ -538,7 +595,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
case T_STRING:
w_uclass(obj, rb_cString, arg);
w_byte(TYPE_STRING, arg);
- w_bytes(RSTRING_PTR(obj), RSTRING_LEN(obj), arg);
+ w_bytes(RSTRING(obj)->ptr, RSTRING(obj)->len, arg);
break;
case T_REGEXP:
@@ -552,8 +609,8 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
w_uclass(obj, rb_cArray, arg);
w_byte(TYPE_ARRAY, arg);
{
- long len = RARRAY_LEN(obj);
- VALUE *ptr = RARRAY_PTR(obj);
+ long len = RARRAY(obj)->len;
+ VALUE *ptr = RARRAY(obj)->ptr;
w_long(len, arg);
while (len--) {
@@ -585,15 +642,15 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
case T_STRUCT:
w_class(TYPE_STRUCT, obj, arg, Qtrue);
{
- long len = RSTRUCT_LEN(obj);
+ long len = RSTRUCT(obj)->len;
VALUE mem;
long i;
w_long(len, arg);
mem = rb_struct_members(obj);
for (i=0; i<len; i++) {
- w_symbol(SYM2ID(RARRAY_PTR(mem)[i]), arg);
- w_object(RSTRUCT_PTR(obj)[i], arg, limit);
+ w_symbol(SYM2ID(RARRAY(mem)->ptr[i]), arg);
+ w_object(RSTRUCT(obj)->ptr[i], arg, limit);
}
}
break;
@@ -607,13 +664,14 @@ w_object(VALUE obj, struct dump_arg *arg, int 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);
+ reentrant_check(arg->str, s_dump_data);
+ w_class(TYPE_DATA, obj, arg, Qtrue);
w_object(v, arg, limit);
}
break;
@@ -630,7 +688,8 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
}
static VALUE
-dump(struct dump_call_arg *arg)
+dump(arg)
+ struct dump_call_arg *arg;
{
w_object(arg->obj, arg->arg, arg->limit);
if (arg->arg->dest) {
@@ -641,13 +700,16 @@ dump(struct dump_call_arg *arg)
}
static VALUE
-dump_ensure(struct dump_arg *arg)
+dump_ensure(arg)
+ struct dump_arg *arg;
{
+ if (RBASIC(arg->str)->klass) return; /* ignore reentrant */
st_free_table(arg->symbols);
st_free_table(arg->data);
if (arg->taint) {
OBJ_TAINT(arg->str);
}
+
return 0;
}
@@ -678,7 +740,9 @@ dump_ensure(struct dump_arg *arg)
* obj.sayHello #=> "hello\n"
*/
static VALUE
-marshal_dump(int argc, VALUE *argv)
+marshal_dump(argc, argv)
+ int argc;
+ VALUE* argv;
{
VALUE obj, port, a1, a2;
int limit = -1;
@@ -698,20 +762,21 @@ marshal_dump(int argc, VALUE *argv)
else port = a1;
}
arg.dest = 0;
+ arg.str = rb_str_buf_new(0);
+ RBASIC(arg.str)->klass = 0;
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);
+ reentrant_check(arg.str, s_dump_data);
}
}
else {
- port = rb_str_buf_new(0);
- arg.str = port;
+ port = arg.str;
}
arg.symbols = st_init_numtable();
@@ -725,6 +790,7 @@ marshal_dump(int argc, VALUE *argv)
w_byte(MARSHAL_MINOR, &arg);
rb_ensure(dump, (VALUE)&c_arg, dump_ensure, (VALUE)&arg);
+ RBASIC(arg.str)->klass = rb_cString;
return port;
}
@@ -738,16 +804,17 @@ struct load_arg {
int taint;
};
-static VALUE r_object(struct load_arg *arg);
+static VALUE r_object _((struct load_arg *arg));
static int
-r_byte(struct load_arg *arg)
+r_byte(arg)
+ struct load_arg *arg;
{
int c;
if (TYPE(arg->src) == T_STRING) {
- if (RSTRING_LEN(arg->src) > arg->offset) {
- c = (unsigned char)RSTRING_PTR(arg->src)[arg->offset++];
+ if (RSTRING(arg->src)->len > arg->offset) {
+ c = (unsigned char)RSTRING(arg->src)->ptr[arg->offset++];
}
else {
rb_raise(rb_eArgError, "marshal data too short");
@@ -756,14 +823,16 @@ r_byte(struct load_arg *arg)
else {
VALUE src = arg->src;
VALUE v = rb_funcall2(src, s_getc, 0, 0);
+ reentrant_check(arg->data, s_getc);
if (NIL_P(v)) rb_eof_error();
- c = (unsigned char)NUM2CHR(v);
+ c = (unsigned char)FIX2INT(v);
}
return c;
}
static void
-long_toobig(int size)
+long_toobig(size)
+ int size;
{
rb_raise(rb_eTypeError, "long too big for this architecture (size %d, given %d)",
sizeof(long), size);
@@ -778,7 +847,8 @@ long_toobig(int size)
#endif
static long
-r_long(struct load_arg *arg)
+r_long(arg)
+ struct load_arg *arg;
{
register long x;
int c = SIGN_EXTEND_CHAR(r_byte(arg));
@@ -813,14 +883,16 @@ r_long(struct load_arg *arg)
#define r_bytes(arg) r_bytes0(r_long(arg), (arg))
static VALUE
-r_bytes0(long len, struct load_arg *arg)
+r_bytes0(len, arg)
+ long len;
+ struct load_arg *arg;
{
VALUE str;
if (len == 0) return rb_str_new(0, 0);
if (TYPE(arg->src) == T_STRING) {
- if (RSTRING_LEN(arg->src) > arg->offset) {
- str = rb_str_new(RSTRING_PTR(arg->src)+arg->offset, len);
+ if (RSTRING(arg->src)->len - arg->offset >= len) {
+ str = rb_str_new(RSTRING(arg->src)->ptr+arg->offset, len);
arg->offset += len;
}
else {
@@ -832,16 +904,18 @@ r_bytes0(long len, struct load_arg *arg)
VALUE src = arg->src;
VALUE n = LONG2NUM(len);
str = rb_funcall2(src, s_read, 1, &n);
+ reentrant_check(arg->data, s_read);
if (NIL_P(str)) goto too_short;
StringValue(str);
- if (RSTRING_LEN(str) != len) goto too_short;
+ if (RSTRING(str)->len != len) goto too_short;
if (OBJ_TAINTED(str)) arg->taint = Qtrue;
}
return str;
}
static ID
-r_symlink(struct load_arg *arg)
+r_symlink(arg)
+ struct load_arg *arg;
{
ID id;
long num = r_long(arg);
@@ -853,19 +927,20 @@ r_symlink(struct load_arg *arg)
}
static ID
-r_symreal(struct load_arg *arg)
+r_symreal(arg)
+ struct load_arg *arg;
{
ID id;
- volatile VALUE s = r_bytes(arg);
- id = rb_intern(RSTRING_PTR(s));
+ id = rb_intern(RSTRING(r_bytes(arg))->ptr);
st_insert(arg->symbols, arg->symbols->num_entries, id);
return id;
}
static ID
-r_symbol(struct load_arg *arg)
+r_symbol(arg)
+ struct load_arg *arg;
{
if (r_byte(arg) == TYPE_SYMLINK) {
return r_symlink(arg);
@@ -873,31 +948,34 @@ r_symbol(struct load_arg *arg)
return r_symreal(arg);
}
-static const char*
-r_unique(struct load_arg *arg)
+static char*
+r_unique(arg)
+ struct load_arg *arg;
{
return rb_id2name(r_symbol(arg));
}
static VALUE
-r_string(struct load_arg *arg)
+r_string(arg)
+ struct load_arg *arg;
{
return r_bytes(arg);
}
static VALUE
-r_entry(VALUE v, struct load_arg *arg)
+r_entry(v, arg)
+ VALUE v;
+ struct load_arg *arg;
{
rb_hash_aset(arg->data, INT2FIX(RHASH(arg->data)->tbl->num_entries), v);
if (arg->taint) OBJ_TAINT(v);
- if (arg->proc) {
- v = rb_funcall(arg->proc, rb_intern("call"), 1, v);
- }
return v;
}
static void
-r_ivar(VALUE obj, struct load_arg *arg)
+r_ivar(obj, arg)
+ VALUE obj;
+ struct load_arg *arg;
{
long len;
@@ -912,7 +990,8 @@ r_ivar(VALUE obj, struct load_arg *arg)
}
static VALUE
-path2class(const char *path)
+path2class(path)
+ char *path;
{
VALUE v = rb_path2class(path);
@@ -923,7 +1002,8 @@ path2class(const char *path)
}
static VALUE
-path2module(const char *path)
+path2module(path)
+ char *path;
{
VALUE v = rb_path2class(path);
@@ -934,7 +1014,11 @@ path2module(const char *path)
}
static VALUE
-r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
+r_object0(arg, proc, ivp, extmod)
+ struct load_arg *arg;
+ VALUE proc;
+ int *ivp;
+ VALUE extmod;
{
VALUE v = Qnil;
int type = r_byte(arg);
@@ -947,16 +1031,13 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
if (NIL_P(v)) {
rb_raise(rb_eArgError, "dump format error (unlinked)");
}
- if (arg->proc) {
- v = rb_funcall(arg->proc, rb_intern("call"), 1, v);
- }
- break;
+ return v;
case TYPE_IVAR:
{
int ivar = Qtrue;
- v = r_object0(arg, &ivar, extmod);
+ v = r_object0(arg, 0, &ivar, extmod);
if (ivar) r_ivar(v, arg);
}
break;
@@ -968,8 +1049,8 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
if (NIL_P(extmod)) extmod = rb_ary_new2(0);
rb_ary_push(extmod, m);
- v = r_object0(arg, 0, extmod);
- while (RARRAY_LEN(extmod) > 0) {
+ v = r_object0(arg, 0, 0, extmod);
+ while (RARRAY(extmod)->len > 0) {
m = rb_ary_pop(extmod);
rb_extend_object(v, m);
}
@@ -983,7 +1064,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
if (FL_TEST(c, FL_SINGLETON)) {
rb_raise(rb_eTypeError, "singleton can't be loaded");
}
- v = r_object0(arg, 0, extmod);
+ v = r_object0(arg, 0, 0, extmod);
if (rb_special_const_p(v) || TYPE(v) == T_OBJECT || TYPE(v) == T_CLASS) {
format_error:
rb_raise(rb_eArgError, "dump format error (user class)");
@@ -1020,7 +1101,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
{
double d, t = 0.0;
VALUE str = r_bytes(arg);
- const char *ptr = RSTRING_PTR(str);
+ const char *ptr = RSTRING(str)->ptr;
if (strcmp(ptr, "nan") == 0) {
d = t / t;
@@ -1034,10 +1115,10 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
else {
char *e;
d = strtod(ptr, &e);
- d = load_mantissa(d, e, RSTRING_LEN(str) - (e - ptr));
+ d = load_mantissa(d, e, RSTRING(str)->len - (e - ptr));
}
v = rb_float_new(d);
- v = r_entry(v, arg);
+ r_entry(v, arg);
}
break;
@@ -1058,7 +1139,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
big->len = (len + 1) * 2 / sizeof(BDIGIT);
#endif
big->digits = digits = ALLOC_N(BDIGIT, big->len);
- MEMCPY(digits, RSTRING_PTR(data), char, len * 2);
+ MEMCPY(digits, RSTRING(data)->ptr, char, len * 2);
#if SIZEOF_BDIGITS > SIZEOF_SHORT
MEMZERO((char *)digits + len * 2, char,
big->len * sizeof(BDIGIT) - len * 2);
@@ -1082,7 +1163,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
len--;
}
v = rb_big_norm((VALUE)big);
- v = r_entry(v, arg);
+ r_entry(v, arg);
}
break;
@@ -1094,7 +1175,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
{
volatile VALUE str = r_bytes(arg);
int options = r_byte(arg);
- v = r_entry(rb_reg_new(RSTRING_PTR(str), RSTRING_LEN(str), options), arg);
+ v = r_entry(rb_reg_new(RSTRING(str)->ptr, RSTRING(str)->len, options), arg);
}
break;
@@ -1103,7 +1184,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
volatile long len = r_long(arg); /* gcc 2.7.2.3 -O2 bug?? */
v = rb_ary_new2(len);
- v = r_entry(v, arg);
+ r_entry(v, arg);
while (len--) {
rb_ary_push(v, r_object(arg));
}
@@ -1116,7 +1197,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
long len = r_long(arg);
v = rb_hash_new();
- v = r_entry(v, arg);
+ r_entry(v, arg);
while (len--) {
VALUE key = r_object(arg);
VALUE value = r_object(arg);
@@ -1147,15 +1228,15 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
rb_ary_push(values, Qnil);
}
v = rb_struct_alloc(klass, values);
- v = r_entry(v, arg);
+ r_entry(v, arg);
for (i=0; i<len; i++) {
slot = r_symbol(arg);
- if (RARRAY_PTR(mem)[i] != ID2SYM(slot)) {
+ if (RARRAY(mem)->ptr[i] != ID2SYM(slot)) {
rb_raise(rb_eTypeError, "struct %s not compatible (:%s for :%s)",
rb_class2name(klass),
rb_id2name(slot),
- rb_id2name(SYM2ID(RARRAY_PTR(mem)[i])));
+ rb_id2name(SYM2ID(RARRAY(mem)->ptr[i])));
}
rb_struct_aset(v, LONG2FIX(i), r_object(arg));
}
@@ -1177,7 +1258,8 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
*ivp = Qfalse;
}
v = rb_funcall(klass, s_load, 1, data);
- v = r_entry(v, arg);
+ reentrant_check(arg->data, s_load);
+ r_entry(v, arg);
}
break;
@@ -1188,7 +1270,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
v = rb_obj_alloc(klass);
if (! NIL_P(extmod)) {
- while (RARRAY_LEN(extmod) > 0) {
+ while (RARRAY(extmod)->len > 0) {
VALUE m = rb_ary_pop(extmod);
rb_extend_object(v, m);
}
@@ -1197,9 +1279,10 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
rb_raise(rb_eTypeError, "instance of %s needs to have method `marshal_load'",
rb_class2name(klass));
}
- v = r_entry(v, arg);
+ r_entry(v, arg);
data = r_object(arg);
rb_funcall(v, s_mload, 1, data);
+ reentrant_check(arg->data, s_mload);
}
break;
@@ -1211,7 +1294,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
if (TYPE(v) != T_OBJECT) {
rb_raise(rb_eArgError, "dump format error");
}
- v = r_entry(v, arg);
+ r_entry(v, arg);
r_ivar(v, arg);
}
break;
@@ -1226,6 +1309,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
warn = Qfalse;
}
v = rb_funcall(klass, s_alloc, 0);
+ reentrant_check(arg->data, s_alloc);
}
else {
v = rb_obj_alloc(klass);
@@ -1233,13 +1317,14 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
if (TYPE(v) != T_DATA) {
rb_raise(rb_eArgError, "dump format error");
}
- v = r_entry(v, arg);
+ r_entry(v, arg);
if (!rb_respond_to(v, s_load_data)) {
rb_raise(rb_eTypeError,
"class %s needs to have instance method `_load_data'",
rb_class2name(klass));
}
- rb_funcall(v, s_load_data, 1, r_object0(arg, 0, extmod));
+ rb_funcall(v, s_load_data, 1, r_object0(arg, 0, 0, extmod));
+ reentrant_check(arg->data, s_load_data);
}
break;
@@ -1247,8 +1332,8 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
{
volatile VALUE str = r_bytes(arg);
- v = rb_path2class(RSTRING_PTR(str));
- v = r_entry(v, arg);
+ v = rb_path2class(RSTRING(str)->ptr);
+ r_entry(v, arg);
}
break;
@@ -1256,8 +1341,8 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
{
volatile VALUE str = r_bytes(arg);
- v = path2class(RSTRING_PTR(str));
- v = r_entry(v, arg);
+ v = path2class(RSTRING(str)->ptr);
+ r_entry(v, arg);
}
break;
@@ -1265,8 +1350,8 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
{
volatile VALUE str = r_bytes(arg);
- v = path2module(RSTRING_PTR(str));
- v = r_entry(v, arg);
+ v = path2module(RSTRING(str)->ptr);
+ r_entry(v, arg);
}
break;
@@ -1275,31 +1360,38 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
break;
case TYPE_SYMLINK:
- v = ID2SYM(r_symlink(arg));
- break;
+ return ID2SYM(r_symlink(arg));
default:
rb_raise(rb_eArgError, "dump format error(0x%x)", type);
break;
}
+ if (proc) {
+ rb_funcall(proc, s_call, 1, v);
+ reentrant_check(arg->data, s_call);
+ }
return v;
}
static VALUE
-r_object(struct load_arg *arg)
+r_object(arg)
+ struct load_arg *arg;
{
- return r_object0(arg, 0, Qnil);
+ return r_object0(arg, arg->proc, 0, Qnil);
}
static VALUE
-load(struct load_arg *arg)
+load(arg)
+ struct load_arg *arg;
{
return r_object(arg);
}
static VALUE
-load_ensure(struct load_arg *arg)
+load_ensure(arg)
+ struct load_arg *arg;
{
+ if (RBASIC(arg->data)->klass) return; /* ignore reentrant */
st_free_table(arg->symbols);
return 0;
}
@@ -1316,7 +1408,9 @@ load_ensure(struct load_arg *arg)
* is deserialized.
*/
static VALUE
-marshal_load(int argc, VALUE *argv)
+marshal_load(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE port, proc;
int major, minor;
@@ -1324,9 +1418,10 @@ marshal_load(int argc, VALUE *argv)
struct load_arg arg;
rb_scan_args(argc, argv, "11", &port, &proc);
- if (rb_respond_to(port, rb_intern("to_str"))) {
+ v = rb_check_string_type(port);
+ if (!NIL_P(v)) {
arg.taint = OBJ_TAINTED(port); /* original taintedness */
- StringValue(port); /* possible conversion */
+ port = v;
}
else if (rb_respond_to(port, s_getc) && rb_respond_to(port, s_read)) {
if (rb_respond_to(port, s_binmode)) {
@@ -1339,6 +1434,7 @@ marshal_load(int argc, VALUE *argv)
}
arg.src = port;
arg.offset = 0;
+ arg.data = 0;
major = r_byte(&arg);
minor = r_byte(&arg);
@@ -1355,9 +1451,11 @@ marshal_load(int argc, VALUE *argv)
arg.symbols = st_init_numtable();
arg.data = rb_hash_new();
+ RBASIC(arg.data)->klass = 0;
if (NIL_P(proc)) arg.proc = 0;
else arg.proc = proc;
v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
+ RBASIC(arg.data)->klass = rb_cHash;
return v;
}
@@ -1396,7 +1494,7 @@ marshal_load(int argc, VALUE *argv)
* The class method _load should take a String and return an object of this class.
*/
void
-Init_marshal(void)
+Init_marshal()
{
VALUE rb_mMarshal = rb_define_module("Marshal");
@@ -1407,6 +1505,7 @@ Init_marshal(void)
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");
@@ -1421,7 +1520,8 @@ Init_marshal(void)
}
VALUE
-rb_marshal_dump(VALUE obj, VALUE port)
+rb_marshal_dump(obj, port)
+ VALUE obj, port;
{
int argc = 1;
VALUE argv[2];
@@ -1433,7 +1533,8 @@ rb_marshal_dump(VALUE obj, VALUE port)
}
VALUE
-rb_marshal_load(VALUE port)
+rb_marshal_load(port)
+ VALUE port;
{
return marshal_load(1, &port);
}
diff --git a/math.c b/math.c
index 2675c71e6d..cf78fc4f2a 100644
--- a/math.c
+++ b/math.c
@@ -23,7 +23,9 @@ VALUE rb_mMath;
} while (0)
static void
-domain_check(double x, char *msg)
+domain_check(x, msg)
+ double x;
+ char *msg;
{
while(1) {
if (errno) {
@@ -32,7 +34,7 @@ domain_check(double x, char *msg)
if (isnan(x)) {
#if defined(EDOM)
errno = EDOM;
-#elif define(ERANGE)
+#elif defined(ERANGE)
errno = ERANGE;
#endif
continue;
@@ -52,7 +54,8 @@ domain_check(double x, char *msg)
*/
static VALUE
-math_atan2(VALUE obj, VALUE y, VALUE x)
+math_atan2(obj, y, x)
+ VALUE obj, x, y;
{
Need_Float2(y, x);
return rb_float_new(atan2(RFLOAT(y)->value, RFLOAT(x)->value));
@@ -68,7 +71,8 @@ math_atan2(VALUE obj, VALUE y, VALUE x)
*/
static VALUE
-math_cos(VALUE obj, VALUE x)
+math_cos(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
return rb_float_new(cos(RFLOAT(x)->value));
@@ -83,7 +87,8 @@ math_cos(VALUE obj, VALUE x)
*/
static VALUE
-math_sin(VALUE obj, VALUE x)
+math_sin(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
@@ -99,7 +104,8 @@ math_sin(VALUE obj, VALUE x)
*/
static VALUE
-math_tan(VALUE obj, VALUE x)
+math_tan(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
@@ -114,7 +120,8 @@ math_tan(VALUE obj, VALUE x)
*/
static VALUE
-math_acos(VALUE obj, VALUE x)
+math_acos(obj, x)
+ VALUE obj, x;
{
double d;
@@ -133,7 +140,8 @@ math_acos(VALUE obj, VALUE x)
*/
static VALUE
-math_asin(VALUE obj, VALUE x)
+math_asin(obj, x)
+ VALUE obj, x;
{
double d;
@@ -152,7 +160,8 @@ math_asin(VALUE obj, VALUE x)
*/
static VALUE
-math_atan(VALUE obj, VALUE x)
+math_atan(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
return rb_float_new(atan(RFLOAT(x)->value));
@@ -160,7 +169,8 @@ math_atan(VALUE obj, VALUE x)
#ifndef HAVE_COSH
double
-cosh(double x)
+cosh(x)
+ double x;
{
return (exp(x) + exp(-x)) / 2;
}
@@ -174,7 +184,8 @@ cosh(double x)
*/
static VALUE
-math_cosh(VALUE obj, VALUE x)
+math_cosh(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
@@ -183,7 +194,8 @@ math_cosh(VALUE obj, VALUE x)
#ifndef HAVE_SINH
double
-sinh(double x)
+sinh(x)
+ double x;
{
return (exp(x) - exp(-x)) / 2;
}
@@ -198,7 +210,8 @@ sinh(double x)
*/
static VALUE
-math_sinh(VALUE obj, VALUE x)
+math_sinh(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
return rb_float_new(sinh(RFLOAT(x)->value));
@@ -206,7 +219,8 @@ math_sinh(VALUE obj, VALUE x)
#ifndef HAVE_TANH
double
-tanh(double x)
+tanh(x)
+ double x;
{
return sinh(x) / cosh(x);
}
@@ -221,7 +235,8 @@ tanh(double x)
*/
static VALUE
-math_tanh(VALUE obj, VALUE x)
+math_tanh(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
return rb_float_new(tanh(RFLOAT(x)->value));
@@ -235,7 +250,8 @@ math_tanh(VALUE obj, VALUE x)
*/
static VALUE
-math_acosh(VALUE obj, VALUE x)
+math_acosh(obj, x)
+ VALUE obj, x;
{
double d;
@@ -254,7 +270,8 @@ math_acosh(VALUE obj, VALUE x)
*/
static VALUE
-math_asinh(VALUE obj, VALUE x)
+math_asinh(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
return rb_float_new(asinh(RFLOAT(x)->value));
@@ -268,7 +285,8 @@ math_asinh(VALUE obj, VALUE x)
*/
static VALUE
-math_atanh(VALUE obj, VALUE x)
+math_atanh(obj, x)
+ VALUE obj, x;
{
double d;
@@ -287,7 +305,8 @@ math_atanh(VALUE obj, VALUE x)
*/
static VALUE
-math_exp(VALUE obj, VALUE x)
+math_exp(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
return rb_float_new(exp(RFLOAT(x)->value));
@@ -310,56 +329,18 @@ math_exp(VALUE obj, VALUE x)
*/
static VALUE
-math_log(int argc, VALUE *argv)
+math_log(obj, x)
+ VALUE obj, x;
{
- VALUE x, base;
double d;
- rb_scan_args(argc, argv, "11", &x, &base);
Need_Float(x);
errno = 0;
d = log(RFLOAT(x)->value);
- if (!NIL_P(base)) {
- Need_Float(base);
- d /= log(RFLOAT(base)->value);
- }
domain_check(d, "log");
return rb_float_new(d);
}
-#ifndef log2
-#ifndef HAVE_LOG2
-double
-log2(double x)
-{
- return log10(x)/log10(2.0);
-}
-#else
-extern double log2(double);
-#endif
-#endif
-
-/*
- * call-seq:
- * Math.log2(numeric) => float
- *
- * Returns the base 2 logarithm of <i>numeric</i>.
- */
-
-static VALUE
-math_log2(VALUE obj, VALUE x)
-{
- double d;
-
- Need_Float(x);
- errno = 0;
- d = log2(RFLOAT(x)->value);
- if (errno) {
- rb_sys_fail("log2");
- }
- return rb_float_new(d);
-}
-
/*
* call-seq:
* Math.log10(numeric) => float
@@ -368,7 +349,8 @@ math_log2(VALUE obj, VALUE x)
*/
static VALUE
-math_log10(VALUE obj, VALUE x)
+math_log10(obj, x)
+ VALUE obj, x;
{
double d;
@@ -387,7 +369,8 @@ math_log10(VALUE obj, VALUE x)
*/
static VALUE
-math_sqrt(VALUE obj, VALUE x)
+math_sqrt(obj, x)
+ VALUE obj, x;
{
double d;
@@ -411,7 +394,8 @@ math_sqrt(VALUE obj, VALUE x)
*/
static VALUE
-math_frexp(VALUE obj, VALUE x)
+math_frexp(obj, x)
+ VALUE obj, x;
{
double d;
int exp;
@@ -433,7 +417,8 @@ math_frexp(VALUE obj, VALUE x)
*/
static VALUE
-math_ldexp(VALUE obj, VALUE x, VALUE n)
+math_ldexp(obj, x, n)
+ VALUE obj, x, n;
{
Need_Float(x);
return rb_float_new(ldexp(RFLOAT(x)->value, NUM2INT(n)));
@@ -450,7 +435,8 @@ math_ldexp(VALUE obj, VALUE x, VALUE n)
*/
static VALUE
-math_hypot(VALUE obj, VALUE x, VALUE y)
+math_hypot(obj, x, y)
+ VALUE obj, x, y;
{
Need_Float2(x, y);
return rb_float_new(hypot(RFLOAT(x)->value, RFLOAT(y)->value));
@@ -464,7 +450,8 @@ math_hypot(VALUE obj, VALUE x, VALUE y)
*/
static VALUE
-math_erf(VALUE obj, VALUE x)
+math_erf(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
return rb_float_new(erf(RFLOAT(x)->value));
@@ -478,7 +465,8 @@ math_erf(VALUE obj, VALUE x)
*/
static VALUE
-math_erfc(VALUE obj, VALUE x)
+math_erfc(obj, x)
+ VALUE obj, x;
{
Need_Float(x);
return rb_float_new(erfc(RFLOAT(x)->value));
@@ -493,7 +481,7 @@ math_erfc(VALUE obj, VALUE x)
void
-Init_Math(void)
+Init_Math()
{
rb_mMath = rb_define_module("Math");
@@ -527,8 +515,7 @@ Init_Math(void)
rb_define_module_function(rb_mMath, "atanh", math_atanh, 1);
rb_define_module_function(rb_mMath, "exp", math_exp, 1);
- rb_define_module_function(rb_mMath, "log", math_log, -1);
- rb_define_module_function(rb_mMath, "log2", math_log2, 1);
+ rb_define_module_function(rb_mMath, "log", math_log, 1);
rb_define_module_function(rb_mMath, "log10", math_log10, 1);
rb_define_module_function(rb_mMath, "sqrt", math_sqrt, 1);
diff --git a/misc/README b/misc/README
index 4a913b1ced..c7e63d7799 100644
--- a/misc/README
+++ b/misc/README
@@ -1,6 +1,7 @@
-README this file
-inf-ruby.el program to run ruby under emacs
-ruby-mode.el ruby mode for emacs
-rubydb2x.el ruby debugger support for emacs 19.2x or before
-rubydb3x.el ruby debugger support for emacs 19.3x or later
-ruby-electric.el emacs minor mode providing electric commands
+README this file
+inf-ruby.el program to run ruby under emacs
+ruby-mode.el ruby mode for emacs
+rubydb2x.el ruby debugger support for emacs 19.2x or before
+rubydb3x.el ruby debugger support for emacs 19.3x or later
+ruby-electric.el emacs minor mode providing electric commands
+rdebug.el ruby-debug (rdebug) support for emacs 19.3x or later
diff --git a/misc/rdebug.el b/misc/rdebug.el
new file mode 100644
index 0000000000..81ab0071a0
--- /dev/null
+++ b/misc/rdebug.el
@@ -0,0 +1,136 @@
+;; This file adds support for ruby-debug (rdebug) in Emacs.
+;; Copyright (C) 2007 Martin Nordholts <enselic@gmail.com>
+;;
+;; This file is based on 'rubydb3x.el' that comes with Ruby which is
+;; Copyright (C) Yukihiro Matsumoto aka Matz
+;;
+;; Installation:
+;; -------------
+;;
+;; 1. Make sure you have ruby-debug on your system (test by running
+;; the commmand 'rdebug -v' in a shell).
+;;
+;; 2. Copy this file into e.g. ~/.elisp and make sure this is in
+;; your ~/.emacs:
+;;
+;; (add-to-list 'load-path "~/.elisp")
+;; (load-library "rdebug")
+;;
+;; you can then start the debugger with M-x rdebug
+;;
+;; 3. Setup convenient keybindings etc. This is what I have:
+;;
+;; (global-set-key [f9] 'gud-step)
+;; (global-set-key [f10] 'gud-next)
+;; (global-set-key [f11] 'gud-cont)
+;;
+;; (global-set-key "\C-c\C-d" 'rdebug)
+;;
+;; 4. Debug like crazy!
+;;
+;; Bugs:
+;; -----
+;;
+;; Basic functionality works fine, though there might be a bug hiding somewhere.
+
+(require 'gud)
+(provide 'rdebug)
+
+;; ======================================================================
+;; rdebug functions
+
+;;; History of argument lists passed to rdebug.
+(defvar gud-rdebug-history nil)
+
+(if (fboundp 'gud-overload-functions)
+ (defun gud-rdebug-massage-args (file args)
+ (cons file args))
+ (defun gud-rdebug-massage-args (file args)
+ args))
+
+;; There's no guarantee that Emacs will hand the filter the entire
+;; marker at once; it could be broken up across several strings. We
+;; might even receive a big chunk with several markers in it. If we
+;; receive a chunk of text which looks like it might contain the
+;; beginning of a marker, we save it here between calls to the
+;; filter.
+(defvar gud-rdebug-marker-acc "")
+(make-variable-buffer-local 'gud-rdebug-marker-acc)
+
+(defun gud-rdebug-marker-filter (string)
+ (setq gud-rdebug-marker-acc (concat gud-rdebug-marker-acc string))
+ (let ((output ""))
+
+ ;; Process all the complete markers in this chunk.
+ (while (string-match "\\([^:\n]*\\):\\([0-9]+\\):.*\n"
+ gud-rdebug-marker-acc)
+ (setq
+
+ ;; Extract the frame position from the marker.
+ gud-last-frame
+ (cons (substring gud-rdebug-marker-acc (match-beginning 1) (match-end 1))
+ (string-to-int (substring gud-rdebug-marker-acc
+ (match-beginning 2)
+ (match-end 2))))
+
+
+ ;; Append any text before the marker to the output we're going
+ ;; to return - we don't include the marker in this text.
+ output (concat output
+ (substring gud-rdebug-marker-acc 0 (match-beginning 0)))
+
+ ;; Set the accumulator to the remaining text.
+ gud-rdebug-marker-acc (substring gud-rdebug-marker-acc (match-end 0))))
+
+ (setq output (concat output gud-rdebug-marker-acc)
+ gud-rdebug-marker-acc "")
+
+ output))
+
+(defun gud-rdebug-find-file (f)
+ (save-excursion
+ (let ((buf (find-file-noselect f)))
+ (set-buffer buf)
+;; (gud-make-debug-menu)
+ buf)))
+
+(defvar rdebug-command-name "rdebug"
+ "File name for executing rdebug.")
+
+;;;###autoload
+(defun rdebug (command-line)
+ "Run rdebug on program FILE in buffer *gud-FILE*.
+The directory containing FILE becomes the initial working directory
+and source-file directory for your debugger."
+ (interactive
+ (list (read-from-minibuffer "Run rdebug (like this): "
+ (if (consp gud-rdebug-history)
+ (car gud-rdebug-history)
+ (concat rdebug-command-name " "))
+ nil nil
+ '(gud-rdebug-history . 1))))
+
+ (if (not (fboundp 'gud-overload-functions))
+ (gud-common-init command-line 'gud-rdebug-massage-args
+ 'gud-rdebug-marker-filter 'gud-rdebug-find-file)
+ (gud-overload-functions '((gud-massage-args . gud-rdebug-massage-args)
+ (gud-marker-filter . gud-rdebug-marker-filter)
+ (gud-find-file . gud-rdebug-find-file)))
+ (gud-common-init command-line rdebug-command-name))
+
+ (gud-def gud-break "break %d%f:%l" "\C-b" "Set breakpoint at current line in current file.")
+; (gud-def gud-remove "delete %d%f:%l" "\C-d" "Remove breakpoint at current line in current file.")
+ (gud-def gud-step "step" "\C-s" "Step one source line with display.")
+ (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
+ (gud-def gud-cont "cont" "\C-r" "Continue with display.")
+ (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
+ (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
+ (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
+ (gud-def gud-print "p %e" "\C-p" "Evaluate ruby expression at point.")
+
+ (setq comint-prompt-regexp "^(rdb:-) ")
+ (if (boundp 'comint-last-output-start)
+ (set-marker comint-last-output-start (point)))
+ (set (make-local-variable 'paragraph-start) comint-prompt-regexp)
+ (run-hooks 'rdebug-mode-hook)
+ )
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index c44b4c7875..779a52def4 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -45,7 +45,7 @@
(concat ruby-modifier-beg-re "\\|" ruby-block-op-re)
)
-(defconst ruby-block-end-re "\\<end\\>\\|;;")
+(defconst ruby-block-end-re "\\<end\\>")
(defconst ruby-here-doc-beg-re
"<<\\(-\\)?\\(\\([a-zA-Z0-9_]+\\)\\|[\"]\\([^\"]+\\)[\"]\\|[']\\([^']+\\)[']\\)")
@@ -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-hooks 'ruby-mode-hook))
+ (run-mode-hooks 'ruby-mode-hook))
(defun ruby-current-indentation ()
(save-excursion
@@ -383,6 +383,8 @@ The variable ruby-indent-level controls the amount of indentation.
(t
(setq in-string (point))
(goto-char end))))
+ ((looking-at "/=")
+ (goto-char pnt))
((looking-at "/")
(cond
((and (not (eobp)) (ruby-expr-beg 'expr-re))
@@ -1011,7 +1013,7 @@ balanced expression is found."
;; ?' ?" ?` are ascii codes
("\\(^\\|[^\\\\]\\)\\(\\\\\\\\\\)*[?$]\\([#\"'`]\\)" 3 (1 . nil))
;; regexps
- ("\\(^\\|[=(,~?:;]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)"
+ ("\\(^\\|[=(,~?:;<>]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)"
(4 (7 . ?/))
(6 (7 . ?/)))
("^\\(=\\)begin\\(\\s \\|$\\)" 1 (7 . nil))
diff --git a/missing.h b/missing.h
index db37e3ae4c..3f56078259 100644
--- a/missing.h
+++ b/missing.h
@@ -26,115 +26,117 @@ struct timeval {
#endif
#ifndef HAVE_ACOSH
-extern double acosh(double);
-extern double asinh(double);
-extern double atanh(double);
+extern double acosh _((double));
+extern double asinh _((double));
+extern double atanh _((double));
#endif
#ifndef HAVE_CRYPT
-extern char *crypt(const char *, const char *);
+extern char *crypt _((char *, char *));
#endif
#ifndef HAVE_DUP2
-extern int dup2(int, int);
+extern int dup2 _((int, int));
#endif
#ifndef HAVE_EACCESS
-extern int eaccess(const char*, int);
+extern int eaccess _((const char*, int));
#endif
#ifndef HAVE_FINITE
-extern int finite(double);
+extern int finite _((double));
#endif
#ifndef HAVE_FLOCK
-extern int flock(int, int);
+extern int flock _((int, int));
#endif
/*
#ifndef HAVE_FREXP
-extern double frexp(double, int *);
+extern double frexp _((double, int *));
#endif
*/
#ifndef HAVE_HYPOT
-extern double hypot(double, double);
+extern double hypot _((double, double));
#endif
#ifndef HAVE_ERF
-extern double erf(double);
-extern double erfc(double);
+extern double erf _((double));
+extern double erfc _((double));
#endif
-#ifndef isinf
-# ifndef HAVE_ISINF
-# if defined(HAVE_FINITE) && defined(HAVE_ISNAN)
-# define isinf(x) (!finite(x) && !isnan(x))
-# else
-extern int isinf(double);
-# endif
+#ifndef HAVE_ISINF
+# if defined(HAVE_FINITE) && defined(HAVE_ISNAN)
+# define isinf(x) (!finite(x) && !isnan(x))
+# else
+extern int isinf _((double));
# endif
#endif
#ifndef HAVE_ISNAN
-extern int isnan(double);
+extern int isnan _((double));
#endif
/*
#ifndef HAVE_MEMCMP
-extern int memcmp(const void *, const void *, size_t);
+extern int memcmp _((char *, char *, int));
#endif
*/
#ifndef HAVE_MEMMOVE
-extern void *memmove(void *, const void *, size_t);
+extern void *memmove _((void *, void *, int));
#endif
/*
#ifndef HAVE_MODF
-extern double modf(double, double *);
+extern double modf _((double, double *));
#endif
*/
#ifndef HAVE_STRCASECMP
-extern int strcasecmp(const char *, const char *);
+extern int strcasecmp _((char *, char *));
#endif
#ifndef HAVE_STRNCASECMP
-extern int strncasecmp(const char *, const char *, size_t);
+extern int strncasecmp _((char *, char *, int));
#endif
#ifndef HAVE_STRCHR
-extern char *strchr(const char *, int);
-extern char *strrchr(const char *, int);
+extern char *strchr _((char *, int));
+extern char *strrchr _((char *, int));
#endif
#ifndef HAVE_STRERROR
-extern char *strerror(int);
+extern char *strerror _((int));
#endif
#ifndef HAVE_STRFTIME
-extern size_t strftime(char *, size_t, const char *, const struct tm *);
+extern size_t strftime _((char *, size_t, const char *, const struct tm *));
#endif
#ifndef HAVE_STRSTR
-extern char *strstr(const char *, const char *);
+extern char *strstr _((char *, char *));
#endif
/*
#ifndef HAVE_STRTOL
-extern long strtol(const char *, char **, int);
+extern long strtol _((char *, char **, int));
#endif
*/
#ifndef HAVE_STRTOUL
-extern unsigned long strtoul(const char *, char **, int);
+extern unsigned long strtoul _((char *, char **, int));
#endif
#ifndef HAVE_VSNPRINTF
-# include <stdarg.h>
-extern int snprintf(char *, size_t n, char const *, ...);
-extern int vsnprintf(char *, size_t n, char const *, va_list);
+# ifdef HAVE_STDARG_PROTOTYPES
+# include <stdarg.h>
+# else
+# include <varargs.h>
+# endif
+extern int snprintf __((char *, size_t n, char const *, ...));
+extern int vsnprintf _((char *, size_t n, char const *, va_list));
#endif
#endif /* MISSING_H */
diff --git a/missing/acosh.c b/missing/acosh.c
index 59f4af9248..a4443e191f 100644
--- a/missing/acosh.c
+++ b/missing/acosh.c
@@ -33,7 +33,8 @@
#ifndef HAVE_ACOSH
double
-acosh(double x)
+acosh(x)
+ double x;
{
if (x < 1)
x = -1; /* NaN */
@@ -49,7 +50,8 @@ acosh(double x)
#ifndef HAVE_ASINH
double
-asinh(double x)
+asinh(x)
+ double x;
{
int neg = x < 0;
double z = fabs(x);
@@ -72,7 +74,8 @@ asinh(double x)
#ifndef HAVE_ATANH
double
-atanh(double x)
+atanh(x)
+ double x;
{
int neg = x < 0;
double z = fabs(x);
diff --git a/missing/dup2.c b/missing/dup2.c
index 00d8145976..e7cc46f4c1 100644
--- a/missing/dup2.c
+++ b/missing/dup2.c
@@ -24,7 +24,8 @@
#define BADEXIT -1
int
-dup2(int fd1, int fd2)
+dup2(fd1, fd2)
+int fd1, fd2;
{
#if defined(HAVE_FCNTL) && defined(F_DUPFD)
if (fd1 != fd2) {
diff --git a/missing/erf.c b/missing/erf.c
index fe65b9a479..d9e7469024 100644
--- a/missing/erf.c
+++ b/missing/erf.c
@@ -25,7 +25,8 @@ static double q_gamma(double, double, double);
/* Incomplete gamma function
1 / Gamma(a) * Int_0^x exp(-t) t^(a-1) dt */
-static double p_gamma(double a, double x, double loggamma_a)
+static double p_gamma(a, x, loggamma_a)
+ double a, x, loggamma_a;
{
int k;
double result, term, previous;
@@ -44,7 +45,8 @@ static double p_gamma(double a, double x, double loggamma_a)
/* Incomplete gamma function
1 / Gamma(a) * Int_x^inf exp(-t) t^(a-1) dt */
-static double q_gamma(double a, double x, double loggamma_a)
+static double q_gamma(a, x, loggamma_a)
+ double a, x, loggamma_a;
{
int k;
double result, w, temp, previous;
@@ -67,7 +69,8 @@ static double q_gamma(double a, double x, double loggamma_a)
#define LOG_PI_OVER_2 0.572364942924700087071713675675 /* log_e(PI)/2 */
-double erf(double x)
+double erf(x)
+ double x;
{
if (!finite(x)) {
if (isnan(x)) return x; /* erf(NaN) = NaN */
@@ -77,7 +80,8 @@ double erf(double x)
else return - p_gamma(0.5, x * x, LOG_PI_OVER_2);
}
-double erfc(double x)
+double erfc(x)
+ double x;
{
if (!finite(x)) {
if (isnan(x)) return x; /* erfc(NaN) = NaN */
diff --git a/missing/finite.c b/missing/finite.c
index 8d0b7af262..f91035a8cd 100644
--- a/missing/finite.c
+++ b/missing/finite.c
@@ -1,7 +1,8 @@
/* public domain rewrite of finite(3) */
int
-finite(double n)
+finite(n)
+ double n;
{
return !isnan(n) && !isinf(n);
}
diff --git a/missing/flock.c b/missing/flock.c
index 7a5a58aaa7..5f6b41c357 100644
--- a/missing/flock.c
+++ b/missing/flock.c
@@ -1,6 +1,7 @@
#include "config.h"
-#if defined HAVE_FCNTL && defined HAVE_FCNTL_H
+#if defined _WIN32
+#elif defined HAVE_FCNTL && defined HAVE_FCNTL_H
/* These are the flock() constants. Since this sytems doesn't have
flock(), the values of the constants are probably not available.
@@ -23,7 +24,9 @@
#include <errno.h>
int
-flock(int fd, int operation)
+flock(fd, operation)
+ int fd;
+ int operation;
{
struct flock lock;
@@ -88,7 +91,9 @@ flock(int fd, int operation)
# endif
int
-flock(int fd, int operation)
+flock(fd, operation)
+ int fd;
+ int operation;
{
switch (operation) {
@@ -118,9 +123,11 @@ flock(int fd, int operation)
return -1;
}
}
-#elif !defined _WIN32
+#else
int
-flock(int fd, int operation)
+flock(fd, operation)
+ int fd;
+ int operation;
{
rb_notimplement();
return -1;
diff --git a/missing/hypot.c b/missing/hypot.c
index 5a663553cf..aad5259e92 100644
--- a/missing/hypot.c
+++ b/missing/hypot.c
@@ -2,7 +2,8 @@
#include <math.h>
-double hypot(double x, double y)
+double hypot(x,y)
+ double x, y;
{
if (x < 0) x = -x;
if (y < 0) y = -y;
diff --git a/missing/isinf.c b/missing/isinf.c
index 27271bdec2..c9e49c6795 100644
--- a/missing/isinf.c
+++ b/missing/isinf.c
@@ -6,7 +6,8 @@
#include <nan.h>
int
-isinf(double n)
+isinf(n)
+ double n;
{
if (IsNANorINF(n) && IsINF(n)) {
return 1;
@@ -27,11 +28,19 @@ isinf(double 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(double n)
+isinf(n)
+ double n;
{
return (!finite(n) && !isnan(n));
}
+#endif
#else
@@ -41,12 +50,13 @@ isinf(double n)
# include <strings.h>
#endif
-static double zero(void) { return 0.0; }
-static double one (void) { return 1.0; }
-static double inf (void) { return one() / zero(); }
+static double zero() { return 0.0; }
+static double one() { return 1.0; }
+static double inf() { return one() / zero(); }
int
-isinf(double n)
+isinf(n)
+ double n;
{
static double pinf = 0.0;
static double ninf = 0.0;
diff --git a/missing/isnan.c b/missing/isnan.c
index a8733978ad..459048e936 100644
--- a/missing/isnan.c
+++ b/missing/isnan.c
@@ -1,15 +1,17 @@
/* public domain rewrite of isnan(3) */
-static int double_ne(double n1, double n2);
+static int double_ne();
int
-isnan(double n)
+isnan(n)
+ double n;
{
return double_ne(n, n);
}
static int
-double_ne(double n1, double n2)
+double_ne(n1, n2)
+ double n1, n2;
{
return n1 != n2;
}
diff --git a/missing/memcmp.c b/missing/memcmp.c
index 5b3ad3817a..9edc9c13b9 100644
--- a/missing/memcmp.c
+++ b/missing/memcmp.c
@@ -1,15 +1,16 @@
/* public domain rewrite of memcmp(3) */
-#include <stddef.h>
-
int
-memcmp(const void *s1, const void *s2, size_t len)
+memcmp(s1,s2,len)
+ char *s1;
+ char *s2;
+ register int len;
{
register unsigned char *a = (unsigned char*)s1;
register unsigned char *b = (unsigned char*)s2;
register int tmp;
- for (; len; --len) {
+ while (len--) {
if (tmp = *a++ - *b++)
return tmp;
}
diff --git a/missing/memmove.c b/missing/memmove.c
index 19c5f18847..c9d67d8b45 100644
--- a/missing/memmove.c
+++ b/missing/memmove.c
@@ -1,21 +1,22 @@
/* public domain rewrite of memcmp(3) */
-#include <stddef.h>
-
void *
-memmove(void *d, const void *s, size_t n)
+memmove (d, s, n)
+ void *d, *s;
+ int n;
{
- char *dst = (char *)d;
- const char *src = (const char *)s;
+ char *dst = d;
+ char *src = s;
+ void *ret = dst;
if (src < dst) {
src += n;
dst += n;
- for (; n; --n)
+ while (n--)
*--dst = *--src;
}
else if (dst < src)
- for (; n; --n)
+ while (n--)
*dst++ = *src++;
- return d;
+ return ret;
}
diff --git a/missing/os2.c b/missing/os2.c
index 3448cdc281..fe7238aad1 100644
--- a/missing/os2.c
+++ b/missing/os2.c
@@ -17,36 +17,11 @@ chown(char *path, int owner, int group)
return 0;
}
-#if 0
int
link(char *from, char *to)
{
return -1;
}
-#endif
-
-#if defined(EMX_REPLACE_GETCWD) && (EMX_REPLACE_GETCWD) \
- || defined(EMX_REPLACE_CHDIR) && (EMX_REPLACE_CHDIR)
-#include <unistd.h>
-
-#if defined(EMX_REPLACE_GETCWD) && (EMX_REPLACE_GETCWD)
-/* to handle the drive letter and DBCS characters within a given path */
-char *
-getcwd(char *path, size_t len)
-{
- return _getcwd2(path, (int)len);
-}
-#endif
-
-#if defined(EMX_REPLACE_CHDIR) && (EMX_REPLACE_CHDIR)
-/* to handle the drive letter and DBCS characters within a given path */
-int
-chdir(__const__ char *path)
-{
- return _chdir2(path);
-}
-#endif
-#endif
typedef char* CHARP;
diff --git a/missing/strcasecmp.c b/missing/strcasecmp.c
index 1ce20704c1..fddb8385be 100644
--- a/missing/strcasecmp.c
+++ b/missing/strcasecmp.c
@@ -3,7 +3,8 @@
#include <ctype.h>
int
-strcasecmp(const char *p1, const char *p2)
+strcasecmp(p1, p2)
+ char *p1, *p2;
{
while (*p1 && *p2) {
if (toupper(*p1) != toupper(*p2))
diff --git a/missing/strchr.c b/missing/strchr.c
index bebd7ba578..886d70ede6 100644
--- a/missing/strchr.c
+++ b/missing/strchr.c
@@ -1,28 +1,32 @@
/* public domain rewrite of strchr(3) and strrchr(3) */
char *
-strchr(const char *s, int c)
+strchr(s, c)
+ char *s;
+ int c;
{
- if (c == 0) return (char *)s + strlen(s);
+ if (c == 0) return s + strlen(s);
while (*s) {
if (*s == c)
- return (char *)s;
+ return s;
s++;
}
return 0;
}
char *
-strrchr(const char *s, int c)
+strrchr(s, c)
+ char *s;
+ int c;
{
- const char *save;
+ char *save;
- if (c == 0) return (char *)s + strlen(s);
+ if (c == 0) return s + strlen(s);
save = 0;
while (*s) {
if (*s == c)
save = s;
s++;
}
- return (char *)save;
+ return save;
}
diff --git a/missing/strerror.c b/missing/strerror.c
index 023935a1ff..c1bf6feff8 100644
--- a/missing/strerror.c
+++ b/missing/strerror.c
@@ -6,7 +6,8 @@ extern char *sys_errlist[];
static char msg[50];
char *
-strerror(int error)
+strerror(error)
+ int error;
{
if (error <= sys_nerr && error > 0) {
return sys_errlist[error];
diff --git a/missing/strftime.c b/missing/strftime.c
index 5522226ec1..caa5eb8719 100644
--- a/missing/strftime.c
+++ b/missing/strftime.c
@@ -115,17 +115,22 @@ 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 char *tzname[2];
-extern int daylight;
-#ifdef SOLARIS
-extern long timezone, altzone;
-#else
-#ifdef __hpux
-extern long timezone;
-#else
-extern int timezone, altzone;
+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;
#endif
+#ifdef HAVE_VAR_ALTZONE
+extern DLL_IMPORT TYPEOF_VAR_ALTZONE altzone;
#endif
#endif
@@ -189,16 +194,8 @@ 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 */
@@ -422,21 +419,18 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
*/
off = timeptr->tm_gmtoff / 60;
#else /* !HAVE_TM_ZONE */
-#if HAVE_TZNAME
- /*
- * Systems with tzname[] probably have timezone as
- * secs west of GMT. Convert to mins east of GMT.
- */
-#ifdef __hpux
+#ifdef HAVE_GETTIMEOFDAY
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) {
@@ -445,7 +439,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
} else {
tbuf[0] = '+';
}
- sprintf(tbuf+1, "%02d%02d", off/60, off%60);
+ sprintf(tbuf+1, "%02u%02u", (unsigned)off/60, (unsigned)off%60);
break;
#endif /* MAILHEADER_EXT */
@@ -460,13 +454,15 @@ 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 __CYGWIN__
+#ifdef TIMEZONE_VOID
strcpy(tbuf, timezone());
#else
strcpy(tbuf, timezone(zone.tz_minuteswest,
timeptr->tm_isdst > 0));
-#endif
+#endif /* TIMEZONE_VOID */
+#endif /* HAVE_TIMEZONE */
#endif /* HAVE_TM_NAME */
#endif /* HAVE_TM_ZONE */
#endif /* HAVE_TZNAME */
@@ -645,7 +641,7 @@ iso8601wknum(const struct tm *timeptr)
* main body of the standard. Thus it requires week 53.
*/
- int weeknum, jan1day, diff;
+ int weeknum, jan1day;
/* get week number, Monday as first day of the week */
weeknum = weeknumber(timeptr, 1);
diff --git a/missing/strncasecmp.c b/missing/strncasecmp.c
index 59d4477a40..a4cc5828b8 100644
--- a/missing/strncasecmp.c
+++ b/missing/strncasecmp.c
@@ -1,10 +1,12 @@
/* public domain rewrite of strncasecmp(3) */
#include <ctype.h>
-#include <stddef.h>
int
-strncasecmp(const char *p1, const char *p2, size_t len)
+strncasecmp(p1, p2, len)
+ char *p1;
+ char *p2;
+ int len;
{
while (len != 0) {
if (toupper(*p1) != toupper(*p2)) {
diff --git a/missing/strstr.c b/missing/strstr.c
index 2e9c282fb1..1673518f06 100644
--- a/missing/strstr.c
+++ b/missing/strstr.c
@@ -1,19 +1,20 @@
/* public domain rewrite of strstr(3) */
char *
-strstr(const char *haystack, const char *needle)
+strstr(haystack, needle)
+ char *haystack, *needle;
{
- const char *hend;
- const char *a, *b;
+ char *hend;
+ char *a, *b;
- if (*needle == 0) return (char *)haystack;
+ if (*needle == 0) return haystack;
hend = haystack + strlen(haystack) - strlen(needle) + 1;
while (haystack < hend) {
if (*haystack == *needle) {
a = haystack;
b = needle;
for (;;) {
- if (*b == 0) return (char *)haystack;
+ if (*b == 0) return haystack;
if (*a++ != *b++) {
break;
}
diff --git a/missing/strtol.c b/missing/strtol.c
index da6636f316..e94aa54ca0 100644
--- a/missing/strtol.c
+++ b/missing/strtol.c
@@ -3,10 +3,13 @@
#include <ctype.h>
long
-strtol(const char *nptr, char **endptr, int base)
+strtol(nptr, endptr, base)
+ char *nptr;
+ char **endptr;
+ int base;
{
long result;
- const char *p = nptr;
+ char *p = nptr;
while (isspace(*p)) {
p++;
@@ -20,7 +23,7 @@ strtol(const char *nptr, char **endptr, int base)
result = strtoul(p, endptr, base);
}
if (endptr != 0 && *endptr == p) {
- *endptr = (char *)nptr;
+ *endptr = nptr;
}
return result;
}
diff --git a/missing/strtoul.c b/missing/strtoul.c
index 4f09f899a1..f16f2ad9cf 100644
--- a/missing/strtoul.c
+++ b/missing/strtoul.c
@@ -21,7 +21,7 @@
* (100 for non-digit characters).
*/
-static const char cvtIn[] = {
+static char cvtIn[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* '0' - '9' */
100, 100, 100, 100, 100, 100, 100, /* punctuation */
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, /* 'A' - 'Z' */
@@ -53,22 +53,22 @@ static const char cvtIn[] = {
*/
unsigned long int
-strtoul(
- const char *string, /* String of ASCII digits, possibly
+strtoul(string, endPtr, base)
+ char *string; /* String of ASCII digits, possibly
* preceded by white space. For bases
* greater than 10, either lower- or
* upper-case digits may be used.
*/
- char **endPtr, /* Where to store address of terminating
+ char **endPtr; /* Where to store address of terminating
* character, or NULL. */
- int base) /* Base for conversion. Must be less
+ int base; /* Base for conversion. Must be less
* than 37. If 0, then the base is chosen
* from the leading characters of string:
* "0x" means hex, "0" means octal, anything
* else means decimal.
*/
{
- register const char *p;
+ register char *p;
register unsigned long int result = 0;
register unsigned digit;
int anyDigits = 0;
@@ -177,7 +177,7 @@ strtoul(
}
if (endPtr != 0) {
- *endPtr = (char *)p;
+ *endPtr = p;
}
return result;
diff --git a/missing/vsnprintf.c b/missing/vsnprintf.c
index 3c8b76686a..6afdfa189f 100644
--- a/missing/vsnprintf.c
+++ b/missing/vsnprintf.c
@@ -65,14 +65,8 @@
#define u_short unsigned short
#define u_int unsigned int
-#if !defined(HAVE_STDARG_PROTOTYPES)
-#if defined(__STDC__)
-#define HAVE_STDARG_PROTOTYPES 1
-#endif
-#endif
-
#undef __P
-#if defined(HAVE_STDARG_PROTOTYPES)
+#if defined(__STDC__)
# include <stdarg.h>
# if !defined(__P)
# define __P(x) x
@@ -111,13 +105,6 @@
#endif /* People who don't like const sys_error */
#include <stddef.h>
-#if defined(__hpux) && !defined(__GNUC__) || defined(__DECC)
-#include <string.h>
-#endif
-
-#if !defined(__CYGWIN32__) && defined(__hpux) && !defined(__GNUC__)
-#include <stdlib.h>
-#endif
#ifndef NULL
#define NULL 0
@@ -164,15 +151,12 @@ struct __sbuf {
*/
typedef struct __sFILE {
unsigned char *_p; /* current position in (some) buffer */
-#if 0
int _r; /* read space left for getc() */
-#endif
int _w; /* write space left for putc() */
short _flags; /* flags, below; this FILE is free if 0 */
short _file; /* fileno, if Unix descriptor, else -1 */
struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
int _lbfsize; /* 0 or -_bf._size, for inline putc */
- int (*vwrite)(/* struct __sFILE*, struct __suio * */);
} FILE;
@@ -201,9 +185,6 @@ typedef struct __sFILE {
#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
#define __sfileno(p) ((p)->_file)
-#undef feof
-#undef ferror
-#undef clearerr
#define feof(p) __sfeof(p)
#define ferror(p) __sferror(p)
#define clearerr(p) __sclearerr(p)
@@ -213,6 +194,10 @@ typedef struct __sFILE {
#endif
+#if defined(__hpux) && !defined(__GNUC__) || defined(__DECC)
+#include <string.h>
+#endif
+
/*
* I/O descriptors for __sfvwrite().
*/
@@ -226,14 +211,13 @@ struct __suio {
int uio_resid;
};
-#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_SNPRINTF)
/*
* Write some memory regions. Return zero on success, EOF on error.
*
* This routine is large and unsightly, but most of the ugliness due
* to the three different kinds of output buffering is handled here.
*/
-static int BSD__sfvwrite(fp, uio)
+static BSD__sfvwrite(fp, uio)
register FILE *fp;
register struct __suio *uio;
{
@@ -300,8 +284,11 @@ static int BSD__sfvwrite(fp, uio)
*/
}
return (0);
+
+err:
+ fp->_flags |= __SERR;
+ return (EOF);
}
-#endif
/*
* Actual printf innards.
@@ -309,12 +296,18 @@ static int BSD__sfvwrite(fp, uio)
* This code is large and complicated...
*/
+#if !defined(__CYGWIN32__) && defined(__hpux) && !defined(__GNUC__)
+#include <stdlib.h>
+#endif
+
/*
* Flush out all the vectors defined by the given uio,
* then reset it so that it can be reused.
*/
static int
-BSD__sprint(FILE *fp, register struct __suio *uio)
+BSD__sprint(fp, uio)
+ FILE *fp;
+ register struct __suio *uio;
{
register int err;
@@ -322,7 +315,7 @@ BSD__sprint(FILE *fp, register struct __suio *uio)
uio->uio_iovcnt = 0;
return (0);
}
- err = (*fp->vwrite)(fp, uio);
+ err = BSD__sfvwrite(fp, uio);
uio->uio_resid = 0;
uio->uio_iovcnt = 0;
return (err);
@@ -335,7 +328,10 @@ BSD__sprint(FILE *fp, register struct __suio *uio)
* worries about ungetc buffers and so forth.
*/
static int
-BSD__sbprintf(register FILE *fp, const char *fmt, va_list ap)
+BSD__sbprintf(fp, fmt, ap)
+ register FILE *fp;
+ const char *fmt;
+ va_list ap;
{
/* We don't support files. */
return 0;
@@ -349,72 +345,6 @@ BSD__sbprintf(register FILE *fp, const char *fmt, va_list ap)
#define is_digit(c) ((unsigned)to_digit(c) <= 9)
#define to_char(n) ((n) + '0')
-#ifdef _HAVE_SANE_QUAD_
-/*
- * Convert an unsigned long long to ASCII for printf purposes, returning
- * a pointer to the first character of the string representation.
- * Octal numbers can be forced to have a leading zero; hex numbers
- * use the given digits.
- */
-static char *
-BSD__uqtoa(register u_quad_t val, char *endp, int base, int octzero, char *xdigs)
-{
- register char *cp = endp;
- register long sval;
-
- /*
- * Handle the three cases separately, in the hope of getting
- * better/faster code.
- */
- switch (base) {
- case 10:
- if (val < 10) { /* many numbers are 1 digit */
- *--cp = to_char(val);
- return (cp);
- }
- /*
- * On many machines, unsigned arithmetic is harder than
- * signed arithmetic, so we do at most one unsigned mod and
- * divide; this is sufficient to reduce the range of
- * the incoming value to where signed arithmetic works.
- */
- if (val > LLONG_MAX) {
- *--cp = to_char(val % 10);
- sval = val / 10;
- } else
- sval = val;
- do {
- *--cp = to_char(sval % 10);
- sval /= 10;
- } while (sval != 0);
- break;
-
- case 8:
- do {
- *--cp = to_char(val & 7);
- val >>= 3;
- } while (val);
- if (octzero && *cp != '0')
- *--cp = '0';
- break;
-
- case 16:
- do {
- *--cp = xdigs[val & 15];
- val >>= 4;
- } while (val);
- break;
-
- default: /* oops */
- /*
- abort();
- */
- break; /* fjc 7-31-97. Don't reference abort() here */
- }
- return (cp);
-}
-#endif /* _HAVE_SANE_QUAD_ */
-
/*
* Convert an unsigned long to ASCII for printf purposes, returning
* a pointer to the first character of the string representation.
@@ -422,7 +352,11 @@ BSD__uqtoa(register u_quad_t val, char *endp, int base, int octzero, char *xdigs
* use the given digits.
*/
static char *
-BSD__ultoa(register u_long val, char *endp, int base, int octzero, char *xdigs)
+BSD__ultoa(val, endp, base, octzero, xdigs)
+ register u_long val;
+ char *endp;
+ int base, octzero;
+ char *xdigs;
{
register char *cp = endp;
register long sval;
@@ -521,7 +455,10 @@ static int exponent __P((char *, int, int));
#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
#define FPT 0x100 /* Floating point number */
static int
-BSD_vfprintf(FILE *fp, const char *fmt0, va_list ap)
+BSD_vfprintf(fp, fmt0, ap)
+ FILE *fp;
+ const char *fmt0;
+ va_list ap;
{
register char *fmt; /* format string */
register int ch; /* character from fmt */
@@ -736,9 +673,10 @@ reswitch: switch (ch) {
uqval = -uqval;
sign = '-';
}
- } else
-#endif /* _HAVE_SANE_QUAD_ */
+ } else {
+#else /* _HAVE_SANE_QUAD_ */
{
+#endif /* _HAVE_SANE_QUAD_ */
ulval = SARG();
if ((long)ulval < 0) {
ulval = -ulval;
@@ -843,7 +781,6 @@ fp_begin: _double = va_arg(ap, double);
* defined manner.''
* -- ANSI X3J11
*/
- prec = sizeof(void*)*CHAR_BIT/4;
#ifdef _HAVE_LLP64_
uqval = (u_long)va_arg(ap, void *);
flags = (flags) | QUADINT | HEXPREFIX;
@@ -933,7 +870,7 @@ number: if ((dprec = prec) >= 0)
#ifdef _HAVE_SANE_QUAD_
if (flags & QUADINT) {
if (uqval != 0 || prec != 0)
- cp = BSD__uqtoa(uqval, cp, base,
+ cp = __uqtoa(uqval, cp, base,
flags & ALT, xdigs);
} else {
#else /* _HAVE_SANE_QUAD_ */
@@ -1136,7 +1073,6 @@ exponent(p0, exp, fmtch)
}
#endif /* FLOATING_POINT */
-#ifndef HAVE_VSNPRINTF
int
vsnprintf(str, n, fmt, ap)
char *str;
@@ -1152,20 +1088,23 @@ vsnprintf(str, n, fmt, ap)
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n - 1;
- f.vwrite = BSD__sfvwrite;
ret = BSD_vfprintf(&f, fmt, ap);
*f._p = 0;
return (ret);
}
-#endif
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#ifndef HAVE_SNPRINTF
+#if defined(__STDC__)
+# include <stdarg.h>
+#else
+# include <varargs.h>
+#endif
+
int
-#if defined(HAVE_STDARG_PROTOTYPES)
+#if defined(__STDC__)
snprintf(char *str, size_t n, char const *fmt, ...)
#else
snprintf(str, n, fmt, va_alist)
@@ -1181,7 +1120,7 @@ va_dcl
if ((int)n < 1)
return (EOF);
-#if defined(HAVE_STDARG_PROTOTYPES)
+#if defined(__STDC__)
va_start(ap, fmt);
#else
va_start(ap);
@@ -1189,10 +1128,8 @@ va_dcl
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n - 1;
- f.vwrite = BSD__sfvwrite;
ret = BSD_vfprintf(&f, fmt, ap);
*f._p = 0;
va_end(ap);
return (ret);
}
-#endif
diff --git a/mkconfig.rb b/mkconfig.rb
index 9cbffa4a89..bffefdad14 100644..100755
--- a/mkconfig.rb
+++ b/mkconfig.rb
@@ -26,7 +26,7 @@ print %[
# This file was created by #{mkconfig} when ruby was built. Any
# changes made to this file will be lost the next time ruby is built.
-module RbConfig
+module Config
RUBY_VERSION == "#{version}" or
raise "ruby lib version (#{version}) doesn't match executable version (\#{RUBY_VERSION})"
@@ -36,12 +36,39 @@ v_fast = []
v_others = []
vars = {}
has_version = false
+continued_name = nil
+continued_line = nil
File.foreach "config.status" do |line|
next if /^#/ =~ line
- if /^s([%,])@(\w+)@\1(?:\|\#_!!_\#\|)?(.*)\1/ =~ line
+ name = nil
+ case line
+ when /^s([%,])@(\w+)@\1(?:\|\#_!!_\#\|)?(.*)\1/
name = $2
val = $3.gsub(/\\(?=,)/, '')
- next if /^(?:ac_.*|DEFS|configure_input|(?:top_)?srcdir|\w+OBJS)$/ =~ name
+ when /^S\["(\w+)"\]\s*=\s*"(.*)"\s*(\\)?$/
+ name = $1
+ val = $2
+ if $3
+ continued_line = []
+ continued_line << val
+ continued_name = name
+ next
+ end
+ when /^"(.+)"\s*(\\)?$/
+ if continued_line
+ continued_line << $1
+ unless $2
+ val = continued_line.join("")
+ name = continued_name
+ continued_line = nil
+ end
+ end
+ when /^(?:ac_given_)?INSTALL=(.*)/
+ v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n"
+ end
+
+ if name
+ next if /^(?:ac_.*|configure_input|(?:top_)?srcdir|\w+OBJS)$/ =~ name
next if /^\$\(ac_\w+\)$/ =~ val
next if /^\$\{ac_\w+\}$/ =~ val
next if /^\$ac_\w+$/ =~ val
@@ -67,8 +94,6 @@ File.foreach "config.status" do |line|
v_others << v
end
has_version = true if name == "MAJOR"
- elsif /^(?:ac_given_)?INSTALL=(.*)/ =~ line
- v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n"
end
# break if /^CEOF/
end
@@ -87,6 +112,10 @@ unless has_version
print " CONFIG[\"MINOR\"] = \"" + $2 + "\"\n"
print " CONFIG[\"TEENY\"] = \"" + $3 + "\"\n"
}
+ patchlevel = IO.foreach(File.join(srcdir, "version.h")) {|l|
+ m = /^\s*#\s*define\s+RUBY_PATCHLEVEL\s+(\d+)/.match(l) and break m[1]
+ }
+ print " CONFIG[\"PATCHLEVEL\"] = \"#{patchlevel}\"\n"
end
dest = drive ? /= \"(?!\$[\(\{])(?:[a-z]:)?/i : /= \"(?!\$[\(\{])/
@@ -117,14 +146,14 @@ print <<EOS
CONFIG["topdir"] = File.dirname(__FILE__)
MAKEFILE_CONFIG = {}
CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
- def RbConfig::expand(val, config = CONFIG)
+ def Config::expand(val, config = CONFIG)
val.gsub!(/\\$\\$|\\$\\(([^()]+)\\)|\\$\\{([^{}]+)\\}/) do |var|
if !(v = $1 || $2)
'$'
elsif key = config[v = v[/\\A[^:]+(?=(?::(.*?)=(.*))?\\z)/]]
pat, sub = $1, $2
config[v] = false
- RbConfig::expand(key, config)
+ Config::expand(key, config)
config[v] = key
key = key.gsub(/\#{Regexp.quote(pat)}(?=\\s|\\z)/n) {sub} if pat
key
@@ -135,10 +164,10 @@ print <<EOS
val
end
CONFIG.each_value do |val|
- RbConfig::expand(val)
+ Config::expand(val)
end
end
-Config = RbConfig # compatibility for ruby-1.8.4 and older.
+RbConfig = Config # compatibility for ruby-1.9
CROSS_COMPILING = nil unless defined? CROSS_COMPILING
EOS
diff --git a/node.h b/node.h
index ddca63ab21..7d3f756e30 100644
--- a/node.h
+++ b/node.h
@@ -62,7 +62,6 @@ enum node_type {
NODE_ZSUPER,
NODE_ARRAY,
NODE_ZARRAY,
- NODE_VALUES,
NODE_HASH,
NODE_RETURN,
NODE_YIELD,
@@ -86,11 +85,11 @@ enum node_type {
NODE_DREGX,
NODE_DREGX_ONCE,
NODE_ARGS,
- NODE_POSTARG,
NODE_ARGSCAT,
NODE_ARGSPUSH,
NODE_SPLAT,
NODE_TO_ARY,
+ NODE_SVALUE,
NODE_BLOCK_ARG,
NODE_BLOCK_PASS,
NODE_DEFN,
@@ -113,17 +112,16 @@ enum node_type {
NODE_NIL,
NODE_TRUE,
NODE_FALSE,
- NODE_ERRINFO,
NODE_DEFINED,
+ NODE_NEWLINE,
NODE_POSTEXE,
NODE_ALLOCA,
+ NODE_DMETHOD,
NODE_BMETHOD,
NODE_MEMO,
NODE_IFUNC,
NODE_DSYM,
NODE_ATTRASGN,
- NODE_PRELUDE,
- NODE_LAMBDA,
NODE_LAST
};
@@ -158,18 +156,12 @@ extern NODE *ruby_top_cref;
#define RNODE(obj) (R_CAST(RNode)(obj))
-/* 0..4:T_TYPES, 5:FL_MARK, 6:reserved, 7:NODE_NEWLINE */
-#define NODE_NEWLINE (1<<7)
-
-#define NODE_TYPESHIFT 8
-#define NODE_TYPEMASK (0x7f<<NODE_TYPESHIFT)
-
-#define nd_type(n) ((int) (((RNODE(n))->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
+#define nd_type(n) ((int)(((RNODE(n))->flags>>FL_USHIFT)&0xff))
#define nd_set_type(n,t) \
- RNODE(n)->flags=((RNODE(n)->flags&~NODE_TYPEMASK)|(((t)<<NODE_TYPESHIFT)&NODE_TYPEMASK))
+ RNODE(n)->flags=((RNODE(n)->flags&~FL_UMASK)|(((t)<<FL_USHIFT)&FL_UMASK))
-#define NODE_LSHIFT (NODE_TYPESHIFT+7)
-#define NODE_LMASK (((VALUE)1<<(sizeof(NODE*)*CHAR_BIT-NODE_LSHIFT))-1)
+#define NODE_LSHIFT (FL_USHIFT+8)
+#define NODE_LMASK (((long)1<<(sizeof(NODE*)*CHAR_BIT-NODE_LSHIFT))-1)
#define nd_line(n) ((unsigned int)(((RNODE(n))->flags>>NODE_LSHIFT)&NODE_LMASK))
#define nd_set_line(n,l) \
RNODE(n)->flags=((RNODE(n)->flags&~(-1<<NODE_LSHIFT))|(((l)&NODE_LMASK)<<NODE_LSHIFT))
@@ -209,7 +201,7 @@ extern NODE *ruby_top_cref;
#define nd_lit u1.value
-#define nd_frml u3.value
+#define nd_frml u1.node
#define nd_rest u2.node
#define nd_opt u1.node
@@ -228,7 +220,6 @@ extern NODE *ruby_top_cref;
#define nd_modl u1.id
#define nd_clss u1.value
-#define nd_vis u2.argc
#define nd_beg u1.node
#define nd_end u2.node
@@ -260,7 +251,6 @@ extern NODE *ruby_top_cref;
#define NEW_UNTIL(c,b,n) NEW_NODE(NODE_UNTIL,c,b,n)
#define NEW_FOR(v,i,b) NEW_NODE(NODE_FOR,v,b,i)
#define NEW_ITER(v,i,b) NEW_NODE(NODE_ITER,v,b,i)
-#define NEW_LAMBDA(a,b) NEW_NODE(NODE_LAMBDA,a,b,0)
#define NEW_BREAK(s) NEW_NODE(NODE_BREAK,s,0,0)
#define NEW_NEXT(s) NEW_NODE(NODE_NEXT,s,0,0)
#define NEW_REDO() NEW_NODE(NODE_REDO,0,0,0)
@@ -314,11 +304,11 @@ extern NODE *ruby_top_cref;
#define NEW_SUPER(a) NEW_NODE(NODE_SUPER,0,0,a)
#define NEW_ZSUPER() NEW_NODE(NODE_ZSUPER,0,0,0)
#define NEW_ARGS(f,o,r) NEW_NODE(NODE_ARGS,o,r,f)
-#define NEW_POSTARG(r,m) NEW_NODE(NODE_POSTARG,m,0,r)
#define NEW_ARGSCAT(a,b) NEW_NODE(NODE_ARGSCAT,a,b,0)
#define NEW_ARGSPUSH(a,b) NEW_NODE(NODE_ARGSPUSH,a,b,0)
#define NEW_SPLAT(a) NEW_NODE(NODE_SPLAT,a,0,0)
#define NEW_TO_ARY(a) NEW_NODE(NODE_TO_ARY,a,0,0)
+#define NEW_SVALUE(a) NEW_NODE(NODE_SVALUE,a,0,0)
#define NEW_BLOCK_ARG(v) NEW_NODE(NODE_BLOCK_ARG,v,0,local_cnt(v))
#define NEW_BLOCK_PASS(b) NEW_NODE(NODE_BLOCK_PASS,0,b,0)
#define NEW_ALIAS(n,o) NEW_NODE(NODE_ALIAS,n,o,0)
@@ -329,6 +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) (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)
@@ -336,45 +327,35 @@ extern NODE *ruby_top_cref;
#define NEW_NIL() NEW_NODE(NODE_NIL,0,0,0)
#define NEW_TRUE() NEW_NODE(NODE_TRUE,0,0,0)
#define NEW_FALSE() NEW_NODE(NODE_FALSE,0,0,0)
-#define NEW_ERRINFO() NEW_NODE(NODE_ERRINFO,0,0,0)
#define NEW_DEFINED(e) NEW_NODE(NODE_DEFINED,e,0,0)
+#define NEW_NEWLINE(n) NEW_NODE(NODE_NEWLINE,0,0,n)
#define NEW_PREEXE(b) NEW_SCOPE(b)
-#define NEW_POSTEXE(b) NEW_NODE(NODE_POSTEXE,0,b,0)
+#define NEW_POSTEXE() NEW_NODE(NODE_POSTEXE,0,0,0)
+#define NEW_DMETHOD(b) NEW_NODE(NODE_DMETHOD,0,0,b)
#define NEW_BMETHOD(b) NEW_NODE(NODE_BMETHOD,0,0,b)
#define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
-#define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0)
#define NOEX_PUBLIC 0
#define NOEX_NOSUPER 1
#define NOEX_PRIVATE 2
-#define NOEX_PROTECTED 4
-#define NOEX_LOCAL 8
-#define NOEX_MASK 14
+#define NOEX_PROTECTED 4
+#define NOEX_MASK 6
#define NOEX_UNDEF NOEX_NOSUPER
-#define NOEX_RECV 16
-
-VALUE rb_parser_new(void);
-VALUE rb_parser_end_seen_p(VALUE);
-NODE *rb_parser_compile_cstr(VALUE, const char*, const char*, int, int);
-NODE *rb_parser_compile_string(VALUE, const char*, VALUE, int);
-NODE *rb_parser_compile_file(VALUE, const char*, VALUE, int);
+NODE *rb_compile_cstr _((const char*, const char*, int, int));
+NODE *rb_compile_string _((const char*, VALUE, int));
+NODE *rb_compile_file _((const char*, VALUE, int));
-NODE *rb_compile_cstr(const char*, const char*, int, int);
-NODE *rb_compile_string(const char*, VALUE, int);
-NODE *rb_compile_file(const char*, VALUE, int);
+void rb_add_method _((VALUE, ID, NODE *, int));
+NODE *rb_node_newnode _((enum node_type,VALUE,VALUE,VALUE));
-void rb_add_method(VALUE, ID, NODE *, int);
-NODE *rb_node_newnode(enum node_type,VALUE,VALUE,VALUE);
+NODE* rb_method_node _((VALUE klass, ID id));
-NODE* rb_method_node(VALUE klass, ID id);
-int rb_node_arity(NODE* node);
-
-struct global_entry *rb_global_entry(ID);
-VALUE rb_gvar_get(struct global_entry *);
-VALUE rb_gvar_set(struct global_entry *, VALUE);
-VALUE rb_gvar_defined(struct global_entry *);
+struct global_entry *rb_global_entry _((ID));
+VALUE rb_gvar_get _((struct global_entry *));
+VALUE rb_gvar_set _((struct global_entry *, VALUE));
+VALUE rb_gvar_defined _((struct global_entry *));
typedef unsigned int rb_event_t;
@@ -389,9 +370,10 @@ typedef unsigned int rb_event_t;
#define RUBY_EVENT_RAISE 0x80
#define RUBY_EVENT_ALL 0xff
-typedef void (*rb_event_hook_func_t)(rb_event_t,NODE*,VALUE,ID,VALUE);
-void rb_add_event_hook(rb_event_hook_func_t,rb_event_t);
-int rb_remove_event_hook(rb_event_hook_func_t);
+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));
#if defined(HAVE_GETCONTEXT) && defined(HAVE_SETCONTEXT)
#include <ucontext.h>
@@ -409,17 +391,17 @@ typedef struct {
typedef jmp_buf rb_jmpbuf_t;
#endif
-enum thread_status {
+enum rb_thread_status {
THREAD_TO_KILL,
THREAD_RUNNABLE,
THREAD_STOPPED,
THREAD_KILLED,
};
-typedef struct thread * rb_thread_t;
+typedef struct rb_thread *rb_thread_t;
-struct thread {
- struct thread *next, *prev;
+struct rb_thread {
+ rb_thread_t next, prev;
rb_jmpbuf_t context;
#if (defined _WIN32 && !defined _WIN32_WCE) || defined __CYGWIN__
unsigned long win32_exception_list;
@@ -444,11 +426,11 @@ struct thread {
struct BLOCK *block;
struct iter *iter;
struct tag *tag;
+ VALUE klass;
VALUE wrapper;
NODE *cref;
- struct ruby_env *anchor;
- int flags; /* misc. states (rb_trap_immediate/raised) */
+ int flags; /* misc. states (vmode/rb_trap_immediate/raised) */
NODE *node;
@@ -460,12 +442,12 @@ struct thread {
int safe;
- enum thread_status status;
+ enum rb_thread_status status;
int wait_for;
int fd;
- rb_fdset_t readfds;
- rb_fdset_t writefds;
- rb_fdset_t exceptfds;
+ fd_set readfds;
+ fd_set writefds;
+ fd_set exceptfds;
int select_value;
double delay;
rb_thread_t join;
@@ -474,17 +456,30 @@ struct thread {
int priority;
VALUE thgroup;
- st_table *locals;
+ struct st_table *locals;
VALUE thread;
VALUE sandbox;
};
-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;
+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) ((th)->flags = 0)
#if defined(__cplusplus)
} /* extern "C" { */
diff --git a/numeric.c b/numeric.c
index e812389c38..21a4f2af4c 100644
--- a/numeric.c
+++ b/numeric.c
@@ -63,6 +63,25 @@
#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;
@@ -74,7 +93,7 @@ VALUE rb_eZeroDivError;
VALUE rb_eFloatDomainError;
void
-rb_num_zerodiv(void)
+rb_num_zerodiv()
{
rb_raise(rb_eZeroDivError, "divided by 0");
}
@@ -97,34 +116,41 @@ rb_num_zerodiv(void)
*/
static VALUE
-num_coerce(VALUE x, VALUE y)
+num_coerce(x, y)
+ VALUE x, y;
{
if (CLASS_OF(x) == CLASS_OF(y))
return rb_assoc_new(y, x);
- return rb_assoc_new(rb_Float(y), rb_Float(x));
+ x = rb_Float(x);
+ y = rb_Float(y);
+ return rb_assoc_new(y, x);
}
static VALUE
-coerce_body(VALUE *x)
+coerce_body(x)
+ VALUE *x;
{
return rb_funcall(x[1], id_coerce, 1, x[0]);
}
static VALUE
-coerce_rescue(VALUE *x)
+coerce_rescue(x)
+ VALUE *x;
{
volatile VALUE v = rb_inspect(x[1]);
rb_raise(rb_eTypeError, "%s can't be coerced into %s",
rb_special_const_p(x[1])?
- RSTRING_PTR(v):
+ RSTRING(v)->ptr:
rb_obj_classname(x[1]),
rb_obj_classname(x[0]));
return Qnil; /* dummy */
}
static int
-do_coerce(VALUE *x, VALUE *y, int err)
+do_coerce(x, y, err)
+ VALUE *x, *y;
+ int err;
{
VALUE ary;
VALUE a[2];
@@ -132,40 +158,43 @@ do_coerce(VALUE *x, VALUE *y, int err)
a[0] = *x; a[1] = *y;
ary = rb_rescue(coerce_body, (VALUE)a, err?coerce_rescue:0, (VALUE)a);
- if (TYPE(ary) != T_ARRAY || RARRAY_LEN(ary) != 2) {
+ if (TYPE(ary) != T_ARRAY || RARRAY(ary)->len != 2) {
if (err) {
rb_raise(rb_eTypeError, "coerce must return [x, y]");
}
return Qfalse;
}
- *x = RARRAY_PTR(ary)[0];
- *y = RARRAY_PTR(ary)[1];
+ *x = RARRAY(ary)->ptr[0];
+ *y = RARRAY(ary)->ptr[1];
return Qtrue;
}
VALUE
-rb_num_coerce_bin(VALUE x, VALUE y)
+rb_num_coerce_bin(x, y)
+ VALUE x, y;
{
do_coerce(&x, &y, Qtrue);
- return rb_funcall(x, rb_frame_this_func(), 1, y);
+ return rb_funcall(x, ruby_frame->orig_func, 1, y);
}
VALUE
-rb_num_coerce_cmp(VALUE x, VALUE y)
+rb_num_coerce_cmp(x, y)
+ VALUE x, y;
{
if (do_coerce(&x, &y, Qfalse))
- return rb_funcall(x, rb_frame_this_func(), 1, y);
+ return rb_funcall(x, ruby_frame->orig_func, 1, y);
return Qnil;
}
VALUE
-rb_num_coerce_relop(VALUE x, VALUE y)
+rb_num_coerce_relop(x, y)
+ VALUE x, y;
{
VALUE c, x0 = x, y0 = y;
if (!do_coerce(&x, &y, Qfalse) ||
- NIL_P(c = rb_funcall(x, rb_frame_this_func(), 1, y))) {
+ NIL_P(c = rb_funcall(x, ruby_frame->orig_func, 1, y))) {
rb_cmperr(x0, y0);
return Qnil; /* not reached */
}
@@ -178,7 +207,8 @@ rb_num_coerce_relop(VALUE x, VALUE y)
*/
static VALUE
-num_sadded(VALUE x, VALUE name)
+num_sadded(x, name)
+ VALUE x, name;
{
ruby_frame = ruby_frame->prev; /* pop frame for "singleton_method_added" */
/* Numerics should be values; singleton_methods should not be added to them */
@@ -191,7 +221,8 @@ num_sadded(VALUE x, VALUE name)
/* :nodoc: */
static VALUE
-num_init_copy(VALUE x, VALUE y)
+num_init_copy(x, y)
+ VALUE x, y;
{
/* Numerics are immutable values, which should not be copied */
rb_raise(rb_eTypeError, "can't copy %s", rb_obj_classname(x));
@@ -206,7 +237,8 @@ num_init_copy(VALUE x, VALUE y)
*/
static VALUE
-num_uplus(VALUE num)
+num_uplus(num)
+ VALUE num;
{
return num;
}
@@ -219,7 +251,8 @@ num_uplus(VALUE num)
*/
static VALUE
-num_uminus(VALUE num)
+num_uminus(num)
+ VALUE num;
{
VALUE zero;
@@ -237,7 +270,8 @@ num_uminus(VALUE num)
*/
static VALUE
-num_quo(VALUE x, VALUE y)
+num_quo(x, y)
+ VALUE x, y;
{
return rb_funcall(x, '/', 1, y);
}
@@ -255,12 +289,14 @@ static VALUE num_floor(VALUE num);
*/
static VALUE
-num_div(VALUE x, VALUE y)
+num_div(x, y)
+ VALUE x, y;
{
return num_floor(rb_funcall(x, '/', 1, y));
}
+
/*
* call-seq:
* num.divmod( aNumeric ) -> anArray
@@ -290,7 +326,7 @@ num_div(VALUE x, VALUE y)
* ------+-----+---------------+---------+-------------+---------------
* -11.5 | 4 | -3, 0.5 | -2.875 | 0.5 | -3.5
* ------+-----+---------------+---------+-------------+---------------
- * -11.5 | -4 | 2, -3.5 | 2.875 | -3.5 | -3.5
+ * -11.5 | -4 | 2 -3.5 | 2.875 | -3.5 | -3.5
*
*
* Examples
@@ -302,7 +338,8 @@ num_div(VALUE x, VALUE y)
*/
static VALUE
-num_divmod(VALUE x, VALUE y)
+num_divmod(x, y)
+ VALUE x, y;
{
return rb_assoc_new(num_div(x, y), rb_funcall(x, '%', 1, y));
}
@@ -316,7 +353,8 @@ num_divmod(VALUE x, VALUE y)
*/
static VALUE
-num_modulo(VALUE x, VALUE y)
+num_modulo(x, y)
+ VALUE x, y;
{
return rb_funcall(x, '%', 1, y);
}
@@ -334,7 +372,8 @@ num_modulo(VALUE x, VALUE y)
*/
static VALUE
-num_remainder(VALUE x, VALUE y)
+num_remainder(x, y)
+ VALUE x, y;
{
VALUE z = rb_funcall(x, '%', 1, y);
@@ -350,20 +389,6 @@ num_remainder(VALUE x, VALUE y)
/*
* call-seq:
- * num.scalar? -> true or false
- *
- * Returns <code>true</code> if <i>num</i> is an <code>Scalar</code>
- * (i.e. non <code>Complex</code>).
- */
-
-static VALUE
-num_scalar_p(VALUE num)
-{
- return Qtrue;
-}
-
-/*
- * call-seq:
* num.integer? -> true or false
*
* Returns <code>true</code> if <i>num</i> is an <code>Integer</code>
@@ -371,7 +396,8 @@ num_scalar_p(VALUE num)
*/
static VALUE
-num_int_p(VALUE num)
+num_int_p(num)
+ VALUE num;
{
return Qfalse;
}
@@ -388,7 +414,8 @@ num_int_p(VALUE num)
*/
static VALUE
-num_abs(VALUE num)
+num_abs(num)
+ VALUE num;
{
if (RTEST(rb_funcall(num, '<', 1, INT2FIX(0)))) {
return rb_funcall(num, rb_intern("-@"), 0);
@@ -405,7 +432,8 @@ num_abs(VALUE num)
*/
static VALUE
-num_zero_p(VALUE num)
+num_zero_p(num)
+ VALUE num;
{
if (rb_equal(num, INT2FIX(0))) {
return Qtrue;
@@ -427,7 +455,8 @@ num_zero_p(VALUE num)
*/
static VALUE
-num_nonzero_p(VALUE num)
+num_nonzero_p(num)
+ VALUE num;
{
if (RTEST(rb_funcall(num, rb_intern("zero?"), 0, 0))) {
return Qnil;
@@ -444,7 +473,8 @@ num_nonzero_p(VALUE num)
*/
static VALUE
-num_to_int(VALUE num)
+num_to_int(num)
+ VALUE num;
{
return rb_funcall(num, id_to_i, 0, 0);
}
@@ -459,7 +489,8 @@ num_to_int(VALUE num)
*/
VALUE
-rb_float_new(double d)
+rb_float_new(d)
+ double d;
{
NEWOBJ(flt, struct RFloat);
OBJSETUP(flt, rb_cFloat, T_FLOAT);
@@ -479,7 +510,8 @@ rb_float_new(double d)
*/
static VALUE
-flo_to_s(VALUE flt)
+flo_to_s(flt)
+ VALUE flt;
{
char buf[32];
double value = RFLOAT(flt)->value;
@@ -512,7 +544,8 @@ flo_to_s(VALUE flt)
*/
static VALUE
-flo_coerce(VALUE x, VALUE y)
+flo_coerce(x, y)
+ VALUE x, y;
{
return rb_assoc_new(rb_Float(y), x);
}
@@ -525,7 +558,8 @@ flo_coerce(VALUE x, VALUE y)
*/
static VALUE
-flo_uminus(VALUE flt)
+flo_uminus(flt)
+ VALUE flt;
{
return rb_float_new(-RFLOAT(flt)->value);
}
@@ -539,7 +573,8 @@ flo_uminus(VALUE flt)
*/
static VALUE
-flo_plus(VALUE x, VALUE y)
+flo_plus(x, y)
+ VALUE x, y;
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -562,7 +597,8 @@ flo_plus(VALUE x, VALUE y)
*/
static VALUE
-flo_minus(VALUE x, VALUE y)
+flo_minus(x, y)
+ VALUE x, y;
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -585,7 +621,8 @@ flo_minus(VALUE x, VALUE y)
*/
static VALUE
-flo_mul(VALUE x, VALUE y)
+flo_mul(x, y)
+ VALUE x, y;
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -608,7 +645,8 @@ flo_mul(VALUE x, VALUE y)
*/
static VALUE
-flo_div(VALUE x, VALUE y)
+flo_div(x, y)
+ VALUE x, y;
{
long f_y;
double d;
@@ -629,7 +667,9 @@ flo_div(VALUE x, VALUE y)
static void
-flodivmod(double x, double y, double *divp, double *modp)
+flodivmod(x, y, divp, modp)
+ double x, y;
+ double *divp, *modp;
{
double div, mod;
@@ -643,7 +683,10 @@ flodivmod(double x, double y, double *divp, double *modp)
mod = x - z * y;
}
#endif
- div = (x - mod) / y;
+ if (isinf(x) && !isinf(y) && !isnan(y))
+ div = x;
+ else
+ div = (x - mod) / y;
if (y*mod < 0) {
mod += y;
div -= 1.0;
@@ -665,7 +708,8 @@ flodivmod(double x, double y, double *divp, double *modp)
*/
static VALUE
-flo_mod(VALUE x, VALUE y)
+flo_mod(x, y)
+ VALUE x, y;
{
double fy, mod;
@@ -694,7 +738,8 @@ flo_mod(VALUE x, VALUE y)
*/
static VALUE
-flo_divmod(VALUE x, VALUE y)
+flo_divmod(x, y)
+ VALUE x, y;
{
double fy, div, mod, val;
volatile VALUE a, b;
@@ -714,11 +759,11 @@ flo_divmod(VALUE x, VALUE y)
}
flodivmod(RFLOAT(x)->value, fy, &div, &mod);
if (FIXABLE(div)) {
- val = div;
- a = LONG2FIX(val);
+ val = round(div);
+ a = LONG2FIX(val);
}
else {
- a = rb_dbl2big(div);
+ a = rb_dbl2big(div);
}
b = rb_float_new(mod);
return rb_assoc_new(a, b);
@@ -733,7 +778,8 @@ flo_divmod(VALUE x, VALUE y)
*/
static VALUE
-flo_pow(VALUE x, VALUE y)
+flo_pow(x, y)
+ VALUE x, y;
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -760,7 +806,8 @@ flo_pow(VALUE x, VALUE y)
*/
static VALUE
-num_eql(VALUE x, VALUE y)
+num_eql(x, y)
+ VALUE x, y;
{
if (TYPE(x) != TYPE(y)) return Qfalse;
@@ -776,14 +823,16 @@ num_eql(VALUE x, VALUE y)
*/
static VALUE
-num_cmp(VALUE x, VALUE y)
+num_cmp(x, y)
+ VALUE x, y;
{
if (x == y) return INT2FIX(0);
return Qnil;
}
static VALUE
-num_equal(VALUE x, VALUE y)
+num_equal(x, y)
+ VALUE x, y;
{
if (x == y) return Qtrue;
return rb_funcall(y, id_eq, 1, x);
@@ -802,7 +851,8 @@ num_equal(VALUE x, VALUE y)
*/
static VALUE
-flo_eq(VALUE x, VALUE y)
+flo_eq(x, y)
+ VALUE x, y;
{
volatile double a, b;
@@ -833,18 +883,26 @@ flo_eq(VALUE x, VALUE y)
*/
static VALUE
-flo_hash(VALUE num)
+flo_hash(num)
+ VALUE num;
{
double d;
- int hash;
+ char *c;
+ int i, hash;
d = RFLOAT(num)->value;
- hash = rb_memhash(&d, sizeof(d));
+ if (d == 0) d = fabs(d);
+ c = (char*)&d;
+ for (hash=0, i=0; i<sizeof(double);i++) {
+ hash = (hash * 971) ^ (unsigned char)c[i];
+ }
+ if (hash < 0) hash = -hash;
return INT2FIX(hash);
}
VALUE
-rb_dbl_cmp(double a, double b)
+rb_dbl_cmp(a, b)
+ double a, b;
{
if (isnan(a) || isnan(b)) return Qnil;
if (a == b) return INT2FIX(0);
@@ -863,7 +921,8 @@ rb_dbl_cmp(double a, double b)
*/
static VALUE
-flo_cmp(VALUE x, VALUE y)
+flo_cmp(x, y)
+ VALUE x, y;
{
double a, b;
@@ -895,7 +954,8 @@ flo_cmp(VALUE x, VALUE y)
*/
static VALUE
-flo_gt(VALUE x, VALUE y)
+flo_gt(x, y)
+ VALUE x, y;
{
double a, b;
@@ -930,7 +990,8 @@ flo_gt(VALUE x, VALUE y)
*/
static VALUE
-flo_ge(VALUE x, VALUE y)
+flo_ge(x, y)
+ VALUE x, y;
{
double a, b;
@@ -964,7 +1025,8 @@ flo_ge(VALUE x, VALUE y)
*/
static VALUE
-flo_lt(VALUE x, VALUE y)
+flo_lt(x, y)
+ VALUE x, y;
{
double a, b;
@@ -999,7 +1061,8 @@ flo_lt(VALUE x, VALUE y)
*/
static VALUE
-flo_le(VALUE x, VALUE y)
+flo_le(x, y)
+ VALUE x, y;
{
double a, b;
@@ -1037,7 +1100,8 @@ flo_le(VALUE x, VALUE y)
*/
static VALUE
-flo_eql(VALUE x, VALUE y)
+flo_eql(x, y)
+ VALUE x, y;
{
if (TYPE(y) == T_FLOAT) {
double a = RFLOAT(x)->value;
@@ -1057,7 +1121,8 @@ flo_eql(VALUE x, VALUE y)
*/
static VALUE
-flo_to_f(VALUE num)
+flo_to_f(num)
+ VALUE num;
{
return num;
}
@@ -1074,7 +1139,8 @@ flo_to_f(VALUE num)
*/
static VALUE
-flo_abs(VALUE flt)
+flo_abs(flt)
+ VALUE flt;
{
double val = fabs(RFLOAT(flt)->value);
return rb_float_new(val);
@@ -1089,7 +1155,8 @@ flo_abs(VALUE flt)
*/
static VALUE
-flo_zero_p(VALUE num)
+flo_zero_p(num)
+ VALUE num;
{
if (RFLOAT(num)->value == 0.0) {
return Qtrue;
@@ -1111,7 +1178,8 @@ flo_zero_p(VALUE num)
*/
static VALUE
-flo_is_nan_p(VALUE num)
+flo_is_nan_p(num)
+ VALUE num;
{
double value = RFLOAT(num)->value;
@@ -1131,7 +1199,8 @@ flo_is_nan_p(VALUE num)
*/
static VALUE
-flo_is_infinite_p(VALUE num)
+flo_is_infinite_p(num)
+ VALUE num;
{
double value = RFLOAT(num)->value;
@@ -1153,7 +1222,8 @@ flo_is_infinite_p(VALUE num)
*/
static VALUE
-flo_is_finite_p(VALUE num)
+flo_is_finite_p(num)
+ VALUE num;
{
double value = RFLOAT(num)->value;
@@ -1181,7 +1251,8 @@ flo_is_finite_p(VALUE num)
*/
static VALUE
-flo_floor(VALUE num)
+flo_floor(num)
+ VALUE num;
{
double f = floor(RFLOAT(num)->value);
long val;
@@ -1207,7 +1278,8 @@ flo_floor(VALUE num)
*/
static VALUE
-flo_ceil(VALUE num)
+flo_ceil(num)
+ VALUE num;
{
double f = ceil(RFLOAT(num)->value);
long val;
@@ -1226,9 +1298,9 @@ flo_ceil(VALUE num)
* Rounds <i>flt</i> to the nearest integer. Equivalent to:
*
* def round
- * return floor(self+0.5) if self > 0.0
- * return ceil(self-0.5) if self < 0.0
- * return 0.0
+ * return (self+0.5).floor if self > 0.0
+ * return (self-0.5).ceil if self < 0.0
+ * return 0
* end
*
* 1.5.round #=> 2
@@ -1237,13 +1309,13 @@ flo_ceil(VALUE num)
*/
static VALUE
-flo_round(VALUE num)
+flo_round(num)
+ VALUE num;
{
double f = RFLOAT(num)->value;
long val;
- if (f > 0.0) f = floor(f+0.5);
- if (f < 0.0) f = ceil(f-0.5);
+ f = round(f);
if (!FIXABLE(f)) {
return rb_dbl2big(f);
@@ -1262,7 +1334,8 @@ flo_round(VALUE num)
*/
static VALUE
-flo_truncate(VALUE num)
+flo_truncate(num)
+ VALUE num;
{
double f = RFLOAT(num)->value;
long val;
@@ -1291,7 +1364,8 @@ flo_truncate(VALUE num)
*/
static VALUE
-num_floor(VALUE num)
+num_floor(num)
+ VALUE num;
{
return flo_floor(rb_Float(num));
}
@@ -1313,7 +1387,8 @@ num_floor(VALUE num)
*/
static VALUE
-num_ceil(VALUE num)
+num_ceil(num)
+ VALUE num;
{
return flo_ceil(rb_Float(num));
}
@@ -1328,7 +1403,8 @@ num_ceil(VALUE num)
*/
static VALUE
-num_round(VALUE num)
+num_round(num)
+ VALUE num;
{
return flo_round(rb_Float(num));
}
@@ -1343,7 +1419,8 @@ num_round(VALUE num)
*/
static VALUE
-num_truncate(VALUE num)
+num_truncate(num)
+ VALUE num;
{
return flo_truncate(rb_Float(num));
}
@@ -1377,11 +1454,13 @@ num_truncate(VALUE num)
*/
static VALUE
-num_step(int argc, VALUE *argv, VALUE from)
+num_step(argc, argv, from)
+ int argc;
+ VALUE *argv;
+ VALUE from;
{
VALUE to, step;
- RETURN_ENUMERATOR(from, argc, argv);
if (argc == 1) {
to = argv[0];
step = INT2FIX(1);
@@ -1453,9 +1532,11 @@ num_step(int argc, VALUE *argv, VALUE from)
return from;
}
-SIGNED_VALUE
-rb_num2long(VALUE val)
+long
+rb_num2long(val)
+ VALUE val;
{
+ again:
if (NIL_P(val)) {
rb_raise(rb_eTypeError, "no implicit conversion from nil to integer");
}
@@ -1466,7 +1547,7 @@ rb_num2long(VALUE val)
case T_FLOAT:
if (RFLOAT(val)->value <= (double)LONG_MAX
&& RFLOAT(val)->value >= (double)LONG_MIN) {
- return (SIGNED_VALUE)(RFLOAT(val)->value);
+ return (long)(RFLOAT(val)->value);
}
else {
char buf[24];
@@ -1482,22 +1563,24 @@ rb_num2long(VALUE val)
default:
val = rb_to_int(val);
- return NUM2LONG(val);
+ goto again;
}
}
-VALUE
-rb_num2ulong(VALUE val)
+unsigned long
+rb_num2ulong(val)
+ VALUE val;
{
if (TYPE(val) == T_BIGNUM) {
return rb_big2ulong(val);
}
- return (VALUE)rb_num2long(val);
+ return (unsigned long)rb_num2long(val);
}
-#if SIZEOF_INT < SIZEOF_VALUE
+#if SIZEOF_INT < SIZEOF_LONG
static void
-check_int(SIGNED_VALUE num)
+check_int(num)
+ long num;
{
const char *s;
@@ -1510,27 +1593,31 @@ check_int(SIGNED_VALUE num)
else {
return;
}
-#if LONG_LONG_VALUE
- rb_raise(rb_eRangeError, "integer %lld too %s to convert to `int'", num, s);
-#else
rb_raise(rb_eRangeError, "integer %ld too %s to convert to `int'", num, s);
-#endif
}
static void
-check_uint(VALUE num)
+check_uint(num, sign)
+ unsigned long num;
+ VALUE sign;
{
- if (num > UINT_MAX) {
-#if LONG_LONG_VALUE
- rb_raise(rb_eRangeError, "integer %llu too big to convert to `unsigned int'", num);
-#else
- rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num);
-#endif
+ 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);
}
}
long
-rb_num2int(VALUE val)
+rb_num2int(val)
+ VALUE val;
{
long num = rb_num2long(val);
@@ -1539,7 +1626,8 @@ rb_num2int(VALUE val)
}
long
-rb_fix2int(VALUE val)
+rb_fix2int(val)
+ VALUE val;
{
long num = FIXNUM_P(val)?FIX2LONG(val):rb_num2long(val);
@@ -1548,18 +1636,18 @@ rb_fix2int(VALUE val)
}
unsigned long
-rb_num2uint(VALUE val)
+rb_num2uint(val)
+ VALUE val;
{
unsigned long num = rb_num2ulong(val);
- if (RTEST(rb_funcall(INT2FIX(0), '<', 1, val))) {
- check_uint(num);
- }
+ check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
return num;
}
unsigned long
-rb_fix2uint(VALUE val)
+rb_fix2uint(val)
+ VALUE val;
{
unsigned long num;
@@ -1567,27 +1655,29 @@ rb_fix2uint(VALUE val)
return rb_num2uint(val);
}
num = FIX2ULONG(val);
- if (FIX2LONG(val) > 0) {
- check_uint(num);
- }
+
+ check_uint(num, rb_funcall(val, '<', 1, INT2FIX(0)));
return num;
}
#else
long
-rb_num2int(VALUE val)
+rb_num2int(val)
+ VALUE val;
{
return rb_num2long(val);
}
long
-rb_fix2int(VALUE val)
+rb_fix2int(val)
+ VALUE val;
{
return FIX2INT(val);
}
#endif
VALUE
-rb_num2fix(VALUE val)
+rb_num2fix(val)
+ VALUE val;
{
long v;
@@ -1602,7 +1692,8 @@ rb_num2fix(VALUE val)
#if HAVE_LONG_LONG
LONG_LONG
-rb_num2ll(VALUE val)
+rb_num2ll(val)
+ VALUE val;
{
if (NIL_P(val)) {
rb_raise(rb_eTypeError, "no implicit conversion from nil");
@@ -1644,7 +1735,8 @@ rb_num2ll(VALUE val)
}
unsigned LONG_LONG
-rb_num2ull(VALUE val)
+rb_num2ull(val)
+ VALUE val;
{
if (TYPE(val) == T_BIGNUM) {
return rb_big2ull(val);
@@ -1678,7 +1770,8 @@ rb_num2ull(VALUE val)
*/
static VALUE
-int_to_i(VALUE num)
+int_to_i(num)
+ VALUE num;
{
return num;
}
@@ -1691,45 +1784,14 @@ int_to_i(VALUE num)
*/
static VALUE
-int_int_p(VALUE num)
+int_int_p(num)
+ VALUE num;
{
return Qtrue;
}
/*
* call-seq:
- * int.odd? -> true or false
- *
- * Returns <code>true</code> if <i>int</i> is an odd number.
- */
-
-static VALUE
-int_odd_p(VALUE num)
-{
- if (rb_funcall(num, '%', 1, INT2FIX(2)) != INT2FIX(0)) {
- return Qtrue;
- }
- return Qfalse;
-}
-
-/*
- * call-seq:
- * int.even? -> true or false
- *
- * Returns <code>true</code> if <i>int</i> is an even number.
- */
-
-static VALUE
-int_even_p(VALUE num)
-{
- if (rb_funcall(num, '%', 1, INT2FIX(2)) == INT2FIX(0)) {
- return Qtrue;
- }
- return Qfalse;
-}
-
-/*
- * call-seq:
* int.next => integer
* int.succ => integer
*
@@ -1740,7 +1802,8 @@ int_even_p(VALUE num)
*/
static VALUE
-int_succ(VALUE num)
+int_succ(num)
+ VALUE num;
{
if (FIXNUM_P(num)) {
long i = FIX2LONG(num) + 1;
@@ -1757,11 +1820,13 @@ int_succ(VALUE num)
* receiver's value.
*
* 65.chr #=> "A"
+ * ?a.chr #=> "a"
* 230.chr #=> "\346"
*/
static VALUE
-int_chr(VALUE num)
+int_chr(num)
+ VALUE num;
{
char c;
long i = NUM2LONG(num);
@@ -1800,7 +1865,8 @@ int_chr(VALUE num)
*/
static VALUE
-rb_fix_induced_from(VALUE klass, VALUE x)
+rb_fix_induced_from(klass, x)
+ VALUE klass, x;
{
return rb_num2fix(x);
}
@@ -1813,7 +1879,8 @@ rb_fix_induced_from(VALUE klass, VALUE x)
*/
static VALUE
-rb_int_induced_from(VALUE klass, VALUE x)
+rb_int_induced_from(klass, x)
+ VALUE klass, x;
{
switch (TYPE(x)) {
case T_FIXNUM:
@@ -1835,7 +1902,8 @@ rb_int_induced_from(VALUE klass, VALUE x)
*/
static VALUE
-rb_flo_induced_from(VALUE klass, VALUE x)
+rb_flo_induced_from(klass, x)
+ VALUE klass, x;
{
switch (TYPE(x)) {
case T_FIXNUM:
@@ -1857,16 +1925,19 @@ rb_flo_induced_from(VALUE klass, VALUE x)
*/
static VALUE
-fix_uminus(VALUE num)
+fix_uminus(num)
+ VALUE num;
{
return LONG2NUM(-FIX2LONG(num));
}
VALUE
-rb_fix2str(VALUE x, int base)
+rb_fix2str(x, base)
+ VALUE x;
+ int base;
{
extern const char ruby_digitmap[];
- char buf[SIZEOF_VALUE*CHAR_BIT + 2], *b = buf + sizeof buf;
+ char buf[SIZEOF_LONG*CHAR_BIT + 2], *b = buf + sizeof buf;
long val = FIX2LONG(x);
int neg = 0;
@@ -1907,7 +1978,10 @@ rb_fix2str(VALUE x, int base)
*
*/
static VALUE
-fix_to_s(int argc, VALUE *argv, VALUE x)
+fix_to_s(argc, argv, x)
+ int argc;
+ VALUE *argv;
+ VALUE x;
{
VALUE b;
int base;
@@ -1929,7 +2003,8 @@ fix_to_s(int argc, VALUE *argv, VALUE x)
*/
static VALUE
-fix_plus(VALUE x, VALUE y)
+fix_plus(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
long a, b, c;
@@ -1942,14 +2017,10 @@ fix_plus(VALUE x, VALUE y)
return r;
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- return rb_big_plus(y, x);
- case T_FLOAT:
+ if (TYPE(y) == T_FLOAT) {
return rb_float_new((double)FIX2LONG(x) + RFLOAT(y)->value);
- default:
- return rb_num_coerce_bin(x, y);
}
+ return rb_num_coerce_bin(x, y);
}
/*
@@ -1962,7 +2033,8 @@ fix_plus(VALUE x, VALUE y)
*/
static VALUE
-fix_minus(VALUE x, VALUE y)
+fix_minus(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
long a, b, c;
@@ -1975,15 +2047,10 @@ fix_minus(VALUE x, VALUE y)
return r;
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- x = rb_int2big(FIX2LONG(x));
- return rb_big_minus(x, y);
- case T_FLOAT:
+ if (TYPE(y) == T_FLOAT) {
return rb_float_new((double)FIX2LONG(x) - RFLOAT(y)->value);
- default:
- return rb_num_coerce_bin(x, y);
}
+ return rb_num_coerce_bin(x, y);
}
/*
@@ -1996,56 +2063,39 @@ fix_minus(VALUE x, VALUE y)
*/
static VALUE
-fix_mul(VALUE x, VALUE y)
+fix_mul(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
#ifdef __HP_cc
-/* avoids an optimization bug of HP aC++/ANSI C B3910B A.06.05 [Jul 25 2005] */
+ /* avoids an optimization bug of HP aC++/ANSI C B3910B A.06.05 [Jul 25 2005] */
volatile
#endif
- SIGNED_VALUE a, b;
-#if SIZEOF_VALUE * 2 <= SIZEOF_LONG_LONG
- LONG_LONG d;
-#else
- SIGNED_VALUE c;
+ long a, b, c;
VALUE r;
-#endif
a = FIX2LONG(x);
- b = FIX2LONG(y);
+ if (a == 0) return x;
-#if SIZEOF_VALUE * 2 <= SIZEOF_LONG_LONG
- d = (LONG_LONG)a * b;
- if (FIXABLE(d)) return LONG2FIX(d);
- return rb_ll2inum(d);
-#else
-# define SQRT_LONG_MAX ((SIGNED_VALUE)1<<((SIZEOF_VALUE*CHAR_BIT-1)/2))
- /*tests if N*N would overflow*/
-# define FIT_SQRT_LONG(n) (((n)<SQRT_LONG_MAX)&&((n)>=-SQRT_LONG_MAX))
- if (FIT_SQRT_LONG(a) && FIT_SQRT_LONG(b))
- return LONG2FIX(a*b);
+ b = FIX2LONG(y);
c = a * b;
r = LONG2FIX(c);
- if (a == 0) return x;
if (FIX2LONG(r) != c || c/a != b) {
r = rb_big_mul(rb_int2big(a), rb_int2big(b));
}
return r;
-#endif
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- return rb_big_mul(y, x);
- case T_FLOAT:
+ if (TYPE(y) == T_FLOAT) {
return rb_float_new((double)FIX2LONG(x) * RFLOAT(y)->value);
- default:
- return rb_num_coerce_bin(x, y);
}
+ return rb_num_coerce_bin(x, y);
}
static void
-fixdivmod(long x, long y, long *divp, long *modp)
+fixdivmod(x, y, divp, modp)
+ long x, y;
+ long *divp, *modp;
{
long div, mod;
@@ -2084,50 +2134,19 @@ fixdivmod(long x, long y, long *divp, long *modp)
*/
static VALUE
-fix_quo(VALUE x, VALUE y)
+fix_quo(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
return rb_float_new((double)FIX2LONG(x) / (double)FIX2LONG(y));
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- return rb_float_new((double)FIX2LONG(y) / rb_big2dbl(y));
- case T_FLOAT:
- return rb_float_new((double)FIX2LONG(x) / RFLOAT(y)->value);
- default:
- return rb_num_coerce_bin(x, y);
- }
-}
-
-static VALUE
-fix_divide(VALUE x, VALUE y, int flo)
-{
- if (FIXNUM_P(y)) {
- long div;
-
- fixdivmod(FIX2LONG(x), FIX2LONG(y), &div, 0);
- return LONG2NUM(div);
- }
- switch (TYPE(y)) {
- case T_BIGNUM:
- x = rb_int2big(FIX2LONG(x));
- return rb_big_div(x, y);
- case T_FLOAT:
- if (flo) {
- return rb_float_new((double)FIX2LONG(x) / RFLOAT(y)->value);
- }
- else {
- long div = (double)FIX2LONG(x) / RFLOAT(y)->value;
- return LONG2NUM(div);
- }
- default:
- return rb_num_coerce_bin(x, y);
- }
+ return rb_num_coerce_bin(x, y);
}
/*
* call-seq:
* fix / numeric => numeric_result
+ * fix.div(numeric) => numeric_result
*
* Performs division: the class of the resulting object depends on
* the class of <code>numeric</code> and on the magnitude of the
@@ -2135,22 +2154,16 @@ fix_divide(VALUE x, VALUE y, int flo)
*/
static VALUE
-fix_div(VALUE x, VALUE y)
+fix_div(x, y)
+ VALUE x, y;
{
- return fix_divide(x, y, Qtrue);
-}
-
-/*
- * call-seq:
- * fix.div(numeric) => numeric_result
- *
- * Performs integer division: returns integer value.
- */
+ if (FIXNUM_P(y)) {
+ long div;
-static VALUE
-fix_idiv(VALUE x, VALUE y)
-{
- return fix_divide(x, y, Qfalse);
+ fixdivmod(FIX2LONG(x), FIX2LONG(y), &div, 0);
+ return LONG2NUM(div);
+ }
+ return rb_num_coerce_bin(x, y);
}
/*
@@ -2163,7 +2176,8 @@ fix_idiv(VALUE x, VALUE y)
*/
static VALUE
-fix_mod(VALUE x, VALUE y)
+fix_mod(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
long mod;
@@ -2171,20 +2185,7 @@ fix_mod(VALUE x, VALUE y)
fixdivmod(FIX2LONG(x), FIX2LONG(y), 0, &mod);
return LONG2NUM(mod);
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- x = rb_int2big(FIX2LONG(x));
- return rb_big_modulo(x, y);
- case T_FLOAT:
- {
- double mod;
-
- flodivmod((double)FIX2LONG(x), RFLOAT(y)->value, 0, &mod);
- return rb_float_new(mod);
- }
- default:
- return rb_num_coerce_bin(x, y);
- }
+ return rb_num_coerce_bin(x, y);
}
/*
@@ -2194,7 +2195,8 @@ fix_mod(VALUE x, VALUE y)
* See <code>Numeric#divmod</code>.
*/
static VALUE
-fix_divmod(VALUE x, VALUE y)
+fix_divmod(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
long div, mod;
@@ -2203,23 +2205,16 @@ fix_divmod(VALUE x, VALUE y)
return rb_assoc_new(LONG2NUM(div), LONG2NUM(mod));
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- x = rb_int2big(FIX2LONG(x));
- return rb_big_divmod(x, y);
- case T_FLOAT:
- {
- double div, mod;
- volatile VALUE a, b;
-
- flodivmod((double)FIX2LONG(x), RFLOAT(y)->value, &div, &mod);
- a = rb_float_new(div);
- b = rb_float_new(mod);
- return rb_assoc_new(a, b);
- }
- default:
- return rb_num_coerce_bin(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;
}
/*
@@ -2235,15 +2230,30 @@ fix_divmod(VALUE x, VALUE y)
*/
static VALUE
-fix_pow(VALUE x, VALUE y)
+fix_pow(x, y)
+ VALUE x, y;
{
+ static const double zero = 0.0;
+ long a = FIX2LONG(x);
+
if (FIXNUM_P(y)) {
- long a, b;
+ long 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);
}
@@ -2251,10 +2261,20 @@ fix_pow(VALUE x, VALUE y)
}
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:
- return rb_float_new(pow((double)FIX2LONG(x), RFLOAT(y)->value));
+ 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);
}
@@ -2272,19 +2292,12 @@ fix_pow(VALUE x, VALUE y)
*/
static VALUE
-fix_equal(VALUE x, VALUE y)
+fix_equal(x, y)
+ VALUE x, y;
{
- if (FIXNUM_P(y)) {
- return (FIX2LONG(x) == FIX2LONG(y))?Qtrue:Qfalse;
- }
- switch (TYPE(y)) {
- case T_BIGNUM:
- return rb_big_eq(y, x);
- case T_FLOAT:
- return (double)FIX2LONG(x) == RFLOAT(y)->value ? Qtrue : Qfalse;
- default:
- return num_equal(x, y);
- }
+ if (x == y) return Qtrue;
+ if (FIXNUM_P(y)) return Qfalse;
+ return num_equal(x, y);
}
/*
@@ -2297,21 +2310,17 @@ fix_equal(VALUE x, VALUE y)
*/
static VALUE
-fix_cmp(VALUE x, VALUE y)
+fix_cmp(x, y)
+ VALUE x, y;
{
+ if (x == y) return INT2FIX(0);
if (FIXNUM_P(y)) {
long a = FIX2LONG(x), b = FIX2LONG(y);
- if (a == b) return INT2FIX(0);
if (a > b) return INT2FIX(1);
return INT2FIX(-1);
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- return rb_big_cmp(rb_int2big(FIX2LONG(x)), y);
- case T_FLOAT:
- return rb_dbl_cmp((double)FIX2LONG(x), RFLOAT(y)->value);
- default:
+ else {
return rb_num_coerce_cmp(x, y);
}
}
@@ -2325,7 +2334,8 @@ fix_cmp(VALUE x, VALUE y)
*/
static VALUE
-fix_gt(VALUE x, VALUE y)
+fix_gt(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
long a = FIX2LONG(x), b = FIX2LONG(y);
@@ -2333,12 +2343,7 @@ fix_gt(VALUE x, VALUE y)
if (a > b) return Qtrue;
return Qfalse;
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) > 0 ? Qtrue : Qfalse;
- case T_FLOAT:
- return (double)FIX2LONG(x) > RFLOAT(y)->value ? Qtrue : Qfalse;
- default:
+ else {
return rb_num_coerce_relop(x, y);
}
}
@@ -2352,7 +2357,8 @@ fix_gt(VALUE x, VALUE y)
*/
static VALUE
-fix_ge(VALUE x, VALUE y)
+fix_ge(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
long a = FIX2LONG(x), b = FIX2LONG(y);
@@ -2360,12 +2366,7 @@ fix_ge(VALUE x, VALUE y)
if (a >= b) return Qtrue;
return Qfalse;
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) >= 0 ? Qtrue : Qfalse;
- case T_FLOAT:
- return (double)FIX2LONG(x) >= RFLOAT(y)->value ? Qtrue : Qfalse;
- default:
+ else {
return rb_num_coerce_relop(x, y);
}
}
@@ -2379,7 +2380,8 @@ fix_ge(VALUE x, VALUE y)
*/
static VALUE
-fix_lt(VALUE x, VALUE y)
+fix_lt(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
long a = FIX2LONG(x), b = FIX2LONG(y);
@@ -2387,12 +2389,7 @@ fix_lt(VALUE x, VALUE y)
if (a < b) return Qtrue;
return Qfalse;
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) < 0 ? Qtrue : Qfalse;
- case T_FLOAT:
- return (double)FIX2LONG(x) < RFLOAT(y)->value ? Qtrue : Qfalse;
- default:
+ else {
return rb_num_coerce_relop(x, y);
}
}
@@ -2406,7 +2403,8 @@ fix_lt(VALUE x, VALUE y)
*/
static VALUE
-fix_le(VALUE x, VALUE y)
+fix_le(x, y)
+ VALUE x, y;
{
if (FIXNUM_P(y)) {
long a = FIX2LONG(x), b = FIX2LONG(y);
@@ -2414,12 +2412,7 @@ fix_le(VALUE x, VALUE y)
if (a <= b) return Qtrue;
return Qfalse;
}
- switch (TYPE(y)) {
- case T_BIGNUM:
- return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) <= 0 ? Qtrue : Qfalse;
- case T_FLOAT:
- return (double)FIX2LONG(x) <= RFLOAT(y)->value ? Qtrue : Qfalse;
- default:
+ else {
return rb_num_coerce_relop(x, y);
}
}
@@ -2432,7 +2425,8 @@ fix_le(VALUE x, VALUE y)
*/
static VALUE
-fix_rev(VALUE num)
+fix_rev(num)
+ VALUE num;
{
long val = FIX2LONG(num);
@@ -2440,6 +2434,16 @@ fix_rev(VALUE 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
@@ -2448,14 +2452,15 @@ fix_rev(VALUE num)
*/
static VALUE
-fix_and(VALUE x, VALUE y)
+fix_and(x, y)
+ VALUE x, y;
{
long val;
- if (TYPE(y) == T_BIGNUM) {
+ if (!FIXNUM_P(y = fix_coerce(y))) {
return rb_big_and(y, x);
}
- val = FIX2LONG(x) & NUM2LONG(y);
+ val = FIX2LONG(x) & FIX2LONG(y);
return LONG2NUM(val);
}
@@ -2467,14 +2472,15 @@ fix_and(VALUE x, VALUE y)
*/
static VALUE
-fix_or(VALUE x, VALUE y)
+fix_or(x, y)
+ VALUE x, y;
{
long val;
- if (TYPE(y) == T_BIGNUM) {
+ if (!FIXNUM_P(y = fix_coerce(y))) {
return rb_big_or(y, x);
}
- val = FIX2LONG(x) | NUM2LONG(y);
+ val = FIX2LONG(x) | FIX2LONG(y);
return LONG2NUM(val);
}
@@ -2486,18 +2492,20 @@ fix_or(VALUE x, VALUE y)
*/
static VALUE
-fix_xor(VALUE x, VALUE y)
+fix_xor(x, y)
+ VALUE x, y;
{
long val;
- if (TYPE(y) == T_BIGNUM) {
+ if (!FIXNUM_P(y = fix_coerce(y))) {
return rb_big_xor(y, x);
}
- val = FIX2LONG(x) ^ NUM2LONG(y);
+ val = FIX2LONG(x) ^ FIX2LONG(y);
return LONG2NUM(val);
}
-static VALUE fix_rshift(VALUE, VALUE);
+static VALUE fix_lshift _((long, unsigned long));
+static VALUE fix_rshift _((long, unsigned long));
/*
* call-seq:
@@ -2507,17 +2515,28 @@ static VALUE fix_rshift(VALUE, VALUE);
*/
static VALUE
-fix_lshift(VALUE x, VALUE y)
+rb_fix_lshift(x, y)
+ VALUE x, y;
{
long val, width;
val = NUM2LONG(x);
- width = NUM2LONG(y);
+ if (!FIXNUM_P(y))
+ return rb_big_lshift(rb_int2big(val), y);
+ width = FIX2LONG(y);
if (width < 0)
- return fix_rshift(x, LONG2FIX(-width));
+ return fix_rshift(val, (unsigned long)-width);
+ return fix_lshift(val, width);
+}
+
+static VALUE
+fix_lshift(val, width)
+ long val;
+ unsigned long 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), y);
+ return rb_big_lshift(rb_int2big(val), ULONG2NUM(width));
}
val = val << width;
return LONG2NUM(val);
@@ -2531,15 +2550,24 @@ fix_lshift(VALUE x, VALUE y)
*/
static VALUE
-fix_rshift(VALUE x, VALUE y)
+rb_fix_rshift(x, y)
+ VALUE x, y;
{
long i, val;
- i = NUM2LONG(y);
- if (i < 0)
- return fix_lshift(x, LONG2FIX(-i));
- if (i == 0) return x;
val = FIX2LONG(x);
+ if (!FIXNUM_P(y))
+ return rb_big_rshift(rb_int2big(val), y);
+ i = FIX2LONG(y);
+ if (i == 0) return x;
+ if (i < 0)
+ return fix_lshift(val, (unsigned long)-i);
+ return fix_rshift(val, i);
+}
+
+static VALUE
+fix_rshift(long val, unsigned long i)
+{
if (i >= sizeof(long)*CHAR_BIT-1) {
if (val < 0) return INT2FIX(-1);
return INT2FIX(0);
@@ -2565,12 +2593,13 @@ fix_rshift(VALUE x, VALUE y)
*/
static VALUE
-fix_aref(VALUE fix, VALUE idx)
+fix_aref(fix, idx)
+ VALUE fix, idx;
{
long val = FIX2LONG(fix);
long i;
- if (TYPE(idx) == T_BIGNUM) {
+ if (!FIXNUM_P(idx = fix_coerce(idx))) {
idx = rb_big_norm(idx);
if (!FIXNUM_P(idx)) {
if (!RBIGNUM(idx)->sign || val >= 0)
@@ -2578,7 +2607,7 @@ fix_aref(VALUE fix, VALUE idx)
return INT2FIX(1);
}
}
- i = NUM2LONG(idx);
+ i = FIX2LONG(idx);
if (i < 0) return INT2FIX(0);
if (sizeof(VALUE)*CHAR_BIT-1 < i) {
@@ -2599,7 +2628,8 @@ fix_aref(VALUE fix, VALUE idx)
*/
static VALUE
-fix_to_f(VALUE num)
+fix_to_f(num)
+ VALUE num;
{
double val;
@@ -2620,7 +2650,8 @@ fix_to_f(VALUE num)
*/
static VALUE
-fix_abs(VALUE fix)
+fix_abs(fix)
+ VALUE fix;
{
long i = FIX2LONG(fix);
@@ -2645,9 +2676,10 @@ fix_abs(VALUE fix)
*/
static VALUE
-fix_id2name(VALUE fix)
+fix_id2name(fix)
+ VALUE fix;
{
- const char *name = rb_id2name(FIX2UINT(fix));
+ char *name = rb_id2name(FIX2UINT(fix));
if (name) return rb_str_new2(name);
return Qnil;
}
@@ -2666,7 +2698,8 @@ fix_id2name(VALUE fix)
*/
static VALUE
-fix_to_sym(VALUE fix)
+fix_to_sym(fix)
+ VALUE fix;
{
ID id = FIX2UINT(fix);
@@ -2690,7 +2723,8 @@ fix_to_sym(VALUE fix)
*/
static VALUE
-fix_size(VALUE fix)
+fix_size(fix)
+ VALUE fix;
{
return INT2FIX(sizeof(long));
}
@@ -2710,9 +2744,9 @@ fix_size(VALUE fix)
*/
static VALUE
-int_upto(VALUE from, VALUE to)
+int_upto(from, to)
+ VALUE from, to;
{
- RETURN_ENUMERATOR(from, 1, &to);
if (FIXNUM_P(from) && FIXNUM_P(to)) {
long i, end;
@@ -2749,9 +2783,9 @@ int_upto(VALUE from, VALUE to)
*/
static VALUE
-int_downto(VALUE from, VALUE to)
+int_downto(from, to)
+ VALUE from, to;
{
- RETURN_ENUMERATOR(from, 1, &to);
if (FIXNUM_P(from) && FIXNUM_P(to)) {
long i, end;
@@ -2789,9 +2823,9 @@ int_downto(VALUE from, VALUE to)
*/
static VALUE
-int_dotimes(VALUE num)
+int_dotimes(num)
+ VALUE num;
{
- RETURN_ENUMERATOR(num, 0, 0);
if (FIXNUM_P(num)) {
long i, end;
@@ -2821,7 +2855,8 @@ int_dotimes(VALUE num)
*/
static VALUE
-fix_zero_p(VALUE num)
+fix_zero_p(num)
+ VALUE num;
{
if (FIX2LONG(num) == 0) {
return Qtrue;
@@ -2829,40 +2864,8 @@ fix_zero_p(VALUE num)
return Qfalse;
}
-/*
- * call-seq:
- * fix.odd? -> true or false
- *
- * Returns <code>true</code> if <i>fix</i> is an odd number.
- */
-
-static VALUE
-fix_odd_p(VALUE num)
-{
- if (num & 2) {
- return Qtrue;
- }
- return Qfalse;
-}
-
-/*
- * call-seq:
- * fix.even? -> true or false
- *
- * Returns <code>true</code> if <i>fix</i> is an even number.
- */
-
-static VALUE
-fix_even_p(VALUE num)
-{
- if (num & 2) {
- return Qfalse;
- }
- return Qtrue;
-}
-
void
-Init_Numeric(void)
+Init_Numeric()
{
#if defined(__FreeBSD__) && __FreeBSD__ < 4
/* allow divide by zero -- Inf */
@@ -2899,7 +2902,6 @@ Init_Numeric(void)
rb_define_method(rb_cNumeric, "abs", num_abs, 0);
rb_define_method(rb_cNumeric, "to_int", num_to_int, 0);
- rb_define_method(rb_cNumeric, "scalar?", num_scalar_p, 0);
rb_define_method(rb_cNumeric, "integer?", num_int_p, 0);
rb_define_method(rb_cNumeric, "zero?", num_zero_p, 0);
rb_define_method(rb_cNumeric, "nonzero?", num_nonzero_p, 0);
@@ -2915,8 +2917,6 @@ Init_Numeric(void)
rb_undef_method(CLASS_OF(rb_cInteger), "new");
rb_define_method(rb_cInteger, "integer?", int_int_p, 0);
- rb_define_method(rb_cInteger, "odd?", int_odd_p, 0);
- rb_define_method(rb_cInteger, "even?", int_even_p, 0);
rb_define_method(rb_cInteger, "upto", int_upto, 1);
rb_define_method(rb_cInteger, "downto", int_downto, 1);
rb_define_method(rb_cInteger, "times", int_dotimes, 0);
@@ -2946,7 +2946,7 @@ Init_Numeric(void)
rb_define_method(rb_cFixnum, "-", fix_minus, 1);
rb_define_method(rb_cFixnum, "*", fix_mul, 1);
rb_define_method(rb_cFixnum, "/", fix_div, 1);
- rb_define_method(rb_cFixnum, "div", fix_idiv, 1);
+ rb_define_method(rb_cFixnum, "div", fix_div, 1);
rb_define_method(rb_cFixnum, "%", fix_mod, 1);
rb_define_method(rb_cFixnum, "modulo", fix_mod, 1);
rb_define_method(rb_cFixnum, "divmod", fix_divmod, 1);
@@ -2968,14 +2968,12 @@ Init_Numeric(void)
rb_define_method(rb_cFixnum, "^", fix_xor, 1);
rb_define_method(rb_cFixnum, "[]", fix_aref, 1);
- rb_define_method(rb_cFixnum, "<<", fix_lshift, 1);
- rb_define_method(rb_cFixnum, ">>", fix_rshift, 1);
+ rb_define_method(rb_cFixnum, "<<", rb_fix_lshift, 1);
+ rb_define_method(rb_cFixnum, ">>", rb_fix_rshift, 1);
rb_define_method(rb_cFixnum, "to_f", fix_to_f, 0);
rb_define_method(rb_cFixnum, "size", fix_size, 0);
rb_define_method(rb_cFixnum, "zero?", fix_zero_p, 0);
- rb_define_method(rb_cFixnum, "odd?", fix_odd_p, 0);
- rb_define_method(rb_cFixnum, "even?", fix_even_p, 0);
rb_cFloat = rb_define_class("Float", rb_cNumeric);
diff --git a/object.c b/object.c
index 9660ee6d95..60df9b3386 100644
--- a/object.c
+++ b/object.c
@@ -20,7 +20,6 @@
#include <ctype.h>
#include <math.h>
-VALUE rb_cBasicObject;
VALUE rb_mKernel;
VALUE rb_cObject;
VALUE rb_cModule;
@@ -30,6 +29,7 @@ VALUE rb_cData;
VALUE rb_cNilClass;
VALUE rb_cTrueClass;
VALUE rb_cFalseClass;
+VALUE rb_cSymbol;
static ID id_eq, id_eql, id_inspect, id_init_copy;
@@ -43,7 +43,8 @@ static ID id_eq, id_eql, id_inspect, id_init_copy;
*/
VALUE
-rb_equal(VALUE obj1, VALUE obj2)
+rb_equal(obj1, obj2)
+ VALUE obj1, obj2;
{
VALUE result;
@@ -54,7 +55,8 @@ rb_equal(VALUE obj1, VALUE obj2)
}
int
-rb_eql(VALUE obj1, VALUE obj2)
+rb_eql(obj1, obj2)
+ VALUE obj1, obj2;
{
return RTEST(rb_funcall(obj1, id_eql, 1, obj2));
}
@@ -76,27 +78,44 @@ rb_eql(VALUE obj1, VALUE obj2)
* object as <code>b</code>).
*
* The <code>eql?</code> method returns <code>true</code> if
- * <i>obj</i> and <i>anObject</i> have the same value. Used by
- * <code>Hash</code> to test members for equality. For objects of
- * class <code>Object</code>, <code>eql?</code> is synonymous with
- * <code>==</code>. Subclasses normally continue this tradition, but
- * there are exceptions. <code>Numeric</code> types, for example,
- * perform type conversion across <code>==</code>, but not across
- * <code>eql?</code>, so:
+ <i>obj</i> and <i>anObject</i> have the
+ * same value. Used by <code>Hash</code> to test members for equality.
+ * For objects of class <code>Object</code>, <code>eql?</code> is
+ * synonymous with <code>==</code>. Subclasses normally continue this
+ * tradition, but there are exceptions. <code>Numeric</code> types, for
+ * example, perform type conversion across <code>==</code>, but not
+ * across <code>eql?</code>, so:
*
* 1 == 1.0 #=> true
* 1.eql? 1.0 #=> false
*/
static VALUE
-rb_obj_equal(VALUE obj1, VALUE obj2)
+rb_obj_equal(obj1, obj2)
+ VALUE obj1, obj2;
{
if (obj1 == obj2) return Qtrue;
return Qfalse;
}
+/*
+ * call-seq:
+ * obj.id => fixnum
+ *
+ * Soon-to-be deprecated version of <code>Object#object_id</code>.
+ */
+
VALUE
-rb_class_real(VALUE cl)
+rb_obj_id_obsolete(obj)
+ VALUE obj;
+{
+ rb_warn("Object#id will be deprecated; use Object#object_id");
+ return rb_obj_id(obj);
+}
+
+VALUE
+rb_class_real(cl)
+ VALUE cl;
{
while (FL_TEST(cl, FL_SINGLETON) || TYPE(cl) == T_ICLASS) {
cl = RCLASS(cl)->super;
@@ -106,6 +125,22 @@ rb_class_real(VALUE cl)
/*
* call-seq:
+ * obj.type => class
+ *
+ * Deprecated synonym for <code>Object#class</code>.
+ */
+
+VALUE
+rb_obj_type(obj)
+ VALUE obj;
+{
+ rb_warn("Object#type is deprecated; use Object#class");
+ return rb_class_real(CLASS_OF(obj));
+}
+
+
+/*
+ * call-seq:
* obj.class => class
*
* Returns the class of <i>obj</i>, now preferred over
@@ -119,20 +154,24 @@ rb_class_real(VALUE cl)
*/
VALUE
-rb_obj_class(VALUE obj)
+rb_obj_class(obj)
+ VALUE obj;
{
return rb_class_real(CLASS_OF(obj));
}
static void
-init_copy(VALUE dest, VALUE obj)
+init_copy(dest, obj)
+ VALUE dest, obj;
{
if (OBJ_FROZEN(dest)) {
rb_raise(rb_eTypeError, "[bug] frozen object (%s) allocated", rb_obj_classname(dest));
}
RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR);
RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR|FL_TAINT);
- rb_copy_generic_ivar(dest, obj);
+ if (FL_TEST(obj, FL_EXIVAR)) {
+ rb_copy_generic_ivar(dest, obj);
+ }
rb_gc_copy_finalizer(dest, obj);
switch (TYPE(obj)) {
case T_OBJECT:
@@ -174,7 +213,8 @@ init_copy(VALUE dest, VALUE obj)
*/
VALUE
-rb_obj_clone(VALUE obj)
+rb_obj_clone(obj)
+ VALUE obj;
{
VALUE clone;
@@ -209,7 +249,8 @@ rb_obj_clone(VALUE obj)
*/
VALUE
-rb_obj_dup(VALUE obj)
+rb_obj_dup(obj)
+ VALUE obj;
{
VALUE dup;
@@ -224,7 +265,8 @@ rb_obj_dup(VALUE obj)
/* :nodoc: */
VALUE
-rb_obj_init_copy(VALUE obj, VALUE orig)
+rb_obj_init_copy(obj, orig)
+ VALUE obj, orig;
{
if (obj == orig) return obj;
rb_check_frozen(obj);
@@ -236,6 +278,30 @@ rb_obj_init_copy(VALUE obj, VALUE orig)
/*
* call-seq:
+ * obj.to_a -> anArray
+ *
+ * Returns an array representation of <i>obj</i>. For objects of class
+ * <code>Object</code> and others that don't explicitly override the
+ * method, the return value is an array containing <code>self</code>.
+ * However, this latter behavior will soon be obsolete.
+ *
+ * self.to_a #=> -:1: warning: default `to_a' will be obsolete
+ * "hello".to_a #=> ["hello"]
+ * Time.new.to_a #=> [39, 54, 8, 9, 4, 2003, 3, 99, true, "CDT"]
+ */
+
+
+static VALUE
+rb_any_to_a(obj)
+ VALUE obj;
+{
+ rb_warn("default `to_a' will be obsolete");
+ return rb_ary_new3(1, obj);
+}
+
+
+/*
+ * call-seq:
* obj.to_s => string
*
* Returns a string representing <i>obj</i>. The default
@@ -245,34 +311,43 @@ rb_obj_init_copy(VALUE obj, VALUE orig)
*/
VALUE
-rb_any_to_s(VALUE obj)
+rb_any_to_s(obj)
+ VALUE obj;
{
char *cname = rb_obj_classname(obj);
+ size_t len;
VALUE str;
- str = rb_sprintf("#<%s:%p>", cname, (void*)obj);
+ len = strlen(cname)+6+16;
+ str = rb_str_new(0, len); /* 6:tags 16:addr */
+ snprintf(RSTRING(str)->ptr, len+1, "#<%s:0x%lx>", cname, obj);
+ RSTRING(str)->len = strlen(RSTRING(str)->ptr);
if (OBJ_TAINTED(obj)) OBJ_TAINT(str);
return str;
}
VALUE
-rb_inspect(VALUE obj)
+rb_inspect(obj)
+ VALUE obj;
{
return rb_obj_as_string(rb_funcall(obj, id_inspect, 0, 0));
}
static int
-inspect_i(ID id, VALUE value, VALUE str)
+inspect_i(id, value, str)
+ ID id;
+ VALUE value;
+ VALUE str;
{
VALUE str2;
- const char *ivname;
+ char *ivname;
/* need not to show internal data */
if (CLASS_OF(value) == 0) return ST_CONTINUE;
if (!rb_is_instance_id(id)) return ST_CONTINUE;
- if (RSTRING_PTR(str)[0] == '-') { /* first element */
- RSTRING_PTR(str)[0] = '#';
+ if (RSTRING(str)->ptr[0] == '-') { /* first element */
+ RSTRING(str)->ptr[0] = '#';
rb_str_cat2(str, " ");
}
else {
@@ -289,16 +364,12 @@ inspect_i(ID id, VALUE value, VALUE str)
}
static VALUE
-inspect_obj(VALUE obj, VALUE str, int recur)
+inspect_obj(obj, str)
+ VALUE obj, str;
{
- if (recur) {
- rb_str_cat2(str, " ...");
- }
- else {
- st_foreach_safe(ROBJECT(obj)->iv_tbl, inspect_i, str);
- }
+ st_foreach_safe(ROBJECT(obj)->iv_tbl, inspect_i, str);
rb_str_cat2(str, ">");
- RSTRING_PTR(str)[0] = '#';
+ RSTRING(str)->ptr[0] = '#';
OBJ_INFECT(str, obj);
return str;
@@ -318,17 +389,29 @@ inspect_obj(VALUE obj, VALUE str, int recur)
static VALUE
-rb_obj_inspect(VALUE obj)
+rb_obj_inspect(obj)
+ VALUE obj;
{
if (TYPE(obj) == T_OBJECT
&& ROBJECT(obj)->iv_tbl
&& ROBJECT(obj)->iv_tbl->num_entries > 0) {
VALUE str;
+ size_t len;
char *c;
c = rb_obj_classname(obj);
- str = rb_sprintf("-<%s:%p", c, (void*)obj);
- return rb_exec_recursive(inspect_obj, obj, str);
+ if (rb_inspecting_p(obj)) {
+ len = strlen(c)+10+16+1;
+ str = rb_str_new(0, len); /* 10:tags 16:addr 1:nul */
+ snprintf(RSTRING(str)->ptr, len, "#<%s:0x%lx ...>", c, obj);
+ RSTRING(str)->len = strlen(RSTRING(str)->ptr);
+ return str;
+ }
+ len = strlen(c)+6+16+1;
+ str = rb_str_new(0, len); /* 6:tags 16:addr 1:nul */
+ snprintf(RSTRING(str)->ptr, len, "-<%s:0x%lx", c, obj);
+ RSTRING(str)->len = strlen(RSTRING(str)->ptr);
+ return rb_protect_inspect(inspect_obj, obj, str);
}
return rb_funcall(obj, rb_intern("to_s"), 0, 0);
}
@@ -343,7 +426,8 @@ rb_obj_inspect(VALUE obj)
*/
VALUE
-rb_obj_is_instance_of(VALUE obj, VALUE c)
+rb_obj_is_instance_of(obj, c)
+ VALUE obj, c;
{
switch (TYPE(c)) {
case T_MODULE:
@@ -386,7 +470,8 @@ rb_obj_is_instance_of(VALUE obj, VALUE c)
*/
VALUE
-rb_obj_is_kind_of(VALUE obj, VALUE c)
+rb_obj_is_kind_of(obj, c)
+ VALUE obj, c;
{
VALUE cl = CLASS_OF(obj);
@@ -543,7 +628,7 @@ rb_obj_is_kind_of(VALUE obj, VALUE c)
*/
static VALUE
-rb_obj_dummy(void)
+rb_obj_dummy()
{
return Qnil;
}
@@ -556,7 +641,8 @@ rb_obj_dummy(void)
*/
VALUE
-rb_obj_tainted(VALUE obj)
+rb_obj_tainted(obj)
+ VALUE obj;
{
if (OBJ_TAINTED(obj))
return Qtrue;
@@ -573,7 +659,8 @@ rb_obj_tainted(VALUE obj)
*/
VALUE
-rb_obj_taint(VALUE obj)
+rb_obj_taint(obj)
+ VALUE obj;
{
rb_secure(4);
if (!OBJ_TAINTED(obj)) {
@@ -594,7 +681,8 @@ rb_obj_taint(VALUE obj)
*/
VALUE
-rb_obj_untaint(VALUE obj)
+rb_obj_untaint(obj)
+ VALUE obj;
{
rb_secure(3);
if (OBJ_TAINTED(obj)) {
@@ -607,7 +695,8 @@ rb_obj_untaint(VALUE obj)
}
void
-rb_obj_infect(VALUE obj1, VALUE obj2)
+rb_obj_infect(obj1, obj2)
+ VALUE obj1, obj2;
{
OBJ_INFECT(obj1, obj2);
}
@@ -633,7 +722,8 @@ rb_obj_infect(VALUE obj1, VALUE obj2)
*/
VALUE
-rb_obj_freeze(VALUE obj)
+rb_obj_freeze(obj)
+ VALUE obj;
{
if (!OBJ_FROZEN(obj)) {
if (rb_safe_level() >= 4 && !OBJ_TAINTED(obj)) {
@@ -656,7 +746,8 @@ rb_obj_freeze(VALUE obj)
*/
static VALUE
-rb_obj_frozen_p(VALUE obj)
+rb_obj_frozen_p(obj)
+ VALUE obj;
{
if (OBJ_FROZEN(obj)) return Qtrue;
return Qfalse;
@@ -680,7 +771,8 @@ rb_obj_frozen_p(VALUE obj)
static VALUE
-nil_to_i(VALUE obj)
+nil_to_i(obj)
+ VALUE obj;
{
return INT2FIX(0);
}
@@ -695,7 +787,8 @@ nil_to_i(VALUE obj)
*/
static VALUE
-nil_to_f(VALUE obj)
+nil_to_f(obj)
+ VALUE obj;
{
return rb_float_new(0.0);
}
@@ -705,17 +798,18 @@ nil_to_f(VALUE obj)
* nil.to_s => ""
*
* Always returns the empty string.
+ *
+ * nil.to_s #=> ""
*/
static VALUE
-nil_to_s(VALUE obj)
+nil_to_s(obj)
+ VALUE obj;
{
return rb_str_new2("");
}
/*
- * Document-method: to_a
- *
* call-seq:
* nil.to_a => []
*
@@ -724,18 +818,9 @@ nil_to_s(VALUE obj)
* nil.to_a #=> []
*/
-/*
- * Document-method: to_splat
- *
- * call-seq:
- * nil.to_splat => []
- *
- * Always returns an empty array.
- *
- */
-
static VALUE
-nil_to_a(VALUE obj)
+nil_to_a(obj)
+ VALUE obj;
{
return rb_ary_new2(0);
}
@@ -748,34 +833,15 @@ nil_to_a(VALUE obj)
*/
static VALUE
-nil_inspect(VALUE obj)
+nil_inspect(obj)
+ VALUE obj;
{
return rb_str_new2("nil");
}
-#ifdef NIL_PLUS
static VALUE
-nil_plus(VALUE x, VALUE 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_PTR(rb_inspect(y)),
- rb_obj_classname(y));
- }
- /* not reached */
-}
-#endif
-
-static VALUE
-main_to_s(VALUE obj)
+main_to_s(obj)
+ VALUE obj;
{
return rb_str_new2("main");
}
@@ -799,7 +865,8 @@ main_to_s(VALUE obj)
*/
static VALUE
-true_to_s(VALUE obj)
+true_to_s(obj)
+ VALUE obj;
{
return rb_str_new2("true");
}
@@ -814,7 +881,8 @@ true_to_s(VALUE obj)
*/
static VALUE
-true_and(VALUE obj, VALUE obj2)
+true_and(obj, obj2)
+ VALUE obj, obj2;
{
return RTEST(obj2)?Qtrue:Qfalse;
}
@@ -836,7 +904,8 @@ true_and(VALUE obj, VALUE obj2)
*/
static VALUE
-true_or(VALUE obj, VALUE obj2)
+true_or(obj, obj2)
+ VALUE obj, obj2;
{
return Qtrue;
}
@@ -852,7 +921,8 @@ true_or(VALUE obj, VALUE obj2)
*/
static VALUE
-true_xor(VALUE obj, VALUE obj2)
+true_xor(obj, obj2)
+ VALUE obj, obj2;
{
return RTEST(obj2)?Qfalse:Qtrue;
}
@@ -876,7 +946,8 @@ true_xor(VALUE obj, VALUE obj2)
*/
static VALUE
-false_to_s(VALUE obj)
+false_to_s(obj)
+ VALUE obj;
{
return rb_str_new2("false");
}
@@ -892,7 +963,8 @@ false_to_s(VALUE obj)
*/
static VALUE
-false_and(VALUE obj, VALUE obj2)
+false_and(obj, obj2)
+ VALUE obj, obj2;
{
return Qfalse;
}
@@ -908,7 +980,8 @@ false_and(VALUE obj, VALUE obj2)
*/
static VALUE
-false_or(VALUE obj, VALUE obj2)
+false_or(obj, obj2)
+ VALUE obj, obj2;
{
return RTEST(obj2)?Qtrue:Qfalse;
}
@@ -927,7 +1000,8 @@ false_or(VALUE obj, VALUE obj2)
*/
static VALUE
-false_xor(VALUE obj, VALUE obj2)
+false_xor(obj, obj2)
+ VALUE obj, obj2;
{
return RTEST(obj2)?Qtrue:Qfalse;
}
@@ -940,7 +1014,8 @@ false_xor(VALUE obj, VALUE obj2)
*/
static VALUE
-rb_true(VALUE obj)
+rb_true(obj)
+ VALUE obj;
{
return Qtrue;
}
@@ -955,7 +1030,8 @@ rb_true(VALUE obj)
static VALUE
-rb_false(VALUE obj)
+rb_false(obj)
+ VALUE obj;
{
return Qfalse;
}
@@ -963,7 +1039,7 @@ rb_false(VALUE obj)
/*
* call-seq:
- * obj =~ other => nil
+ * obj =~ other => false
*
* Pattern Match---Overridden by descendents (notably
* <code>Regexp</code> and <code>String</code>) to provide meaningful
@@ -971,9 +1047,139 @@ rb_false(VALUE obj)
*/
static VALUE
-rb_obj_pattern_match(VALUE obj1, VALUE obj2)
+rb_obj_pattern_match(obj1, obj2)
+ VALUE obj1, obj2;
{
- return Qnil;
+ return Qfalse;
+}
+
+/**********************************************************************
+ * Document-class: Symbol
+ *
+ * <code>Symbol</code> objects represent names and some strings
+ * inside the Ruby
+ * interpreter. They are generated using the <code>:name</code> and
+ * <code>:"string"</code> literals
+ * syntax, and by the various <code>to_sym</code> methods. The same
+ * <code>Symbol</code> object will be created for a given name or string
+ * for the duration of a program's execution, regardless of the context
+ * or meaning of that name. Thus if <code>Fred</code> is a constant in
+ * one context, a method in another, and a class in a third, the
+ * <code>Symbol</code> <code>:Fred</code> will be the same object in
+ * all three contexts.
+ *
+ * module One
+ * class Fred
+ * end
+ * $f1 = :Fred
+ * end
+ * module Two
+ * Fred = 1
+ * $f2 = :Fred
+ * end
+ * def Fred()
+ * end
+ * $f3 = :Fred
+ * $f1.id #=> 2514190
+ * $f2.id #=> 2514190
+ * $f3.id #=> 2514190
+ *
+ */
+
+/*
+ * call-seq:
+ * sym.to_i => fixnum
+ *
+ * Returns an integer that is unique for each symbol within a
+ * particular execution of a program.
+ *
+ * :fred.to_i #=> 9809
+ * "fred".to_sym.to_i #=> 9809
+ */
+
+static VALUE
+sym_to_i(sym)
+ VALUE sym;
+{
+ ID id = SYM2ID(sym);
+
+ return LONG2FIX(id);
+}
+
+
+/* :nodoc: */
+
+static VALUE
+sym_to_int(sym)
+ VALUE sym;
+{
+ rb_warning("treating Symbol as an integer");
+ return sym_to_i(sym);
+}
+
+
+/*
+ * call-seq:
+ * sym.inspect => string
+ *
+ * Returns the representation of <i>sym</i> as a symbol literal.
+ *
+ * :fred.inspect #=> ":fred"
+ */
+
+static VALUE
+sym_inspect(sym)
+ VALUE sym;
+{
+ VALUE str;
+ char *name;
+ ID id = SYM2ID(sym);
+
+ name = rb_id2name(id);
+ str = rb_str_new(0, strlen(name)+1);
+ RSTRING(str)->ptr[0] = ':';
+ strcpy(RSTRING(str)->ptr+1, name);
+ if (!rb_symname_p(name)) {
+ str = rb_str_dump(str);
+ strncpy(RSTRING(str)->ptr, ":\"", 2);
+ }
+ return str;
+}
+
+
+/*
+ * call-seq:
+ * sym.id2name => string
+ * sym.to_s => string
+ *
+ * Returns the name or string corresponding to <i>sym</i>.
+ *
+ * :fred.id2name #=> "fred"
+ */
+
+
+static VALUE
+sym_to_s(sym)
+ VALUE sym;
+{
+ return rb_str_new2(rb_id2name(SYM2ID(sym)));
+}
+
+
+/*
+ * call-seq:
+ * sym.to_sym => sym
+ *
+ * In general, <code>to_sym</code> returns the <code>Symbol</code> corresponding
+ * to an object. As <i>sym</i> is already a symbol, <code>self</code> is returned
+ * in this case.
+ */
+
+static VALUE
+sym_to_sym(sym)
+ VALUE sym;
+{
+ return sym;
}
@@ -1015,7 +1221,9 @@ rb_obj_pattern_match(VALUE obj1, VALUE obj2)
*/
static VALUE
-rb_mod_to_s(VALUE klass)
+rb_mod_to_s(klass)
+ VALUE klass;
+
{
if (FL_TEST(klass, FL_SINGLETON)) {
VALUE s = rb_str_new2("#<");
@@ -1045,7 +1253,8 @@ rb_mod_to_s(VALUE klass)
*/
static VALUE
-rb_mod_freeze(VALUE mod)
+rb_mod_freeze(mod)
+ VALUE mod;
{
rb_mod_to_s(mod);
return rb_obj_freeze(mod);
@@ -1062,7 +1271,8 @@ rb_mod_freeze(VALUE mod)
*/
static VALUE
-rb_mod_eqq(VALUE mod, VALUE arg)
+rb_mod_eqq(mod, arg)
+ VALUE mod, arg;
{
return rb_obj_is_kind_of(arg, mod);
}
@@ -1080,7 +1290,8 @@ rb_mod_eqq(VALUE mod, VALUE arg)
*/
VALUE
-rb_class_inherited_p(VALUE mod, VALUE arg)
+rb_class_inherited_p(mod, arg)
+ VALUE mod, arg;
{
VALUE start = mod;
@@ -1092,6 +1303,12 @@ rb_class_inherited_p(VALUE mod, VALUE arg)
default:
rb_raise(rb_eTypeError, "compared with non class/module");
}
+
+ if (FL_TEST(mod, FL_SINGLETON)) {
+ if (RCLASS(mod)->m_tbl == RCLASS(arg)->m_tbl)
+ return Qtrue;
+ mod = RBASIC(mod)->klass;
+ }
while (mod) {
if (RCLASS(mod)->m_tbl == RCLASS(arg)->m_tbl)
return Qtrue;
@@ -1118,7 +1335,8 @@ rb_class_inherited_p(VALUE mod, VALUE arg)
*/
static VALUE
-rb_mod_lt(VALUE mod, VALUE arg)
+rb_mod_lt(mod, arg)
+ VALUE mod, arg;
{
if (mod == arg) return Qfalse;
return rb_class_inherited_p(mod, arg);
@@ -1138,7 +1356,8 @@ rb_mod_lt(VALUE mod, VALUE arg)
*/
static VALUE
-rb_mod_ge(VALUE mod, VALUE arg)
+rb_mod_ge(mod, arg)
+ VALUE mod, arg;
{
switch (TYPE(arg)) {
case T_MODULE:
@@ -1163,7 +1382,8 @@ rb_mod_ge(VALUE mod, VALUE arg)
*/
static VALUE
-rb_mod_gt(VALUE mod, VALUE arg)
+rb_mod_gt(mod, arg)
+ VALUE mod, arg;
{
if (mod == arg) return Qfalse;
return rb_mod_ge(mod, arg);
@@ -1181,7 +1401,8 @@ rb_mod_gt(VALUE mod, VALUE arg)
*/
static VALUE
-rb_mod_cmp(VALUE mod, VALUE arg)
+rb_mod_cmp(mod, arg)
+ VALUE mod, arg;
{
VALUE cmp;
@@ -1202,8 +1423,10 @@ rb_mod_cmp(VALUE mod, VALUE arg)
return INT2FIX(1);
}
+static VALUE rb_module_s_alloc _((VALUE));
static VALUE
-rb_module_s_alloc(VALUE klass)
+rb_module_s_alloc(klass)
+ VALUE klass;
{
VALUE mod = rb_module_new();
@@ -1211,8 +1434,10 @@ rb_module_s_alloc(VALUE klass)
return mod;
}
+static VALUE rb_class_s_alloc _((VALUE));
static VALUE
-rb_class_s_alloc(VALUE klass)
+rb_class_s_alloc(klass)
+ VALUE klass;
{
return rb_class_boot(0);
}
@@ -1241,10 +1466,11 @@ rb_class_s_alloc(VALUE klass)
*/
static VALUE
-rb_mod_initialize(VALUE module)
+rb_mod_initialize(module)
+ VALUE module;
{
if (rb_block_given_p()) {
- rb_mod_module_exec(1, &module, module);
+ rb_mod_module_eval(0, 0, module);
}
return Qnil;
}
@@ -1260,7 +1486,10 @@ rb_mod_initialize(VALUE module)
*/
static VALUE
-rb_class_initialize(int argc, VALUE *argv, VALUE klass)
+rb_class_initialize(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE super;
@@ -1275,8 +1504,8 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass)
}
RCLASS(klass)->super = super;
rb_make_metaclass(klass, RBASIC(super)->klass);
- rb_class_inherited(super, klass);
rb_mod_initialize(klass);
+ rb_class_inherited(super, klass);
return klass;
}
@@ -1291,15 +1520,16 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass)
*/
VALUE
-rb_obj_alloc(VALUE klass)
+rb_obj_alloc(klass)
+ VALUE klass;
{
VALUE obj;
- if (RCLASS(klass)->super == 0 && klass != rb_cBasicObject) {
+ if (RCLASS(klass)->super == 0) {
rb_raise(rb_eTypeError, "can't instantiate uninitialized class");
}
if (FL_TEST(klass, FL_SINGLETON)) {
- rb_raise(rb_eTypeError, "can't create instance of singleton class");
+ rb_raise(rb_eTypeError, "can't create instance of virtual class");
}
obj = rb_funcall(klass, ID_ALLOCATOR, 0, 0);
if (rb_obj_class(obj) != rb_class_real(klass)) {
@@ -1308,8 +1538,10 @@ rb_obj_alloc(VALUE klass)
return obj;
}
+static VALUE rb_class_allocate_instance _((VALUE));
static VALUE
-rb_class_allocate_instance(VALUE klass)
+rb_class_allocate_instance(klass)
+ VALUE klass;
{
NEWOBJ(obj, struct RObject);
OBJSETUP(obj, klass, T_OBJECT);
@@ -1329,7 +1561,10 @@ rb_class_allocate_instance(VALUE klass)
*/
VALUE
-rb_class_new_instance(int argc, VALUE *argv, VALUE klass)
+rb_class_new_instance(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
VALUE obj;
@@ -1352,13 +1587,17 @@ rb_class_new_instance(int argc, VALUE *argv, VALUE klass)
*/
static VALUE
-rb_class_superclass(VALUE klass)
+rb_class_superclass(klass)
+ VALUE klass;
{
VALUE super = RCLASS(klass)->super;
if (!super) {
rb_raise(rb_eTypeError, "uninitialized class");
}
+ if (FL_TEST(klass, FL_SINGLETON)) {
+ super = RBASIC(klass)->klass;
+ }
while (TYPE(super) == T_ICLASS) {
super = RCLASS(super)->super;
}
@@ -1368,10 +1607,87 @@ rb_class_superclass(VALUE klass)
return super;
}
+static ID
+str_to_id(str)
+ VALUE str;
+{
+ VALUE sym = rb_str_intern(str);
+
+ return SYM2ID(sym);
+}
+
+ID
+rb_to_id(name)
+ VALUE name;
+{
+ VALUE tmp;
+ ID id;
+
+ switch (TYPE(name)) {
+ case T_STRING:
+ return str_to_id(name);
+ case T_FIXNUM:
+ rb_warn("do not use Fixnums as Symbols");
+ id = FIX2LONG(name);
+ if (!rb_id2name(id)) {
+ rb_raise(rb_eArgError, "%ld is not a symbol", id);
+ }
+ break;
+ case T_SYMBOL:
+ id = SYM2ID(name);
+ break;
+ default:
+ tmp = rb_check_string_type(name);
+ if (!NIL_P(tmp)) {
+ return str_to_id(tmp);
+ }
+ rb_raise(rb_eTypeError, "%s is not a symbol", RSTRING(rb_inspect(name))->ptr);
+ }
+ return id;
+}
+
+/*
+ * call-seq:
+ * attr(symbol, writable=false) => nil
+ *
+ * Defines a named attribute for this module, where the name is
+ * <i>symbol.</i><code>id2name</code>, creating an instance variable
+ * (<code>@name</code>) and a corresponding access method to read it.
+ * If the optional <i>writable</i> argument is <code>true</code>, also
+ * creates a method called <code>name=</code> to set the attribute.
+ *
+ * module Mod
+ * attr :size, true
+ * end
+ *
+ * <em>is equivalent to:</em>
+ *
+ * module Mod
+ * def size
+ * @size
+ * end
+ * def size=(val)
+ * @size = val
+ * end
+ * end
+ */
+
+static VALUE
+rb_mod_attr(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
+{
+ VALUE name, pub;
+
+ rb_scan_args(argc, argv, "11", &name, &pub);
+ rb_attr(klass, rb_to_id(name), 1, RTEST(pub), Qtrue);
+ return Qnil;
+}
+
/*
* call-seq:
* attr_reader(symbol, ...) => nil
- * attr(symbol, ...) => nil
*
* Creates instance variables and corresponding methods that return the
* value of each instance variable. Equivalent to calling
@@ -1379,27 +1695,19 @@ rb_class_superclass(VALUE klass)
*/
static VALUE
-rb_mod_attr_reader(int argc, VALUE *argv, VALUE klass)
+rb_mod_attr_reader(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
int i;
for (i=0; i<argc; i++) {
- rb_attr(klass, rb_to_id(argv[i]), Qtrue, Qfalse, Qtrue);
+ rb_attr(klass, rb_to_id(argv[i]), 1, 0, Qtrue);
}
return Qnil;
}
-VALUE
-rb_mod_attr(int argc, VALUE *argv, VALUE klass)
-{
- if (argc == 2 && (argv[1] == Qtrue || argv[1] == Qfalse)) {
- rb_warning("optional boolean argument is obsoleted");
- rb_attr(klass, rb_to_id(argv[0]), 1, RTEST(argv[1]), Qtrue);
- return Qnil;
- }
- return rb_mod_attr_reader(argc, argv, klass);
-}
-
/*
* call-seq:
* attr_writer(symbol, ...) => nil
@@ -1409,12 +1717,15 @@ rb_mod_attr(int argc, VALUE *argv, VALUE klass)
*/
static VALUE
-rb_mod_attr_writer(int argc, VALUE *argv, VALUE klass)
+rb_mod_attr_writer(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
int i;
for (i=0; i<argc; i++) {
- rb_attr(klass, rb_to_id(argv[i]), Qfalse, Qtrue, Qtrue);
+ rb_attr(klass, rb_to_id(argv[i]), 0, 1, Qtrue);
}
return Qnil;
}
@@ -1423,10 +1734,8 @@ rb_mod_attr_writer(int argc, VALUE *argv, VALUE klass)
* call-seq:
* attr_accessor(symbol, ...) => nil
*
- * Defines a named attribute for this module, where the name is
- * <i>symbol.</i><code>id2name</code>, creating an instance variable
- * (<code>@name</code>) and a corresponding access method to read it.
- * Also creates a method called <code>name=</code> to set the attribute.
+ * Equivalent to calling ``<code>attr</code><i>symbol</i><code>,
+ * true</code>'' on each <i>symbol</i> in turn.
*
* module Mod
* attr_accessor(:one, :two)
@@ -1435,46 +1744,38 @@ rb_mod_attr_writer(int argc, VALUE *argv, VALUE klass)
*/
static VALUE
-rb_mod_attr_accessor(int argc, VALUE *argv, VALUE klass)
+rb_mod_attr_accessor(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
int i;
for (i=0; i<argc; i++) {
- rb_attr(klass, rb_to_id(argv[i]), Qtrue, Qtrue, Qtrue);
+ rb_attr(klass, rb_to_id(argv[i]), 1, 1, Qtrue);
}
return Qnil;
}
/*
* call-seq:
- * mod.const_get(sym, inherit=true) => obj
+ * mod.const_get(sym) => obj
*
* Returns the value of the named constant in <i>mod</i>.
*
* Math.const_get(:PI) #=> 3.14159265358979
- *
- * If the constant is not defined or is defined by the ancestors and
- * +inherit+ is false, +NameError+ will be raised.
*/
static VALUE
-rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
+rb_mod_const_get(mod, name)
+ VALUE mod, name;
{
- VALUE name, recur;
- ID id;
+ ID id = rb_to_id(name);
- if (argc == 1) {
- name = argv[0];
- recur = Qtrue;
- }
- else {
- rb_scan_args(argc, argv, "11", &name, &recur);
- }
- id = rb_to_id(name);
if (!rb_is_const_id(id)) {
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
}
- return RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id);
+ return rb_const_get(mod, id);
}
/*
@@ -1490,7 +1791,8 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
*/
static VALUE
-rb_mod_const_set(VALUE mod, VALUE name, VALUE value)
+rb_mod_const_set(mod, name, value)
+ VALUE mod, name, value;
{
ID id = rb_to_id(name);
@@ -1503,34 +1805,24 @@ rb_mod_const_set(VALUE mod, VALUE name, VALUE value)
/*
* call-seq:
- * mod.const_defined?(sym, inherit=true) => true or false
+ * mod.const_defined?(sym) => true or false
*
* Returns <code>true</code> if a constant with the given name is
- * defined by <i>mod</i>, or its ancestors if +inherit+ is not false.
+ * defined by <i>mod</i>.
*
* Math.const_defined? "PI" #=> true
- * IO.const_defined? "SYNC" #=> true
- * IO.const_defined? "SYNC", false #=> false
*/
static VALUE
-rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
+rb_mod_const_defined(mod, name)
+ VALUE mod, name;
{
- VALUE name, recur;
- ID id;
+ ID id = rb_to_id(name);
- if (argc == 1) {
- name = argv[0];
- recur = Qtrue;
- }
- else {
- rb_scan_args(argc, argv, "11", &name, &recur);
- }
- id = rb_to_id(name);
if (!rb_is_const_id(id)) {
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
}
- return RTEST(recur) ? rb_const_defined(mod, id) : rb_const_defined_at(mod, id);
+ return rb_const_defined_at(mod, id);
}
/*
@@ -1553,7 +1845,10 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
*/
static VALUE
-rb_obj_methods(int argc, VALUE *argv, VALUE obj)
+rb_obj_methods(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
retry:
if (argc == 0) {
@@ -1584,7 +1879,10 @@ rb_obj_methods(int argc, VALUE *argv, VALUE obj)
*/
static VALUE
-rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj)
+rb_obj_protected_methods(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
if (argc == 0) { /* hack to stop warning */
VALUE args[1];
@@ -1605,7 +1903,10 @@ rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj)
*/
static VALUE
-rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
+rb_obj_private_methods(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
if (argc == 0) { /* hack to stop warning */
VALUE args[1];
@@ -1626,7 +1927,10 @@ rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
*/
static VALUE
-rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
+rb_obj_public_methods(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
if (argc == 0) { /* hack to stop warning */
VALUE args[1];
@@ -1640,10 +1944,12 @@ rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
/*
* call-seq:
* obj.instance_variable_get(symbol) => obj
- *
- * Returns the value of the given instance variable (or throws a
- * <code>NameError</code> exception). The <code>@</code> part of the
- * variable name should be included for regular instance variables
+ *
+ * Returns the value of the given instance variable, or nil if the
+ * instance variable is not set. The <code>@</code> part of the
+ * variable name should be included for regular instance
+ * variables. Throws a <code>NameError</code> exception if the
+ * supplied symbol is not valid as an instance variable name.
*
* class Fred
* def initialize(p1, p2)
@@ -1656,7 +1962,8 @@ rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
*/
static VALUE
-rb_obj_ivar_get(VALUE obj, VALUE iv)
+rb_obj_ivar_get(obj, iv)
+ VALUE obj, iv;
{
ID id = rb_to_id(iv);
@@ -1687,7 +1994,8 @@ rb_obj_ivar_get(VALUE obj, VALUE iv)
*/
static VALUE
-rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val)
+rb_obj_ivar_set(obj, iv, val)
+ VALUE obj, iv, val;
{
ID id = rb_to_id(iv);
@@ -1716,7 +2024,8 @@ rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val)
*/
static VALUE
-rb_obj_ivar_defined(VALUE obj, VALUE iv)
+rb_obj_ivar_defined(obj, iv)
+ VALUE obj, iv;
{
ID id = rb_to_id(iv);
@@ -1737,11 +2046,15 @@ rb_obj_ivar_defined(VALUE obj, VALUE iv)
* class Fred
* @@foo = 99
* end
- * Fred.class_variable_get(:@@foo) #=> 99
+ *
+ * def Fred.foo
+ * class_variable_get(:@@foo) #=> 99
+ * end
*/
static VALUE
-rb_mod_cvar_get(VALUE obj, VALUE iv)
+rb_mod_cvar_get(obj, iv)
+ VALUE obj, iv;
{
ID id = rb_to_id(iv);
@@ -1764,12 +2077,17 @@ rb_mod_cvar_get(VALUE obj, VALUE iv)
* @@foo
* end
* end
- * Fred.class_variable_set(:@@foo, 101) #=> 101
+ *
+ * def Fred.foo
+ * class_variable_set(:@@foo, 101) #=> 101
+ * end
+ * Fred.foo
* Fred.new.foo #=> 101
*/
static VALUE
-rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val)
+rb_mod_cvar_set(obj, iv, val)
+ VALUE obj, iv, val;
{
ID id = rb_to_id(iv);
@@ -1795,7 +2113,8 @@ rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val)
*/
static VALUE
-rb_mod_cvar_defined(VALUE obj, VALUE iv)
+rb_mod_cvar_defined(obj, iv)
+ VALUE obj, iv;
{
ID id = rb_to_id(iv);
@@ -1806,7 +2125,10 @@ rb_mod_cvar_defined(VALUE obj, VALUE iv)
}
static VALUE
-convert_type(VALUE val, const char *tname, const char *method, int raise)
+convert_type(val, tname, method, raise)
+ VALUE val;
+ const char *tname, *method;
+ int raise;
{
ID m;
@@ -1828,22 +2150,27 @@ convert_type(VALUE val, const char *tname, const char *method, int raise)
}
VALUE
-rb_convert_type(VALUE val, int type, const char *tname, const char *method)
+rb_convert_type(val, type, tname, method)
+ VALUE val;
+ int type;
+ const char *tname, *method;
{
VALUE v;
if (TYPE(val) == type) return val;
v = convert_type(val, tname, method, Qtrue);
if (TYPE(v) != type) {
- char *cname = rb_obj_classname(val);
- rb_raise(rb_eTypeError, "can't convert %s to %s (%s#%s gives %s)",
- cname, tname, cname, method, rb_obj_classname(v));
+ rb_raise(rb_eTypeError, "%s#%s should return %s",
+ rb_obj_classname(val), method, tname);
}
return v;
}
VALUE
-rb_check_convert_type(VALUE val, int type, const char *tname, const char *method)
+rb_check_convert_type(val, type, tname, method)
+ VALUE val;
+ int type;
+ const char *tname, *method;
{
VALUE v;
@@ -1852,44 +2179,36 @@ rb_check_convert_type(VALUE val, int type, const char *tname, const char *method
v = convert_type(val, tname, method, Qfalse);
if (NIL_P(v)) return Qnil;
if (TYPE(v) != type) {
- char *cname = rb_obj_classname(val);
- rb_raise(rb_eTypeError, "can't convert %s to %s (%s#%s gives %s)",
- cname, tname, cname, method, rb_obj_classname(v));
+ rb_raise(rb_eTypeError, "%s#%s should return %s",
+ rb_obj_classname(val), method, tname);
}
return v;
}
static VALUE
-rb_to_integer(VALUE val, const char *method)
+rb_to_integer(val, method)
+ VALUE val;
+ const char *method;
{
VALUE v = convert_type(val, "Integer", method, Qtrue);
if (!rb_obj_is_kind_of(v, rb_cInteger)) {
- char *cname = rb_obj_classname(val);
- rb_raise(rb_eTypeError, "can't convert %s to Integer (%s#%s gives %s)",
- cname, cname, method, rb_obj_classname(v));
- }
- return v;
-}
-
-VALUE
-rb_check_to_integer(VALUE val, const char *method)
-{
- VALUE v = convert_type(val, "Integer", method, Qfalse);
- if (!rb_obj_is_kind_of(v, rb_cInteger)) {
- return Qnil;
+ rb_raise(rb_eTypeError, "%s#%s should return Integer",
+ rb_obj_classname(val), method);
}
return v;
}
VALUE
-rb_to_int(VALUE val)
+rb_to_int(val)
+ VALUE val;
{
return rb_to_integer(val, "to_int");
}
VALUE
-rb_Integer(VALUE val)
+rb_Integer(val)
+ VALUE val;
{
VALUE tmp;
@@ -1908,10 +2227,6 @@ rb_Integer(VALUE val)
case T_STRING:
return rb_str_to_inum(val, 0, Qtrue);
- case T_NIL:
- rb_raise(rb_eTypeError, "can't convert nil into Integer");
- break;
-
default:
break;
}
@@ -1940,13 +2255,16 @@ rb_Integer(VALUE val)
*/
static VALUE
-rb_f_integer(VALUE obj, VALUE arg)
+rb_f_integer(obj, arg)
+ VALUE obj, arg;
{
return rb_Integer(arg);
}
double
-rb_cstr_to_dbl(const char *p, int badcheck)
+rb_cstr_to_dbl(p, badcheck)
+ const char *p;
+ int badcheck;
{
const char *q;
char *end;
@@ -1957,7 +2275,13 @@ rb_cstr_to_dbl(const char *p, int badcheck)
if (!p) return 0.0;
q = p;
- while (ISSPACE(*p)) p++;
+ if (badcheck) {
+ while (ISSPACE(*p)) p++;
+ }
+ else {
+ while (ISSPACE(*p) || *p == '_') p++;
+ }
+ errno = 0;
d = strtod(p, &end);
if (errno == ERANGE) {
OutOfRange();
@@ -1965,8 +2289,8 @@ rb_cstr_to_dbl(const char *p, int badcheck)
errno = 0;
}
if (p == end) {
- bad:
if (badcheck) {
+ bad:
rb_invalid_str(q, "Float()");
}
return d;
@@ -1979,11 +2303,14 @@ rb_cstr_to_dbl(const char *p, int badcheck)
while (*p) {
if (*p == '_') {
/* remove underscores between digits */
- if (n == buf || !ISDIGIT(n[-1])) goto bad;
- while (*++p == '_');
- if (!ISDIGIT(*p)) {
- if (badcheck) goto bad;
- break;
+ if (badcheck) {
+ if (n == buf || !ISDIGIT(n[-1])) goto bad;
+ ++p;
+ if (!ISDIGIT(*p)) goto bad;
+ }
+ else {
+ while (*++p == '_');
+ continue;
}
}
*n++ = *p++;
@@ -2011,14 +2338,16 @@ rb_cstr_to_dbl(const char *p, int badcheck)
}
double
-rb_str_to_dbl(VALUE str, int badcheck)
+rb_str_to_dbl(str, badcheck)
+ VALUE str;
+ int badcheck;
{
char *s;
long len;
StringValue(str);
- s = RSTRING_PTR(str);
- len = RSTRING_LEN(str);
+ s = RSTRING(str)->ptr;
+ len = RSTRING(str)->len;
if (s) {
if (s[len]) { /* no sentinel somehow */
char *p = ALLOCA_N(char, len+1);
@@ -2035,7 +2364,8 @@ rb_str_to_dbl(VALUE str, int badcheck)
}
VALUE
-rb_Float(VALUE val)
+rb_Float(val)
+ VALUE val;
{
switch (TYPE(val)) {
case T_FIXNUM:
@@ -2078,13 +2408,15 @@ rb_Float(VALUE val)
*/
static VALUE
-rb_f_float(VALUE obj, VALUE arg)
+rb_f_float(obj, arg)
+ VALUE obj, arg;
{
return rb_Float(arg);
}
double
-rb_num2dbl(VALUE val)
+rb_num2dbl(val)
+ VALUE val;
{
switch (TYPE(val)) {
case T_FLOAT:
@@ -2106,18 +2438,21 @@ rb_num2dbl(VALUE val)
}
char*
-rb_str2cstr(VALUE str, long *len)
+rb_str2cstr(str, len)
+ VALUE str;
+ long *len;
{
StringValue(str);
- if (len) *len = RSTRING_LEN(str);
- else if (RTEST(ruby_verbose) && RSTRING_LEN(str) != strlen(RSTRING_PTR(str))) {
+ if (len) *len = RSTRING(str)->len;
+ else if (RTEST(ruby_verbose) && RSTRING(str)->len != strlen(RSTRING(str)->ptr)) {
rb_warn("string contains \\0 character");
}
- return RSTRING_PTR(str);
+ return RSTRING(str)->ptr;
}
VALUE
-rb_String(VALUE val)
+rb_String(val)
+ VALUE val;
{
return rb_convert_type(val, T_STRING, "String", "to_s");
}
@@ -2136,21 +2471,28 @@ rb_String(VALUE val)
*/
static VALUE
-rb_f_string(VALUE obj, VALUE arg)
+rb_f_string(obj, arg)
+ VALUE obj, arg;
{
return rb_String(arg);
}
+#if 0
VALUE
-rb_Array(VALUE val)
+rb_Array(val)
+ VALUE val;
{
VALUE tmp = rb_check_array_type(val);
if (NIL_P(tmp)) {
- return rb_convert_type(val, T_ARRAY, "Array", "to_a");
+ tmp = rb_check_convert_type(val, T_ARRAY, "Array", "to_a");
+ if (NIL_P(tmp)) {
+ return rb_ary_new3(1, val);
+ }
}
return tmp;
}
+#endif
/*
* call-seq:
@@ -2158,18 +2500,23 @@ rb_Array(VALUE val)
*
* Returns <i>arg</i> as an <code>Array</code>. First tries to call
* <i>arg</i><code>.to_ary</code>, then <i>arg</i><code>.to_a</code>.
+ * If both fail, creates a single element array containing <i>arg</i>
+ * (unless <i>arg</i> is <code>nil</code>).
*
* Array(1..5) #=> [1, 2, 3, 4, 5]
*/
static VALUE
-rb_f_array(VALUE obj, VALUE arg)
+rb_f_array(obj, arg)
+ VALUE obj, arg;
{
return rb_Array(arg);
}
static VALUE
-boot_defclass(const char *name, VALUE super)
+boot_defclass(name, super)
+ char *name;
+ VALUE super;
{
extern st_table *rb_class_tbl;
VALUE obj = rb_class_boot(super);
@@ -2220,12 +2567,9 @@ VALUE ruby_top_self;
* that follows, the vertical arrows represent inheritance, and the
* parentheses meta-classes. All metaclasses are instances
* of the class `Class'.
- *
- * +-----------------+
- * | |
- * BasicObject-->(BasicObject) |
- * ^ ^ |
- * | | |
+ *
+ * +------------------+
+ * | |
* Object---->(Object) |
* ^ ^ ^ ^ |
* | | | | |
@@ -2245,12 +2589,10 @@ VALUE ruby_top_self;
/*
- * <code>BasicObject</code> is the parent class of all classes in Ruby.
- * It's an explicit blank class. <code>Object</code>, the root of Ruby's
- * class hierarchy is a direct subclass of <code>BasicObject</code>. Its
+ * <code>Object</code> is the parent class of all classes in Ruby. Its
* methods are therefore available to all objects unless explicitly
* overridden.
- *
+ *
* <code>Object</code> mixes in the <code>Kernel</code> module, making
* the built-in kernel functions globally accessible. Although the
* instance methods of <code>Object</code> are defined by the
@@ -2263,27 +2605,22 @@ VALUE ruby_top_self;
*/
void
-Init_Object(void)
+Init_Object()
{
VALUE metaclass;
- rb_cBasicObject = boot_defclass("BasicObject", 0);
- rb_cObject = boot_defclass("Object", rb_cBasicObject);
+ rb_cObject = boot_defclass("Object", 0);
rb_cModule = boot_defclass("Module", rb_cObject);
rb_cClass = boot_defclass("Class", rb_cModule);
- metaclass = rb_make_metaclass(rb_cBasicObject, rb_cClass);
- metaclass = rb_make_metaclass(rb_cObject, metaclass);
+ metaclass = rb_make_metaclass(rb_cObject, rb_cClass);
metaclass = rb_make_metaclass(rb_cModule, metaclass);
metaclass = rb_make_metaclass(rb_cClass, metaclass);
- rb_define_private_method(rb_cBasicObject, "initialize", rb_obj_dummy, 0);
- rb_define_alloc_func(rb_cBasicObject, rb_class_allocate_instance);
- rb_define_method(rb_cBasicObject, "==", rb_obj_equal, 1);
- rb_define_method(rb_cBasicObject, "equal?", rb_obj_equal, 1);
-
rb_mKernel = rb_define_module("Kernel");
rb_include_module(rb_cObject, rb_mKernel);
+ rb_define_alloc_func(rb_cObject, rb_class_allocate_instance);
+ rb_define_private_method(rb_cObject, "initialize", rb_obj_dummy, 0);
rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, "included", rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, "extended", rb_obj_dummy, 1);
@@ -2291,12 +2628,17 @@ Init_Object(void)
rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy, 1);
+
rb_define_method(rb_mKernel, "nil?", rb_false, 0);
+ rb_define_method(rb_mKernel, "==", rb_obj_equal, 1);
+ rb_define_method(rb_mKernel, "equal?", rb_obj_equal, 1);
rb_define_method(rb_mKernel, "===", rb_equal, 1);
rb_define_method(rb_mKernel, "=~", rb_obj_pattern_match, 1);
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
+ rb_define_method(rb_mKernel, "id", rb_obj_id_obsolete, 0);
+ rb_define_method(rb_mKernel, "type", rb_obj_type, 0);
rb_define_method(rb_mKernel, "class", rb_obj_class, 0);
rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);
@@ -2309,14 +2651,18 @@ Init_Object(void)
rb_define_method(rb_mKernel, "freeze", rb_obj_freeze, 0);
rb_define_method(rb_mKernel, "frozen?", rb_obj_frozen_p, 0);
+ rb_define_method(rb_mKernel, "to_a", rb_any_to_a, 0); /* to be removed */
rb_define_method(rb_mKernel, "to_s", rb_any_to_s, 0);
rb_define_method(rb_mKernel, "inspect", rb_obj_inspect, 0);
rb_define_method(rb_mKernel, "methods", rb_obj_methods, -1);
- rb_define_method(rb_mKernel, "singleton_methods", rb_obj_singleton_methods, -1); /* in class.c */
- rb_define_method(rb_mKernel, "protected_methods", rb_obj_protected_methods, -1);
+ rb_define_method(rb_mKernel, "singleton_methods",
+ rb_obj_singleton_methods, -1); /* in class.c */
+ rb_define_method(rb_mKernel, "protected_methods",
+ rb_obj_protected_methods, -1);
rb_define_method(rb_mKernel, "private_methods", rb_obj_private_methods, -1);
rb_define_method(rb_mKernel, "public_methods", rb_obj_public_methods, -1);
- rb_define_method(rb_mKernel, "instance_variables", rb_obj_instance_variables, 0); /* in variable.c */
+ rb_define_method(rb_mKernel, "instance_variables",
+ rb_obj_instance_variables, 0); /* in variable.c */
rb_define_method(rb_mKernel, "instance_variable_get", rb_obj_ivar_get, 1);
rb_define_method(rb_mKernel, "instance_variable_set", rb_obj_ivar_set, 2);
rb_define_method(rb_mKernel, "instance_variable_defined?", rb_obj_ivar_defined, 1);
@@ -2332,7 +2678,7 @@ Init_Object(void)
rb_define_private_method(rb_mKernel, "singleton_method_undefined", rb_obj_dummy, 1);
rb_define_global_function("sprintf", rb_f_sprintf, -1); /* in sprintf.c */
- rb_define_global_function("format", rb_f_sprintf, -1); /* in sprintf.c */
+ rb_define_global_function("format", rb_f_sprintf, -1); /* in sprintf.c */
rb_define_global_function("Integer", rb_f_integer, 1);
rb_define_global_function("Float", rb_f_float, 1);
@@ -2345,7 +2691,6 @@ Init_Object(void)
rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0);
rb_define_method(rb_cNilClass, "to_s", nil_to_s, 0);
rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0);
- rb_define_method(rb_cNilClass, "to_splat", nil_to_a, 0);
rb_define_method(rb_cNilClass, "inspect", nil_inspect, 0);
rb_define_method(rb_cNilClass, "&", false_and, 1);
rb_define_method(rb_cNilClass, "|", false_or, 1);
@@ -2356,6 +2701,20 @@ Init_Object(void)
rb_undef_method(CLASS_OF(rb_cNilClass), "new");
rb_define_global_const("NIL", Qnil);
+ rb_cSymbol = rb_define_class("Symbol", rb_cObject);
+ rb_define_singleton_method(rb_cSymbol, "all_symbols",
+ rb_sym_all_symbols, 0); /* in parse.y */
+ rb_undef_alloc_func(rb_cSymbol);
+ rb_undef_method(CLASS_OF(rb_cSymbol), "new");
+
+ rb_define_method(rb_cSymbol, "to_i", sym_to_i, 0);
+ rb_define_method(rb_cSymbol, "to_int", sym_to_int, 0);
+ rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
+ rb_define_method(rb_cSymbol, "to_s", sym_to_s, 0);
+ rb_define_method(rb_cSymbol, "id2name", sym_to_s, 0);
+ rb_define_method(rb_cSymbol, "to_sym", sym_to_sym, 0);
+ rb_define_method(rb_cSymbol, "===", rb_obj_equal, 1);
+
rb_define_method(rb_cModule, "freeze", rb_mod_freeze, 0);
rb_define_method(rb_cModule, "===", rb_mod_eqq, 1);
rb_define_method(rb_cModule, "==", rb_obj_equal, 1);
@@ -2366,7 +2725,8 @@ Init_Object(void)
rb_define_method(rb_cModule, ">=", rb_mod_ge, 1);
rb_define_method(rb_cModule, "initialize_copy", rb_mod_init_copy, 1); /* in class.c */
rb_define_method(rb_cModule, "to_s", rb_mod_to_s, 0);
- rb_define_method(rb_cModule, "included_modules", rb_mod_included_modules, 0); /* in class.c */
+ rb_define_method(rb_cModule, "included_modules",
+ rb_mod_included_modules, 0); /* in class.c */
rb_define_method(rb_cModule, "include?", rb_mod_include_p, 1); /* in class.c */
rb_define_method(rb_cModule, "name", rb_mod_name, 0); /* in variable.c */
rb_define_method(rb_cModule, "ancestors", rb_mod_ancestors, 0); /* in class.c */
@@ -2378,31 +2738,30 @@ Init_Object(void)
rb_define_alloc_func(rb_cModule, rb_module_s_alloc);
rb_define_method(rb_cModule, "initialize", rb_mod_initialize, 0);
- rb_define_method(rb_cModule, "instance_methods", rb_class_instance_methods, -1); /* in class.c */
+ rb_define_method(rb_cModule, "instance_methods",
+ rb_class_instance_methods, -1); /* in class.c */
rb_define_method(rb_cModule, "public_instance_methods",
rb_class_public_instance_methods, -1); /* in class.c */
rb_define_method(rb_cModule, "protected_instance_methods",
rb_class_protected_instance_methods, -1); /* in class.c */
rb_define_method(rb_cModule, "private_instance_methods",
rb_class_private_instance_methods, -1); /* in class.c */
- rb_define_method(rb_cModule, "local_methods",
- rb_class_local_methods, 0); /* in class.c */
+ rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
rb_define_method(rb_cModule, "constants", rb_mod_constants, 0); /* in variable.c */
- rb_define_method(rb_cModule, "const_get", rb_mod_const_get, -1);
+ rb_define_method(rb_cModule, "const_get", rb_mod_const_get, 1);
rb_define_method(rb_cModule, "const_set", rb_mod_const_set, 2);
- rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, -1);
+ rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, 1);
rb_define_private_method(rb_cModule, "remove_const",
rb_mod_remove_const, 1); /* in variable.c */
rb_define_method(rb_cModule, "const_missing",
rb_mod_const_missing, 1); /* in variable.c */
rb_define_method(rb_cModule, "class_variables",
rb_mod_class_variables, 0); /* in variable.c */
- rb_define_method(rb_cModule, "remove_class_variable",
- rb_mod_remove_cvar, 1); /* in variable.c */
- rb_define_method(rb_cModule, "class_variable_get", rb_mod_cvar_get, 1);
- rb_define_method(rb_cModule, "class_variable_set", rb_mod_cvar_set, 2);
- rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
+ rb_define_private_method(rb_cModule, "remove_class_variable",
+ rb_mod_remove_cvar, 1); /* in variable.c */
+ rb_define_private_method(rb_cModule, "class_variable_get", rb_mod_cvar_get, 1);
+ rb_define_private_method(rb_cModule, "class_variable_set", rb_mod_cvar_set, 2);
rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
diff --git a/oniguruma.h b/oniguruma.h
deleted file mode 100644
index 2bb822bd22..0000000000
--- a/oniguruma.h
+++ /dev/null
@@ -1,909 +0,0 @@
-#ifndef ONIGURUMA_H
-#define ONIGURUMA_H
-/**********************************************************************
- oniguruma.h - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define ONIGURUMA
-#define ONIGURUMA_VERSION_MAJOR 4
-#define ONIGURUMA_VERSION_MINOR 4
-#define ONIGURUMA_VERSION_TEENY 5
-
-#ifdef __cplusplus
-# ifndef HAVE_PROTOTYPES
-# define HAVE_PROTOTYPES 1
-# endif
-# ifndef HAVE_STDARG_PROTOTYPES
-# define HAVE_STDARG_PROTOTYPES 1
-# endif
-#endif
-
-/* escape Mac OS X/Xcode 2.4/gcc 4.0.1 problem */
-#if defined(__APPLE__) && defined(__GNUC__) && __GNUC__ >= 4
-# ifndef HAVE_STDARG_PROTOTYPES
-# define HAVE_STDARG_PROTOTYPES 1
-# endif
-#endif
-
-#ifndef P_
-#if defined(__STDC__) || defined(_WIN32)
-# define P_(args) args
-#else
-# define P_(args) ()
-#endif
-#endif
-
-#ifndef PV_
-#ifdef HAVE_STDARG_PROTOTYPES
-# define PV_(args) args
-#else
-# define PV_(args) ()
-#endif
-#endif
-
-#ifndef ONIG_EXTERN
-#if defined(_WIN32) && !defined(__GNUC__)
-#if defined(EXPORT) || defined(RUBY_EXPORT)
-#define ONIG_EXTERN extern __declspec(dllexport)
-#else
-#define ONIG_EXTERN extern __declspec(dllimport)
-#endif
-#endif
-#endif
-
-#ifndef ONIG_EXTERN
-#define ONIG_EXTERN extern
-#endif
-
-/* PART: character encoding */
-
-#ifndef ONIG_ESCAPE_UCHAR_COLLISION
-#define UChar OnigUChar
-#endif
-
-typedef unsigned char OnigUChar;
-typedef unsigned long OnigCodePoint;
-typedef unsigned int OnigDistance;
-
-#define ONIG_INFINITE_DISTANCE ~((OnigDistance )0)
-
-/* ambiguous match flag */
-typedef unsigned int OnigAmbigType;
-
-ONIG_EXTERN OnigAmbigType OnigDefaultAmbigFlag;
-
-#define ONIGENC_AMBIGUOUS_MATCH_NONE 0
-#define ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE (1<<0)
-#define ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE (1<<1)
-/* #define ONIGENC_AMBIGUOUS_MATCH_ACCENT (1<<2) */
-/* #define ONIGENC_AMBIGUOUS_MATCH_HIRAGANA_KATAKANA (1<<3) */
-/* #define ONIGENC_AMBIGUOUS_MATCH_KATAKANA_WIDTH (1<<4) */
-
-#define ONIGENC_AMBIGUOUS_MATCH_LIMIT (1<<1)
-#define ONIGENC_AMBIGUOUS_MATCH_COMPOUND (1<<30)
-
-#define ONIGENC_AMBIGUOUS_MATCH_FULL \
- ( ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE | \
- ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE | \
- ONIGENC_AMBIGUOUS_MATCH_COMPOUND )
-#define ONIGENC_AMBIGUOUS_MATCH_DEFAULT OnigDefaultAmbigFlag
-
-
-#define ONIGENC_MAX_COMP_AMBIG_CODE_LEN 3
-#define ONIGENC_MAX_COMP_AMBIG_CODE_ITEM_NUM 4
-
-/* code range */
-#define ONIGENC_CODE_RANGE_NUM(range) ((int )range[0])
-#define ONIGENC_CODE_RANGE_FROM(range,i) range[((i)*2) + 1]
-#define ONIGENC_CODE_RANGE_TO(range,i) range[((i)*2) + 2]
-
-typedef struct {
- int len;
- OnigCodePoint code[ONIGENC_MAX_COMP_AMBIG_CODE_LEN];
-} OnigCompAmbigCodeItem;
-
-typedef struct {
- int n;
- OnigCodePoint code;
- OnigCompAmbigCodeItem items[ONIGENC_MAX_COMP_AMBIG_CODE_ITEM_NUM];
-} OnigCompAmbigCodes;
-
-typedef struct {
- OnigCodePoint from;
- OnigCodePoint to;
-} OnigPairAmbigCodes;
-
-typedef struct {
- OnigCodePoint esc;
- OnigCodePoint anychar;
- OnigCodePoint anytime;
- OnigCodePoint zero_or_one_time;
- OnigCodePoint one_or_more_time;
- OnigCodePoint anychar_anytime;
-} OnigMetaCharTableType;
-
-
-#if defined(RUBY_PLATFORM) && defined(M17N_H)
-
-#define ONIG_RUBY_M17N
-typedef m17n_encoding* OnigEncoding;
-
-#else
-
-typedef struct {
- int (*mbc_enc_len)(const OnigUChar* p);
- const char* name;
- int max_enc_len;
- int min_enc_len;
- OnigAmbigType support_ambig_flag;
- OnigMetaCharTableType meta_char_table;
- int (*is_mbc_newline)(const OnigUChar* p, const OnigUChar* end);
- OnigCodePoint (*mbc_to_code)(const OnigUChar* p, const OnigUChar* end);
- int (*code_to_mbclen)(OnigCodePoint code);
- int (*code_to_mbc)(OnigCodePoint code, OnigUChar *buf);
- int (*mbc_to_normalize)(OnigAmbigType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to);
- int (*is_mbc_ambiguous)(OnigAmbigType flag, const OnigUChar** pp, const OnigUChar* end);
- int (*get_all_pair_ambig_codes)(OnigAmbigType flag, const OnigPairAmbigCodes** acs);
- int (*get_all_comp_ambig_codes)(OnigAmbigType flag, const OnigCompAmbigCodes** acs);
- int (*is_code_ctype)(OnigCodePoint code, unsigned int ctype);
- int (*get_ctype_code_range)(int ctype, const OnigCodePoint* sb_range[], const OnigCodePoint* mb_range[]);
- OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p);
- int (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end);
-} OnigEncodingType;
-
-typedef OnigEncodingType* OnigEncoding;
-
-ONIG_EXTERN OnigEncodingType OnigEncodingASCII;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_1;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_2;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_3;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_4;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_5;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_6;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_7;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_8;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_9;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_10;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_11;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_13;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_14;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_15;
-ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_16;
-ONIG_EXTERN OnigEncodingType OnigEncodingUTF8;
-ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_BE;
-ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_LE;
-ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_BE;
-ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_LE;
-ONIG_EXTERN OnigEncodingType OnigEncodingEUC_JP;
-ONIG_EXTERN OnigEncodingType OnigEncodingEUC_TW;
-ONIG_EXTERN OnigEncodingType OnigEncodingEUC_KR;
-ONIG_EXTERN OnigEncodingType OnigEncodingEUC_CN;
-ONIG_EXTERN OnigEncodingType OnigEncodingSJIS;
-ONIG_EXTERN OnigEncodingType OnigEncodingKOI8;
-ONIG_EXTERN OnigEncodingType OnigEncodingKOI8_R;
-ONIG_EXTERN OnigEncodingType OnigEncodingBIG5;
-ONIG_EXTERN OnigEncodingType OnigEncodingGB18030;
-
-#define ONIG_ENCODING_ASCII (&OnigEncodingASCII)
-#define ONIG_ENCODING_ISO_8859_1 (&OnigEncodingISO_8859_1)
-#define ONIG_ENCODING_ISO_8859_2 (&OnigEncodingISO_8859_2)
-#define ONIG_ENCODING_ISO_8859_3 (&OnigEncodingISO_8859_3)
-#define ONIG_ENCODING_ISO_8859_4 (&OnigEncodingISO_8859_4)
-#define ONIG_ENCODING_ISO_8859_5 (&OnigEncodingISO_8859_5)
-#define ONIG_ENCODING_ISO_8859_6 (&OnigEncodingISO_8859_6)
-#define ONIG_ENCODING_ISO_8859_7 (&OnigEncodingISO_8859_7)
-#define ONIG_ENCODING_ISO_8859_8 (&OnigEncodingISO_8859_8)
-#define ONIG_ENCODING_ISO_8859_9 (&OnigEncodingISO_8859_9)
-#define ONIG_ENCODING_ISO_8859_10 (&OnigEncodingISO_8859_10)
-#define ONIG_ENCODING_ISO_8859_11 (&OnigEncodingISO_8859_11)
-#define ONIG_ENCODING_ISO_8859_13 (&OnigEncodingISO_8859_13)
-#define ONIG_ENCODING_ISO_8859_14 (&OnigEncodingISO_8859_14)
-#define ONIG_ENCODING_ISO_8859_15 (&OnigEncodingISO_8859_15)
-#define ONIG_ENCODING_ISO_8859_16 (&OnigEncodingISO_8859_16)
-#define ONIG_ENCODING_UTF8 (&OnigEncodingUTF8)
-#define ONIG_ENCODING_UTF16_BE (&OnigEncodingUTF16_BE)
-#define ONIG_ENCODING_UTF16_LE (&OnigEncodingUTF16_LE)
-#define ONIG_ENCODING_UTF32_BE (&OnigEncodingUTF32_BE)
-#define ONIG_ENCODING_UTF32_LE (&OnigEncodingUTF32_LE)
-#define ONIG_ENCODING_EUC_JP (&OnigEncodingEUC_JP)
-#define ONIG_ENCODING_EUC_TW (&OnigEncodingEUC_TW)
-#define ONIG_ENCODING_EUC_KR (&OnigEncodingEUC_KR)
-#define ONIG_ENCODING_EUC_CN (&OnigEncodingEUC_CN)
-#define ONIG_ENCODING_SJIS (&OnigEncodingSJIS)
-#define ONIG_ENCODING_KOI8 (&OnigEncodingKOI8)
-#define ONIG_ENCODING_KOI8_R (&OnigEncodingKOI8_R)
-#define ONIG_ENCODING_BIG5 (&OnigEncodingBIG5)
-#define ONIG_ENCODING_GB18030 (&OnigEncodingGB18030)
-
-#endif /* else RUBY && M17N */
-
-#define ONIG_ENCODING_UNDEF ((OnigEncoding )0)
-
-
-/* work size */
-#define ONIGENC_CODE_TO_MBC_MAXLEN 7
-#define ONIGENC_MBC_NORMALIZE_MAXLEN ONIGENC_CODE_TO_MBC_MAXLEN
-
-/* character types */
-#define ONIGENC_CTYPE_NEWLINE (1<< 0)
-#define ONIGENC_CTYPE_ALPHA (1<< 1)
-#define ONIGENC_CTYPE_BLANK (1<< 2)
-#define ONIGENC_CTYPE_CNTRL (1<< 3)
-#define ONIGENC_CTYPE_DIGIT (1<< 4)
-#define ONIGENC_CTYPE_GRAPH (1<< 5)
-#define ONIGENC_CTYPE_LOWER (1<< 6)
-#define ONIGENC_CTYPE_PRINT (1<< 7)
-#define ONIGENC_CTYPE_PUNCT (1<< 8)
-#define ONIGENC_CTYPE_SPACE (1<< 9)
-#define ONIGENC_CTYPE_UPPER (1<<10)
-#define ONIGENC_CTYPE_XDIGIT (1<<11)
-#define ONIGENC_CTYPE_WORD (1<<12)
-#define ONIGENC_CTYPE_ASCII (1<<13)
-#define ONIGENC_CTYPE_ALNUM (ONIGENC_CTYPE_ALPHA | ONIGENC_CTYPE_DIGIT)
-
-#define enc_len(enc,p) ONIGENC_MBC_ENC_LEN(enc, p)
-
-#define ONIGENC_IS_UNDEF(enc) ((enc) == ONIG_ENCODING_UNDEF)
-#define ONIGENC_IS_SINGLEBYTE(enc) (ONIGENC_MBC_MAXLEN(enc) == 1)
-#define ONIGENC_IS_MBC_HEAD(enc,p) (ONIGENC_MBC_ENC_LEN(enc,p) != 1)
-#define ONIGENC_IS_MBC_ASCII(p) (*(p) < 128)
-#define ONIGENC_IS_CODE_ASCII(code) ((code) < 128)
-#define ONIGENC_IS_CODE_SB_WORD(enc,code) \
- (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_WORD(enc,code))
-#define ONIGENC_IS_MBC_WORD(enc,s,end) \
- ONIGENC_IS_CODE_WORD(enc,ONIGENC_MBC_TO_CODE(enc,s,end))
-
-
-#ifdef ONIG_RUBY_M17N
-
-#include <ctype.h> /* for isblank(), isgraph() */
-
-#define ONIGENC_MBC_TO_NORMALIZE(enc,flag,pp,end,buf) \
- onigenc_mbc_to_normalize(enc,flag,pp,end,buf)
-#define ONIGENC_IS_MBC_AMBIGUOUS(enc,flag,pp,end) \
- onigenc_is_mbc_ambiguous(enc,flag,pp,end)
-
-#define ONIGENC_SUPPORT_AMBIG_FLAG(enc) ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE
-#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
- onigenc_is_allowed_reverse_match(enc, s, end)
-#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s) \
- onigenc_get_left_adjust_char_head(enc, start, s)
-#define ONIGENC_GET_ALL_PAIR_AMBIG_CODES(enc, ambig_flag, acs) 0
-#define ONIGENC_GET_ALL_COMP_AMBIG_CODES(enc, ambig_flag, acs) 0
-#define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbr,mbr) \
- ONIG_NO_SUPPORT_CONFIG
-#define ONIGENC_MBC_ENC_LEN(enc,p) m17n_mbclen(enc,(int )(*p))
-#define ONIGENC_MBC_MAXLEN(enc) m17n_mbmaxlen(enc)
-#define ONIGENC_MBC_MAXLEN_DIST(enc) \
- (ONIGENC_MBC_MAXLEN(enc) > 0 ? ONIGENC_MBC_MAXLEN(enc) \
- : ONIG_INFINITE_DISTANCE)
-#define ONIGENC_MBC_MINLEN(enc) 1
-#define ONIGENC_MBC_TO_CODE(enc,p,e) m17n_codepoint((enc),(p),(e))
-#define ONIGENC_CODE_TO_MBCLEN(enc,code) m17n_codelen((enc),(code))
-#define ONIGENC_CODE_TO_MBC(enc,code,buf) onigenc_code_to_mbc(enc, code, buf)
-
-#if 0 /* !! not supported !! */
-#define ONIGENC_IS_MBC_NEWLINE(enc,p,end)
-#define ONIGENC_STEP_BACK(enc,start,s,n)
-#endif
-
-#define ONIGENC_IS_CODE_CTYPE(enc,code,ctype) \
- onigenc_is_code_ctype(enc,code,ctype)
-
-#ifdef isblank
-# define ONIGENC_IS_CODE_BLANK(enc,code) isblank((int )code)
-#else
-# define ONIGENC_IS_CODE_BLANK(enc,code) ((code) == ' ' || (code) == '\t')
-#endif
-#ifdef isgraph
-# define ONIGENC_IS_CODE_GRAPH(enc,code) isgraph((int )code)
-#else
-# define ONIGENC_IS_CODE_GRAPH(enc,code) \
- (isprint((int )code) && !isspace((int )code))
-#endif
-
-#define ONIGENC_IS_CODE_PRINT(enc,code) m17n_isprint(enc,code)
-#define ONIGENC_IS_CODE_ALNUM(enc,code) m17n_isalnum(enc,code)
-#define ONIGENC_IS_CODE_ALPHA(enc,code) m17n_isalpha(enc,code)
-#define ONIGENC_IS_CODE_LOWER(enc,code) m17n_islower(enc,code)
-#define ONIGENC_IS_CODE_UPPER(enc,code) m17n_isupper(enc,code)
-#define ONIGENC_IS_CODE_CNTRL(enc,code) m17n_iscntrl(enc,code)
-#define ONIGENC_IS_CODE_PUNCT(enc,code) m17n_ispunct(enc,code)
-#define ONIGENC_IS_CODE_SPACE(enc,code) m17n_isspace(enc,code)
-#define ONIGENC_IS_CODE_DIGIT(enc,code) m17n_isdigit(enc,code)
-#define ONIGENC_IS_CODE_XDIGIT(enc,code) m17n_isxdigit(enc,code)
-#define ONIGENC_IS_CODE_WORD(enc,code) m17n_iswchar(enc,code)
-
-ONIG_EXTERN
-int onigenc_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, int ctype));
-ONIG_EXTERN
-int onigenc_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, OnigUChar *buf));
-ONIG_EXTERN
-int onigenc_mbc_to_normalize P_((OnigEncoding enc, OnigAmbigType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* buf));
-ONIG_EXTERN
-int onigenc_is_mbc_ambiguous P_((OnigEncoding enc, OnigAmbigType flag, const OnigUChar** pp, const OnigUChar* end));
-ONIG_EXTERN
-int onigenc_is_allowed_reverse_match P_((OnigEncoding enc, const OnigUChar* s, const OnigUChar* end));
-
-#else /* ONIG_RUBY_M17N */
-
-#define ONIGENC_NAME(enc) ((enc)->name)
-
-#define ONIGENC_MBC_TO_NORMALIZE(enc,flag,pp,end,buf) \
- (enc)->mbc_to_normalize(flag,(const OnigUChar** )pp,end,buf)
-#define ONIGENC_IS_MBC_AMBIGUOUS(enc,flag,pp,end) \
- (enc)->is_mbc_ambiguous(flag,(const OnigUChar** )pp,end)
-#define ONIGENC_SUPPORT_AMBIG_FLAG(enc) ((enc)->support_ambig_flag)
-#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
- (enc)->is_allowed_reverse_match(s,end)
-#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s) \
- (enc)->left_adjust_char_head(start, s)
-#define ONIGENC_GET_ALL_PAIR_AMBIG_CODES(enc,ambig_flag,acs) \
- (enc)->get_all_pair_ambig_codes(ambig_flag,acs)
-#define ONIGENC_GET_ALL_COMP_AMBIG_CODES(enc,ambig_flag,acs) \
- (enc)->get_all_comp_ambig_codes(ambig_flag,acs)
-#define ONIGENC_STEP_BACK(enc,start,s,n) \
- onigenc_step_back((enc),(start),(s),(n))
-
-#define ONIGENC_MBC_ENC_LEN(enc,p) (enc)->mbc_enc_len(p)
-#define ONIGENC_MBC_MAXLEN(enc) ((enc)->max_enc_len)
-#define ONIGENC_MBC_MAXLEN_DIST(enc) ONIGENC_MBC_MAXLEN(enc)
-#define ONIGENC_MBC_MINLEN(enc) ((enc)->min_enc_len)
-#define ONIGENC_IS_MBC_NEWLINE(enc,p,end) (enc)->is_mbc_newline((p),(end))
-#define ONIGENC_MBC_TO_CODE(enc,p,end) (enc)->mbc_to_code((p),(end))
-#define ONIGENC_CODE_TO_MBCLEN(enc,code) (enc)->code_to_mbclen(code)
-#define ONIGENC_CODE_TO_MBC(enc,code,buf) (enc)->code_to_mbc(code,buf)
-
-#define ONIGENC_IS_CODE_CTYPE(enc,code,ctype) (enc)->is_code_ctype(code,ctype)
-
-#define ONIGENC_IS_CODE_NEWLINE(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_NEWLINE)
-#define ONIGENC_IS_CODE_GRAPH(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_GRAPH)
-#define ONIGENC_IS_CODE_PRINT(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PRINT)
-#define ONIGENC_IS_CODE_ALNUM(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALNUM)
-#define ONIGENC_IS_CODE_ALPHA(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALPHA)
-#define ONIGENC_IS_CODE_LOWER(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_LOWER)
-#define ONIGENC_IS_CODE_UPPER(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_UPPER)
-#define ONIGENC_IS_CODE_CNTRL(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_CNTRL)
-#define ONIGENC_IS_CODE_PUNCT(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PUNCT)
-#define ONIGENC_IS_CODE_SPACE(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_SPACE)
-#define ONIGENC_IS_CODE_BLANK(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_BLANK)
-#define ONIGENC_IS_CODE_DIGIT(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_DIGIT)
-#define ONIGENC_IS_CODE_XDIGIT(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_XDIGIT)
-#define ONIGENC_IS_CODE_WORD(enc,code) \
- ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_WORD)
-
-#define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbr,mbr) \
- (enc)->get_ctype_code_range(ctype,sbr,mbr)
-
-ONIG_EXTERN
-OnigUChar* onigenc_step_back P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, int n));
-
-#endif /* is not ONIG_RUBY_M17N */
-
-
-/* encoding API */
-ONIG_EXTERN
-int onigenc_init P_(());
-ONIG_EXTERN
-int onigenc_set_default_encoding P_((OnigEncoding enc));
-ONIG_EXTERN
-OnigEncoding onigenc_get_default_encoding P_(());
-ONIG_EXTERN
-void onigenc_set_default_caseconv_table P_((const OnigUChar* table));
-ONIG_EXTERN
-OnigUChar* onigenc_get_right_adjust_char_head_with_prev P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar** prev));
-ONIG_EXTERN
-OnigUChar* onigenc_get_prev_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
-ONIG_EXTERN
-OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
-ONIG_EXTERN
-OnigUChar* onigenc_get_right_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
-ONIG_EXTERN
-int onigenc_strlen P_((OnigEncoding enc, const OnigUChar* p, const OnigUChar* end));
-ONIG_EXTERN
-int onigenc_strlen_null P_((OnigEncoding enc, const OnigUChar* p));
-ONIG_EXTERN
-int onigenc_str_bytelen_null P_((OnigEncoding enc, const OnigUChar* p));
-
-
-
-/* PART: regular expression */
-
-/* config parameters */
-#define ONIG_NREGION 10
-#define ONIG_MAX_BACKREF_NUM 1000
-#define ONIG_MAX_REPEAT_NUM 100000
-#define ONIG_MAX_MULTI_BYTE_RANGES_NUM 10000
-/* constants */
-#define ONIG_MAX_ERROR_MESSAGE_LEN 90
-
-typedef unsigned int OnigOptionType;
-
-#define ONIG_OPTION_DEFAULT ONIG_OPTION_NONE
-
-/* options */
-#define ONIG_OPTION_NONE 0U
-#define ONIG_OPTION_IGNORECASE 1U
-#define ONIG_OPTION_EXTEND (ONIG_OPTION_IGNORECASE << 1)
-#define ONIG_OPTION_MULTILINE (ONIG_OPTION_EXTEND << 1)
-#define ONIG_OPTION_SINGLELINE (ONIG_OPTION_MULTILINE << 1)
-#define ONIG_OPTION_FIND_LONGEST (ONIG_OPTION_SINGLELINE << 1)
-#define ONIG_OPTION_FIND_NOT_EMPTY (ONIG_OPTION_FIND_LONGEST << 1)
-#define ONIG_OPTION_NEGATE_SINGLELINE (ONIG_OPTION_FIND_NOT_EMPTY << 1)
-#define ONIG_OPTION_DONT_CAPTURE_GROUP (ONIG_OPTION_NEGATE_SINGLELINE << 1)
-#define ONIG_OPTION_CAPTURE_GROUP (ONIG_OPTION_DONT_CAPTURE_GROUP << 1)
-/* options (search time) */
-#define ONIG_OPTION_NOTBOL (ONIG_OPTION_CAPTURE_GROUP << 1)
-#define ONIG_OPTION_NOTEOL (ONIG_OPTION_NOTBOL << 1)
-#define ONIG_OPTION_POSIX_REGION (ONIG_OPTION_NOTEOL << 1)
-#define ONIG_OPTION_MAXBIT ONIG_OPTION_POSIX_REGION /* limit */
-
-#define ONIG_OPTION_ON(options,regopt) ((options) |= (regopt))
-#define ONIG_OPTION_OFF(options,regopt) ((options) &= ~(regopt))
-#define ONIG_IS_OPTION_ON(options,option) ((options) & (option))
-
-/* syntax */
-typedef struct {
- unsigned int op;
- unsigned int op2;
- unsigned int behavior;
- OnigOptionType options; /* default option */
-} OnigSyntaxType;
-
-ONIG_EXTERN OnigSyntaxType OnigSyntaxASIS;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl_NG;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
-
-/* predefined syntaxes (see regsyntax.c) */
-#define ONIG_SYNTAX_ASIS (&OnigSyntaxASIS)
-#define ONIG_SYNTAX_POSIX_BASIC (&OnigSyntaxPosixBasic)
-#define ONIG_SYNTAX_POSIX_EXTENDED (&OnigSyntaxPosixExtended)
-#define ONIG_SYNTAX_EMACS (&OnigSyntaxEmacs)
-#define ONIG_SYNTAX_GREP (&OnigSyntaxGrep)
-#define ONIG_SYNTAX_GNU_REGEX (&OnigSyntaxGnuRegex)
-#define ONIG_SYNTAX_JAVA (&OnigSyntaxJava)
-#define ONIG_SYNTAX_PERL (&OnigSyntaxPerl)
-#define ONIG_SYNTAX_PERL_NG (&OnigSyntaxPerl_NG)
-#define ONIG_SYNTAX_RUBY (&OnigSyntaxRuby)
-
-/* default syntax */
-ONIG_EXTERN OnigSyntaxType* OnigDefaultSyntax;
-#define ONIG_SYNTAX_DEFAULT OnigDefaultSyntax
-
-/* syntax (operators) */
-#define ONIG_SYN_OP_VARIABLE_META_CHARACTERS (1U<<0)
-#define ONIG_SYN_OP_DOT_ANYCHAR (1U<<1) /* . */
-#define ONIG_SYN_OP_ASTERISK_ZERO_INF (1U<<2) /* * */
-#define ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF (1U<<3)
-#define ONIG_SYN_OP_PLUS_ONE_INF (1U<<4) /* + */
-#define ONIG_SYN_OP_ESC_PLUS_ONE_INF (1U<<5)
-#define ONIG_SYN_OP_QMARK_ZERO_ONE (1U<<6) /* ? */
-#define ONIG_SYN_OP_ESC_QMARK_ZERO_ONE (1U<<7)
-#define ONIG_SYN_OP_BRACE_INTERVAL (1U<<8) /* {lower,upper} */
-#define ONIG_SYN_OP_ESC_BRACE_INTERVAL (1U<<9) /* \{lower,upper\} */
-#define ONIG_SYN_OP_VBAR_ALT (1U<<10) /* | */
-#define ONIG_SYN_OP_ESC_VBAR_ALT (1U<<11) /* \| */
-#define ONIG_SYN_OP_LPAREN_SUBEXP (1U<<12) /* (...) */
-#define ONIG_SYN_OP_ESC_LPAREN_SUBEXP (1U<<13) /* \(...\) */
-#define ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR (1U<<14) /* \A, \Z, \z */
-#define ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR (1U<<15) /* \G */
-#define ONIG_SYN_OP_DECIMAL_BACKREF (1U<<16) /* \num */
-#define ONIG_SYN_OP_BRACKET_CC (1U<<17) /* [...] */
-#define ONIG_SYN_OP_ESC_W_WORD (1U<<18) /* \w, \W */
-#define ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END (1U<<19) /* \<. \> */
-#define ONIG_SYN_OP_ESC_B_WORD_BOUND (1U<<20) /* \b, \B */
-#define ONIG_SYN_OP_ESC_S_WHITE_SPACE (1U<<21) /* \s, \S */
-#define ONIG_SYN_OP_ESC_D_DIGIT (1U<<22) /* \d, \D */
-#define ONIG_SYN_OP_LINE_ANCHOR (1U<<23) /* ^, $ */
-#define ONIG_SYN_OP_POSIX_BRACKET (1U<<24) /* [:xxxx:] */
-#define ONIG_SYN_OP_QMARK_NON_GREEDY (1U<<25) /* ??,*?,+?,{n,m}? */
-#define ONIG_SYN_OP_ESC_CONTROL_CHARS (1U<<26) /* \n,\r,\t,\a ... */
-#define ONIG_SYN_OP_ESC_C_CONTROL (1U<<27) /* \cx */
-#define ONIG_SYN_OP_ESC_OCTAL3 (1U<<28) /* \OOO */
-#define ONIG_SYN_OP_ESC_X_HEX2 (1U<<29) /* \xHH */
-#define ONIG_SYN_OP_ESC_X_BRACE_HEX8 (1U<<30) /* \x{7HHHHHHH} */
-
-#define ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE (1U<<0) /* \Q...\E */
-#define ONIG_SYN_OP2_QMARK_GROUP_EFFECT (1U<<1) /* (?...) */
-#define ONIG_SYN_OP2_OPTION_PERL (1U<<2) /* (?imsx),(?-imsx) */
-#define ONIG_SYN_OP2_OPTION_RUBY (1U<<3) /* (?imx), (?-imx) */
-#define ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT (1U<<4) /* ?+,*+,++ */
-#define ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL (1U<<5) /* {n,m}+ */
-#define ONIG_SYN_OP2_CCLASS_SET_OP (1U<<6) /* [...&&..[..]..] */
-#define ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP (1U<<7) /* (?<name>...) */
-#define ONIG_SYN_OP2_ESC_K_NAMED_BACKREF (1U<<8) /* \k<name> */
-#define ONIG_SYN_OP2_ESC_G_SUBEXP_CALL (1U<<9) /* \g<name>, \g<n> */
-#define ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY (1U<<10) /* (?@..),(?@<x>..) */
-#define ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL (1U<<11) /* \C-x */
-#define ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META (1U<<12) /* \M-x */
-#define ONIG_SYN_OP2_ESC_V_VTAB (1U<<13) /* \v as VTAB */
-#define ONIG_SYN_OP2_ESC_U_HEX4 (1U<<14) /* \uHHHH */
-#define ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR (1U<<15) /* \`, \' */
-#define ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY (1U<<16) /* \p{...}, \P{...} */
-#define ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT (1U<<17) /* \p{^..}, \P{^..} */
-#define ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS (1U<<18) /* \p{IsXDigit} */
-#define ONIG_SYN_OP2_ESC_H_XDIGIT (1U<<19) /* \h, \H */
-#define ONIG_SYN_OP2_INEFFECTIVE_ESCAPE (1U<<20) /* \ */
-
-/* syntax (behavior) */
-#define ONIG_SYN_CONTEXT_INDEP_ANCHORS (1U<<31) /* not implemented */
-#define ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS (1U<<0) /* ?, *, +, {n,m} */
-#define ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS (1U<<1) /* error or ignore */
-#define ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP (1U<<2) /* ...)... */
-#define ONIG_SYN_ALLOW_INVALID_INTERVAL (1U<<3) /* {??? */
-#define ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV (1U<<4) /* {,n} => {0,n} */
-#define ONIG_SYN_STRICT_CHECK_BACKREF (1U<<5) /* /(\1)/,/\1()/ ..*/
-#define ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND (1U<<6) /* (?<=a|bc) */
-#define ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP (1U<<7) /* see doc/RE */
-#define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME (1U<<8) /* (?<x>)(?<x>) */
-#define ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY (1U<<9) /* a{n}?=(?:a{n})? */
-
-/* syntax (behavior) in char class [...] */
-#define ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC (1U<<20) /* [^...] */
-#define ONIG_SYN_BACKSLASH_ESCAPE_IN_CC (1U<<21) /* [..\w..] etc.. */
-#define ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC (1U<<22)
-#define ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC (1U<<23) /* [0-9-a]=[0-9\-a] */
-/* syntax (behavior) warning */
-#define ONIG_SYN_WARN_CC_OP_NOT_ESCAPED (1U<<24) /* [,-,] */
-#define ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT (1U<<25) /* (?:a*)+ */
-
-/* meta character specifiers (onig_set_meta_char()) */
-#define ONIG_META_CHAR_ESCAPE 0
-#define ONIG_META_CHAR_ANYCHAR 1
-#define ONIG_META_CHAR_ANYTIME 2
-#define ONIG_META_CHAR_ZERO_OR_ONE_TIME 3
-#define ONIG_META_CHAR_ONE_OR_MORE_TIME 4
-#define ONIG_META_CHAR_ANYCHAR_ANYTIME 5
-
-#define ONIG_INEFFECTIVE_META_CHAR 0
-
-/* error codes */
-#define ONIG_IS_PATTERN_ERROR(ecode) ((ecode) <= -100 && (ecode) > -1000)
-/* normal return */
-#define ONIG_NORMAL 0
-#define ONIG_MISMATCH -1
-#define ONIG_NO_SUPPORT_CONFIG -2
-
-/* internal error */
-#define ONIGERR_MEMORY -5
-#define ONIGERR_TYPE_BUG -6
-#define ONIGERR_PARSER_BUG -11
-#define ONIGERR_STACK_BUG -12
-#define ONIGERR_UNDEFINED_BYTECODE -13
-#define ONIGERR_UNEXPECTED_BYTECODE -14
-#define ONIGERR_MATCH_STACK_LIMIT_OVER -15
-#define ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED -21
-#define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR -22
-/* general error */
-#define ONIGERR_INVALID_ARGUMENT -30
-/* syntax error */
-#define ONIGERR_END_PATTERN_AT_LEFT_BRACE -100
-#define ONIGERR_END_PATTERN_AT_LEFT_BRACKET -101
-#define ONIGERR_EMPTY_CHAR_CLASS -102
-#define ONIGERR_PREMATURE_END_OF_CHAR_CLASS -103
-#define ONIGERR_END_PATTERN_AT_ESCAPE -104
-#define ONIGERR_END_PATTERN_AT_META -105
-#define ONIGERR_END_PATTERN_AT_CONTROL -106
-#define ONIGERR_META_CODE_SYNTAX -108
-#define ONIGERR_CONTROL_CODE_SYNTAX -109
-#define ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE -110
-#define ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE -111
-#define ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS -112
-#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED -113
-#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID -114
-#define ONIGERR_NESTED_REPEAT_OPERATOR -115
-#define ONIGERR_UNMATCHED_CLOSE_PARENTHESIS -116
-#define ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS -117
-#define ONIGERR_END_PATTERN_IN_GROUP -118
-#define ONIGERR_UNDEFINED_GROUP_OPTION -119
-#define ONIGERR_INVALID_POSIX_BRACKET_TYPE -121
-#define ONIGERR_INVALID_LOOK_BEHIND_PATTERN -122
-#define ONIGERR_INVALID_REPEAT_RANGE_PATTERN -123
-/* values error (syntax error) */
-#define ONIGERR_TOO_BIG_NUMBER -200
-#define ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE -201
-#define ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE -202
-#define ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS -203
-#define ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE -204
-#define ONIGERR_TOO_MANY_MULTI_BYTE_RANGES -205
-#define ONIGERR_TOO_SHORT_MULTI_BYTE_STRING -206
-#define ONIGERR_TOO_BIG_BACKREF_NUMBER -207
-#define ONIGERR_INVALID_BACKREF -208
-#define ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED -209
-#define ONIGERR_TOO_LONG_WIDE_CHAR_VALUE -212
-#define ONIGERR_EMPTY_GROUP_NAME -214
-#define ONIGERR_INVALID_GROUP_NAME -215
-#define ONIGERR_INVALID_CHAR_IN_GROUP_NAME -216
-#define ONIGERR_UNDEFINED_NAME_REFERENCE -217
-#define ONIGERR_UNDEFINED_GROUP_REFERENCE -218
-#define ONIGERR_MULTIPLEX_DEFINED_NAME -219
-#define ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL -220
-#define ONIGERR_NEVER_ENDING_RECURSION -221
-#define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY -222
-#define ONIGERR_INVALID_CHAR_PROPERTY_NAME -223
-#define ONIGERR_INVALID_WIDE_CHAR_VALUE -400
-#define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE -401
-#define ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION -402
-#define ONIGERR_INVALID_COMBINATION_OF_OPTIONS -403
-
-/* errors related to thread */
-#define ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT -1001
-
-
-/* must be smaller than BIT_STATUS_BITS_NUM (unsigned int * 8) */
-#define ONIG_MAX_CAPTURE_HISTORY_GROUP 31
-#define ONIG_IS_CAPTURE_HISTORY_GROUP(r, i) \
- ((i) <= ONIG_MAX_CAPTURE_HISTORY_GROUP && (r)->list && (r)->list[i])
-
-typedef struct OnigCaptureTreeNodeStruct {
- int group; /* group number */
- int beg;
- int end;
- int allocated;
- int num_childs;
- struct OnigCaptureTreeNodeStruct** childs;
-} OnigCaptureTreeNode;
-
-/* match result region type */
-struct re_registers {
- int allocated;
- int num_regs;
- int* beg;
- int* end;
- /* extended */
- OnigCaptureTreeNode* history_root; /* capture history tree root */
-};
-
-/* capture tree traverse */
-#define ONIG_TRAVERSE_CALLBACK_AT_FIRST 1
-#define ONIG_TRAVERSE_CALLBACK_AT_LAST 2
-#define ONIG_TRAVERSE_CALLBACK_AT_BOTH \
- ( ONIG_TRAVERSE_CALLBACK_AT_FIRST | ONIG_TRAVERSE_CALLBACK_AT_LAST )
-
-
-#define ONIG_REGION_NOTPOS -1
-
-typedef struct re_registers OnigRegion;
-
-typedef struct {
- OnigEncoding enc;
- OnigUChar* par;
- OnigUChar* par_end;
-} OnigErrorInfo;
-
-typedef struct {
- int lower;
- int upper;
-} OnigRepeatRange;
-
-typedef void (*OnigWarnFunc) P_((const char* s));
-extern void onig_null_warn P_((const char* s));
-#define ONIG_NULL_WARN onig_null_warn
-
-#define ONIG_CHAR_TABLE_SIZE 256
-
-/* regex_t state */
-#define ONIG_STATE_NORMAL 0
-#define ONIG_STATE_SEARCHING 1
-#define ONIG_STATE_COMPILING -1
-#define ONIG_STATE_MODIFY -2
-
-#define ONIG_STATE(reg) \
- ((reg)->state > 0 ? ONIG_STATE_SEARCHING : (reg)->state)
-
-typedef struct re_pattern_buffer {
- /* common members of BBuf(bytes-buffer) */
- unsigned char* p; /* compiled pattern */
- unsigned int used; /* used space for p */
- unsigned int alloc; /* allocated space for p */
-
- int state; /* normal, searching, compiling */
- int num_mem; /* used memory(...) num counted from 1 */
- int num_repeat; /* OP_REPEAT/OP_REPEAT_NG id-counter */
- int num_null_check; /* OP_NULL_CHECK_START/END id counter */
- int num_comb_exp_check; /* combination explosion check */
- int num_call; /* number of subexp call */
- unsigned int capture_history; /* (?@...) flag (1-31) */
- unsigned int bt_mem_start; /* need backtrack flag */
- unsigned int bt_mem_end; /* need backtrack flag */
- int stack_pop_level;
- int repeat_range_alloc;
- OnigRepeatRange* repeat_range;
-
- OnigEncoding enc;
- OnigOptionType options;
- OnigSyntaxType* syntax;
- OnigAmbigType ambig_flag;
- void* name_table;
-
- /* optimization info (string search, char-map and anchors) */
- int optimize; /* optimize flag */
- int threshold_len; /* search str-length for apply optimize */
- int anchor; /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */
- OnigDistance anchor_dmin; /* (SEMI_)END_BUF anchor distance */
- OnigDistance anchor_dmax; /* (SEMI_)END_BUF anchor distance */
- int sub_anchor; /* start-anchor for exact or map */
- unsigned char *exact;
- unsigned char *exact_end;
- unsigned char map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */
- int *int_map; /* BM skip for exact_len > 255 */
- int *int_map_backward; /* BM skip for backward search */
- OnigDistance dmin; /* min-distance of exact or map */
- OnigDistance dmax; /* max-distance of exact or map */
-
- /* regex_t link chain */
- struct re_pattern_buffer* chain; /* escape compile-conflict */
-} OnigRegexType;
-
-typedef OnigRegexType* OnigRegex;
-
-#ifndef ONIG_ESCAPE_REGEX_T_COLLISION
- typedef OnigRegexType regex_t;
-#endif
-
-
-typedef struct {
- int num_of_elements;
- OnigEncoding pattern_enc;
- OnigEncoding target_enc;
- OnigSyntaxType* syntax;
- OnigOptionType option;
- OnigAmbigType ambig_flag;
-} OnigCompileInfo;
-
-/* Oniguruma Native API */
-ONIG_EXTERN
-int onig_init P_((void));
-ONIG_EXTERN
-int onig_error_code_to_str PV_((OnigUChar* s, int err_code, ...));
-ONIG_EXTERN
-void onig_set_warn_func P_((OnigWarnFunc f));
-ONIG_EXTERN
-void onig_set_verb_warn_func P_((OnigWarnFunc f));
-ONIG_EXTERN
-int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
-ONIG_EXTERN
-int onig_new_deluxe P_((OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
-ONIG_EXTERN
-void onig_free P_((OnigRegex));
-ONIG_EXTERN
-int onig_recompile P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
-ONIG_EXTERN
-int onig_recompile_deluxe P_((OnigRegex reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
-ONIG_EXTERN
-int onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
-ONIG_EXTERN
-int onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option));
-ONIG_EXTERN
-OnigRegion* onig_region_new P_((void));
-ONIG_EXTERN
-void onig_region_init P_((OnigRegion* region));
-ONIG_EXTERN
-void onig_region_free P_((OnigRegion* region, int free_self));
-ONIG_EXTERN
-void onig_region_copy P_((OnigRegion* to, OnigRegion* from));
-ONIG_EXTERN
-void onig_region_clear P_((OnigRegion* region));
-ONIG_EXTERN
-int onig_region_resize P_((OnigRegion* region, int n));
-ONIG_EXTERN
-int onig_region_set P_((OnigRegion* region, int at, int beg, int end));
-ONIG_EXTERN
-int onig_name_to_group_numbers P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, int** nums));
-ONIG_EXTERN
-int onig_name_to_backref_number P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, OnigRegion *region));
-ONIG_EXTERN
-int onig_foreach_name P_((OnigRegex reg, int (*func)(const OnigUChar*, const OnigUChar*,int,int*,OnigRegex,void*), void* arg));
-ONIG_EXTERN
-int onig_number_of_names P_((OnigRegex reg));
-ONIG_EXTERN
-int onig_number_of_captures P_((OnigRegex reg));
-ONIG_EXTERN
-int onig_number_of_capture_histories P_((OnigRegex reg));
-ONIG_EXTERN
-OnigCaptureTreeNode* onig_get_capture_tree P_((OnigRegion* region));
-ONIG_EXTERN
-int onig_capture_tree_traverse P_((OnigRegion* region, int at, int(*callback_func)(int,int,int,int,int,void*), void* arg));
-ONIG_EXTERN
-int onig_noname_group_capture_is_active P_((OnigRegex reg));
-ONIG_EXTERN
-OnigEncoding onig_get_encoding P_((OnigRegex reg));
-ONIG_EXTERN
-OnigOptionType onig_get_options P_((OnigRegex reg));
-ONIG_EXTERN
-OnigAmbigType onig_get_ambig_flag P_((OnigRegex reg));
-ONIG_EXTERN
-OnigSyntaxType* onig_get_syntax P_((OnigRegex reg));
-ONIG_EXTERN
-int onig_set_default_syntax P_((OnigSyntaxType* syntax));
-ONIG_EXTERN
-void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
-ONIG_EXTERN
-unsigned int onig_get_syntax_op P_((OnigSyntaxType* syntax));
-ONIG_EXTERN
-unsigned int onig_get_syntax_op2 P_((OnigSyntaxType* syntax));
-ONIG_EXTERN
-unsigned int onig_get_syntax_behavior P_((OnigSyntaxType* syntax));
-ONIG_EXTERN
-OnigOptionType onig_get_syntax_options P_((OnigSyntaxType* syntax));
-ONIG_EXTERN
-void onig_set_syntax_op P_((OnigSyntaxType* syntax, unsigned int op));
-ONIG_EXTERN
-void onig_set_syntax_op2 P_((OnigSyntaxType* syntax, unsigned int op2));
-ONIG_EXTERN
-void onig_set_syntax_behavior P_((OnigSyntaxType* syntax, unsigned int behavior));
-ONIG_EXTERN
-void onig_set_syntax_options P_((OnigSyntaxType* syntax, OnigOptionType options));
-ONIG_EXTERN
-int onig_set_meta_char P_((OnigEncoding enc, unsigned int what, OnigCodePoint code));
-ONIG_EXTERN
-void onig_copy_encoding P_((OnigEncoding to, OnigEncoding from));
-ONIG_EXTERN
-OnigAmbigType onig_get_default_ambig_flag P_(());
-ONIG_EXTERN
-int onig_set_default_ambig_flag P_((OnigAmbigType ambig_flag));
-ONIG_EXTERN
-unsigned int onig_get_match_stack_limit_size P_((void));
-ONIG_EXTERN
-int onig_set_match_stack_limit_size P_((unsigned int size));
-ONIG_EXTERN
-int onig_end P_((void));
-ONIG_EXTERN
-const char* onig_version P_((void));
-ONIG_EXTERN
-const char* onig_copyright P_((void));
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* ONIGURUMA_H */
diff --git a/pack.c b/pack.c
index fd0fbd6ac9..e5324d1e8e 100644
--- a/pack.c
+++ b/pack.c
@@ -52,7 +52,8 @@
#define define_swapx(x, xtype) \
static xtype \
-TOKEN_PASTE(swap,x)(xtype z) \
+TOKEN_PASTE(swap,x)(z) \
+ xtype z; \
{ \
xtype r; \
xtype *zp; \
@@ -134,7 +135,8 @@ define_swapx(f,float)
#else
#if SIZEOF_LONG == 4 /* SIZEOF_DOUBLE == 8 && 4 == SIZEOF_LONG */
static double
-swapd(const double d)
+swapd(d)
+ const double d;
{
double dtmp = d;
unsigned long utmp[2];
@@ -151,7 +153,8 @@ swapd(const double d)
#else
#if SIZEOF_SHORT == 4 /* SIZEOF_DOUBLE == 8 && 4 == SIZEOF_SHORT */
static double
-swapd(const double d)
+swapd(d)
+ const double d;
{
double dtmp = d;
unsigned short utmp[2];
@@ -184,7 +187,7 @@ define_swapx(d, double)
#undef htonl
#endif
static int
-endian(void)
+endian()
{
static int init = 0;
static int endian_value;
@@ -328,10 +331,11 @@ endian(void)
#define VTOHD(x,y) vtohd(x)
#endif
-unsigned long rb_big2ulong_pack(VALUE x);
+unsigned long rb_big2ulong_pack _((VALUE x));
static unsigned long
-num2i32(VALUE x)
+num2i32(x)
+ VALUE x;
{
x = rb_to_int(x); /* is nil OK? (should not) */
@@ -362,11 +366,11 @@ num2i32(VALUE x)
#endif
static const char toofew[] = "too few arguments";
-static void encodes(VALUE,const char*,long,int);
-static void qpencode(VALUE,VALUE,long);
+static void encodes _((VALUE,char*,long,int));
+static void qpencode _((VALUE,VALUE,long));
-static int uv_to_utf8(char*,unsigned long);
-static unsigned long utf8_to_uv(const char*,long*);
+static int uv_to_utf8 _((char*,unsigned long));
+static unsigned long utf8_to_uv _((char*,long*));
/*
* call-seq:
@@ -434,33 +438,34 @@ static unsigned long utf8_to_uv(const char*,long*);
*/
static VALUE
-pack_pack(VALUE ary, VALUE fmt)
+pack_pack(ary, fmt)
+ VALUE ary, fmt;
{
- static const char nul10[] = "\0\0\0\0\0\0\0\0\0\0";
- static const char spc10[] = " ";
- const char *p, *pend;
+ static char *nul10 = "\0\0\0\0\0\0\0\0\0\0";
+ static char *spc10 = " ";
+ char *p, *pend;
VALUE res, from, associates = 0;
char type;
long items, len, idx, plen;
- const char *ptr;
+ char *ptr;
#ifdef NATINT_PACK
int natint; /* native integer */
#endif
StringValue(fmt);
- p = RSTRING_PTR(fmt);
- pend = p + RSTRING_LEN(fmt);
+ p = RSTRING(fmt)->ptr;
+ pend = p + RSTRING(fmt)->len;
res = rb_str_buf_new(0);
- items = RARRAY_LEN(ary);
+ items = RARRAY(ary)->len;
idx = 0;
#define TOO_FEW (rb_raise(rb_eArgError, toofew), 0)
-#define THISFROM (items > 0 ? RARRAY_PTR(ary)[idx] : TOO_FEW)
-#define NEXTFROM (items-- > 0 ? RARRAY_PTR(ary)[idx++] : TOO_FEW)
+#define THISFROM (items > 0 ? RARRAY(ary)->ptr[idx] : TOO_FEW)
+#define NEXTFROM (items-- > 0 ? RARRAY(ary)->ptr[idx++] : TOO_FEW)
while (p < pend) {
- if (RSTRING_PTR(fmt) + RSTRING_LEN(fmt) != pend) {
+ if (RSTRING(fmt)->ptr + RSTRING(fmt)->len != pend) {
rb_raise(rb_eRuntimeError, "format string modified");
}
type = *p++; /* get data type */
@@ -510,8 +515,8 @@ pack_pack(VALUE ary, VALUE fmt)
}
else {
StringValue(from);
- ptr = RSTRING_PTR(from);
- plen = RSTRING_LEN(from);
+ ptr = RSTRING(from)->ptr;
+ plen = RSTRING(from)->len;
OBJ_INFECT(res, from);
}
@@ -843,14 +848,15 @@ pack_pack(VALUE ary, VALUE fmt)
case 'X': /* back up byte */
shrink:
- plen = RSTRING_LEN(res);
+ plen = RSTRING(res)->len;
if (plen < len)
rb_raise(rb_eArgError, "X outside of string");
- rb_str_set_len(res, plen - len);
+ RSTRING(res)->len = plen - len;
+ RSTRING(res)->ptr[plen - len] = '\0';
break;
case '@': /* null fill to absolute position */
- len -= RSTRING_LEN(res);
+ len -= RSTRING(res)->len;
if (len > 0) goto grow;
len = -len;
if (len > 0) goto shrink;
@@ -881,8 +887,8 @@ pack_pack(VALUE ary, VALUE fmt)
case 'm': /* base64 encoded string */
from = NEXTFROM;
StringValue(from);
- ptr = RSTRING_PTR(from);
- plen = RSTRING_LEN(from);
+ ptr = RSTRING(from)->ptr;
+ plen = RSTRING(from)->len;
if (len <= 2)
len = 45;
@@ -912,9 +918,9 @@ pack_pack(VALUE ary, VALUE fmt)
from = THISFROM;
if (!NIL_P(from)) {
StringValue(from);
- if (RSTRING_LEN(from) < len) {
+ if (RSTRING(from)->len < len) {
rb_raise(rb_eArgError, "too short buffer for P(%ld for %ld)",
- RSTRING_LEN(from), len);
+ RSTRING(from)->len, len);
}
}
len = 1;
@@ -949,9 +955,9 @@ pack_pack(VALUE ary, VALUE fmt)
VALUE big128 = rb_uint2big(128);
while (TYPE(from) == T_BIGNUM) {
from = rb_big_divmod(from, big128);
- c = NUM2INT(RARRAY_PTR(from)[1]) | 0x80; /* mod */
+ c = NUM2INT(RARRAY(from)->ptr[1]) | 0x80; /* mod */
rb_str_buf_cat(buf, &c, sizeof(char));
- from = RARRAY_PTR(from)[0]; /* div */
+ from = RARRAY(from)->ptr[0]; /* div */
}
}
@@ -969,16 +975,16 @@ pack_pack(VALUE ary, VALUE fmt)
ul >>= 7;
}
- if (RSTRING_LEN(buf)) {
- bufs = RSTRING_PTR(buf);
- bufe = bufs + RSTRING_LEN(buf) - 1;
+ if (RSTRING(buf)->len) {
+ bufs = RSTRING(buf)->ptr;
+ bufe = bufs + RSTRING(buf)->len - 1;
*bufs &= 0x7f; /* clear continue bit */
while (bufs < bufe) { /* reverse */
c = *bufs;
*bufs++ = *bufe;
*bufe-- = c;
}
- rb_str_buf_cat(res, RSTRING_PTR(buf), RSTRING_LEN(buf));
+ rb_str_buf_cat(res, RSTRING(buf)->ptr, RSTRING(buf)->len);
}
else {
c = 0;
@@ -998,17 +1004,21 @@ pack_pack(VALUE ary, VALUE fmt)
return res;
}
-static const char uu_table[] =
+static char uu_table[] =
"`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
-static const char b64_table[] =
+static char b64_table[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void
-encodes(VALUE str, const char *s, long len, int type)
+encodes(str, s, len, type)
+ VALUE str;
+ char *s;
+ long len;
+ int type;
{
char *buff = ALLOCA_N(char, len * 4 / 3 + 6);
long i = 0;
- const char *trans = type == 'u' ? uu_table : b64_table;
+ char *trans = type == 'u' ? uu_table : b64_table;
int padding;
if (type == 'u') {
@@ -1042,15 +1052,17 @@ encodes(VALUE str, const char *s, long len, int type)
rb_str_buf_cat(str, buff, i);
}
-static const char hex_table[] = "0123456789ABCDEF";
+static char hex_table[] = "0123456789ABCDEF";
static void
-qpencode(VALUE str, VALUE from, long len)
+qpencode(str, from, len)
+ VALUE str, from;
+ long len;
{
char buff[1024];
long i = 0, n = 0, prev = EOF;
- unsigned char *s = (unsigned char*)RSTRING_PTR(from);
- unsigned char *send = s + RSTRING_LEN(from);
+ unsigned char *s = (unsigned char*)RSTRING(from)->ptr;
+ unsigned char *send = s + RSTRING(from)->len;
while (s < send) {
if ((*s > 126) ||
@@ -1098,7 +1110,8 @@ qpencode(VALUE str, VALUE from, long len)
}
static inline int
-hex2num(char c)
+hex2num(c)
+ char c;
{
switch (c) {
case '0': case '1': case '2': case '3': case '4':
@@ -1138,7 +1151,10 @@ hex2num(char c)
#define PACK_ITEM_ADJUST() while (tmp--) rb_ary_push(ary, Qnil)
static VALUE
-infected_str_new(const char *ptr, long len, VALUE str)
+infected_str_new(ptr, len, str)
+ const char *ptr;
+ long len;
+ VALUE str;
{
VALUE s = rb_str_new(ptr, len);
@@ -1285,9 +1301,10 @@ infected_str_new(const char *ptr, long len, VALUE str)
*/
static VALUE
-pack_unpack(VALUE str, VALUE fmt)
+pack_unpack(str, fmt)
+ VALUE str, fmt;
{
- static const char *hexdigits = "0123456789abcdef0123456789ABCDEFx";
+ static char *hexdigits = "0123456789abcdef0123456789ABCDEFx";
char *s, *send;
char *p, *pend;
VALUE ary;
@@ -1297,25 +1314,15 @@ pack_unpack(VALUE str, VALUE fmt)
#ifdef NATINT_PACK
int natint; /* native integer */
#endif
- int block_p = rb_block_given_p();
-#define UNPACK_PUSH(item) do {\
- VALUE item_val = (item);\
- if (block_p) {\
- rb_yield(item_val);\
- }\
- else {\
- rb_ary_push(ary, item_val);\
- }\
- } while (0)
StringValue(str);
StringValue(fmt);
- s = RSTRING_PTR(str);
- send = s + RSTRING_LEN(str);
- p = RSTRING_PTR(fmt);
- pend = p + RSTRING_LEN(fmt);
+ s = RSTRING(str)->ptr;
+ send = s + RSTRING(str)->len;
+ p = RSTRING(fmt)->ptr;
+ pend = p + RSTRING(fmt)->len;
- ary = block_p ? Qnil : rb_ary_new();
+ ary = rb_ary_new();
while (p < pend) {
type = *p++;
#ifdef NATINT_PACK
@@ -1331,7 +1338,7 @@ pack_unpack(VALUE str, VALUE fmt)
}
star = 0;
if (*p == '_' || *p == '!') {
- const char *natstr = "sSiIlL";
+ char *natstr = "sSiIlL";
if (strchr(natstr, type)) {
#ifdef NATINT_PACK
@@ -1372,7 +1379,7 @@ pack_unpack(VALUE str, VALUE fmt)
if (*t != ' ' && *t != '\0') break;
t--; len--;
}
- UNPACK_PUSH(infected_str_new(s, len, str));
+ rb_ary_push(ary, infected_str_new(s, len, str));
s += end;
}
break;
@@ -1383,7 +1390,7 @@ pack_unpack(VALUE str, VALUE fmt)
if (len > send-s) len = send-s;
while (t < s+len && *t) t++;
- UNPACK_PUSH(infected_str_new(s, t-s, str));
+ rb_ary_push(ary, infected_str_new(s, t-s, str));
if (t < send) t++;
s = star ? t : s+len;
}
@@ -1391,7 +1398,7 @@ pack_unpack(VALUE str, VALUE fmt)
case 'a':
if (len > send - s) len = send - s;
- UNPACK_PUSH(infected_str_new(s, len, str));
+ rb_ary_push(ary, infected_str_new(s, len, str));
s += len;
break;
@@ -1405,8 +1412,8 @@ pack_unpack(VALUE str, VALUE fmt)
if (p[-1] == '*' || len > (send - s) * 8)
len = (send - s) * 8;
bits = 0;
- UNPACK_PUSH(bitstr = rb_str_new(0, len));
- t = RSTRING_PTR(bitstr);
+ rb_ary_push(ary, bitstr = rb_str_new(0, len));
+ t = RSTRING(bitstr)->ptr;
for (i=0; i<len; i++) {
if (i & 7) bits >>= 1;
else bits = *s++;
@@ -1425,8 +1432,8 @@ pack_unpack(VALUE str, VALUE fmt)
if (p[-1] == '*' || len > (send - s) * 8)
len = (send - s) * 8;
bits = 0;
- UNPACK_PUSH(bitstr = rb_str_new(0, len));
- t = RSTRING_PTR(bitstr);
+ rb_ary_push(ary, bitstr = rb_str_new(0, len));
+ t = RSTRING(bitstr)->ptr;
for (i=0; i<len; i++) {
if (i & 7) bits <<= 1;
else bits = *s++;
@@ -1445,8 +1452,8 @@ pack_unpack(VALUE str, VALUE fmt)
if (p[-1] == '*' || len > (send - s) * 2)
len = (send - s) * 2;
bits = 0;
- UNPACK_PUSH(bitstr = rb_str_new(0, len));
- t = RSTRING_PTR(bitstr);
+ rb_ary_push(ary, bitstr = rb_str_new(0, len));
+ t = RSTRING(bitstr)->ptr;
for (i=0; i<len; i++) {
if (i & 1)
bits >>= 4;
@@ -1467,8 +1474,8 @@ pack_unpack(VALUE str, VALUE fmt)
if (p[-1] == '*' || len > (send - s) * 2)
len = (send - s) * 2;
bits = 0;
- UNPACK_PUSH(bitstr = rb_str_new(0, len));
- t = RSTRING_PTR(bitstr);
+ rb_ary_push(ary, bitstr = rb_str_new(0, len));
+ t = RSTRING(bitstr)->ptr;
for (i=0; i<len; i++) {
if (i & 1)
bits <<= 4;
@@ -1484,7 +1491,7 @@ pack_unpack(VALUE str, VALUE fmt)
while (len-- > 0) {
int c = *s++;
if (c > (char)127) c-=256;
- UNPACK_PUSH(INT2FIX(c));
+ rb_ary_push(ary, INT2FIX(c));
}
PACK_ITEM_ADJUST();
break;
@@ -1493,7 +1500,7 @@ pack_unpack(VALUE str, VALUE fmt)
PACK_LENGTH_ADJUST(unsigned char,sizeof(unsigned char));
while (len-- > 0) {
unsigned char c = *s++;
- UNPACK_PUSH(INT2FIX(c));
+ rb_ary_push(ary, INT2FIX(c));
}
PACK_ITEM_ADJUST();
break;
@@ -1505,7 +1512,7 @@ pack_unpack(VALUE str, VALUE fmt)
memcpy(OFF16(&tmp), s, NATINT_LEN(short,2));
EXTEND16(tmp);
s += NATINT_LEN(short,2);
- UNPACK_PUSH(INT2FIX(tmp));
+ rb_ary_push(ary, INT2FIX(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1516,7 +1523,7 @@ pack_unpack(VALUE str, VALUE fmt)
unsigned short tmp = 0;
memcpy(OFF16(&tmp), s, NATINT_LEN(unsigned short,2));
s += NATINT_LEN(unsigned short,2);
- UNPACK_PUSH(INT2FIX(tmp));
+ rb_ary_push(ary, INT2FIX(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1527,7 +1534,7 @@ pack_unpack(VALUE str, VALUE fmt)
int tmp;
memcpy(&tmp, s, sizeof(int));
s += sizeof(int);
- UNPACK_PUSH(INT2NUM(tmp));
+ rb_ary_push(ary, INT2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1538,7 +1545,7 @@ pack_unpack(VALUE str, VALUE fmt)
unsigned int tmp;
memcpy(&tmp, s, sizeof(unsigned int));
s += sizeof(unsigned int);
- UNPACK_PUSH(UINT2NUM(tmp));
+ rb_ary_push(ary, UINT2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1550,17 +1557,18 @@ pack_unpack(VALUE str, VALUE fmt)
memcpy(OFF32(&tmp), s, NATINT_LEN(long,4));
EXTEND32(tmp);
s += NATINT_LEN(long,4);
- UNPACK_PUSH(LONG2NUM(tmp));
+ rb_ary_push(ary, LONG2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
+
case 'L':
PACK_LENGTH_ADJUST(unsigned long,4);
while (len-- > 0) {
unsigned long tmp = 0;
memcpy(OFF32(&tmp), s, NATINT_LEN(unsigned long,4));
s += NATINT_LEN(unsigned long,4);
- UNPACK_PUSH(ULONG2NUM(tmp));
+ rb_ary_push(ary, ULONG2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1570,16 +1578,17 @@ pack_unpack(VALUE str, VALUE fmt)
while (len-- > 0) {
char *tmp = (char*)s;
s += QUAD_SIZE;
- UNPACK_PUSH(rb_quad_unpack(tmp, 1));
+ rb_ary_push(ary, rb_quad_unpack(tmp, 1));
}
PACK_ITEM_ADJUST();
break;
- case 'Q':
+
+ case 'Q':
PACK_LENGTH_ADJUST_SIZE(QUAD_SIZE);
while (len-- > 0) {
char *tmp = (char*)s;
s += QUAD_SIZE;
- UNPACK_PUSH(rb_quad_unpack(tmp, 0));
+ rb_ary_push(ary, rb_quad_unpack(tmp, 0));
}
break;
@@ -1589,7 +1598,7 @@ pack_unpack(VALUE str, VALUE fmt)
unsigned short tmp = 0;
memcpy(OFF16B(&tmp), s, NATINT_LEN(unsigned short,2));
s += NATINT_LEN(unsigned short,2);
- UNPACK_PUSH(UINT2NUM(ntohs(tmp)));
+ rb_ary_push(ary, UINT2NUM(ntohs(tmp)));
}
PACK_ITEM_ADJUST();
break;
@@ -1600,7 +1609,7 @@ pack_unpack(VALUE str, VALUE fmt)
unsigned long tmp = 0;
memcpy(OFF32B(&tmp), s, NATINT_LEN(unsigned long,4));
s += NATINT_LEN(unsigned long,4);
- UNPACK_PUSH(ULONG2NUM(ntohl(tmp)));
+ rb_ary_push(ary, ULONG2NUM(ntohl(tmp)));
}
PACK_ITEM_ADJUST();
break;
@@ -1611,7 +1620,7 @@ pack_unpack(VALUE str, VALUE fmt)
unsigned short tmp = 0;
memcpy(OFF16(&tmp), s, NATINT_LEN(unsigned short,2));
s += NATINT_LEN(unsigned short,2);
- UNPACK_PUSH(UINT2NUM(vtohs(tmp)));
+ rb_ary_push(ary, UINT2NUM(vtohs(tmp)));
}
PACK_ITEM_ADJUST();
break;
@@ -1622,7 +1631,7 @@ pack_unpack(VALUE str, VALUE fmt)
unsigned long tmp = 0;
memcpy(OFF32(&tmp), s, NATINT_LEN(long,4));
s += NATINT_LEN(long,4);
- UNPACK_PUSH(ULONG2NUM(vtohl(tmp)));
+ rb_ary_push(ary, ULONG2NUM(vtohl(tmp)));
}
PACK_ITEM_ADJUST();
break;
@@ -1634,7 +1643,7 @@ pack_unpack(VALUE str, VALUE fmt)
float tmp;
memcpy(&tmp, s, sizeof(float));
s += sizeof(float);
- UNPACK_PUSH(rb_float_new((double)tmp));
+ rb_ary_push(ary, rb_float_new((double)tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1648,7 +1657,7 @@ pack_unpack(VALUE str, VALUE fmt)
memcpy(&tmp, s, sizeof(float));
s += sizeof(float);
tmp = VTOHF(tmp,ftmp);
- UNPACK_PUSH(rb_float_new((double)tmp));
+ rb_ary_push(ary, rb_float_new((double)tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1662,7 +1671,7 @@ pack_unpack(VALUE str, VALUE fmt)
memcpy(&tmp, s, sizeof(double));
s += sizeof(double);
tmp = VTOHD(tmp,dtmp);
- UNPACK_PUSH(rb_float_new(tmp));
+ rb_ary_push(ary, rb_float_new(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1674,7 +1683,7 @@ pack_unpack(VALUE str, VALUE fmt)
double tmp;
memcpy(&tmp, s, sizeof(double));
s += sizeof(double);
- UNPACK_PUSH(rb_float_new(tmp));
+ rb_ary_push(ary, rb_float_new(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1688,7 +1697,7 @@ pack_unpack(VALUE str, VALUE fmt)
memcpy(&tmp, s, sizeof(float));
s += sizeof(float);
tmp = NTOHF(tmp,ftmp);
- UNPACK_PUSH(rb_float_new((double)tmp));
+ rb_ary_push(ary, rb_float_new((double)tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1702,7 +1711,7 @@ pack_unpack(VALUE str, VALUE fmt)
memcpy(&tmp, s, sizeof(double));
s += sizeof(double);
tmp = NTOHD(tmp,dtmp);
- UNPACK_PUSH(rb_float_new(tmp));
+ rb_ary_push(ary, rb_float_new(tmp));
}
PACK_ITEM_ADJUST();
break;
@@ -1715,14 +1724,14 @@ pack_unpack(VALUE str, VALUE fmt)
l = utf8_to_uv(s, &alen);
s += alen; len--;
- UNPACK_PUSH(ULONG2NUM(l));
+ rb_ary_push(ary, ULONG2NUM(l));
}
break;
case 'u':
{
VALUE buf = infected_str_new(0, (send - s)*3/4, str);
- char *ptr = RSTRING_PTR(buf);
+ char *ptr = RSTRING(buf)->ptr;
long total = 0;
while (s < send && *s > ' ' && *s < 'a') {
@@ -1732,9 +1741,9 @@ pack_unpack(VALUE str, VALUE fmt)
hunk[3] = '\0';
len = (*s++ - ' ') & 077;
total += len;
- if (total > RSTRING_LEN(buf)) {
- len -= total - RSTRING_LEN(buf);
- total = RSTRING_LEN(buf);
+ if (total > RSTRING(buf)->len) {
+ len -= total - RSTRING(buf)->len;
+ total = RSTRING(buf)->len;
}
while (len > 0) {
@@ -1768,16 +1777,17 @@ pack_unpack(VALUE str, VALUE fmt)
else if (s < send && (s+1 == send || s[1] == '\n'))
s += 2; /* possible checksum byte */
}
-
- rb_str_set_len(buf, total);
- UNPACK_PUSH(buf);
+
+ RSTRING(buf)->ptr[total] = '\0';
+ RSTRING(buf)->len = total;
+ rb_ary_push(ary, buf);
}
break;
case 'm':
{
VALUE buf = infected_str_new(0, (send - s)*3/4, str);
- char *ptr = RSTRING_PTR(buf);
+ char *ptr = RSTRING(buf)->ptr;
int a = -1,b = -1,c = 0,d;
static int first = 1;
static int b64_xtable[256];
@@ -1794,33 +1804,41 @@ pack_unpack(VALUE str, VALUE fmt)
}
}
while (s < send) {
- while (s[0] == '\r' || s[0] == '\n') { s++; }
- if ((a = b64_xtable[(int)s[0]]) == -1) break;
- if ((b = b64_xtable[(int)s[1]]) == -1) break;
- if ((c = b64_xtable[(int)s[2]]) == -1) break;
- if ((d = b64_xtable[(int)s[3]]) == -1) break;
+ a = b = c = d = -1;
+ while((a = b64_xtable[(int)(*(unsigned char*)s)]) == -1 && s < send) { s++; }
+ if( s >= send ) break;
+ s++;
+ while((b = b64_xtable[(int)(*(unsigned char*)s)]) == -1 && s < send) { s++; }
+ if( s >= send ) break;
+ s++;
+ while((c = b64_xtable[(int)(*(unsigned char*)s)]) == -1 && s < send) { if( *s == '=' ) break; s++; }
+ if( *s == '=' || s >= send ) break;
+ s++;
+ while((d = b64_xtable[(int)(*(unsigned char*)s)]) == -1 && s < send) { if( *s == '=' ) break; s++; }
+ if( *s == '=' || s >= send ) break;
+ s++;
*ptr++ = a << 2 | b >> 4;
*ptr++ = b << 4 | c >> 2;
*ptr++ = c << 6 | d;
- s += 4;
}
if (a != -1 && b != -1) {
- if (s + 2 < send && s[2] == '=')
+ if (c == -1 && *s == '=')
*ptr++ = a << 2 | b >> 4;
- if (c != -1 && s + 3 < send && s[3] == '=') {
+ else if (c != -1 && *s == '=') {
*ptr++ = a << 2 | b >> 4;
*ptr++ = b << 4 | c >> 2;
}
}
- rb_str_set_len(buf, ptr - RSTRING_PTR(buf));
- UNPACK_PUSH(buf);
+ *ptr = '\0';
+ RSTRING(buf)->len = ptr - RSTRING(buf)->ptr;
+ rb_ary_push(ary, buf);
}
break;
case 'M':
{
VALUE buf = infected_str_new(0, send - s, str);
- char *ptr = RSTRING_PTR(buf);
+ char *ptr = RSTRING(buf)->ptr;
int c1, c2;
while (s < send) {
@@ -1840,19 +1858,20 @@ pack_unpack(VALUE str, VALUE fmt)
}
s++;
}
- rb_str_set_len(buf, ptr - RSTRING_PTR(buf));
- UNPACK_PUSH(buf);
+ *ptr = '\0';
+ RSTRING(buf)->len = ptr - RSTRING(buf)->ptr;
+ rb_ary_push(ary, buf);
}
break;
case '@':
- if (len > RSTRING_LEN(str))
+ if (len > RSTRING(str)->len)
rb_raise(rb_eArgError, "@ outside of string");
- s = RSTRING_PTR(str) + len;
+ s = RSTRING(str)->ptr + len;
break;
case 'X':
- if (len > s - RSTRING_PTR(str))
+ if (len > s - RSTRING(str)->ptr)
rb_raise(rb_eArgError, "X outside of string");
s -= len;
break;
@@ -1877,11 +1896,11 @@ pack_unpack(VALUE str, VALUE fmt)
if (!(a = rb_str_associated(str))) {
rb_raise(rb_eArgError, "no associated pointer");
}
- p = RARRAY_PTR(a);
- pend = p + RARRAY_LEN(a);
+ p = RARRAY(a)->ptr;
+ pend = p + RARRAY(a)->len;
while (p < pend) {
- if (TYPE(*p) == T_STRING && RSTRING_PTR(*p) == t) {
- if (len < RSTRING_LEN(*p)) {
+ if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t) {
+ if (len < RSTRING(*p)->len) {
tmp = rb_tainted_str_new(t, len);
rb_str_associate(tmp, a);
}
@@ -1899,7 +1918,7 @@ pack_unpack(VALUE str, VALUE fmt)
else {
tmp = Qnil;
}
- UNPACK_PUSH(tmp);
+ rb_ary_push(ary, tmp);
}
break;
@@ -1922,10 +1941,10 @@ pack_unpack(VALUE str, VALUE fmt)
if (!(a = rb_str_associated(str))) {
rb_raise(rb_eArgError, "no associated pointer");
}
- p = RARRAY_PTR(a);
- pend = p + RARRAY_LEN(a);
+ p = RARRAY(a)->ptr;
+ pend = p + RARRAY(a)->len;
while (p < pend) {
- if (TYPE(*p) == T_STRING && RSTRING_PTR(*p) == t) {
+ if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t) {
tmp = *p;
break;
}
@@ -1938,7 +1957,7 @@ pack_unpack(VALUE str, VALUE fmt)
else {
tmp = Qnil;
}
- UNPACK_PUSH(tmp);
+ rb_ary_push(ary, tmp);
}
}
break;
@@ -1952,7 +1971,7 @@ pack_unpack(VALUE str, VALUE fmt)
ul <<= 7;
ul |= (*s & 0x7f);
if (!(*s++ & 0x80)) {
- UNPACK_PUSH(ULONG2NUM(ul));
+ rb_ary_push(ary, ULONG2NUM(ul));
len--;
ul = 0;
}
@@ -1963,7 +1982,7 @@ pack_unpack(VALUE str, VALUE fmt)
big = rb_big_mul(big, big128);
big = rb_big_plus(big, rb_uint2big(*s & 0x7f));
if (!(*s++ & 0x80)) {
- UNPACK_PUSH(big);
+ rb_ary_push(ary, big);
len--;
ul = 0;
break;
@@ -1985,7 +2004,9 @@ pack_unpack(VALUE str, VALUE fmt)
#define BYTEWIDTH 8
static int
-uv_to_utf8(char *buf, unsigned long uv)
+uv_to_utf8(buf, uv)
+ char *buf;
+ unsigned long uv;
{
if (uv <= 0x7f) {
buf[0] = (char)uv;
@@ -2040,7 +2061,9 @@ static const unsigned long utf8_limits[] = {
};
static unsigned long
-utf8_to_uv(const char *p, long *lenp)
+utf8_to_uv(p, lenp)
+ char *p;
+ long *lenp;
{
int c = *p++ & 0xff;
unsigned long uv = c;
@@ -2065,7 +2088,7 @@ utf8_to_uv(const char *p, long *lenp)
rb_raise(rb_eArgError, "malformed UTF-8 character");
}
if (n > *lenp) {
- rb_raise(rb_eArgError, "malformed UTF-8 character (expected %ld bytes, given %ld bytes)",
+ rb_raise(rb_eArgError, "malformed UTF-8 character (expected %d bytes, given %d bytes)",
n, *lenp);
}
*lenp = n--;
@@ -2090,7 +2113,7 @@ utf8_to_uv(const char *p, long *lenp)
}
void
-Init_pack(void)
+Init_pack()
{
rb_define_method(rb_cArray, "pack", pack_pack, 1);
rb_define_method(rb_cString, "unpack", pack_unpack, 1);
diff --git a/parse.y b/parse.y
index a1aef62b9e..5556d725fb 100644
--- a/parse.y
+++ b/parse.y
@@ -6,7 +6,7 @@
$Date$
created at: Fri May 28 18:02:42 JST 1993
- Copyright (C) 1993-2004 Yukihiro Matsumoto
+ Copyright (C) 1993-2003 Yukihiro Matsumoto
**********************************************************************/
@@ -14,7 +14,9 @@
#define YYDEBUG 1
#define YYERROR_VERBOSE 1
+#ifndef YYSTACK_USE_ALLOCA
#define YYSTACK_USE_ALLOCA 0
+#endif
#include "ruby.h"
#include "env.h"
@@ -25,14 +27,25 @@
#include <errno.h>
#include <ctype.h>
-#define YYMALLOC(size) rb_parser_malloc(parser, size)
-#define YYREALLOC(ptr, size) rb_parser_realloc(parser, ptr, size)
-#define YYCALLOC(nelem, size) rb_parser_calloc(parser, nelem, size)
-#define YYFREE(ptr) rb_parser_free(parser, ptr)
+#define YYMALLOC rb_parser_malloc
+#define YYREALLOC rb_parser_realloc
+#define YYCALLOC rb_parser_calloc
+#define YYFREE rb_parser_free
#define malloc YYMALLOC
#define realloc YYREALLOC
#define calloc YYCALLOC
#define free YYFREE
+static void *rb_parser_malloc _((size_t));
+static void *rb_parser_realloc _((void *, size_t));
+static void *rb_parser_calloc _((size_t, size_t));
+static void rb_parser_free _((void *));
+
+#define yyparse ruby_yyparse
+#define yylex ruby_yylex
+#define yyerror ruby_yyerror
+#define yylval ruby_yylval
+#define yychar ruby_yychar
+#define yydebug ruby_yydebug
#define ID_SCOPE_SHIFT 3
#define ID_SCOPE_MASK 0x07
@@ -59,283 +72,120 @@
((id)&ID_SCOPE_MASK) == ID_INSTANCE || \
((id)&ID_SCOPE_MASK) == ID_CLASS))
-#ifndef RIPPER
+NODE *ruby_eval_tree_begin = 0;
+NODE *ruby_eval_tree = 0;
+
char *ruby_sourcefile; /* current source file */
int ruby_sourceline; /* current line no. */
-#endif
-enum lex_state_e {
+static int yylex();
+static int yyerror();
+
+static enum lex_state {
EXPR_BEG, /* ignore newline, +/- is a sign. */
- EXPR_END, /* newline significant, +/- is a operator. */
- EXPR_ARG, /* newline significant, +/- is a operator. */
- EXPR_CMDARG, /* newline significant, +/- is a operator. */
- EXPR_ENDARG, /* newline significant, +/- is a operator. */
- EXPR_MID, /* newline significant, +/- is a operator. */
+ EXPR_END, /* newline significant, +/- is an operator. */
+ EXPR_ARG, /* newline significant, +/- is an operator. */
+ EXPR_CMDARG, /* newline significant, +/- is an operator. */
+ EXPR_ENDARG, /* newline significant, +/- is an operator. */
+ EXPR_MID, /* newline significant, +/- is an operator. */
EXPR_FNAME, /* ignore newline, no reserved words. */
EXPR_DOT, /* right after `.' or `::', no reserved words. */
EXPR_CLASS, /* immediate after `class', no here document. */
- EXPR_VALUE, /* alike EXPR_BEG but label is disallowed. */
-};
+} lex_state;
+static NODE *lex_strterm;
-# ifdef HAVE_LONG_LONG
+#ifdef HAVE_LONG_LONG
typedef unsigned LONG_LONG stack_type;
-# else
+#else
typedef unsigned long stack_type;
-# endif
+#endif
-# define BITSTACK_PUSH(stack, n) (stack = (stack<<1)|((n)&1))
-# define BITSTACK_POP(stack) (stack = stack >> 1)
-# define BITSTACK_LEXPOP(stack) (stack = (stack >> 1) | (stack & 1))
-# define BITSTACK_SET_P(stack) (stack&1)
+#define BITSTACK_PUSH(stack, n) (stack = (stack<<1)|((n)&1))
+#define BITSTACK_POP(stack) (stack >>= 1)
+#define BITSTACK_LEXPOP(stack) (stack = (stack >> 1) | (stack & 1))
+#define BITSTACK_SET_P(stack) (stack&1)
+static stack_type cond_stack = 0;
#define COND_PUSH(n) BITSTACK_PUSH(cond_stack, n)
#define COND_POP() BITSTACK_POP(cond_stack)
#define COND_LEXPOP() BITSTACK_LEXPOP(cond_stack)
#define COND_P() BITSTACK_SET_P(cond_stack)
+static stack_type cmdarg_stack = 0;
#define CMDARG_PUSH(n) BITSTACK_PUSH(cmdarg_stack, n)
#define CMDARG_POP() BITSTACK_POP(cmdarg_stack)
#define CMDARG_LEXPOP() BITSTACK_LEXPOP(cmdarg_stack)
#define CMDARG_P() BITSTACK_SET_P(cmdarg_stack)
-/* must sync with real YYSTYPE */
-union tmpyystype {
- VALUE val;
- NODE *node;
- unsigned long id;
- int num;
- struct RVarmap *vars;
-};
-
-struct local_vars {
- ID *tbl;
- int nofree;
- int cnt;
- int dlev;
- int dname_size;
- ID *dnames;
- struct RVarmap* dyna_vars;
- struct local_vars *prev;
-};
-
-/*
- Structure of Lexer Buffer:
-
- lex_pbeg tokp lex_p lex_pend
- | | | |
- |-----------+--------------+------------|
- |<------------>|
- token
-*/
-struct parser_params {
- NODE *heap;
-
- union tmpyystype *parser_yylval; /* YYSTYPE not defined yet */
- VALUE eofp;
-
- NODE *parser_lex_strterm;
- enum lex_state_e parser_lex_state;
- stack_type parser_cond_stack;
- stack_type parser_cmdarg_stack;
- int parser_class_nest;
- int parser_paren_nest;
- int parser_lpar_beg;
- int parser_in_single;
- int parser_in_def;
- int parser_compile_for_eval;
- VALUE parser_cur_mid;
- int parser_in_defined;
- char *parser_tokenbuf;
- int parser_tokidx;
- int parser_toksiz;
- VALUE parser_lex_input;
- VALUE parser_lex_lastline;
- const char *parser_lex_pbeg;
- const char *parser_lex_p;
- const char *parser_lex_pend;
- int parser_heredoc_end;
- int parser_command_start;
- int parser_lex_gets_ptr;
- VALUE (*parser_lex_gets)(struct parser_params*,VALUE);
- struct local_vars *parser_lvtbl;
- int parser_ruby__end__seen;
- int line_count;
- int has_shebang;
-
-#ifndef RIPPER
- /* Ruby core only */
- NODE *parser_eval_tree_begin;
- NODE *parser_eval_tree;
- VALUE debug_lines;
-#else
- /* Ripper only */
- int parser_ruby_sourceline;
- VALUE parser_ruby_sourcefile;
- const char *tokp;
- VALUE delayed;
- int delayed_line;
- int delayed_col;
-
- VALUE value;
- VALUE result;
- VALUE parsing_thread;
- int toplevel_p;
-#endif
-};
-
-#ifdef YYMALLOC
-void *rb_parser_malloc(struct parser_params *, size_t);
-void *rb_parser_realloc(struct parser_params *, void *, size_t);
-void *rb_parser_calloc(struct parser_params *, size_t, size_t);
-void rb_parser_free(struct parser_params *, void *);
-#endif
-
-static int parser_yyerror(struct parser_params*, const char*);
-#define yyerror(msg) parser_yyerror(parser, msg)
-
-#define YYPARSE_PARAM parser_v
-#define YYLEX_PARAM parser_v
-#define parser ((struct parser_params*)parser_v)
-
-#define ruby_eval_tree (parser->parser_eval_tree)
-#define ruby_eval_tree_begin (parser->parser_eval_tree_begin)
-#define lex_strterm (parser->parser_lex_strterm)
-#define lex_state (parser->parser_lex_state)
-#define cond_stack (parser->parser_cond_stack)
-#define cmdarg_stack (parser->parser_cmdarg_stack)
-#define class_nest (parser->parser_class_nest)
-#define paren_nest (parser->parser_paren_nest)
-#define lpar_beg (parser->parser_lpar_beg)
-#define in_single (parser->parser_in_single)
-#define in_def (parser->parser_in_def)
-#define compile_for_eval (parser->parser_compile_for_eval)
-#define cur_mid (parser->parser_cur_mid)
-#define in_defined (parser->parser_in_defined)
-#define tokenbuf (parser->parser_tokenbuf)
-#define tokidx (parser->parser_tokidx)
-#define toksiz (parser->parser_toksiz)
-#define lex_input (parser->parser_lex_input)
-#define lex_lastline (parser->parser_lex_lastline)
-#define lex_pbeg (parser->parser_lex_pbeg)
-#define lex_p (parser->parser_lex_p)
-#define lex_pend (parser->parser_lex_pend)
-#define heredoc_end (parser->parser_heredoc_end)
-#define command_start (parser->parser_command_start)
-#define lex_gets_ptr (parser->parser_lex_gets_ptr)
-#define lex_gets (parser->parser_lex_gets)
-#define lvtbl (parser->parser_lvtbl)
-#define ruby__end__seen (parser->parser_ruby__end__seen)
-#ifdef RIPPER
-#define ruby_sourceline (parser->parser_ruby_sourceline)
-#define ruby_sourcefile (parser->parser_ruby_sourcefile)
-#else
-#define ruby_debug_lines (parser->debug_lines)
-#endif
-
-static int yylex(void*, void*);
-
-#ifndef RIPPER
-#define yyparse ruby_yyparse
-#define yydebug ruby_yydebug
-
-static NODE *cond_gen(struct parser_params*,NODE*);
-#define cond(node) cond_gen(parser, node)
-static NODE *logop_gen(struct parser_params*,enum node_type,NODE*,NODE*);
-#define logop(type,node1,node2) logop_gen(parser, type, node1, node2)
-
-static int cond_negative(NODE**);
-
-static NODE *newline_node(NODE*);
-static void fixpos(NODE*,NODE*);
-
-static int value_expr_gen(struct parser_params*,NODE*);
-static void void_expr_gen(struct parser_params*,NODE*);
-static NODE *remove_begin(NODE*);
-#define value_expr(node) value_expr_gen(parser, (node) = remove_begin(node))
-#define void_expr(node) void_expr_gen(parser, (node) = remove_begin(node))
-static void void_stmts_gen(struct parser_params*,NODE*);
-#define void_stmts(node) void_stmts_gen(parser, node)
-static void reduce_nodes(NODE**);
-static void block_dup_check(NODE*,NODE*);
-
-static NODE *block_append(NODE*,NODE*);
-static NODE *list_append(NODE*,NODE*);
-static NODE *list_concat(NODE*,NODE*);
-static NODE *arg_append(NODE*,NODE*);
-static NODE *arg_concat(NODE*,NODE*);
-static NODE *literal_concat(NODE*,NODE*);
-static NODE *new_evstr(NODE*);
-static NODE *evstr2dstr(NODE*);
-
-static NODE *call_op_gen(struct parser_params*,NODE*,ID,int,NODE*);
-#define call_op(recv,id,narg,arg1) call_op_gen(parser, recv,id,narg,arg1)
-
-static NODE *new_args_gen(struct parser_params*,VALUE,NODE*,NODE*,NODE*,NODE*);
-#define new_args(f,o,r,p,b) new_args_gen(parser, f,o,r,p,b)
-static void shadowing_lvar_gen(struct parser_params*,ID);
-#define shadowing_lvar(name) shadowing_lvar_gen(parser, name)
-
-static NODE *negate_lit(NODE*);
-static NODE *ret_args(NODE*);
-static NODE *arg_blk_pass(NODE*,NODE*);
-static NODE *new_yield(NODE*);
-
-static NODE *gettable_gen(struct parser_params*,ID);
-#define gettable(id) gettable_gen(parser,id)
-static NODE *assignable_gen(struct parser_params*,ID,NODE*);
-#define assignable(id,node) assignable_gen(parser, id, node)
-static NODE *new_bv_gen(struct parser_params*,ID,NODE*);
-#define new_bv(id,node) new_bv_gen(parser, id, node)
-static NODE *aryset_gen(struct parser_params*,NODE*,NODE*);
-#define aryset(node1,node2) aryset_gen(parser, node1, node2)
-static NODE *attrset_gen(struct parser_params*,NODE*,ID);
-#define attrset(node,id) attrset_gen(parser, node, id)
-
-static void rb_backref_error(NODE*);
-static NODE *node_assign_gen(struct parser_params*,NODE*,NODE*);
-#define node_assign(node1, node2) node_assign_gen(parser, node1, node2)
-
-static NODE *match_op_gen(struct parser_params*,NODE*,NODE*);
-#define match_op(node1,node2) match_op_gen(parser, node1, node2)
-
-static void local_push_gen(struct parser_params*,int);
-#define local_push(top) local_push_gen(parser,top)
-static void local_pop_gen(struct parser_params*);
-#define local_pop() local_pop_gen(parser)
-static int local_append_gen(struct parser_params*, ID);
-#define local_append(id) local_append_gen(parser, id)
-static int local_cnt_gen(struct parser_params*, ID);
-#define local_cnt(id) local_cnt_gen(parser, id)
-static int local_id_gen(struct parser_params*, ID);
-#define local_id(id) local_id_gen(parser, id)
-static ID *local_tbl_gen(struct parser_params*);
-#define local_tbl() local_tbl_gen(parser)
-static ID internal_id(void);
-
-static struct RVarmap *dyna_push_gen(struct parser_params*);
-#define dyna_push() dyna_push_gen(parser)
-static void dyna_pop_gen(struct parser_params*, struct RVarmap*);
-#define dyna_pop(vars) dyna_pop_gen(parser, vars)
-static int dyna_in_block_gen(struct parser_params*);
-#define dyna_in_block() (lvtbl->dlev > 0)
-static NODE *dyna_init_gen(struct parser_params*, NODE*, struct RVarmap *);
-#define dyna_init(node, pre) dyna_init_gen(parser, node, pre)
-static void dyna_var_gen(struct parser_params*,ID);
-#define dyna_var(id) dyna_var_gen(parser, id)
-static void dyna_check_gen(struct parser_params*,ID);
-#define dyna_check(id) dyna_check_gen(parser, id)
-
-static void top_local_init_gen(struct parser_params*);
-#define top_local_init() top_local_init_gen(parser)
-static void top_local_setup_gen(struct parser_params*);
-#define top_local_setup() top_local_setup_gen(parser)
-#else
-#define remove_begin(node) (node)
-#endif /* !RIPPER */
-static int lvar_defined_gen(struct parser_params*, ID);
-#define lvar_defined(id) lvar_defined_gen(parser, id)
-
-#define RE_OPTION_ONCE (1<<16)
+static int class_nest = 0;
+static int in_single = 0;
+static int in_def = 0;
+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();
+
+static NODE *newline_node();
+static void fixpos();
+
+static int value_expr0();
+static void void_expr0();
+static void void_stmts();
+static NODE *remove_begin();
+#define value_expr(node) value_expr0((node) = remove_begin(node))
+#define void_expr(node) void_expr0((node) = remove_begin(node))
+
+static NODE *block_append();
+static NODE *list_append();
+static NODE *list_concat();
+static NODE *arg_concat();
+static NODE *arg_prepend();
+static NODE *literal_concat();
+static NODE *new_evstr();
+static NODE *evstr2dstr();
+static NODE *call_op();
+static int in_defined = 0;
+
+static NODE *negate_lit();
+static NODE *ret_args();
+static NODE *arg_blk_pass();
+static NODE *new_call();
+static NODE *new_fcall();
+static NODE *new_super();
+static NODE *new_yield();
+
+static NODE *gettable();
+static NODE *assignable();
+static NODE *aryset();
+static NODE *attrset();
+static void rb_backref_error();
+static NODE *node_assign();
+
+static NODE *match_gen();
+static void local_push();
+static void local_pop();
+static int local_append();
+static int local_cnt();
+static int local_id();
+static ID *local_tbl();
+static ID internal_id();
+
+static struct RVarmap *dyna_push();
+static void dyna_pop();
+static int dyna_in_block();
+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 */
#define NODE_HEREDOC NODE_ARRAY /* 1, 3 to gc */
@@ -347,103 +197,7 @@ static int lvar_defined_gen(struct parser_params*, ID);
#define nd_term(node) SIGN_EXTEND((node)->u2.id, CHAR_BIT*2)
#endif
#define nd_paren(node) (char)((node)->u2.id >> CHAR_BIT*2)
-#define nd_nest u3.cnt
-
-/****** Ripper *******/
-
-#ifdef RIPPER
-#define RIPPER_VERSION "0.1.0"
-
-#include "eventids1.c"
-#include "eventids2.c"
-static ID ripper_id_gets;
-
-static VALUE ripper_dispatch0(struct parser_params*,ID);
-static VALUE ripper_dispatch1(struct parser_params*,ID,VALUE);
-static VALUE ripper_dispatch2(struct parser_params*,ID,VALUE,VALUE);
-static VALUE ripper_dispatch3(struct parser_params*,ID,VALUE,VALUE,VALUE);
-static VALUE ripper_dispatch4(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE);
-static VALUE ripper_dispatch5(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,VALUE);
-
-#define dispatch0(n) ripper_dispatch0(parser, TOKEN_PASTE(ripper_id_, n))
-#define dispatch1(n,a) ripper_dispatch1(parser, TOKEN_PASTE(ripper_id_, n), a)
-#define dispatch2(n,a,b) ripper_dispatch2(parser, TOKEN_PASTE(ripper_id_, n), a, b)
-#define dispatch3(n,a,b,c) ripper_dispatch3(parser, TOKEN_PASTE(ripper_id_, n), a, b, c)
-#define dispatch4(n,a,b,c,d) ripper_dispatch4(parser, TOKEN_PASTE(ripper_id_, n), a, b, c, d)
-#define dispatch5(n,a,b,c,d,e) ripper_dispatch5(parser, TOKEN_PASTE(ripper_id_, n), a, b, c, d, e)
-
-#define yyparse ripper_yyparse
-#define yydebug ripper_yydebug
-
-static VALUE ripper_intern(const char*);
-static VALUE ripper_id2sym(ID);
-
-#define arg_new() dispatch0(arglist_new)
-#define arg_add(l,a) dispatch2(arglist_add, l, a)
-#define arg_prepend(l,a) dispatch2(arglist_prepend, l, a)
-#define arg_add_star(l,a) dispatch2(arglist_add_star, l, a)
-#define arg_add_block(l,b) dispatch2(arglist_add_block, l, b)
-#define arg_add_optblock(l,b) ((b)==Qundef? l : dispatch2(arglist_add_block, l, b))
-#define bare_assoc(v) dispatch1(bare_assoc_hash, v)
-#define arg_add_assocs(l,b) arg_add(l, bare_assoc(b))
-
-#define args2mrhs(a) dispatch1(mrhs_new_from_arglist, a)
-#define mrhs_new() dispatch0(mrhs_new)
-#define mrhs_add(l,a) dispatch2(mrhs_add, l, a)
-#define mrhs_add_star(l,a) dispatch2(mrhs_add_star, l, a)
-
-#define mlhs_new() dispatch0(mlhs_new)
-#define mlhs_add(l,a) dispatch2(mlhs_add, l, a)
-#define mlhs_add_star(l,a) dispatch2(mlhs_add_star, l, a)
-
-#define blockvar_new(p) dispatch1(blockvar_new, p)
-#define blockvar_add_star(l,a) dispatch2(blockvar_add_star, l, a)
-#define blockvar_add_block(l,a) dispatch2(blockvar_add_block, l, a)
-
-#define method_optarg(m,a) ((a)==Qundef ? m : dispatch2(method_add_arg,m,a))
-#define method_arg(m,a) dispatch2(method_add_arg,m,a)
-#define escape_Qundef(x) ((x)==Qundef ? Qnil : (x))
-
-#define FIXME 0
-
-#endif /* RIPPER */
-
-#ifndef RIPPER
-# define ifndef_ripper(x) x
-#else
-# define ifndef_ripper(x)
-#endif
-
-#ifndef RIPPER
-# define rb_warn0(fmt) rb_warn(fmt)
-# define rb_warnI(fmt,a) rb_warn(fmt,a)
-# define rb_warnS(fmt,a) rb_warn(fmt,a)
-# define rb_warning0(fmt) rb_warning(fmt)
-# define rb_warningS(fmt,a) rb_warning(fmt,a)
-#else
-# define rb_warn0(fmt) ripper_warn0(parser, fmt)
-# define rb_warnI(fmt,a) ripper_warnI(parser, fmt, a)
-# define rb_warnS(fmt,a) ripper_warnS(parser, fmt, a)
-# define rb_warning0(fmt) ripper_warning0(parser, fmt)
-# define rb_warningS(fmt,a) ripper_warningS(parser, fmt, a)
-static void ripper_warn0(struct parser_params*, const char*);
-static void ripper_warnI(struct parser_params*, const char*, int);
-static void ripper_warnS(struct parser_params*, const char*, const char*);
-static void ripper_warning0(struct parser_params*, const char*);
-static void ripper_warningS(struct parser_params*, const char*, const char*);
-#endif
-
-#ifdef RIPPER
-static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
-# define rb_compile_error ripper_compile_error
-# define compile_error ripper_compile_error
-# define PARSER_ARG parser,
-#else
-# define compile_error rb_compile_error
-# define PARSER_ARG
-#endif
-
-#define NEW_BLOCK_PARAM(b, v) NEW_NODE(NODE_BLOCK_PASS, 0, b, v)
+#define nd_nest u3.id
/* Older versions of Yacc set YYMAXDEPTH to a very low value by default (150,
for instance). This is too low for Ruby to parse some files, such as
@@ -456,72 +210,63 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
%}
-%pure_parser
-
%union {
- VALUE val;
NODE *node;
ID id;
int num;
struct RVarmap *vars;
}
-/*%%%*/
-%token
-/*%
-%token <val>
-%*/
- keyword_class
- keyword_module
- keyword_def
- keyword_undef
- keyword_begin
- keyword_rescue
- keyword_ensure
- keyword_end
- keyword_if
- keyword_unless
- keyword_then
- keyword_elsif
- keyword_else
- keyword_case
- keyword_when
- keyword_while
- keyword_until
- keyword_for
- keyword_break
- keyword_next
- keyword_redo
- keyword_retry
- keyword_in
- keyword_do
- keyword_do_cond
- keyword_do_block
- keyword_do_LAMBDA
- keyword_return
- keyword_yield
- keyword_super
- keyword_self
- keyword_nil
- keyword_true
- keyword_false
- keyword_and
- keyword_or
- keyword_not
- modifier_if
- modifier_unless
- modifier_while
- modifier_until
- modifier_rescue
- keyword_alias
- keyword_defined
- keyword_BEGIN
- keyword_END
- keyword__LINE__
- keyword__FILE__
-
-%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
-%token <node> tINTEGER tFLOAT tSTRING_CONTENT tCHAR
+%token kCLASS
+ kMODULE
+ kDEF
+ kUNDEF
+ kBEGIN
+ kRESCUE
+ kENSURE
+ kEND
+ kIF
+ kUNLESS
+ kTHEN
+ kELSIF
+ kELSE
+ kCASE
+ kWHEN
+ kWHILE
+ kUNTIL
+ kFOR
+ kBREAK
+ kNEXT
+ kREDO
+ kRETRY
+ kIN
+ kDO
+ kDO_COND
+ kDO_BLOCK
+ kRETURN
+ kYIELD
+ kSUPER
+ kSELF
+ kNIL
+ kTRUE
+ kFALSE
+ kAND
+ kOR
+ kNOT
+ kIF_MOD
+ kUNLESS_MOD
+ kWHILE_MOD
+ kUNTIL_MOD
+ kRESCUE_MOD
+ kALIAS
+ kDEFINED
+ klBEGIN
+ klEND
+ k__LINE__
+ k__FILE__
+
+%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR
+%token <node> tINTEGER tFLOAT tSTRING_CONTENT
%token <node> tNTH_REF tBACK_REF
%token <num> tREGEXP_END
@@ -532,24 +277,16 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
%type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
%type <node> expr_value arg_value primary_value
%type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
-%type <node> args call_args call_args2 opt_call_args
-%type <node> open_args paren_args opt_paren_args
+%type <node> args when_args call_args call_args2 open_args paren_args opt_paren_args
%type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs
%type <node> mrhs superclass block_call block_command
-%type <node> f_arglist f_args f_rest_arg f_post_arg
-%type <node> f_optarg f_opt f_block_arg opt_f_block_arg
-%type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
-%type <node> block_param opt_block_param block_param_def bparam_list bparam_item
-%type <node> opt_bv_decl bv_decls bvar lambda f_larglist lambda_body
-%type <node> brace_block cmd_brace_block do_block lhs none fitem
-%type <node> mlhs mlhs_head mlhs_basic mlhs_item mlhs_node mlhs_post
+%type <node> f_arglist f_args f_optarg f_opt f_rest_arg f_block_arg opt_f_block_arg
+%type <node> assoc_list assocs assoc undef_list backref string_dvar
+%type <node> block_var opt_block_var brace_block cmd_brace_block do_block lhs none fitem
+%type <node> mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node
%type <id> fsym variable sym symbol operation operation2 operation3
-%type <id> cname fname op f_norm_arg
-%type <val> f_arg
-/*%%%*/
-/*%
-%type <val> program reswords then do dot_or_colon
-%*/
+%type <id> cname fname op
+%type <num> f_norm_arg f_arg
%token tUPLUS /* unary+ */
%token tUMINUS /* unary- */
%token tPOW /* ** */
@@ -576,9 +313,8 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
%token tLBRACE_ARG /* { */
%token tSTAR /* * */
%token tAMPER /* & */
-%token tLAMBDA /* -> */
%token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG
-%token tSTRING_DBEG tSTRING_DVAR tSTRING_END tLAMBEG
+%token tSTRING_DBEG tSTRING_DVAR tSTRING_END
/*
* precedence table
@@ -587,12 +323,12 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
%nonassoc tLOWEST
%nonassoc tLBRACE_ARG
-%nonassoc modifier_if modifier_unless modifier_while modifier_until
-%left keyword_or keyword_and
-%right keyword_not
-%nonassoc keyword_defined
+%nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
+%left kOR kAND
+%right kNOT
+%nonassoc kDEFINED
%right '=' tOP_ASGN
-%left modifier_rescue
+%left kRESCUE_MOD
%right '?' ':'
%nonassoc tDOT2 tDOT3
%left tOROP
@@ -612,21 +348,15 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
%%
program : {
- /*%%%*/
lex_state = EXPR_BEG;
- top_local_init();
+ top_local_init();
if (ruby_class == rb_cObject) class_nest = 0;
else class_nest = 1;
- /*%
- lex_state = EXPR_BEG;
- class_nest = !parser->toplevel_p;
- %*/
}
compstmt
{
- /*%%%*/
if ($2 && !compile_for_eval) {
- /* last expression should not be void */
+ /* last expression should not be void */
if (nd_type($2) != NODE_BLOCK) void_expr($2);
else {
NODE *node = $2;
@@ -637,13 +367,8 @@ program : {
}
}
ruby_eval_tree = block_append(ruby_eval_tree, $2);
- top_local_setup();
- class_nest = 0;
- /*%
+ top_local_setup();
class_nest = 0;
- $$ = $2;
- parser->result = dispatch1(program, $$);
- %*/
}
;
@@ -652,8 +377,7 @@ bodystmt : compstmt
opt_else
opt_ensure
{
- /*%%%*/
- $$ = $1;
+ $$ = $1;
if ($2) {
$$ = NEW_RESCUE($1, $2, $3);
}
@@ -662,58 +386,28 @@ bodystmt : compstmt
$$ = block_append($$, $3);
}
if ($4) {
- if ($$) {
- $$ = NEW_ENSURE($$, $4);
- }
- else {
- $$ = block_append($4, NEW_NIL());
- }
+ $$ = NEW_ENSURE($$, $4);
}
fixpos($$, $1);
- /*%
- $$ = dispatch4(bodystmt,
- escape_Qundef($1),
- escape_Qundef($2),
- escape_Qundef($3),
- escape_Qundef($4));
- %*/
}
;
compstmt : stmts opt_terms
{
- /*%%%*/
void_stmts($1);
- $$ = $1;
- /*%
- $$ = $1;
- %*/
+ fixup_nodes(&deferred_nodes);
+ $$ = $1;
}
;
stmts : none
- /*%c%*/
- /*%c
- {
- $$ = dispatch2(stmts_add, dispatch0(stmts_new),
- dispatch0(void_stmt));
- }
- %*/
| stmt
{
- /*%%%*/
- $$ = newline_node(remove_begin($1));
- /*%
- $$ = dispatch2(stmts_add, dispatch0(stmts_new), $1);
- %*/
+ $$ = newline_node($1);
}
| stmts terms stmt
{
- /*%%%*/
- $$ = block_append($1, newline_node(remove_begin($3)));
- /*%
- $$ = dispatch2(stmts_add, $1, $3);
- %*/
+ $$ = block_append($1, newline_node($3));
}
| error stmt
{
@@ -721,80 +415,50 @@ stmts : none
}
;
-stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
+stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
{
- /*%%%*/
- $$ = NEW_ALIAS($2, $4);
- /*%
- $$ = dispatch2(alias, $2, $4);
- %*/
+ $$ = NEW_ALIAS($2, $4);
}
- | keyword_alias tGVAR tGVAR
+ | kALIAS tGVAR tGVAR
{
- /*%%%*/
- $$ = NEW_VALIAS($2, $3);
- /*%
- $$ = dispatch2(var_alias, $2, $3);
- %*/
+ $$ = NEW_VALIAS($2, $3);
}
- | keyword_alias tGVAR tBACK_REF
+ | kALIAS tGVAR tBACK_REF
{
- /*%%%*/
char buf[3];
sprintf(buf, "$%c", (char)$3->nd_nth);
- $$ = NEW_VALIAS($2, rb_intern(buf));
- /*%
- $$ = dispatch2(var_alias, $2, $3);
- %*/
+ $$ = NEW_VALIAS($2, rb_intern(buf));
}
- | keyword_alias tGVAR tNTH_REF
+ | kALIAS tGVAR tNTH_REF
{
- /*%%%*/
- yyerror("can't make alias for the number variables");
- $$ = 0;
- /*%
- $$ = dispatch2(var_alias, $2, $3);
- $$ = dispatch1(alias_error, $$);
- %*/
+ yyerror("can't make alias for the number variables");
+ $$ = 0;
}
- | keyword_undef undef_list
+ | kUNDEF undef_list
{
- /*%%%*/
$$ = $2;
- /*%
- $$ = dispatch1(undef, $2);
- %*/
}
- | stmt modifier_if expr_value
+ | stmt kIF_MOD expr_value
{
- /*%%%*/
- $$ = NEW_IF(cond($3), $1, 0);
- fixpos($$, $3);
+ $$ = NEW_IF(cond($3), remove_begin($1), 0);
+ fixpos($$, $3);
if (cond_negative(&$$->nd_cond)) {
- $$->nd_else = $$->nd_body;
- $$->nd_body = 0;
+ $$->nd_else = $$->nd_body;
+ $$->nd_body = 0;
}
- /*%
- $$ = dispatch2(if_mod, $3, $1);
- %*/
}
- | stmt modifier_unless expr_value
+ | stmt kUNLESS_MOD expr_value
{
- /*%%%*/
- $$ = NEW_UNLESS(cond($3), $1, 0);
- fixpos($$, $3);
+ $$ = NEW_UNLESS(cond($3), remove_begin($1), 0);
+ fixpos($$, $3);
if (cond_negative(&$$->nd_cond)) {
- $$->nd_body = $$->nd_else;
- $$->nd_else = 0;
+ $$->nd_body = $$->nd_else;
+ $$->nd_else = 0;
}
- /*%
- $$ = dispatch2(unless_mod, $3, $1);
- %*/
}
- | stmt modifier_while expr_value
+ | stmt kWHILE_MOD expr_value
{
- /*%%%*/
if ($1 && nd_type($1) == NODE_BEGIN) {
$$ = NEW_WHILE(cond($3), $1->nd_body, 0);
}
@@ -804,13 +468,9 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
if (cond_negative(&$$->nd_cond)) {
nd_set_type($$, NODE_UNTIL);
}
- /*%
- $$ = dispatch2(while_mod, $3, $1);
- %*/
}
- | stmt modifier_until expr_value
+ | stmt kUNTIL_MOD expr_value
{
- /*%%%*/
if ($1 && nd_type($1) == NODE_BEGIN) {
$$ = NEW_UNTIL(cond($3), $1->nd_body, 0);
}
@@ -820,74 +480,46 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
if (cond_negative(&$$->nd_cond)) {
nd_set_type($$, NODE_WHILE);
}
- /*%
- $$ = dispatch2(until_mod, $3, $1);
- %*/
}
- | stmt modifier_rescue stmt
+ | stmt kRESCUE_MOD stmt
{
- /*%%%*/
- $$ = NEW_RESCUE($1, NEW_RESBODY(0,$3,0), 0);
- /*%
- $$ = dispatch2(rescue_mod, $3, $1);
- %*/
+ NODE *resq = NEW_RESBODY(0, remove_begin($3), 0);
+ $$ = NEW_RESCUE(remove_begin($1), resq, 0);
}
- | keyword_BEGIN
+ | klBEGIN
{
- /*%%%*/
if (in_def || in_single) {
yyerror("BEGIN in method");
}
local_push(0);
- /*%
- if (in_def || in_single) {
- yyerror("BEGIN in method");
- }
- %*/
}
'{' compstmt '}'
{
- /*%%%*/
ruby_eval_tree_begin = block_append(ruby_eval_tree_begin,
NEW_PREEXE($4));
local_pop();
$$ = 0;
- /*%
- $$ = dispatch1(BEGIN, $4);
- %*/
}
- | keyword_END '{' compstmt '}'
+ | klEND '{' compstmt '}'
{
if (in_def || in_single) {
- rb_warn0("END in method; use at_exit");
+ rb_warn("END in method; use at_exit");
}
- /*%%%*/
- $$ = NEW_POSTEXE($3);
- /*%
- $$ = dispatch1(END, $3);
- %*/
+
+ $$ = NEW_ITER(0, NEW_POSTEXE(), $3);
}
| lhs '=' command_call
{
- /*%%%*/
$$ = node_assign($1, $3);
- /*%
- $$ = dispatch2(assign, $1, $3);
- %*/
}
| mlhs '=' command_call
{
- /*%%%*/
value_expr($3);
$1->nd_value = ($1->nd_head) ? NEW_TO_ARY($3) : NEW_ARRAY($3);
$$ = $1;
- /*%
- $$ = dispatch2(massign, $1, $3);
- %*/
}
| var_lhs tOP_ASGN command_call
{
- /*%%%*/
value_expr($3);
if ($1) {
ID vid = $1->nd_vid;
@@ -910,16 +542,13 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
else {
$$ = 0;
}
- /*%
- $$ = dispatch3(opassign, $1, $2, $3);
- %*/
}
- | primary_value '[' opt_call_args rbracket tOP_ASGN command_call
+ | primary_value '[' aref_args ']' tOP_ASGN command_call
{
- /*%%%*/
- NODE *args = $3;
+ NODE *args;
value_expr($6);
+ if (!$3) $3 = NEW_ZARRAY();
args = arg_concat($6, $3);
if ($5 == tOROP) {
$5 = 0;
@@ -928,15 +557,10 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
$5 = 1;
}
$$ = NEW_OP_ASGN1($1, $5, args);
- fixpos($$, $1);
- /*%
- $$ = dispatch2(aref_field, $1, escape_Qundef($3));
- $$ = dispatch3(opassign, $$, $5, $6);
- %*/
+ fixpos($$, $1);
}
| primary_value '.' tIDENTIFIER tOP_ASGN command_call
{
- /*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
@@ -945,15 +569,10 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
- fixpos($$, $1);
- /*%
- $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
- $$ = dispatch3(opassign, $$, $4, $5);
- %*/
+ fixpos($$, $1);
}
| primary_value '.' tCONSTANT tOP_ASGN command_call
{
- /*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
@@ -962,15 +581,10 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
- fixpos($$, $1);
- /*%
- $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
- $$ = dispatch3(opassign, $$, $4, $5);
- %*/
+ fixpos($$, $1);
}
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
{
- /*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
@@ -979,576 +593,315 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
- fixpos($$, $1);
- /*%
- $$ = dispatch3(field, $1, ripper_intern("::"), $3);
- $$ = dispatch3(opassign, $$, $4, $5);
- %*/
+ fixpos($$, $1);
}
| backref tOP_ASGN command_call
{
- /*%%%*/
- rb_backref_error($1);
+ rb_backref_error($1);
$$ = 0;
- /*%
- $$ = dispatch2(assign, dispatch1(var_field, $1), $3);
- $$ = dispatch1(assign_error, $$);
- %*/
}
| lhs '=' mrhs
{
- /*%%%*/
- $$ = node_assign($1, $3);
- /*%
- $$ = dispatch2(assign, $1, $3);
- %*/
+ $$ = node_assign($1, NEW_SVALUE($3));
}
| mlhs '=' arg_value
{
- /*%%%*/
- $1->nd_value = $3;
+ $1->nd_value = ($1->nd_head) ? NEW_TO_ARY($3) : NEW_ARRAY($3);
$$ = $1;
- /*%
- dispatch2(massign, $1, $3);
- %*/
}
| mlhs '=' mrhs
{
- /*%%%*/
$1->nd_value = $3;
$$ = $1;
- /*%
- $$ = dispatch2(massign, $1, $3);
- %*/
}
| expr
;
expr : command_call
- | expr keyword_and expr
+ | expr kAND expr
{
- /*%%%*/
$$ = logop(NODE_AND, $1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("and"), $3);
- %*/
}
- | expr keyword_or expr
+ | expr kOR expr
{
- /*%%%*/
$$ = logop(NODE_OR, $1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("or"), $3);
- %*/
}
- | keyword_not expr
+ | kNOT expr
{
- /*%%%*/
$$ = NEW_NOT(cond($2));
- /*%
- $$ = dispatch2(unary, ripper_intern("not"), $2);
- %*/
}
| '!' command_call
{
- /*%%%*/
$$ = NEW_NOT(cond($2));
- /*%
- $$ = dispatch2(unary, ID2SYM('!'), $2);
- %*/
}
| arg
;
expr_value : expr
{
- /*%%%*/
value_expr($$);
$$ = $1;
- /*%
- $$ = $1;
- %*/
}
;
command_call : command
| block_command
- | keyword_return call_args
+ | kRETURN call_args
{
- /*%%%*/
$$ = NEW_RETURN(ret_args($2));
- /*%
- $$ = dispatch1(return, $2);
- %*/
}
- | keyword_break call_args
+ | kBREAK call_args
{
- /*%%%*/
$$ = NEW_BREAK(ret_args($2));
- /*%
- $$ = dispatch1(break, $2);
- %*/
}
- | keyword_next call_args
+ | kNEXT call_args
{
- /*%%%*/
$$ = NEW_NEXT(ret_args($2));
- /*%
- $$ = dispatch1(next, $2);
- %*/
}
;
block_command : block_call
| block_call '.' operation2 command_args
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- /*%
- $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
- $$ = method_arg($$, $4);
- %*/
+ $$ = new_call($1, $3, $4);
}
| block_call tCOLON2 operation2 command_args
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- /*%
- $$ = dispatch3(call, $1, ripper_intern("::"), $3);
- $$ = method_arg($$, $4);
- %*/
+ $$ = new_call($1, $3, $4);
}
;
cmd_brace_block : tLBRACE_ARG
{
- /*%%%*/
$<vars>$ = dyna_push();
$<num>1 = ruby_sourceline;
- /*%
- %*/
}
- opt_block_param {$<vars>$ = ruby_dyna_vars;}
+ opt_block_var {$<vars>$ = ruby_dyna_vars;}
compstmt
'}'
{
- /*%%%*/
- $3->nd_body = block_append($3->nd_body,
- dyna_init($5, $<vars>4));
- $$ = $3;
+ $$ = NEW_ITER($3, 0, dyna_init($5, $<vars>4));
nd_set_line($$, $<num>1);
dyna_pop($<vars>2);
- /*%
- $$ = dispatch2(brace_block, escape_Qundef($3), $5);
- %*/
}
;
command : operation command_args %prec tLOWEST
{
- /*%%%*/
- $$ = NEW_FCALL($1, $2);
- fixpos($$, $2);
- /*%
- $$ = dispatch2(command, $1, $2);
- %*/
- }
+ $$ = new_fcall($1, $2);
+ fixpos($$, $2);
+ }
| operation command_args cmd_brace_block
{
- /*%%%*/
- $$ = NEW_FCALL($1, $2);
- block_dup_check($2,$3);
- fixpos($$, $2);
- /*%
- $$ = dispatch2(command, $1, $2);
- $$ = dispatch2(iter_block, $$, $3);
- %*/
- }
+ $$ = new_fcall($1, $2);
+ if ($3) {
+ if (nd_type($$) == NODE_BLOCK_PASS) {
+ rb_compile_error("both block arg and actual block given");
+ }
+ $3->nd_iter = $$;
+ $$ = $3;
+ }
+ fixpos($$, $2);
+ }
| primary_value '.' operation2 command_args %prec tLOWEST
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- fixpos($$, $1);
- /*%
- $$ = dispatch4(command_call, $1, ripper_id2sym('.'), $3, $4);
- %*/
+ $$ = new_call($1, $3, $4);
+ fixpos($$, $1);
}
| primary_value '.' operation2 command_args cmd_brace_block
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- block_dup_check($4,$5);
- fixpos($$, $1);
- /*%
- $$ = dispatch4(command_call, $1, ripper_id2sym('.'), $3, $4);
- $$ = dispatch2(iter_block, $$, $5);
- %*/
+ $$ = new_call($1, $3, $4);
+ if ($5) {
+ if (nd_type($$) == NODE_BLOCK_PASS) {
+ rb_compile_error("both block arg and actual block given");
+ }
+ $5->nd_iter = $$;
+ $$ = $5;
+ }
+ fixpos($$, $1);
}
| primary_value tCOLON2 operation2 command_args %prec tLOWEST
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- fixpos($$, $1);
- /*%
- $$ = dispatch4(command_call, $1, ripper_intern("::"), $3, $4);
- %*/
+ $$ = new_call($1, $3, $4);
+ fixpos($$, $1);
}
| primary_value tCOLON2 operation2 command_args cmd_brace_block
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- block_dup_check($4,$5);
- fixpos($$, $1);
- /*%
- $$ = dispatch4(command_call, $1, ripper_intern("::"), $3, $4);
- $$ = dispatch2(iter_block, $$, $5);
- %*/
+ $$ = new_call($1, $3, $4);
+ if ($5) {
+ if (nd_type($$) == NODE_BLOCK_PASS) {
+ rb_compile_error("both block arg and actual block given");
+ }
+ $5->nd_iter = $$;
+ $$ = $5;
+ }
+ fixpos($$, $1);
}
- | keyword_super command_args
+ | kSUPER command_args
{
- /*%%%*/
- $$ = NEW_SUPER($2);
- fixpos($$, $2);
- /*%
- $$ = dispatch1(super, $2);
- %*/
+ $$ = new_super($2);
+ fixpos($$, $2);
}
- | keyword_yield command_args
+ | kYIELD command_args
{
- /*%%%*/
$$ = new_yield($2);
- fixpos($$, $2);
- /*%
- $$ = dispatch1(yield, $2);
- %*/
+ fixpos($$, $2);
}
;
mlhs : mlhs_basic
- | tLPAREN mlhs rparen
+ | tLPAREN mlhs_entry ')'
+ {
+ $$ = $2;
+ }
+ ;
+
+mlhs_entry : mlhs_basic
+ | tLPAREN mlhs_entry ')'
{
- /*%%%*/
$$ = NEW_MASGN(NEW_LIST($2), 0);
- /*%
- $$ = dispatch1(mlhs_paren, $2);
- %*/
}
;
mlhs_basic : mlhs_head
{
- /*%%%*/
$$ = NEW_MASGN($1, 0);
- /*%
- $$ = $1;
- %*/
}
| mlhs_head mlhs_item
{
- /*%%%*/
$$ = NEW_MASGN(list_append($1,$2), 0);
- /*%
- $$ = mlhs_add($1, $2);
- %*/
}
| mlhs_head tSTAR mlhs_node
{
- /*%%%*/
$$ = NEW_MASGN($1, $3);
- /*%
- $$ = mlhs_add_star($1, $3);
- %*/
- }
- | mlhs_head tSTAR mlhs_node ',' mlhs_post
- {
- /*%%%*/
- $$ = NEW_MASGN($1, NEW_POSTARG($3,$5));
- /*%
- $$ = mlhs_add_star($1, $3);
- %*/
}
| mlhs_head tSTAR
{
- /*%%%*/
$$ = NEW_MASGN($1, -1);
- /*%
- $$ = mlhs_add_star($1, Qnil);
- %*/
- }
- | mlhs_head tSTAR ',' mlhs_post
- {
- /*%%%*/
- $$ = NEW_MASGN($1, NEW_POSTARG(-1,$4));
- /*%
- $$ = mlhs_add_star($1, Qnil);
- %*/
}
| tSTAR mlhs_node
{
- /*%%%*/
$$ = NEW_MASGN(0, $2);
- /*%
- $$ = mlhs_add_star(mlhs_new(), $2);
- %*/
- }
- | tSTAR mlhs_node ',' mlhs_post
- {
- /*%%%*/
- $$ = NEW_MASGN(0, NEW_POSTARG($2,$4));
- /*%
- $$ = mlhs_add_star(mlhs_new(), $2);
- %*/
}
| tSTAR
{
- /*%%%*/
$$ = NEW_MASGN(0, -1);
- /*%
- $$ = mlhs_add_star(mlhs_new(), Qnil);
- %*/
- }
- | tSTAR ',' mlhs_head
- {
- /*%%%*/
- $$ = NEW_MASGN(0, NEW_POSTARG(-1,$3));
- /*%
- $$ = mlhs_add_star(mlhs_new(), Qnil);
- %*/
}
;
mlhs_item : mlhs_node
- | tLPAREN mlhs rparen
+ | tLPAREN mlhs_entry ')'
{
- /*%%%*/
$$ = $2;
- /*%
- $$ = dispatch1(mlhs_paren, $2);
- %*/
}
;
mlhs_head : mlhs_item ','
{
- /*%%%*/
$$ = NEW_LIST($1);
- /*%
- $$ = mlhs_add(mlhs_new(), $1);
- %*/
}
| mlhs_head mlhs_item ','
{
- /*%%%*/
$$ = list_append($1, $2);
- /*%
- $$ = mlhs_add($1, $2);
- %*/
- }
- ;
-
-mlhs_post : mlhs_item
- {
- /*%%%*/
- $$ = NEW_LIST($1);
- /*%
- $$ = mlhs_add(mlhs_new(), $1);
- %*/
- }
- | mlhs_post ',' mlhs_item
- {
- /*%%%*/
- $$ = list_append($1, $3);
- /*%
- $$ = mlhs_add($1, $3);
- %*/
}
;
mlhs_node : variable
{
- /*%%%*/
$$ = assignable($1, 0);
- /*%
- $$ = $1;
- %*/
}
- | primary_value '[' opt_call_args rbracket
+ | primary_value '[' aref_args ']'
{
- /*%%%*/
$$ = aryset($1, $3);
- /*%
- $$ = dispatch2(aref_field, $1, escape_Qundef($3));
- %*/
}
| primary_value '.' tIDENTIFIER
{
- /*%%%*/
$$ = attrset($1, $3);
- /*%
- $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
- %*/
}
| primary_value tCOLON2 tIDENTIFIER
{
- /*%%%*/
$$ = attrset($1, $3);
- /*%
- $$ = dispatch2(constpath_field, $1, $3);
- %*/
}
| primary_value '.' tCONSTANT
{
- /*%%%*/
$$ = attrset($1, $3);
- /*%
- $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
- %*/
}
| primary_value tCOLON2 tCONSTANT
{
- /*%%%*/
if (in_def || in_single)
yyerror("dynamic constant assignment");
$$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
- /*%
- if (in_def || in_single)
- yyerror("dynamic constant assignment");
- $$ = dispatch2(constpath_field, $1, $3);
- %*/
}
| tCOLON3 tCONSTANT
{
- /*%%%*/
if (in_def || in_single)
yyerror("dynamic constant assignment");
$$ = NEW_CDECL(0, 0, NEW_COLON3($2));
- /*%
- $$ = dispatch1(topconst_field, $2);
- %*/
}
| backref
{
- /*%%%*/
- rb_backref_error($1);
+ rb_backref_error($1);
$$ = 0;
- /*%
- $$ = dispatch1(var_field, $1);
- $$ = dispatch1(assign_error, $$);
- %*/
}
;
lhs : variable
{
- /*%%%*/
$$ = assignable($1, 0);
- /*%
- $$ = dispatch1(var_field, $1);
- %*/
}
- | primary_value '[' opt_call_args rbracket
+ | primary_value '[' aref_args ']'
{
- /*%%%*/
$$ = aryset($1, $3);
- /*%
- $$ = dispatch2(aref_field, $1, escape_Qundef($3));
- %*/
}
| primary_value '.' tIDENTIFIER
{
- /*%%%*/
$$ = attrset($1, $3);
- /*%
- $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
- %*/
}
| primary_value tCOLON2 tIDENTIFIER
{
- /*%%%*/
$$ = attrset($1, $3);
- /*%
- $$ = dispatch3(field, $1, ripper_intern("::"), $3);
- %*/
}
| primary_value '.' tCONSTANT
{
- /*%%%*/
$$ = attrset($1, $3);
- /*%
- $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
- %*/
}
| primary_value tCOLON2 tCONSTANT
{
- /*%%%*/
if (in_def || in_single)
yyerror("dynamic constant assignment");
$$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
- /*%
- $$ = dispatch2(constpath_field, $1, $3);
- if (in_def || in_single) {
- $$ = dispatch1(assign_error, $$);
- }
- %*/
}
| tCOLON3 tCONSTANT
{
- /*%%%*/
if (in_def || in_single)
yyerror("dynamic constant assignment");
$$ = NEW_CDECL(0, 0, NEW_COLON3($2));
- /*%
- $$ = dispatch1(topconst_field, $2);
- if (in_def || in_single) {
- $$ = dispatch1(assign_error, $$);
- }
- %*/
}
| backref
{
- /*%%%*/
- rb_backref_error($1);
+ rb_backref_error($1);
$$ = 0;
- /*%
- $$ = dispatch1(assign_error, $1);
- %*/
}
;
cname : tIDENTIFIER
{
- /*%%%*/
yyerror("class/module name must be CONSTANT");
- /*%
- $$ = dispatch1(class_name_error, $1);
- %*/
}
| tCONSTANT
;
cpath : tCOLON3 cname
{
- /*%%%*/
$$ = NEW_COLON3($2);
- /*%
- $$ = dispatch1(topconst_ref, $2);
- %*/
}
| cname
{
- /*%%%*/
$$ = NEW_COLON2(0, $$);
- /*%
- $$ = dispatch1(const_ref, $1);
- %*/
}
| primary_value tCOLON2 cname
{
- /*%%%*/
$$ = NEW_COLON2($1, $3);
- /*%
- $$ = dispatch2(constpath_ref, $1, $3);
- %*/
}
;
@@ -1557,23 +910,13 @@ fname : tIDENTIFIER
| tFID
| op
{
- /*%%%*/
- lex_state = EXPR_END;
- $$ = $1;
- /*%
lex_state = EXPR_END;
$$ = $1;
- %*/
}
| reswords
{
- /*%%%*/
lex_state = EXPR_END;
$$ = $<id>1;
- /*%
- lex_state = EXPR_END;
- $$ = $1;
- %*/
}
;
@@ -1583,93 +926,68 @@ fsym : fname
fitem : fsym
{
- /*%%%*/
$$ = NEW_LIT(ID2SYM($1));
- /*%
- $$ = dispatch1(symbol_literal, $1);
- %*/
}
| dsym
;
undef_list : fitem
{
- /*%%%*/
$$ = NEW_UNDEF($1);
- /*%
- $$ = rb_ary_new3(1, $1);
- %*/
}
| undef_list ',' {lex_state = EXPR_FNAME;} fitem
{
- /*%%%*/
$$ = block_append($1, NEW_UNDEF($4));
- /*%
- rb_ary_push($1, $4);
- %*/
}
;
-op : '|' { ifndef_ripper($$ = '|'); }
- | '^' { ifndef_ripper($$ = '^'); }
- | '&' { ifndef_ripper($$ = '&'); }
- | tCMP { ifndef_ripper($$ = tCMP); }
- | tEQ { ifndef_ripper($$ = tEQ); }
- | tEQQ { ifndef_ripper($$ = tEQQ); }
- | tMATCH { ifndef_ripper($$ = tMATCH); }
- | '>' { ifndef_ripper($$ = '>'); }
- | tGEQ { ifndef_ripper($$ = tGEQ); }
- | '<' { ifndef_ripper($$ = '<'); }
- | tLEQ { ifndef_ripper($$ = tLEQ); }
- | tLSHFT { ifndef_ripper($$ = tLSHFT); }
- | tRSHFT { ifndef_ripper($$ = tRSHFT); }
- | '+' { ifndef_ripper($$ = '+'); }
- | '-' { ifndef_ripper($$ = '-'); }
- | '*' { ifndef_ripper($$ = '*'); }
- | tSTAR { ifndef_ripper($$ = '*'); }
- | '/' { ifndef_ripper($$ = '/'); }
- | '%' { ifndef_ripper($$ = '%'); }
- | tPOW { ifndef_ripper($$ = tPOW); }
- | '~' { ifndef_ripper($$ = '~'); }
- | tUPLUS { ifndef_ripper($$ = tUPLUS); }
- | tUMINUS { ifndef_ripper($$ = tUMINUS); }
- | tAREF { ifndef_ripper($$ = tAREF); }
- | tASET { ifndef_ripper($$ = tASET); }
- | '`' { ifndef_ripper($$ = '`'); }
+op : '|' { $$ = '|'; }
+ | '^' { $$ = '^'; }
+ | '&' { $$ = '&'; }
+ | tCMP { $$ = tCMP; }
+ | tEQ { $$ = tEQ; }
+ | tEQQ { $$ = tEQQ; }
+ | tMATCH { $$ = tMATCH; }
+ | '>' { $$ = '>'; }
+ | tGEQ { $$ = tGEQ; }
+ | '<' { $$ = '<'; }
+ | tLEQ { $$ = tLEQ; }
+ | tLSHFT { $$ = tLSHFT; }
+ | tRSHFT { $$ = tRSHFT; }
+ | '+' { $$ = '+'; }
+ | '-' { $$ = '-'; }
+ | '*' { $$ = '*'; }
+ | tSTAR { $$ = '*'; }
+ | '/' { $$ = '/'; }
+ | '%' { $$ = '%'; }
+ | tPOW { $$ = tPOW; }
+ | '~' { $$ = '~'; }
+ | tUPLUS { $$ = tUPLUS; }
+ | tUMINUS { $$ = tUMINUS; }
+ | tAREF { $$ = tAREF; }
+ | tASET { $$ = tASET; }
+ | '`' { $$ = '`'; }
;
-reswords : keyword__LINE__ | keyword__FILE__ | keyword_BEGIN | keyword_END
- | keyword_alias | keyword_and | keyword_begin
- | keyword_break | keyword_case | keyword_class | keyword_def
- | keyword_defined | keyword_do | keyword_else | keyword_elsif
- | keyword_end | keyword_ensure | keyword_false
- | keyword_for | keyword_in | keyword_module | keyword_next
- | keyword_nil | keyword_not | keyword_or | keyword_redo
- | keyword_rescue | keyword_retry | keyword_return | keyword_self
- | keyword_super | keyword_then | keyword_true | keyword_undef
- | keyword_when | keyword_yield | keyword_if | keyword_unless
- | keyword_while | keyword_until
+reswords : k__LINE__ | k__FILE__ | klBEGIN | klEND
+ | kALIAS | kAND | kBEGIN | kBREAK | kCASE | kCLASS | kDEF
+ | kDEFINED | kDO | kELSE | kELSIF | kEND | kENSURE | kFALSE
+ | kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT
+ | kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF | kSUPER
+ | kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD
+ | kIF | kUNLESS | kWHILE | kUNTIL
;
arg : lhs '=' arg
{
- /*%%%*/
$$ = node_assign($1, $3);
- /*%
- $$ = dispatch2(assign, $1, $3);
- %*/
}
- | lhs '=' arg modifier_rescue arg
+ | lhs '=' arg kRESCUE_MOD arg
{
- /*%%%*/
$$ = node_assign($1, NEW_RESCUE($3, NEW_RESBODY(0,$5,0), 0));
- /*%
- $$ = dispatch2(assign, $1, dispatch2(rescue_mod,$3,$5));
- %*/
}
| var_lhs tOP_ASGN arg
{
- /*%%%*/
value_expr($3);
if ($1) {
ID vid = $1->nd_vid;
@@ -1692,16 +1010,13 @@ arg : lhs '=' arg
else {
$$ = 0;
}
- /*%
- $$ = dispatch3(opassign, $1, $2, $3);
- %*/
}
- | primary_value '[' opt_call_args rbracket tOP_ASGN arg
+ | primary_value '[' aref_args ']' tOP_ASGN arg
{
- /*%%%*/
- NODE *args;
+ NODE *args;
value_expr($6);
+ if (!$3) $3 = NEW_ZARRAY();
args = arg_concat($6, $3);
if ($5 == tOROP) {
$5 = 0;
@@ -1710,15 +1025,10 @@ arg : lhs '=' arg
$5 = 1;
}
$$ = NEW_OP_ASGN1($1, $5, args);
- fixpos($$, $1);
- /*%
- $1 = dispatch2(aref_field, $1, escape_Qundef($3));
- $$ = dispatch3(opassign, $1, $5, $6);
- %*/
+ fixpos($$, $1);
}
| primary_value '.' tIDENTIFIER tOP_ASGN arg
{
- /*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
@@ -1727,15 +1037,10 @@ arg : lhs '=' arg
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
- fixpos($$, $1);
- /*%
- $1 = dispatch3(field, $1, ripper_id2sym('.'), $3);
- $$ = dispatch3(opassign, $1, $4, $5);
- %*/
+ fixpos($$, $1);
}
| primary_value '.' tCONSTANT tOP_ASGN arg
{
- /*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
@@ -1744,15 +1049,10 @@ arg : lhs '=' arg
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
- fixpos($$, $1);
- /*%
- $1 = dispatch3(field, $1, ripper_id2sym('.'), $3);
- $$ = dispatch3(opassign, $1, $4, $5);
- %*/
+ fixpos($$, $1);
}
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
{
- /*%%%*/
value_expr($5);
if ($4 == tOROP) {
$4 = 0;
@@ -1761,336 +1061,173 @@ arg : lhs '=' arg
$4 = 1;
}
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
- fixpos($$, $1);
- /*%
- $1 = dispatch3(field, $1, ripper_intern("::"), $3);
- $$ = dispatch3(opassign, $1, $4, $5);
- %*/
+ fixpos($$, $1);
}
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg
{
- /*%%%*/
yyerror("constant re-assignment");
$$ = 0;
- /*%
- $$ = dispatch2(constpath_field, $1, $3);
- $$ = dispatch3(opassign, $$, $4, $5);
- $$ = dispatch1(assign_error, $$);
- %*/
}
| tCOLON3 tCONSTANT tOP_ASGN arg
{
- /*%%%*/
yyerror("constant re-assignment");
$$ = 0;
- /*%
- $$ = dispatch1(topconst_field, $2);
- $$ = dispatch3(opassign, $$, $3, $4);
- $$ = dispatch1(assign_error, $$);
- %*/
}
| backref tOP_ASGN arg
{
- /*%%%*/
- rb_backref_error($1);
+ rb_backref_error($1);
$$ = 0;
- /*%
- $$ = dispatch1(var_field, $1);
- $$ = dispatch3(opassign, $$, $2, $3);
- $$ = dispatch1(assign_error, $$);
- %*/
}
| arg tDOT2 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)) {
- $1->nd_lit = rb_range_new($1->nd_lit, $3->nd_lit, Qfalse);
- $$ = $1;
+ deferred_nodes = list_append(deferred_nodes, $$);
}
- else {
- $$ = NEW_DOT2($1, $3);
- }
- /*%
- $$ = dispatch2(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)) {
- $1->nd_lit = rb_range_new($1->nd_lit, $3->nd_lit, Qtrue);
- $$ = $1;
+ deferred_nodes = list_append(deferred_nodes, $$);
}
- else {
- $$ = NEW_DOT3($1, $3);
- }
- /*%
- $$ = dispatch2(dot3, $1, $3);
- %*/
}
| arg '+' arg
{
- /*%%%*/
$$ = call_op($1, '+', 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ID2SYM('+'), $3);
- %*/
}
| arg '-' arg
{
- /*%%%*/
- $$ = call_op($1, '-', 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ID2SYM('-'), $3);
- %*/
+ $$ = call_op($1, '-', 1, $3);
}
| arg '*' arg
{
- /*%%%*/
- $$ = call_op($1, '*', 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ID2SYM('*'), $3);
- %*/
+ $$ = call_op($1, '*', 1, $3);
}
| arg '/' arg
{
- /*%%%*/
$$ = call_op($1, '/', 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ID2SYM('/'), $3);
- %*/
}
| arg '%' arg
{
- /*%%%*/
$$ = call_op($1, '%', 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ID2SYM('%'), $3);
- %*/
}
| arg tPOW arg
{
- /*%%%*/
$$ = call_op($1, tPOW, 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("**"), $3);
- %*/
}
| tUMINUS_NUM tINTEGER tPOW arg
{
- /*%%%*/
$$ = call_op(call_op($2, tPOW, 1, $4), tUMINUS, 0, 0);
- /*%
- $$ = dispatch3(binary, $2, ripper_intern("**"), $4);
- $$ = dispatch2(unary, ripper_intern("-@"), $$);
- %*/
}
| tUMINUS_NUM tFLOAT tPOW arg
{
- /*%%%*/
$$ = call_op(call_op($2, tPOW, 1, $4), tUMINUS, 0, 0);
- /*%
- $$ = dispatch3(binary, $2, ripper_intern("**"), $4);
- $$ = dispatch2(unary, ripper_intern("-@"), $$);
- %*/
}
| tUPLUS arg
{
- /*%%%*/
if ($2 && nd_type($2) == NODE_LIT) {
$$ = $2;
}
else {
$$ = call_op($2, tUPLUS, 0, 0);
}
- /*%
- $$ = dispatch2(unary, ripper_intern("+@"), $2);
- %*/
}
| tUMINUS arg
{
- /*%%%*/
$$ = call_op($2, tUMINUS, 0, 0);
- /*%
- $$ = dispatch2(unary, ripper_intern("-@"), $2);
- %*/
}
| arg '|' arg
{
- /*%%%*/
- $$ = call_op($1, '|', 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ID2SYM('!'), $3);
- %*/
+ $$ = call_op($1, '|', 1, $3);
}
| arg '^' arg
{
- /*%%%*/
$$ = call_op($1, '^', 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ID2SYM('^'), $3);
- %*/
}
| arg '&' arg
{
- /*%%%*/
$$ = call_op($1, '&', 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ID2SYM('&'), $3);
- %*/
}
| arg tCMP arg
{
- /*%%%*/
$$ = call_op($1, tCMP, 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("<=>"), $3);
- %*/
}
| arg '>' arg
{
- /*%%%*/
$$ = call_op($1, '>', 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ID2SYM('>'), $3);
- %*/
}
| arg tGEQ arg
{
- /*%%%*/
$$ = call_op($1, tGEQ, 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern(">="), $3);
- %*/
}
| arg '<' arg
{
- /*%%%*/
$$ = call_op($1, '<', 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ID2SYM('<'), $3);
- %*/
}
| arg tLEQ arg
{
- /*%%%*/
$$ = call_op($1, tLEQ, 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("<="), $3);
- %*/
}
| arg tEQ arg
{
- /*%%%*/
$$ = call_op($1, tEQ, 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("=="), $3);
- %*/
}
| arg tEQQ arg
{
- /*%%%*/
$$ = call_op($1, tEQQ, 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("==="), $3);
- %*/
}
| arg tNEQ arg
{
- /*%%%*/
$$ = NEW_NOT(call_op($1, tEQ, 1, $3));
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("!="), $3);
- %*/
}
| arg tMATCH arg
{
- /*%%%*/
- $$ = match_op($1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("=~"), $3);
- %*/
+ $$ = match_gen($1, $3);
}
| arg tNMATCH arg
{
- /*%%%*/
- $$ = NEW_NOT(match_op($1, $3));
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("!~"), $3);
- %*/
+ $$ = NEW_NOT(match_gen($1, $3));
}
| '!' arg
{
- /*%%%*/
$$ = NEW_NOT(cond($2));
- /*%
- $$ = dispatch2(unary, ID2SYM('!'), $2);
- %*/
}
| '~' arg
{
- /*%%%*/
$$ = call_op($2, '~', 0, 0);
- /*%
- $$ = dispatch2(unary, ID2SYM('~'), $2);
- %*/
}
| arg tLSHFT arg
{
- /*%%%*/
$$ = call_op($1, tLSHFT, 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("<<"), $3);
- %*/
}
| arg tRSHFT arg
{
- /*%%%*/
$$ = call_op($1, tRSHFT, 1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern(">>"), $3);
- %*/
}
| arg tANDOP arg
{
- /*%%%*/
$$ = logop(NODE_AND, $1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("&&"), $3);
- %*/
}
| arg tOROP arg
{
- /*%%%*/
$$ = logop(NODE_OR, $1, $3);
- /*%
- $$ = dispatch3(binary, $1, ripper_intern("||"), $3);
- %*/
}
- | keyword_defined opt_nl {in_defined = 1;} arg
+ | kDEFINED opt_nl {in_defined = 1;} arg
{
- /*%%%*/
in_defined = 0;
$$ = NEW_DEFINED($4);
- /*%
- in_defined = 0;
- $$ = dispatch1(defined, $4);
- %*/
}
- | arg '?' arg opt_nl ':' arg
+ | arg '?' arg ':' arg
{
- /*%%%*/
- $$ = NEW_IF(cond($1), $3, $6);
- fixpos($$, $1);
- /*%
- $$ = dispatch3(ifop, $1, $3, $6);
- %*/
+ $$ = NEW_IF(cond($1), $3, $5);
+ fixpos($$, $1);
}
| primary
{
@@ -2100,45 +1237,54 @@ arg : lhs '=' arg
arg_value : arg
{
- /*%%%*/
value_expr($1);
$$ = $1;
- /*%
- $$ = $1;
- %*/
}
;
aref_args : none
+ | command opt_nl
+ {
+ rb_warn("parenthesize argument(s) for future version");
+ $$ = NEW_LIST($1);
+ }
| args trailer
{
$$ = $1;
}
- | args ',' assocs trailer
+ | args ',' tSTAR arg opt_nl
{
- /*%%%*/
- $$ = list_append($1, NEW_HASH($3));
- /*%
- $$ = arg_add_assocs($1, $3);
- %*/
+ value_expr($4);
+ $$ = arg_concat($1, $4);
}
| assocs trailer
{
- /*%%%*/
$$ = NEW_LIST(NEW_HASH($1));
- /*%
- $$ = arg_add_assocs(arg_new(), $1);
- %*/
+ }
+ | tSTAR arg opt_nl
+ {
+ value_expr($2);
+ $$ = NEW_NEWLINE(NEW_SPLAT($2));
}
;
-paren_args : '(' opt_call_args rparen
+paren_args : '(' none ')'
+ {
+ $$ = $2;
+ }
+ | '(' call_args opt_nl ')'
{
- /*%%%*/
$$ = $2;
- /*%
- $$ = dispatch1(arg_paren, escape_Qundef($2));
- %*/
+ }
+ | '(' block_call opt_nl ')'
+ {
+ rb_warn("parenthesize argument for future version");
+ $$ = NEW_LIST($2);
+ }
+ | '(' args ',' block_call opt_nl ')'
+ {
+ rb_warn("parenthesize argument for future version");
+ $$ = list_append($2, $4);
}
;
@@ -2146,99 +1292,99 @@ opt_paren_args : none
| paren_args
;
-opt_call_args : none
- | call_args
- ;
-
call_args : command
{
- rb_warn("parenthesize argument(s) for future version");
- /*%%%*/
+ rb_warn("parenthesize argument(s) for future version");
$$ = NEW_LIST($1);
- /*%
- $$ = arg_add(arg_new(), $1);
- %*/
}
| args opt_block_arg
{
- /*%%%*/
$$ = arg_blk_pass($1, $2);
- /*%
- $$ = arg_add_optblock($1, $2);
- %*/
+ }
+ | args ',' tSTAR arg_value opt_block_arg
+ {
+ $$ = arg_concat($1, $4);
+ $$ = arg_blk_pass($$, $5);
}
| assocs opt_block_arg
{
- /*%%%*/
$$ = NEW_LIST(NEW_HASH($1));
$$ = arg_blk_pass($$, $2);
- /*%
- $$ = arg_add_assocs(arg_new(), $1);
- $$ = arg_add_optblock($$, $2);
- %*/
+ }
+ | assocs ',' tSTAR arg_value opt_block_arg
+ {
+ $$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4);
+ $$ = arg_blk_pass($$, $5);
}
| args ',' assocs opt_block_arg
{
- /*%%%*/
- $$ = arg_append($1, NEW_HASH($3));
+ $$ = list_append($1, NEW_HASH($3));
$$ = arg_blk_pass($$, $4);
- /*%
- $$ = arg_add_optblock(arg_add_assocs($1, $3), $4);
- %*/
}
- | block_arg
- /*%c%*/
- /*%c
+ | args ',' assocs ',' tSTAR arg opt_block_arg
+ {
+ value_expr($6);
+ $$ = arg_concat(list_append($1, NEW_HASH($3)), $6);
+ $$ = arg_blk_pass($$, $7);
+ }
+ | tSTAR arg_value opt_block_arg
{
- $$ = arg_add_block(arg_new(), $1);
+ $$ = arg_blk_pass(NEW_SPLAT($2), $3);
}
- %*/
+ | block_arg
;
call_args2 : arg_value ',' args opt_block_arg
{
- /*%%%*/
$$ = arg_blk_pass(list_concat(NEW_LIST($1),$3), $4);
- /*%
- $$ = arg_add_optblock(arg_prepend($3, $1), $4);
- %*/
}
| arg_value ',' block_arg
{
- /*%%%*/
- $$ = arg_blk_pass($1, $3);
- /*%
- $$ = arg_add_block(arg_add(arg_new(), $1), $3);
- %*/
+ $$ = arg_blk_pass($1, $3);
+ }
+ | arg_value ',' tSTAR arg_value opt_block_arg
+ {
+ $$ = arg_concat(NEW_LIST($1), $4);
+ $$ = arg_blk_pass($$, $5);
+ }
+ | arg_value ',' args ',' tSTAR arg_value opt_block_arg
+ {
+ $$ = arg_concat(list_concat(NEW_LIST($1),$3), $6);
+ $$ = arg_blk_pass($$, $7);
}
| assocs opt_block_arg
{
- /*%%%*/
$$ = NEW_LIST(NEW_HASH($1));
$$ = arg_blk_pass($$, $2);
- /*%
- $$ = arg_add_optblock(arg_add_assocs(arg_new(), $1), $2);
- %*/
+ }
+ | assocs ',' tSTAR arg_value opt_block_arg
+ {
+ $$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4);
+ $$ = arg_blk_pass($$, $5);
}
| arg_value ',' assocs opt_block_arg
{
- /*%%%*/
- $$ = arg_append(NEW_LIST($1), NEW_HASH($3));
+ $$ = list_append(NEW_LIST($1), NEW_HASH($3));
$$ = arg_blk_pass($$, $4);
- /*%
- $$ = arg_add_assocs(arg_add(arg_new(), $1), $3);
- $$ = arg_add_optblock($$, $4);
- %*/
}
| arg_value ',' args ',' assocs opt_block_arg
{
- /*%%%*/
- $$ = arg_append(list_concat(NEW_LIST($1),$3), NEW_HASH($5));
+ $$ = list_append(list_concat(NEW_LIST($1),$3), NEW_HASH($5));
$$ = arg_blk_pass($$, $6);
- /*%
- $$ = arg_add_assocs(arg_prepend($3, $1), $5);
- $$ = arg_add_optblock($$, $6);
- %*/
+ }
+ | arg_value ',' assocs ',' tSTAR arg_value opt_block_arg
+ {
+ $$ = arg_concat(list_append(NEW_LIST($1), NEW_HASH($3)), $6);
+ $$ = arg_blk_pass($$, $7);
+ }
+ | arg_value ',' args ',' assocs ',' tSTAR arg_value opt_block_arg
+ {
+ $$ = arg_concat(list_append(list_concat(NEW_LIST($1), $3), NEW_HASH($5)), $8);
+ $$ = arg_blk_pass($$, $9);
+ }
+ | tSTAR arg_value opt_block_arg
+ {
+ $$ = arg_blk_pass(NEW_SPLAT($2), $3);
}
| block_arg
;
@@ -2250,39 +1396,27 @@ command_args : {
open_args
{
/* CMDARG_POP() */
- cmdarg_stack = $<num>1;
+ cmdarg_stack = $<num>1;
$$ = $2;
}
;
open_args : call_args
- | tLPAREN_ARG {lex_state = EXPR_ENDARG;} rparen
+ | tLPAREN_ARG {lex_state = EXPR_ENDARG;} ')'
{
- /*%%%*/
- rb_warning("don't put space before argument parentheses");
+ rb_warn("don't put space before argument parentheses");
$$ = 0;
- /*%
- $$ = dispatch1(space, dispatch1(arg_paren, arg_new()));
- %*/
}
- | tLPAREN_ARG call_args2 {lex_state = EXPR_ENDARG;} rparen
+ | tLPAREN_ARG call_args2 {lex_state = EXPR_ENDARG;} ')'
{
- /*%%%*/
- rb_warning("don't put space before argument parentheses");
+ rb_warn("don't put space before argument parentheses");
$$ = $2;
- /*%
- $$ = dispatch1(space, dispatch1(arg_paren, $2));
- %*/
}
;
block_arg : tAMPER arg_value
{
- /*%%%*/
$$ = NEW_BLOCK_PASS($2);
- /*%
- $$ = $2;
- %*/
}
;
@@ -2293,63 +1427,27 @@ opt_block_arg : ',' block_arg
| none
;
-args : arg_value
+args : arg_value
{
- /*%%%*/
$$ = NEW_LIST($1);
- /*%
- $$ = arg_add(arg_new(), $1);
- %*/
- }
- | tSTAR arg_value
- {
- /*%%%*/
- $$ = NEW_SPLAT($2);
- /*%
- $$ = arg_add_star(arg_new(), $2);
- %*/
}
| args ',' arg_value
{
- /*%%%*/
- $$ = arg_append($1, $3);
- /*%
- $$ = arg_add($1, $3);
- %*/
- }
- | args ',' tSTAR arg_value
- {
- /*%%%*/
- $$ = arg_concat($1, $4);
- /*%
- $$ = arg_add_star($1, $4);
- %*/
+ $$ = list_append($1, $3);
}
;
mrhs : args ',' arg_value
{
- /*%%%*/
$$ = list_append($1, $3);
- /*%
- $$ = mrhs_add(args2mrhs($1), $3);
- %*/
}
| args ',' tSTAR arg_value
{
- /*%%%*/
$$ = arg_concat($1, $4);
- /*%
- $$ = mrhs_add_star(args2mrhs($1), $4);
- %*/
}
| tSTAR arg_value
{
- /*%%%*/
$$ = NEW_SPLAT($2);
- /*%
- $$ = mrhs_add_star(mrhs_new(), $2);
- %*/
}
;
@@ -2363,1048 +1461,428 @@ primary : literal
| backref
| tFID
{
- /*%%%*/
$$ = NEW_FCALL($1, 0);
- /*%
- $$ = method_arg(dispatch1(fcall, $1), arg_new());
- %*/
}
- | keyword_begin
+ | kBEGIN
{
- /*%%%*/
$<num>1 = ruby_sourceline;
- /*%
- %*/
}
bodystmt
- keyword_end
+ kEND
{
- /*%%%*/
- if ($3 == NULL) {
+ if ($3 == NULL)
$$ = NEW_NIL();
- }
- else {
- if (nd_type($3) == NODE_RESCUE ||
- nd_type($3) == NODE_ENSURE)
- nd_set_line($3, $<num>1);
+ else
$$ = NEW_BEGIN($3);
- }
nd_set_line($$, $<num>1);
- /*%
- $$ = dispatch1(begin, $3);
- %*/
}
- | tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} rparen
+ | tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} opt_nl ')'
{
- rb_warning0("(...) interpreted as grouped expression");
- /*%%%*/
+ rb_warning("(...) interpreted as grouped expression");
$$ = $2;
- /*%
- $$ = dispatch1(paren, $2);
- %*/
}
| tLPAREN compstmt ')'
{
- /*%%%*/
if (!$2) $$ = NEW_NIL();
else $$ = $2;
- /*%
- $$ = dispatch1(paren, $2);
- %*/
}
| primary_value tCOLON2 tCONSTANT
{
- /*%%%*/
$$ = NEW_COLON2($1, $3);
- /*%
- $$ = dispatch2(constpath_ref, $1, $3);
- %*/
}
| tCOLON3 tCONSTANT
{
- /*%%%*/
$$ = NEW_COLON3($2);
- /*%
- $$ = dispatch1(topconst_ref, $2);
- %*/
+ }
+ | primary_value '[' aref_args ']'
+ {
+ if ($1 && nd_type($1) == NODE_SELF)
+ $$ = NEW_FCALL(tAREF, $3);
+ else
+ $$ = NEW_CALL($1, tAREF, $3);
+ fixpos($$, $1);
}
| tLBRACK aref_args ']'
{
- /*%%%*/
- if ($2 == 0) {
+ if ($2 == 0) {
$$ = NEW_ZARRAY(); /* zero length array*/
}
else {
$$ = $2;
}
- /*%
- $$ = dispatch1(array, escape_Qundef($2));
- %*/
}
| tLBRACE assoc_list '}'
{
- /*%%%*/
$$ = NEW_HASH($2);
- /*%
- $$ = dispatch1(hash, escape_Qundef($2));
- %*/
}
- | keyword_return
+ | kRETURN
{
- /*%%%*/
$$ = NEW_RETURN(0);
- /*%
- $$ = dispatch0(return0);
- %*/
}
- | keyword_yield '(' call_args rparen
+ | kYIELD '(' call_args ')'
{
- /*%%%*/
$$ = new_yield($3);
- /*%
- $$ = dispatch1(yield, dispatch1(paren, $3));
- %*/
}
- | keyword_yield '(' rparen
+ | kYIELD '(' ')'
{
- /*%%%*/
$$ = NEW_YIELD(0, Qfalse);
- /*%
- $$ = dispatch1(yield, dispatch1(paren, arg_new()));
- %*/
}
- | keyword_yield
+ | kYIELD
{
- /*%%%*/
$$ = NEW_YIELD(0, Qfalse);
- /*%
- $$ = dispatch0(yield0);
- %*/
}
- | keyword_defined opt_nl '(' {in_defined = 1;} expr rparen
+ | kDEFINED opt_nl '(' {in_defined = 1;} expr ')'
{
- /*%%%*/
in_defined = 0;
$$ = NEW_DEFINED($5);
- /*%
- in_defined = 0;
- $$ = dispatch1(defined, $5);
- %*/
}
| operation brace_block
{
- /*%%%*/
$2->nd_iter = NEW_FCALL($1, 0);
$$ = $2;
fixpos($2->nd_iter, $2);
- /*%
- $$ = method_arg(dispatch1(fcall, $1), arg_new());
- $$ = dispatch2(iter_block, $$, $2);
- %*/
}
| method_call
| method_call brace_block
{
- /*%%%*/
- block_dup_check($1->nd_args, $2);
+ if ($1 && nd_type($1) == NODE_BLOCK_PASS) {
+ rb_compile_error("both block arg and actual block given");
+ }
$2->nd_iter = $1;
- $$ = $2;
- fixpos($$, $1);
- /*%
- $$ = dispatch2(iter_block, $1, $2);
- %*/
- }
- | tLAMBDA lambda
- {
$$ = $2;
+ fixpos($$, $1);
}
- | keyword_if expr_value then
+ | kIF expr_value then
compstmt
if_tail
- keyword_end
+ kEND
{
- /*%%%*/
$$ = NEW_IF(cond($2), $4, $5);
- fixpos($$, $2);
+ fixpos($$, $2);
if (cond_negative(&$$->nd_cond)) {
- NODE *tmp = $$->nd_body;
- $$->nd_body = $$->nd_else;
- $$->nd_else = tmp;
+ NODE *tmp = $$->nd_body;
+ $$->nd_body = $$->nd_else;
+ $$->nd_else = tmp;
}
- /*%
- $$ = dispatch3(if, $2, $4, escape_Qundef($5));
- %*/
}
- | keyword_unless expr_value then
+ | kUNLESS expr_value then
compstmt
opt_else
- keyword_end
+ kEND
{
- /*%%%*/
$$ = NEW_UNLESS(cond($2), $4, $5);
- fixpos($$, $2);
+ fixpos($$, $2);
if (cond_negative(&$$->nd_cond)) {
- NODE *tmp = $$->nd_body;
- $$->nd_body = $$->nd_else;
- $$->nd_else = tmp;
+ NODE *tmp = $$->nd_body;
+ $$->nd_body = $$->nd_else;
+ $$->nd_else = tmp;
}
- /*%
- $$ = dispatch3(unless, $2, $4, escape_Qundef($5));
- %*/
}
- | keyword_while {COND_PUSH(1);} expr_value do {COND_POP();}
+ | kWHILE {COND_PUSH(1);} expr_value do {COND_POP();}
compstmt
- keyword_end
+ kEND
{
- /*%%%*/
$$ = NEW_WHILE(cond($3), $6, 1);
- fixpos($$, $3);
+ fixpos($$, $3);
if (cond_negative(&$$->nd_cond)) {
nd_set_type($$, NODE_UNTIL);
}
- /*%
- $$ = dispatch2(while, $3, $6);
- %*/
}
- | keyword_until {COND_PUSH(1);} expr_value do {COND_POP();}
+ | kUNTIL {COND_PUSH(1);} expr_value do {COND_POP();}
compstmt
- keyword_end
+ kEND
{
- /*%%%*/
$$ = NEW_UNTIL(cond($3), $6, 1);
- fixpos($$, $3);
+ fixpos($$, $3);
if (cond_negative(&$$->nd_cond)) {
nd_set_type($$, NODE_WHILE);
}
- /*%
- $$ = dispatch2(until, $3, $6);
- %*/
}
- | keyword_case expr_value opt_terms
+ | kCASE expr_value opt_terms
case_body
- keyword_end
+ kEND
{
- /*%%%*/
$$ = NEW_CASE($2, $4);
- fixpos($$, $2);
- /*%
- $$ = dispatch2(case, $2, $4);
- %*/
+ fixpos($$, $2);
+ }
+ | kCASE opt_terms case_body kEND
+ {
+ $$ = $3;
}
- | keyword_case opt_terms case_body keyword_end
+ | kCASE opt_terms kELSE compstmt kEND
{
- /*%%%*/
- $$ = NEW_CASE(0, $3);
- /*%
- $$ = dispatch2(case, Qnil, $3);
- %*/
+ $$ = $4;
}
- | keyword_for for_var keyword_in {COND_PUSH(1);} expr_value do {COND_POP();}
+ | kFOR block_var kIN {COND_PUSH(1);} expr_value do {COND_POP();}
compstmt
- keyword_end
+ kEND
{
- /*%%%*/
$$ = NEW_FOR($2, $5, $8);
- fixpos($$, $2);
- /*%
- $$ = dispatch3(for, $2, $5, $8);
- %*/
+ fixpos($$, $2);
}
- | keyword_class cpath superclass
+ | kCLASS cpath superclass
{
- /*%%%*/
if (in_def || in_single)
yyerror("class definition in method body");
class_nest++;
local_push(0);
- $<num>$ = ruby_sourceline;
- /*%
- if (in_def || in_single)
- yyerror("class definition in method body");
- class_nest++;
- %*/
+ $<num>$ = ruby_sourceline;
}
bodystmt
- keyword_end
+ kEND
{
- /*%%%*/
- $$ = NEW_CLASS($2, $5, $3);
- nd_set_line($$, $<num>4);
- local_pop();
- class_nest--;
- /*%
- $$ = dispatch3(class, $2, $3, $5);
+ $$ = NEW_CLASS($2, $5, $3);
+ nd_set_line($$, $<num>4);
+ local_pop();
class_nest--;
- %*/
}
- | keyword_class tLSHFT expr
+ | kCLASS tLSHFT expr
{
- /*%%%*/
$<num>$ = in_def;
- in_def = 0;
- /*%
- in_def = 0;
- %*/
+ in_def = 0;
}
term
{
- /*%%%*/
- $<num>$ = in_single;
- in_single = 0;
+ $<num>$ = in_single;
+ in_single = 0;
class_nest++;
local_push(0);
- /*%
- $$ = in_single;
- in_single = 0;
- class_nest++;
- %*/
}
bodystmt
- keyword_end
+ kEND
{
- /*%%%*/
- $$ = NEW_SCLASS($3, $7);
- fixpos($$, $3);
- local_pop();
- class_nest--;
- in_def = $<num>4;
- in_single = $<num>6;
- /*%
- $$ = dispatch2(sclass, $3, $7);
+ $$ = NEW_SCLASS($3, $7);
+ fixpos($$, $3);
+ local_pop();
class_nest--;
- in_def = $<val>4;
- in_single = $<val>6;
- %*/
+ in_def = $<num>4;
+ in_single = $<num>6;
}
- | keyword_module cpath
+ | kMODULE cpath
{
- /*%%%*/
if (in_def || in_single)
yyerror("module definition in method body");
class_nest++;
local_push(0);
- $<num>$ = ruby_sourceline;
- /*%
- if (in_def || in_single)
- yyerror("module definition in method body");
- class_nest++;
- %*/
+ $<num>$ = ruby_sourceline;
}
bodystmt
- keyword_end
+ kEND
{
- /*%%%*/
- $$ = NEW_MODULE($2, $4);
- nd_set_line($$, $<num>3);
- local_pop();
- class_nest--;
- /*%
- $$ = dispatch2(module, $2, $4);
+ $$ = NEW_MODULE($2, $4);
+ nd_set_line($$, $<num>3);
+ local_pop();
class_nest--;
- %*/
}
- | keyword_def fname
+ | kDEF fname
{
- /*%%%*/
$<id>$ = cur_mid;
cur_mid = $2;
in_def++;
local_push(0);
- /*%
- $<id>$ = cur_mid;
- cur_mid = $2;
- in_def++;
- %*/
}
f_arglist
bodystmt
- keyword_end
- {
- /*%%%*/
- NODE *body = remove_begin($5);
- reduce_nodes(&body);
- $$ = NEW_DEFN($2, $4, body, NOEX_PRIVATE);
- fixpos($$, $4);
- local_pop();
- in_def--;
- cur_mid = $<id>3;
- /*%
- $$ = dispatch3(def, $2, $4, $5);
+ kEND
+ {
+ if (!$5) $5 = NEW_NIL();
+ $$ = NEW_DEFN($2, $4, $5, NOEX_PRIVATE);
+ fixpos($$, $4);
+ local_pop();
in_def--;
cur_mid = $<id>3;
- %*/
}
- | keyword_def singleton dot_or_colon {lex_state = EXPR_FNAME;} fname
+ | kDEF singleton dot_or_colon {lex_state = EXPR_FNAME;} fname
{
- /*%%%*/
in_single++;
local_push(0);
- lex_state = EXPR_END; /* force for args */
- /*%
- in_single++;
- lex_state = EXPR_END;
- %*/
+ lex_state = EXPR_END; /* force for args */
}
f_arglist
bodystmt
- keyword_end
- {
- /*%%%*/
- NODE *body = remove_begin($8);
- reduce_nodes(&body);
- $$ = NEW_DEFS($2, $5, $7, body);
- fixpos($$, $2);
- local_pop();
- in_single--;
- /*%
- $$ = dispatch5(defs, $2, $3, $5, $7, $8);
+ kEND
+ {
+ $$ = NEW_DEFS($2, $5, $7, $8);
+ fixpos($$, $2);
+ local_pop();
in_single--;
- %*/
}
- | keyword_break
+ | kBREAK
{
- /*%%%*/
$$ = NEW_BREAK(0);
- /*%
- $$ = dispatch1(break, arg_new());
- %*/
}
- | keyword_next
+ | kNEXT
{
- /*%%%*/
$$ = NEW_NEXT(0);
- /*%
- $$ = dispatch1(next, arg_new());
- %*/
}
- | keyword_redo
+ | kREDO
{
- /*%%%*/
$$ = NEW_REDO();
- /*%
- $$ = dispatch0(redo);
- %*/
}
- | keyword_retry
+ | kRETRY
{
- /*%%%*/
$$ = NEW_RETRY();
- /*%
- $$ = dispatch0(retry);
- %*/
}
;
-primary_value : primary
+primary_value : primary
{
- /*%%%*/
value_expr($1);
$$ = $1;
- /*%
- $$ = $1;
- %*/
}
;
then : term
- /*%c%*/
- /*%c
- { $$ = Qnil; }
- %*/
- | keyword_then
- | term keyword_then
- /*%c%*/
- /*%c
- { $$ = $2; }
- %*/
+ | ':'
+ | kTHEN
+ | term kTHEN
;
do : term
- /*%c%*/
- /*%c
- { $$ = Qnil; }
- %*/
- | keyword_do_cond
+ | ':'
+ | kDO_COND
;
if_tail : opt_else
- | keyword_elsif expr_value then
+ | kELSIF expr_value then
compstmt
if_tail
{
- /*%%%*/
$$ = NEW_IF(cond($2), $4, $5);
- fixpos($$, $2);
- /*%
- $$ = dispatch3(elsif, $2, $4, escape_Qundef($5));
- %*/
+ fixpos($$, $2);
}
;
opt_else : none
- | keyword_else compstmt
+ | kELSE compstmt
{
- /*%%%*/
$$ = $2;
- /*%
- $$ = dispatch1(else, $2);
- %*/
}
;
-for_var : lhs
+block_var : lhs
| mlhs
;
-bparam_item : bvar
- | tLPAREN block_param rparen
- {
- /*%%%*/
- if (nd_type($2) != NODE_MASGN) {
- $$ = NEW_MASGN(NEW_LIST($2), 0);
- }
- else {
- $$ = $2;
- }
- /*%
- $$ = dispatch1(mlhs_paren, $2);
- %*/
- }
- ;
-
-bparam_list : bparam_item
- {
- /*%%%*/
- $$ = NEW_LIST($1);
- /*%
- $$ = mlhs_add(mlhs_new(), $1);
- %*/
- }
- | bparam_list ',' bparam_item
- {
- /*%%%*/
- $$ = list_append($1, $3);
- /*%
- $$ = mlhs_add($1, $3);
- %*/
- }
- ;
-
-block_param : bparam_list
- {
- /*%%%*/
- if ($1->nd_alen == 1 && nd_type($1->nd_head) != NODE_MASGN) {
- $$ = $1->nd_head;
- rb_gc_force_recycle((VALUE)$1);
- }
- else {
- $$ = NEW_MASGN($1, 0);
- }
- /*%
- $$ = blockvar_new($1);
- %*/
- }
- | bparam_list ','
- {
- /*%%%*/
- $$ = NEW_MASGN($1, 0);
- /*%
- $$ = blockvar_new($1);
- %*/
- }
- | bparam_list ',' tAMPER bvar
- {
- /*%%%*/
- $$ = NEW_BLOCK_PARAM($4, NEW_MASGN($1, 0));
- /*%
- $$ = blockvar_add_block(blockvar_new($1), $4);
- %*/
- }
- | bparam_list ',' tSTAR bvar ',' bparam_list ',' tAMPER bvar
- {
- /*%%%*/
- $$ = NEW_BLOCK_PARAM($9, NEW_MASGN($1, NEW_POSTARG($4,$6)));
- /*%
- $$ = blockvar_add_star(blockvar_new($1), $4);
- $$ = blockvar_add_block($$, $9);
- %*/
- }
- | bparam_list ',' tSTAR bvar ',' tAMPER bvar
- {
- /*%%%*/
- $$ = NEW_BLOCK_PARAM($7, NEW_MASGN($1, $4));
- /*%
- $$ = blockvar_add_star(blockvar_new($1), $4);
- $$ = blockvar_add_block($$, $7);
- %*/
- }
- | bparam_list ',' tSTAR ',' tAMPER bvar
- {
- /*%%%*/
- $$ = NEW_BLOCK_PARAM($6, NEW_MASGN($1, -1));
- /*%
- $$ = blockvar_add_star(blockvar_new($1), Qnil);
- $$ = blockvar_add_block($$, $6);
- %*/
- }
- | bparam_list ',' tSTAR ',' bparam_list ',' tAMPER bvar
- {
- /*%%%*/
- $$ = NEW_BLOCK_PARAM($8, NEW_MASGN($1, NEW_POSTARG(-1,$5)));
- /*%
- $$ = blockvar_add_star(blockvar_new($1), Qnil);
- $$ = blockvar_add_block($$, $8);
- %*/
- }
- | bparam_list ',' tSTAR bvar
- {
- /*%%%*/
- $$ = NEW_MASGN($1, $4);
- /*%
- $$ = blockvar_add_star(blockvar_new($1), $4);
- %*/
- }
- | bparam_list ',' tSTAR bvar ',' bparam_list
- {
- /*%%%*/
- $$ = NEW_MASGN($1, NEW_POSTARG($4,$6));
- /*%
- $$ = blockvar_add_star(blockvar_new($1), $4);
- %*/
- }
- | bparam_list ',' tSTAR
- {
- /*%%%*/
- $$ = NEW_MASGN($1, -1);
- /*%
- $$ = blockvar_add_star(blockvar_new($1), Qnil);
- %*/
- }
- | bparam_list ',' tSTAR ',' bparam_list
- {
- /*%%%*/
- $$ = NEW_MASGN($1, NEW_MASGN($1, NEW_POSTARG(-1,$5)));
- /*%
- $$ = blockvar_add_star(blockvar_new($1), Qnil);
- %*/
- }
- | tSTAR bvar ',' tAMPER bvar
- {
- /*%%%*/
- $$ = NEW_BLOCK_PARAM($5, NEW_MASGN(0, $2));
- /*%
- $$ = blockvar_add_star(blockvar_new(Qnil), $2);
- $$ = blockvar_add_block($$, $5);
- %*/
- }
- | tSTAR ',' tAMPER bvar
- {
- /*%%%*/
- $$ = NEW_BLOCK_PARAM($4, NEW_MASGN(0, -1));
- /*%
- $$ = blockvar_add_star(blockvar_new(Qnil), Qnil);
- $$ = blockvar_add_block($$, $4);
- %*/
- }
- | tSTAR bvar
- {
- /*%%%*/
- $$ = NEW_MASGN(0, $2);
- /*%
- $$ = blockvar_add_star(blockvar_new(Qnil), $2);
- %*/
- }
- | tSTAR bvar ',' bparam_list
- {
- /*%%%*/
- $$ = NEW_MASGN(0, NEW_POSTARG($2,$4));
- /*%
- $$ = blockvar_add_star(blockvar_new(Qnil), $2);
- %*/
- }
- | tSTAR bvar ',' bparam_list ',' tAMPER bvar
- {
- /*%%%*/
- $$ = NEW_BLOCK_PARAM($7, NEW_MASGN(0, NEW_POSTARG($2,$4)));
- /*%
- $$ = blockvar_add_star(blockvar_new(Qnil), Qnil);
- $$ = blockvar_add_block($$, $7);
- %*/
- }
- | tSTAR
- {
- /*%%%*/
- $$ = NEW_MASGN(0, -1);
- /*%
- $$ = blockvar_add_star(blockvar_new(Qnil), Qnil);
- %*/
- }
- | tSTAR ',' bparam_list
- {
- /*%%%*/
- $$ = NEW_MASGN(0, NEW_POSTARG(-1,$3));
- /*%
- $$ = blockvar_add_star(blockvar_new(Qnil), Qnil);
- %*/
- }
- | tSTAR ',' bparam_list ',' tAMPER bvar
- {
- /*%%%*/
- $$ = NEW_BLOCK_PARAM($6, NEW_MASGN(0, NEW_POSTARG(-1,$3)));
- /*%
- $$ = blockvar_add_star(blockvar_new(Qnil), Qnil);
- $$ = blockvar_add_block($$, $6);
- %*/
- }
- | tAMPER bvar
+opt_block_var : none
+ | '|' /* none */ '|'
{
- /*%%%*/
- $$ = NEW_BLOCK_PARAM($2, (NODE*)1);
- /*%
- $$ = blockvar_add_block(blockvar_new(Qnil), $2);
- %*/
- }
- ;
-
-opt_block_param : none
- {
- /*%%%*/
- $$ = NEW_ITER(0, 0, 0);
- /*%
- %*/
- }
- | block_param_def
- ;
-
-block_param_def : '|' opt_bv_decl '|'
- {
- /*%%%*/
- $$ = NEW_ITER((NODE*)1, 0, $2);
- /*%
- $$ = blockvar_new(mlhs_new());
- %*/
+ $$ = (NODE*)1;
}
| tOROP
{
- /*%%%*/
- $$ = NEW_ITER((NODE*)1, 0, 0);
- /*%
- $$ = blockvar_new(mlhs_new());
- %*/
- }
- | '|' block_param opt_bv_decl '|'
- {
- /*%%%*/
- $$ = NEW_ITER($2, 0, $3);
- /*%
- $$ = blockvar_new($2);
- %*/
- }
- ;
-
-
-opt_bv_decl : none
- | ';' bv_decls
- {
- /*%%%*/
- $$ = $2;
- /*%
- $$ = FIXME;
- %*/
- }
- ;
-
-bv_decls : bvar
- {
- /*%%%*/
- $$ = $1;
- /*%
- $$ = FIXME;
- %*/
- }
- | bv_decls ',' bvar
- {
- /*%%%*/
- $$ = block_append($1, $3);
- /*%
- $$ = FIXME;
- %*/
- }
- ;
-
-bvar : tIDENTIFIER
- {
- /*%%%*/
- $$ = new_bv($1, NEW_NIL());
- /*%
- $$ = FIXME;
- %*/
- }
- ;
-
-lambda : {
- /*%%%*/
- $<vars>$ = dyna_push();
- /*%
- %*/
- }
- {
- $<num>$ = lpar_beg;
- lpar_beg = ++paren_nest;
- }
- f_larglist
- lambda_body
- {
- /*%%%*/
- $$ = $3;
- $$->nd_body = block_append($$->nd_body, $4);
- dyna_pop($<vars>1);
- lpar_beg = $<num>2;
- /*%
- $$ = dispatch2(lambda, $3, $4);
- %*/
- }
- ;
-
-f_larglist : '(' f_args opt_bv_decl rparen
- {
- /*%%%*/
- $$ = NEW_LAMBDA($2, $3);
- /*%
- $$ = dispatch1(paren, $2);
- %*/
- }
- | f_args opt_bv_decl
- {
- /*%%%*/
- $$ = NEW_LAMBDA($1, $2);
- /*%
- $$ = $1;
- %*/
- }
- ;
-
-lambda_body : tLAMBEG compstmt '}'
- {
- $$ = $2;
+ $$ = (NODE*)1;
}
- | keyword_do_LAMBDA compstmt keyword_end
+ | '|' block_var '|'
{
$$ = $2;
}
;
-do_block : keyword_do_block
+do_block : kDO_BLOCK
{
- /*%%%*/
- $<vars>$ = dyna_push();
+ $<vars>$ = dyna_push();
$<num>1 = ruby_sourceline;
- /*% %*/
- }
- opt_block_param
- {
- /*%%%*/
- $<vars>$ = ruby_dyna_vars;
- /*% %*/
}
+ opt_block_var {$<vars>$ = ruby_dyna_vars;}
compstmt
- keyword_end
+ kEND
{
- /*%%%*/
- $3->nd_body = block_append($3->nd_body,
- dyna_init($5, $<vars>4));
- $$ = $3;
+ $$ = NEW_ITER($3, 0, dyna_init($5, $<vars>4));
nd_set_line($$, $<num>1);
dyna_pop($<vars>2);
- /*%
- $$ = dispatch2(do_block, escape_Qundef($3), $5);
- %*/
}
;
block_call : command do_block
{
- /*%%%*/
- block_dup_check($1->nd_args, $2);
+ if ($1 && nd_type($1) == NODE_BLOCK_PASS) {
+ rb_compile_error("both block arg and actual block given");
+ }
$2->nd_iter = $1;
- $$ = $2;
- fixpos($$, $1);
- /*%
- $$ = dispatch2(iter_block, $1, $2);
- %*/
+ $$ = $2;
+ fixpos($$, $1);
}
| block_call '.' operation2 opt_paren_args
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- /*%
- $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
- $$ = method_optarg($$, $4);
- %*/
+ $$ = new_call($1, $3, $4);
}
| block_call tCOLON2 operation2 opt_paren_args
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- /*%
- $$ = dispatch3(call, $1, ripper_intern("::"), $3);
- $$ = method_optarg($$, $4);
- %*/
+ $$ = new_call($1, $3, $4);
}
;
method_call : operation paren_args
{
- /*%%%*/
- $$ = NEW_FCALL($1, $2);
- fixpos($$, $2);
- /*%
- $$ = method_arg(dispatch1(fcall, $1), $2);
- %*/
+ $$ = new_fcall($1, $2);
+ fixpos($$, $2);
}
| primary_value '.' operation2 opt_paren_args
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- fixpos($$, $1);
- /*%
- $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
- $$ = method_optarg($$, $4);
- %*/
+ $$ = new_call($1, $3, $4);
+ fixpos($$, $1);
}
| primary_value tCOLON2 operation2 paren_args
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, $4);
- fixpos($$, $1);
- /*%
- $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
- $$ = method_optarg($$, $4);
- %*/
+ $$ = new_call($1, $3, $4);
+ fixpos($$, $1);
}
| primary_value tCOLON2 operation3
{
- /*%%%*/
- $$ = NEW_CALL($1, $3, 0);
- /*%
- $$ = dispatch3(call, $1, ripper_intern("::"), $3);
- %*/
- }
- | primary_value '.' paren_args
- {
- /*%%%*/
- $$ = NEW_CALL($1, rb_intern("call"), $3);
- fixpos($$, $1);
- /*%
- $$ = dispatch3(call, dispatch1(paren, $1),
- ripper_id2sym('.'), rb_intern("call"));
- $$ = method_optarg($$, $3);
- %*/
- }
- | primary_value tCOLON2 paren_args
- {
- /*%%%*/
- $$ = NEW_CALL($1, rb_intern("call"), $3);
- fixpos($$, $1);
- /*%
- $$ = dispatch3(call, dispatch1(paren, $1),
- ripper_id2sym('.'), rb_intern("call"));
- $$ = method_optarg($$, $3);
- %*/
+ $$ = new_call($1, $3, 0);
}
- | keyword_super paren_args
+ | kSUPER paren_args
{
- /*%%%*/
- $$ = NEW_SUPER($2);
- /*%
- $$ = dispatch1(super, $2);
- %*/
+ $$ = new_super($2);
}
- | keyword_super
+ | kSUPER
{
- /*%%%*/
$$ = NEW_ZSUPER();
- /*%
- $$ = dispatch0(zsuper);
- %*/
- }
- | primary_value '[' opt_call_args rbracket
- {
- /*%%%*/
- if ($1 && nd_type($1) == NODE_SELF)
- $$ = NEW_FCALL(tAREF, $3);
- else
- $$ = NEW_CALL($1, tAREF, $3);
- fixpos($$, $1);
- /*%
- $$ = dispatch2(aref, $1, escape_Qundef($3));
- %*/
}
;
brace_block : '{'
{
- /*%%%*/
- $<vars>$ = dyna_push();
+ $<vars>$ = dyna_push();
$<num>1 = ruby_sourceline;
- /*% %*/
- }
- opt_block_param
- {
- /*%%%*/
- $<vars>$ = ruby_dyna_vars;
- /*%
- %*/
}
+ opt_block_var {$<vars>$ = ruby_dyna_vars;}
compstmt '}'
{
- /*%%%*/
- $3->nd_body = block_append($3->nd_body,
- dyna_init($5, $<vars>4));
- $$ = $3;
+ $$ = NEW_ITER($3, 0, dyna_init($5, $<vars>4));
nd_set_line($$, $<num>1);
dyna_pop($<vars>2);
- /*%
- $$ = dispatch2(brace_block, escape_Qundef($3), $5);
- %*/
}
- | keyword_do
+ | kDO
{
- /*%%%*/
- $<vars>$ = dyna_push();
+ $<vars>$ = dyna_push();
$<num>1 = ruby_sourceline;
- /*% %*/
}
- opt_block_param
+ opt_block_var {$<vars>$ = ruby_dyna_vars;}
+ compstmt kEND
{
- /*%%%*/
- $<vars>$ = ruby_dyna_vars;
- /*%
- %*/
- }
- compstmt keyword_end
- {
- /*%%%*/
- $3->nd_body = block_append($3->nd_body,
- dyna_init($5, $<vars>4));
- $$ = $3;
+ $$ = NEW_ITER($3, 0, dyna_init($5, $<vars>4));
nd_set_line($$, $<num>1);
dyna_pop($<vars>2);
- /*%
- $$ = dispatch2(do_block, escape_Qundef($3), $5);
- %*/
}
;
-case_body : keyword_when args then
+case_body : kWHEN when_args then
compstmt
cases
{
- /*%%%*/
$$ = NEW_WHEN($2, $4, $5);
- /*%
- $$ = dispatch3(when, $2, $4, escape_Qundef($5));
- %*/
+ }
+ ;
+when_args : args
+ | args ',' tSTAR arg_value
+ {
+ $$ = list_append($1, NEW_WHEN($4, 0, 0));
+ }
+ | tSTAR arg_value
+ {
+ $$ = NEW_LIST(NEW_WHEN($2, 0, 0));
}
;
@@ -3412,35 +1890,23 @@ cases : opt_else
| case_body
;
-opt_rescue : keyword_rescue exc_list exc_var then
+opt_rescue : kRESCUE exc_list exc_var then
compstmt
opt_rescue
{
- /*%%%*/
- if ($3) {
- $3 = node_assign($3, NEW_ERRINFO());
+ if ($3) {
+ $3 = node_assign($3, NEW_GVAR(rb_intern("$!")));
$5 = block_append($3, $5);
}
$$ = NEW_RESBODY($2, $5, $6);
- fixpos($$, $2?$2:$5);
- /*%
- $$ = dispatch4(rescue,
- escape_Qundef($2),
- escape_Qundef($3),
- escape_Qundef($5),
- escape_Qundef($6));
- %*/
+ fixpos($$, $2?$2:$5);
}
| none
;
exc_list : arg_value
{
- /*%%%*/
$$ = NEW_LIST($1);
- /*%
- $$ = rb_ary_new3(1, $1);
- %*/
}
| mrhs
| none
@@ -3453,13 +1919,13 @@ exc_var : tASSOC lhs
| none
;
-opt_ensure : keyword_ensure compstmt
+opt_ensure : kENSURE compstmt
{
- /*%%%*/
- $$ = $2;
- /*%
- $$ = dispatch1(ensure, $2);
- %*/
+ if ($2)
+ $$ = $2;
+ else
+ /* place holder */
+ $$ = NEW_NIL();
}
| none
;
@@ -3467,18 +1933,13 @@ opt_ensure : keyword_ensure compstmt
literal : numeric
| symbol
{
- /*%%%*/
$$ = NEW_LIT(ID2SYM($1));
- /*%
- $$ = dispatch1(symbol_literal, $1);
- %*/
}
| dsym
;
strings : string
{
- /*%%%*/
NODE *node = $1;
if (!node) {
node = NEW_STR(rb_str_new(0, 0));
@@ -3487,37 +1948,24 @@ strings : string
node = evstr2dstr(node);
}
$$ = node;
- /*%
- $$ = $1;
- %*/
}
;
-string : tCHAR
- | string1
+string : string1
| string string1
{
- /*%%%*/
$$ = literal_concat($1, $2);
- /*%
- $$ = dispatch2(string_concat, $1, $2);
- %*/
}
;
string1 : tSTRING_BEG string_contents tSTRING_END
{
- /*%%%*/
$$ = $2;
- /*%
- $$ = dispatch1(string_literal, $2);
- %*/
}
;
xstring : tXSTRING_BEG xstring_contents tSTRING_END
{
- /*%%%*/
NODE *node = $2;
if (!node) {
node = NEW_XSTR(rb_str_new(0, 0));
@@ -3536,28 +1984,24 @@ xstring : tXSTRING_BEG xstring_contents tSTRING_END
}
}
$$ = node;
- /*%
- $$ = dispatch1(xstring_literal, $2);
- %*/
}
;
regexp : tREGEXP_BEG xstring_contents tREGEXP_END
{
- /*%%%*/
int options = $3;
NODE *node = $2;
if (!node) {
- node = NEW_LIT(rb_reg_compile("", 0, options & ~RE_OPTION_ONCE));
+ node = NEW_LIT(rb_reg_new("", 0, options & ~RE_OPTION_ONCE));
}
else switch (nd_type(node)) {
case NODE_STR:
{
VALUE src = node->nd_lit;
nd_set_type(node, NODE_LIT);
- node->nd_lit = rb_reg_compile(RSTRING_PTR(src),
- RSTRING_LEN(src),
- options & ~RE_OPTION_ONCE);
+ node->nd_lit = rb_reg_new(RSTRING(src)->ptr,
+ RSTRING(src)->len,
+ options & ~RE_OPTION_ONCE);
}
break;
default:
@@ -3573,19 +2017,12 @@ regexp : tREGEXP_BEG xstring_contents tREGEXP_END
break;
}
$$ = node;
- /*%
- $$ = dispatch2(regexp_literal, $2, $3);
- %*/
}
;
words : tWORDS_BEG ' ' tSTRING_END
{
- /*%%%*/
$$ = NEW_ZARRAY();
- /*%
- $$ = dispatch0(words_new);
- %*/
}
| tWORDS_BEG word_list tSTRING_END
{
@@ -3595,47 +2032,24 @@ words : tWORDS_BEG ' ' tSTRING_END
word_list : /* none */
{
- /*%%%*/
$$ = 0;
- /*%
- $$ = dispatch0(words_new);
- %*/
}
| word_list word ' '
{
- /*%%%*/
$$ = list_append($1, evstr2dstr($2));
- /*%
- $$ = dispatch2(words_add, $1, $2);
- %*/
}
;
word : string_content
- /*%c%*/
- /*%c
- {
- $$ = dispatch0(word_new);
- $$ = dispatch2(word_add, $$, $1);
- }
- %*/
| word string_content
{
- /*%%%*/
$$ = literal_concat($1, $2);
- /*%
- $$ = dispatch2(word_add, $1, $2);
- %*/
}
;
qwords : tQWORDS_BEG ' ' tSTRING_END
{
- /*%%%*/
$$ = NEW_ZARRAY();
- /*%
- $$ = dispatch0(qwords_new);
- %*/
}
| tQWORDS_BEG qword_list tSTRING_END
{
@@ -3645,55 +2059,31 @@ qwords : tQWORDS_BEG ' ' tSTRING_END
qword_list : /* none */
{
- /*%%%*/
$$ = 0;
- /*%
- $$ = dispatch0(qwords_new);
- %*/
}
| qword_list tSTRING_CONTENT ' '
{
- /*%%%*/
$$ = list_append($1, $2);
- /*%
- $$ = dispatch2(qwords_add, $1, $2);
- %*/
}
;
string_contents : /* none */
{
- /*%%%*/
$$ = 0;
- /*%
- $$ = dispatch0(string_content);
- %*/
}
| string_contents string_content
{
- /*%%%*/
$$ = literal_concat($1, $2);
- /*%
- $$ = dispatch2(string_add, $1, $2);
- %*/
}
;
xstring_contents: /* none */
{
- /*%%%*/
$$ = 0;
- /*%
- $$ = dispatch0(xstring_new);
- %*/
}
| xstring_contents string_content
{
- /*%%%*/
$$ = literal_concat($1, $2);
- /*%
- $$ = dispatch2(xstring_add, $1, $2);
- %*/
}
;
@@ -3706,13 +2096,8 @@ string_content : tSTRING_CONTENT
}
string_dvar
{
- /*%%%*/
- lex_strterm = $<node>2;
- $$ = NEW_EVSTR($3);
- /*%
lex_strterm = $<node>2;
- $$ = dispatch1(string_dvar, $3);
- %*/
+ $$ = NEW_EVSTR($3);
}
| tSTRING_DBEG
{
@@ -3727,51 +2112,24 @@ string_content : tSTRING_CONTENT
lex_strterm = $<node>2;
COND_LEXPOP();
CMDARG_LEXPOP();
- /*%%%*/
- if ($3) $3->flags &= ~NODE_NEWLINE;
- $$ = new_evstr($3);
- /*%
- $$ = dispatch1(string_embexpr, $3);
- %*/
+ if (($$ = $3) && nd_type($$) == NODE_NEWLINE) {
+ $$ = $$->nd_next;
+ rb_gc_force_recycle((VALUE)$3);
+ }
+ $$ = new_evstr($$);
}
;
-string_dvar : tGVAR
- {
- /*%%%*/
- $$ = NEW_GVAR($1);
- /*%
- $$ = dispatch1(var_ref, $1);
- %*/
- }
- | tIVAR
- {
- /*%%%*/
- $$ = NEW_IVAR($1);
- /*%
- $$ = dispatch1(var_ref, $1);
- %*/
- }
- | tCVAR
- {
- /*%%%*/
- $$ = NEW_CVAR($1);
- /*%
- $$ = dispatch1(var_ref, $1);
- %*/
- }
+string_dvar : tGVAR {$$ = NEW_GVAR($1);}
+ | tIVAR {$$ = NEW_IVAR($1);}
+ | tCVAR {$$ = NEW_CVAR($1);}
| backref
;
symbol : tSYMBEG sym
{
- /*%%%*/
- lex_state = EXPR_END;
+ lex_state = EXPR_END;
$$ = $2;
- /*%
- lex_state = EXPR_END;
- $$ = dispatch1(symbol, $2);
- %*/
}
;
@@ -3783,9 +2141,9 @@ sym : fname
dsym : tSYMBEG xstring_contents tSTRING_END
{
- /*%%%*/
- lex_state = EXPR_END;
+ lex_state = EXPR_END;
if (!($$ = $2)) {
+ $$ = NEW_NIL();
yyerror("empty symbol literal");
}
else {
@@ -3797,12 +2155,12 @@ dsym : tSYMBEG xstring_contents tSTRING_END
break;
case NODE_STR:
lit = $$->nd_lit;
- if (RSTRING_LEN(lit) == 0) {
+ if (RSTRING(lit)->len == 0) {
yyerror("empty symbol literal");
break;
}
- if (strlen(RSTRING_PTR(lit)) == RSTRING_LEN(lit)) {
- $$->nd_lit = ID2SYM(rb_intern(RSTRING_PTR($$->nd_lit)));
+ if (strlen(RSTRING(lit)->ptr) == RSTRING(lit)->len) {
+ $$->nd_lit = ID2SYM(rb_intern(RSTRING($$->nd_lit)->ptr));
nd_set_type($$, NODE_LIT);
break;
}
@@ -3812,30 +2170,18 @@ dsym : tSYMBEG xstring_contents tSTRING_END
break;
}
}
- /*%
- lex_state = EXPR_END;
- $$ = dispatch1(dyna_symbol, $2);
- %*/
}
;
-numeric : tINTEGER
+numeric : tINTEGER
| tFLOAT
| tUMINUS_NUM tINTEGER %prec tLOWEST
{
- /*%%%*/
$$ = negate_lit($2);
- /*%
- $$ = dispatch2(unary, ripper_intern("-@"), $2);
- %*/
}
| tUMINUS_NUM tFLOAT %prec tLOWEST
{
- /*%%%*/
$$ = negate_lit($2);
- /*%
- $$ = dispatch2(unary, ripper_intern("-@"), $2);
- %*/
}
;
@@ -3844,31 +2190,23 @@ variable : tIDENTIFIER
| tGVAR
| tCONSTANT
| tCVAR
- | keyword_nil {ifndef_ripper($$ = keyword_nil);}
- | keyword_self {ifndef_ripper($$ = keyword_self);}
- | keyword_true {ifndef_ripper($$ = keyword_true);}
- | keyword_false {ifndef_ripper($$ = keyword_false);}
- | keyword__FILE__ {ifndef_ripper($$ = keyword__FILE__);}
- | keyword__LINE__ {ifndef_ripper($$ = keyword__LINE__);}
+ | kNIL {$$ = kNIL;}
+ | kSELF {$$ = kSELF;}
+ | kTRUE {$$ = kTRUE;}
+ | kFALSE {$$ = kFALSE;}
+ | k__FILE__ {$$ = k__FILE__;}
+ | k__LINE__ {$$ = k__LINE__;}
;
var_ref : variable
{
- /*%%%*/
$$ = gettable($1);
- /*%
- $$ = dispatch1(var_ref, $1);
- %*/
}
;
var_lhs : variable
{
- /*%%%*/
$$ = assignable($1, 0);
- /*%
- $$ = dispatch1(var_field, $1);
- %*/
}
;
@@ -3878,11 +2216,7 @@ backref : tNTH_REF
superclass : term
{
- /*%%%*/
$$ = 0;
- /*%
- $$ = Qnil;
- %*/
}
| '<'
{
@@ -3892,29 +2226,14 @@ superclass : term
{
$$ = $3;
}
- | error term
- {
- /*%%%*/
- yyerrok;
- $$ = 0;
- /*%
- yyerrok;
- $$ = Qnil;
- %*/
- }
+ | error term {yyerrok; $$ = 0;}
;
-f_arglist : '(' f_args rparen
+f_arglist : '(' f_args opt_nl ')'
{
- /*%%%*/
$$ = $2;
lex_state = EXPR_BEG;
command_start = Qtrue;
- /*%
- $$ = dispatch1(paren, $2);
- lex_state = EXPR_BEG;
- command_start = Qtrue;
- %*/
}
| f_args term
{
@@ -3924,251 +2243,94 @@ f_arglist : '(' f_args rparen
f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg
{
- /*%%%*/
- $$ = new_args($1, $3, $5, 0, $6);
- /*%
- $$ = dispatch5(params, $1, $3, $5, Qnil, escape_Qundef($6));
- %*/
- }
- | f_arg ',' f_optarg ',' f_rest_arg ',' f_post_arg opt_f_block_arg
- {
- /*%%%*/
- $$ = new_args($1, $3, $5, $7, $8);
- /*%
- $$ = dispatch5(params, $1, $3, $5, $7, escape_Qundef($8));
- %*/
+ $$ = block_append(NEW_ARGS($1, $3, $5), $6);
}
| f_arg ',' f_optarg opt_f_block_arg
{
- /*%%%*/
- $$ = new_args($1, $3, 0, 0, $4);
- /*%
- $$ = dispatch5(params, $1, $3, Qnil, Qnil, escape_Qundef($4));
- %*/
- }
- | f_arg ',' f_optarg ',' f_post_arg opt_f_block_arg
- {
- /*%%%*/
- $$ = new_args($1, $3, 0, $5, $6);
- /*%
- $$ = dispatch5(params, $1, $3, Qnil, $5, escape_Qundef($6));
- %*/
+ $$ = block_append(NEW_ARGS($1, $3, 0), $4);
}
| f_arg ',' f_rest_arg opt_f_block_arg
{
- /*%%%*/
- $$ = new_args($1, 0, $3, 0, $4);
- /*%
- $$ = dispatch5(params, $1, Qnil, $3, Qnil, escape_Qundef($4));
- %*/
- }
- | f_arg ',' f_rest_arg ',' f_post_arg opt_f_block_arg
- {
- /*%%%*/
- $$ = new_args($1, 0, $3, $5, $6);
- /*%
- $$ = dispatch5(params, $1, Qnil, $3, $5, escape_Qundef($6));
- %*/
+ $$ = block_append(NEW_ARGS($1, 0, $3), $4);
}
| f_arg opt_f_block_arg
{
- /*%%%*/
- $$ = new_args($1, 0, 0, 0, $2);
- /*%
- $$ = dispatch5(params, $1, Qnil, Qnil, Qnil, escape_Qundef($2));
- %*/
+ $$ = block_append(NEW_ARGS($1, 0, 0), $2);
}
| f_optarg ',' f_rest_arg opt_f_block_arg
{
- /*%%%*/
- $$ = new_args(0, $1, $3, 0, $4);
- /*%
- $$ = dispatch5(params, Qnil, $1, $3, Qnil, escape_Qundef($4));
- %*/
- }
- | f_optarg ',' f_rest_arg ',' f_post_arg opt_f_block_arg
- {
- /*%%%*/
- $$ = new_args(0, $1, $3, $5, $6);
- /*%
- $$ = dispatch5(params, Qnil, $1, $3, $5, escape_Qundef($6));
- %*/
+ $$ = block_append(NEW_ARGS(0, $1, $3), $4);
}
| f_optarg opt_f_block_arg
{
- /*%%%*/
- $$ = new_args(0, $1, 0, 0, $2);
- /*%
- $$ = dispatch5(params, Qnil, $1, Qnil, Qnil, escape_Qundef($2));
- %*/
- }
- | f_optarg ',' f_post_arg opt_f_block_arg
- {
- /*%%%*/
- $$ = new_args(0, $1, 0, $3, $4);
- /*%
- $$ = dispatch5(params, Qnil, $1, Qnil, $3, escape_Qundef($4));
- %*/
+ $$ = block_append(NEW_ARGS(0, $1, 0), $2);
}
| f_rest_arg opt_f_block_arg
{
- /*%%%*/
- $$ = new_args(0, 0, $1, 0, $2);
- /*%
- $$ = dispatch5(params, Qnil, Qnil, $1, Qnil, escape_Qundef($2));
- %*/
- }
- | f_rest_arg ',' f_post_arg opt_f_block_arg
- {
- /*%%%*/
- $$ = new_args(0, 0, $1, $3, $4);
- /*%
- $$ = dispatch5(params, Qnil, Qnil, $1, $3, escape_Qundef($4));
- %*/
+ $$ = block_append(NEW_ARGS(0, 0, $1), $2);
}
| f_block_arg
{
- /*%%%*/
- $$ = new_args(0, 0, 0, 0, $1);
- /*%
- $$ = dispatch5(params, Qnil, Qnil, Qnil, Qnil, $1);
- %*/
+ $$ = block_append(NEW_ARGS(0, 0, 0), $1);
}
| /* none */
{
- /*%%%*/
- $$ = new_args(0, 0, 0, 0, 0);
- /*%
- $$ = dispatch5(params, Qnil, Qnil, Qnil, Qnil, Qnil);
- %*/
+ $$ = NEW_ARGS(0, 0, 0);
}
;
f_norm_arg : tCONSTANT
{
- /*%%%*/
yyerror("formal argument cannot be a constant");
- /*%
- $$ = dispatch1(param_error, $1);
- %*/
}
- | tIVAR
+ | tIVAR
{
- /*%%%*/
- yyerror("formal argument cannot be an instance variable");
- /*%
- $$ = dispatch1(param_error, $1);
- %*/
+ yyerror("formal argument cannot be an instance variable");
}
- | tGVAR
+ | tGVAR
{
- /*%%%*/
- yyerror("formal argument cannot be a global variable");
- /*%
- $$ = dispatch1(param_error, $1);
- %*/
+ yyerror("formal argument cannot be a global variable");
}
- | tCVAR
+ | tCVAR
{
- /*%%%*/
- yyerror("formal argument cannot be a class variable");
- /*%
- $$ = dispatch1(param_error, $1);
- %*/
+ yyerror("formal argument cannot be a class variable");
}
| tIDENTIFIER
{
- /*%%%*/
if (!is_local_id($1))
yyerror("formal argument must be local variable");
- if (dyna_in_block()) {
- shadowing_lvar($1);
- dyna_var($1);
- }
- else {
- local_cnt($1);
- }
- $$ = $1;
- /*%
- $$ = $1;
- %*/
+ else if (local_id($1))
+ yyerror("duplicate argument name");
+ local_cnt($1);
+ $$ = 1;
}
;
f_arg : f_norm_arg
- {
- /*%%%*/
- VALUE arg = ID2SYM($1);
- /*%
- VALUE arg = $1;
- %*/
- $$ = rb_ary_new3(1, arg);
- }
| f_arg ',' f_norm_arg
{
- /*%%%*/
- VALUE arg = ID2SYM($3);
- $$ = $1;
- if (rb_ary_includes($$, arg)) {
- yyerror("duplicated argument name");
- }
- rb_ary_push($$, arg);
- /*%
- rb_ary_push($$, $3);
- %*/
- }
- ;
-
-f_post_arg : f_norm_arg
- {
- /*%%%*/
- $$ = NEW_LIST(assignable($1, 0));
- /*%
- $$ = mlhs_add(mlhs_new(), $1);
- %*/
- }
- | f_post_arg ',' f_norm_arg
- {
- /*%%%*/
- $$ = list_append($1, assignable($3, 0));
- /*%
- $$ = mlhs_add($1, $3);
- %*/
+ $$ += 1;
}
;
f_opt : tIDENTIFIER '=' arg_value
{
- /*%%%*/
if (!is_local_id($1))
yyerror("formal argument must be local variable");
- if (dyna_in_block()) {
- shadowing_lvar($1);
- dyna_var($1);
- }
+ else if (local_id($1))
+ yyerror("duplicate optional argument name");
$$ = assignable($1, $3);
- /*%
- $$ = rb_assoc_new($1, $3);
- %*/
}
;
f_optarg : f_opt
{
- /*%%%*/
$$ = NEW_BLOCK($1);
$$->nd_end = $$;
- /*%
- $$ = rb_ary_new3(1, $1);
- %*/
}
| f_optarg ',' f_opt
{
- /*%%%*/
$$ = block_append($1, $3);
- /*%
- $$ = rb_ary_push($1, $3);
- %*/
}
;
@@ -4178,30 +2340,23 @@ restarg_mark : '*'
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()) {
- shadowing_lvar($2);
- dyna_var($2);
+ rb_dvar_push($2, Qnil);
}
$$ = assignable($2, 0);
- /*%
- $$ = dispatch1(restparam, $2);
- %*/
}
| restarg_mark
{
- /*%%%*/
if (dyna_in_block()) {
$$ = NEW_DASGN_CURR(internal_id(), 0);
}
else {
$$ = NEW_NODE(NODE_LASGN,0,0,local_append(0));
}
- /*%
- $$ = dispatch1(restparam, Qnil);
- %*/
}
;
@@ -4211,22 +2366,11 @@ blkarg_mark : '&'
f_block_arg : blkarg_mark tIDENTIFIER
{
- /*%%%*/
if (!is_local_id($2))
yyerror("block argument must be local variable");
- else if (!dyna_in_block() && local_id($2))
- yyerror("duplicated block argument name");
- if (dyna_in_block()) {
- shadowing_lvar($2);
- dyna_var($2);
- $$ = assignable($2, 0);
- }
- else {
- $$ = NEW_BLOCK_ARG($2);
- }
- /*%
- $$ = $2;
- %*/
+ else if (local_id($2))
+ yyerror("duplicate block argument name");
+ $$ = NEW_BLOCK_ARG($2);
}
;
@@ -4239,16 +2383,11 @@ opt_f_block_arg : ',' f_block_arg
singleton : var_ref
{
- /*%%%*/
$$ = $1;
value_expr($$);
- /*%
- $$ = $1;
- %*/
}
- | '(' {lex_state = EXPR_BEG;} expr rparen
+ | '(' {lex_state = EXPR_BEG;} expr opt_nl ')'
{
- /*%%%*/
if ($3 == 0) {
yyerror("can't define singleton method for ().");
}
@@ -4269,9 +2408,6 @@ singleton : var_ref
}
}
$$ = $3;
- /*%
- $$ = dispatch1(paren, $3);
- %*/
}
;
@@ -4282,49 +2418,23 @@ assoc_list : none
}
| args trailer
{
- /*%%%*/
if ($1->nd_alen%2 != 0) {
yyerror("odd number list for Hash");
}
$$ = $1;
- /*%
- $$ = dispatch1(assoclist_from_args, $1);
- %*/
}
;
assocs : assoc
- /*%c%*/
- /*%c
- {
- $$ = rb_ary_new3(1, $1);
- }
- %*/
| assocs ',' assoc
{
- /*%%%*/
$$ = list_concat($1, $3);
- /*%
- rb_ary_push($$, $3);
- %*/
}
;
assoc : arg_value tASSOC arg_value
{
- /*%%%*/
$$ = list_append(NEW_LIST($1), $3);
- /*%
- $$ = dispatch2(assoc_new, $1, $3);
- %*/
- }
- | tLABEL arg_value
- {
- /*%%%*/
- $$ = list_append(NEW_LIST(NEW_LIT(ID2SYM($1))), $2);
- /*%
- $$ = dispatch2(assoc_new, $1, $2);
- %*/
}
;
@@ -4345,15 +2455,7 @@ operation3 : tIDENTIFIER
;
dot_or_colon : '.'
- /*%c%*/
- /*%c
- { $$ = $<val>1; }
- %*/
| tCOLON2
- /*%c%*/
- /*%c
- { $$ = $<val>1; }
- %*/
;
opt_terms : /* none */
@@ -4364,12 +2466,6 @@ opt_nl : /* none */
| '\n'
;
-rparen : opt_nl ')'
- ;
-
-rbracket : opt_nl ']'
- ;
-
trailer : /* none */
| '\n'
| ','
@@ -4383,93 +2479,13 @@ terms : term
| terms ';' {yyerrok;}
;
-none : /* none */
- {
- /*%%%*/
- $$ = 0;
- /*%
- $$ = Qundef;
- %*/
- }
+none : /* none */ {$$ = 0;}
;
%%
-# undef parser
-# undef yylex
-# undef yylval
-# define yylval (*((YYSTYPE*)(parser->parser_yylval)))
-
-static int parser_regx_options(struct parser_params*);
-static int parser_tokadd_string(struct parser_params*,int,int,int,long*);
-static int parser_parse_string(struct parser_params*,NODE*);
-static int parser_here_document(struct parser_params*,NODE*);
-
-# define nextc() parser_nextc(parser)
-# define pushback(c) parser_pushback(parser, c)
-# define newtok() parser_newtok(parser)
-# define tokadd(c) parser_tokadd(parser, c)
-# define read_escape() parser_read_escape(parser)
-# define tokadd_escape(t) parser_tokadd_escape(parser, t)
-# define regx_options() parser_regx_options(parser)
-# define tokadd_string(f,t,p,n) parser_tokadd_string(parser,f,t,p,n)
-# define parse_string(n) parser_parse_string(parser,n)
-# define here_document(n) parser_here_document(parser,n)
-# define heredoc_identifier() parser_heredoc_identifier(parser)
-# define heredoc_restore(n) parser_heredoc_restore(parser,n)
-# define whole_match_p(e,l,i) parser_whole_match_p(parser,e,l,i)
-
-#ifdef RIPPER
-/* FIXME */
-# define local_cnt(x) 3
-# define local_id(x) 1
-# define dyna_in_block() 1
-#endif /* RIPPER */
-
-#ifndef RIPPER
-# define set_yylval_str(x) yylval.node = NEW_STR(x)
-# define set_yylval_num(x) yylval.num = x
-# define set_yylval_id(x) yylval.id = x
-# define set_yylval_literal(x) yylval.node = NEW_LIT(x)
-# define set_yylval_node(x) yylval.node = x
-# define yylval_id() yylval.id
-#else
-# define set_yylval_str(x) (void)(x)
-# define set_yylval_num(x) (void)(x)
-# define set_yylval_id(x) (void)(x)
-# define set_yylval_literal(x) (void)(x)
-# define set_yylval_node(x) (void)(x)
-# define yylval_id() SYM2ID(yylval.val)
+#ifdef yystacksize
+#undef YYMALLOC
#endif
-#ifdef RIPPER
-#define ripper_flush(p) (p->tokp = p->parser_lex_p)
-
-static void
-ripper_dispatch_scan_event(struct parser_params *parser, int t)
-{
- VALUE str;
-
- if (lex_p < parser->tokp) rb_raise(rb_eRuntimeError, "lex_p < tokp");
- if (lex_p == parser->tokp) return;
- str = rb_str_new(parser->tokp, lex_p - parser->tokp);
- yylval.val = ripper_dispatch1(parser, ripper_token2eventid(t), str);
- ripper_flush(parser);
-}
-
-static void
-ripper_dispatch_delayed_token(struct parser_params *parser, int t)
-{
- int saved_line = ruby_sourceline;
- const char *saved_tokp = parser->tokp;
-
- ruby_sourceline = parser->delayed_line;
- parser->tokp = lex_pbeg + parser->delayed_col;
- yylval.val = ripper_dispatch1(parser, ripper_token2eventid(t), parser->delayed);
- parser->delayed = Qnil;
- ruby_sourceline = saved_line;
- parser->tokp = saved_tokp;
-}
-#endif /* RIPPER */
-
#include "regex.h"
#include "util.h"
@@ -4486,10 +2502,23 @@ ripper_dispatch_delayed_token(struct parser_params *parser, int t)
#endif
#define is_identchar(c) (SIGN_EXTEND_CHAR(c)!=-1&&(ISALNUM(c) || (c) == '_' || ismbchar(c)))
+static char *tokenbuf = NULL;
+static int tokidx, toksiz = 0;
+
+#define LEAVE_BS 1
+
+static VALUE (*lex_gets)(); /* gets function */
+static VALUE lex_input; /* non-nil if File */
+static VALUE lex_lastline; /* gc protect */
+static char *lex_pbeg;
+static char *lex_p;
+static char *lex_pend;
+
static int
-parser_yyerror(struct parser_params *parser, const char *msg)
+yyerror(msg)
+ const char *msg;
{
-#ifndef RIPPER
+ const int max_line_margin = 30;
const char *p, *pe;
char *buf;
int len, i;
@@ -4511,10 +2540,24 @@ parser_yyerror(struct parser_params *parser, const char *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", buf);
+ rb_compile_error_append("%s%s%s", pre, buf, post);
i = lex_p - p;
p2 = buf; pe = buf + len;
@@ -4527,26 +2570,30 @@ parser_yyerror(struct parser_params *parser, const char *msg)
buf[i+1] = '\0';
rb_compile_error_append("%s", buf);
}
-#else
- dispatch1(parse_error, rb_str_new2(msg));
-#endif /* !RIPPER */
+
return 0;
}
-static void parser_prepare(struct parser_params *parser);
+static int heredoc_end;
+
+int ruby_in_compile = 0;
+int ruby__end__seen;
+
+static VALUE ruby_debug_lines;
+#ifdef YYMALLOC
+static NODE *parser_heap;
+#endif
-#ifndef RIPPER
static NODE*
-yycompile(VALUE vparser, const char *f, int line)
+yycompile(f, line)
+ char *f;
+ int line;
{
int n;
+ NODE *node = 0;
struct RVarmap *vp, *vars = ruby_dyna_vars;
- const char *kcode_save;
- volatile VALUE parser_save;
- struct parser_params *parser;
- *(&parser_save) = vparser;
- Data_Get_Struct(vparser, struct parser_params, parser);
+ ruby_in_compile = 1;
if (!compile_for_eval && rb_safe_level() == 0 &&
rb_const_defined(rb_cObject, rb_intern("SCRIPT_LINES__"))) {
VALUE hash, fname;
@@ -4554,30 +2601,38 @@ yycompile(VALUE vparser, const char *f, int 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_hash_aref(hash, fname);
- if (NIL_P(ruby_debug_lines)) {
- ruby_debug_lines = rb_ary_new();
- rb_hash_aset(hash, fname, 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);
- n = line - 1;
- do {
+ while (line > 1) {
rb_ary_push(ruby_debug_lines, str);
- } while (--n);
+ line--;
+ }
}
}
- kcode_save = rb_get_kcode();
+ 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);
- ruby_sourceline = line - 1;
- parser_prepare(parser);
- n = yyparse((void*)parser);
+ deferred_nodes = 0;
+ n = yyparse();
ruby_debug_lines = 0;
compile_for_eval = 0;
- rb_set_kcode(kcode_save);
+ ruby_in_compile = 0;
+ cond_stack = 0;
+ cmdarg_stack = 0;
+ command_start = 1;
+ class_nest = 0;
+ in_single = 0;
+ in_def = 0;
+ cur_mid = 0;
+ deferred_nodes = 0;
vp = ruby_dyna_vars;
ruby_dyna_vars = vars;
@@ -4587,151 +2642,98 @@ yycompile(VALUE vparser, const char *f, int line)
vp = vp->next;
rb_gc_force_recycle((VALUE)tmp);
}
- if (ruby_eval_tree_begin) {
- return NEW_PRELUDE(ruby_eval_tree_begin, ruby_eval_tree);
- }
- else {
- return ruby_eval_tree;
- }
+ if (n == 0) node = ruby_eval_tree;
+ if (ruby_nerrs) ruby_eval_tree_begin = 0;
+ return node;
}
-#endif /* !RIPPER */
+
+static int lex_gets_ptr;
static VALUE
-lex_get_str(struct parser_params *parser, VALUE s)
+lex_get_str(s)
+ VALUE s;
{
char *beg, *end, *pend;
- beg = RSTRING_PTR(s);
+ beg = RSTRING(s)->ptr;
if (lex_gets_ptr) {
- if (RSTRING_LEN(s) == lex_gets_ptr) return Qnil;
+ if (RSTRING(s)->len == lex_gets_ptr) return Qnil;
beg += lex_gets_ptr;
}
- pend = RSTRING_PTR(s) + RSTRING_LEN(s);
+ pend = RSTRING(s)->ptr + RSTRING(s)->len;
end = beg;
while (end < pend) {
if (*end++ == '\n') break;
}
- lex_gets_ptr = end - RSTRING_PTR(s);
+ lex_gets_ptr = end - RSTRING(s)->ptr;
return rb_str_new(beg, end - beg);
}
static VALUE
-lex_getline(struct parser_params *parser)
+lex_getline()
{
- VALUE line = (*parser->parser_lex_gets)(parser, parser->parser_lex_input);
-#ifndef RIPPER
+ VALUE line = (*lex_gets)(lex_input);
if (ruby_debug_lines && !NIL_P(line)) {
rb_ary_push(ruby_debug_lines, line);
}
-#endif
return line;
}
-#ifndef RIPPER
NODE*
-rb_compile_string(const char *f, VALUE s, int line)
+rb_compile_string(f, s, line)
+ const char *f;
+ VALUE s;
+ int line;
{
- VALUE volatile vparser = rb_parser_new();
-
- return rb_parser_compile_string(vparser, f, s, line);
-}
-
-NODE*
-rb_parser_compile_string(VALUE vparser, const char *f, VALUE s, int line)
-{
- struct parser_params *parser;
-
- Data_Get_Struct(vparser, struct parser_params, parser);
lex_gets = lex_get_str;
lex_gets_ptr = 0;
lex_input = s;
lex_pbeg = lex_p = lex_pend = 0;
+ ruby_sourceline = line - 1;
compile_for_eval = ruby_in_eval;
- return yycompile(vparser, f, line);
+ return yycompile(f, line);
}
NODE*
-rb_compile_cstr(const char *f, const char *s, int len, int line)
+rb_compile_cstr(f, s, len, line)
+ const char *f, *s;
+ int len, line;
{
return rb_compile_string(f, rb_str_new(s, len), line);
}
NODE*
-rb_parser_compile_cstr(VALUE vparser, const char *f, const char *s, int len, int line)
-{
- return rb_parser_compile_string(vparser, f, rb_str_new(s, len), line);
-}
-
-static VALUE
-lex_io_gets(struct parser_params *parser, VALUE io)
-{
- return rb_io_gets(io);
-}
-
-NODE*
-rb_compile_file(const char *f, VALUE file, int start)
-{
- VALUE volatile vparser = rb_parser_new();
-
- return rb_parser_compile_file(vparser, f, file, start);
-}
-
-NODE*
-rb_parser_compile_file(VALUE vparser, const char *f, VALUE file, int start)
+rb_compile_file(f, file, start)
+ const char *f;
+ VALUE file;
+ int start;
{
- struct parser_params *parser;
-
- Data_Get_Struct(vparser, struct parser_params, parser);
- lex_gets = lex_io_gets;
+ lex_gets = rb_io_gets;
lex_input = file;
lex_pbeg = lex_p = lex_pend = 0;
+ ruby_sourceline = start - 1;
- return yycompile(vparser, f, start);
+ return yycompile(f, start);
}
-#endif /* !RIPPER */
static inline int
-parser_nextc(struct parser_params *parser)
+nextc()
{
int c;
if (lex_p == lex_pend) {
- if (parser->eofp)
- return -1;
if (lex_input) {
- VALUE v = lex_getline(parser);
+ VALUE v = lex_getline();
- if (NIL_P(v)) {
- parser->eofp = Qtrue;
- return -1;
- }
-#ifdef RIPPER
- if (parser->tokp < lex_pend) {
- if (NIL_P(parser->delayed)) {
- parser->delayed = rb_str_buf_new(1024);
- rb_str_buf_cat(parser->delayed,
- parser->tokp, lex_pend - parser->tokp);
- parser->delayed_line = ruby_sourceline;
- parser->delayed_col = parser->tokp - lex_pbeg;
- }
- else {
- rb_str_buf_cat(parser->delayed,
- parser->tokp, lex_pend - parser->tokp);
- }
- }
-#endif
+ if (NIL_P(v)) return -1;
if (heredoc_end > 0) {
ruby_sourceline = heredoc_end;
heredoc_end = 0;
}
ruby_sourceline++;
- parser->line_count++;
- lex_pbeg = lex_p = RSTRING_PTR(v);
- lex_pend = lex_p + RSTRING_LEN(v);
-#ifdef RIPPER
- ripper_flush(parser);
-#endif
+ lex_pbeg = lex_p = RSTRING(v)->ptr;
+ lex_pend = lex_p + RSTRING(v)->len;
lex_lastline = v;
}
else {
@@ -4749,16 +2751,13 @@ parser_nextc(struct parser_params *parser)
}
static void
-parser_pushback(struct parser_params *parser, int c)
+pushback(c)
+ int c;
{
if (c == -1) return;
lex_p--;
- if (lex_p > lex_pbeg && lex_p[0] == '\n' && lex_p[-1] == '\r') {
- lex_p--;
- }
}
-#define lex_goto_eol(parser) (parser->parser_lex_p = parser->parser_lex_pend)
#define was_bol() (lex_p == lex_pbeg + 1)
#define peek(c) (lex_p != lex_pend && (c) == *lex_p)
@@ -4768,7 +2767,7 @@ parser_pushback(struct parser_params *parser, int c)
#define toklast() (tokidx>0?tokenbuf[tokidx-1]:0)
static char*
-parser_newtok(struct parser_params *parser)
+newtok()
{
tokidx = 0;
if (!tokenbuf) {
@@ -4783,9 +2782,10 @@ parser_newtok(struct parser_params *parser)
}
static void
-parser_tokadd(struct parser_params *parser, int c)
+tokadd(c)
+ char c;
{
- tokenbuf[tokidx++] = (char)c;
+ tokenbuf[tokidx++] = c;
if (tokidx >= toksiz) {
toksiz *= 2;
REALLOC_N(tokenbuf, char, toksiz);
@@ -4793,7 +2793,7 @@ parser_tokadd(struct parser_params *parser, int c)
}
static int
-parser_read_escape(struct parser_params *parser)
+read_escape()
{
int c;
@@ -4883,7 +2883,7 @@ parser_read_escape(struct parser_params *parser)
eof:
case -1:
- yyerror("Invalid escape character syntax");
+ yyerror("Invalid escape character syntax");
return '\0';
default:
@@ -4892,7 +2892,8 @@ parser_read_escape(struct parser_params *parser)
}
static int
-parser_tokadd_escape(struct parser_params *parser, int term)
+tokadd_escape(term)
+ int term;
{
int c;
@@ -4965,7 +2966,7 @@ parser_tokadd_escape(struct parser_params *parser, int term)
eof:
case -1:
- yyerror("Invalid escape character syntax");
+ yyerror("Invalid escape character syntax");
return -1;
default:
@@ -4977,32 +2978,49 @@ parser_tokadd_escape(struct parser_params *parser, int term)
}
static int
-parser_regx_options(struct parser_params *parser)
+regx_options()
{
- extern int rb_char_to_option_kcode(int c, int *option, int *kcode);
-
- int kcode = 0;
+ char kcode = 0;
int options = 0;
- int c, opt, kc;
+ int c;
newtok();
while (c = nextc(), ISALPHA(c)) {
- if (c == 'o') {
- options |= RE_OPTION_ONCE;
- }
- else if (rb_char_to_option_kcode(c, &opt, &kc)) {
- options |= opt;
- if (kc != 0) kcode = kc;
- }
- else {
+ switch (c) {
+ case 'i':
+ options |= RE_OPTION_IGNORECASE;
+ break;
+ case 'x':
+ options |= RE_OPTION_EXTENDED;
+ break;
+ case 'm':
+ options |= RE_OPTION_MULTILINE;
+ break;
+ case 'o':
+ options |= RE_OPTION_ONCE;
+ break;
+ case 'n':
+ kcode = 16;
+ break;
+ case 'e':
+ kcode = 32;
+ break;
+ case 's':
+ kcode = 48;
+ break;
+ case 'u':
+ kcode = 64;
+ break;
+ default:
tokadd(c);
- }
+ break;
+ }
}
pushback(c);
if (toklen()) {
tokfix();
- compile_error(PARSER_ARG "unknown regexp option%s - %s",
- toklen() > 1 ? "s" : "", tok());
+ rb_compile_error("unknown regexp option%s - %s",
+ toklen() > 1 ? "s" : "", tok());
}
return options | kcode;
}
@@ -5026,22 +3044,20 @@ enum string_type {
};
static void
-dispose_string(VALUE str)
+dispose_string(str)
+ VALUE str;
{
- if (RBASIC(str)->flags & RSTRING_NOEMBED)
- xfree(RSTRING_PTR(str));
+ xfree(RSTRING(str)->ptr);
rb_gc_force_recycle(str);
}
static int
-parser_tokadd_string(struct parser_params *parser,
- int func, int term, int paren, long *nest)
+tokadd_string(func, term, paren, nest)
+ int func, term, paren, *nest;
{
int c;
- unsigned char uc;
while ((c = nextc()) != -1) {
- uc = (unsigned char)c;
if (paren && c == paren) {
++*nest;
}
@@ -5092,8 +3108,8 @@ parser_tokadd_string(struct parser_params *parser,
}
}
}
- else if (ismbchar(uc)) {
- int i, len = mbclen(uc)-1;
+ else if (ismbchar(c)) {
+ int i, len = mbclen(c)-1;
for (i = 0; i < len; i++) {
tokadd(c);
@@ -5106,7 +3122,7 @@ parser_tokadd_string(struct parser_params *parser,
}
if (!c && (func & STR_FUNC_SYMBOL)) {
func &= ~STR_FUNC_SYMBOL;
- rb_compile_error(PARSER_ARG "symbol cannot contain '\\0'");
+ rb_compile_error("symbol cannot contain '\\0'");
continue;
}
tokadd(c);
@@ -5114,23 +3130,12 @@ parser_tokadd_string(struct parser_params *parser,
return c;
}
-#define NEW_STRTERM0(func, term, paren) \
+#define NEW_STRTERM(func, term, paren) \
rb_node_newnode(NODE_STRTERM, (func), (term) | ((paren) << (CHAR_BIT * 2)), 0)
-#ifndef RIPPER
-# define NEW_STRTERM(func, term, paren) NEW_STRTERM0(func, term, paren)
-#else
-# define NEW_STRTERM(func, term, paren) ripper_new_strterm(parser, func, term, paren)
-static NODE *
-ripper_new_strterm(struct parser_params *parser, VALUE func, VALUE term, VALUE paren)
-{
- NODE *node = NEW_STRTERM0(func, term, paren);
- nd_set_line(node, ruby_sourceline);
- return node;
-}
-#endif
static int
-parser_parse_string(struct parser_params *parser, NODE *quote)
+parse_string(quote)
+ NODE *quote;
{
int func = quote->nd_func;
int term = nd_term(quote);
@@ -5149,7 +3154,7 @@ parser_parse_string(struct parser_params *parser, NODE *quote)
return ' ';
}
if (!(func & STR_FUNC_REGEXP)) return tSTRING_END;
- set_yylval_num(regx_options());
+ yylval.num = regx_options();
return tREGEXP_END;
}
if (space) {
@@ -5170,28 +3175,20 @@ parser_parse_string(struct parser_params *parser, NODE *quote)
}
pushback(c);
if (tokadd_string(func, term, paren, &quote->nd_nest) == -1) {
- if (func & STR_FUNC_REGEXP) {
- ruby_sourceline = nd_line(quote);
- rb_compile_error(PARSER_ARG "unterminated regexp meets end of file");
- return tREGEXP_END;
- }
- else {
- ruby_sourceline = nd_line(quote);
- rb_compile_error(PARSER_ARG "unterminated string meets end of file");
- return tSTRING_END;
- }
+ ruby_sourceline = nd_line(quote);
+ rb_compile_error("unterminated string meets end of file");
+ return tSTRING_END;
}
tokfix();
- set_yylval_str(rb_str_new(tok(), toklen()));
+ yylval.node = NEW_STR(rb_str_new(tok(), toklen()));
return tSTRING_CONTENT;
}
static int
-parser_heredoc_identifier(struct parser_params *parser)
+heredoc_identifier()
{
int c = nextc(), term, func = 0, len;
- unsigned int uc;
if (c == '-') {
c = nextc();
@@ -5209,19 +3206,17 @@ parser_heredoc_identifier(struct parser_params *parser)
tokadd(func);
term = c;
while ((c = nextc()) != -1 && c != term) {
- uc = (unsigned int)c;
- len = mbclen(uc);
+ len = mbclen(c);
do {tokadd(c);} while (--len > 0 && (c = nextc()) != -1);
}
if (c == -1) {
- rb_compile_error(PARSER_ARG "unterminated here document identifier");
+ rb_compile_error("unterminated here document identifier");
return 0;
}
break;
default:
- uc = (unsigned int)c;
- if (!is_identchar(uc)) {
+ if (!is_identchar(c)) {
pushback(c);
if (func & STR_FUNC_INDENT) {
pushback('-');
@@ -5232,62 +3227,44 @@ parser_heredoc_identifier(struct parser_params *parser)
term = '"';
tokadd(func |= str_dquote);
do {
- uc = (unsigned int)c;
- len = mbclen(uc);
+ len = mbclen(c);
do {tokadd(c);} while (--len > 0 && (c = nextc()) != -1);
- } while ((c = nextc()) != -1 &&
- (uc = (unsigned char)c, is_identchar(uc)));
+ } while ((c = nextc()) != -1 && is_identchar(c));
pushback(c);
break;
}
tokfix();
-#ifdef RIPPER
- ripper_dispatch_scan_event(parser, tHEREDOC_BEG);
-#endif
len = lex_p - lex_pbeg;
- lex_goto_eol(parser);
+ lex_p = lex_pend;
lex_strterm = rb_node_newnode(NODE_HEREDOC,
rb_str_new(tok(), toklen()), /* nd_lit */
len, /* nd_nth */
lex_lastline); /* nd_orig */
- nd_set_line(lex_strterm, ruby_sourceline);
-#ifdef RIPPER
- ripper_flush(parser);
-#endif
return term == '`' ? tXSTRING_BEG : tSTRING_BEG;
}
static void
-parser_heredoc_restore(struct parser_params *parser, NODE *here)
+heredoc_restore(here)
+ NODE *here;
{
- VALUE line;
-
-#ifdef RIPPER
- if (!NIL_P(parser->delayed))
- ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
- lex_goto_eol(parser);
- ripper_dispatch_scan_event(parser, tHEREDOC_END);
-#endif
- line = here->nd_orig;
+ VALUE line = here->nd_orig;
lex_lastline = line;
- lex_pbeg = RSTRING_PTR(line);
- lex_pend = lex_pbeg + RSTRING_LEN(line);
+ lex_pbeg = RSTRING(line)->ptr;
+ lex_pend = lex_pbeg + RSTRING(line)->len;
lex_p = lex_pbeg + here->nd_nth;
heredoc_end = ruby_sourceline;
ruby_sourceline = nd_line(here);
dispose_string(here->nd_lit);
rb_gc_force_recycle((VALUE)here);
-#ifdef RIPPER
- ripper_flush(parser);
-#endif
}
static int
-parser_whole_match_p(struct parser_params *parser,
- const char *eos, int len, int indent)
+whole_match_p(eos, len, indent)
+ char *eos;
+ int len, indent;
{
- const char *p = lex_pbeg;
+ char *p = lex_pbeg;
int n;
if (indent) {
@@ -5300,20 +3277,21 @@ parser_whole_match_p(struct parser_params *parser,
}
static int
-parser_here_document(struct parser_params *parser, NODE *here)
+here_document(here)
+ NODE *here;
{
int c, func, indent = 0;
- const char *eos, *p, *pend;
+ char *eos, *p, *pend;
long len;
VALUE str = 0;
- eos = RSTRING_PTR(here->nd_lit);
- len = RSTRING_LEN(here->nd_lit) - 1;
+ eos = RSTRING(here->nd_lit)->ptr;
+ len = RSTRING(here->nd_lit)->len - 1;
indent = (func = *eos++) & STR_FUNC_INDENT;
if ((c = nextc()) == -1) {
error:
- rb_compile_error(PARSER_ARG "can't find string \"%s\" anywhere before EOF", eos);
+ rb_compile_error("can't find string \"%s\" anywhere before EOF", eos);
heredoc_restore(lex_strterm);
lex_strterm = 0;
return 0;
@@ -5325,7 +3303,7 @@ parser_here_document(struct parser_params *parser, NODE *here)
if (!(func & STR_FUNC_EXPAND)) {
do {
- p = RSTRING_PTR(lex_lastline);
+ p = RSTRING(lex_lastline)->ptr;
pend = lex_pend;
if (pend > p) {
switch (pend[-1]) {
@@ -5343,7 +3321,7 @@ parser_here_document(struct parser_params *parser, NODE *here)
else
str = rb_str_new(p, pend - p);
if (pend < lex_pend) rb_str_cat(str, "\n", 1);
- lex_goto_eol(parser);
+ lex_p = lex_pend;
if (nextc() == -1) {
if (str) dispose_string(str);
goto error;
@@ -5367,7 +3345,7 @@ parser_here_document(struct parser_params *parser, NODE *here)
pushback(c);
if ((c = tokadd_string(func, '\n', 0, NULL)) == -1) goto error;
if (c != '\n') {
- set_yylval_str(rb_str_new(tok(), toklen()));
+ yylval.node = NEW_STR(rb_str_new(tok(), toklen()));
return tSTRING_CONTENT;
}
tokadd(nextc());
@@ -5377,213 +3355,27 @@ parser_here_document(struct parser_params *parser, NODE *here)
}
heredoc_restore(lex_strterm);
lex_strterm = NEW_STRTERM(-1, 0, 0);
- set_yylval_str(str);
+ yylval.node = NEW_STR(str);
return tSTRING_CONTENT;
}
#include "lex.c"
-#ifndef RIPPER
static void
-arg_ambiguous(void)
+arg_ambiguous()
{
rb_warning("ambiguous first argument; put parentheses or even spaces");
}
-#else
-static void
-ripper_arg_ambiguous(struct parser_params *parser)
-{
- dispatch0(arg_ambiguous);
-}
-#define arg_ambiguous() ripper_arg_ambiguous(parser)
-#endif
-
-static int
-lvar_defined_gen(struct parser_params *parser, ID id)
-{
-#ifndef RIPPER
- return (dyna_in_block() && rb_dvar_defined(id)) || local_id(id);
-#else
- return 0;
-#endif
-}
-
-/* emacsen -*- hack */
-#ifndef RIPPER
-typedef void (*rb_pragma_setter_t)(struct parser_params *parser, const char *name, const char *val);
-
-static void
-pragma_encoding(struct parser_params *parser, const char *name, const char *val)
-{
- if (parser && parser->line_count != (parser->has_shebang ? 2 : 1))
- return;
- rb_set_kcode(val);
-}
-
-struct pragma {
- const char *name;
- rb_pragma_setter_t func;
-};
-
-static const struct pragma pragmas[] = {
- {"coding", pragma_encoding},
-};
-#endif
-
-static const char *
-pragma_marker(const char *str, int len)
-{
- int i = 2;
-
- while (i < len) {
- switch (str[i]) {
- case '-':
- if (str[i-1] == '*' && str[i-2] == '-') {
- return str + i + 1;
- }
- i += 2;
- break;
- case '*':
- if (i + 1 >= len) return 0;
- if (str[i+1] != '-') {
- i += 4;
- }
- else if (str[i-1] != '-') {
- i += 2;
- }
- else {
- return str + i + 2;
- }
- break;
- default:
- i += 3;
- break;
- }
- }
- return 0;
-}
-
-static int
-parser_pragma(struct parser_params *parser, const char *str, int len)
-{
- VALUE name = 0, val = 0;
- const char *beg, *end, *vbeg, *vend;
-#define str_copy(_s, _p, _n) ((_s) \
- ? (rb_str_resize((_s), (_n)), \
- MEMCPY(RSTRING_PTR(_s), (_p), char, (_n)), (_s)) \
- : ((_s) = rb_str_new((_p), (_n))))
-
- if (len <= 7) return Qfalse;
- if (!(beg = pragma_marker(str, len))) return Qfalse;
- if (!(end = pragma_marker(beg, str + len - beg))) return Qfalse;
- str = beg;
- len = end - beg - 3;
-
- /* %r"([^\\s\'\":;]+)\\s*:\\s*(\"(?:\\\\.|[^\"])*\"|[^\"\\s;]+)[\\s;]*" */
- while (len > 0) {
-#ifndef RIPPER
- const struct pragma *p = pragmas;
-#endif
- int n = 0;
-
- for (; len > 0 && *str; str++, --len) {
- switch (*str) {
- case '\'': case '"': case ':': case ';':
- continue;
- }
- if (!ISSPACE(*str)) break;
- }
- for (beg = str; len > 0; str++, --len) {
- switch (*str) {
- case '\'': case '"': case ':': case ';':
- break;
- default:
- if (ISSPACE(*str)) break;
- continue;
- }
- break;
- }
- for (end = str; len > 0 && ISSPACE(*str); str++, --len);
- if (!len) break;
- if (*str != ':') continue;
-
- do str++; while (--len > 0 && ISSPACE(*str));
- if (!len) break;
- if (*str == '"') {
- for (vbeg = ++str; --len > 0 && *str != '"'; str++) {
- if (*str == '\\') {
- --len;
- ++str;
- }
- }
- vend = str;
- if (len) {
- --len;
- ++str;
- }
- }
- else {
- for (vbeg = str; len > 0 && *str != '"' && !ISSPACE(*str); --len, str++);
- vend = str;
- }
- while (len > 0 && (*str == ';' || ISSPACE(*str))) --len, str++;
-
- n = end - beg;
- str_copy(name, beg, n);
- rb_funcall(name, rb_intern("downcase!"), 0);
-#ifndef RIPPER
- do {
- if (strncmp(p->name, RSTRING_PTR(name), n) == 0) {
- str_copy(val, vbeg, vend - vbeg);
- (*p->func)(parser, RSTRING_PTR(name), RSTRING_PTR(val));
- break;
- }
- } while (++p < pragmas + sizeof(pragmas) / sizeof(*p));
-#else
- dispatch2(pragma, name, val);
-#endif
- }
-
- return Qtrue;
-}
-
-static void
-parser_prepare(struct parser_params *parser)
-{
- int c = nextc();
- switch (c) {
- case '#':
- if (peek('!')) parser->has_shebang = 1;
- break;
- case 0xef: /* UTF-8 BOM marker */
- if (lex_pend - lex_p >= 2 &&
- (unsigned char)lex_p[0] == 0xbb &&
- (unsigned char)lex_p[1] == 0xbf) {
- rb_set_kcode("UTF-8");
- lex_p += 2;
- return;
- }
- break;
- case EOF:
- return;
- }
- pushback(c);
-}
#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_VALUE || lex_state == EXPR_CLASS)
static int
-parser_yylex(struct parser_params *parser)
+yylex()
{
register int c;
int space_seen = 0;
int cmd_state;
- unsigned char uc;
- enum lex_state_e last_state;
-#ifdef RIPPER
- int fallthru = Qfalse;
-#endif
+ enum lex_state last_state;
if (lex_strterm) {
int token;
@@ -5607,21 +3399,6 @@ parser_yylex(struct parser_params *parser)
cmd_state = command_start;
command_start = Qfalse;
retry:
-#ifdef RIPPER
- while ((c = nextc())) {
- switch (c) {
- case ' ': case '\t': case '\f': case '\r':
- case '\13': /* '\v' */
- space_seen++;
- break;
- default:
- goto outofloop;
- }
- }
- outofloop:
- pushback(c);
- ripper_dispatch_scan_event(parser, tSP);
-#endif
switch (c = nextc()) {
case '\0': /* NUL */
case '\004': /* ^D */
@@ -5636,15 +3413,10 @@ parser_yylex(struct parser_params *parser)
goto retry;
case '#': /* it's a comment */
- if (!parser->has_shebang || parser->line_count != 1) {
- /* no pragma in shebang line */
- parser_pragma(parser, lex_p, lex_pend - lex_p);
- }
- lex_p = lex_pend;
-#ifdef RIPPER
- ripper_dispatch_scan_event(parser, tCOMMENT);
- fallthru = Qtrue;
-#endif
+ while ((c = nextc()) != '\n') {
+ if (c == -1)
+ return 0;
+ }
/* fall through */
case '\n':
switch (lex_state) {
@@ -5652,13 +3424,6 @@ parser_yylex(struct parser_params *parser)
case EXPR_FNAME:
case EXPR_DOT:
case EXPR_CLASS:
- case EXPR_VALUE:
-#ifdef RIPPER
- if (!fallthru) {
- ripper_dispatch_scan_event(parser, tIGNORED_NL);
- }
- fallthru = Qfalse;
-#endif
goto retry;
default:
break;
@@ -5670,7 +3435,7 @@ parser_yylex(struct parser_params *parser)
case '*':
if ((c = nextc()) == '*') {
if ((c = nextc()) == '=') {
- set_yylval_id(tPOW);
+ yylval.id = tPOW;
lex_state = EXPR_BEG;
return tOP_ASGN;
}
@@ -5679,16 +3444,16 @@ parser_yylex(struct parser_params *parser)
}
else {
if (c == '=') {
- set_yylval_id('*');
+ yylval.id = '*';
lex_state = EXPR_BEG;
return tOP_ASGN;
}
pushback(c);
if (IS_ARG() && space_seen && !ISSPACE(c)){
- rb_warning0("`*' interpreted as argument prefix");
+ 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 {
@@ -5718,23 +3483,11 @@ parser_yylex(struct parser_params *parser)
if (was_bol()) {
/* skip embedded rd document */
if (strncmp(lex_p, "begin", 5) == 0 && ISSPACE(lex_p[5])) {
-#ifdef RIPPER
- int first_p = Qtrue;
-
- lex_goto_eol(parser);
- ripper_dispatch_scan_event(parser, tEMBDOC_BEG);
-#endif
for (;;) {
- lex_goto_eol(parser);
-#ifdef RIPPER
- if (!first_p) {
- ripper_dispatch_scan_event(parser, tEMBDOC);
- }
- first_p = Qfalse;
-#endif
+ lex_p = lex_pend;
c = nextc();
if (c == -1) {
- rb_compile_error(PARSER_ARG "embedded document meets end of file");
+ rb_compile_error("embedded document meets end of file");
return 0;
}
if (c != '=') continue;
@@ -5743,10 +3496,7 @@ parser_yylex(struct parser_params *parser)
break;
}
}
- lex_goto_eol(parser);
-#ifdef RIPPER
- ripper_dispatch_scan_event(parser, tEMBDOC_END);
-#endif
+ lex_p = lex_pend;
goto retry;
}
}
@@ -5799,7 +3549,7 @@ parser_yylex(struct parser_params *parser)
}
if (c == '<') {
if ((c = nextc()) == '=') {
- set_yylval_id(tLSHFT);
+ yylval.id = tLSHFT;
lex_state = EXPR_BEG;
return tOP_ASGN;
}
@@ -5821,7 +3571,7 @@ parser_yylex(struct parser_params *parser)
}
if (c == '>') {
if ((c = nextc()) == '=') {
- set_yylval_id(tRSHFT);
+ yylval.id = tRSHFT;
lex_state = EXPR_BEG;
return tOP_ASGN;
}
@@ -5855,17 +3605,15 @@ parser_yylex(struct parser_params *parser)
return tSTRING_BEG;
case '?':
- if (lex_state == EXPR_END ||
- lex_state == EXPR_ENDARG) {
- lex_state = EXPR_VALUE;
+ if (lex_state == EXPR_END || lex_state == EXPR_ENDARG) {
+ lex_state = EXPR_BEG;
return '?';
}
c = nextc();
if (c == -1) {
- rb_compile_error(PARSER_ARG "incomplete character syntax");
+ rb_compile_error("incomplete character syntax");
return 0;
}
- uc = (unsigned char)c;
if (ISSPACE(c)){
if (!IS_ARG()){
int c2 = 0;
@@ -5890,44 +3638,34 @@ parser_yylex(struct parser_params *parser)
break;
}
if (c2) {
- rb_warnI("invalid character syntax; use ?\\%c", c2);
+ rb_warn("invalid character syntax; use ?\\%c", c2);
}
}
ternary:
pushback(c);
- lex_state = EXPR_VALUE;
+ lex_state = EXPR_BEG;
return '?';
}
- newtok();
- if (ismbchar(uc)) {
- int i, len = mbclen(uc)-1;
-
- tokadd(c);
- for (i = 0; i < len; i++) {
- c = nextc();
- tokadd(c);
- }
+ else if (ismbchar(c)) {
+ rb_warn("multibyte character literal not supported yet; use ?\\%.3o", c);
+ goto ternary;
}
else if ((ISALNUM(c) || c == '_') && lex_p < lex_pend && is_identchar(*lex_p)) {
goto ternary;
}
else if (c == '\\') {
c = read_escape();
- tokadd(c);
- }
- else {
- tokadd(c);
}
- tokfix();
- set_yylval_str(rb_str_new(tok(), toklen()));
+ c &= 0xff;
lex_state = EXPR_END;
- return tCHAR;
+ yylval.node = NEW_LIT(INT2FIX(c));
+ return tINTEGER;
case '&':
if ((c = nextc()) == '&') {
lex_state = EXPR_BEG;
if ((c = nextc()) == '=') {
- set_yylval_id(tANDOP);
+ yylval.id = tANDOP;
lex_state = EXPR_BEG;
return tOP_ASGN;
}
@@ -5935,16 +3673,16 @@ parser_yylex(struct parser_params *parser)
return tANDOP;
}
else if (c == '=') {
- set_yylval_id('&');
+ yylval.id = '&';
lex_state = EXPR_BEG;
return tOP_ASGN;
}
pushback(c);
if (IS_ARG() && space_seen && !ISSPACE(c)){
- rb_warning0("`&' interpreted as argument prefix");
+ 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 {
@@ -5962,7 +3700,7 @@ parser_yylex(struct parser_params *parser)
if ((c = nextc()) == '|') {
lex_state = EXPR_BEG;
if ((c = nextc()) == '=') {
- set_yylval_id(tOROP);
+ yylval.id = tOROP;
lex_state = EXPR_BEG;
return tOP_ASGN;
}
@@ -5970,7 +3708,7 @@ parser_yylex(struct parser_params *parser)
return tOROP;
}
if (c == '=') {
- set_yylval_id('|');
+ yylval.id = '|';
lex_state = EXPR_BEG;
return tOP_ASGN;
}
@@ -5994,11 +3732,11 @@ parser_yylex(struct parser_params *parser)
return '+';
}
if (c == '=') {
- set_yylval_id('+');
+ yylval.id = '+';
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;
@@ -6024,15 +3762,11 @@ parser_yylex(struct parser_params *parser)
return '-';
}
if (c == '=') {
- set_yylval_id('-');
+ yylval.id = '-';
lex_state = EXPR_BEG;
return tOP_ASGN;
}
- if (c == '>') {
- lex_state = EXPR_ARG;
- return tLAMBDA;
- }
- 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;
@@ -6099,7 +3833,7 @@ parser_yylex(struct parser_params *parser)
yyerror("numeric literal without digits");
}
else if (nondigit) goto trailing_uc;
- set_yylval_literal(rb_cstr_to_inum(tok(), 16, Qfalse));
+ yylval.node = NEW_LIT(rb_cstr_to_inum(tok(), 16, Qfalse));
return tINTEGER;
}
if (c == 'b' || c == 'B') {
@@ -6123,7 +3857,7 @@ parser_yylex(struct parser_params *parser)
yyerror("numeric literal without digits");
}
else if (nondigit) goto trailing_uc;
- set_yylval_literal(rb_cstr_to_inum(tok(), 2, Qfalse));
+ yylval.node = NEW_LIT(rb_cstr_to_inum(tok(), 2, Qfalse));
return tINTEGER;
}
if (c == 'd' || c == 'D') {
@@ -6147,7 +3881,7 @@ parser_yylex(struct parser_params *parser)
yyerror("numeric literal without digits");
}
else if (nondigit) goto trailing_uc;
- set_yylval_literal(rb_cstr_to_inum(tok(), 10, Qfalse));
+ yylval.node = NEW_LIT(rb_cstr_to_inum(tok(), 10, Qfalse));
return tINTEGER;
}
if (c == '_') {
@@ -6164,13 +3898,14 @@ parser_yylex(struct parser_params *parser)
if (c >= '0' && c <= '7') {
/* octal */
octal_number:
- do {
+ do {
if (c == '_') {
if (nondigit) break;
nondigit = c;
continue;
}
- if (c < '0' || c > '7') break;
+ if (c < '0' || c > '9') break;
+ if (c > '7') goto invalid_octal;
nondigit = 0;
tokadd(c);
} while ((c = nextc()) != -1);
@@ -6178,7 +3913,7 @@ parser_yylex(struct parser_params *parser)
pushback(c);
tokfix();
if (nondigit) goto trailing_uc;
- set_yylval_literal(rb_cstr_to_inum(tok(), 8, Qfalse));
+ yylval.node = NEW_LIT(rb_cstr_to_inum(tok(), 8, Qfalse));
return tINTEGER;
}
if (nondigit) {
@@ -6187,6 +3922,7 @@ parser_yylex(struct parser_params *parser)
}
}
if (c > '7' && c <= '9') {
+ invalid_octal:
yyerror("Illegal octal digit");
}
else if (c == '.' || c == 'e' || c == 'E') {
@@ -6194,7 +3930,7 @@ parser_yylex(struct parser_params *parser)
}
else {
pushback(c);
- set_yylval_literal(INT2FIX(0));
+ yylval.node = NEW_LIT(INT2FIX(0));
return tINTEGER;
}
}
@@ -6270,20 +4006,19 @@ parser_yylex(struct parser_params *parser)
if (is_float) {
double d = strtod(tok(), 0);
if (errno == ERANGE) {
- rb_warnS("Float %s out of range", tok());
+ rb_warn("Float %s out of range", tok());
errno = 0;
}
- set_yylval_literal(rb_float_new(d));
+ yylval.node = NEW_LIT(rb_float_new(d));
return tFLOAT;
}
- set_yylval_literal(rb_cstr_to_inum(tok(), 10, Qfalse));
+ yylval.node = NEW_LIT(rb_cstr_to_inum(tok(), 10, Qfalse));
return tINTEGER;
}
- case ')':
case ']':
- paren_nest--;
case '}':
+ case ')':
COND_LEXPOP();
CMDARG_LEXPOP();
lex_state = EXPR_END;
@@ -6292,7 +4027,7 @@ parser_yylex(struct parser_params *parser)
case ':':
c = nextc();
if (c == ':') {
- if (IS_BEG() ||
+ if (lex_state == EXPR_BEG || lex_state == EXPR_MID ||
lex_state == EXPR_CLASS || (IS_ARG() && space_seen)) {
lex_state = EXPR_BEG;
return tCOLON3;
@@ -6300,8 +4035,7 @@ parser_yylex(struct parser_params *parser)
lex_state = EXPR_DOT;
return tCOLON2;
}
- if (lex_state == EXPR_END ||
- lex_state == EXPR_ENDARG || ISSPACE(c)) {
+ if (lex_state == EXPR_END || lex_state == EXPR_ENDARG || ISSPACE(c)) {
pushback(c);
lex_state = EXPR_BEG;
return ':';
@@ -6321,12 +4055,12 @@ parser_yylex(struct parser_params *parser)
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;
}
if ((c = nextc()) == '=') {
- set_yylval_id('/');
+ yylval.id = '/';
lex_state = EXPR_BEG;
return tOP_ASGN;
}
@@ -6348,7 +4082,7 @@ parser_yylex(struct parser_params *parser)
case '^':
if ((c = nextc()) == '=') {
- set_yylval_id('^');
+ yylval.id = '^';
lex_state = EXPR_BEG;
return tOP_ASGN;
}
@@ -6362,13 +4096,10 @@ parser_yylex(struct parser_params *parser)
return '^';
case ';':
- lex_state = EXPR_BEG;
command_start = Qtrue;
- return ';';
-
case ',':
lex_state = EXPR_BEG;
- return ',';
+ return c;
case '~':
if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
@@ -6385,7 +4116,8 @@ parser_yylex(struct parser_params *parser)
return '~';
case '(':
- if (IS_BEG()) {
+ command_start = Qtrue;
+ if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
c = tLPAREN;
}
else if (space_seen) {
@@ -6393,18 +4125,16 @@ parser_yylex(struct parser_params *parser)
c = tLPAREN_ARG;
}
else if (lex_state == EXPR_ARG) {
- rb_warning0("don't put space before argument parentheses");
+ rb_warn("don't put space before argument parentheses");
c = '(';
}
}
- paren_nest++;
COND_PUSH(0);
CMDARG_PUSH(0);
lex_state = EXPR_BEG;
return c;
case '[':
- paren_nest++;
if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
lex_state = EXPR_ARG;
if ((c = nextc()) == ']') {
@@ -6417,7 +4147,7 @@ parser_yylex(struct parser_params *parser)
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) {
@@ -6429,14 +4159,8 @@ parser_yylex(struct parser_params *parser)
return c;
case '{':
- if (lpar_beg && lpar_beg == paren_nest) {
- lex_state = EXPR_BEG;
- lpar_beg = 0;
- --paren_nest;
- return tLAMBEG;
- }
if (IS_ARG() || lex_state == EXPR_END)
- c = '{'; /* block (primary) */
+ c = '{'; /* block (primary) */
else if (lex_state == EXPR_ENDARG)
c = tLBRACE_ARG; /* block (expr) */
else
@@ -6450,16 +4174,13 @@ parser_yylex(struct parser_params *parser)
c = nextc();
if (c == '\n') {
space_seen = 1;
-#ifdef RIPPER
- ripper_dispatch_scan_event(parser, tSP);
-#endif
goto retry; /* skip \\n */
}
pushback(c);
return '\\';
case '%':
- if (IS_BEG()) {
+ if (lex_state == EXPR_BEG || lex_state == EXPR_MID) {
int term;
int paren;
@@ -6471,14 +4192,13 @@ parser_yylex(struct parser_params *parser)
}
else {
term = nextc();
- uc = (unsigned char)c;
- if (ISALNUM(term) || ismbchar(uc)) {
+ if (ISALNUM(term) || ismbchar(term)) {
yyerror("unknown type of %string");
return 0;
}
}
if (c == -1 || term == -1) {
- rb_compile_error(PARSER_ARG "unterminated quoted string meets end of file");
+ rb_compile_error("unterminated quoted string meets end of file");
return 0;
}
paren = term;
@@ -6528,7 +4248,7 @@ parser_yylex(struct parser_params *parser)
}
}
if ((c = nextc()) == '=') {
- set_yylval_id('%');
+ yylval.id = '%';
lex_state = EXPR_BEG;
return tOP_ASGN;
}
@@ -6552,8 +4272,7 @@ parser_yylex(struct parser_params *parser)
switch (c) {
case '_': /* $_: last read line string */
c = nextc();
- uc = (unsigned char)c;
- if (is_identchar(uc)) {
+ if (is_identchar(c)) {
tokadd('$');
tokadd('_');
break;
@@ -6562,7 +4281,7 @@ parser_yylex(struct parser_params *parser)
c = '_';
/* fall through */
case '~': /* $~: match-data */
- (void)local_cnt(c);
+ local_cnt(c);
/* fall through */
case '*': /* $*: argv */
case '$': /* $$: pid */
@@ -6582,15 +4301,14 @@ parser_yylex(struct parser_params *parser)
tokadd('$');
tokadd(c);
tokfix();
- set_yylval_id(rb_intern(tok()));
+ yylval.id = rb_intern(tok());
return tGVAR;
case '-':
tokadd('$');
tokadd(c);
c = nextc();
- uc = (unsigned char)c;
- if (is_identchar(uc)) {
+ if (is_identchar(c)) {
tokadd(c);
}
else {
@@ -6598,11 +4316,8 @@ parser_yylex(struct parser_params *parser)
}
gvar:
tokfix();
- set_yylval_id(rb_intern(tok()));
- if (!is_global_id(yylval_id())) {
- rb_compile_error(PARSER_ARG "invalid global variable `%s'", rb_id2name(yylval.id));
- return 0;
- }
+ yylval.id = rb_intern(tok());
+ /* xxx shouldn't check if valid option variable */
return tGVAR;
case '&': /* $&: last match */
@@ -6614,7 +4329,7 @@ parser_yylex(struct parser_params *parser)
tokadd(c);
goto gvar;
}
- set_yylval_node(NEW_BACK_REF(c));
+ yylval.node = NEW_BACK_REF(c);
return tBACK_REF;
case '1': case '2': case '3':
@@ -6628,12 +4343,11 @@ parser_yylex(struct parser_params *parser)
pushback(c);
if (last_state == EXPR_FNAME) goto gvar;
tokfix();
- set_yylval_node(NEW_NTH_REF(atoi(tok()+1)));
+ yylval.node = NEW_NTH_REF(atoi(tok()+1));
return tNTH_REF;
default:
- uc = (unsigned char)c;
- if (!is_identchar(uc)) {
+ if (!is_identchar(c)) {
pushback(c);
return '$';
}
@@ -6652,14 +4366,14 @@ parser_yylex(struct parser_params *parser)
}
if (ISDIGIT(c)) {
if (tokidx == 1) {
- rb_compile_error(PARSER_ARG "`@%c' is not allowed as an instance variable name", c);
+ rb_compile_error("`@%c' is not allowed as an instance variable name", c);
}
else {
- rb_compile_error(PARSER_ARG "`@@%c' is not allowed as a class variable name", c);
+ rb_compile_error("`@@%c' is not allowed as a class variable name", c);
}
+ return 0;
}
- uc = (unsigned char)c;
- if (!is_identchar(uc)) {
+ if (!is_identchar(c)) {
pushback(c);
return '@';
}
@@ -6669,21 +4383,14 @@ parser_yylex(struct parser_params *parser)
if (was_bol() && whole_match_p("__END__", 7, 0)) {
ruby__end__seen = 1;
lex_lastline = 0;
-#ifndef RIPPER
return -1;
-#else
- lex_goto_eol(parser);
- ripper_dispatch_scan_event(parser, k__END__);
- return 0;
-#endif
}
newtok();
break;
default:
- uc = (unsigned char)c;
- if (!is_identchar(uc)) {
- rb_compile_error(PARSER_ARG "Invalid char `\\%03o' in expression", c);
+ if (!is_identchar(c)) {
+ rb_compile_error("Invalid char `\\%03o' in expression", c);
goto retry;
}
@@ -6691,11 +4398,10 @@ parser_yylex(struct parser_params *parser)
break;
}
- uc = (unsigned char)c;
do {
tokadd(c);
- if (ismbchar(uc)) {
- int i, len = mbclen(uc)-1;
+ if (ismbchar(c)) {
+ int i, len = mbclen(c)-1;
for (i = 0; i < len; i++) {
c = nextc();
@@ -6703,8 +4409,7 @@ parser_yylex(struct parser_params *parser)
}
}
c = nextc();
- uc = (unsigned char)c;
- } while (is_identchar(uc));
+ } while (is_identchar(c));
if ((c == '!' || c == '?') && is_identchar(tok()[0]) && !peek('=')) {
tokadd(c);
}
@@ -6755,31 +4460,26 @@ parser_yylex(struct parser_params *parser)
}
if (lex_state != EXPR_DOT) {
- const struct kwtable *kw;
+ struct kwtable *kw;
/* See if it is a reserved word. */
kw = rb_reserved_word(tok(), toklen());
if (kw) {
- enum lex_state_e state = lex_state;
+ enum lex_state state = lex_state;
lex_state = kw->state;
if (state == EXPR_FNAME) {
- set_yylval_id(rb_intern(kw->name));
+ yylval.id = rb_intern(kw->name);
return kw->id[0];
}
- if (kw->id[0] == keyword_do) {
- if (lpar_beg && lpar_beg == paren_nest) {
- lpar_beg = 0;
- --paren_nest;
- return keyword_do_LAMBDA;
- }
- if (COND_P()) return keyword_do_cond;
+ if (kw->id[0] == kDO) {
+ if (COND_P()) return kDO_COND;
if (CMDARG_P() && state != EXPR_CMDARG)
- return keyword_do_block;
- if (state == EXPR_ENDARG || state == EXPR_BEG)
- return keyword_do_block;
- return keyword_do;
+ return kDO_BLOCK;
+ if (state == EXPR_ENDARG)
+ return kDO_BLOCK;
+ return kDO;
}
- if (state == EXPR_BEG || state == EXPR_VALUE)
+ if (state == EXPR_BEG)
return kw->id[0];
else {
if (kw->id[0] != kw->id[1])
@@ -6789,19 +4489,11 @@ parser_yylex(struct parser_params *parser)
}
}
- if ((lex_state == EXPR_BEG && !cmd_state) ||
+ if (lex_state == EXPR_BEG ||
+ lex_state == EXPR_MID ||
+ lex_state == EXPR_DOT ||
lex_state == EXPR_ARG ||
lex_state == EXPR_CMDARG) {
- if (peek(':') && !(lex_p + 1 < lex_pend && lex_p[1] == ':')) {
- lex_state = EXPR_BEG;
- nextc();
- set_yylval_id(rb_intern(tok()));
- return tLABEL;
- }
- }
- if (IS_BEG() ||
- lex_state == EXPR_DOT ||
- IS_ARG()) {
if (cmd_state) {
lex_state = EXPR_CMDARG;
}
@@ -6813,48 +4505,20 @@ parser_yylex(struct parser_params *parser)
lex_state = EXPR_END;
}
}
- {
- ID ident = rb_intern(tok());
-
- set_yylval_id(ident);
- if (last_state != EXPR_DOT && is_local_id(ident) && lvar_defined(ident)) {
- lex_state = EXPR_END;
- }
+ yylval.id = rb_intern(tok());
+ if (is_local_id(yylval.id) &&
+ last_state != EXPR_DOT &&
+ ((dyna_in_block() && rb_dvar_defined(yylval.id)) || local_id(yylval.id))) {
+ lex_state = EXPR_END;
}
return result;
}
}
-#if YYPURE
-static int
-yylex(void *lval, void *p)
-#else
-yylex(void *p)
-#endif
-{
- struct parser_params *parser = (struct parser_params*)p;
- int t;
-
-#if YYPURE
- parser->parser_yylval = (union tmpyystype*)lval;
- parser->parser_yylval->val = Qundef;
-#endif
- t = parser_yylex(parser);
-#ifdef RIPPER
- if (!NIL_P(parser->delayed)) {
- ripper_dispatch_delayed_token(parser, t);
- return t;
- }
- if (t != 0)
- ripper_dispatch_scan_event(parser, t);
-#endif
-
- return t;
-}
-
-#ifndef RIPPER
NODE*
-rb_node_newnode(enum node_type type, VALUE a0, VALUE a1, VALUE a2)
+rb_node_newnode(type, a0, a1, a2)
+ enum node_type type;
+ VALUE a0, a1, a2;
{
NODE *n = (NODE*)rb_newobj();
@@ -6870,29 +4534,40 @@ rb_node_newnode(enum node_type type, VALUE a0, VALUE a1, VALUE a2)
return n;
}
-enum node_type
-nodetype(NODE *node) /* for debug */
+static enum node_type
+nodetype(node) /* for debug */
+ NODE *node;
{
return (enum node_type)nd_type(node);
}
-int
-nodeline(NODE *node)
+static int
+nodeline(node)
+ NODE *node;
{
return nd_line(node);
}
static NODE*
-newline_node(NODE *node)
+newline_node(node)
+ NODE *node;
{
+ NODE *nl = 0;
if (node) {
- node->flags |= NODE_NEWLINE;
+ 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;
}
- return node;
+ return nl;
}
static void
-fixpos(NODE *node, NODE *orig)
+fixpos(node, orig)
+ NODE *node, *orig;
{
if (!node) return;
if (!orig) return;
@@ -6902,7 +4577,9 @@ fixpos(NODE *node, NODE *orig)
}
static void
-parser_warning(NODE *node, const char *mesg)
+parser_warning(node, mesg)
+ NODE *node;
+ const char *mesg;
{
int line = ruby_sourceline;
ruby_sourceline = nd_line(node);
@@ -6911,7 +4588,9 @@ parser_warning(NODE *node, const char *mesg)
}
static void
-parser_warn(NODE *node, const char *mesg)
+parser_warn(node, mesg)
+ NODE *node;
+ const char *mesg;
{
int line = ruby_sourceline;
ruby_sourceline = nd_line(node);
@@ -6920,20 +4599,21 @@ parser_warn(NODE *node, const char *mesg)
}
static NODE*
-block_append(NODE *head, NODE *tail)
+block_append(head, tail)
+ NODE *head, *tail;
{
- NODE *end, *h = head, *nd;
+ NODE *end, *h = head;
if (tail == 0) return head;
+ again:
if (h == 0) return tail;
switch (nd_type(h)) {
+ case NODE_NEWLINE:
+ h = h->nd_next;
+ goto again;
case NODE_LIT:
case NODE_STR:
- case NODE_SELF:
- case NODE_TRUE:
- case NODE_FALSE:
- case NODE_NIL:
parser_warning(h, "unused literal ignored");
return tail;
default:
@@ -6947,20 +4627,25 @@ block_append(NODE *head, NODE *tail)
break;
}
- nd = end->nd_head;
- switch (nd_type(nd)) {
- case NODE_RETURN:
- case NODE_BREAK:
- case NODE_NEXT:
- case NODE_REDO:
- case NODE_RETRY:
- if (RTEST(ruby_verbose)) {
+ if (RTEST(ruby_verbose)) {
+ NODE *nd = end->nd_head;
+ newline:
+ switch (nd_type(nd)) {
+ case NODE_RETURN:
+ case NODE_BREAK:
+ case NODE_NEXT:
+ case NODE_REDO:
+ case NODE_RETRY:
parser_warning(nd, "statement not reached");
- }
- break;
+ break;
- default:
- break;
+ case NODE_NEWLINE:
+ nd = nd->nd_next;
+ goto newline;
+
+ default:
+ break;
+ }
}
if (nd_type(tail) != NODE_BLOCK) {
@@ -6974,7 +4659,8 @@ block_append(NODE *head, NODE *tail)
/* append item to the list */
static NODE*
-list_append(NODE *list, NODE *item)
+list_append(list, item)
+ NODE *list, *item;
{
NODE *last;
@@ -6994,7 +4680,8 @@ list_append(NODE *list, NODE *item)
/* concat two lists */
static NODE*
-list_concat(NODE *head, NODE *tail)
+list_concat(head, tail)
+ NODE *head, *tail;
{
NODE *last;
@@ -7019,7 +4706,8 @@ list_concat(NODE *head, NODE *tail)
/* concat two string literals */
static NODE *
-literal_concat(NODE *head, NODE *tail)
+literal_concat(head, tail)
+ NODE *head, *tail;
{
enum node_type htype;
@@ -7068,7 +4756,8 @@ literal_concat(NODE *head, NODE *tail)
}
static NODE *
-evstr2dstr(NODE *node)
+evstr2dstr(node)
+ NODE *node;
{
if (nd_type(node) == NODE_EVSTR) {
node = list_append(NEW_DSTR(rb_str_new(0, 0)), node);
@@ -7077,23 +4766,32 @@ evstr2dstr(NODE *node)
}
static NODE *
-new_evstr(NODE *node)
+new_evstr(node)
+ NODE *node;
{
NODE *head = node;
+ again:
if (node) {
switch (nd_type(node)) {
case NODE_STR: case NODE_DSTR: case NODE_EVSTR:
return node;
+ case NODE_NEWLINE:
+ node = node->nd_next;
+ goto again;
}
}
return NEW_EVSTR(head);
}
static NODE *
-call_op_gen(struct parser_params *parser, NODE *recv, ID id, int narg, NODE *arg1)
+call_op(recv, id, narg, arg1)
+ NODE *recv;
+ ID id;
+ int narg;
+ NODE *arg1;
{
- value_expr(arg1);
+ value_expr(recv);
if (narg == 1) {
value_expr(arg1);
arg1 = NEW_LIST(arg1);
@@ -7105,7 +4803,9 @@ call_op_gen(struct parser_params *parser, NODE *recv, ID id, int narg, NODE *arg
}
static NODE*
-match_op_gen(struct parser_params *parser, NODE *node1, NODE *node2)
+match_gen(node1, node2)
+ NODE *node1;
+ NODE *node2;
{
local_cnt('~');
@@ -7141,31 +4841,36 @@ match_op_gen(struct parser_params *parser, NODE *node1, NODE *node2)
}
static NODE*
-gettable_gen(struct parser_params *parser, ID id)
+gettable(id)
+ ID id;
{
- if (id == keyword_self) {
+ if (id == kSELF) {
return NEW_SELF();
}
- else if (id == keyword_nil) {
+ else if (id == kNIL) {
return NEW_NIL();
}
- else if (id == keyword_true) {
+ else if (id == kTRUE) {
return NEW_TRUE();
}
- else if (id == keyword_false) {
+ else if (id == kFALSE) {
return NEW_FALSE();
}
- else if (id == keyword__FILE__) {
+ else if (id == k__FILE__) {
return NEW_STR(rb_str_new2(ruby_sourcefile));
}
- else if (id == keyword__LINE__) {
+ else if (id == k__LINE__) {
return NEW_LIT(INT2FIX(ruby_sourceline));
}
else if (is_local_id(id)) {
if (dyna_in_block() && rb_dvar_defined(id)) return NEW_DVAR(id);
if (local_id(id)) return NEW_LVAR(id);
/* method call without arguments */
- dyna_check(id);
+#if 0
+ /* Rite will warn this */
+ rb_warn("ambiguous identifier; %s() or self.%s is better for method call",
+ rb_id2name(id), rb_id2name(id));
+#endif
return NEW_VCALL(id);
}
else if (is_global_id(id)) {
@@ -7184,40 +4889,44 @@ gettable_gen(struct parser_params *parser, ID id)
return 0;
}
+static VALUE dyna_var_lookup _((ID id));
+
static NODE*
-assignable_gen(struct parser_params *parser, ID id, NODE *val)
+assignable(id, val)
+ ID id;
+ NODE *val;
{
value_expr(val);
- if (id == keyword_self) {
+ if (id == kSELF) {
yyerror("Can't change the value of self");
}
- else if (id == keyword_nil) {
+ else if (id == kNIL) {
yyerror("Can't assign to nil");
}
- else if (id == keyword_true) {
+ else if (id == kTRUE) {
yyerror("Can't assign to true");
}
- else if (id == keyword_false) {
+ else if (id == kFALSE) {
yyerror("Can't assign to false");
}
- else if (id == keyword__FILE__) {
+ else if (id == k__FILE__) {
yyerror("Can't assign to __FILE__");
}
- else if (id == keyword__LINE__) {
+ else if (id == k__LINE__) {
yyerror("Can't assign to __LINE__");
}
else if (is_local_id(id)) {
if (rb_dvar_curr(id)) {
return NEW_DASGN_CURR(id, val);
}
- else if (rb_dvar_defined(id)) {
+ else if (dyna_var_lookup(id)) {
return NEW_DASGN(id, val);
}
else if (local_id(id) || !dyna_in_block()) {
return NEW_LASGN(id, val);
}
else{
- dyna_var(id);
+ rb_dvar_push(id, Qnil);
return NEW_DASGN_CURR(id, val);
}
}
@@ -7242,29 +4951,9 @@ assignable_gen(struct parser_params *parser, ID id, NODE *val)
return 0;
}
-static void
-shadowing_lvar_gen(struct parser_params *parser, ID name)
-{
- if (rb_dvar_defined(name) || local_id(name)) {
- rb_warningS("shadowing outer local variable - %s", rb_id2name(name));
- }
-}
-
-static NODE*
-new_bv_gen(struct parser_params *parser, ID name, NODE *val)
-{
- if (!is_local_id(name)) {
- compile_error(PARSER_ARG "invalid local variable - %s",
- rb_id2name(name));
- return 0;
- }
- shadowing_lvar(name);
- dyna_var(name);
- return NEW_DASGN_CURR(name, val);
-}
-
static NODE *
-aryset_gen(struct parser_params *parser, NODE *recv, NODE *idx)
+aryset(recv, idx)
+ NODE *recv, *idx;
{
if (recv && nd_type(recv) == NODE_SELF)
recv = (NODE *)1;
@@ -7273,16 +4962,9 @@ aryset_gen(struct parser_params *parser, NODE *recv, NODE *idx)
return NEW_ATTRASGN(recv, tASET, idx);
}
-static void
-block_dup_check(NODE *node1, NODE *node2)
-{
- if (node2 && node1 && nd_type(node1) == NODE_BLOCK_PASS) {
- compile_error("both block arg and actual block given");
- }
-}
-
ID
-rb_id_attrset(ID id)
+rb_id_attrset(id)
+ ID id;
{
id &= ~ID_SCOPE_MASK;
id |= ID_ATTRSET;
@@ -7290,7 +4972,9 @@ rb_id_attrset(ID id)
}
static NODE *
-attrset_gen(struct parser_params *parser, NODE *recv, ID id)
+attrset(recv, id)
+ NODE *recv;
+ ID id;
{
if (recv && nd_type(recv) == NODE_SELF)
recv = (NODE *)1;
@@ -7300,11 +4984,12 @@ attrset_gen(struct parser_params *parser, NODE *recv, ID id)
}
static void
-rb_backref_error(NODE *node)
+rb_backref_error(node)
+ NODE *node;
{
switch (nd_type(node)) {
case NODE_NTH_REF:
- rb_compile_error("Can't set variable $%ld", node->nd_nth);
+ rb_compile_error("Can't set variable $%d", node->nd_nth);
break;
case NODE_BACK_REF:
rb_compile_error("Can't set variable $%c", (int)node->nd_nth);
@@ -7313,48 +4998,31 @@ rb_backref_error(NODE *node)
}
static NODE *
-arg_concat(NODE *node1, NODE *node2)
+arg_concat(node1, node2)
+ NODE *node1;
+ NODE *node2;
{
if (!node2) return node1;
- if (nd_type(node1) == NODE_BLOCK_PASS) {
- node1->nd_iter = arg_concat(node1->nd_iter, node2);
- return node1;
- }
return NEW_ARGSCAT(node1, node2);
}
static NODE *
-arg_append(NODE *node1, NODE *node2)
+arg_add(node1, node2)
+ NODE *node1;
+ NODE *node2;
{
if (!node1) return NEW_LIST(node2);
- switch (nd_type(node1)) {
- case NODE_ARRAY:
+ if (nd_type(node1) == NODE_ARRAY) {
return list_append(node1, node2);
- case NODE_BLOCK_PASS:
- node1->nd_head = arg_append(node1->nd_head, node2);
- return node1;
- default:
- return NEW_ARGSPUSH(node1, node2);
}
-}
-
-static NODE *
-arg_add(NODE *node1, NODE *node2)
-{
- if (!node1) return NEW_LIST(node2);
- switch (nd_type(node1)) {
- case NODE_ARRAY:
- return list_append(node1, node2);
- case NODE_BLOCK_PASS:
- node1->nd_head = arg_add(node1->nd_head, node2);
- return node1;
- default:
+ else {
return NEW_ARGSPUSH(node1, node2);
}
}
static NODE*
-node_assign_gen(struct parser_params *parser, NODE *lhs, NODE *rhs)
+node_assign(lhs, rhs)
+ NODE *lhs, *rhs;
{
if (!lhs) return 0;
@@ -7386,7 +5054,8 @@ node_assign_gen(struct parser_params *parser, NODE *lhs, NODE *rhs)
}
static int
-value_expr_gen(struct parser_params *parser, NODE *node)
+value_expr0(node)
+ NODE *node;
{
int cond = 0;
@@ -7428,6 +5097,10 @@ value_expr_gen(struct parser_params *parser, NODE *node)
node = node->nd_2nd;
break;
+ case NODE_NEWLINE:
+ node = node->nd_next;
+ break;
+
default:
return Qtrue;
}
@@ -7437,14 +5110,20 @@ value_expr_gen(struct parser_params *parser, NODE *node)
}
static void
-void_expr_gen(struct parser_params *parser, NODE *node)
+void_expr0(node)
+ NODE *node;
{
- const char *useless = 0;
+ char *useless = 0;
if (!RTEST(ruby_verbose)) return;
+ again:
if (!node) return;
switch (nd_type(node)) {
+ case NODE_NEWLINE:
+ node = node->nd_next;
+ goto again;
+
case NODE_CALL:
switch (node->nd_mid) {
case '+':
@@ -7527,7 +5206,8 @@ void_expr_gen(struct parser_params *parser, NODE *node)
}
static void
-void_stmts_gen(struct parser_params *parser, NODE *node)
+void_stmts(node)
+ NODE *node;
{
if (!RTEST(ruby_verbose)) return;
if (!node) return;
@@ -7535,79 +5215,33 @@ void_stmts_gen(struct parser_params *parser, NODE *node)
for (;;) {
if (!node->nd_next) return;
- void_expr(node->nd_head);
+ void_expr0(node->nd_head);
node = node->nd_next;
}
}
static NODE *
-remove_begin(NODE *node)
+remove_begin(node)
+ NODE *node;
{
NODE **n = &node;
while (*n) {
- if (nd_type(*n) != NODE_BEGIN) {
- return node;
- }
- *n = (*n)->nd_body;
- }
- return node;
-}
-
-static void
-reduce_nodes(NODE **body)
-{
- NODE *node = *body;
-
- if (!node) {
- *body = NEW_NIL();
- return;
- }
-#define subnodes(n1, n2) \
- ((!node->n1) ? (node->n2 ? (body = &node->n2, 1) : 0) : \
- (!node->n2) ? (body = &node->n1, 1) : \
- (reduce_nodes(&node->n1), body = &node->n2, 1))
-
- while (node) {
- switch (nd_type(node)) {
- end:
- case NODE_NIL:
- *body = 0;
- return;
- case NODE_RETURN:
- *body = node = node->nd_stts;
+ switch (nd_type(*n)) {
+ case NODE_NEWLINE:
+ n = &(*n)->nd_next;
continue;
case NODE_BEGIN:
- *body = node = node->nd_body;
- continue;
- case NODE_BLOCK:
- body = &node->nd_end->nd_head;
- break;
- case NODE_IF:
- if (subnodes(nd_body, nd_else)) break;
- return;
- case NODE_CASE:
- body = &node->nd_body;
- break;
- case NODE_WHEN:
- if (!subnodes(nd_body, nd_next)) goto end;
- break;
- case NODE_ENSURE:
- if (!subnodes(nd_head, nd_resq)) goto end;
- break;
- case NODE_RESCUE:
- if (!subnodes(nd_head, nd_resq)) goto end;
- break;
+ *n = (*n)->nd_body;
default:
- return;
+ return node;
}
- node = *body;
}
-
-#undef subnodes
+ return node;
}
static int
-assign_in_cond(struct parser_params *parser, NODE *node)
+assign_in_cond(node)
+ NODE *node;
{
switch (nd_type(node)) {
case NODE_MASGN:
@@ -7620,6 +5254,7 @@ assign_in_cond(struct parser_params *parser, NODE *node)
case NODE_IASGN:
break;
+ case NODE_NEWLINE:
default:
return 0;
}
@@ -7642,11 +5277,16 @@ assign_in_cond(struct parser_params *parser, NODE *node)
default:
break;
}
+#if 0
+ if (assign_in_cond(node->nd_value) == 0) {
+ parser_warning(node->nd_value, "assignment in condition");
+ }
+#endif
return 1;
}
static int
-e_option_supplied(void)
+e_option_supplied()
{
if (strcmp(ruby_sourcefile, "-e") == 0)
return Qtrue;
@@ -7654,39 +5294,77 @@ e_option_supplied(void)
}
static void
-warn_unless_e_option(NODE *node, const char *str)
+warn_unless_e_option(node, str)
+ NODE *node;
+ const char *str;
{
if (!e_option_supplied()) parser_warn(node, str);
}
static void
-warning_unless_e_option(NODE *node, const char *str)
+warning_unless_e_option(node, str)
+ NODE *node;
+ const char *str;
{
if (!e_option_supplied()) parser_warning(node, str);
}
-static NODE *cond0(struct parser_params*,NODE*);
+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*
-range_op(struct parser_params *parser, NODE *node)
+range_op(node)
+ NODE *node;
{
enum node_type type;
- if (!e_option_supplied()) return node;
if (node == 0) return 0;
- value_expr(node);
- node = cond0(parser, 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 node;
+ return cond0(node);
}
static int
-literal_node(NODE *node)
+literal_node(node)
+ NODE *node;
{
if (!node) return 1; /* same as NODE_NIL */
switch (nd_type(node)) {
@@ -7707,10 +5385,11 @@ literal_node(NODE *node)
}
static NODE*
-cond0(struct parser_params *parser, NODE *node)
+cond0(node)
+ NODE *node;
{
if (node == 0) return 0;
- assign_in_cond(parser, node);
+ assign_in_cond(node);
switch (nd_type(node)) {
case NODE_DSTR:
@@ -7728,14 +5407,14 @@ cond0(struct parser_params *parser, NODE *node)
case NODE_AND:
case NODE_OR:
- node->nd_1st = cond0(parser, node->nd_1st);
- node->nd_2nd = cond0(parser, node->nd_2nd);
+ node->nd_1st = cond0(node->nd_1st);
+ node->nd_2nd = cond0(node->nd_2nd);
break;
case NODE_DOT2:
case NODE_DOT3:
- node->nd_beg = range_op(parser, node->nd_beg);
- node->nd_end = range_op(parser, node->nd_end);
+ node->nd_beg = range_op(node->nd_beg);
+ node->nd_end = range_op(node->nd_end);
if (nd_type(node) == NODE_DOT2) nd_set_type(node,NODE_FLIP2);
else if (nd_type(node) == NODE_DOT3) nd_set_type(node, NODE_FLIP3);
node->nd_cnt = local_append(internal_id());
@@ -7769,15 +5448,22 @@ cond0(struct parser_params *parser, NODE *node)
}
static NODE*
-cond_gen(struct parser_params *parser, NODE *node)
+cond(node)
+ NODE *node;
{
if (node == 0) return 0;
value_expr(node);
- return cond0(parser, node);
+ if (nd_type(node) == NODE_NEWLINE){
+ node->nd_next = cond0(node->nd_next);
+ return node;
+ }
+ return cond0(node);
}
static NODE*
-logop_gen(struct parser_params *parser, enum node_type type, NODE *left, NODE *right)
+logop(type, left, right)
+ enum node_type type;
+ NODE *left, *right;
{
value_expr(left);
if (left && nd_type(left) == type) {
@@ -7792,7 +5478,8 @@ logop_gen(struct parser_params *parser, enum node_type type, NODE *left, NODE *r
}
static int
-cond_negative(NODE **nodep)
+cond_negative(nodep)
+ NODE **nodep;
{
NODE *c = *nodep;
@@ -7801,12 +5488,18 @@ cond_negative(NODE **nodep)
case NODE_NOT:
*nodep = c->nd_body;
return 1;
+ case NODE_NEWLINE:
+ if (c->nd_next && nd_type(c->nd_next) == NODE_NOT) {
+ c->nd_next = c->nd_next->nd_body;
+ return 1;
+ }
}
return 0;
}
static void
-no_blockarg(NODE *node)
+no_blockarg(node)
+ NODE *node;
{
if (node && nd_type(node) == NODE_BLOCK_PASS) {
rb_compile_error("block argument should not be given");
@@ -7814,45 +5507,46 @@ no_blockarg(NODE *node)
}
static NODE *
-ret_args(NODE *node)
+ret_args(node)
+ NODE *node;
{
if (node) {
no_blockarg(node);
- if (nd_type(node) == NODE_ARRAY) {
- if (node->nd_next == 0) {
- node = node->nd_head;
- }
- else {
- nd_set_type(node, NODE_VALUES);
- }
+ if (nd_type(node) == NODE_ARRAY && node->nd_next == 0) {
+ node = node->nd_head;
+ }
+ if (node && nd_type(node) == NODE_SPLAT) {
+ node = NEW_SVALUE(node);
}
}
return node;
}
static NODE *
-new_yield(NODE *node)
+new_yield(node)
+ NODE *node;
{
long state = Qtrue;
if (node) {
- no_blockarg(node);
- if (nd_type(node) == NODE_ARRAY && node->nd_next == 0) {
- node = node->nd_head;
- state = Qfalse;
- }
- else if (node && nd_type(node) == NODE_SPLAT) {
- state = Qtrue;
- }
+ no_blockarg(node);
+ if (nd_type(node) == NODE_ARRAY && node->nd_next == 0) {
+ node = node->nd_head;
+ state = Qfalse;
+ }
+ if (node && nd_type(node) == NODE_SPLAT) {
+ state = Qtrue;
+ }
}
else {
- state = Qfalse;
+ state = Qfalse;
}
return NEW_YIELD(node, state);
}
static NODE*
-negate_lit(NODE *node)
+negate_lit(node)
+ NODE *node;
{
switch (TYPE(node->nd_lit)) {
case T_FIXNUM:
@@ -7871,7 +5565,9 @@ negate_lit(NODE *node)
}
static NODE *
-arg_blk_pass(NODE *node1, NODE *node2)
+arg_blk_pass(node1, node2)
+ NODE *node1;
+ NODE *node2;
{
if (node2) {
node2->nd_head = node1;
@@ -7880,71 +5576,75 @@ arg_blk_pass(NODE *node1, NODE *node2)
return node1;
}
-static int
-arg_dup_check(ID vid, VALUE m, VALUE list, NODE *node)
+static NODE*
+arg_prepend(node1, node2)
+ NODE *node1, *node2;
{
- VALUE sym;
+ switch (nd_type(node2)) {
+ case NODE_ARRAY:
+ return list_concat(NEW_LIST(node1), node2);
- if (!vid) return 0;
- if (is_junk_id(vid)) return 0;
- sym = ID2SYM(vid);
- if ((m && rb_ary_includes(m, sym)) || rb_ary_includes(list, sym)) {
- ruby_sourceline = nd_line(node);
- return 1;
+ case NODE_SPLAT:
+ return arg_concat(node1, node2->nd_head);
+
+ case NODE_BLOCK_PASS:
+ node2->nd_body = arg_prepend(node1, node2->nd_body);
+ return node2;
+
+ default:
+ rb_bug("unknown nodetype(%d) for arg_prepend", nd_type(node2));
}
- rb_ary_push(list, sym);
- return 0;
+ return 0; /* not reached */
}
static NODE*
-new_args_gen(struct parser_params *parser, VALUE m, NODE *o, NODE *r, NODE *p, NODE *b)
+new_call(r,m,a)
+ NODE *r;
+ ID m;
+ NODE *a;
{
- int saved_line = ruby_sourceline;
- NODE *node;
- VALUE list;
-
- list = rb_ary_new();
- node = o;
- while (node) {
- if (!node->nd_head) break;
- if (arg_dup_check(node->nd_head->nd_vid, m, list, node)) {
- yyerror("duplicated optional argument name");
- return 0;
- }
- node = node->nd_next;
- }
- if (RTEST(r)) {
- if (arg_dup_check(r->nd_vid, m, list, r)) {
- yyerror("duplicated rest argument name");
- return 0;
- }
+ if (a && nd_type(a) == NODE_BLOCK_PASS) {
+ a->nd_iter = NEW_CALL(r,m,a->nd_head);
+ return a;
}
- if (p) {
- node = p;
- while (node) {
- if (!node->nd_head) break;
- if (arg_dup_check(node->nd_head->nd_vid, m, list, node)) {
- yyerror("duplicated argument name");
- return 0;
- }
- node = node->nd_next;
- }
- r = NEW_POSTARG(r, p);
+ return NEW_CALL(r,m,a);
+}
+
+static NODE*
+new_fcall(m,a)
+ ID m;
+ NODE *a;
+{
+ if (a && nd_type(a) == NODE_BLOCK_PASS) {
+ a->nd_iter = NEW_FCALL(m,a->nd_head);
+ return a;
}
- node = NEW_ARGS(m, o, r);
- if (b) {
- if (arg_dup_check(b->nd_vid, m, list, b)) {
- yyerror("duplicated block argument name");
- return 0;
- }
- node = block_append(node, b);
+ return NEW_FCALL(m,a);
+}
+
+static NODE*
+new_super(a)
+ NODE *a;
+{
+ if (a && nd_type(a) == NODE_BLOCK_PASS) {
+ a->nd_iter = NEW_SUPER(a->nd_head);
+ return a;
}
- ruby_sourceline = saved_line;
- return node;
+ return NEW_SUPER(a);
}
+static struct local_vars {
+ ID *tbl;
+ int nofree;
+ int cnt;
+ int dlev;
+ struct RVarmap* dyna_vars;
+ struct local_vars *prev;
+} *lvtbl;
+
static void
-local_push_gen(struct parser_params *parser, int top)
+local_push(top)
+ int top;
{
struct local_vars *local;
@@ -7954,8 +5654,6 @@ local_push_gen(struct parser_params *parser, int top)
local->cnt = 0;
local->tbl = 0;
local->dlev = 0;
- local->dname_size = 0;
- local->dnames = 0;
local->dyna_vars = ruby_dyna_vars;
lvtbl = local;
if (!top) {
@@ -7966,7 +5664,7 @@ local_push_gen(struct parser_params *parser, int top)
}
static void
-local_pop_gen(struct parser_params *parser)
+local_pop()
{
struct local_vars *local = lvtbl->prev;
@@ -7974,23 +5672,21 @@ local_pop_gen(struct parser_params *parser)
if (!lvtbl->nofree) xfree(lvtbl->tbl);
else lvtbl->tbl[0] = lvtbl->cnt;
}
- if (lvtbl->dnames) {
- xfree(lvtbl->dnames);
- }
ruby_dyna_vars = lvtbl->dyna_vars;
xfree(lvtbl);
lvtbl = local;
}
static ID*
-local_tbl_gen(struct parser_params *parser)
+local_tbl()
{
lvtbl->nofree = 1;
return lvtbl->tbl;
}
static int
-local_append_gen(struct parser_params *parser, ID id)
+local_append(id)
+ ID id;
{
if (lvtbl->tbl == 0) {
lvtbl->tbl = ALLOC_N(ID, 4);
@@ -8010,7 +5706,8 @@ local_append_gen(struct parser_params *parser, ID id)
}
static int
-local_cnt_gen(struct parser_params *parser, ID id)
+local_cnt(id)
+ ID id;
{
int cnt, max;
@@ -8023,7 +5720,8 @@ local_cnt_gen(struct parser_params *parser, ID id)
}
static int
-local_id_gen(struct parser_params *parser, ID id)
+local_id(id)
+ ID id;
{
int i, max;
@@ -8035,7 +5733,7 @@ local_id_gen(struct parser_params *parser, ID id)
}
static void
-top_local_init_gen(struct parser_params *parser)
+top_local_init()
{
local_push(1);
lvtbl->cnt = ruby_scope->local_tbl?ruby_scope->local_tbl[0]:0;
@@ -8053,7 +5751,7 @@ top_local_init_gen(struct parser_params *parser)
}
static void
-top_local_setup_gen(struct parser_params *parser)
+top_local_setup()
{
int len = lvtbl->cnt;
int i;
@@ -8070,7 +5768,7 @@ top_local_setup_gen(struct parser_params *parser)
rb_mem_clear(vars+i, len-i);
}
else {
- *vars++ = (VALUE)ruby_scope;
+ *vars++ = 0;
rb_mem_clear(vars, len);
}
ruby_scope->local_vars = vars;
@@ -8083,48 +5781,36 @@ top_local_setup_gen(struct parser_params *parser)
rb_mem_clear(ruby_scope->local_vars+i, len-i);
}
if (ruby_scope->local_tbl && ruby_scope->local_vars[-1] == 0) {
- xfree(ruby_scope->local_tbl);
+ 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();
}
}
local_pop();
}
-static void
-dyna_var_gen(struct parser_params *parser, ID id)
-{
- int i;
+#define DVAR_USED FL_USER6
- rb_dvar_push(id, Qnil);
- for (i=0; i<lvtbl->dname_size; i++) {
- if (lvtbl->dnames[i] == id) return;
- }
- if (lvtbl->dname_size == 0) {
- lvtbl->dnames = ALLOC_N(ID, 1);
- }
- else {
- REALLOC_N(lvtbl->dnames, ID, lvtbl->dname_size+1);
- }
- lvtbl->dnames[lvtbl->dname_size++] = id;
-}
-
-static void
-dyna_check_gen(struct parser_params *parser, ID id)
+static VALUE
+dyna_var_lookup(id)
+ ID id;
{
- int i;
+ struct RVarmap *vars = ruby_dyna_vars;
- if (in_defined) return; /* no check needed */
- for (i=0; i<lvtbl->dname_size; i++) {
- if (lvtbl->dnames[i] == id) {
- rb_warnS("out-of-scope variable - %s", rb_id2name(id));
- return;
+ while (vars) {
+ if (vars->id == id) {
+ FL_SET(vars, DVAR_USED);
+ return Qtrue;
}
+ vars = vars->next;
}
+ return Qfalse;
}
static struct RVarmap*
-dyna_push_gen(struct parser_params *parser)
+dyna_push()
{
struct RVarmap* vars = ruby_dyna_vars;
@@ -8134,79 +5820,96 @@ dyna_push_gen(struct parser_params *parser)
}
static void
-dyna_pop_gen(struct parser_params *parser, struct RVarmap* vars)
+dyna_pop(vars)
+ struct RVarmap* vars;
{
lvtbl->dlev--;
ruby_dyna_vars = vars;
}
+static int
+dyna_in_block()
+{
+ return (lvtbl->dlev > 0);
+}
+
static NODE *
-dyna_init_gen(struct parser_params *parser, NODE *node, struct RVarmap *pre)
+dyna_init(node, pre)
+ NODE *node;
+ struct RVarmap *pre;
{
struct RVarmap *post = ruby_dyna_vars;
NODE *var;
if (!node || !post || pre == post) return node;
for (var = 0; post != pre && post->id; post = post->next) {
- var = NEW_DASGN_CURR(post->id, var);
+ if (FL_TEST(post, DVAR_USED)) {
+ var = NEW_DASGN_CURR(post->id, var);
+ }
}
return block_append(var, node);
}
-void
-rb_gc_mark_parser(void)
+int
+ruby_parser_stack_on_heap()
{
+#if defined(YYMALLOC)
+ return Qfalse;
+#else
+ return Qtrue;
+#endif
}
-NODE*
-rb_parser_append_print(NODE *node)
+void
+rb_gc_mark_parser()
{
- NODE *prelude = 0;
+#if defined YYMALLOC
+ rb_gc_mark((VALUE)parser_heap);
+#elif defined yystacksize
+ if (yyvsp) rb_gc_mark_locations((VALUE *)yyvs, (VALUE *)yyvsp);
+#endif
- if (node && (nd_type(node) == NODE_PRELUDE)) {
- prelude = node;
- node = node->nd_body;
- }
- node = block_append(node,
- NEW_FCALL(rb_intern("print"),
- NEW_ARRAY(NEW_GVAR(rb_intern("$_")))));
- if (prelude) {
- prelude->nd_body = node;
- return prelude;
- }
- return node;
+ if (!ruby_in_compile) return;
+
+ rb_gc_mark_maybe((VALUE)yylval.node);
+ rb_gc_mark(ruby_debug_lines);
+ rb_gc_mark(lex_lastline);
+ rb_gc_mark(lex_input);
+ rb_gc_mark((VALUE)lex_strterm);
+ rb_gc_mark((VALUE)deferred_nodes);
}
-NODE *
-rb_parser_while_loop(NODE *node, int chop, int split)
+void
+rb_parser_append_print()
{
- NODE *prelude = 0;
+ ruby_eval_tree =
+ block_append(ruby_eval_tree,
+ NEW_FCALL(rb_intern("print"),
+ NEW_ARRAY(NEW_GVAR(rb_intern("$_")))));
+}
- if (node && (nd_type(node) == NODE_PRELUDE)) {
- prelude = node;
- node = node->nd_body;
- }
+void
+rb_parser_while_loop(chop, split)
+ int chop, split;
+{
if (split) {
- node = block_append(NEW_GASGN(rb_intern("$F"),
- NEW_CALL(NEW_GVAR(rb_intern("$_")),
- rb_intern("split"), 0)),
- node);
+ ruby_eval_tree =
+ block_append(NEW_GASGN(rb_intern("$F"),
+ NEW_CALL(NEW_GVAR(rb_intern("$_")),
+ rb_intern("split"), 0)),
+ ruby_eval_tree);
}
if (chop) {
- node = block_append(NEW_CALL(NEW_GVAR(rb_intern("$_")),
- rb_intern("chop!"), 0), node);
- }
- node = NEW_OPT_N(node);
- if (prelude) {
- prelude->nd_body = node;
- return prelude;
+ ruby_eval_tree =
+ block_append(NEW_CALL(NEW_GVAR(rb_intern("$_")),
+ rb_intern("chop!"), 0), ruby_eval_tree);
}
- return node;
+ ruby_eval_tree = NEW_OPT_N(ruby_eval_tree);
}
-static const struct {
+static struct {
ID token;
- const char *name;
+ char *name;
} op_tbl[] = {
{tDOT2, ".."},
{tDOT3, "..."},
@@ -8250,38 +5953,27 @@ static const struct {
{0, 0}
};
-static struct symbols {
- ID last_id;
- st_table *sym_id;
- st_table *id_sym;
-} global_symbols = {tLAST_TOKEN};
-
-static struct st_hash_type symhash = {
- rb_str_cmp,
- rb_str_hash,
-};
+static st_table *sym_tbl;
+static st_table *sym_rev_tbl;
void
-Init_sym(void)
+Init_sym()
{
- global_symbols.sym_id = st_init_table_with_size(&symhash, 1000);
- global_symbols.id_sym = st_init_numtable_with_size(1000);
+ sym_tbl = st_init_strtable_with_size(200);
+ sym_rev_tbl = st_init_numtable_with_size(200);
}
-void
-rb_gc_mark_symbols(void)
-{
- rb_mark_tbl(global_symbols.id_sym);
-}
+static ID last_id = tLAST_TOKEN;
static ID
-internal_id(void)
+internal_id()
{
- return ID_INTERNAL | (++global_symbols.last_id << ID_SCOPE_SHIFT);
+ return ID_INTERNAL | (++last_id << ID_SCOPE_SHIFT);
}
static int
-is_special_global_name(const char *m)
+is_special_global_name(m)
+ const char *m;
{
switch (*m) {
case '~': case '*': case '$': case '?': case '!': case '@':
@@ -8303,7 +5995,8 @@ is_special_global_name(const char *m)
}
int
-rb_symname_p(const char *name)
+rb_symname_p(name)
+ const char *name;
{
const char *m = name;
int localid = Qfalse;
@@ -8381,23 +6074,23 @@ rb_sym_interned_p(str)
{
ID id;
- if (st_lookup(global_symbols.sym_id, (st_data_t)str, (st_data_t *)&id))
+ if (st_lookup(sym_tbl, (st_data_t)RSTRING(str)->ptr, (st_data_t *)&id))
return Qtrue;
return Qfalse;
}
ID
-rb_intern2(const char *name, long len)
+rb_intern(name)
+ const char *name;
{
const char *m = name;
- VALUE sym = rb_str_new(name, len);
ID id;
int last;
- if (st_lookup(global_symbols.sym_id, (st_data_t)sym, (st_data_t *)&id))
+ if (st_lookup(sym_tbl, (st_data_t)name, (st_data_t *)&id))
return id;
- last = len-1;
+ last = strlen(name)-1;
id = 0;
switch (*name) {
case '$':
@@ -8423,7 +6116,7 @@ rb_intern2(const char *name, long len)
if (*op_tbl[i].name == *name &&
strcmp(op_tbl[i].name, name) == 0) {
id = op_tbl[i].token;
- goto id_register;
+ goto id_regist;
}
}
}
@@ -8437,13 +6130,13 @@ rb_intern2(const char *name, long len)
id = rb_intern(buf);
if (id > tLAST_TOKEN && !is_attrset_id(id)) {
id = rb_id_attrset(id);
- goto id_register;
+ goto id_regist;
}
id = ID_ATTRSET;
}
else if (ISUPPER(name[0])) {
id = ID_CONST;
- }
+ }
else {
id = ID_LOCAL;
}
@@ -8456,53 +6149,23 @@ rb_intern2(const char *name, long len)
}
if (*m) id = ID_JUNK;
new_id:
- id |= ++global_symbols.last_id << ID_SCOPE_SHIFT;
- id_register:
- RBASIC(sym)->klass = rb_cSymbol;
- OBJ_FREEZE(sym);
- st_add_direct(global_symbols.sym_id, (st_data_t)sym, id);
- st_add_direct(global_symbols.id_sym, id, (st_data_t)sym);
+ id |= ++last_id << ID_SCOPE_SHIFT;
+ id_regist:
+ name = strdup(name);
+ st_add_direct(sym_tbl, (st_data_t)name, id);
+ st_add_direct(sym_rev_tbl, id, (st_data_t)name);
return id;
}
-ID
-rb_intern(const char *name)
-{
- return rb_intern2(name, strlen(name));
-}
-
-VALUE
-rb_id2sym(ID id)
-{
- VALUE data;
-
- while (!st_lookup(global_symbols.id_sym, id, &data)) {
- rb_id2name(id);
- }
- if (!RBASIC(data)->klass) {
- RBASIC(data)->klass = rb_cSymbol;
- }
- return data;
-}
-
-ID
-rb_sym2id(VALUE sym)
-{
- ID data;
-
- if (st_lookup(global_symbols.sym_id, sym, &data))
- return data;
- return rb_intern2(RSTRING_PTR(sym), RSTRING_LEN(sym));
-}
-
-const char *
-rb_id2name(ID id)
+char *
+rb_id2name(id)
+ ID id;
{
- const char *name;
+ char *name;
st_data_t data;
if (id < tLAST_TOKEN) {
- int i = 0;
+ int i;
for (i=0; op_tbl[i].token; i++) {
if (op_tbl[i].token == id)
@@ -8510,8 +6173,8 @@ rb_id2name(ID id)
}
}
- if (st_lookup(global_symbols.id_sym, id, &data))
- return RSTRING_PTR(data);
+ if (st_lookup(sym_rev_tbl, id, &data))
+ return (char *)data;
if (is_attrset_id(id)) {
ID id2 = (id & ~ID_SCOPE_MASK) | ID_LOCAL;
@@ -8535,12 +6198,12 @@ rb_id2name(ID id)
}
static int
-symbols_i(VALUE sym, ID value, VALUE ary)
+symbols_i(key, value, ary)
+ char *key;
+ ID value;
+ VALUE ary;
{
- if (!RBASIC(sym)->klass) {
- RBASIC(sym)->klass = rb_cSymbol;
- }
- rb_ary_push(ary, sym);
+ rb_ary_push(ary, ID2SYM(value));
return ST_CONTINUE;
}
@@ -8561,57 +6224,61 @@ symbols_i(VALUE sym, ID value, VALUE ary)
*/
VALUE
-rb_sym_all_symbols(void)
+rb_sym_all_symbols()
{
- VALUE ary = rb_ary_new2(global_symbols.sym_id->num_entries);
+ VALUE ary = rb_ary_new2(sym_tbl->num_entries);
- st_foreach(global_symbols.sym_id, symbols_i, ary);
+ st_foreach(sym_tbl, symbols_i, ary);
return ary;
}
int
-rb_is_const_id(ID id)
+rb_is_const_id(id)
+ ID id;
{
if (is_const_id(id)) return Qtrue;
return Qfalse;
}
int
-rb_is_class_id(ID id)
+rb_is_class_id(id)
+ ID id;
{
if (is_class_id(id)) return Qtrue;
return Qfalse;
}
int
-rb_is_instance_id(ID id)
+rb_is_instance_id(id)
+ ID id;
{
if (is_instance_id(id)) return Qtrue;
return Qfalse;
}
int
-rb_is_local_id(ID id)
+rb_is_local_id(id)
+ ID id;
{
if (is_local_id(id)) return Qtrue;
return Qfalse;
}
int
-rb_is_junk_id(ID id)
+rb_is_junk_id(id)
+ ID id;
{
if (is_junk_id(id)) return Qtrue;
return Qfalse;
}
static void
-special_local_set(char c, VALUE val)
+special_local_set(c, val)
+ char c;
+ VALUE val;
{
- VALUE volatile vparser = rb_parser_new();
- struct parser_params *parser;
int cnt;
-
- Data_Get_Struct(vparser, struct parser_params, parser);
+
top_local_init();
cnt = local_cnt(c);
top_local_setup();
@@ -8619,7 +6286,7 @@ special_local_set(char c, VALUE val)
}
VALUE
-rb_backref_get(void)
+rb_backref_get()
{
VALUE *var = rb_svar(1);
if (var) {
@@ -8629,7 +6296,8 @@ rb_backref_get(void)
}
void
-rb_backref_set(VALUE val)
+rb_backref_set(val)
+ VALUE val;
{
VALUE *var = rb_svar(1);
if (var) {
@@ -8641,7 +6309,7 @@ rb_backref_set(VALUE val)
}
VALUE
-rb_lastline_get(void)
+rb_lastline_get()
{
VALUE *var = rb_svar(0);
if (var) {
@@ -8651,7 +6319,8 @@ rb_lastline_get(void)
}
void
-rb_lastline_set(VALUE val)
+rb_lastline_set(val)
+ VALUE val;
{
VALUE *var = rb_svar(0);
if (var) {
@@ -8661,136 +6330,16 @@ rb_lastline_set(VALUE val)
special_local_set('_', val);
}
}
-#endif /* !RIPPER */
-
-static void
-parser_initialize(struct parser_params *parser)
-{
- parser->eofp = Qfalse;
-
- parser->parser_lex_strterm = 0;
- parser->parser_cond_stack = 0;
- parser->parser_cmdarg_stack = 0;
- parser->parser_class_nest = 0;
- parser->parser_paren_nest = 0;
- parser->parser_lpar_beg = 0;
- parser->parser_in_single = 0;
- parser->parser_in_def = 0;
- parser->parser_in_defined = 0;
- parser->parser_compile_for_eval = 0;
- parser->parser_cur_mid = 0;
- parser->parser_tokenbuf = NULL;
- parser->parser_tokidx = 0;
- parser->parser_toksiz = 0;
- parser->parser_heredoc_end = 0;
- parser->parser_command_start = Qtrue;
- parser->parser_lex_pbeg = 0;
- parser->parser_lex_p = 0;
- parser->parser_lex_pend = 0;
- parser->parser_lvtbl = 0;
- parser->parser_ruby__end__seen = 0;
-#ifndef RIPPER
- parser->parser_eval_tree_begin = 0;
- parser->parser_eval_tree = 0;
-#else
- parser->parser_ruby_sourcefile = Qnil;
- parser->delayed = Qnil;
-
- parser->result = Qnil;
- parser->parsing_thread = Qnil;
- parser->toplevel_p = Qtrue;
-#endif
-#ifdef YYMALLOC
- parser->heap = NULL;
-#endif
-}
-
-static void
-parser_mark(void *ptr)
-{
- struct parser_params *p = (struct parser_params*)ptr;
-
- rb_gc_mark((VALUE)p->parser_lex_strterm);
- rb_gc_mark(p->parser_lex_input);
- rb_gc_mark(p->parser_lex_lastline);
-#ifndef RIPPER
- rb_gc_mark((VALUE)p->parser_eval_tree_begin) ;
- rb_gc_mark((VALUE)p->parser_eval_tree) ;
- rb_gc_mark(p->debug_lines);
-#else
- rb_gc_mark(p->parser_ruby_sourcefile);
- rb_gc_mark(p->delayed);
- rb_gc_mark(p->value);
- rb_gc_mark(p->result);
- rb_gc_mark(p->parsing_thread);
-#endif
-#ifdef YYMALLOC
- rb_gc_mark((VALUE)p->heap);
-#endif
-}
-
-static void
-parser_free(void *ptr)
-{
- struct parser_params *p = (struct parser_params*)ptr;
- struct local_vars *local, *prev;
-
- if (p->parser_tokenbuf) {
- xfree(p->parser_tokenbuf);
- }
- for (local = p->parser_lvtbl; local; local = prev) {
- if (local->tbl && !local->nofree)
- xfree(local->tbl);
- prev = local->prev;
- xfree(local);
- }
- xfree(p);
-}
-
-#ifndef RIPPER
-static struct parser_params *
-parser_new(void)
-{
- struct parser_params *p;
-
- p = ALLOC_N(struct parser_params, 1);
- MEMZERO(p, struct parser_params, 1);
- parser_initialize(p);
- return p;
-}
-
-VALUE
-rb_parser_new(void)
-{
- struct parser_params *p = parser_new();
-
- return Data_Wrap_Struct(0, parser_mark, parser_free, p);
-}
-
-/*
- * call-seq:
- * ripper#end_seen? -> Boolean
- *
- * Return if parsed source ended by +\_\_END\_\_+.
- * This number starts from 1.
- */
-VALUE
-rb_parser_end_seen_p(VALUE vparser)
-{
- struct parser_params *parser;
-
- Data_Get_Struct(vparser, struct parser_params, parser);
- return ruby__end__seen ? Qtrue : Qfalse;
-}
#ifdef YYMALLOC
#define HEAPCNT(n, size) ((n) * (size) / sizeof(YYSTYPE))
-#define NEWHEAP() rb_node_newnode(NODE_ALLOCA, 0, (VALUE)parserp->heap, 0)
-#define ADD2HEAP(n, c, p) ((parserp->heap = (n))->u1.node = (p), \
+#define NEWHEAP() rb_node_newnode(NODE_ALLOCA, 0, (VALUE)parser_heap, 0)
+#define ADD2HEAP(n, c, p) ((parser_heap = (n))->u1.node = (p), \
(n)->u3.cnt = (c), (p))
-void *
-rb_parser_malloc(struct parser_params *parserp, size_t size)
+static void *
+rb_parser_malloc(size)
+ size_t size;
{
size_t cnt = HEAPCNT(1, size);
NODE *n = NEWHEAP();
@@ -8799,8 +6348,9 @@ rb_parser_malloc(struct parser_params *parserp, size_t size)
return ADD2HEAP(n, cnt, ptr);
}
-void *
-rb_parser_calloc(struct parser_params *parserp, size_t nelem, size_t size)
+static void *
+rb_parser_calloc(nelem, size)
+ size_t nelem, size;
{
size_t cnt = HEAPCNT(nelem, size);
NODE *n = NEWHEAP();
@@ -8809,13 +6359,15 @@ rb_parser_calloc(struct parser_params *parserp, size_t nelem, size_t size)
return ADD2HEAP(n, cnt, ptr);
}
-void *
-rb_parser_realloc(struct parser_params *parserp, void *ptr, size_t size)
+static void *
+rb_parser_realloc(ptr, size)
+ void *ptr;
+ size_t size;
{
NODE *n;
size_t cnt = HEAPCNT(1, size);
- if (ptr && (n = parserp->heap) != NULL) {
+ if (ptr && (n = parser_heap) != NULL) {
do {
if (n->u1.node == ptr) {
n->u1.node = ptr = xrealloc(ptr, size);
@@ -8829,12 +6381,13 @@ rb_parser_realloc(struct parser_params *parserp, void *ptr, size_t size)
return ADD2HEAP(n, cnt, ptr);
}
-void
-rb_parser_free(struct parser_params *parserp, void *ptr)
+static void
+rb_parser_free(ptr)
+ void *ptr;
{
- NODE **prev = &parserp->heap, *n;
+ NODE **prev = &parser_heap, *n;
- while ((n = *prev) != NULL) {
+ while ((n = *prev) != 0) {
if (n->u1.node == ptr) {
*prev = n->u2.node;
rb_gc_force_recycle((VALUE)n);
@@ -8845,474 +6398,3 @@ rb_parser_free(struct parser_params *parserp, void *ptr)
xfree(ptr);
}
#endif
-#endif
-
-#ifdef RIPPER
-#ifdef RIPPER_DEBUG
-extern int rb_is_pointer_to_heap(VALUE);
-
-/* :nodoc: */
-static VALUE
-ripper_validate_object(VALUE self, VALUE x)
-{
- if (x == Qfalse) return x;
- if (x == Qtrue) return x;
- if (x == Qnil) return x;
- if (x == Qundef)
- rb_raise(rb_eArgError, "Qundef given");
- if (FIXNUM_P(x)) return x;
- if (SYMBOL_P(x)) return x;
- if (!rb_is_pointer_to_heap(x))
- rb_raise(rb_eArgError, "invalid pointer: %p", x);
- switch (TYPE(x)) {
- case T_STRING:
- case T_OBJECT:
- case T_ARRAY:
- case T_BIGNUM:
- case T_FLOAT:
- return x;
- case T_NODE:
- rb_raise(rb_eArgError, "NODE given: %p", x);
- default:
- rb_raise(rb_eArgError, "wrong type of ruby object: %p (%s)",
- x, rb_obj_classname(x));
- }
- return x;
-}
-#endif
-
-#define validate(x)
-
-static VALUE
-ripper_dispatch0(struct parser_params *parser, ID mid)
-{
- return rb_funcall(parser->value, mid, 0);
-}
-
-static VALUE
-ripper_dispatch1(struct parser_params *parser, ID mid, VALUE a)
-{
- validate(a);
- return rb_funcall(parser->value, mid, 1, a);
-}
-
-static VALUE
-ripper_dispatch2(struct parser_params *parser, ID mid, VALUE a, VALUE b)
-{
- validate(a);
- validate(b);
- return rb_funcall(parser->value, mid, 2, a, b);
-}
-
-static VALUE
-ripper_dispatch3(struct parser_params *parser, ID mid, VALUE a, VALUE b, VALUE c)
-{
- validate(a);
- validate(b);
- validate(c);
- return rb_funcall(parser->value, mid, 3, a, b, c);
-}
-
-static VALUE
-ripper_dispatch4(struct parser_params *parser, ID mid, VALUE a, VALUE b, VALUE c, VALUE d)
-{
- validate(a);
- validate(b);
- validate(c);
- validate(d);
- return rb_funcall(parser->value, mid, 4, a, b, c, d);
-}
-
-static VALUE
-ripper_dispatch5(struct parser_params *parser, ID mid, VALUE a, VALUE b, VALUE c, VALUE d, VALUE e)
-{
- validate(a);
- validate(b);
- validate(c);
- validate(d);
- validate(e);
- return rb_funcall(parser->value, mid, 5, a, b, c, d, e);
-}
-
-static struct kw_assoc {
- ID id;
- const char *name;
-} keyword_to_name[] = {
- {keyword_class, "class"},
- {keyword_module, "module"},
- {keyword_def, "def"},
- {keyword_undef, "undef"},
- {keyword_begin, "begin"},
- {keyword_rescue, "rescue"},
- {keyword_ensure, "ensure"},
- {keyword_end, "end"},
- {keyword_if, "if"},
- {keyword_unless, "unless"},
- {keyword_then, "then"},
- {keyword_elsif, "elsif"},
- {keyword_else, "else"},
- {keyword_case, "case"},
- {keyword_when, "when"},
- {keyword_while, "while"},
- {keyword_until, "until"},
- {keyword_for, "for"},
- {keyword_break, "break"},
- {keyword_next, "next"},
- {keyword_redo, "redo"},
- {keyword_retry, "retry"},
- {keyword_in, "in"},
- {keyword_do, "do"},
- {keyword_do_cond, "do"},
- {keyword_do_block, "do"},
- {keyword_return, "return"},
- {keyword_yield, "yield"},
- {keyword_super, "super"},
- {keyword_self, "self"},
- {keyword_nil, "nil"},
- {keyword_true, "true"},
- {keyword_false, "false"},
- {keyword_and, "and"},
- {keyword_or, "or"},
- {keyword_not, "not"},
- {modifier_if, "if"},
- {modifier_unless, "unless"},
- {modifier_while, "while"},
- {modifier_until, "until"},
- {modifier_rescue, "rescue"},
- {keyword_alias, "alias"},
- {keyword_defined, "defined?"},
- {keyword_BEGIN, "BEGIN"},
- {keyword_END, "END"},
- {keyword__LINE__, "__LINE__"},
- {keyword__FILE__, "__FILE__"},
- {0, NULL}
-};
-
-static const char*
-keyword_id_to_str(ID id)
-{
- struct kw_assoc *a;
-
- for (a = keyword_to_name; a->id; a++) {
- if (a->id == id)
- return a->name;
- }
- return NULL;
-}
-
-static VALUE
-ripper_id2sym(ID id)
-{
- const char *name;
- char buf[8];
-
- if (id <= 256) {
- buf[0] = id;
- buf[1] = '\0';
- return ID2SYM(rb_intern(buf));
- }
- if ((name = keyword_id_to_str(id))) {
- return ID2SYM(rb_intern(name));
- }
- switch (id) {
- case tOROP:
- name = "||";
- break;
- case tANDOP:
- name = "&&";
- break;
- default:
- name = rb_id2name(id);
- if (!name) {
- rb_bug("cannot convert ID to string: %ld", (unsigned long)id);
- }
- break;
- }
- return ID2SYM(rb_intern(name));
-}
-
-static VALUE
-ripper_intern(const char *s)
-{
- return ID2SYM(rb_intern(s));
-}
-
-static void
-ripper_compile_error(struct parser_params *parser, const char *fmt, ...)
-{
- VALUE str;
- va_list args;
-
- va_start(args, fmt);
- str = rb_vsprintf(fmt, args);
- va_end(args);
- rb_funcall(parser->value, rb_intern("compile_error"), 1, str);
-}
-
-static void
-ripper_warn0(struct parser_params *parser, const char *fmt)
-{
- rb_funcall(parser->value, rb_intern("warn"), 1, rb_str_new2(fmt));
-}
-
-static void
-ripper_warnI(struct parser_params *parser, const char *fmt, int a)
-{
- rb_funcall(parser->value, rb_intern("warn"), 2,
- rb_str_new2(fmt), INT2NUM(a));
-}
-
-static void
-ripper_warnS(struct parser_params *parser, const char *fmt, const char *str)
-{
- rb_funcall(parser->value, rb_intern("warn"), 2,
- rb_str_new2(fmt), rb_str_new2(str));
-}
-
-static void
-ripper_warning0(struct parser_params *parser, const char *fmt)
-{
- rb_funcall(parser->value, rb_intern("warning"), 1, rb_str_new2(fmt));
-}
-
-static void
-ripper_warningS(struct parser_params *parser, const char *fmt, const char *str)
-{
- rb_funcall(parser->value, rb_intern("warning"), 2,
- rb_str_new2(fmt), rb_str_new2(str));
-}
-
-static VALUE
-ripper_lex_get_generic(struct parser_params *parser, VALUE src)
-{
- return rb_funcall(src, ripper_id_gets, 0);
-}
-
-static VALUE
-ripper_s_allocate(VALUE klass)
-{
- struct parser_params *p;
- VALUE self;
-
- p = ALLOC_N(struct parser_params, 1);
- MEMZERO(p, struct parser_params, 1);
- self = Data_Wrap_Struct(klass, parser_mark, parser_free, p);
- p->value = self;
- return self;
-}
-
-#define ripper_initialized_p(r) ((r)->parser_lex_input != 0)
-
-/*
- * call-seq:
- * Ripper.new(src, filename="(ripper)", lineno=1) -> ripper
- *
- * Create a new Ripper object.
- * _src_ must be a String, a IO, or an Object which has #gets method.
- *
- * This method does not starts parsing.
- * See also Ripper#parse and Ripper.parse.
- */
-static VALUE
-ripper_initialize(int argc, VALUE *argv, VALUE self)
-{
- struct parser_params *parser;
- VALUE src, fname, lineno;
-
- Data_Get_Struct(self, struct parser_params, parser);
- rb_scan_args(argc, argv, "12", &src, &fname, &lineno);
- if (rb_obj_respond_to(src, ripper_id_gets, 0)) {
- parser->parser_lex_gets = ripper_lex_get_generic;
- }
- else {
- StringValue(src);
- parser->parser_lex_gets = lex_get_str;
- }
- parser->parser_lex_input = src;
- parser->eofp = Qfalse;
- if (NIL_P(fname)) {
- fname = rb_str_new2("(ripper)");
- }
- else {
- StringValue(fname);
- }
- parser_initialize(parser);
- parser->parser_ruby_sourcefile = fname;
- parser->parser_ruby_sourceline = NIL_P(lineno) ? 0 : NUM2INT(lineno) - 1;
-
- return Qnil;
-}
-
-/*
- * call-seq:
- * Ripper.yydebug -> true or false
- *
- * Get yydebug.
- */
-static VALUE
-ripper_s_get_yydebug(VALUE self)
-{
- return ripper_yydebug ? Qtrue : Qfalse;
-}
-
-/*
- * call-seq:
- * Ripper.yydebug = flag
- *
- * Set yydebug.
- */
-static VALUE
-ripper_s_set_yydebug(VALUE self, VALUE flag)
-{
- ripper_yydebug = RTEST(flag);
- return flag;
-}
-
-extern VALUE rb_thread_pass(void);
-
-struct ripper_args {
- struct parser_params *parser;
- int argc;
- VALUE *argv;
-};
-
-static VALUE
-ripper_parse0(VALUE parser_v)
-{
- struct parser_params *parser;
-
- Data_Get_Struct(parser_v, struct parser_params, parser);
- parser_prepare(parser);
- ripper_yyparse((void*)parser);
- return parser->result;
-}
-
-static VALUE
-ripper_ensure(VALUE parser_v)
-{
- struct parser_params *parser;
-
- Data_Get_Struct(parser_v, struct parser_params, parser);
- parser->parsing_thread = Qnil;
- return Qnil;
-}
-
-/*
- * call-seq:
- * ripper#parse
- *
- * Start parsing and returns the value of the root action.
- */
-static VALUE
-ripper_parse(VALUE self)
-{
- struct parser_params *parser;
-
- Data_Get_Struct(self, struct parser_params, parser);
- if (!ripper_initialized_p(parser)) {
- rb_raise(rb_eArgError, "method called for uninitialized object");
- }
- if (!NIL_P(parser->parsing_thread)) {
- if (parser->parsing_thread == rb_thread_current())
- rb_raise(rb_eArgError, "Ripper#parse is not reentrant");
- else
- rb_raise(rb_eArgError, "Ripper#parse is not multithread-safe");
- }
- parser->parsing_thread = rb_thread_current();
- rb_ensure(ripper_parse0, self, ripper_ensure, self);
-
- return parser->result;
-}
-
-/*
- * call-seq:
- * ripper#column -> Integer
- *
- * Return column number of current parsing line.
- * This number starts from 0.
- */
-static VALUE
-ripper_column(VALUE self)
-{
- struct parser_params *parser;
- long col;
-
- Data_Get_Struct(self, struct parser_params, parser);
- if (!ripper_initialized_p(parser)) {
- rb_raise(rb_eArgError, "method called for uninitialized object");
- }
- if (NIL_P(parser->parsing_thread)) return Qnil;
- col = parser->tokp - parser->parser_lex_pbeg;
- return LONG2NUM(col);
-}
-
-/*
- * call-seq:
- * ripper#lineno -> Integer
- *
- * Return line number of current parsing line.
- * This number starts from 1.
- */
-static VALUE
-ripper_lineno(VALUE self)
-{
- struct parser_params *parser;
-
- Data_Get_Struct(self, struct parser_params, parser);
- if (!ripper_initialized_p(parser)) {
- rb_raise(rb_eArgError, "method called for uninitialized object");
- }
- if (NIL_P(parser->parsing_thread)) return Qnil;
- return INT2NUM(parser->parser_ruby_sourceline);
-}
-
-#ifdef RIPPER_DEBUG
-/* :nodoc: */
-static VALUE
-ripper_assert_Qundef(VALUE self, VALUE obj, VALUE msg)
-{
- StringValue(msg);
- if (obj == Qundef) {
- rb_raise(rb_eArgError, "%s", RSTRING_PTR(msg));
- }
- return Qnil;
-}
-
-/* :nodoc: */
-static VALUE
-ripper_value(VALUE self, VALUE obj)
-{
- return ULONG2NUM(obj);
-}
-#endif
-
-void
-Init_ripper(void)
-{
- VALUE Ripper;
-
- Ripper = rb_define_class("Ripper", rb_cObject);
- rb_define_const(Ripper, "Version", rb_str_new2(RIPPER_VERSION));
- rb_define_singleton_method(Ripper, "yydebug", ripper_s_get_yydebug, 0);
- rb_define_singleton_method(Ripper, "yydebug=", ripper_s_set_yydebug, 1);
- rb_define_alloc_func(Ripper, ripper_s_allocate);
- rb_define_method(Ripper, "initialize", ripper_initialize, -1);
- rb_define_method(Ripper, "parse", ripper_parse, 0);
- rb_define_method(Ripper, "column", ripper_column, 0);
- rb_define_method(Ripper, "lineno", ripper_lineno, 0);
- rb_define_method(Ripper, "end_seen?", rb_parser_end_seen_p, 0);
-#ifdef RIPPER_DEBUG
- rb_define_method(rb_mKernel, "assert_Qundef", ripper_assert_Qundef, 2);
- rb_define_method(rb_mKernel, "rawVALUE", ripper_value, 1);
- rb_define_method(rb_mKernel, "validate_object", ripper_validate_object, 1);
-#endif
-
- ripper_id_gets = rb_intern("gets");
- ripper_init_eventids1(Ripper);
- ripper_init_eventids2(Ripper);
- /* ensure existing in symbol table */
- rb_intern("||");
- rb_intern("&&");
-}
-#endif /* RIPPER */
-
diff --git a/prec.c b/prec.c
index 80396dfdef..7b215fba09 100644
--- a/prec.c
+++ b/prec.c
@@ -32,7 +32,8 @@ static ID prc_pr, prc_if;
*/
static VALUE
-prec_prec(VALUE x, VALUE klass)
+prec_prec(x, klass)
+ VALUE x, klass;
{
return rb_funcall(klass, prc_if, 1, x);
}
@@ -46,7 +47,8 @@ prec_prec(VALUE x, VALUE klass)
*/
static VALUE
-prec_prec_i(VALUE x)
+prec_prec_i(x)
+ VALUE x;
{
VALUE klass = rb_cInteger;
@@ -62,7 +64,8 @@ prec_prec_i(VALUE x)
*/
static VALUE
-prec_prec_f(VALUE x)
+prec_prec_f(x)
+ VALUE x;
{
VALUE klass = rb_cFloat;
@@ -83,7 +86,8 @@ prec_prec_f(VALUE x)
*/
static VALUE
-prec_induced_from(VALUE module, VALUE x)
+prec_induced_from(module, x)
+ VALUE module, x;
{
rb_raise(rb_eTypeError, "undefined conversion from %s into %s",
rb_obj_classname(x), rb_class2name(module));
@@ -100,7 +104,8 @@ prec_induced_from(VALUE module, VALUE x)
*/
static VALUE
-prec_included(VALUE module, VALUE include)
+prec_included(module, include)
+ VALUE module, include;
{
switch (TYPE(include)) {
case T_CLASS:
@@ -123,7 +128,7 @@ prec_included(VALUE module, VALUE include)
*/
void
-Init_Precision(void)
+Init_Precision()
{
rb_mPrecision = rb_define_module("Precision");
rb_define_singleton_method(rb_mPrecision, "included", prec_included, 1);
diff --git a/process.c b/process.c
index b0886071a7..718b8ff67b 100644
--- a/process.c
+++ b/process.c
@@ -23,9 +23,6 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
#ifdef __DJGPP__
#include <process.h>
#endif
@@ -40,7 +37,7 @@
#define EXIT_FAILURE 1
#endif
-struct timeval rb_time_interval(VALUE);
+struct timeval rb_time_interval _((VALUE));
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
@@ -104,6 +101,13 @@ 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
@@ -128,7 +132,7 @@ static VALUE S_Tms;
*/
static VALUE
-get_pid(void)
+get_pid()
{
rb_secure(2);
return INT2FIX(getpid());
@@ -152,9 +156,9 @@ get_pid(void)
*/
static VALUE
-get_ppid(void)
+get_ppid()
{
- rb_secure(2);
+ rb_secure(2);
#ifdef _WIN32
return INT2FIX(0);
#else
@@ -197,7 +201,8 @@ static VALUE rb_cProcStatus;
VALUE rb_last_status = Qnil;
static void
-last_status_set(int status, int pid)
+last_status_set(status, pid)
+ int status, pid;
{
rb_last_status = rb_obj_alloc(rb_cProcStatus);
rb_iv_set(rb_last_status, "status", INT2FIX(status));
@@ -219,7 +224,8 @@ last_status_set(int status, int pid)
*/
static VALUE
-pst_to_i(VALUE st)
+pst_to_i(st)
+ VALUE st;
{
return rb_iv_get(st, "status");
}
@@ -233,7 +239,8 @@ pst_to_i(VALUE st)
*/
static VALUE
-pst_to_s(VALUE st)
+pst_to_s(st)
+ VALUE st;
{
return rb_fix2str(pst_to_i(st), 10);
}
@@ -251,7 +258,8 @@ pst_to_s(VALUE st)
*/
static VALUE
-pst_pid(VALUE st)
+pst_pid(st)
+ VALUE st;
{
return rb_iv_get(st, "pid");
}
@@ -265,7 +273,8 @@ pst_pid(VALUE st)
*/
static VALUE
-pst_inspect(VALUE st)
+pst_inspect(st)
+ VALUE st;
{
VALUE pid;
int status;
@@ -275,7 +284,8 @@ pst_inspect(VALUE st)
pid = pst_pid(st);
status = NUM2INT(st);
- str = rb_sprintf("#<%s: pid=%ld", rb_class2name(CLASS_OF(st)), NUM2LONG(pid));
+ snprintf(buf, sizeof(buf), "#<%s: pid=%ld", rb_class2name(CLASS_OF(st)), NUM2LONG(pid));
+ str = rb_str_new2(buf);
if (WIFSTOPPED(status)) {
int stopsig = WSTOPSIG(status);
const char *signame = ruby_signal_name(stopsig);
@@ -321,7 +331,8 @@ pst_inspect(VALUE st)
*/
static VALUE
-pst_equal(VALUE st1, VALUE st2)
+pst_equal(st1, st2)
+ VALUE st1, st2;
{
if (st1 == st2) return Qtrue;
return rb_equal(pst_to_i(st1), st2);
@@ -341,7 +352,8 @@ pst_equal(VALUE st1, VALUE st2)
*/
static VALUE
-pst_bitand(VALUE st1, VALUE st2)
+pst_bitand(st1, st2)
+ VALUE st1, st2;
{
int status = NUM2INT(st1) & NUM2INT(st2);
@@ -362,7 +374,8 @@ pst_bitand(VALUE st1, VALUE st2)
*/
static VALUE
-pst_rshift(VALUE st1, VALUE st2)
+pst_rshift(st1, st2)
+ VALUE st1, st2;
{
int status = NUM2INT(st1) >> NUM2INT(st2);
@@ -380,7 +393,8 @@ pst_rshift(VALUE st1, VALUE st2)
*/
static VALUE
-pst_wifstopped(VALUE st)
+pst_wifstopped(st)
+ VALUE st;
{
int status = NUM2INT(st);
@@ -400,7 +414,8 @@ pst_wifstopped(VALUE st)
*/
static VALUE
-pst_wstopsig(VALUE st)
+pst_wstopsig(st)
+ VALUE st;
{
int status = NUM2INT(st);
@@ -419,7 +434,8 @@ pst_wstopsig(VALUE st)
*/
static VALUE
-pst_wifsignaled(VALUE st)
+pst_wifsignaled(st)
+ VALUE st;
{
int status = NUM2INT(st);
@@ -440,7 +456,8 @@ pst_wifsignaled(VALUE st)
*/
static VALUE
-pst_wtermsig(VALUE st)
+pst_wtermsig(st)
+ VALUE st;
{
int status = NUM2INT(st);
@@ -460,7 +477,8 @@ pst_wtermsig(VALUE st)
*/
static VALUE
-pst_wifexited(VALUE st)
+pst_wifexited(st)
+ VALUE st;
{
int status = NUM2INT(st);
@@ -491,7 +509,8 @@ pst_wifexited(VALUE st)
*/
static VALUE
-pst_wexitstatus(VALUE st)
+pst_wexitstatus(st)
+ VALUE st;
{
int status = NUM2INT(st);
@@ -510,7 +529,8 @@ pst_wexitstatus(VALUE st)
*/
static VALUE
-pst_success_p(VALUE st)
+pst_success_p(st)
+ VALUE st;
{
int status = NUM2INT(st);
@@ -529,7 +549,8 @@ pst_success_p(VALUE st)
*/
static VALUE
-pst_wcoredump(VALUE st)
+pst_wcoredump(st)
+ VALUE st;
{
#ifdef WCOREDUMP
int status = NUM2INT(st);
@@ -549,7 +570,10 @@ static st_table *pid_tbl;
#endif
int
-rb_waitpid(int pid, int *st, int flags)
+rb_waitpid(pid, st, flags)
+ int pid;
+ int *st;
+ int flags;
{
int result;
#ifndef NO_WAITPID
@@ -580,7 +604,7 @@ rb_waitpid(int pid, int *st, int flags)
goto retry;
}
#else /* NO_WAITPID */
- if (pid_tbl && st_lookup(pid_tbl, pid, (st_data_t *)st)) {
+ if (pid_tbl && st_lookup(pid_tbl, pid, st)) {
last_status_set(*st, pid);
st_delete(pid_tbl, (st_data_t*)&pid, NULL);
return pid;
@@ -606,7 +630,7 @@ rb_waitpid(int pid, int *st, int flags)
}
if (!pid_tbl)
pid_tbl = st_init_numtable();
- st_insert(pid_tbl, pid, (st_data_t)st);
+ st_insert(pid_tbl, pid, st);
if (!rb_thread_alone()) rb_thread_schedule();
}
#endif
@@ -623,7 +647,9 @@ struct wait_data {
};
static int
-wait_each(int pid, int status, struct wait_data *data)
+wait_each(pid, status, data)
+ int pid, status;
+ struct wait_data *data;
{
if (data->status != -1) return ST_STOP;
@@ -633,7 +659,9 @@ wait_each(int pid, int status, struct wait_data *data)
}
static int
-waitall_each(int pid, int status, VALUE ary)
+waitall_each(pid, status, ary)
+ int pid, status;
+ VALUE ary;
{
last_status_set(status, pid);
rb_ary_push(ary, rb_assoc_new(INT2NUM(pid), rb_last_status));
@@ -701,7 +729,9 @@ waitall_each(int pid, int status, VALUE ary)
*/
static VALUE
-proc_wait(int argc, VALUE *argv)
+proc_wait(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE vpid, vflags;
int pid, flags, status;
@@ -745,7 +775,9 @@ proc_wait(int argc, VALUE *argv)
*/
static VALUE
-proc_wait2(int argc, VALUE *argv)
+proc_wait2(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE pid = proc_wait(argc, argv);
if (NIL_P(pid)) return Qnil;
@@ -774,7 +806,7 @@ proc_wait2(int argc, VALUE *argv)
*/
static VALUE
-proc_waitall(void)
+proc_waitall()
{
VALUE result;
int pid, status;
@@ -816,21 +848,22 @@ proc_waitall(void)
}
static VALUE
-detach_process_watcher(int *pid_p)
+detach_process_watcher(arg)
+ void *arg;
{
- int cpid, status;
+ int pid = (int)(VALUE)arg, status;
- for (;;) {
- cpid = rb_waitpid(*pid_p, &status, WNOHANG);
- if (cpid != 0) return rb_last_status;
+ while (rb_waitpid(pid, &status, WNOHANG) == 0) {
rb_thread_sleep(1);
}
+ return rb_last_status;
}
VALUE
-rb_detach_process(int pid)
+rb_detach_process(pid)
+ int pid;
{
- return rb_thread_create(detach_process_watcher, (void*)&pid);
+ return rb_thread_create(detach_process_watcher, (void*)(VALUE)pid);
}
@@ -899,10 +932,11 @@ char *strtok();
#define after_exec()
#endif
-extern char *dln_find_exe(const char *fname, const char *path);
+extern char *dln_find_exe();
static void
-security(const char *str)
+security(str)
+ char *str;
{
if (rb_env_path_tainted()) {
if (rb_safe_level() > 0) {
@@ -912,16 +946,16 @@ security(const char *str)
}
static int
-proc_exec_v(char **argv, const char *prog)
+proc_exec_v(argv, prog)
+ char **argv;
+ char *prog;
{
if (!prog)
prog = argv[0];
security(prog);
prog = dln_find_exe(prog, 0);
- if (!prog) {
- errno = ENOENT;
+ if (!prog)
return -1;
- }
#if (defined(MSDOS) && !defined(DJGPP)) || defined(__human68k__) || defined(__EMX__) || defined(OS2)
{
@@ -961,20 +995,29 @@ proc_exec_v(char **argv, const char *prog)
}
#endif /* MSDOS or __human68k__ or __EMX__ */
before_exec();
+ rb_thread_cancel_timer();
execv(prog, argv);
preserving_errno(after_exec());
return -1;
}
-int
-rb_proc_exec_n(int argc, VALUE *argv, const char *prog)
+static int
+proc_exec_n(argc, argv, progv)
+ int argc;
+ VALUE *argv;
+ VALUE progv;
{
+ char *prog = 0;
char **args;
int i;
+ if (progv) {
+ prog = RSTRING(progv)->ptr;
+ }
args = ALLOCA_N(char*, argc+1);
for (i=0; i<argc; i++) {
- args[i] = RSTRING_PTR(argv[i]);
+ SafeStringValue(argv[i]);
+ args[i] = RSTRING(argv[i])->ptr;
}
args[i] = 0;
if (args[0]) {
@@ -984,7 +1027,8 @@ rb_proc_exec_n(int argc, VALUE *argv, const char *prog)
}
int
-rb_proc_exec(const char *str)
+rb_proc_exec(str)
+ const char *str;
{
const char *s = str;
char *ss, *t;
@@ -995,18 +1039,10 @@ rb_proc_exec(const char *str)
#ifdef _WIN32
before_exec();
- rb_w32_spawn(P_OVERLAY, (char *)str, 0);
+ do_spawn(P_OVERLAY, (char *)str);
after_exec();
#else
for (s=str; *s; s++) {
- if (ISSPACE(*s)) {
- const char *p, *nl = NULL;
- for (p = s; ISSPACE(*p); p++) {
- if (*p == '\n') nl = p;
- }
- if (!*p) break;
- if (nl) s = nl;
- }
if (*s != ' ' && !ISALPHA(*s) && strchr("*?{}[]<>()~&|\\$;'`\"\n",*s)) {
#if defined(MSDOS)
int status;
@@ -1015,7 +1051,8 @@ rb_proc_exec(const char *str)
after_exec();
if (status != -1)
exit(status);
-#elif defined(__human68k__) || defined(__CYGWIN32__) || defined(__EMX__)
+#else
+#if defined(__human68k__) || defined(__CYGWIN32__) || defined(__EMX__)
char *shell = dln_find_exe("sh", 0);
int status = -1;
before_exec();
@@ -1031,15 +1068,15 @@ rb_proc_exec(const char *str)
execl("/bin/sh", "sh", "-c", str, (char *)NULL);
preserving_errno(after_exec());
#endif
+#endif
return -1;
}
}
a = argv = ALLOCA_N(char*, (s-str)/2+2);
ss = ALLOCA_N(char, s-str+1);
- memcpy(ss, str, s-str);
- ss[s-str] = '\0';
- if (*a++ = strtok(ss, " \t")) {
- while (t = strtok(NULL, " \t")) {
+ strcpy(ss, str);
+ if ((*a++ = strtok(ss, " \t")) != 0) {
+ while ((t = strtok(NULL, " \t")) != 0) {
*a++ = t;
}
*a = NULL;
@@ -1052,16 +1089,11 @@ rb_proc_exec(const char *str)
return -1;
}
-#if defined(_WIN32)
-#define HAVE_SPAWNV 1
-#endif
-
-#if !defined(HAVE_FORK) && defined(HAVE_SPAWNV)
-#if defined(_WIN32)
-#define proc_spawn_v(argv, prog) rb_w32_aspawn(P_NOWAIT, prog, argv)
-#else
+#if defined(__human68k__) || defined(__DJGPP__) || defined(_WIN32)
static int
-proc_spawn_v(char **argv, char *prog)
+proc_spawn_v(argv, prog)
+ char **argv;
+ char *prog;
{
char *extension;
int status;
@@ -1098,45 +1130,54 @@ proc_spawn_v(char **argv, char *prog)
}
#endif
before_exec();
+#if defined(_WIN32)
+ status = do_aspawn(P_WAIT, prog, argv);
+#else
status = spawnv(P_WAIT, prog, argv);
- last_status_set(status == -1 ? 127 : status, 0);
+#endif
after_exec();
return status;
}
-#endif
static int
-proc_spawn_n(int argc, VALUE *argv, VALUE prog)
+proc_spawn_n(argc, argv, prog)
+ int argc;
+ VALUE *argv;
+ VALUE prog;
{
char **args;
int i;
args = ALLOCA_N(char*, argc + 1);
for (i = 0; i < argc; i++) {
- args[i] = RSTRING_PTR(argv[i]);
+ SafeStringValue(argv[i]);
+ args[i] = StringValueCStr(argv[i]);
}
+ if (prog)
+ SafeStringValue(prog);
args[i] = (char*) 0;
if (args[0])
- return proc_spawn_v(args, prog ? RSTRING_PTR(prog) : 0);
+ return proc_spawn_v(args, prog ? StringValueCStr(prog) : 0);
return -1;
}
-#if defined(_WIN32)
-#define proc_spawn(str) rb_w32_spawn(P_NOWAIT, str, 0)
-#else
+#if !defined(_WIN32)
static int
-proc_spawn(char *str)
+proc_spawn(sv)
+ VALUE sv;
{
+ char *str;
char *s, *t;
char **argv, **a;
int status;
+ SafeStringValue(sv);
+ str = s = StringValueCStr(sv);
for (s = str; *s; s++) {
if (*s != ' ' && !ISALPHA(*s) && strchr("*?{}[]<>()~&|\\$;'`\"\n",*s)) {
char *shell = dln_find_exe("sh", 0);
before_exec();
status = shell?spawnl(P_WAIT,shell,"sh","-c",str,(char*)NULL):system(str);
- last_status_set(status == -1 ? 127 : status, 0);
after_exec();
return status;
}
@@ -1154,24 +1195,23 @@ proc_spawn(char *str)
#endif
#endif
-VALUE
-rb_check_argv(int argc, VALUE *argv)
+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;
{
- VALUE tmp, prog;
int i;
- if (argc == 0) {
- rb_raise(rb_eArgError, "wrong number of arguments");
- }
-
- prog = 0;
- tmp = rb_check_array_type(argv[0]);
- if (!NIL_P(tmp)) {
- if (RARRAY_LEN(tmp) != 2) {
- rb_raise(rb_eArgError, "wrong first argument");
- }
- prog = RARRAY_PTR(tmp)[0];
- argv[0] = RARRAY_PTR(tmp)[1];
+ MEMZERO(e, struct rb_exec_arg, 1);
+ if (prog) {
SafeStringValue(prog);
StringValueCStr(prog);
}
@@ -1179,8 +1219,27 @@ rb_check_argv(int argc, VALUE *argv)
SafeStringValue(argv[i]);
StringValueCStr(argv[i]);
}
- security(RSTRING_PTR(prog ? prog : argv[0]));
- return prog;
+ 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);
+ }
}
/*
@@ -1200,9 +1259,6 @@ rb_check_argv(int argc, VALUE *argv)
* used, so the running command may inherit some of the environment of
* the original program (including open file descriptors).
*
- * Raises SystemCallError if the _command_ couldn't execute (typically
- * <code>Errno::ENOENT</code> when it was not found).
- *
* exec "echo *" # echoes list of files in current directory
* # never get here
*
@@ -1212,169 +1268,34 @@ rb_check_argv(int argc, VALUE *argv)
*/
VALUE
-rb_f_exec(int argc, VALUE *argv)
+rb_f_exec(argc, argv)
+ int argc;
+ VALUE *argv;
{
- struct rb_exec_arg e;
- VALUE prog;
-
- prog = rb_check_argv(argc, argv);
- if (!prog && argc == 1) {
- e.argc = 0;
- e.argv = 0;
- e.prog = RSTRING_PTR(argv[0]);
- }
- else {
- e.argc = argc;
- e.argv = argv;
- e.prog = prog ? RSTRING_PTR(prog) : 0;
- }
- rb_exec(&e);
- rb_sys_fail(e.prog);
- return Qnil; /* dummy */
-}
-
-int
-rb_exec(const struct rb_exec_arg *e)
-{
- int argc = e->argc;
- VALUE *argv = e->argv;
- const char *prog = e->prog;
+ VALUE prog = 0;
+ VALUE tmp;
+ struct rb_exec_arg earg;
if (argc == 0) {
- rb_proc_exec(prog);
- }
- else {
- rb_proc_exec_n(argc, argv, prog);
+ rb_last_status = Qnil;
+ rb_raise(rb_eArgError, "wrong number of arguments");
}
-#ifndef FD_CLOEXEC
- preserving_errno({
- fprintf(stderr, "%s:%d: command not found: %s\n",
- ruby_sourcefile, ruby_sourceline, prog);
- });
-#endif
- return -1;
-}
-
-#ifdef HAVE_FORK
-#ifdef FD_CLOEXEC
-#if SIZEOF_INT == SIZEOF_LONG
-#define proc_syswait (VALUE (*)(VALUE))rb_syswait
-#else
-static VALUE
-proc_syswait(VALUE pid)
-{
- rb_syswait((int)pid);
- return Qnil;
-}
-#endif
-#endif
-/*
- * Forks child process, and returns the process ID in the parent
- * process.
- *
- * If +status+ is given, protects from any exceptions and sets the
- * jump status to it.
- *
- * In the child process, just returns 0 if +chfunc+ is +NULL+.
- * Otherwise +chfunc+ will be called with +charg+, and then the child
- * process exits with +EXIT_SUCCESS+ when it returned zero.
- *
- * In the case of the function is called and returns non-zero value,
- * the child process exits with non-+EXIT_SUCCESS+ value (normaly
- * 127). And, on the platforms where +FD_CLOEXEC+ is available,
- * +errno+ is propagated to the parent process, and this function
- * returns -1 in the parent process. On the other platforms, just
- * returns pid.
- *
- * +chfunc+ must not raise any exceptions.
- */
-int
-rb_fork(int *status, int (*chfunc)(void*), void *charg)
-{
- int pid, err, state = 0;
-#ifdef FD_CLOEXEC
- int ep[2];
-#endif
-
-#ifndef __VMS
- rb_io_flush(rb_stdout);
- rb_io_flush(rb_stderr);
-#endif
-
-#ifdef FD_CLOEXEC
- if (chfunc) {
- if (pipe(ep)) return -1;
- if (fcntl(ep[1], F_SETFD, FD_CLOEXEC)) {
- preserving_errno((close(ep[0]), close(ep[1])));
- return -1;
- }
- }
-#endif
- while ((pid = fork()) < 0) {
- switch (errno) {
- case EAGAIN:
-#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- if (!status && !chfunc) {
- rb_thread_sleep(1);
- continue;
- }
- else {
- rb_protect((VALUE (*)())rb_thread_sleep, 1, &state);
- if (status) *status = state;
- if (!state) continue;
- }
- default:
-#ifdef FD_CLOEXEC
- if (chfunc) {
- preserving_errno((close(ep[0]), close(ep[1])));
- }
-#endif
- if (state && !status) rb_jump_tag(state);
- return -1;
- }
- }
- if (!pid) {
- if (chfunc) {
-#ifdef FD_CLOEXEC
- close(ep[0]);
-#endif
- if (!(*chfunc)(charg)) _exit(EXIT_SUCCESS);
-#ifdef FD_CLOEXEC
- err = errno;
- write(ep[1], &err, sizeof(err));
-#endif
-#if EXIT_SUCCESS == 127
- _exit(EXIT_FAILURE);
-#else
- _exit(127);
-#endif
- }
- }
-#ifdef FD_CLOEXEC
- else if (chfunc) {
- close(ep[1]);
- if ((state = read(ep[0], &err, sizeof(err))) < 0) {
- err = errno;
- }
- close(ep[0]);
- if (state) {
- if (status) {
- rb_protect(proc_syswait, (VALUE)pid, status);
- }
- else {
- rb_syswait(pid);
- }
- errno = err;
- return -1;
+ tmp = rb_check_array_type(argv[0]);
+ if (!NIL_P(tmp)) {
+ if (RARRAY(tmp)->len != 2) {
+ rb_raise(rb_eArgError, "wrong first argument");
}
+ prog = RARRAY(tmp)->ptr[0];
+ argv[0] = RARRAY(tmp)->ptr[1];
+ SafeStringValue(prog);
}
-#endif
- return pid;
+ proc_prepare_args(&earg, argc, argv, prog);
+ proc_exec_args((VALUE)&earg);
+ rb_sys_fail(RSTRING(argv[0])->ptr);
+ return Qnil; /* dummy */
}
-#endif
+
/*
* call-seq:
@@ -1398,14 +1319,20 @@ rb_fork(int *status, int (*chfunc)(void*), void *charg)
*/
static VALUE
-rb_f_fork(VALUE obj)
+rb_f_fork(obj)
+ VALUE obj;
{
-#ifdef HAVE_FORK
+#if !defined(__human68k__) && !defined(_WIN32) && !defined(__MACOS__) && !defined(__EMX__) && !defined(__VMS)
int pid;
rb_secure(2);
- switch (pid = rb_fork(0, 0, 0)) {
+#ifndef __VMS
+ fflush(stdout);
+ fflush(stderr);
+#endif
+
+ switch (pid = fork()) {
case 0:
#ifdef linux
after_exec();
@@ -1444,7 +1371,10 @@ rb_f_fork(VALUE obj)
*/
static VALUE
-rb_f_exit_bang(int argc, VALUE *argv, VALUE obj)
+rb_f_exit_bang(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE status;
int istatus;
@@ -1476,16 +1406,17 @@ rb_f_exit_bang(int argc, VALUE *argv, VALUE obj)
#endif
void
-rb_syswait(int pid)
+rb_syswait(pid)
+ int pid;
{
static int overriding;
#ifdef SIGHUP
- RETSIGTYPE (*hfunc)(int);
+ RETSIGTYPE (*hfunc)_((int));
#endif
#ifdef SIGQUIT
- RETSIGTYPE (*qfunc)(int);
+ RETSIGTYPE (*qfunc)_((int));
#endif
- RETSIGTYPE (*ifunc)(int);
+ RETSIGTYPE (*ifunc)_((int));
int status;
int i, hooked = Qfalse;
@@ -1517,56 +1448,15 @@ rb_syswait(int pid)
}
}
-int
-rb_spawn(int argc, VALUE *argv)
-{
- int status;
- VALUE prog;
-#if defined HAVE_FORK
- struct rb_exec_arg earg;
-#endif
-
- prog = rb_check_argv(argc, argv);
-
- if (!prog && argc == 1) {
- --argc;
- prog = *argv++;
- }
-#if defined HAVE_FORK
- earg.argc = argc;
- earg.argv = argv;
- earg.prog = prog ? RSTRING_PTR(prog) : 0;
- status = rb_fork(&status, (int (*)(void*))rb_exec, &earg);
- if (prog && argc) argv[0] = prog;
-#elif defined HAVE_SPAWNV
- if (!argc) {
- status = proc_spawn(RSTRING_PTR(prog));
- }
- else {
- status = proc_spawn_n(argc, argv, prog);
- }
- if (prog && argc) argv[0] = prog;
-#else
- if (prog && argc) argv[0] = prog;
- if (argc) prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
- status = system(StringValuePtr(prog));
-# if defined(__human68k__) || defined(__DJGPP__)
- last_status_set(status == -1 ? 127 : status, 0);
-# else
- last_status_set((status & 0xff) << 8, 0);
-# endif
-#endif
- return status;
-}
-
/*
* call-seq:
* system(cmd [, arg, ...]) => true or false
*
- * Executes _cmd_ in a subshell, returning +true+ if the command ran
- * successfully, +false+ otherwise. An error status is available in
- * <code>$?</code>. The arguments are processed in the same way as
- * for <code>Kernel::exec</code>, and raises same exceptions as it.
+ * Executes _cmd_ in a subshell, returning +true+ if
+ * the command was found and ran successfully, +false+
+ * otherwise. An error status is available in <code>$?</code>. The
+ * arguments are processed in the same way as for
+ * <code>Kernel::exec</code>.
*
* system("echo *")
* system("echo", "*")
@@ -1577,56 +1467,134 @@ rb_spawn(int argc, VALUE *argv)
* *
*/
-#if defined(SIGCLD) && !defined(SIGCHLD)
-# define SIGCHLD SIGCLD
-#endif
-
static VALUE
-rb_f_system(int argc, VALUE *argv)
+rb_f_system(argc, argv)
+ int argc;
+ VALUE *argv;
{
int status;
-#ifdef SIGCHLD
- RETSIGTYPE (*chfunc)(int);
+#if defined(__EMX__)
+ VALUE cmd;
- chfunc = signal(SIGCHLD, SIG_DFL);
-#endif
- status = rb_spawn(argc, argv);
-#if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
- if (status > 0) {
- rb_syswait(status);
+ fflush(stdout);
+ fflush(stderr);
+ if (argc == 0) {
+ rb_last_status = Qnil;
+ rb_raise(rb_eArgError, "wrong number of arguments");
+ }
+
+ if (TYPE(argv[0]) == T_ARRAY) {
+ if (RARRAY(argv[0])->len != 2) {
+ rb_raise(rb_eArgError, "wrong first argument");
+ }
+ argv[0] = RARRAY(argv[0])->ptr[0];
+ }
+ cmd = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
+
+ SafeStringValue(cmd);
+ status = do_spawn(RSTRING(cmd)->ptr);
+ last_status_set(status, 0);
+#elif defined(__human68k__) || defined(__DJGPP__) || defined(_WIN32)
+ volatile VALUE prog = 0;
+
+ fflush(stdout);
+ fflush(stderr);
+ if (argc == 0) {
+ rb_last_status = Qnil;
+ rb_raise(rb_eArgError, "wrong number of arguments");
+ }
+
+ if (TYPE(argv[0]) == T_ARRAY) {
+ if (RARRAY(argv[0])->len != 2) {
+ rb_raise(rb_eArgError, "wrong first argument");
+ }
+ prog = RARRAY(argv[0])->ptr[0];
+ argv[0] = RARRAY(argv[0])->ptr[1];
}
+
+ if (argc == 1 && prog == 0) {
+#if defined(_WIN32)
+ SafeStringValue(argv[0]);
+ status = do_spawn(P_WAIT, StringValueCStr(argv[0]));
+#else
+ status = proc_spawn(argv[0]);
#endif
-#ifdef SIGCHLD
- signal(SIGCHLD, chfunc);
+ }
+ else {
+ status = proc_spawn_n(argc, argv, prog);
+ }
+#if !defined(_WIN32)
+ last_status_set(status == -1 ? 127 : status, 0);
+#else
+ if (status == -1)
+ last_status_set(0x7f << 8, 0);
#endif
- if (status < 0) {
- rb_sys_fail(RSTRING_PTR(argv[0]));
+#elif defined(__VMS)
+ VALUE cmd;
+
+ if (argc == 0) {
+ rb_last_status = Qnil;
+ rb_raise(rb_eArgError, "wrong number of arguments");
}
- status = NUM2INT(rb_last_status);
- if (status == EXIT_SUCCESS) return Qtrue;
- return Qfalse;
-}
-/*
- * call-seq:
- * spawn(cmd [, arg, ...]) => pid
- *
- * Similar to <code>Kernel::system</code> except for not waiting for
- * end of _cmd_, but returns its <i>pid</i>.
- */
+ if (TYPE(argv[0]) == T_ARRAY) {
+ if (RARRAY(argv[0])->len != 2) {
+ rb_raise(rb_eArgError, "wrong first argument");
+ }
+ argv[0] = RARRAY(argv[0])->ptr[0];
+ }
+ cmd = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
-static VALUE
-rb_f_spawn(int argc, VALUE *argv)
-{
+ SafeStringValue(cmd);
+ status = system(StringValueCStr(cmd));
+ last_status_set((status & 0xff) << 8, 0);
+#else
+ volatile VALUE prog = 0;
int pid;
+ struct rb_exec_arg earg;
+ RETSIGTYPE (*chfunc)(int);
- pid = rb_spawn(argc, argv);
- if (pid == -1) rb_sys_fail(RSTRING_PTR(argv[0]));
-#if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
- return INT2NUM(pid);
-#else
- return Qnil;
+ fflush(stdout);
+ fflush(stderr);
+ if (argc == 0) {
+ rb_last_status = Qnil;
+ rb_raise(rb_eArgError, "wrong number of arguments");
+ }
+
+ if (TYPE(argv[0]) == T_ARRAY) {
+ if (RARRAY(argv[0])->len != 2) {
+ rb_raise(rb_eArgError, "wrong first argument");
+ }
+ prog = RARRAY(argv[0])->ptr[0];
+ argv[0] = RARRAY(argv[0])->ptr[1];
+ }
+ proc_prepare_args(&earg, argc, argv, prog);
+
+ chfunc = signal(SIGCHLD, SIG_DFL);
+ retry:
+ pid = fork();
+ if (pid == 0) {
+ /* child process */
+ rb_thread_atfork();
+ rb_protect(proc_exec_args, (VALUE)&earg, NULL);
+ _exit(127);
+ }
+ if (pid < 0) {
+ if (errno == EAGAIN) {
+ rb_thread_sleep(1);
+ goto retry;
+ }
+ }
+ else {
+ rb_syswait(pid);
+ }
+ signal(SIGCHLD, chfunc);
+ if (pid < 0) rb_sys_fail(0);
+ status = NUM2INT(rb_last_status);
#endif
+
+ if (status == EXIT_SUCCESS) return Qtrue;
+ return Qfalse;
}
/*
@@ -1647,7 +1615,9 @@ rb_f_spawn(int argc, VALUE *argv)
*/
static VALUE
-rb_f_sleep(int argc, VALUE *argv)
+rb_f_sleep(argc, argv)
+ int argc;
+ VALUE *argv;
{
int beg, end;
@@ -1679,8 +1649,12 @@ rb_f_sleep(int argc, VALUE *argv)
* Process.getpgrp #=> 25527
*/
+#if defined(SIGCLD) && !defined(SIGCHLD)
+# define SIGCHLD SIGCLD
+#endif
+
static VALUE
-proc_getpgrp(void)
+proc_getpgrp()
{
int pgrp;
@@ -1710,7 +1684,7 @@ proc_getpgrp(void)
*/
static VALUE
-proc_setpgrp(void)
+proc_setpgrp()
{
rb_secure(2);
/* check for posix setpgid() first; this matches the posix */
@@ -1739,7 +1713,8 @@ proc_setpgrp(void)
*/
static VALUE
-proc_getpgid(VALUE obj, VALUE pid)
+proc_getpgid(obj, pid)
+ VALUE obj, pid;
{
#if defined(HAVE_GETPGID) && !defined(__CHECKER__)
int i;
@@ -1763,7 +1738,8 @@ proc_getpgid(VALUE obj, VALUE pid)
*/
static VALUE
-proc_setpgid(VALUE obj, VALUE pid, VALUE pgrp)
+proc_setpgid(obj, pid, pgrp)
+ VALUE obj, pid, pgrp;
{
#ifdef HAVE_SETPGID
int ipid, ipgrp;
@@ -1792,7 +1768,7 @@ proc_setpgid(VALUE obj, VALUE pid, VALUE pgrp)
*/
static VALUE
-proc_setsid(void)
+proc_setsid()
{
#if defined(HAVE_SETSID)
int pid;
@@ -1846,7 +1822,8 @@ proc_setsid(void)
*/
static VALUE
-proc_getpriority(VALUE obj, VALUE which, VALUE who)
+proc_getpriority(obj, which, who)
+ VALUE obj, which, who;
{
#ifdef HAVE_GETPRIORITY
int prio, iwhich, iwho;
@@ -1878,7 +1855,8 @@ proc_getpriority(VALUE obj, VALUE which, VALUE who)
*/
static VALUE
-proc_setpriority(VALUE obj, VALUE which, VALUE who, VALUE prio)
+proc_setpriority(obj, which, who, prio)
+ VALUE obj, which, who, prio;
{
#ifdef HAVE_GETPRIORITY
int iwhich, iwho, iprio;
@@ -1935,7 +1913,7 @@ proc_getrlimit(VALUE obj, VALUE resource)
rb_secure(2);
if (getrlimit(NUM2INT(resource), &rlim) < 0) {
- rb_sys_fail("getrlimit");
+ rb_sys_fail("getrlimit");
}
return rb_assoc_new(RLIM2NUM(rlim.rlim_cur), RLIM2NUM(rlim.rlim_max));
#else
@@ -1997,7 +1975,7 @@ proc_setrlimit(int argc, VALUE *argv, VALUE obj)
rlim.rlim_max = NUM2RLIM(rlim_max);
if (setrlimit(NUM2INT(resource), &rlim) < 0) {
- rb_sys_fail("setrlimit");
+ rb_sys_fail("setrlimit");
}
return Qnil;
#else
@@ -2007,7 +1985,7 @@ proc_setrlimit(int argc, VALUE *argv, VALUE obj)
static int under_uid_switch = 0;
static void
-check_uid_switch(void)
+check_uid_switch()
{
rb_secure(2);
if (under_uid_switch) {
@@ -2017,7 +1995,7 @@ check_uid_switch(void)
static int under_gid_switch = 0;
static void
-check_gid_switch(void)
+check_gid_switch()
{
rb_secure(2);
if (under_gid_switch) {
@@ -2047,7 +2025,8 @@ check_gid_switch(void)
*/
static VALUE
-p_sys_setuid(VALUE obj, VALUE id)
+p_sys_setuid(obj, id)
+ VALUE obj, id;
{
#if defined HAVE_SETUID
check_uid_switch();
@@ -2070,7 +2049,8 @@ p_sys_setuid(VALUE obj, VALUE id)
*/
static VALUE
-p_sys_setruid(VALUE obj, VALUE id)
+p_sys_setruid(obj, id)
+ VALUE obj, id;
{
#if defined HAVE_SETRUID
check_uid_switch();
@@ -2092,7 +2072,8 @@ p_sys_setruid(VALUE obj, VALUE id)
*/
static VALUE
-p_sys_seteuid(VALUE obj, VALUE id)
+p_sys_seteuid(obj, id)
+ VALUE obj, id;
{
#if defined HAVE_SETEUID
check_uid_switch();
@@ -2116,7 +2097,8 @@ p_sys_seteuid(VALUE obj, VALUE id)
*/
static VALUE
-p_sys_setreuid(VALUE obj, VALUE rid, VALUE eid)
+p_sys_setreuid(obj, rid, eid)
+ VALUE obj, rid, eid;
{
#if defined HAVE_SETREUID
check_uid_switch();
@@ -2140,7 +2122,8 @@ p_sys_setreuid(VALUE obj, VALUE rid, VALUE eid)
*/
static VALUE
-p_sys_setresuid(VALUE obj, VALUE rid, VALUE eid, VALUE sid)
+p_sys_setresuid(obj, rid, eid, sid)
+ VALUE obj, rid, eid, sid;
{
#if defined HAVE_SETRESUID
check_uid_switch();
@@ -2164,7 +2147,8 @@ p_sys_setresuid(VALUE obj, VALUE rid, VALUE eid, VALUE sid)
*/
static VALUE
-proc_getuid(VALUE obj)
+proc_getuid(obj)
+ VALUE obj;
{
int uid = getuid();
return INT2FIX(uid);
@@ -2180,7 +2164,8 @@ proc_getuid(VALUE obj)
*/
static VALUE
-proc_setuid(VALUE obj, VALUE id)
+proc_setuid(obj, id)
+ VALUE obj, id;
{
int uid = NUM2INT(id);
@@ -2221,7 +2206,8 @@ static int SAVED_USER_ID = -1;
#ifdef BROKEN_SETREUID
int
-setreuid(rb_uid_t ruid, rb_uid_t euid)
+setreuid(ruid, euid)
+ rb_uid_t ruid, euid;
{
if (ruid != -1 && ruid != getuid()) {
if (euid == -1) euid = geteuid();
@@ -2248,7 +2234,8 @@ setreuid(rb_uid_t ruid, rb_uid_t euid)
*/
static VALUE
-p_uid_change_privilege(VALUE obj, VALUE id)
+p_uid_change_privilege(obj, id)
+ VALUE obj, id;
{
int uid;
@@ -2397,7 +2384,8 @@ p_uid_change_privilege(VALUE obj, VALUE id)
*/
static VALUE
-p_sys_setgid(VALUE obj, VALUE id)
+p_sys_setgid(obj, id)
+ VALUE obj, id;
{
#if defined HAVE_SETGID
check_gid_switch();
@@ -2419,7 +2407,8 @@ p_sys_setgid(VALUE obj, VALUE id)
*/
static VALUE
-p_sys_setrgid(VALUE obj, VALUE id)
+p_sys_setrgid(obj, id)
+ VALUE obj, id;
{
#if defined HAVE_SETRGID
check_gid_switch();
@@ -2442,7 +2431,8 @@ p_sys_setrgid(VALUE obj, VALUE id)
*/
static VALUE
-p_sys_setegid(VALUE obj, VALUE id)
+p_sys_setegid(obj, id)
+ VALUE obj, id;
{
#if defined HAVE_SETEGID
check_gid_switch();
@@ -2466,7 +2456,8 @@ p_sys_setegid(VALUE obj, VALUE id)
*/
static VALUE
-p_sys_setregid(VALUE obj, VALUE rid, VALUE eid)
+p_sys_setregid(obj, rid, eid)
+ VALUE obj, rid, eid;
{
#if defined HAVE_SETREGID
check_gid_switch();
@@ -2489,7 +2480,8 @@ p_sys_setregid(VALUE obj, VALUE rid, VALUE eid)
*/
static VALUE
-p_sys_setresgid(VALUE obj, VALUE rid, VALUE eid, VALUE sid)
+p_sys_setresgid(obj, rid, eid, sid)
+ VALUE obj, rid, eid, sid;
{
#if defined HAVE_SETRESGID
check_gid_switch();
@@ -2514,7 +2506,8 @@ p_sys_setresgid(VALUE obj, VALUE rid, VALUE eid, VALUE sid)
*/
static VALUE
-p_sys_issetugid(VALUE obj)
+p_sys_issetugid(obj)
+ VALUE obj;
{
#if defined HAVE_ISSETUGID
rb_secure(2);
@@ -2542,7 +2535,8 @@ p_sys_issetugid(VALUE obj)
*/
static VALUE
-proc_getgid(VALUE obj)
+proc_getgid(obj)
+ VALUE obj;
{
int gid = getgid();
return INT2FIX(gid);
@@ -2557,7 +2551,8 @@ proc_getgid(VALUE obj)
*/
static VALUE
-proc_setgid(VALUE obj, VALUE id)
+proc_setgid(obj, id)
+ VALUE obj, id;
{
int gid = NUM2INT(id);
@@ -2649,14 +2644,14 @@ proc_setgroups(VALUE obj, VALUE ary)
Check_Type(ary, T_ARRAY);
- ngroups = RARRAY_LEN(ary);
+ ngroups = RARRAY(ary)->len;
if (ngroups > maxgroups)
- rb_raise(rb_eArgError, "too many groups, %lu max", (unsigned long)maxgroups);
+ rb_raise(rb_eArgError, "too many groups, %d max", maxgroups);
groups = ALLOCA_N(rb_gid_t, ngroups);
- for (i = 0; i < ngroups && i < RARRAY_LEN(ary); i++) {
- VALUE g = RARRAY_PTR(ary)[i];
+ for (i = 0; i < ngroups && i < RARRAY(ary)->len; i++) {
+ VALUE g = RARRAY(ary)->ptr[i];
if (FIXNUM_P(g)) {
groups[i] = FIX2INT(g);
@@ -2668,10 +2663,10 @@ proc_setgroups(VALUE obj, VALUE ary)
groups[i] = NUM2INT(g);
}
else {
- gr = getgrnam(RSTRING_PTR(tmp));
+ gr = getgrnam(RSTRING(tmp)->ptr);
if (gr == NULL)
rb_raise(rb_eArgError,
- "can't find group for %s", RSTRING_PTR(tmp));
+ "can't find group for %s", RSTRING(tmp)->ptr);
groups[i] = gr->gr_gid;
}
}
@@ -2707,7 +2702,8 @@ proc_setgroups(VALUE obj, VALUE ary)
*/
static VALUE
-proc_initgroups(VALUE obj, VALUE uname, VALUE base_grp)
+proc_initgroups(obj, uname, base_grp)
+ VALUE obj, uname, base_grp;
{
#ifdef HAVE_INITGROUPS
if (initgroups(StringValuePtr(uname), (rb_gid_t)NUM2INT(base_grp)) != 0) {
@@ -2732,7 +2728,8 @@ proc_initgroups(VALUE obj, VALUE uname, VALUE base_grp)
*/
static VALUE
-proc_getmaxgroups(VALUE obj)
+proc_getmaxgroups(obj)
+ VALUE obj;
{
return INT2FIX(maxgroups);
}
@@ -2759,59 +2756,6 @@ proc_setmaxgroups(VALUE obj, VALUE val)
return INT2FIX(maxgroups);
}
-/*
- * call-seq:
- * Process.daemon() => fixnum
- * Process.daemon(nochdir=nil,noclose=nil) => fixnum
- *
- * Detach the process from controlling terminal and run in
- * the background as system daemon. Unless the argument
- * nochdir is true (i.e. non false), it changes the current
- * working directory to the root ("/"). Unless the argument
- * noclose is true, daemon() will redirect standard input,
- * standard output and standard error to /dev/null.
- */
-
-static VALUE
-proc_daemon(int argc, VALUE *argv)
-{
- VALUE nochdir, noclose;
- int n;
-
- rb_secure(2);
- rb_scan_args(argc, argv, "02", &nochdir, &noclose);
-
-#if defined(HAVE_DAEMON)
- n = daemon(RTEST(nochdir), RTEST(noclose));
- if (n < 0) rb_sys_fail("daemon");
- return INT2FIX(n);
-#elif defined(HAVE_FORK)
- switch (rb_fork(0, 0, 0)) {
- case -1:
- return (-1);
- case 0:
- break;
- default:
- _exit(0);
- }
-
- proc_setsid();
-
- if (!RTEST(nochdir))
- (void)chdir("/");
-
- if (!RTEST(noclose) && (n = open("/dev/null", O_RDWR, 0)) != -1) {
- (void)dup2(n, 0);
- (void)dup2(n, 1);
- (void)dup2(n, 2);
- if (n > 2)
- (void)close (n);
- }
- return INT2FIX(0);
-#else
- rb_notimplement();
-#endif
-}
/********************************************************************
*
@@ -2827,7 +2771,8 @@ static int SAVED_GROUP_ID = -1;
#ifdef BROKEN_SETREGID
int
-setregid(rb_gid_t rgid, rb_gid_t egid)
+setregid(rgid, egid)
+ rb_gid_t rgid, egid;
{
if (rgid != -1 && rgid != getgid()) {
if (egid == -1) egid = getegid();
@@ -2854,7 +2799,8 @@ setregid(rb_gid_t rgid, rb_gid_t egid)
*/
static VALUE
-p_gid_change_privilege(VALUE obj, VALUE id)
+p_gid_change_privilege(obj, id)
+ VALUE obj, id;
{
int gid;
@@ -3005,7 +2951,8 @@ p_gid_change_privilege(VALUE obj, VALUE id)
*/
static VALUE
-proc_geteuid(VALUE obj)
+proc_geteuid(obj)
+ VALUE obj;
{
int euid = geteuid();
return INT2FIX(euid);
@@ -3021,7 +2968,8 @@ proc_geteuid(VALUE obj)
*/
static VALUE
-proc_seteuid(VALUE obj, VALUE euid)
+proc_seteuid(obj, euid)
+ VALUE obj, euid;
{
check_uid_switch();
#if defined(HAVE_SETRESUID) && !defined(__CHECKER__)
@@ -3045,7 +2993,8 @@ proc_seteuid(VALUE obj, VALUE euid)
}
static VALUE
-rb_seteuid_core(int euid)
+rb_seteuid_core(euid)
+ int euid;
{
int uid;
@@ -3094,7 +3043,8 @@ rb_seteuid_core(int euid)
*/
static VALUE
-p_uid_grant_privilege(VALUE obj, VALUE id)
+p_uid_grant_privilege(obj, id)
+ VALUE obj, id;
{
return rb_seteuid_core(NUM2INT(id));
}
@@ -3113,7 +3063,8 @@ p_uid_grant_privilege(VALUE obj, VALUE id)
*/
static VALUE
-proc_getegid(VALUE obj)
+proc_getegid(obj)
+ VALUE obj;
{
int egid = getegid();
@@ -3130,7 +3081,8 @@ proc_getegid(VALUE obj)
*/
static VALUE
-proc_setegid(VALUE obj, VALUE egid)
+proc_setegid(obj, egid)
+ VALUE obj, egid;
{
check_gid_switch();
@@ -3155,7 +3107,8 @@ proc_setegid(VALUE obj, VALUE egid)
}
static VALUE
-rb_setegid_core(int egid)
+rb_setegid_core(egid)
+ int egid;
{
int gid;
@@ -3204,7 +3157,8 @@ rb_setegid_core(int egid)
*/
static VALUE
-p_gid_grant_privilege(VALUE obj, VALUE id)
+p_gid_grant_privilege(obj, id)
+ VALUE obj, id;
{
return rb_setegid_core(NUM2INT(id));
}
@@ -3220,7 +3174,7 @@ p_gid_grant_privilege(VALUE obj, VALUE id)
*/
static VALUE
-p_uid_exchangeable(void)
+p_uid_exchangeable()
{
#if defined(HAVE_SETRESUID) && !defined(__CHECKER__)
return Qtrue;
@@ -3245,7 +3199,8 @@ p_uid_exchangeable(void)
*/
static VALUE
-p_uid_exchange(VALUE obj)
+p_uid_exchange(obj)
+ VALUE obj;
{
int uid, euid;
@@ -3277,7 +3232,7 @@ p_uid_exchange(VALUE obj)
*/
static VALUE
-p_gid_exchangeable(void)
+p_gid_exchangeable()
{
#if defined(HAVE_SETRESGID) && !defined(__CHECKER__)
return Qtrue;
@@ -3302,7 +3257,8 @@ p_gid_exchangeable(void)
*/
static VALUE
-p_gid_exchange(VALUE obj)
+p_gid_exchange(obj)
+ VALUE obj;
{
int gid, egid;
@@ -3335,7 +3291,7 @@ p_gid_exchange(VALUE obj)
*/
static VALUE
-p_uid_have_saved_id(void)
+p_uid_have_saved_id()
{
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS)
return Qtrue;
@@ -3347,7 +3303,8 @@ p_uid_have_saved_id(void)
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS)
static VALUE
-p_uid_sw_ensure(int id)
+p_uid_sw_ensure(id)
+ int id;
{
under_uid_switch = 0;
return rb_seteuid_core(id);
@@ -3368,7 +3325,8 @@ p_uid_sw_ensure(int id)
*/
static VALUE
-p_uid_switch(VALUE obj)
+p_uid_switch(obj)
+ VALUE obj;
{
int uid, euid;
@@ -3400,14 +3358,16 @@ p_uid_switch(VALUE obj)
#else
static VALUE
-p_uid_sw_ensure(VALUE obj)
+p_uid_sw_ensure(obj)
+ VALUE obj;
{
under_uid_switch = 0;
return p_uid_exchange(obj);
}
static VALUE
-p_uid_switch(VALUE obj)
+p_uid_switch(obj)
+ VALUE obj;
{
int uid, euid;
@@ -3443,7 +3403,7 @@ p_uid_switch(VALUE obj)
*/
static VALUE
-p_gid_have_saved_id(void)
+p_gid_have_saved_id()
{
#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || defined(_POSIX_SAVED_IDS)
return Qtrue;
@@ -3454,7 +3414,8 @@ p_gid_have_saved_id(void)
#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || defined(_POSIX_SAVED_IDS)
static VALUE
-p_gid_sw_ensure(int id)
+p_gid_sw_ensure(id)
+ int id;
{
under_gid_switch = 0;
return rb_setegid_core(id);
@@ -3475,7 +3436,8 @@ p_gid_sw_ensure(int id)
*/
static VALUE
-p_gid_switch(VALUE obj)
+p_gid_switch(obj)
+ VALUE obj;
{
int gid, egid;
@@ -3506,14 +3468,16 @@ p_gid_switch(VALUE obj)
}
#else
static VALUE
-p_gid_sw_ensure(VALUE obj)
+p_gid_sw_ensure(obj)
+ VALUE obj;
{
under_gid_switch = 0;
return p_gid_exchange(obj);
}
static VALUE
-p_gid_switch(VALUE obj)
+p_gid_switch(obj)
+ VALUE obj;
{
int gid, egid;
@@ -3550,7 +3514,8 @@ p_gid_switch(VALUE obj)
*/
VALUE
-rb_proc_times(VALUE obj)
+rb_proc_times(obj)
+ VALUE obj;
{
#if defined(HAVE_TIMES) && !defined(__CHECKER__)
const double hertz =
@@ -3592,7 +3557,7 @@ VALUE rb_mProcID_Syscall;
*/
void
-Init_process(void)
+Init_process()
{
rb_define_virtual_variable("$$", get_pid, 0);
rb_define_readonly_variable("$?", &rb_last_status);
@@ -3600,7 +3565,6 @@ Init_process(void)
rb_define_global_function("fork", rb_f_fork, 0);
rb_define_global_function("exit!", rb_f_exit_bang, -1);
rb_define_global_function("system", rb_f_system, -1);
- rb_define_global_function("spawn", rb_f_spawn, -1);
rb_define_global_function("sleep", rb_f_sleep, -1);
rb_mProcess = rb_define_module("Process");
@@ -3618,9 +3582,7 @@ Init_process(void)
#endif
#endif
- rb_define_singleton_method(rb_mProcess, "exec", rb_f_exec, -1);
rb_define_singleton_method(rb_mProcess, "fork", rb_f_fork, 0);
- rb_define_singleton_method(rb_mProcess, "spawn", rb_f_spawn, -1);
rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1);
rb_define_singleton_method(rb_mProcess, "exit", rb_f_exit, -1); /* in eval.c */
rb_define_singleton_method(rb_mProcess, "abort", rb_f_abort, -1); /* in eval.c */
@@ -3735,8 +3697,6 @@ Init_process(void)
rb_define_module_function(rb_mProcess, "maxgroups", proc_getmaxgroups, 0);
rb_define_module_function(rb_mProcess, "maxgroups=", proc_setmaxgroups, 1);
- rb_define_module_function(rb_mProcess, "daemon", proc_daemon, -1);
-
rb_define_module_function(rb_mProcess, "times", rb_proc_times, 0);
#if defined(HAVE_TIMES) || defined(_WIN32)
@@ -3757,8 +3717,8 @@ Init_process(void)
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_mProcUID, "eid=", "grant_privilege");
- rb_define_alias(rb_mProcGID, "eid=", "grant_privilege");
+ rb_define_alias(rb_singleton_class(rb_mProcUID), "eid=", "grant_privilege");
+ rb_define_alias(rb_singleton_class(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 8dad78a274..eb9803af07 100644
--- a/random.c
+++ b/random.c
@@ -76,7 +76,8 @@ static unsigned long *next;
/* initializes state[N] with a seed */
static void
-init_genrand(unsigned long s)
+init_genrand(s)
+ unsigned long s;
{
int j;
state[0]= s & 0xffffffffUL;
@@ -123,7 +124,7 @@ init_by_array(unsigned long init_key[], int key_length)
}
static void
-next_state(void)
+next_state()
{
unsigned long *p=state;
int j;
@@ -145,7 +146,7 @@ next_state(void)
}
/* generates a random number on [0,0xffffffff]-interval */
-unsigned long
+static unsigned long
genrand_int32(void)
{
unsigned long y;
@@ -163,8 +164,8 @@ genrand_int32(void)
}
/* generates a random number on [0,1) with 53-bit resolution*/
-double
-genrand_real(void)
+static double
+genrand_real(void)
{
unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
return(a*67108864.0+b)*(1.0/9007199254740992.0);
@@ -188,10 +189,12 @@ genrand_real(void)
#include <fcntl.h>
#endif
+static int first = 1;
static VALUE saved_seed = INT2FIX(0);
static VALUE
-rand_init(VALUE vseed)
+rand_init(vseed)
+ VALUE vseed;
{
volatile VALUE seed;
VALUE old;
@@ -242,6 +245,7 @@ rand_init(VALUE vseed)
len--;
init_by_array(buf, len);
}
+ first = 0;
old = saved_seed;
saved_seed = seed;
free(buf);
@@ -249,7 +253,7 @@ rand_init(VALUE vseed)
}
static VALUE
-random_seed(void)
+random_seed()
{
static int n = 0;
struct timeval tv;
@@ -306,8 +310,8 @@ random_seed(void)
* 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
- * or zero, seeds the generator using a combination of the time, the
+ * <i>number</i>.<code>to_i.abs</code>. If <i>number</i> is omitted,
+ * 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
@@ -316,7 +320,10 @@ random_seed(void)
*/
static VALUE
-rb_f_srand(int argc, VALUE *argv, VALUE obj)
+rb_f_srand(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE seed, old;
@@ -429,12 +436,18 @@ limited_big_rand(struct RBignum *limit)
*/
static VALUE
-rb_f_rand(int argc, VALUE *argv, VALUE obj)
+rb_f_rand(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
VALUE vmax;
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) {
@@ -468,6 +481,7 @@ rb_f_rand(int argc, VALUE *argv, VALUE obj)
default:
vmax = rb_Integer(vmax);
if (TYPE(vmax) == T_BIGNUM) goto bignum;
+ /* fall through */
case T_FIXNUM:
max = FIX2LONG(vmax);
break;
@@ -482,9 +496,8 @@ rb_f_rand(int argc, VALUE *argv, VALUE obj)
}
void
-Init_Random(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 8d5bae8179..568b24d4b8 100644
--- a/range.c
+++ b/range.c
@@ -11,7 +11,6 @@
**********************************************************************/
#include "ruby.h"
-#include "env.h"
VALUE rb_cRange;
static ID id_cmp, id_succ, id_beg, id_end, id_excl;
@@ -20,20 +19,23 @@ static ID id_cmp, id_succ, id_beg, id_end, id_excl;
#define SET_EXCL(r,v) rb_ivar_set((r), id_excl, (v) ? Qtrue : Qfalse)
static VALUE
-range_failed(void)
+range_failed()
{
rb_raise(rb_eArgError, "bad value for range");
return Qnil; /* dummy */
}
static VALUE
-range_check(VALUE *args)
+range_check(args)
+ VALUE *args;
{
return rb_funcall(args[0], id_cmp, 1, args[1]);
}
static void
-range_init(VALUE range, VALUE beg, VALUE end, int exclude_end)
+range_init(range, beg, end, exclude_end)
+ VALUE range, beg, end;
+ int exclude_end;
{
VALUE args[2];
@@ -53,7 +55,9 @@ range_init(VALUE range, VALUE beg, VALUE end, int exclude_end)
}
VALUE
-rb_range_new(VALUE beg, VALUE end, int exclude_end)
+rb_range_new(beg, end, exclude_end)
+ VALUE beg, end;
+ int exclude_end;
{
VALUE range = rb_obj_alloc(rb_cRange);
@@ -71,7 +75,10 @@ rb_range_new(VALUE beg, VALUE end, int exclude_end)
*/
static VALUE
-range_initialize(int argc, VALUE *argv, VALUE range)
+range_initialize(argc, argv, range)
+ int argc;
+ VALUE *argv;
+ VALUE range;
{
VALUE beg, end, flags;
@@ -93,7 +100,8 @@ range_initialize(int argc, VALUE *argv, VALUE range)
*/
static VALUE
-range_exclude_end_p(VALUE range)
+range_exclude_end_p(range)
+ VALUE range;
{
return EXCL(range) ? Qtrue : Qfalse;
}
@@ -114,7 +122,8 @@ range_exclude_end_p(VALUE range)
*/
static VALUE
-range_eq(VALUE range, VALUE obj)
+range_eq(range, obj)
+ VALUE range, obj;
{
if (range == obj) return Qtrue;
if (!rb_obj_is_instance_of(obj, rb_obj_class(range)))
@@ -131,7 +140,8 @@ range_eq(VALUE range, VALUE obj)
}
static int
-r_lt(VALUE a, VALUE b)
+r_lt(a, b)
+ VALUE a, b;
{
VALUE r = rb_funcall(a, id_cmp, 1, b);
@@ -141,7 +151,8 @@ r_lt(VALUE a, VALUE b)
}
static int
-r_le(VALUE a, VALUE b)
+r_le(a, b)
+ VALUE a, b;
{
int c;
VALUE r = rb_funcall(a, id_cmp, 1, b);
@@ -169,7 +180,8 @@ r_le(VALUE a, VALUE b)
*/
static VALUE
-range_eql(VALUE range, VALUE obj)
+range_eql(range, obj)
+ VALUE range, obj;
{
if (range == obj) return Qtrue;
if (!rb_obj_is_instance_of(obj, rb_obj_class(range)))
@@ -195,7 +207,8 @@ range_eql(VALUE range, VALUE obj)
*/
static VALUE
-range_hash(VALUE range)
+range_hash(range)
+ VALUE range;
{
long hash = EXCL(range);
VALUE v;
@@ -210,15 +223,18 @@ range_hash(VALUE range)
}
static VALUE
-str_step(VALUE arg)
+str_step(args)
+ VALUE *args;
{
- VALUE *args = (VALUE *)arg;
-
return rb_str_upto(args[0], args[1], EXCL(args[2]));
}
static void
-range_each_func(VALUE range, VALUE (*func) (VALUE, void *), VALUE v, VALUE e, void *arg)
+range_each_func(range, func, v, e, arg)
+ VALUE range;
+ void (*func) _((VALUE, void*));
+ VALUE v, e;
+ void *arg;
{
int c;
@@ -238,10 +254,10 @@ range_each_func(VALUE range, VALUE (*func) (VALUE, void *), VALUE v, VALUE e, vo
}
static VALUE
-step_i(VALUE i, void *arg)
+step_i(i, iter)
+ VALUE i;
+ long *iter;
{
- long *iter = (long *)arg;
-
iter[0]--;
if (iter[0] == 0) {
rb_yield(i);
@@ -279,13 +295,14 @@ step_i(VALUE i, void *arg)
static VALUE
-range_step(int argc, VALUE *argv, VALUE range)
+range_step(argc, argv, range)
+ int argc;
+ VALUE *argv;
+ VALUE range;
{
VALUE b, e, step;
long unit;
- RETURN_ENUMERATOR(range, argc, argv);
-
b = rb_ivar_get(range, id_beg);
e = rb_ivar_get(range, id_end);
if (rb_scan_args(argc, argv, "01", &step) == 0) {
@@ -296,14 +313,17 @@ range_step(int argc, VALUE *argv, VALUE range)
if (unit < 0) {
rb_raise(rb_eArgError, "step can't be negative");
}
- if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
if (FIXNUM_P(b) && FIXNUM_P(e)) { /* fixnums are special */
long end = FIX2LONG(e);
long i;
+ if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
if (!EXCL(range)) end += 1;
- for (i=FIX2LONG(b); i<end; i+=unit) {
+ i = FIX2LONG(b);
+ while (i < end) {
rb_yield(LONG2NUM(i));
+ if (i + unit < i) break;
+ i += unit;
}
}
else {
@@ -314,9 +334,11 @@ range_step(int argc, VALUE *argv, VALUE range)
long iter[2];
b = tmp;
+ if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
args[0] = b; args[1] = e; args[2] = range;
iter[0] = 1; iter[1] = unit;
- rb_iterate(str_step, (VALUE)args, step_i, (VALUE)iter);
+ rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i,
+ (VALUE)iter);
}
else if (rb_obj_is_kind_of(b, rb_cNumeric)) {
ID c = rb_intern(EXCL(range) ? "<" : "<=");
@@ -330,10 +352,12 @@ range_step(int argc, VALUE *argv, VALUE range)
else {
long args[2];
+ if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
if (!rb_respond_to(b, id_succ)) {
rb_raise(rb_eTypeError, "can't iterate from %s",
rb_obj_classname(b));
}
+
args[0] = 1;
args[1] = unit;
range_each_func(range, step_i, b, e, args);
@@ -342,11 +366,12 @@ range_step(int argc, VALUE *argv, VALUE range)
return range;
}
-static VALUE
-each_i(VALUE v, void *arg)
+static void
+each_i(v, arg)
+ VALUE v;
+ void *arg;
{
rb_yield(v);
- return Qnil;
}
/*
@@ -368,12 +393,11 @@ each_i(VALUE v, void *arg)
*/
static VALUE
-range_each(VALUE range)
+range_each(range)
+ VALUE range;
{
VALUE beg, end;
- RETURN_ENUMERATOR(range, 0, 0);
-
beg = rb_ivar_get(range, id_beg);
end = rb_ivar_get(range, id_end);
@@ -396,7 +420,8 @@ range_each(VALUE range)
args[0] = beg; args[1] = end; args[2] = range;
iter[0] = 1; iter[1] = 1;
- rb_iterate(str_step, (VALUE)args, step_i, (VALUE)iter);
+ rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i,
+ (VALUE)iter);
}
else {
range_each_func(range, each_i, beg, end, NULL);
@@ -413,7 +438,8 @@ range_each(VALUE range)
*/
static VALUE
-range_first(VALUE range)
+range_first(range)
+ VALUE range;
{
return rb_ivar_get(range, id_beg);
}
@@ -432,95 +458,25 @@ range_first(VALUE range)
static VALUE
-range_last(VALUE range)
+range_last(range)
+ VALUE range;
{
return rb_ivar_get(range, id_end);
}
-/*
- * call-seq:
- * rng.min => obj
- * rng.min {| a,b | block } => obj
- *
- * Returns the minimum value in <i>rng</i>. The second uses
- * the block to compare values. Returns nil if the first
- * value in range is larger than the last value.
- *
- */
-
-
-static VALUE
-range_min(VALUE range)
-{
- if (rb_block_given_p()) {
- return rb_call_super(0, 0);
- }
- else {
- VALUE b = rb_ivar_get(range, id_beg);
- VALUE e = rb_ivar_get(range, id_end);
- int c = rb_cmpint(rb_funcall(b, id_cmp, 1, e), b, e);
-
- if (c > 0) return Qnil;
- return b;
- }
-}
-
-/*
- * call-seq:
- * rng.max => obj
- * rng.max {| a,b | block } => obj
- *
- * Returns the maximum value in <i>rng</i>. The second uses
- * the block to compare values. Returns nil if the first
- * value in range is larger than the last value.
- *
- */
-
-
-static VALUE
-range_max(VALUE range)
-{
- VALUE e = rb_ivar_get(range, id_end);
- int ip = FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cInteger);
-
- if (rb_block_given_p() || (EXCL(range) && !ip)) {
- return rb_call_super(0, 0);
- }
- else {
- VALUE b = rb_ivar_get(range, id_beg);
- int c = rb_cmpint(rb_funcall(b, id_cmp, 1, e), b, e);
-
- if (c > 0) return Qnil;
- if (EXCL(range)) {
- if (FIXNUM_P(e)) {
- return INT2NUM(FIX2INT(e)-1);
- }
- return rb_funcall(e, '-', 1, INT2FIX(1));
- }
- return e;
- }
-}
-
VALUE
-rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
+rb_range_beg_len(range, begp, lenp, len, err)
+ VALUE range;
+ long *begp, *lenp;
+ long len;
+ int err;
{
- VALUE b, e;
- long beg, end, excl;
+ long beg, end, b, e;
- if (rb_obj_is_kind_of(range, rb_cRange)) {
- b = rb_ivar_get(range, id_beg);
- e = rb_ivar_get(range, id_end);
- excl = EXCL(range);
- }
- else {
- b = rb_check_to_integer(range, "begin");
- if (NIL_P(b)) return Qfalse;
- e = rb_check_to_integer(range, "end");
- if (NIL_P(e)) return Qfalse;
- excl = RTEST(rb_funcall(range, rb_intern("exclude_end?"), 0));
- }
- beg = NUM2LONG(b);
- end = NUM2LONG(e);
+ if (!rb_obj_is_kind_of(range, rb_cRange)) return Qfalse;
+
+ beg = b = NUM2LONG(rb_ivar_get(range, id_beg));
+ end = e = NUM2LONG(rb_ivar_get(range, id_end));
if (beg < 0) {
beg += len;
@@ -531,7 +487,7 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
if (end > len) end = len;
}
if (end < 0) end += len;
- if (!excl) end++; /* include end point */
+ if (!EXCL(range)) end++; /* include end point */
len = end - beg;
if (len < 0) len = 0;
@@ -542,7 +498,7 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
out_of_range:
if (err) {
rb_raise(rb_eRangeError, "%ld..%s%ld out of range",
- b, excl ? "." : "", e);
+ b, EXCL(range)? "." : "", e);
}
return Qnil;
}
@@ -555,7 +511,8 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
*/
static VALUE
-range_to_s(VALUE range)
+range_to_s(range)
+ VALUE range;
{
VALUE str, str2;
@@ -571,19 +528,6 @@ range_to_s(VALUE range)
/*
* call-seq:
- * rng.to_splat => array
- *
- * Convert this range object to an array to splat.
- */
-
-static VALUE
-range_to_splat(VALUE range)
-{
- return rb_convert_type(range, T_ARRAY, "Array", "to_a");
-}
-
-/*
- * call-seq:
* rng.inspect => string
*
* Convert this range object to a printable form (using
@@ -593,7 +537,8 @@ range_to_splat(VALUE range)
static VALUE
-range_inspect(VALUE range)
+range_inspect(range)
+ VALUE range;
{
VALUE str, str2;
@@ -630,46 +575,8 @@ range_inspect(VALUE range)
*/
static VALUE
-range_include(VALUE range, VALUE val)
-{
- VALUE beg = rb_ivar_get(range, id_beg);
- VALUE end = rb_ivar_get(range, id_end);
- int nv = FIXNUM_P(beg) || FIXNUM_P(end) ||
- rb_obj_is_kind_of(beg, rb_cNumeric) ||
- rb_obj_is_kind_of(end, rb_cNumeric);
-
- if (nv ||
- !NIL_P(rb_check_to_integer(beg, "to_int")) ||
- !NIL_P(rb_check_to_integer(end, "to_int"))) {
- if (r_le(beg, val)) {
- if (EXCL(range)) {
- if (r_lt(val, end)) return Qtrue;
- }
- else {
- if (r_le(val, end)) return Qtrue;
- }
- }
- return Qfalse;
- }
- ruby_frame->this_func = rb_intern("include?");
- return rb_call_super(1, &val);
-}
-
-
-/*
- * call-seq:
- * rng.cover?(val) => true or false
- *
- * Returns <code>true</code> if <i>obj</i> is between beg and end,
- * i.e <code>beg <= obj <= end</code> (or <i>end</i> exclusive when
- * <code>exclude_end?</code> is true).
- *
- * ("a".."z").cover?("c") #=> true
- * ("a".."z").cover?("5") #=> false
- */
-
-static VALUE
-range_cover(VALUE range, VALUE val)
+range_include(range, val)
+ VALUE range, val;
{
VALUE beg, end;
@@ -740,7 +647,7 @@ range_cover(VALUE range, VALUE val)
*/
void
-Init_Range(void)
+Init_Range()
{
rb_cRange = rb_define_class("Range", rb_cObject);
rb_include_module(rb_cRange, rb_mEnumerable);
@@ -755,17 +662,13 @@ Init_Range(void)
rb_define_method(rb_cRange, "last", range_last, 0);
rb_define_method(rb_cRange, "begin", range_first, 0);
rb_define_method(rb_cRange, "end", range_last, 0);
- rb_define_method(rb_cRange, "min", range_min, 0);
- rb_define_method(rb_cRange, "max", range_max, 0);
rb_define_method(rb_cRange, "to_s", range_to_s, 0);
rb_define_method(rb_cRange, "inspect", range_inspect, 0);
- rb_define_method(rb_cRange, "to_splat", range_to_splat, 0);
rb_define_method(rb_cRange, "exclude_end?", range_exclude_end_p, 0);
rb_define_method(rb_cRange, "member?", range_include, 1);
rb_define_method(rb_cRange, "include?", range_include, 1);
- rb_define_method(rb_cRange, "cover?", range_cover, 1);
id_cmp = rb_intern("<=>");
id_succ = rb_intern("succ");
diff --git a/re.c b/re.c
index 1a01490e5b..5553d28dba 100644
--- a/re.c
+++ b/re.c
@@ -5,20 +5,14 @@
$Author$
created at: Mon Aug 9 18:24:49 JST 1993
- Copyright (C) 1993-2006 Yukihiro Matsumoto
+ Copyright (C) 1993-2003 Yukihiro Matsumoto
**********************************************************************/
#include "ruby.h"
#include "re.h"
-#include "regint.h"
#include <ctype.h>
-#define MBCTYPE_ASCII 0
-#define MBCTYPE_EUC 1
-#define MBCTYPE_SJIS 2
-#define MBCTYPE_UTF8 3
-
VALUE rb_eRegexpError;
#define BEG(no) regs->beg[no]
@@ -76,20 +70,24 @@ static const char casetable[] = {
#endif
int
-rb_memcicmp(const void *x, const void *y, long len)
+rb_memcicmp(x, y, len)
+ const void *x, *y;
+ long len;
{
const unsigned char *p1 = x, *p2 = y;
int tmp;
while (len--) {
- if ((tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++]))
+ if ((tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++]) != 0)
return tmp;
}
return 0;
}
int
-rb_memcmp(const void *p1, const void *p2, long len)
+rb_memcmp(p1, p2, len)
+ const void *p1, *p2;
+ long len;
{
if (!ruby_ignorecase) {
return memcmp(p1, p2, len);
@@ -98,9 +96,11 @@ rb_memcmp(const void *p1, const void *p2, long len)
}
long
-rb_memsearch(const void *x0, long m, const void *y0, long n)
+rb_memsearch(x0, m, y0, n)
+ const void *x0, *y0;
+ long m, n;
{
- const unsigned char *x = x0, *y = y0;
+ const unsigned char *x = (unsigned char *)x0, *y = (unsigned char *)y0;
const unsigned char *s, *e;
long i;
int d;
@@ -154,7 +154,6 @@ rb_memsearch(const void *x0, long m, const void *y0, long n)
#define REG_LITERAL FL_USER5
#define REG_CASESTATE FL_USER0
-
#define KCODE_NONE 0
#define KCODE_EUC FL_USER1
#define KCODE_SJIS FL_USER2
@@ -162,131 +161,48 @@ rb_memsearch(const void *x0, long m, const void *y0, long n)
#define KCODE_FIXED FL_USER4
#define KCODE_MASK (KCODE_EUC|KCODE_SJIS|KCODE_UTF8)
-#define ARG_REG_OPTION_MASK 0x0f
-#define ARG_KCODE_UNIT 16
-#define ARG_KCODE_NONE (ARG_KCODE_UNIT * 1)
-#define ARG_KCODE_EUC (ARG_KCODE_UNIT * 2)
-#define ARG_KCODE_SJIS (ARG_KCODE_UNIT * 3)
-#define ARG_KCODE_UTF8 (ARG_KCODE_UNIT * 4)
-#define ARG_KCODE_MASK (ARG_KCODE_UNIT * 7)
-
static int reg_kcode = DEFAULT_KCODE;
-static int char_to_option(int c)
+static void
+kcode_euc(re)
+ struct RRegexp *re;
{
- int val;
-
- switch (c) {
- case 'i':
- val = ONIG_OPTION_IGNORECASE;
- break;
- case 'x':
- val = ONIG_OPTION_EXTEND;
- break;
- case 'm':
- val = ONIG_OPTION_MULTILINE;
- break;
- default:
- val = 0;
- break;
- }
- return val;
+ FL_UNSET(re, KCODE_MASK);
+ FL_SET(re, KCODE_EUC);
+ FL_SET(re, KCODE_FIXED);
}
-extern int rb_char_to_option_kcode(int c, int *option, int *kcode)
+static void
+kcode_sjis(re)
+ struct RRegexp *re;
{
- *option = 0;
-
- switch (c) {
- case 'n':
- *kcode = ARG_KCODE_NONE;
- break;
- case 'e':
- *kcode = ARG_KCODE_EUC;
- break;
- case 's':
- *kcode = ARG_KCODE_SJIS;
- break;
- case 'u':
- *kcode = ARG_KCODE_UTF8;
- break;
- default:
- *kcode = 0;
- *option = char_to_option(c);
- break;
- }
-
- return ((*kcode == 0 && *option == 0) ? 0 : 1);
+ FL_UNSET(re, KCODE_MASK);
+ FL_SET(re, KCODE_SJIS);
+ FL_SET(re, KCODE_FIXED);
}
-static int char_to_arg_kcode(int c)
+static void
+kcode_utf8(re)
+ struct RRegexp *re;
{
- int kcode, option;
-
- if (ISUPPER(c)) c = tolower(c);
-
- (void )rb_char_to_option_kcode(c, &option, &kcode);
- return kcode;
-}
-
-static int
-kcode_to_arg_value(unsigned int kcode)
-{
- switch (kcode & KCODE_MASK) {
- case KCODE_NONE:
- return ARG_KCODE_NONE;
- case KCODE_EUC:
- return ARG_KCODE_EUC;
- case KCODE_SJIS:
- return ARG_KCODE_SJIS;
- case KCODE_UTF8:
- return ARG_KCODE_UTF8;
- default:
- return 0;
- }
+ FL_UNSET(re, KCODE_MASK);
+ FL_SET(re, KCODE_UTF8);
+ FL_SET(re, KCODE_FIXED);
}
static void
-set_re_kcode_by_option(struct RRegexp *re, int options)
-{
- switch (options & ARG_KCODE_MASK) {
- case ARG_KCODE_NONE:
- FL_UNSET(re, KCODE_MASK);
- FL_SET(re, KCODE_FIXED);
- break;
- case ARG_KCODE_EUC:
- FL_UNSET(re, KCODE_MASK);
- FL_SET(re, KCODE_EUC);
- FL_SET(re, KCODE_FIXED);
- break;
- case ARG_KCODE_SJIS:
- FL_UNSET(re, KCODE_MASK);
- FL_SET(re, KCODE_SJIS);
- FL_SET(re, KCODE_FIXED);
- break;
- case ARG_KCODE_UTF8:
- FL_UNSET(re, KCODE_MASK);
- FL_SET(re, KCODE_UTF8);
- FL_SET(re, KCODE_FIXED);
- break;
-
- case 0:
- default:
- FL_SET(re, reg_kcode);
- break;
- }
-}
-
-static int
-re_to_kcode_arg_value(VALUE re)
+kcode_none(re)
+ struct RRegexp *re;
{
- return kcode_to_arg_value(RBASIC(re)->flags);
+ FL_UNSET(re, KCODE_MASK);
+ FL_SET(re, KCODE_FIXED);
}
static int curr_kcode;
-static void
-kcode_set_option(VALUE re)
+void
+rb_kcode_set_option(re)
+ VALUE re;
{
if (!FL_TEST(re, KCODE_FIXED)) return;
@@ -294,64 +210,71 @@ kcode_set_option(VALUE re)
if (reg_kcode == curr_kcode) return;
switch (curr_kcode) {
case KCODE_NONE:
- onigenc_set_default_encoding(ONIG_ENCODING_ASCII);
+ re_mbcinit(MBCTYPE_ASCII);
break;
case KCODE_EUC:
- onigenc_set_default_encoding(ONIG_ENCODING_EUC_JP);
+ re_mbcinit(MBCTYPE_EUC);
break;
case KCODE_SJIS:
- onigenc_set_default_encoding(ONIG_ENCODING_SJIS);
+ re_mbcinit(MBCTYPE_SJIS);
break;
case KCODE_UTF8:
- onigenc_set_default_encoding(ONIG_ENCODING_UTF8);
+ re_mbcinit(MBCTYPE_UTF8);
break;
}
-}
+}
-static void
-kcode_reset_option(void)
+void
+rb_kcode_reset_option()
{
if (reg_kcode == curr_kcode) return;
switch (reg_kcode) {
case KCODE_NONE:
- onigenc_set_default_encoding(ONIG_ENCODING_ASCII);
+ re_mbcinit(MBCTYPE_ASCII);
break;
case KCODE_EUC:
- onigenc_set_default_encoding(ONIG_ENCODING_EUC_JP);
+ re_mbcinit(MBCTYPE_EUC);
break;
case KCODE_SJIS:
- onigenc_set_default_encoding(ONIG_ENCODING_SJIS);
+ re_mbcinit(MBCTYPE_SJIS);
break;
case KCODE_UTF8:
- onigenc_set_default_encoding(ONIG_ENCODING_UTF8);
+ re_mbcinit(MBCTYPE_UTF8);
break;
}
}
int
-rb_reg_mbclen2(unsigned int c, VALUE re)
+rb_reg_mbclen2(c, re)
+ unsigned int c;
+ VALUE re;
{
int len;
- unsigned char uc = (unsigned char)c;
if (!FL_TEST(re, KCODE_FIXED))
- return mbclen(uc);
- kcode_set_option(re);
- len = mbclen(uc);
- kcode_reset_option();
+ return mbclen(c);
+ rb_kcode_set_option(re);
+ len = mbclen(c);
+ rb_kcode_reset_option();
return len;
}
static void
-rb_reg_check(VALUE re)
+rb_reg_check(re)
+ VALUE re;
{
if (!RREGEXP(re)->ptr || !RREGEXP(re)->str) {
rb_raise(rb_eTypeError, "uninitialized Regexp");
}
}
+extern int ruby_in_compile;
+
static void
-rb_reg_expr_str(VALUE str, const char *s, long len)
+rb_reg_expr_str(str, s, len)
+ VALUE str;
+ const char *s;
+ long len;
{
const char *p, *pend;
int need_escape = 0;
@@ -368,7 +291,7 @@ rb_reg_expr_str(VALUE str, const char *s, long len)
rb_str_buf_cat(str, s, len);
}
else {
- p = s;
+ p = s;
while (p<pend) {
if (*p == '\\') {
int n = mbclen(p[1]) + 1;
@@ -404,7 +327,10 @@ rb_reg_expr_str(VALUE str, const char *s, long len)
}
static VALUE
-rb_reg_desc(const char *s, long len, VALUE re)
+rb_reg_desc(s, len, re)
+ const char *s;
+ long len;
+ VALUE re;
{
VALUE str = rb_str_buf_new2("/");
@@ -412,13 +338,13 @@ rb_reg_desc(const char *s, long len, VALUE re)
rb_str_buf_cat2(str, "/");
if (re) {
rb_reg_check(re);
- if (RREGEXP(re)->ptr->options & ONIG_OPTION_MULTILINE)
+ if (RREGEXP(re)->ptr->options & RE_OPTION_MULTILINE)
rb_str_buf_cat2(str, "m");
- if (RREGEXP(re)->ptr->options & ONIG_OPTION_IGNORECASE)
+ if (RREGEXP(re)->ptr->options & RE_OPTION_IGNORECASE)
rb_str_buf_cat2(str, "i");
- if (RREGEXP(re)->ptr->options & ONIG_OPTION_EXTEND)
+ if (RREGEXP(re)->ptr->options & RE_OPTION_EXTENDED)
rb_str_buf_cat2(str, "x");
-
+
if (FL_TEST(re, KCODE_FIXED)) {
switch ((RBASIC(re)->flags & KCODE_MASK)) {
case KCODE_NONE:
@@ -451,7 +377,8 @@ rb_reg_desc(const char *s, long len, VALUE re)
*/
static VALUE
-rb_reg_source(VALUE re)
+rb_reg_source(re)
+ VALUE re;
{
VALUE str;
@@ -473,7 +400,8 @@ rb_reg_source(VALUE re)
*/
static VALUE
-rb_reg_inspect(VALUE re)
+rb_reg_inspect(re)
+ VALUE re;
{
rb_reg_check(re);
return rb_reg_desc(RREGEXP(re)->str, RREGEXP(re)->len, re);
@@ -501,18 +429,19 @@ rb_reg_inspect(VALUE re)
*/
static VALUE
-rb_reg_to_s(VALUE re)
+rb_reg_to_s(re)
+ VALUE re;
{
- int options, opt;
- const int embeddable = ONIG_OPTION_MULTILINE|ONIG_OPTION_IGNORECASE|ONIG_OPTION_EXTEND;
+ int options;
+ const int embeddable = RE_OPTION_MULTILINE|RE_OPTION_IGNORECASE|RE_OPTION_EXTENDED;
long len;
- const UChar* ptr;
+ const char* ptr;
VALUE str = rb_str_buf_new2("(?");
rb_reg_check(re);
options = RREGEXP(re)->ptr->options;
- ptr = (UChar*)RREGEXP(re)->str;
+ ptr = RREGEXP(re)->str;
len = RREGEXP(re)->len;
again:
if (len >= 4 && ptr[0] == '(' && ptr[1] == '?') {
@@ -520,13 +449,16 @@ rb_reg_to_s(VALUE re)
ptr += 2;
if ((len -= 2) > 0) {
do {
- opt = char_to_option((int )*ptr);
- if (opt != 0) {
- options |= opt;
- }
- else {
- break;
- }
+ if (*ptr == 'm') {
+ options |= RE_OPTION_MULTILINE;
+ }
+ else if (*ptr == 'i') {
+ options |= RE_OPTION_IGNORECASE;
+ }
+ else if (*ptr == 'x') {
+ options |= RE_OPTION_EXTENDED;
+ }
+ else break;
++ptr;
} while (--len > 0);
}
@@ -534,13 +466,16 @@ rb_reg_to_s(VALUE re)
++ptr;
--len;
do {
- opt = char_to_option((int )*ptr);
- if (opt != 0) {
- options &= ~opt;
- }
- else {
- break;
- }
+ if (*ptr == 'm') {
+ options &= ~RE_OPTION_MULTILINE;
+ }
+ else if (*ptr == 'i') {
+ options &= ~RE_OPTION_IGNORECASE;
+ }
+ else if (*ptr == 'x') {
+ options &= ~RE_OPTION_EXTENDED;
+ }
+ else break;
++ptr;
} while (--len > 0);
}
@@ -550,41 +485,34 @@ rb_reg_to_s(VALUE re)
goto again;
}
if (*ptr == ':' && ptr[len-1] == ')') {
- int r;
Regexp *rp;
- kcode_set_option(re);
- r = onig_alloc_init(&rp, ONIG_OPTION_DEFAULT,
- ONIGENC_AMBIGUOUS_MATCH_DEFAULT,
- onigenc_get_default_encoding(),
- OnigDefaultSyntax);
- if (r == 0) {
- ++ptr;
- len -= 2;
- err = (onig_compile(rp, ptr, ptr + len, NULL) != 0);
- }
- kcode_reset_option();
- onig_free(rp);
+ rb_kcode_set_option(re);
+ rp = ALLOC(Regexp);
+ MEMZERO((char *)rp, Regexp, 1);
+ err = re_compile_pattern(++ptr, len -= 2, rp) != 0;
+ rb_kcode_reset_option();
+ re_free_pattern(rp);
}
if (err) {
options = RREGEXP(re)->ptr->options;
- ptr = (UChar*)RREGEXP(re)->str;
+ ptr = RREGEXP(re)->str;
len = RREGEXP(re)->len;
}
}
- if (options & ONIG_OPTION_MULTILINE) rb_str_buf_cat2(str, "m");
- if (options & ONIG_OPTION_IGNORECASE) rb_str_buf_cat2(str, "i");
- if (options & ONIG_OPTION_EXTEND) rb_str_buf_cat2(str, "x");
+ if (options & RE_OPTION_MULTILINE) rb_str_buf_cat2(str, "m");
+ if (options & RE_OPTION_IGNORECASE) rb_str_buf_cat2(str, "i");
+ if (options & RE_OPTION_EXTENDED) rb_str_buf_cat2(str, "x");
if ((options & embeddable) != embeddable) {
rb_str_buf_cat2(str, "-");
- if (!(options & ONIG_OPTION_MULTILINE)) rb_str_buf_cat2(str, "m");
- if (!(options & ONIG_OPTION_IGNORECASE)) rb_str_buf_cat2(str, "i");
- if (!(options & ONIG_OPTION_EXTEND)) rb_str_buf_cat2(str, "x");
+ if (!(options & RE_OPTION_MULTILINE)) rb_str_buf_cat2(str, "m");
+ if (!(options & RE_OPTION_IGNORECASE)) rb_str_buf_cat2(str, "i");
+ if (!(options & RE_OPTION_EXTENDED)) rb_str_buf_cat2(str, "x");
}
rb_str_buf_cat2(str, ":");
- rb_reg_expr_str(str, (char*)ptr, len);
+ rb_reg_expr_str(str, ptr, len);
rb_str_buf_cat2(str, ")");
OBJ_INFECT(str, re);
@@ -592,14 +520,18 @@ rb_reg_to_s(VALUE re)
}
static void
-rb_reg_raise(const char *s, long len, const char *err, VALUE re, int ce)
+rb_reg_raise(s, len, err, re)
+ const char *s;
+ long len;
+ const char *err;
+ VALUE re;
{
VALUE desc = rb_reg_desc(s, len, re);
- if (ce)
- rb_compile_error("%s: %s", err, RSTRING_PTR(desc));
+ if (ruby_in_compile)
+ rb_compile_error("%s: %s", err, RSTRING(desc)->ptr);
else
- rb_raise(rb_eRegexpError, "%s: %s", err, RSTRING_PTR(desc));
+ rb_raise(rb_eRegexpError, "%s: %s", err, RSTRING(desc)->ptr);
}
@@ -611,10 +543,11 @@ rb_reg_raise(const char *s, long len, const char *err, VALUE re, int ce)
*/
static VALUE
-rb_reg_casefold_p(VALUE re)
+rb_reg_casefold_p(re)
+ VALUE re;
{
rb_reg_check(re);
- if (RREGEXP(re)->ptr->options & ONIG_OPTION_IGNORECASE) return Qtrue;
+ if (RREGEXP(re)->ptr->options & RE_OPTION_IGNORECASE) return Qtrue;
return Qfalse;
}
@@ -643,7 +576,8 @@ rb_reg_casefold_p(VALUE re)
*/
static VALUE
-rb_reg_options_m(VALUE re)
+rb_reg_options_m(re)
+ VALUE re;
{
int options = rb_reg_options(re);
return INT2NUM(options);
@@ -658,9 +592,10 @@ rb_reg_options_m(VALUE re)
*/
static VALUE
-rb_reg_kcode_m(VALUE re)
+rb_reg_kcode_m(re)
+ VALUE re;
{
- const char *kcode;
+ char *kcode;
if (FL_TEST(re, KCODE_FIXED)) {
switch (RBASIC(re)->flags & KCODE_MASK) {
@@ -682,12 +617,13 @@ rb_reg_kcode_m(VALUE re)
}
static Regexp*
-make_regexp(const char *s, long len, int flags, int ce)
+make_regexp(s, len, flags)
+ const char *s;
+ long len;
+ int flags;
{
Regexp *rp;
- char err[ONIG_MAX_ERROR_MESSAGE_LEN];
- int r;
- OnigErrorInfo einfo;
+ char *err;
/* Handle escaped characters first. */
@@ -696,21 +632,19 @@ make_regexp(const char *s, long len, int flags, int ce)
from that.
*/
- r = onig_alloc_init(&rp, flags,
- ONIGENC_AMBIGUOUS_MATCH_DEFAULT,
- onigenc_get_default_encoding(),
- OnigDefaultSyntax);
- if (r) {
- onig_error_code_to_str((UChar*)err, r);
- rb_reg_raise(s, len, err, 0, ce);
+ rp = ALLOC(Regexp);
+ MEMZERO((char *)rp, Regexp, 1);
+ rp->buffer = ALLOC_N(char, 16);
+ rp->allocated = 16;
+ rp->fastmap = ALLOC_N(char, 256);
+ if (flags) {
+ rp->options = flags;
}
+ err = re_compile_pattern(s, len, rp);
- r = onig_compile(rp, (UChar*)s, (UChar*)(s + len), &einfo);
-
- if (r != 0) {
- onig_free(rp);
- (void )onig_error_code_to_str((UChar*)err, r, &einfo);
- rb_reg_raise(s, len, err, 0, ce);
+ if (err != NULL) {
+ re_free_pattern(rp);
+ rb_reg_raise(s, len, err, 0);
return 0;
}
return rp;
@@ -732,15 +666,16 @@ make_regexp(const char *s, long len, int flags, int ce)
VALUE rb_cMatch;
+static VALUE match_alloc _((VALUE));
static VALUE
-match_alloc(VALUE klass)
+match_alloc(klass)
+ VALUE klass;
{
NEWOBJ(match, struct RMatch);
OBJSETUP(match, klass, T_MATCH);
match->str = 0;
match->regs = 0;
- match->regexp = 0;
match->regs = ALLOC(struct re_registers);
MEMZERO(match->regs, struct re_registers, 1);
@@ -749,7 +684,8 @@ match_alloc(VALUE klass)
/* :nodoc: */
static VALUE
-match_init_copy(VALUE obj, VALUE orig)
+match_init_copy(obj, orig)
+ VALUE obj, orig;
{
if (obj == orig) return obj;
@@ -757,9 +693,9 @@ match_init_copy(VALUE obj, VALUE orig)
rb_raise(rb_eTypeError, "wrong argument class");
}
RMATCH(obj)->str = RMATCH(orig)->str;
- onig_region_free(RMATCH(obj)->regs, 0);
+ re_free_registers(RMATCH(obj)->regs);
RMATCH(obj)->regs->allocated = 0;
- onig_region_copy(RMATCH(obj)->regs, RMATCH(orig)->regs);
+ re_copy_registers(RMATCH(obj)->regs, RMATCH(orig)->regs);
return obj;
}
@@ -778,7 +714,8 @@ match_init_copy(VALUE obj, VALUE orig)
*/
static VALUE
-match_size(VALUE match)
+match_size(match)
+ VALUE match;
{
return INT2FIX(RMATCH(match)->regs->num_regs);
}
@@ -797,7 +734,8 @@ match_size(VALUE match)
*/
static VALUE
-match_offset(VALUE match, VALUE n)
+match_offset(match, n)
+ VALUE match, n;
{
int i = NUM2INT(n);
@@ -825,7 +763,8 @@ match_offset(VALUE match, VALUE n)
*/
static VALUE
-match_begin(VALUE match, VALUE n)
+match_begin(match, n)
+ VALUE match, n;
{
int i = NUM2INT(n);
@@ -852,7 +791,8 @@ match_begin(VALUE match, VALUE n)
*/
static VALUE
-match_end(VALUE match, VALUE n)
+match_end(match, n)
+ VALUE match, n;
{
int i = NUM2INT(n);
@@ -868,7 +808,8 @@ match_end(VALUE match, VALUE n)
#define MATCH_BUSY FL_USER2
void
-rb_match_busy(VALUE match)
+rb_match_busy(match)
+ VALUE match;
{
FL_SET(match, MATCH_BUSY);
}
@@ -877,7 +818,8 @@ int ruby_ignorecase;
static int may_need_recompile;
static void
-rb_reg_prepare_re(VALUE re)
+rb_reg_prepare_re(re)
+ VALUE re;
{
int need_recompile = 0;
int state;
@@ -887,12 +829,12 @@ rb_reg_prepare_re(VALUE re)
/* ignorecase status */
if (ruby_ignorecase && !state) {
FL_SET(re, REG_CASESTATE);
- RREGEXP(re)->ptr->options |= ONIG_OPTION_IGNORECASE;
+ RREGEXP(re)->ptr->options |= RE_OPTION_IGNORECASE;
need_recompile = 1;
}
if (!ruby_ignorecase && state) {
FL_UNSET(re, REG_CASESTATE);
- RREGEXP(re)->ptr->options &= ~ONIG_OPTION_IGNORECASE;
+ RREGEXP(re)->ptr->options &= ~RE_OPTION_IGNORECASE;
need_recompile = 1;
}
@@ -904,80 +846,56 @@ rb_reg_prepare_re(VALUE re)
}
if (need_recompile) {
- char err[ONIG_MAX_ERROR_MESSAGE_LEN];
- int r;
- OnigErrorInfo einfo;
- regex_t *reg, *reg2;
- UChar *pattern;
+ char *err;
if (FL_TEST(re, KCODE_FIXED))
- kcode_set_option(re);
+ rb_kcode_set_option(re);
rb_reg_check(re);
- reg = RREGEXP(re)->ptr;
- pattern = ((UChar*)RREGEXP(re)->str);
-
- r = onig_new(&reg2, (UChar* )pattern,
- (UChar* )(pattern + RREGEXP(re)->len),
- reg->options, onigenc_get_default_encoding(),
- OnigDefaultSyntax, &einfo);
- if (r) {
- onig_error_code_to_str((UChar*)err, r, &einfo);
- rb_reg_raise((char* )pattern, RREGEXP(re)->len, err, re, Qfalse);
+ RREGEXP(re)->ptr->fastmap_accurate = 0;
+ err = re_compile_pattern(RREGEXP(re)->str, RREGEXP(re)->len, RREGEXP(re)->ptr);
+ if (err != NULL) {
+ rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len, err, re);
}
-
- RREGEXP(re)->ptr = reg2;
- onig_free(reg);
}
}
long
-rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, long reverse)
+rb_reg_adjust_startpos(re, str, pos, reverse)
+ VALUE re, str;
+ long pos, reverse;
{
long range;
- OnigEncoding enc;
- UChar *p, *string;
rb_reg_check(re);
if (may_need_recompile) rb_reg_prepare_re(re);
if (FL_TEST(re, KCODE_FIXED))
- kcode_set_option(re);
+ rb_kcode_set_option(re);
else if (reg_kcode != curr_kcode)
- kcode_reset_option();
+ rb_kcode_reset_option();
if (reverse) {
range = -pos;
}
else {
- range = RSTRING_LEN(str) - pos;
- }
-
- enc = (RREGEXP(re)->ptr)->enc;
-
- if (pos > 0 && ONIGENC_MBC_MAXLEN(enc) != 1 && pos < RSTRING_LEN(str)) {
- string = (UChar*)RSTRING_PTR(str);
-
- if (range > 0) {
- p = onigenc_get_right_adjust_char_head(enc, string, string + pos);
- }
- else {
- p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, string, string + pos);
- }
- return p - string;
+ range = RSTRING(str)->len - pos;
}
-
- return pos;
+ return re_adjust_startpos(RREGEXP(re)->ptr,
+ RSTRING(str)->ptr, RSTRING(str)->len,
+ pos, range);
}
long
-rb_reg_search(VALUE re, VALUE str, long pos, long reverse)
+rb_reg_search(re, str, pos, reverse)
+ VALUE re, str;
+ long pos, reverse;
{
long result;
VALUE match;
- static struct re_registers regs;
+ struct re_registers regs;
long range;
- if (pos > RSTRING_LEN(str) || pos < 0) {
+ if (pos > RSTRING(str)->len || pos < 0) {
rb_backref_set(Qnil);
return -1;
}
@@ -986,37 +904,32 @@ rb_reg_search(VALUE re, VALUE str, long pos, long reverse)
if (may_need_recompile) rb_reg_prepare_re(re);
if (FL_TEST(re, KCODE_FIXED))
- kcode_set_option(re);
+ rb_kcode_set_option(re);
else if (reg_kcode != curr_kcode)
- kcode_reset_option();
+ rb_kcode_reset_option();
if (reverse) {
range = -pos;
}
else {
- range = RSTRING_LEN(str) - pos;
+ range = RSTRING(str)->len - pos;
}
-
- result = onig_search(RREGEXP(re)->ptr,
- (UChar*)(RSTRING_PTR(str)),
- ((UChar*)(RSTRING_PTR(str)) + RSTRING_LEN(str)),
- ((UChar*)(RSTRING_PTR(str)) + pos),
- ((UChar*)(RSTRING_PTR(str)) + pos + range),
- &regs, ONIG_OPTION_NONE);
+ MEMZERO(&regs, struct re_registers, 1);
+ result = re_search(RREGEXP(re)->ptr,RSTRING(str)->ptr,RSTRING(str)->len,
+ pos, range, &regs);
if (FL_TEST(re, KCODE_FIXED))
- kcode_reset_option();
+ rb_kcode_reset_option();
+
+ if (result == -2) {
+ rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len,
+ "Stack overflow in regexp matcher", re);
+ }
if (result < 0) {
- if (result == ONIG_MISMATCH) {
- rb_backref_set(Qnil);
- return result;
- }
- else {
- char err[ONIG_MAX_ERROR_MESSAGE_LEN];
- onig_error_code_to_str((UChar*)err, result);
- rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len, err, 0, Qfalse);
- }
+ re_free_registers(&regs);
+ rb_backref_set(Qnil);
+ return result;
}
match = rb_backref_get();
@@ -1024,15 +937,15 @@ rb_reg_search(VALUE re, VALUE str, long pos, long reverse)
match = match_alloc(rb_cMatch);
}
else {
- if (rb_safe_level() >= 3)
+ if (rb_safe_level() >= 3)
OBJ_TAINT(match);
else
FL_UNSET(match, FL_TAINT);
}
- onig_region_copy(RMATCH(match)->regs, &regs);
+ re_copy_registers(RMATCH(match)->regs, &regs);
+ re_free_registers(&regs);
RMATCH(match)->str = rb_str_new4(str);
- RMATCH(match)->regexp = re;
rb_backref_set(match);
OBJ_INFECT(match, re);
@@ -1041,7 +954,9 @@ rb_reg_search(VALUE re, VALUE str, long pos, long reverse)
}
VALUE
-rb_reg_nth_defined(int nth, VALUE match)
+rb_reg_nth_defined(nth, match)
+ int nth;
+ VALUE match;
{
if (NIL_P(match)) return Qnil;
if (nth >= RMATCH(match)->regs->num_regs) {
@@ -1056,7 +971,9 @@ rb_reg_nth_defined(int nth, VALUE match)
}
VALUE
-rb_reg_nth_match(int nth, VALUE match)
+rb_reg_nth_match(nth, match)
+ int nth;
+ VALUE match;
{
VALUE str;
long start, end, len;
@@ -1079,7 +996,8 @@ rb_reg_nth_match(int nth, VALUE match)
}
VALUE
-rb_reg_last_match(VALUE match)
+rb_reg_last_match(match)
+ VALUE match;
{
return rb_reg_nth_match(0, match);
}
@@ -1097,7 +1015,8 @@ rb_reg_last_match(VALUE match)
*/
VALUE
-rb_reg_match_pre(VALUE match)
+rb_reg_match_pre(match)
+ VALUE match;
{
VALUE str;
@@ -1121,7 +1040,8 @@ rb_reg_match_pre(VALUE match)
*/
VALUE
-rb_reg_match_post(VALUE match)
+rb_reg_match_post(match)
+ VALUE match;
{
VALUE str;
long pos;
@@ -1130,13 +1050,14 @@ rb_reg_match_post(VALUE match)
if (RMATCH(match)->BEG(0) == -1) return Qnil;
str = RMATCH(match)->str;
pos = RMATCH(match)->END(0);
- str = rb_str_substr(str, pos, RSTRING_LEN(str) - pos);
+ str = rb_str_substr(str, pos, RSTRING(str)->len - pos);
if (OBJ_TAINTED(match)) OBJ_TAINT(str);
return str;
}
VALUE
-rb_reg_match_last(VALUE match)
+rb_reg_match_last(match)
+ VALUE match;
{
int i;
@@ -1150,38 +1071,40 @@ rb_reg_match_last(VALUE match)
}
static VALUE
-last_match_getter(void)
+last_match_getter()
{
return rb_reg_last_match(rb_backref_get());
}
static VALUE
-prematch_getter(void)
+prematch_getter()
{
return rb_reg_match_pre(rb_backref_get());
}
static VALUE
-postmatch_getter(void)
+postmatch_getter()
{
return rb_reg_match_post(rb_backref_get());
}
static VALUE
-last_paren_match_getter(void)
+last_paren_match_getter()
{
return rb_reg_match_last(rb_backref_get());
}
static VALUE
-match_array(VALUE match, int start)
+match_array(match, start)
+ VALUE match;
+ int start;
{
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);
-
+
for (i=start; i<regs->num_regs; i++) {
if (regs->beg[i] == -1) {
rb_ary_push(ary, Qnil);
@@ -1223,7 +1146,8 @@ match_array(VALUE match, int start)
*/
static VALUE
-match_to_a(VALUE match)
+match_to_a(match)
+ VALUE match;
{
return match_array(match, 0);
}
@@ -1242,34 +1166,18 @@ match_to_a(VALUE match)
* f4 #=> "8"
*/
static VALUE
-match_captures(VALUE match)
+match_captures(match)
+ VALUE match;
{
return match_array(match, 1);
}
-static int
-name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end)
-{
- int num;
-
- num = onig_name_to_backref_number(RREGEXP(regexp)->ptr,
- (const unsigned char* )name, (const unsigned char* )name_end, regs);
- if (num >= 1) {
- return num;
- }
- else {
- VALUE s = rb_str_new(name, (long )(name_end - name));
- rb_raise(rb_eRuntimeError, "undefined group name reference: %s",
- StringValuePtr(s));
- }
-}
/*
* call-seq:
- * mtch[i] => str or nil
+ * mtch[i] => obj
* mtch[start, length] => array
* mtch[range] => array
- * mtch[name] => str or nil
*
* Match Reference---<code>MatchData</code> acts as an array, and may be
* accessed using the normal array indexing techniques. <i>mtch</i>[0] is
@@ -1282,54 +1190,29 @@ name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name
* m[1, 2] #=> ["H", "X"]
* m[1..3] #=> ["H", "X", "113"]
* m[-3, 2] #=> ["X", "113"]
- *
- * m = /(?<foo>a+)b/.match("ccaaab")
- * m["foo"] #=> "aaa"
- * m[:foo] #=> "aaa"
*/
static VALUE
-match_aref(int argc, VALUE *argv, VALUE match)
+match_aref(argc, argv, match)
+ int argc;
+ VALUE *argv;
+ VALUE match;
{
VALUE idx, rest;
rb_scan_args(argc, argv, "11", &idx, &rest);
- if (NIL_P(rest)) {
- if (FIXNUM_P(idx)) {
- if (FIX2INT(idx) >= 0) {
- return rb_reg_nth_match(FIX2INT(idx), match);
- }
- }
- else {
- const char *p;
- int num;
-
- switch (TYPE(idx)) {
- case T_SYMBOL:
- p = rb_id2name(SYM2ID(idx));
- goto name_to_backref;
- break;
- case T_STRING:
- p = StringValuePtr(idx);
-
- name_to_backref:
- num = name_to_backref_number(RMATCH(match)->regs,
- RMATCH(match)->regexp, p, p + strlen(p));
- return rb_reg_nth_match(num, match);
- break;
-
- default:
- break;
- }
- }
+ if (!NIL_P(rest) || !FIXNUM_P(idx) || FIX2INT(idx) < 0) {
+ return rb_ary_aref(argc, argv, match_to_a(match));
}
-
- return rb_ary_aref(argc, argv, match_to_a(match));
+ return rb_reg_nth_match(FIX2INT(idx), match);
}
+static VALUE match_entry _((VALUE, long));
static VALUE
-match_entry(VALUE match, long n)
+match_entry(match, n)
+ VALUE match;
+ long n;
{
return rb_reg_nth_match(n, match);
}
@@ -1337,8 +1220,6 @@ match_entry(VALUE match, long n)
/*
* call-seq:
- if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)
- rb_raise(rb_eSecurityError, "Insecure: can't modify regexp");
* mtch.select([index]*) => array
*
* Uses each <i>index</i> to access the matching values, returning an array of
@@ -1350,9 +1231,12 @@ match_entry(VALUE match, long n)
*/
static VALUE
-match_values_at(int argc, VALUE *argv, VALUE match)
+match_values_at(argc, argv, match)
+ int argc;
+ VALUE *argv;
+ VALUE match;
{
- return rb_get_values_at(match, RMATCH(match)->regs->num_regs, argc, argv, match_entry);
+ return rb_values_at(match, RMATCH(match)->regs->num_regs, argc, argv, match_entry);
}
@@ -1369,7 +1253,10 @@ match_values_at(int argc, VALUE *argv, VALUE match)
*/
static VALUE
-match_select(int argc, VALUE *argv, VALUE match)
+match_select(argc, argv, match)
+ int argc;
+ VALUE *argv;
+ VALUE match;
{
if (argc > 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
@@ -1404,7 +1291,8 @@ match_select(int argc, VALUE *argv, VALUE match)
*/
static VALUE
-match_to_s(VALUE match)
+match_to_s(match)
+ VALUE match;
{
VALUE str = rb_reg_last_match(match);
@@ -1426,7 +1314,8 @@ match_to_s(VALUE match)
*/
static VALUE
-match_string(VALUE match)
+match_string(match)
+ VALUE match;
{
return RMATCH(match)->str; /* str is frozen */
}
@@ -1434,9 +1323,17 @@ match_string(VALUE match)
VALUE rb_cRegexp;
static void
-rb_reg_initialize(VALUE obj, const char *s, long len,
- int options,
- int ce) /* call rb_compile_error() */
+rb_reg_initialize(obj, s, len, options)
+ VALUE obj;
+ const char *s;
+ long len;
+ int options; /* CASEFOLD = 1 */
+ /* EXTENDED = 2 */
+ /* MULTILINE = 4 */
+ /* CODE_NONE = 16 */
+ /* CODE_EUC = 32 */
+ /* CODE_SJIS = 48 */
+ /* CODE_UTF8 = 64 */
{
struct RRegexp *re = RREGEXP(obj);
@@ -1445,33 +1342,52 @@ rb_reg_initialize(VALUE obj, const char *s, long len,
rb_check_frozen(obj);
if (FL_TEST(obj, REG_LITERAL))
rb_raise(rb_eSecurityError, "can't modify literal regexp");
- if (re->ptr) onig_free(re->ptr);
+ if (re->ptr) re_free_pattern(re->ptr);
if (re->str) free(re->str);
re->ptr = 0;
re->str = 0;
- set_re_kcode_by_option(re, options);
+ switch (options & ~0xf) {
+ case 0:
+ default:
+ FL_SET(re, reg_kcode);
+ break;
+ case 16:
+ kcode_none(re);
+ break;
+ case 32:
+ kcode_euc(re);
+ break;
+ case 48:
+ kcode_sjis(re);
+ break;
+ case 64:
+ kcode_utf8(re);
+ break;
+ }
- if (options & ARG_KCODE_MASK) {
- kcode_set_option((VALUE)re);
+ if (options & ~0xf) {
+ rb_kcode_set_option((VALUE)re);
}
if (ruby_ignorecase) {
- options |= ONIG_OPTION_IGNORECASE;
+ options |= RE_OPTION_IGNORECASE;
FL_SET(re, REG_CASESTATE);
}
- re->ptr = make_regexp(s, len, options & ARG_REG_OPTION_MASK, ce);
+ re->ptr = make_regexp(s, len, options & 0xf);
re->str = ALLOC_N(char, len+1);
memcpy(re->str, s, len);
re->str[len] = '\0';
re->len = len;
- if (options & ARG_KCODE_MASK) {
- kcode_reset_option();
+ if (options & ~0xf) {
+ rb_kcode_reset_option();
}
- if (ce) FL_SET(obj, REG_LITERAL);
+ if (ruby_in_compile) FL_SET(obj, REG_LITERAL);
}
+static VALUE rb_reg_s_alloc _((VALUE));
static VALUE
-rb_reg_s_alloc(VALUE klass)
+rb_reg_s_alloc(klass)
+ VALUE klass;
{
NEWOBJ(re, struct RRegexp);
OBJSETUP(re, klass, T_REGEXP);
@@ -1484,20 +1400,14 @@ rb_reg_s_alloc(VALUE klass)
}
VALUE
-rb_reg_new(const char *s, long len, int options)
-{
- VALUE re = rb_reg_s_alloc(rb_cRegexp);
-
- rb_reg_initialize(re, s, len, options, Qfalse);
- return (VALUE)re;
-}
-
-VALUE
-rb_reg_compile(const char *s, long len, int options)
+rb_reg_new(s, len, options)
+ const char *s;
+ long len;
+ int options;
{
VALUE re = rb_reg_s_alloc(rb_cRegexp);
- rb_reg_initialize(re, s, len, options, Qtrue);
+ rb_reg_initialize(re, s, len, options);
return (VALUE)re;
}
@@ -1506,23 +1416,25 @@ static int kcode_cache;
static VALUE reg_cache;
VALUE
-rb_reg_regcomp(VALUE str)
+rb_reg_regcomp(str)
+ VALUE str;
{
volatile VALUE save_str = str;
- if (reg_cache && RREGEXP(reg_cache)->len == RSTRING_LEN(str)
+ if (reg_cache && RREGEXP(reg_cache)->len == RSTRING(str)->len
&& case_cache == ruby_ignorecase
&& kcode_cache == reg_kcode
- && memcmp(RREGEXP(reg_cache)->str, RSTRING_PTR(str), RSTRING_LEN(str)) == 0)
+ && memcmp(RREGEXP(reg_cache)->str, RSTRING(str)->ptr, RSTRING(str)->len) == 0)
return reg_cache;
case_cache = ruby_ignorecase;
kcode_cache = reg_kcode;
- return reg_cache = rb_reg_new(RSTRING_PTR(save_str), RSTRING_LEN(save_str),
+ return reg_cache = rb_reg_new(RSTRING(str)->ptr, RSTRING(str)->len,
ruby_ignorecase);
}
static int
-rb_reg_cur_kcode(VALUE re)
+rb_reg_cur_kcode(re)
+ VALUE re;
{
if (FL_TEST(re, KCODE_FIXED)) {
return RBASIC(re)->flags & KCODE_MASK;
@@ -1538,7 +1450,8 @@ rb_reg_cur_kcode(VALUE re)
*/
static VALUE
-rb_reg_hash(VALUE re)
+rb_reg_hash(re)
+ VALUE re;
{
int hashval, len;
char *p;
@@ -1551,7 +1464,7 @@ rb_reg_hash(VALUE re)
hashval = hashval * 33 + *p++;
}
hashval = hashval + (hashval>>5);
-
+
return INT2FIX(hashval);
}
@@ -1571,7 +1484,8 @@ rb_reg_hash(VALUE re)
*/
static VALUE
-rb_reg_equal(VALUE re1, VALUE re2)
+rb_reg_equal(re1, re2)
+ VALUE re1, re2;
{
if (re1 == re2) return Qtrue;
if (TYPE(re2) != T_REGEXP) return Qfalse;
@@ -1585,44 +1499,36 @@ rb_reg_equal(VALUE re1, VALUE re2)
return Qfalse;
}
-static VALUE
-rb_reg_match_pos(VALUE re, VALUE str, long pos)
+
+/*
+ * call-seq:
+ * rxp.match(str) => matchdata or nil
+ *
+ * Returns a <code>MatchData</code> object describing the match, or
+ * <code>nil</code> if there was no match. This is equivalent to retrieving the
+ * value of the special variable <code>$~</code> following a normal match.
+ *
+ * /(.)(.)(.)/.match("abc")[2] #=> "b"
+ */
+
+VALUE
+rb_reg_match(re, str)
+ VALUE re, str;
{
+ long start;
+
if (NIL_P(str)) {
rb_backref_set(Qnil);
return Qnil;
}
StringValue(str);
- if (pos != 0) {
- if (pos < 0) {
- pos += RSTRING_LEN(str);
- if (pos < 0) {
- return Qnil;
- }
- }
- pos = rb_reg_adjust_startpos(re, str, pos, 0);
- }
- pos = rb_reg_search(re, str, pos, 0);
- if (pos < 0) {
+ start = rb_reg_search(re, str, 0, 0);
+ if (start < 0) {
return Qnil;
}
- return LONG2FIX(pos);
+ return LONG2FIX(start);
}
-/*
- * call-seq:
- * rxp =~ str => integer or nil
- *
- * Match---Matches <i>rxp</i> against <i>str</i>.
- *
- * /at/ =~ "input data" #=> 7
- */
-
-VALUE
-rb_reg_match(VALUE re, VALUE str)
-{
- return rb_reg_match_pos(re, str, 0);
-}
/*
* call-seq:
@@ -1643,7 +1549,8 @@ rb_reg_match(VALUE re, VALUE str)
*/
VALUE
-rb_reg_eqq(VALUE re, VALUE str)
+rb_reg_eqq(re, str)
+ VALUE re, str;
{
long start;
@@ -1675,7 +1582,8 @@ rb_reg_eqq(VALUE re, VALUE str)
*/
VALUE
-rb_reg_match2(VALUE re)
+rb_reg_match2(re)
+ VALUE re;
{
long start;
VALUE line = rb_lastline_get();
@@ -1695,37 +1603,22 @@ rb_reg_match2(VALUE re)
/*
* call-seq:
- * rxp.match(str) => matchdata or nil
- * rxp.match(str,pos) => matchdata or nil
+ * rxp.match(str) => matchdata or nil
*
* Returns a <code>MatchData</code> object describing the match, or
* <code>nil</code> if there was no match. This is equivalent to retrieving the
* value of the special variable <code>$~</code> following a normal match.
- * If the second parameter is present, it specifies the position in the string
- * to begin the search.
- *
+ *
* /(.)(.)(.)/.match("abc")[2] #=> "b"
- * /(.)(.)/.match("abc", 1)[2] #=> "c"
*/
static VALUE
-rb_reg_match_m(int argc, VALUE *argv, VALUE re)
+rb_reg_match_m(re, str)
+ VALUE re, str;
{
- VALUE result, str, initpos;
- long pos;
-
- if (rb_scan_args(argc, argv, "11", &str, &initpos) == 2) {
- pos = NUM2LONG(initpos);
- }
- else {
- pos = 0;
- }
+ VALUE result = rb_reg_match(re, str);
- result = rb_reg_match_pos(re, str, pos);
- if (NIL_P(result)) {
- rb_backref_set(Qnil);
- return Qnil;
- }
+ if (NIL_P(result)) return Qnil;
result = rb_backref_get();
rb_match_busy(result);
return result;
@@ -1737,7 +1630,6 @@ rb_reg_match_m(int argc, VALUE *argv, VALUE re)
* Synonym for <code>Regexp.new</code>
*/
-
/*
* call-seq:
* Regexp.new(string [, options [, lang]]) => regexp
@@ -1763,7 +1655,10 @@ rb_reg_match_m(int argc, VALUE *argv, VALUE re)
*/
static VALUE
-rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
+rb_reg_initialize_m(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
const char *s;
long len;
@@ -1777,9 +1672,24 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
rb_warn("flags%s ignored", (argc == 3) ? " and encoding": "");
}
rb_reg_check(argv[0]);
- flags = RREGEXP(argv[0])->ptr->options & ARG_REG_OPTION_MASK;
+ flags = RREGEXP(argv[0])->ptr->options & 0xf;
if (FL_TEST(argv[0], KCODE_FIXED)) {
- flags |= re_to_kcode_arg_value(argv[0]);
+ switch (RBASIC(argv[0])->flags & KCODE_MASK) {
+ case KCODE_NONE:
+ flags |= 16;
+ break;
+ case KCODE_EUC:
+ flags |= 32;
+ break;
+ case KCODE_SJIS:
+ flags |= 48;
+ break;
+ case KCODE_UTF8:
+ flags |= 64;
+ break;
+ default:
+ break;
+ }
}
s = RREGEXP(argv[0])->str;
len = RREGEXP(argv[0])->len;
@@ -1787,34 +1697,50 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
else {
if (argc >= 2) {
if (FIXNUM_P(argv[1])) flags = FIX2INT(argv[1]);
- else if (RTEST(argv[1])) flags = ONIG_OPTION_IGNORECASE;
+ else if (RTEST(argv[1])) flags = RE_OPTION_IGNORECASE;
}
if (argc == 3 && !NIL_P(argv[2])) {
char *kcode = StringValuePtr(argv[2]);
- flags &= ~ARG_KCODE_MASK;
- flags |= char_to_arg_kcode((int )kcode[0]);
+ flags &= ~0x70;
+ switch (kcode[0]) {
+ case 'n': case 'N':
+ flags |= 16;
+ break;
+ case 'e': case 'E':
+ flags |= 32;
+ break;
+ case 's': case 'S':
+ flags |= 48;
+ break;
+ case 'u': case 'U':
+ flags |= 64;
+ break;
+ default:
+ break;
+ }
}
s = StringValuePtr(argv[0]);
- len = RSTRING_LEN(argv[0]);
+ len = RSTRING(argv[0])->len;
}
- rb_reg_initialize(self, s, len, flags, Qfalse);
+ rb_reg_initialize(self, s, len, flags);
return self;
}
VALUE
-rb_reg_quote(VALUE str)
+rb_reg_quote(str)
+ VALUE str;
{
char *s, *send, *t;
VALUE tmp;
int c;
- s = RSTRING_PTR(str);
- send = s + RSTRING_LEN(str);
+ s = RSTRING(str)->ptr;
+ send = s + RSTRING(str)->len;
for (; s < send; s++) {
c = *s;
- if (ismbchar(*s)) {
- int n = mbclen(*s);
+ if (ismbchar(c)) {
+ int n = mbclen(c);
while (n-- && s < send)
s++;
@@ -1831,19 +1757,19 @@ rb_reg_quote(VALUE str)
goto meta_found;
}
}
- return str;
+ return rb_str_new3(str);
meta_found:
- tmp = rb_str_new(0, RSTRING_LEN(str)*2);
- t = RSTRING_PTR(tmp);
+ tmp = rb_str_new(0, RSTRING(str)->len*2);
+ t = RSTRING(tmp)->ptr;
/* copy upto metacharacter */
- memcpy(t, RSTRING_PTR(str), s - RSTRING_PTR(str));
- t += s - RSTRING_PTR(str);
+ memcpy(t, RSTRING(str)->ptr, s - RSTRING(str)->ptr);
+ t += s - RSTRING(str)->ptr;
for (; s < send; s++) {
c = *s;
- if (ismbchar(*s)) {
- int n = mbclen(*s);
+ if (ismbchar(c)) {
+ int n = mbclen(c);
while (n-- && s < send)
*t++ = *s++;
@@ -1881,7 +1807,7 @@ rb_reg_quote(VALUE str)
}
*t++ = c;
}
- rb_str_resize(tmp, t - RSTRING_PTR(tmp));
+ rb_str_resize(tmp, t - RSTRING(tmp)->ptr);
OBJ_INFECT(tmp, str);
return tmp;
}
@@ -1901,7 +1827,9 @@ rb_reg_quote(VALUE str)
*/
static VALUE
-rb_reg_s_quote(int argc, VALUE *argv)
+rb_reg_s_quote(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE str, kcode;
int kcode_saved = reg_kcode;
@@ -1914,12 +1842,12 @@ rb_reg_s_quote(int argc, VALUE *argv)
}
StringValue(str);
str = rb_reg_quote(str);
- kcode_reset_option();
+ rb_kcode_reset_option();
return str;
}
int
-rb_kcode(void)
+rb_kcode()
{
switch (reg_kcode) {
case KCODE_EUC:
@@ -1934,16 +1862,35 @@ rb_kcode(void)
rb_bug("wrong reg_kcode value (0x%x)", reg_kcode);
}
+static int
+rb_reg_get_kcode(re)
+ VALUE re;
+{
+ switch (RBASIC(re)->flags & KCODE_MASK) {
+ case KCODE_NONE:
+ return 16;
+ case KCODE_EUC:
+ return 32;
+ case KCODE_SJIS:
+ return 48;
+ case KCODE_UTF8:
+ return 64;
+ default:
+ return 0;
+ }
+}
+
int
-rb_reg_options(VALUE re)
+rb_reg_options(re)
+ VALUE re;
{
int options;
rb_reg_check(re);
options = RREGEXP(re)->ptr->options &
- (ONIG_OPTION_IGNORECASE|ONIG_OPTION_MULTILINE|ONIG_OPTION_EXTEND);
+ (RE_OPTION_IGNORECASE|RE_OPTION_MULTILINE|RE_OPTION_EXTENDED);
if (FL_TEST(re, KCODE_FIXED)) {
- options |= re_to_kcode_arg_value(re);
+ options |= rb_reg_get_kcode(re);
}
return options;
}
@@ -1964,7 +1911,9 @@ rb_reg_options(VALUE re)
* Regexp.union(/dogs/, /cats/i) #=> /(?-mix:dogs)|(?i-mx:cats)/
*/
static VALUE
-rb_reg_s_union(int argc, VALUE *argv)
+rb_reg_s_union(argc, argv)
+ int argc;
+ VALUE *argv;
{
if (argc == 0) {
VALUE args[1];
@@ -2003,7 +1952,7 @@ rb_reg_s_union(int argc, VALUE *argv)
str1 = rb_inspect(kcode_re);
str2 = rb_inspect(v);
rb_raise(rb_eArgError, "mixed kcode: %s and %s",
- RSTRING_PTR(str1), RSTRING_PTR(str2));
+ RSTRING(str1)->ptr, RSTRING(str2)->ptr);
}
}
v = rb_reg_to_s(v);
@@ -2039,7 +1988,8 @@ rb_reg_s_union(int argc, VALUE *argv)
/* :nodoc: */
static VALUE
-rb_reg_init_copy(VALUE copy, VALUE re)
+rb_reg_init_copy(copy, re)
+ VALUE copy, re;
{
if (copy == re) return copy;
rb_check_frozen(copy);
@@ -2049,31 +1999,31 @@ rb_reg_init_copy(VALUE copy, VALUE re)
}
rb_reg_check(re);
rb_reg_initialize(copy, RREGEXP(re)->str, RREGEXP(re)->len,
- rb_reg_options(re), Qfalse);
+ rb_reg_options(re));
return copy;
}
VALUE
-rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
+rb_reg_regsub(str, src, regs)
+ VALUE str, src;
+ struct re_registers *regs;
{
VALUE val = 0;
- char *p, *s, *e;
- unsigned char uc;
+ char *p, *s, *e, c;
int no;
-
- p = s = RSTRING_PTR(str);
- e = s + RSTRING_LEN(str);
+ p = s = RSTRING(str)->ptr;
+ e = s + RSTRING(str)->len;
while (s < e) {
char *ss = s;
- uc = (unsigned char)*s++;
- if (ismbchar(uc)) {
- s += mbclen(uc) - 1;
+ c = *s++;
+ if (ismbchar(c)) {
+ s += mbclen(c) - 1;
continue;
}
- if (uc != '\\' || s == e) continue;
+ if (c != '\\' || s == e) continue;
if (!val) {
val = rb_str_buf_new(ss-p);
@@ -2083,53 +2033,23 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
rb_str_buf_cat(val, p, ss-p);
}
- uc = (unsigned char)*s++;
+ c = *s++;
p = s;
- switch (uc) {
- case '1': case '2': case '3': case '4':
+ switch (c) {
+ case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
- if (onig_noname_group_capture_is_active(RREGEXP(regexp)->ptr)) {
- no = uc - '0';
- }
- else {
- continue;
- }
+ no = c - '0';
break;
-
- case 'k':
- if (s < e && *s == '<') {
- char *name, *name_end;
-
- name_end = name = s + 1;
- while (name_end < e) {
- if (*name_end == '>') break;
- uc = (unsigned char)*name_end;
- name_end += mbclen(uc);
- }
- if (name_end < e) {
- no = name_to_backref_number(regs, regexp, name, name_end);
- p = s = name_end + 1;
- break;
- }
- else {
- rb_raise(rb_eRuntimeError, "invalid group name reference format");
- }
- }
-
- rb_str_buf_cat(val, s-2, 2);
- continue;
-
- case '0':
case '&':
no = 0;
break;
case '`':
- rb_str_buf_cat(val, RSTRING_PTR(src), BEG(0));
+ rb_str_buf_cat(val, RSTRING(src)->ptr, BEG(0));
continue;
case '\'':
- rb_str_buf_cat(val, RSTRING_PTR(src)+END(0), RSTRING_LEN(src)-END(0));
+ rb_str_buf_cat(val, RSTRING(src)->ptr+END(0), RSTRING(src)->len-END(0));
continue;
case '+':
@@ -2150,7 +2070,7 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
if (no >= 0) {
if (no >= regs->num_regs) continue;
if (BEG(no) == -1) continue;
- rb_str_buf_cat(val, RSTRING_PTR(src)+BEG(no), END(no)-BEG(no));
+ rb_str_buf_cat(val, RSTRING(src)->ptr+BEG(no), END(no)-BEG(no));
}
}
@@ -2169,7 +2089,7 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
}
const char*
-rb_get_kcode(void)
+rb_get_kcode()
{
switch (reg_kcode) {
case KCODE_SJIS:
@@ -2184,13 +2104,14 @@ rb_get_kcode(void)
}
static VALUE
-kcode_getter(void)
+kcode_getter()
{
return rb_str_new2(rb_get_kcode());
}
void
-rb_set_kcode(const char *code)
+rb_set_kcode(code)
+ const char *code;
{
if (code == 0) goto set_no_conversion;
@@ -2198,17 +2119,17 @@ rb_set_kcode(const char *code)
case 'E':
case 'e':
reg_kcode = KCODE_EUC;
- onigenc_set_default_encoding(ONIG_ENCODING_EUC_JP);
+ re_mbcinit(MBCTYPE_EUC);
break;
case 'S':
case 's':
reg_kcode = KCODE_SJIS;
- onigenc_set_default_encoding(ONIG_ENCODING_SJIS);
+ re_mbcinit(MBCTYPE_SJIS);
break;
case 'U':
case 'u':
reg_kcode = KCODE_UTF8;
- onigenc_set_default_encoding(ONIG_ENCODING_UTF8);
+ re_mbcinit(MBCTYPE_UTF8);
break;
default:
case 'N':
@@ -2217,26 +2138,29 @@ rb_set_kcode(const char *code)
case 'a':
set_no_conversion:
reg_kcode = KCODE_NONE;
- onigenc_set_default_encoding(ONIG_ENCODING_ASCII);
+ re_mbcinit(MBCTYPE_ASCII);
break;
}
}
static void
-kcode_setter(VALUE val)
+kcode_setter(val)
+ VALUE val;
{
may_need_recompile = 1;
rb_set_kcode(StringValuePtr(val));
}
static VALUE
-ignorecase_getter(void)
+ignorecase_getter()
{
return ruby_ignorecase?Qtrue:Qfalse;
}
static void
-ignorecase_setter(VALUE val, ID id)
+ignorecase_setter(val, id)
+ VALUE val;
+ ID id;
{
rb_warn("modifying %s is deprecated", rb_id2name(id));
may_need_recompile = 1;
@@ -2244,7 +2168,7 @@ ignorecase_setter(VALUE val, ID id)
}
static VALUE
-match_getter(void)
+match_getter()
{
VALUE match = rb_backref_get();
@@ -2254,7 +2178,8 @@ match_getter(void)
}
static void
-match_setter(VALUE val)
+match_setter(val)
+ VALUE val;
{
if (!NIL_P(val)) {
Check_Type(val, T_MATCH);
@@ -2280,7 +2205,9 @@ match_setter(VALUE val)
*/
static VALUE
-rb_reg_s_last_match(int argc, VALUE *argv)
+rb_reg_s_last_match(argc, argv)
+ int argc;
+ VALUE *argv;
{
VALUE nth;
@@ -2302,21 +2229,21 @@ rb_reg_s_last_match(int argc, VALUE *argv)
*/
void
-Init_Regexp(void)
+Init_Regexp()
{
rb_eRegexpError = rb_define_class("RegexpError", rb_eStandardError);
- onigenc_set_default_caseconv_table((UChar*)casetable);
+ re_set_casetable(casetable);
#if DEFAULT_KCODE == KCODE_EUC
- onigenc_set_default_encoding(ONIG_ENCODING_EUC_JP);
+ re_mbcinit(MBCTYPE_EUC);
#else
#if DEFAULT_KCODE == KCODE_SJIS
- onigenc_set_default_encoding(ONIG_ENCODING_SJIS);
+ re_mbcinit(MBCTYPE_SJIS);
#else
#if DEFAULT_KCODE == KCODE_UTF8
- onigenc_set_default_encoding(ONIG_ENCODING_UTF8);
+ re_mbcinit(MBCTYPE_UTF8);
#else
- onigenc_set_default_encoding(ONIG_ENCODING_ASCII);
+ re_mbcinit(MBCTYPE_ASCII);
#endif
#endif
#endif
@@ -2347,7 +2274,7 @@ Init_Regexp(void)
rb_define_method(rb_cRegexp, "=~", rb_reg_match, 1);
rb_define_method(rb_cRegexp, "===", rb_reg_eqq, 1);
rb_define_method(rb_cRegexp, "~", rb_reg_match2, 0);
- rb_define_method(rb_cRegexp, "match", rb_reg_match_m, -1);
+ rb_define_method(rb_cRegexp, "match", rb_reg_match_m, 1);
rb_define_method(rb_cRegexp, "to_s", rb_reg_to_s, 0);
rb_define_method(rb_cRegexp, "inspect", rb_reg_inspect, 0);
rb_define_method(rb_cRegexp, "source", rb_reg_source, 0);
@@ -2355,9 +2282,9 @@ Init_Regexp(void)
rb_define_method(rb_cRegexp, "options", rb_reg_options_m, 0);
rb_define_method(rb_cRegexp, "kcode", rb_reg_kcode_m, 0);
- rb_define_const(rb_cRegexp, "IGNORECASE", INT2FIX(ONIG_OPTION_IGNORECASE));
- rb_define_const(rb_cRegexp, "EXTENDED", INT2FIX(ONIG_OPTION_EXTEND));
- rb_define_const(rb_cRegexp, "MULTILINE", INT2FIX(ONIG_OPTION_MULTILINE));
+ rb_define_const(rb_cRegexp, "IGNORECASE", INT2FIX(RE_OPTION_IGNORECASE));
+ rb_define_const(rb_cRegexp, "EXTENDED", INT2FIX(RE_OPTION_EXTENDED));
+ rb_define_const(rb_cRegexp, "MULTILINE", INT2FIX(RE_OPTION_MULTILINE));
rb_global_variable(&reg_cache);
diff --git a/re.h b/re.h
index ab66352288..45b2753dd5 100644
--- a/re.h
+++ b/re.h
@@ -24,20 +24,19 @@ struct RMatch {
struct RBasic basic;
VALUE str;
struct re_registers *regs;
- VALUE regexp; /* RRegexp */
};
#define RMATCH(obj) (R_CAST(RMatch)(obj))
-VALUE rb_reg_regcomp(VALUE);
-long rb_reg_search(VALUE, VALUE, long, long);
-VALUE rb_reg_regsub(VALUE, VALUE, struct re_registers *, VALUE);
-long rb_reg_adjust_startpos(VALUE, VALUE, long, long);
-void rb_match_busy(VALUE);
-VALUE rb_reg_quote(VALUE);
+VALUE rb_reg_regcomp _((VALUE));
+long rb_reg_search _((VALUE, VALUE, long, long));
+VALUE rb_reg_regsub _((VALUE, VALUE, struct re_registers *));
+long rb_reg_adjust_startpos _((VALUE, VALUE, long, long));
+void rb_match_busy _((VALUE));
+VALUE rb_reg_quote _((VALUE));
RUBY_EXTERN int ruby_ignorecase;
-int rb_reg_mbclen2(unsigned int, VALUE);
+int rb_reg_mbclen2 _((unsigned int, VALUE));
#define mbclen2(c,re) rb_reg_mbclen2((c),(re))
#endif
diff --git a/regcomp.c b/regcomp.c
deleted file mode 100644
index 3f7168d968..0000000000
--- a/regcomp.c
+++ /dev/null
@@ -1,6017 +0,0 @@
-/**********************************************************************
- regcomp.c - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "regparse.h"
-
-OnigAmbigType OnigDefaultAmbigFlag =
- (ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE |
- ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE);
-
-extern OnigAmbigType
-onig_get_default_ambig_flag()
-{
- return OnigDefaultAmbigFlag;
-}
-
-extern int
-onig_set_default_ambig_flag(OnigAmbigType ambig_flag)
-{
- OnigDefaultAmbigFlag = ambig_flag;
- return 0;
-}
-
-
-#ifndef PLATFORM_UNALIGNED_WORD_ACCESS
-static unsigned char PadBuf[WORD_ALIGNMENT_SIZE];
-#endif
-
-static UChar*
-k_strdup(UChar* s, UChar* end)
-{
- int len = end - s;
-
- if (len > 0) {
- UChar* r = (UChar* )xmalloc(len + 1);
- CHECK_NULL_RETURN(r);
- xmemcpy(r, s, len);
- r[len] = (UChar )0;
- return r;
- }
- else return NULL;
-}
-
-/*
- Caution: node should not be a string node.
- (s and end member address break)
-*/
-static void
-swap_node(Node* a, Node* b)
-{
- Node c;
- c = *a; *a = *b; *b = c;
-}
-
-static OnigDistance
-distance_add(OnigDistance d1, OnigDistance d2)
-{
- if (d1 == ONIG_INFINITE_DISTANCE || d2 == ONIG_INFINITE_DISTANCE)
- return ONIG_INFINITE_DISTANCE;
- else {
- if (d1 <= ONIG_INFINITE_DISTANCE - d2) return d1 + d2;
- else return ONIG_INFINITE_DISTANCE;
- }
-}
-
-static OnigDistance
-distance_multiply(OnigDistance d, int m)
-{
- if (m == 0) return 0;
-
- if (d < ONIG_INFINITE_DISTANCE / m)
- return d * m;
- else
- return ONIG_INFINITE_DISTANCE;
-}
-
-static int
-bitset_is_empty(BitSetRef bs)
-{
- int i;
- for (i = 0; i < BITSET_SIZE; i++) {
- if (bs[i] != 0) return 0;
- }
- return 1;
-}
-
-#ifdef ONIG_DEBUG
-static int
-bitset_on_num(BitSetRef bs)
-{
- int i, n;
-
- n = 0;
- for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
- if (BITSET_AT(bs, i)) n++;
- }
- return n;
-}
-#endif
-
-extern int
-onig_bbuf_init(BBuf* buf, int size)
-{
- buf->p = (UChar* )xmalloc(size);
- if (IS_NULL(buf->p)) return(ONIGERR_MEMORY);
-
- buf->alloc = size;
- buf->used = 0;
- return 0;
-}
-
-
-#ifdef USE_SUBEXP_CALL
-
-static int
-unset_addr_list_init(UnsetAddrList* uslist, int size)
-{
- UnsetAddr* p;
-
- p = (UnsetAddr* )xmalloc(sizeof(UnsetAddr)* size);
- CHECK_NULL_RETURN_VAL(p, ONIGERR_MEMORY);
- uslist->num = 0;
- uslist->alloc = size;
- uslist->us = p;
- return 0;
-}
-
-static void
-unset_addr_list_end(UnsetAddrList* uslist)
-{
- if (IS_NOT_NULL(uslist->us))
- xfree(uslist->us);
-}
-
-static int
-unset_addr_list_add(UnsetAddrList* uslist, int offset, struct _Node* node)
-{
- UnsetAddr* p;
- int size;
-
- if (uslist->num >= uslist->alloc) {
- size = uslist->alloc * 2;
- p = (UnsetAddr* )xrealloc(uslist->us, sizeof(UnsetAddr) * size);
- CHECK_NULL_RETURN_VAL(p, ONIGERR_MEMORY);
- uslist->alloc = size;
- uslist->us = p;
- }
-
- uslist->us[uslist->num].offset = offset;
- uslist->us[uslist->num].target = node;
- uslist->num++;
- return 0;
-}
-#endif /* USE_SUBEXP_CALL */
-
-
-static int
-add_opcode(regex_t* reg, int opcode)
-{
- BBUF_ADD1(reg, opcode);
- return 0;
-}
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
-static int
-add_state_check_num(regex_t* reg, int num)
-{
- StateCheckNumType n = (StateCheckNumType )num;
-
- BBUF_ADD(reg, &n, SIZE_STATE_CHECK_NUM);
- return 0;
-}
-#endif
-
-static int
-add_rel_addr(regex_t* reg, int addr)
-{
- RelAddrType ra = (RelAddrType )addr;
-
- BBUF_ADD(reg, &ra, SIZE_RELADDR);
- return 0;
-}
-
-static int
-add_abs_addr(regex_t* reg, int addr)
-{
- AbsAddrType ra = (AbsAddrType )addr;
-
- BBUF_ADD(reg, &ra, SIZE_ABSADDR);
- return 0;
-}
-
-static int
-add_length(regex_t* reg, int len)
-{
- LengthType l = (LengthType )len;
-
- BBUF_ADD(reg, &l, SIZE_LENGTH);
- return 0;
-}
-
-static int
-add_mem_num(regex_t* reg, int num)
-{
- MemNumType n = (MemNumType )num;
-
- BBUF_ADD(reg, &n, SIZE_MEMNUM);
- return 0;
-}
-
-static int
-add_pointer(regex_t* reg, void* addr)
-{
- PointerType ptr = (PointerType )addr;
-
- BBUF_ADD(reg, &ptr, SIZE_POINTER);
- return 0;
-}
-
-static int
-add_option(regex_t* reg, OnigOptionType option)
-{
- BBUF_ADD(reg, &option, SIZE_OPTION);
- return 0;
-}
-
-static int
-add_opcode_rel_addr(regex_t* reg, int opcode, int addr)
-{
- int r;
-
- r = add_opcode(reg, opcode);
- if (r) return r;
- r = add_rel_addr(reg, addr);
- return r;
-}
-
-static int
-add_bytes(regex_t* reg, UChar* bytes, int len)
-{
- BBUF_ADD(reg, bytes, len);
- return 0;
-}
-
-static int
-add_bitset(regex_t* reg, BitSetRef bs)
-{
- BBUF_ADD(reg, bs, SIZE_BITSET);
- return 0;
-}
-
-static int
-add_opcode_option(regex_t* reg, int opcode, OnigOptionType option)
-{
- int r;
-
- r = add_opcode(reg, opcode);
- if (r) return r;
- r = add_option(reg, option);
- return r;
-}
-
-static int compile_length_tree(Node* node, regex_t* reg);
-static int compile_tree(Node* node, regex_t* reg);
-
-
-#define IS_NEED_STR_LEN_OP_EXACT(op) \
- ((op) == OP_EXACTN || (op) == OP_EXACTMB2N ||\
- (op) == OP_EXACTMB3N || (op) == OP_EXACTMBN || (op) == OP_EXACTN_IC)
-
-static int
-select_str_opcode(int mb_len, int str_len, int ignore_case)
-{
- int op;
-
- if (ignore_case) {
- switch (str_len) {
- case 1: op = OP_EXACT1_IC; break;
- default: op = OP_EXACTN_IC; break;
- }
- }
- else {
- switch (mb_len) {
- case 1:
- switch (str_len) {
- case 1: op = OP_EXACT1; break;
- case 2: op = OP_EXACT2; break;
- case 3: op = OP_EXACT3; break;
- case 4: op = OP_EXACT4; break;
- case 5: op = OP_EXACT5; break;
- default: op = OP_EXACTN; break;
- }
- break;
-
- case 2:
- switch (str_len) {
- case 1: op = OP_EXACTMB2N1; break;
- case 2: op = OP_EXACTMB2N2; break;
- case 3: op = OP_EXACTMB2N3; break;
- default: op = OP_EXACTMB2N; break;
- }
- break;
-
- case 3:
- op = OP_EXACTMB3N;
- break;
-
- default:
- op = OP_EXACTMBN;
- break;
- }
- }
- return op;
-}
-
-static int
-compile_tree_empty_check(Node* node, regex_t* reg, int empty_info)
-{
- int r;
- int saved_num_null_check = reg->num_null_check;
-
- if (empty_info != 0) {
- r = add_opcode(reg, OP_NULL_CHECK_START);
- if (r) return r;
- r = add_mem_num(reg, reg->num_null_check); /* NULL CHECK ID */
- if (r) return r;
- reg->num_null_check++;
- }
-
- r = compile_tree(node, reg);
- if (r) return r;
-
- if (empty_info != 0) {
- if (empty_info == NQ_TARGET_IS_EMPTY)
- r = add_opcode(reg, OP_NULL_CHECK_END);
- else if (empty_info == NQ_TARGET_IS_EMPTY_MEM)
- r = add_opcode(reg, OP_NULL_CHECK_END_MEMST);
- else if (empty_info == NQ_TARGET_IS_EMPTY_REC)
- r = add_opcode(reg, OP_NULL_CHECK_END_MEMST_PUSH);
-
- if (r) return r;
- r = add_mem_num(reg, saved_num_null_check); /* NULL CHECK ID */
- }
- return r;
-}
-
-#ifdef USE_SUBEXP_CALL
-static int
-compile_call(CallNode* node, regex_t* reg)
-{
- int r;
-
- r = add_opcode(reg, OP_CALL);
- if (r) return r;
- r = unset_addr_list_add(node->unset_addr_list, BBUF_GET_OFFSET_POS(reg),
- node->target);
- if (r) return r;
- r = add_abs_addr(reg, 0 /*dummy addr.*/);
- return r;
-}
-#endif
-
-static int
-compile_tree_n_times(Node* node, int n, regex_t* reg)
-{
- int i, r;
-
- for (i = 0; i < n; i++) {
- r = compile_tree(node, reg);
- if (r) return r;
- }
- return 0;
-}
-
-static int
-add_compile_string_length(UChar* s, int mb_len, int str_len,
- regex_t* reg, int ignore_case)
-{
- int len;
- int op = select_str_opcode(mb_len, str_len, ignore_case);
-
- len = SIZE_OPCODE;
-
- if (op == OP_EXACTMBN) len += SIZE_LENGTH;
- if (IS_NEED_STR_LEN_OP_EXACT(op))
- len += SIZE_LENGTH;
-
- len += mb_len * str_len;
- return len;
-}
-
-static int
-add_compile_string(UChar* s, int mb_len, int str_len,
- regex_t* reg, int ignore_case)
-{
- int op = select_str_opcode(mb_len, str_len, ignore_case);
- add_opcode(reg, op);
-
- if (op == OP_EXACTMBN)
- add_length(reg, mb_len);
-
- if (IS_NEED_STR_LEN_OP_EXACT(op)) {
- if (op == OP_EXACTN_IC)
- add_length(reg, mb_len * str_len);
- else
- add_length(reg, str_len);
- }
-
- add_bytes(reg, s, mb_len * str_len);
- return 0;
-}
-
-
-static int
-compile_length_string_node(Node* node, regex_t* reg)
-{
- int rlen, r, len, prev_len, slen, ambig;
- OnigEncoding enc = reg->enc;
- UChar *p, *prev;
- StrNode* sn;
-
- sn = &(NSTRING(node));
- if (sn->end <= sn->s)
- return 0;
-
- ambig = NSTRING_IS_AMBIG(node);
-
- p = prev = sn->s;
- prev_len = enc_len(enc, p);
- p += prev_len;
- slen = 1;
- rlen = 0;
-
- for (; p < sn->end; ) {
- len = enc_len(enc, p);
- if (len == prev_len) {
- slen++;
- }
- else {
- r = add_compile_string_length(prev, prev_len, slen, reg, ambig);
- rlen += r;
- prev = p;
- slen = 1;
- prev_len = len;
- }
- p += len;
- }
- r = add_compile_string_length(prev, prev_len, slen, reg, ambig);
- rlen += r;
- return rlen;
-}
-
-static int
-compile_length_string_raw_node(StrNode* sn, regex_t* reg)
-{
- if (sn->end <= sn->s)
- return 0;
-
- return add_compile_string_length(sn->s, 1 /* sb */, sn->end - sn->s, reg, 0);
-}
-
-static int
-compile_string_node(Node* node, regex_t* reg)
-{
- int r, len, prev_len, slen, ambig;
- OnigEncoding enc = reg->enc;
- UChar *p, *prev, *end;
- StrNode* sn;
-
- sn = &(NSTRING(node));
- if (sn->end <= sn->s)
- return 0;
-
- end = sn->end;
- ambig = NSTRING_IS_AMBIG(node);
-
- p = prev = sn->s;
- prev_len = enc_len(enc, p);
- p += prev_len;
- slen = 1;
-
- for (; p < end; ) {
- len = enc_len(enc, p);
- if (len == prev_len) {
- slen++;
- }
- else {
- r = add_compile_string(prev, prev_len, slen, reg, ambig);
- if (r) return r;
-
- prev = p;
- slen = 1;
- prev_len = len;
- }
-
- p += len;
- }
- return add_compile_string(prev, prev_len, slen, reg, ambig);
-}
-
-static int
-compile_string_raw_node(StrNode* sn, regex_t* reg)
-{
- if (sn->end <= sn->s)
- return 0;
-
- return add_compile_string(sn->s, 1 /* sb */, sn->end - sn->s, reg, 0);
-}
-
-static int
-add_multi_byte_cclass(BBuf* mbuf, regex_t* reg)
-{
-#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
- add_length(reg, mbuf->used);
- return add_bytes(reg, mbuf->p, mbuf->used);
-#else
- int r, pad_size;
- UChar* p = BBUF_GET_ADD_ADDRESS(reg) + SIZE_LENGTH;
-
- GET_ALIGNMENT_PAD_SIZE(p, pad_size);
- add_length(reg, mbuf->used + (WORD_ALIGNMENT_SIZE - 1));
- if (pad_size != 0) add_bytes(reg, PadBuf, pad_size);
-
- r = add_bytes(reg, mbuf->p, mbuf->used);
-
- /* padding for return value from compile_length_cclass_node() to be fix. */
- pad_size = (WORD_ALIGNMENT_SIZE - 1) - pad_size;
- if (pad_size != 0) add_bytes(reg, PadBuf, pad_size);
- return r;
-#endif
-}
-
-static int
-compile_length_cclass_node(CClassNode* cc, regex_t* reg)
-{
- int len;
-
- if (IS_CCLASS_SHARE(cc)) {
- len = SIZE_OPCODE + SIZE_POINTER;
- return len;
- }
-
- if (IS_NULL(cc->mbuf)) {
- len = SIZE_OPCODE + SIZE_BITSET;
- }
- else {
- if (ONIGENC_MBC_MINLEN(reg->enc) > 1 || bitset_is_empty(cc->bs)) {
- len = SIZE_OPCODE;
- }
- else {
- len = SIZE_OPCODE + SIZE_BITSET;
- }
-#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
- len += SIZE_LENGTH + cc->mbuf->used;
-#else
- len += SIZE_LENGTH + cc->mbuf->used + (WORD_ALIGNMENT_SIZE - 1);
-#endif
- }
-
- return len;
-}
-
-static int
-compile_cclass_node(CClassNode* cc, regex_t* reg)
-{
- int r;
-
- if (IS_CCLASS_SHARE(cc)) {
- add_opcode(reg, OP_CCLASS_NODE);
- r = add_pointer(reg, cc);
- return r;
- }
-
- if (IS_NULL(cc->mbuf)) {
- if (IS_CCLASS_NOT(cc))
- add_opcode(reg, OP_CCLASS_NOT);
- else
- add_opcode(reg, OP_CCLASS);
-
- r = add_bitset(reg, cc->bs);
- }
- else {
- if (ONIGENC_MBC_MINLEN(reg->enc) > 1 || bitset_is_empty(cc->bs)) {
- if (IS_CCLASS_NOT(cc))
- add_opcode(reg, OP_CCLASS_MB_NOT);
- else
- add_opcode(reg, OP_CCLASS_MB);
-
- r = add_multi_byte_cclass(cc->mbuf, reg);
- }
- else {
- if (IS_CCLASS_NOT(cc))
- add_opcode(reg, OP_CCLASS_MIX_NOT);
- else
- add_opcode(reg, OP_CCLASS_MIX);
-
- r = add_bitset(reg, cc->bs);
- if (r) return r;
- r = add_multi_byte_cclass(cc->mbuf, reg);
- }
- }
-
- return r;
-}
-
-static int
-entry_repeat_range(regex_t* reg, int id, int lower, int upper)
-{
-#define REPEAT_RANGE_ALLOC 4
-
- OnigRepeatRange* p;
-
- if (reg->repeat_range_alloc == 0) {
- p = (OnigRepeatRange* )xmalloc(sizeof(OnigRepeatRange) * REPEAT_RANGE_ALLOC);
- CHECK_NULL_RETURN_VAL(p, ONIGERR_MEMORY);
- reg->repeat_range = p;
- reg->repeat_range_alloc = REPEAT_RANGE_ALLOC;
- }
- else if (reg->repeat_range_alloc <= id) {
- int n;
- n = reg->repeat_range_alloc + REPEAT_RANGE_ALLOC;
- p = (OnigRepeatRange* )xrealloc(reg->repeat_range,
- sizeof(OnigRepeatRange) * n);
- CHECK_NULL_RETURN_VAL(p, ONIGERR_MEMORY);
- reg->repeat_range = p;
- reg->repeat_range_alloc = n;
- }
- else {
- p = reg->repeat_range;
- }
-
- p[id].lower = lower;
- p[id].upper = (IS_REPEAT_INFINITE(upper) ? 0x7fffffff : upper);
- return 0;
-}
-
-static int
-compile_range_repeat_node(QualifierNode* qn, int target_len, int empty_info,
- regex_t* reg)
-{
- int r;
- int num_repeat = reg->num_repeat;
-
- r = add_opcode(reg, qn->greedy ? OP_REPEAT : OP_REPEAT_NG);
- if (r) return r;
- r = add_mem_num(reg, num_repeat); /* OP_REPEAT ID */
- reg->num_repeat++;
- if (r) return r;
- r = add_rel_addr(reg, target_len + SIZE_OP_REPEAT_INC);
- if (r) return r;
-
- r = entry_repeat_range(reg, num_repeat, qn->lower, qn->upper);
- if (r) return r;
-
- r = compile_tree_empty_check(qn->target, reg, empty_info);
- if (r) return r;
-
- if (
-#ifdef USE_SUBEXP_CALL
- reg->num_call > 0 ||
-#endif
- IS_QUALIFIER_IN_REPEAT(qn)) {
- r = add_opcode(reg, qn->greedy ? OP_REPEAT_INC_SG : OP_REPEAT_INC_NG_SG);
- }
- else {
- r = add_opcode(reg, qn->greedy ? OP_REPEAT_INC : OP_REPEAT_INC_NG);
- }
- if (r) return r;
- r = add_mem_num(reg, num_repeat); /* OP_REPEAT ID */
- return r;
-}
-
-static int
-is_anychar_star_qualifier(QualifierNode* qn)
-{
- if (qn->greedy && IS_REPEAT_INFINITE(qn->upper) &&
- NTYPE(qn->target) == N_ANYCHAR)
- return 1;
- else
- return 0;
-}
-
-#define QUALIFIER_EXPAND_LIMIT_SIZE 50
-#define CKN_ON (ckn > 0)
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
-
-static int
-compile_length_qualifier_node(QualifierNode* qn, regex_t* reg)
-{
- int len, mod_tlen, cklen;
- int ckn;
- int infinite = IS_REPEAT_INFINITE(qn->upper);
- int empty_info = qn->target_empty_info;
- int tlen = compile_length_tree(qn->target, reg);
-
- if (tlen < 0) return tlen;
-
- ckn = ((reg->num_comb_exp_check > 0) ? qn->comb_exp_check_num : 0);
-
- cklen = (CKN_ON ? SIZE_STATE_CHECK_NUM: 0);
-
- /* anychar repeat */
- if (NTYPE(qn->target) == N_ANYCHAR) {
- if (qn->greedy && infinite) {
- if (IS_NOT_NULL(qn->next_head_exact) && !CKN_ON)
- return SIZE_OP_ANYCHAR_STAR_PEEK_NEXT + tlen * qn->lower + cklen;
- else
- return SIZE_OP_ANYCHAR_STAR + tlen * qn->lower + cklen;
- }
- }
-
- if (empty_info != 0)
- mod_tlen = tlen + (SIZE_OP_NULL_CHECK_START + SIZE_OP_NULL_CHECK_END);
- else
- mod_tlen = tlen;
-
- if (infinite && qn->lower <= 1) {
- if (qn->greedy) {
- if (qn->lower == 1)
- len = SIZE_OP_JUMP;
- else
- len = 0;
-
- len += SIZE_OP_PUSH + cklen + mod_tlen + SIZE_OP_JUMP;
- }
- else {
- if (qn->lower == 0)
- len = SIZE_OP_JUMP;
- else
- len = 0;
-
- len += mod_tlen + SIZE_OP_PUSH + cklen;
- }
- }
- else if (qn->upper == 0) {
- if (qn->is_refered != 0) /* /(?<n>..){0}/ */
- len = SIZE_OP_JUMP + tlen;
- else
- len = 0;
- }
- else if (qn->upper == 1 && qn->greedy) {
- if (qn->lower == 0) {
- if (CKN_ON) {
- len = SIZE_OP_STATE_CHECK_PUSH + tlen;
- }
- else {
- len = SIZE_OP_PUSH + tlen;
- }
- }
- else {
- len = tlen;
- }
- }
- else if (!qn->greedy && qn->upper == 1 && qn->lower == 0) { /* '??' */
- len = SIZE_OP_PUSH + cklen + SIZE_OP_JUMP + tlen;
- }
- else {
- len = SIZE_OP_REPEAT_INC
- + mod_tlen + SIZE_OPCODE + SIZE_RELADDR + SIZE_MEMNUM;
- if (CKN_ON)
- len += SIZE_OP_STATE_CHECK;
- }
-
- return len;
-}
-
-static int
-compile_qualifier_node(QualifierNode* qn, regex_t* reg)
-{
- int r, mod_tlen;
- int ckn;
- int infinite = IS_REPEAT_INFINITE(qn->upper);
- int empty_info = qn->target_empty_info;
- int tlen = compile_length_tree(qn->target, reg);
-
- if (tlen < 0) return tlen;
-
- ckn = ((reg->num_comb_exp_check > 0) ? qn->comb_exp_check_num : 0);
-
- if (is_anychar_star_qualifier(qn)) {
- r = compile_tree_n_times(qn->target, qn->lower, reg);
- if (r) return r;
- if (IS_NOT_NULL(qn->next_head_exact) && !CKN_ON) {
- if (IS_MULTILINE(reg->options))
- r = add_opcode(reg, OP_ANYCHAR_ML_STAR_PEEK_NEXT);
- else
- r = add_opcode(reg, OP_ANYCHAR_STAR_PEEK_NEXT);
- if (r) return r;
- if (CKN_ON) {
- r = add_state_check_num(reg, ckn);
- if (r) return r;
- }
-
- return add_bytes(reg, NSTRING(qn->next_head_exact).s, 1);
- }
- else {
- if (IS_MULTILINE(reg->options)) {
- r = add_opcode(reg, (CKN_ON ?
- OP_STATE_CHECK_ANYCHAR_ML_STAR
- : OP_ANYCHAR_ML_STAR));
- }
- else {
- r = add_opcode(reg, (CKN_ON ?
- OP_STATE_CHECK_ANYCHAR_STAR
- : OP_ANYCHAR_STAR));
- }
- if (r) return r;
- if (CKN_ON)
- r = add_state_check_num(reg, ckn);
-
- return r;
- }
- }
-
- if (empty_info != 0)
- mod_tlen = tlen + (SIZE_OP_NULL_CHECK_START + SIZE_OP_NULL_CHECK_END);
- else
- mod_tlen = tlen;
-
- if (infinite && qn->lower <= 1) {
- if (qn->greedy) {
- if (qn->lower == 1) {
- r = add_opcode_rel_addr(reg, OP_JUMP,
- (CKN_ON ? SIZE_OP_STATE_CHECK_PUSH : SIZE_OP_PUSH));
- if (r) return r;
- }
-
- if (CKN_ON) {
- r = add_opcode(reg, OP_STATE_CHECK_PUSH);
- if (r) return r;
- r = add_state_check_num(reg, ckn);
- if (r) return r;
- r = add_rel_addr(reg, mod_tlen + SIZE_OP_JUMP);
- }
- else {
- r = add_opcode_rel_addr(reg, OP_PUSH, mod_tlen + SIZE_OP_JUMP);
- }
- if (r) return r;
- r = compile_tree_empty_check(qn->target, reg, empty_info);
- if (r) return r;
- r = add_opcode_rel_addr(reg, OP_JUMP,
- -(mod_tlen + (int )SIZE_OP_JUMP
- + (int )(CKN_ON ? SIZE_OP_STATE_CHECK_PUSH : SIZE_OP_PUSH)));
- }
- else {
- if (qn->lower == 0) {
- r = add_opcode_rel_addr(reg, OP_JUMP, mod_tlen);
- if (r) return r;
- }
- r = compile_tree_empty_check(qn->target, reg, empty_info);
- if (r) return r;
- if (CKN_ON) {
- r = add_opcode(reg, OP_STATE_CHECK_PUSH_OR_JUMP);
- if (r) return r;
- r = add_state_check_num(reg, ckn);
- if (r) return r;
- r = add_rel_addr(reg,
- -(mod_tlen + (int )SIZE_OP_STATE_CHECK_PUSH_OR_JUMP));
- }
- else
- r = add_opcode_rel_addr(reg, OP_PUSH, -(mod_tlen + (int )SIZE_OP_PUSH));
- }
- }
- else if (qn->upper == 0) {
- if (qn->is_refered != 0) { /* /(?<n>..){0}/ */
- r = add_opcode_rel_addr(reg, OP_JUMP, tlen);
- if (r) return r;
- r = compile_tree(qn->target, reg);
- }
- else
- r = 0;
- }
- else if (qn->upper == 1 && qn->greedy) {
- if (qn->lower == 0) {
- if (CKN_ON) {
- r = add_opcode(reg, OP_STATE_CHECK_PUSH);
- if (r) return r;
- r = add_state_check_num(reg, ckn);
- if (r) return r;
- r = add_rel_addr(reg, tlen);
- }
- else {
- r = add_opcode_rel_addr(reg, OP_PUSH, tlen);
- }
- if (r) return r;
- }
-
- r = compile_tree(qn->target, reg);
- }
- else if (!qn->greedy && qn->upper == 1 && qn->lower == 0) { /* '??' */
- if (CKN_ON) {
- r = add_opcode(reg, OP_STATE_CHECK_PUSH);
- if (r) return r;
- r = add_state_check_num(reg, ckn);
- if (r) return r;
- r = add_rel_addr(reg, SIZE_OP_JUMP);
- }
- else {
- r = add_opcode_rel_addr(reg, OP_PUSH, SIZE_OP_JUMP);
- }
-
- if (r) return r;
- r = add_opcode_rel_addr(reg, OP_JUMP, tlen);
- if (r) return r;
- r = compile_tree(qn->target, reg);
- }
- else {
- r = compile_range_repeat_node(qn, mod_tlen, empty_info, reg);
- if (CKN_ON) {
- if (r) return r;
- r = add_opcode(reg, OP_STATE_CHECK);
- if (r) return r;
- r = add_state_check_num(reg, ckn);
- }
- }
- return r;
-}
-
-#else /* USE_COMBINATION_EXPLOSION_CHECK */
-
-static int
-compile_length_qualifier_node(QualifierNode* qn, regex_t* reg)
-{
- int len, mod_tlen;
- int infinite = IS_REPEAT_INFINITE(qn->upper);
- int empty_info = qn->target_empty_info;
- int tlen = compile_length_tree(qn->target, reg);
-
- if (tlen < 0) return tlen;
-
- /* anychar repeat */
- if (NTYPE(qn->target) == N_ANYCHAR) {
- if (qn->greedy && infinite) {
- if (IS_NOT_NULL(qn->next_head_exact))
- return SIZE_OP_ANYCHAR_STAR_PEEK_NEXT + tlen * qn->lower;
- else
- return SIZE_OP_ANYCHAR_STAR + tlen * qn->lower;
- }
- }
-
- if (empty_info != 0)
- mod_tlen = tlen + (SIZE_OP_NULL_CHECK_START + SIZE_OP_NULL_CHECK_END);
- else
- mod_tlen = tlen;
-
- if (infinite &&
- (qn->lower <= 1 || tlen * qn->lower <= QUALIFIER_EXPAND_LIMIT_SIZE)) {
- if (qn->lower == 1 && tlen > QUALIFIER_EXPAND_LIMIT_SIZE) {
- len = SIZE_OP_JUMP;
- }
- else {
- len = tlen * qn->lower;
- }
-
- if (qn->greedy) {
- if (IS_NOT_NULL(qn->head_exact))
- len += SIZE_OP_PUSH_OR_JUMP_EXACT1 + mod_tlen + SIZE_OP_JUMP;
- else if (IS_NOT_NULL(qn->next_head_exact))
- len += SIZE_OP_PUSH_IF_PEEK_NEXT + mod_tlen + SIZE_OP_JUMP;
- else
- len += SIZE_OP_PUSH + mod_tlen + SIZE_OP_JUMP;
- }
- else
- len += SIZE_OP_JUMP + mod_tlen + SIZE_OP_PUSH;
- }
- else if (qn->upper == 0 && qn->is_refered != 0) { /* /(?<n>..){0}/ */
- len = SIZE_OP_JUMP + tlen;
- }
- else if (!infinite && qn->greedy &&
- (qn->upper == 1 || (tlen + SIZE_OP_PUSH) * qn->upper
- <= QUALIFIER_EXPAND_LIMIT_SIZE)) {
- len = tlen * qn->lower;
- len += (SIZE_OP_PUSH + tlen) * (qn->upper - qn->lower);
- }
- else if (!qn->greedy && qn->upper == 1 && qn->lower == 0) { /* '??' */
- len = SIZE_OP_PUSH + SIZE_OP_JUMP + tlen;
- }
- else {
- len = SIZE_OP_REPEAT_INC
- + mod_tlen + SIZE_OPCODE + SIZE_RELADDR + SIZE_MEMNUM;
- }
-
- return len;
-}
-
-static int
-compile_qualifier_node(QualifierNode* qn, regex_t* reg)
-{
- int i, r, mod_tlen;
- int infinite = IS_REPEAT_INFINITE(qn->upper);
- int empty_info = qn->target_empty_info;
- int tlen = compile_length_tree(qn->target, reg);
-
- if (tlen < 0) return tlen;
-
- if (is_anychar_star_qualifier(qn)) {
- r = compile_tree_n_times(qn->target, qn->lower, reg);
- if (r) return r;
- if (IS_NOT_NULL(qn->next_head_exact)) {
- if (IS_MULTILINE(reg->options))
- r = add_opcode(reg, OP_ANYCHAR_ML_STAR_PEEK_NEXT);
- else
- r = add_opcode(reg, OP_ANYCHAR_STAR_PEEK_NEXT);
- if (r) return r;
- return add_bytes(reg, NSTRING(qn->next_head_exact).s, 1);
- }
- else {
- if (IS_MULTILINE(reg->options))
- return add_opcode(reg, OP_ANYCHAR_ML_STAR);
- else
- return add_opcode(reg, OP_ANYCHAR_STAR);
- }
- }
-
- if (empty_info != 0)
- mod_tlen = tlen + (SIZE_OP_NULL_CHECK_START + SIZE_OP_NULL_CHECK_END);
- else
- mod_tlen = tlen;
-
- if (infinite &&
- (qn->lower <= 1 || tlen * qn->lower <= QUALIFIER_EXPAND_LIMIT_SIZE)) {
- if (qn->lower == 1 && tlen > QUALIFIER_EXPAND_LIMIT_SIZE) {
- if (qn->greedy) {
- if (IS_NOT_NULL(qn->head_exact))
- r = add_opcode_rel_addr(reg, OP_JUMP, SIZE_OP_PUSH_OR_JUMP_EXACT1);
- else if (IS_NOT_NULL(qn->next_head_exact))
- r = add_opcode_rel_addr(reg, OP_JUMP, SIZE_OP_PUSH_IF_PEEK_NEXT);
- else
- r = add_opcode_rel_addr(reg, OP_JUMP, SIZE_OP_PUSH);
- }
- else {
- r = add_opcode_rel_addr(reg, OP_JUMP, SIZE_OP_JUMP);
- }
- if (r) return r;
- }
- else {
- r = compile_tree_n_times(qn->target, qn->lower, reg);
- if (r) return r;
- }
-
- if (qn->greedy) {
- if (IS_NOT_NULL(qn->head_exact)) {
- r = add_opcode_rel_addr(reg, OP_PUSH_OR_JUMP_EXACT1,
- mod_tlen + SIZE_OP_JUMP);
- if (r) return r;
- add_bytes(reg, NSTRING(qn->head_exact).s, 1);
- r = compile_tree_empty_check(qn->target, reg, empty_info);
- if (r) return r;
- r = add_opcode_rel_addr(reg, OP_JUMP,
- -(mod_tlen + (int )SIZE_OP_JUMP + (int )SIZE_OP_PUSH_OR_JUMP_EXACT1));
- }
- else if (IS_NOT_NULL(qn->next_head_exact)) {
- r = add_opcode_rel_addr(reg, OP_PUSH_IF_PEEK_NEXT,
- mod_tlen + SIZE_OP_JUMP);
- if (r) return r;
- add_bytes(reg, NSTRING(qn->next_head_exact).s, 1);
- r = compile_tree_empty_check(qn->target, reg, empty_info);
- if (r) return r;
- r = add_opcode_rel_addr(reg, OP_JUMP,
- -(mod_tlen + (int )SIZE_OP_JUMP + (int )SIZE_OP_PUSH_IF_PEEK_NEXT));
- }
- else {
- r = add_opcode_rel_addr(reg, OP_PUSH, mod_tlen + SIZE_OP_JUMP);
- if (r) return r;
- r = compile_tree_empty_check(qn->target, reg, empty_info);
- if (r) return r;
- r = add_opcode_rel_addr(reg, OP_JUMP,
- -(mod_tlen + (int )SIZE_OP_JUMP + (int )SIZE_OP_PUSH));
- }
- }
- else {
- r = add_opcode_rel_addr(reg, OP_JUMP, mod_tlen);
- if (r) return r;
- r = compile_tree_empty_check(qn->target, reg, empty_info);
- if (r) return r;
- r = add_opcode_rel_addr(reg, OP_PUSH, -(mod_tlen + (int )SIZE_OP_PUSH));
- }
- }
- else if (qn->upper == 0 && qn->is_refered != 0) { /* /(?<n>..){0}/ */
- r = add_opcode_rel_addr(reg, OP_JUMP, tlen);
- if (r) return r;
- r = compile_tree(qn->target, reg);
- }
- else if (!infinite && qn->greedy &&
- (qn->upper == 1 || (tlen + SIZE_OP_PUSH) * qn->upper
- <= QUALIFIER_EXPAND_LIMIT_SIZE)) {
- int n = qn->upper - qn->lower;
-
- r = compile_tree_n_times(qn->target, qn->lower, reg);
- if (r) return r;
-
- for (i = 0; i < n; i++) {
- r = add_opcode_rel_addr(reg, OP_PUSH,
- (n - i) * tlen + (n - i - 1) * SIZE_OP_PUSH);
- if (r) return r;
- r = compile_tree(qn->target, reg);
- if (r) return r;
- }
- }
- else if (!qn->greedy && qn->upper == 1 && qn->lower == 0) { /* '??' */
- r = add_opcode_rel_addr(reg, OP_PUSH, SIZE_OP_JUMP);
- if (r) return r;
- r = add_opcode_rel_addr(reg, OP_JUMP, tlen);
- if (r) return r;
- r = compile_tree(qn->target, reg);
- }
- else {
- r = compile_range_repeat_node(qn, mod_tlen, empty_info, reg);
- }
- return r;
-}
-#endif /* USE_COMBINATION_EXPLOSION_CHECK */
-
-static int
-compile_length_option_node(EffectNode* node, regex_t* reg)
-{
- int tlen;
- OnigOptionType prev = reg->options;
-
- reg->options = node->option;
- tlen = compile_length_tree(node->target, reg);
- reg->options = prev;
-
- if (tlen < 0) return tlen;
-
- if (IS_DYNAMIC_OPTION(prev ^ node->option)) {
- return SIZE_OP_SET_OPTION_PUSH + SIZE_OP_SET_OPTION + SIZE_OP_FAIL
- + tlen + SIZE_OP_SET_OPTION;
- }
- else
- return tlen;
-}
-
-static int
-compile_option_node(EffectNode* node, regex_t* reg)
-{
- int r;
- OnigOptionType prev = reg->options;
-
- if (IS_DYNAMIC_OPTION(prev ^ node->option)) {
- r = add_opcode_option(reg, OP_SET_OPTION_PUSH, node->option);
- if (r) return r;
- r = add_opcode_option(reg, OP_SET_OPTION, prev);
- if (r) return r;
- r = add_opcode(reg, OP_FAIL);
- if (r) return r;
- }
-
- reg->options = node->option;
- r = compile_tree(node->target, reg);
- reg->options = prev;
-
- if (IS_DYNAMIC_OPTION(prev ^ node->option)) {
- if (r) return r;
- r = add_opcode_option(reg, OP_SET_OPTION, prev);
- }
- return r;
-}
-
-static int
-compile_length_effect_node(EffectNode* node, regex_t* reg)
-{
- int len;
- int tlen;
-
- if (node->type == EFFECT_OPTION)
- return compile_length_option_node(node, reg);
-
- if (node->target) {
- tlen = compile_length_tree(node->target, reg);
- if (tlen < 0) return tlen;
- }
- else
- tlen = 0;
-
- switch (node->type) {
- case EFFECT_MEMORY:
-#ifdef USE_SUBEXP_CALL
- if (IS_EFFECT_CALLED(node)) {
- len = SIZE_OP_MEMORY_START_PUSH + tlen
- + SIZE_OP_CALL + SIZE_OP_JUMP + SIZE_OP_RETURN;
- if (BIT_STATUS_AT(reg->bt_mem_end, node->regnum))
- len += (IS_EFFECT_RECURSION(node)
- ? SIZE_OP_MEMORY_END_PUSH_REC : SIZE_OP_MEMORY_END_PUSH);
- else
- len += (IS_EFFECT_RECURSION(node)
- ? SIZE_OP_MEMORY_END_REC : SIZE_OP_MEMORY_END);
- }
- else
-#endif
- {
- if (BIT_STATUS_AT(reg->bt_mem_start, node->regnum))
- len = SIZE_OP_MEMORY_START_PUSH;
- else
- len = SIZE_OP_MEMORY_START;
-
- len += tlen + (BIT_STATUS_AT(reg->bt_mem_end, node->regnum)
- ? SIZE_OP_MEMORY_END_PUSH : SIZE_OP_MEMORY_END);
- }
- break;
-
- case EFFECT_STOP_BACKTRACK:
- if (IS_EFFECT_STOP_BT_SIMPLE_REPEAT(node)) {
- QualifierNode* qn = &NQUALIFIER(node->target);
- tlen = compile_length_tree(qn->target, reg);
- if (tlen < 0) return tlen;
-
- len = tlen * qn->lower
- + SIZE_OP_PUSH + tlen + SIZE_OP_POP + SIZE_OP_JUMP;
- }
- else {
- len = SIZE_OP_PUSH_STOP_BT + tlen + SIZE_OP_POP_STOP_BT;
- }
- break;
-
- default:
- return ONIGERR_TYPE_BUG;
- break;
- }
-
- return len;
-}
-
-static int get_char_length_tree(Node* node, regex_t* reg, int* len);
-
-static int
-compile_effect_node(EffectNode* node, regex_t* reg)
-{
- int r, len;
-
- if (node->type == EFFECT_OPTION)
- return compile_option_node(node, reg);
-
- switch (node->type) {
- case EFFECT_MEMORY:
-#ifdef USE_SUBEXP_CALL
- if (IS_EFFECT_CALLED(node)) {
- r = add_opcode(reg, OP_CALL);
- if (r) return r;
- node->call_addr = BBUF_GET_OFFSET_POS(reg) + SIZE_ABSADDR + SIZE_OP_JUMP;
- node->state |= NST_ADDR_FIXED;
- r = add_abs_addr(reg, (int )node->call_addr);
- if (r) return r;
- len = compile_length_tree(node->target, reg);
- len += (SIZE_OP_MEMORY_START_PUSH + SIZE_OP_RETURN);
- if (BIT_STATUS_AT(reg->bt_mem_end, node->regnum))
- len += (IS_EFFECT_RECURSION(node)
- ? SIZE_OP_MEMORY_END_PUSH_REC : SIZE_OP_MEMORY_END_PUSH);
- else
- len += (IS_EFFECT_RECURSION(node)
- ? SIZE_OP_MEMORY_END_REC : SIZE_OP_MEMORY_END);
-
- r = add_opcode_rel_addr(reg, OP_JUMP, len);
- if (r) return r;
- }
-#endif
- if (BIT_STATUS_AT(reg->bt_mem_start, node->regnum))
- r = add_opcode(reg, OP_MEMORY_START_PUSH);
- else
- r = add_opcode(reg, OP_MEMORY_START);
- if (r) return r;
- r = add_mem_num(reg, node->regnum);
- if (r) return r;
- r = compile_tree(node->target, reg);
- if (r) return r;
-#ifdef USE_SUBEXP_CALL
- if (IS_EFFECT_CALLED(node)) {
- if (BIT_STATUS_AT(reg->bt_mem_end, node->regnum))
- r = add_opcode(reg, (IS_EFFECT_RECURSION(node)
- ? OP_MEMORY_END_PUSH_REC : OP_MEMORY_END_PUSH));
- else
- r = add_opcode(reg, (IS_EFFECT_RECURSION(node)
- ? OP_MEMORY_END_REC : OP_MEMORY_END));
-
- if (r) return r;
- r = add_mem_num(reg, node->regnum);
- if (r) return r;
- r = add_opcode(reg, OP_RETURN);
- }
- else
-#endif
- {
- if (BIT_STATUS_AT(reg->bt_mem_end, node->regnum))
- r = add_opcode(reg, OP_MEMORY_END_PUSH);
- else
- r = add_opcode(reg, OP_MEMORY_END);
- if (r) return r;
- r = add_mem_num(reg, node->regnum);
- }
- break;
-
- case EFFECT_STOP_BACKTRACK:
- if (IS_EFFECT_STOP_BT_SIMPLE_REPEAT(node)) {
- QualifierNode* qn = &NQUALIFIER(node->target);
- r = compile_tree_n_times(qn->target, qn->lower, reg);
- if (r) return r;
-
- len = compile_length_tree(qn->target, reg);
- if (len < 0) return len;
-
- r = add_opcode_rel_addr(reg, OP_PUSH, len + SIZE_OP_POP + SIZE_OP_JUMP);
- if (r) return r;
- r = compile_tree(qn->target, reg);
- if (r) return r;
- r = add_opcode(reg, OP_POP);
- if (r) return r;
- r = add_opcode_rel_addr(reg, OP_JUMP,
- -((int )SIZE_OP_PUSH + len + (int )SIZE_OP_POP + (int )SIZE_OP_JUMP));
- }
- else {
- r = add_opcode(reg, OP_PUSH_STOP_BT);
- if (r) return r;
- r = compile_tree(node->target, reg);
- if (r) return r;
- r = add_opcode(reg, OP_POP_STOP_BT);
- }
- break;
-
- default:
- return ONIGERR_TYPE_BUG;
- break;
- }
-
- return r;
-}
-
-static int
-compile_length_anchor_node(AnchorNode* node, regex_t* reg)
-{
- int len;
- int tlen = 0;
-
- if (node->target) {
- tlen = compile_length_tree(node->target, reg);
- if (tlen < 0) return tlen;
- }
-
- switch (node->type) {
- case ANCHOR_PREC_READ:
- len = SIZE_OP_PUSH_POS + tlen + SIZE_OP_POP_POS;
- break;
- case ANCHOR_PREC_READ_NOT:
- len = SIZE_OP_PUSH_POS_NOT + tlen + SIZE_OP_FAIL_POS;
- break;
- case ANCHOR_LOOK_BEHIND:
- len = SIZE_OP_LOOK_BEHIND + tlen;
- break;
- case ANCHOR_LOOK_BEHIND_NOT:
- len = SIZE_OP_PUSH_LOOK_BEHIND_NOT + tlen + SIZE_OP_FAIL_LOOK_BEHIND_NOT;
- break;
-
- default:
- len = SIZE_OPCODE;
- break;
- }
-
- return len;
-}
-
-static int
-compile_anchor_node(AnchorNode* node, regex_t* reg)
-{
- int r, len;
-
- switch (node->type) {
- case ANCHOR_BEGIN_BUF: r = add_opcode(reg, OP_BEGIN_BUF); break;
- case ANCHOR_END_BUF: r = add_opcode(reg, OP_END_BUF); break;
- case ANCHOR_BEGIN_LINE: r = add_opcode(reg, OP_BEGIN_LINE); break;
- case ANCHOR_END_LINE: r = add_opcode(reg, OP_END_LINE); break;
- case ANCHOR_SEMI_END_BUF: r = add_opcode(reg, OP_SEMI_END_BUF); break;
- case ANCHOR_BEGIN_POSITION: r = add_opcode(reg, OP_BEGIN_POSITION); break;
-
- case ANCHOR_WORD_BOUND: r = add_opcode(reg, OP_WORD_BOUND); break;
- case ANCHOR_NOT_WORD_BOUND: r = add_opcode(reg, OP_NOT_WORD_BOUND); break;
-#ifdef USE_WORD_BEGIN_END
- case ANCHOR_WORD_BEGIN: r = add_opcode(reg, OP_WORD_BEGIN); break;
- case ANCHOR_WORD_END: r = add_opcode(reg, OP_WORD_END); break;
-#endif
-
- case ANCHOR_PREC_READ:
- r = add_opcode(reg, OP_PUSH_POS);
- if (r) return r;
- r = compile_tree(node->target, reg);
- if (r) return r;
- r = add_opcode(reg, OP_POP_POS);
- break;
-
- case ANCHOR_PREC_READ_NOT:
- len = compile_length_tree(node->target, reg);
- if (len < 0) return len;
- r = add_opcode_rel_addr(reg, OP_PUSH_POS_NOT, len + SIZE_OP_FAIL_POS);
- if (r) return r;
- r = compile_tree(node->target, reg);
- if (r) return r;
- r = add_opcode(reg, OP_FAIL_POS);
- break;
-
- case ANCHOR_LOOK_BEHIND:
- {
- int n;
- r = add_opcode(reg, OP_LOOK_BEHIND);
- if (r) return r;
- if (node->char_len < 0) {
- r = get_char_length_tree(node->target, reg, &n);
- if (r) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
- }
- else
- n = node->char_len;
- r = add_length(reg, n);
- if (r) return r;
- r = compile_tree(node->target, reg);
- }
- break;
-
- case ANCHOR_LOOK_BEHIND_NOT:
- {
- int n;
- len = compile_length_tree(node->target, reg);
- r = add_opcode_rel_addr(reg, OP_PUSH_LOOK_BEHIND_NOT,
- len + SIZE_OP_FAIL_LOOK_BEHIND_NOT);
- if (r) return r;
- if (node->char_len < 0) {
- r = get_char_length_tree(node->target, reg, &n);
- if (r) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
- }
- else
- n = node->char_len;
- r = add_length(reg, n);
- if (r) return r;
- r = compile_tree(node->target, reg);
- if (r) return r;
- r = add_opcode(reg, OP_FAIL_LOOK_BEHIND_NOT);
- }
- break;
-
- default:
- return ONIGERR_TYPE_BUG;
- break;
- }
-
- return r;
-}
-
-static int
-compile_length_tree(Node* node, regex_t* reg)
-{
- int len, type, r;
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- len = 0;
- do {
- r = compile_length_tree(NCONS(node).left, reg);
- if (r < 0) return r;
- len += r;
- } while (IS_NOT_NULL(node = NCONS(node).right));
- r = len;
- break;
-
- case N_ALT:
- {
- int n;
-
- n = r = 0;
- do {
- r += compile_length_tree(NCONS(node).left, reg);
- n++;
- } while (IS_NOT_NULL(node = NCONS(node).right));
- r += (SIZE_OP_PUSH + SIZE_OP_JUMP) * (n - 1);
- }
- break;
-
- case N_STRING:
- if (NSTRING_IS_RAW(node))
- r = compile_length_string_raw_node(&(NSTRING(node)), reg);
- else
- r = compile_length_string_node(node, reg);
- break;
-
- case N_CCLASS:
- r = compile_length_cclass_node(&(NCCLASS(node)), reg);
- break;
-
- case N_CTYPE:
- case N_ANYCHAR:
- r = SIZE_OPCODE;
- break;
-
- case N_BACKREF:
- {
- BackrefNode* br = &(NBACKREF(node));
-
-#ifdef USE_BACKREF_AT_LEVEL
- if (IS_BACKREF_NEST_LEVEL(br)) {
- r = SIZE_OPCODE + SIZE_OPTION + SIZE_LENGTH +
- SIZE_LENGTH + (SIZE_MEMNUM * br->back_num);
- }
- else
-#endif
- if (br->back_num == 1) {
- r = ((!IS_IGNORECASE(reg->options) && br->back_static[0] <= 2)
- ? SIZE_OPCODE : (SIZE_OPCODE + SIZE_MEMNUM));
- }
- else {
- r = SIZE_OPCODE + SIZE_LENGTH + (SIZE_MEMNUM * br->back_num);
- }
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
- r = SIZE_OP_CALL;
- break;
-#endif
-
- case N_QUALIFIER:
- r = compile_length_qualifier_node(&(NQUALIFIER(node)), reg);
- break;
-
- case N_EFFECT:
- r = compile_length_effect_node(&NEFFECT(node), reg);
- break;
-
- case N_ANCHOR:
- r = compile_length_anchor_node(&(NANCHOR(node)), reg);
- break;
-
- default:
- return ONIGERR_TYPE_BUG;
- break;
- }
-
- return r;
-}
-
-static int
-compile_tree(Node* node, regex_t* reg)
-{
- int n, type, len, pos, r = 0;
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- do {
- r = compile_tree(NCONS(node).left, reg);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_ALT:
- {
- Node* x = node;
- len = 0;
- do {
- len += compile_length_tree(NCONS(x).left, reg);
- if (NCONS(x).right != NULL) {
- len += SIZE_OP_PUSH + SIZE_OP_JUMP;
- }
- } while (IS_NOT_NULL(x = NCONS(x).right));
- pos = reg->used + len; /* goal position */
-
- do {
- len = compile_length_tree(NCONS(node).left, reg);
- if (IS_NOT_NULL(NCONS(node).right)) {
- r = add_opcode_rel_addr(reg, OP_PUSH, len + SIZE_OP_JUMP);
- if (r) break;
- }
- r = compile_tree(NCONS(node).left, reg);
- if (r) break;
- if (IS_NOT_NULL(NCONS(node).right)) {
- len = pos - (reg->used + SIZE_OP_JUMP);
- r = add_opcode_rel_addr(reg, OP_JUMP, len);
- if (r) break;
- }
- } while (IS_NOT_NULL(node = NCONS(node).right));
- }
- break;
-
- case N_STRING:
- if (NSTRING_IS_RAW(node))
- r = compile_string_raw_node(&(NSTRING(node)), reg);
- else
- r = compile_string_node(node, reg);
- break;
-
- case N_CCLASS:
- r = compile_cclass_node(&(NCCLASS(node)), reg);
- break;
-
- case N_CTYPE:
- {
- int op;
-
- switch (NCTYPE(node).type) {
- case CTYPE_WORD: op = OP_WORD; break;
- case CTYPE_NOT_WORD: op = OP_NOT_WORD; break;
- default:
- return ONIGERR_TYPE_BUG;
- break;
- }
- r = add_opcode(reg, op);
- }
- break;
-
- case N_ANYCHAR:
- if (IS_MULTILINE(reg->options))
- r = add_opcode(reg, OP_ANYCHAR_ML);
- else
- r = add_opcode(reg, OP_ANYCHAR);
- break;
-
- case N_BACKREF:
- {
- BackrefNode* br = &(NBACKREF(node));
-
-#ifdef USE_BACKREF_AT_LEVEL
- if (IS_BACKREF_NEST_LEVEL(br)) {
- r = add_opcode(reg, OP_BACKREF_AT_LEVEL);
- if (r) return r;
- r = add_option(reg, (reg->options & ONIG_OPTION_IGNORECASE));
- if (r) return r;
- r = add_length(reg, br->nest_level);
- if (r) return r;
-
- goto add_bacref_mems;
- }
- else
-#endif
- if (br->back_num == 1) {
- n = br->back_static[0];
- if (IS_IGNORECASE(reg->options)) {
- r = add_opcode(reg, OP_BACKREFN_IC);
- if (r) return r;
- r = add_mem_num(reg, n);
- }
- else {
- switch (n) {
- case 1: r = add_opcode(reg, OP_BACKREF1); break;
- case 2: r = add_opcode(reg, OP_BACKREF2); break;
- default:
- r = add_opcode(reg, OP_BACKREFN);
- if (r) return r;
- r = add_mem_num(reg, n);
- break;
- }
- }
- }
- else {
- int i;
- int* p;
-
- if (IS_IGNORECASE(reg->options)) {
- r = add_opcode(reg, OP_BACKREF_MULTI_IC);
- }
- else {
- r = add_opcode(reg, OP_BACKREF_MULTI);
- }
- if (r) return r;
-
-#ifdef USE_BACKREF_AT_LEVEL
- add_bacref_mems:
-#endif
- r = add_length(reg, br->back_num);
- if (r) return r;
- p = BACKREFS_P(br);
- for (i = br->back_num - 1; i >= 0; i--) {
- r = add_mem_num(reg, p[i]);
- if (r) return r;
- }
- }
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
- r = compile_call(&(NCALL(node)), reg);
- break;
-#endif
-
- case N_QUALIFIER:
- r = compile_qualifier_node(&(NQUALIFIER(node)), reg);
- break;
-
- case N_EFFECT:
- r = compile_effect_node(&NEFFECT(node), reg);
- break;
-
- case N_ANCHOR:
- r = compile_anchor_node(&(NANCHOR(node)), reg);
- break;
-
- default:
-#ifdef ONIG_DEBUG
- fprintf(stderr, "compile_tree: undefined node type %d\n", NTYPE(node));
-#endif
- break;
- }
-
- return r;
-}
-
-#ifdef USE_NAMED_GROUP
-
-static int
-noname_disable_map(Node** plink, GroupNumRemap* map, int* counter)
-{
- int r = 0;
- Node* node = *plink;
-
- switch (NTYPE(node)) {
- case N_LIST:
- case N_ALT:
- do {
- r = noname_disable_map(&(NCONS(node).left), map, counter);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_QUALIFIER:
- {
- Node** ptarget = &(NQUALIFIER(node).target);
- Node* old = *ptarget;
- r = noname_disable_map(ptarget, map, counter);
- if (*ptarget != old && NTYPE(*ptarget) == N_QUALIFIER) {
- onig_reduce_nested_qualifier(node, *ptarget);
- }
- }
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
- if (en->type == EFFECT_MEMORY) {
- if (IS_EFFECT_NAMED_GROUP(en)) {
- (*counter)++;
- map[en->regnum].new_val = *counter;
- en->regnum = *counter;
- r = noname_disable_map(&(en->target), map, counter);
- }
- else {
- *plink = en->target;
- en->target = NULL_NODE;
- onig_node_free(node);
- r = noname_disable_map(plink, map, counter);
- }
- }
- else
- r = noname_disable_map(&(en->target), map, counter);
- }
- break;
-
- default:
- break;
- }
-
- return r;
-}
-
-static int
-renumber_node_backref(Node* node, GroupNumRemap* map)
-{
- int i, pos, n, old_num;
- int *backs;
- BackrefNode* bn = &(NBACKREF(node));
-
- if (! IS_BACKREF_NAME_REF(bn))
- return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED;
-
- old_num = bn->back_num;
- if (IS_NULL(bn->back_dynamic))
- backs = bn->back_static;
- else
- backs = bn->back_dynamic;
-
- for (i = 0, pos = 0; i < old_num; i++) {
- n = map[backs[i]].new_val;
- if (n > 0) {
- backs[pos] = n;
- pos++;
- }
- }
-
- bn->back_num = pos;
- return 0;
-}
-
-static int
-renumber_by_map(Node* node, GroupNumRemap* map)
-{
- int r = 0;
-
- switch (NTYPE(node)) {
- case N_LIST:
- case N_ALT:
- do {
- r = renumber_by_map(NCONS(node).left, map);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
- case N_QUALIFIER:
- r = renumber_by_map(NQUALIFIER(node).target, map);
- break;
- case N_EFFECT:
- r = renumber_by_map(NEFFECT(node).target, map);
- break;
-
- case N_BACKREF:
- r = renumber_node_backref(node, map);
- break;
-
- default:
- break;
- }
-
- return r;
-}
-
-static int
-numbered_ref_check(Node* node)
-{
- int r = 0;
-
- switch (NTYPE(node)) {
- case N_LIST:
- case N_ALT:
- do {
- r = numbered_ref_check(NCONS(node).left);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
- case N_QUALIFIER:
- r = numbered_ref_check(NQUALIFIER(node).target);
- break;
- case N_EFFECT:
- r = numbered_ref_check(NEFFECT(node).target);
- break;
-
- case N_BACKREF:
- if (! IS_BACKREF_NAME_REF(&(NBACKREF(node))))
- return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED;
- break;
-
- default:
- break;
- }
-
- return r;
-}
-
-static int
-disable_noname_group_capture(Node** root, regex_t* reg, ScanEnv* env)
-{
- int r, i, pos, counter;
- BitStatusType loc;
- GroupNumRemap* map;
-
- map = (GroupNumRemap* )xalloca(sizeof(GroupNumRemap) * (env->num_mem + 1));
- CHECK_NULL_RETURN_VAL(map, ONIGERR_MEMORY);
- for (i = 1; i <= env->num_mem; i++) {
- map[i].new_val = 0;
- }
- counter = 0;
- r = noname_disable_map(root, map, &counter);
- if (r != 0) return r;
-
- r = renumber_by_map(*root, map);
- if (r != 0) return r;
-
- for (i = 1, pos = 1; i <= env->num_mem; i++) {
- if (map[i].new_val > 0) {
- SCANENV_MEM_NODES(env)[pos] = SCANENV_MEM_NODES(env)[i];
- pos++;
- }
- }
-
- loc = env->capture_history;
- BIT_STATUS_CLEAR(env->capture_history);
- for (i = 1; i <= ONIG_MAX_CAPTURE_HISTORY_GROUP; i++) {
- if (BIT_STATUS_AT(loc, i)) {
- BIT_STATUS_ON_AT_SIMPLE(env->capture_history, map[i].new_val);
- }
- }
-
- env->num_mem = env->num_named;
- reg->num_mem = env->num_named;
-
- return onig_renumber_name_table(reg, map);
-}
-#endif /* USE_NAMED_GROUP */
-
-#ifdef USE_SUBEXP_CALL
-static int
-unset_addr_list_fix(UnsetAddrList* uslist, regex_t* reg)
-{
- int i, offset;
- EffectNode* en;
- AbsAddrType addr;
-
- for (i = 0; i < uslist->num; i++) {
- en = &(NEFFECT(uslist->us[i].target));
- if (! IS_EFFECT_ADDR_FIXED(en)) return ONIGERR_PARSER_BUG;
- addr = en->call_addr;
- offset = uslist->us[i].offset;
-
- BBUF_WRITE(reg, offset, &addr, SIZE_ABSADDR);
- }
- return 0;
-}
-#endif
-
-#ifdef USE_INFINITE_REPEAT_MONOMANIAC_MEM_STATUS_CHECK
-static int
-qualifiers_memory_node_info(Node* node)
-{
- int r = 0;
-
- switch (NTYPE(node)) {
- case N_LIST:
- case N_ALT:
- {
- int v;
- do {
- v = qualifiers_memory_node_info(NCONS(node).left);
- if (v > r) r = v;
- } while (v >= 0 && IS_NOT_NULL(node = NCONS(node).right));
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
- if (IS_CALL_RECURSION(&NCALL(node))) {
- return NQ_TARGET_IS_EMPTY_REC; /* tiny version */
- }
- else
- r = qualifiers_memory_node_info(NCALL(node).target);
- break;
-#endif
-
- case N_QUALIFIER:
- {
- QualifierNode* qn = &(NQUALIFIER(node));
- if (qn->upper != 0) {
- r = qualifiers_memory_node_info(qn->target);
- }
- }
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
- switch (en->type) {
- case EFFECT_MEMORY:
- return NQ_TARGET_IS_EMPTY_MEM;
- break;
-
- case EFFECT_OPTION:
- case EFFECT_STOP_BACKTRACK:
- r = qualifiers_memory_node_info(en->target);
- break;
- default:
- break;
- }
- }
- break;
-
- case N_BACKREF:
- case N_STRING:
- case N_CTYPE:
- case N_CCLASS:
- case N_ANYCHAR:
- case N_ANCHOR:
- default:
- break;
- }
-
- return r;
-}
-#endif /* USE_INFINITE_REPEAT_MONOMANIAC_MEM_STATUS_CHECK */
-
-static int
-get_min_match_length(Node* node, OnigDistance *min, ScanEnv* env)
-{
- OnigDistance tmin;
- int r = 0;
-
- *min = 0;
- switch (NTYPE(node)) {
- case N_BACKREF:
- {
- int i;
- int* backs;
- Node** nodes = SCANENV_MEM_NODES(env);
- BackrefNode* br = &(NBACKREF(node));
- if (br->state & NST_RECURSION) break;
-
- backs = BACKREFS_P(br);
- if (backs[0] > env->num_mem) return ONIGERR_INVALID_BACKREF;
- r = get_min_match_length(nodes[backs[0]], min, env);
- if (r != 0) break;
- for (i = 1; i < br->back_num; i++) {
- if (backs[i] > env->num_mem) return ONIGERR_INVALID_BACKREF;
- r = get_min_match_length(nodes[backs[i]], &tmin, env);
- if (r != 0) break;
- if (*min > tmin) *min = tmin;
- }
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
- if (IS_CALL_RECURSION(&NCALL(node))) {
- EffectNode* en = &(NEFFECT(NCALL(node).target));
- if (IS_EFFECT_MIN_FIXED(en))
- *min = en->min_len;
- }
- else
- r = get_min_match_length(NCALL(node).target, min, env);
- break;
-#endif
-
- case N_LIST:
- do {
- r = get_min_match_length(NCONS(node).left, &tmin, env);
- if (r == 0) *min += tmin;
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_ALT:
- {
- Node *x, *y;
- y = node;
- do {
- x = NCONS(y).left;
- r = get_min_match_length(x, &tmin, env);
- if (r != 0) break;
- if (y == node) *min = tmin;
- else if (*min > tmin) *min = tmin;
- } while (r == 0 && IS_NOT_NULL(y = NCONS(y).right));
- }
- break;
-
- case N_STRING:
- {
- StrNode* sn = &(NSTRING(node));
- *min = sn->end - sn->s;
- }
- break;
-
- case N_CTYPE:
- switch (NCTYPE(node).type) {
- case CTYPE_WORD: *min = 1; break;
- case CTYPE_NOT_WORD: *min = 1; break;
- default:
- break;
- }
- break;
-
- case N_CCLASS:
- case N_ANYCHAR:
- *min = 1;
- break;
-
- case N_QUALIFIER:
- {
- QualifierNode* qn = &(NQUALIFIER(node));
-
- if (qn->lower > 0) {
- r = get_min_match_length(qn->target, min, env);
- if (r == 0)
- *min = distance_multiply(*min, qn->lower);
- }
- }
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
- switch (en->type) {
- case EFFECT_MEMORY:
-#ifdef USE_SUBEXP_CALL
- if (IS_EFFECT_MIN_FIXED(en))
- *min = en->min_len;
- else {
- r = get_min_match_length(en->target, min, env);
- if (r == 0) {
- en->min_len = *min;
- SET_EFFECT_STATUS(node, NST_MIN_FIXED);
- }
- }
- break;
-#endif
- case EFFECT_OPTION:
- case EFFECT_STOP_BACKTRACK:
- r = get_min_match_length(en->target, min, env);
- break;
- }
- }
- break;
-
- case N_ANCHOR:
- default:
- break;
- }
-
- return r;
-}
-
-static int
-get_max_match_length(Node* node, OnigDistance *max, ScanEnv* env)
-{
- OnigDistance tmax;
- int r = 0;
-
- *max = 0;
- switch (NTYPE(node)) {
- case N_LIST:
- do {
- r = get_max_match_length(NCONS(node).left, &tmax, env);
- if (r == 0)
- *max = distance_add(*max, tmax);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_ALT:
- do {
- r = get_max_match_length(NCONS(node).left, &tmax, env);
- if (r == 0 && *max < tmax) *max = tmax;
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_STRING:
- {
- StrNode* sn = &(NSTRING(node));
- *max = sn->end - sn->s;
- }
- break;
-
- case N_CTYPE:
- switch (NCTYPE(node).type) {
- case CTYPE_WORD:
- case CTYPE_NOT_WORD:
- *max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
- break;
-
- default:
- break;
- }
- break;
-
- case N_CCLASS:
- case N_ANYCHAR:
- *max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
- break;
-
- case N_BACKREF:
- {
- int i;
- int* backs;
- Node** nodes = SCANENV_MEM_NODES(env);
- BackrefNode* br = &(NBACKREF(node));
- if (br->state & NST_RECURSION) {
- *max = ONIG_INFINITE_DISTANCE;
- break;
- }
- backs = BACKREFS_P(br);
- for (i = 0; i < br->back_num; i++) {
- if (backs[i] > env->num_mem) return ONIGERR_INVALID_BACKREF;
- r = get_max_match_length(nodes[backs[i]], &tmax, env);
- if (r != 0) break;
- if (*max < tmax) *max = tmax;
- }
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
- if (! IS_CALL_RECURSION(&(NCALL(node))))
- r = get_max_match_length(NCALL(node).target, max, env);
- else
- *max = ONIG_INFINITE_DISTANCE;
- break;
-#endif
-
- case N_QUALIFIER:
- {
- QualifierNode* qn = &(NQUALIFIER(node));
-
- if (qn->upper != 0) {
- r = get_max_match_length(qn->target, max, env);
- if (r == 0 && *max != 0) {
- if (! IS_REPEAT_INFINITE(qn->upper))
- *max = distance_multiply(*max, qn->upper);
- else
- *max = ONIG_INFINITE_DISTANCE;
- }
- }
- }
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
- switch (en->type) {
- case EFFECT_MEMORY:
-#ifdef USE_SUBEXP_CALL
- if (IS_EFFECT_MAX_FIXED(en))
- *max = en->max_len;
- else {
- r = get_max_match_length(en->target, max, env);
- if (r == 0) {
- en->max_len = *max;
- SET_EFFECT_STATUS(node, NST_MAX_FIXED);
- }
- }
- break;
-#endif
- case EFFECT_OPTION:
- case EFFECT_STOP_BACKTRACK:
- r = get_max_match_length(en->target, max, env);
- break;
- }
- }
- break;
-
- case N_ANCHOR:
- default:
- break;
- }
-
- return r;
-}
-
-#define GET_CHAR_LEN_VARLEN -1
-#define GET_CHAR_LEN_TOP_ALT_VARLEN -2
-
-/* fixed size pattern node only */
-static int
-get_char_length_tree1(Node* node, regex_t* reg, int* len, int level)
-{
- int tlen;
- int r = 0;
-
- level++;
- *len = 0;
- switch (NTYPE(node)) {
- case N_LIST:
- do {
- r = get_char_length_tree1(NCONS(node).left, reg, &tlen, level);
- if (r == 0)
- *len = distance_add(*len, tlen);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_ALT:
- {
- int tlen2;
- int varlen = 0;
-
- r = get_char_length_tree1(NCONS(node).left, reg, &tlen, level);
- while (r == 0 && IS_NOT_NULL(node = NCONS(node).right)) {
- r = get_char_length_tree1(NCONS(node).left, reg, &tlen2, level);
- if (r == 0) {
- if (tlen != tlen2)
- varlen = 1;
- }
- }
- if (r == 0) {
- if (varlen != 0) {
- if (level == 1)
- r = GET_CHAR_LEN_TOP_ALT_VARLEN;
- else
- r = GET_CHAR_LEN_VARLEN;
- }
- else
- *len = tlen;
- }
- }
- break;
-
- case N_STRING:
- {
- StrNode* sn = &(NSTRING(node));
- UChar *s = sn->s;
- while (s < sn->end) {
- s += enc_len(reg->enc, s);
- (*len)++;
- }
- }
- break;
-
- case N_QUALIFIER:
- {
- QualifierNode* qn = &(NQUALIFIER(node));
- if (qn->lower == qn->upper) {
- r = get_char_length_tree1(qn->target, reg, &tlen, level);
- if (r == 0)
- *len = distance_multiply(tlen, qn->lower);
- }
- else
- r = GET_CHAR_LEN_VARLEN;
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
- if (! IS_CALL_RECURSION(&(NCALL(node))))
- r = get_char_length_tree1(NCALL(node).target, reg, len, level);
- else
- r = GET_CHAR_LEN_VARLEN;
- break;
-#endif
-
- case N_CTYPE:
- switch (NCTYPE(node).type) {
- case CTYPE_WORD:
- case CTYPE_NOT_WORD:
- *len = 1;
- break;
- }
- break;
-
- case N_CCLASS:
- case N_ANYCHAR:
- *len = 1;
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
- switch (en->type) {
- case EFFECT_MEMORY:
-#ifdef USE_SUBEXP_CALL
- if (IS_EFFECT_CLEN_FIXED(en))
- *len = en->char_len;
- else {
- r = get_char_length_tree1(en->target, reg, len, level);
- if (r == 0) {
- en->char_len = *len;
- SET_EFFECT_STATUS(node, NST_CLEN_FIXED);
- }
- }
- break;
-#endif
- case EFFECT_OPTION:
- case EFFECT_STOP_BACKTRACK:
- r = get_char_length_tree1(en->target, reg, len, level);
- break;
- default:
- break;
- }
- }
- break;
-
- case N_ANCHOR:
- break;
-
- default:
- r = GET_CHAR_LEN_VARLEN;
- break;
- }
-
- return r;
-}
-
-static int
-get_char_length_tree(Node* node, regex_t* reg, int* len)
-{
- return get_char_length_tree1(node, reg, len, 0);
-}
-
-/* x is not included y ==> 1 : 0 */
-static int
-is_not_included(Node* x, Node* y, regex_t* reg)
-{
- int i, len;
- OnigCodePoint code;
- UChar *p, c;
- int ytype;
-
- retry:
- ytype = NTYPE(y);
- switch (NTYPE(x)) {
- case N_CTYPE:
- {
- switch (ytype) {
- case N_CTYPE:
- switch (NCTYPE(x).type) {
- case CTYPE_WORD:
- if (NCTYPE(y).type == CTYPE_NOT_WORD)
- return 1;
- else
- return 0;
- break;
- case CTYPE_NOT_WORD:
- if (NCTYPE(y).type == CTYPE_WORD)
- return 1;
- else
- return 0;
- break;
- default:
- break;
- }
- break;
-
- case N_CCLASS:
- swap:
- {
- Node* tmp;
- tmp = x; x = y; y = tmp;
- goto retry;
- }
- break;
-
- case N_STRING:
- goto swap;
- break;
-
- default:
- break;
- }
- }
- break;
-
- case N_CCLASS:
- {
- CClassNode* xc = &(NCCLASS(x));
- switch (ytype) {
- case N_CTYPE:
- switch (NCTYPE(y).type) {
- case CTYPE_WORD:
- if (IS_NULL(xc->mbuf) && !IS_CCLASS_NOT(xc)) {
- for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
- if (BITSET_AT(xc->bs, i)) {
- if (ONIGENC_IS_CODE_SB_WORD(reg->enc, i)) return 0;
- }
- }
- return 1;
- }
- return 0;
- break;
- case CTYPE_NOT_WORD:
- for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
- if (! ONIGENC_IS_CODE_SB_WORD(reg->enc, i)) {
- if (!IS_CCLASS_NOT(xc)) {
- if (BITSET_AT(xc->bs, i))
- return 0;
- }
- else {
- if (! BITSET_AT(xc->bs, i))
- return 0;
- }
- }
- }
- return 1;
- break;
-
- default:
- break;
- }
- break;
-
- case N_CCLASS:
- {
- int v;
- CClassNode* yc = &(NCCLASS(y));
-
- for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
- v = BITSET_AT(xc->bs, i);
- if ((v != 0 && !IS_CCLASS_NOT(xc)) ||
- (v == 0 && IS_CCLASS_NOT(xc))) {
- v = BITSET_AT(yc->bs, i);
- if ((v != 0 && !IS_CCLASS_NOT(yc)) ||
- (v == 0 && IS_CCLASS_NOT(yc)))
- return 0;
- }
- }
- if ((IS_NULL(xc->mbuf) && !IS_CCLASS_NOT(xc)) ||
- (IS_NULL(yc->mbuf) && !IS_CCLASS_NOT(yc)))
- return 1;
- return 0;
- }
- break;
-
- case N_STRING:
- goto swap;
- break;
-
- default:
- break;
- }
- }
- break;
-
- case N_STRING:
- {
- StrNode* xs = &(NSTRING(x));
- if (NSTRING_LEN(x) == 0)
- break;
-
- c = *(xs->s);
- switch (ytype) {
- case N_CTYPE:
- switch (NCTYPE(y).type) {
- case CTYPE_WORD:
- return (ONIGENC_IS_MBC_WORD(reg->enc, xs->s, xs->end) ? 0 : 1);
- break;
- case CTYPE_NOT_WORD:
- return (ONIGENC_IS_MBC_WORD(reg->enc, xs->s, xs->end) ? 1 : 0);
- break;
- default:
- break;
- }
- break;
-
- case N_CCLASS:
- {
- CClassNode* cc = &(NCCLASS(y));
-
- code = ONIGENC_MBC_TO_CODE(reg->enc, xs->s,
- xs->s + ONIGENC_MBC_MAXLEN(reg->enc));
- return (onig_is_code_in_cc(reg->enc, code, cc) != 0 ? 0 : 1);
- }
- break;
-
- case N_STRING:
- {
- UChar *q;
- StrNode* ys = &(NSTRING(y));
- len = NSTRING_LEN(x);
- if (len > NSTRING_LEN(y)) len = NSTRING_LEN(y);
- if (NSTRING_IS_AMBIG(x) || NSTRING_IS_AMBIG(y)) {
- /* tiny version */
- return 0;
- }
- else {
- for (i = 0, p = ys->s, q = xs->s; i < len; i++, p++, q++) {
- if (*p != *q) return 1;
- }
- }
- }
- break;
-
- default:
- break;
- }
- }
- break;
-
- default:
- break;
- }
-
- return 0;
-}
-
-static Node*
-get_head_value_node(Node* node, int exact, regex_t* reg)
-{
- Node* n = NULL_NODE;
-
- switch (NTYPE(node)) {
- case N_BACKREF:
- case N_ALT:
- case N_ANYCHAR:
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
-#endif
- break;
-
- case N_CTYPE:
- case N_CCLASS:
- if (exact == 0) {
- n = node;
- }
- break;
-
- case N_LIST:
- n = get_head_value_node(NCONS(node).left, exact, reg);
- break;
-
- case N_STRING:
- {
- StrNode* sn = &(NSTRING(node));
-
- if (sn->end <= sn->s)
- break;
-
- if (exact != 0 &&
- !NSTRING_IS_RAW(node) && IS_IGNORECASE(reg->options)) {
-#if 0
- UChar* tmp = sn->s;
- if (! ONIGENC_IS_MBC_AMBIGUOUS(reg->enc, reg->ambig_flag,
- &tmp, sn->end))
- n = node;
-#endif
- }
- else {
- n = node;
- }
- }
- break;
-
- case N_QUALIFIER:
- {
- QualifierNode* qn = &(NQUALIFIER(node));
- if (qn->lower > 0) {
- if (IS_NOT_NULL(qn->head_exact))
- n = qn->head_exact;
- else
- n = get_head_value_node(qn->target, exact, reg);
- }
- }
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
- switch (en->type) {
- case EFFECT_OPTION:
- {
- OnigOptionType options = reg->options;
-
- reg->options = NEFFECT(node).option;
- n = get_head_value_node(NEFFECT(node).target, exact, reg);
- reg->options = options;
- }
- break;
-
- case EFFECT_MEMORY:
- case EFFECT_STOP_BACKTRACK:
- n = get_head_value_node(en->target, exact, reg);
- break;
- }
- }
- break;
-
- case N_ANCHOR:
- if (NANCHOR(node).type == ANCHOR_PREC_READ)
- n = get_head_value_node(NANCHOR(node).target, exact, reg);
- break;
-
- default:
- break;
- }
-
- return n;
-}
-
-static int
-check_type_tree(Node* node, int type_mask, int effect_mask, int anchor_mask)
-{
- int type, r = 0;
-
- type = NTYPE(node);
- if ((type & type_mask) == 0)
- return 1;
-
- switch (type) {
- case N_LIST:
- case N_ALT:
- do {
- r = check_type_tree(NCONS(node).left, type_mask, effect_mask, anchor_mask);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_QUALIFIER:
- r = check_type_tree(NQUALIFIER(node).target, type_mask, effect_mask,
- anchor_mask);
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
- if ((en->type & effect_mask) == 0)
- return 1;
-
- r = check_type_tree(en->target, type_mask, effect_mask, anchor_mask);
- }
- break;
-
- case N_ANCHOR:
- type = NANCHOR(node).type;
- if ((type & anchor_mask) == 0)
- return 1;
-
- if (NANCHOR(node).target)
- r = check_type_tree(NANCHOR(node).target,
- type_mask, effect_mask, anchor_mask);
- break;
-
- default:
- break;
- }
- return r;
-}
-
-#ifdef USE_SUBEXP_CALL
-
-#define RECURSION_EXIST 1
-#define RECURSION_INFINITE 2
-
-static int
-subexp_inf_recursive_check(Node* node, ScanEnv* env, int head)
-{
- int type;
- int r = 0;
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- {
- Node *x;
- OnigDistance min;
- int ret;
-
- x = node;
- do {
- ret = subexp_inf_recursive_check(NCONS(x).left, env, head);
- if (ret < 0 || ret == RECURSION_INFINITE) return ret;
- r |= ret;
- if (head) {
- ret = get_min_match_length(NCONS(x).left, &min, env);
- if (ret != 0) return ret;
- if (min != 0) head = 0;
- }
- } while (IS_NOT_NULL(x = NCONS(x).right));
- }
- break;
-
- case N_ALT:
- {
- int ret;
- r = RECURSION_EXIST;
- do {
- ret = subexp_inf_recursive_check(NCONS(node).left, env, head);
- if (ret < 0 || ret == RECURSION_INFINITE) return ret;
- r &= ret;
- } while (IS_NOT_NULL(node = NCONS(node).right));
- }
- break;
-
- case N_QUALIFIER:
- r = subexp_inf_recursive_check(NQUALIFIER(node).target, env, head);
- if (r == RECURSION_EXIST) {
- if (NQUALIFIER(node).lower == 0) r = 0;
- }
- break;
-
- case N_ANCHOR:
- {
- AnchorNode* an = &(NANCHOR(node));
- switch (an->type) {
- case ANCHOR_PREC_READ:
- case ANCHOR_PREC_READ_NOT:
- case ANCHOR_LOOK_BEHIND:
- case ANCHOR_LOOK_BEHIND_NOT:
- r = subexp_inf_recursive_check(an->target, env, head);
- break;
- }
- }
- break;
-
- case N_CALL:
- r = subexp_inf_recursive_check(NCALL(node).target, env, head);
- break;
-
- case N_EFFECT:
- if (IS_EFFECT_MARK2(&(NEFFECT(node))))
- return 0;
- else if (IS_EFFECT_MARK1(&(NEFFECT(node))))
- return (head == 0 ? RECURSION_EXIST : RECURSION_INFINITE);
- else {
- SET_EFFECT_STATUS(node, NST_MARK2);
- r = subexp_inf_recursive_check(NEFFECT(node).target, env, head);
- CLEAR_EFFECT_STATUS(node, NST_MARK2);
- }
- break;
-
- default:
- break;
- }
-
- return r;
-}
-
-static int
-subexp_inf_recursive_check_trav(Node* node, ScanEnv* env)
-{
- int type;
- int r = 0;
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- case N_ALT:
- do {
- r = subexp_inf_recursive_check_trav(NCONS(node).left, env);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_QUALIFIER:
- r = subexp_inf_recursive_check_trav(NQUALIFIER(node).target, env);
- break;
-
- case N_ANCHOR:
- {
- AnchorNode* an = &(NANCHOR(node));
- switch (an->type) {
- case ANCHOR_PREC_READ:
- case ANCHOR_PREC_READ_NOT:
- case ANCHOR_LOOK_BEHIND:
- case ANCHOR_LOOK_BEHIND_NOT:
- r = subexp_inf_recursive_check_trav(an->target, env);
- break;
- }
- }
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
-
- if (IS_EFFECT_RECURSION(en)) {
- SET_EFFECT_STATUS(node, NST_MARK1);
- r = subexp_inf_recursive_check(en->target, env, 1);
- if (r > 0) return ONIGERR_NEVER_ENDING_RECURSION;
- CLEAR_EFFECT_STATUS(node, NST_MARK1);
- }
- r = subexp_inf_recursive_check_trav(en->target, env);
- }
-
- break;
-
- default:
- break;
- }
-
- return r;
-}
-
-static int
-subexp_recursive_check(Node* node)
-{
- int type;
- int r = 0;
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- case N_ALT:
- do {
- r |= subexp_recursive_check(NCONS(node).left);
- } while (IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_QUALIFIER:
- r = subexp_recursive_check(NQUALIFIER(node).target);
- break;
-
- case N_ANCHOR:
- {
- AnchorNode* an = &(NANCHOR(node));
- switch (an->type) {
- case ANCHOR_PREC_READ:
- case ANCHOR_PREC_READ_NOT:
- case ANCHOR_LOOK_BEHIND:
- case ANCHOR_LOOK_BEHIND_NOT:
- r = subexp_recursive_check(an->target);
- break;
- }
- }
- break;
-
- case N_CALL:
- r = subexp_recursive_check(NCALL(node).target);
- if (r != 0) SET_CALL_RECURSION(node);
- break;
-
- case N_EFFECT:
- if (IS_EFFECT_MARK2(&(NEFFECT(node))))
- return 0;
- else if (IS_EFFECT_MARK1(&(NEFFECT(node))))
- return 1; /* recursion */
- else {
- SET_EFFECT_STATUS(node, NST_MARK2);
- r = subexp_recursive_check(NEFFECT(node).target);
- CLEAR_EFFECT_STATUS(node, NST_MARK2);
- }
- break;
-
- default:
- break;
- }
-
- return r;
-}
-
-
-static int
-subexp_recursive_check_trav(Node* node, ScanEnv* env)
-{
-#define FOUND_CALLED_NODE 1
-
- int type;
- int r = 0;
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- case N_ALT:
- {
- int ret;
- do {
- ret = subexp_recursive_check_trav(NCONS(node).left, env);
- if (ret == FOUND_CALLED_NODE) r = FOUND_CALLED_NODE;
- else if (ret < 0) return ret;
- } while (IS_NOT_NULL(node = NCONS(node).right));
- }
- break;
-
- case N_QUALIFIER:
- r = subexp_recursive_check_trav(NQUALIFIER(node).target, env);
- if (NQUALIFIER(node).upper == 0) {
- if (r == FOUND_CALLED_NODE)
- NQUALIFIER(node).is_refered = 1;
- }
- break;
-
- case N_ANCHOR:
- {
- AnchorNode* an = &(NANCHOR(node));
- switch (an->type) {
- case ANCHOR_PREC_READ:
- case ANCHOR_PREC_READ_NOT:
- case ANCHOR_LOOK_BEHIND:
- case ANCHOR_LOOK_BEHIND_NOT:
- r = subexp_recursive_check_trav(an->target, env);
- break;
- }
- }
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
-
- if (! IS_EFFECT_RECURSION(en)) {
- if (IS_EFFECT_CALLED(en)) {
- SET_EFFECT_STATUS(node, NST_MARK1);
- r = subexp_recursive_check(en->target);
- if (r != 0) SET_EFFECT_STATUS(node, NST_RECURSION);
- CLEAR_EFFECT_STATUS(node, NST_MARK1);
- }
- }
- r = subexp_recursive_check_trav(en->target, env);
- if (IS_EFFECT_CALLED(en))
- r |= FOUND_CALLED_NODE;
- }
- break;
-
- default:
- break;
- }
-
- return r;
-}
-
-static int
-setup_subexp_call(Node* node, ScanEnv* env)
-{
- int type;
- int r = 0;
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- do {
- r = setup_subexp_call(NCONS(node).left, env);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_ALT:
- do {
- r = setup_subexp_call(NCONS(node).left, env);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_QUALIFIER:
- r = setup_subexp_call(NQUALIFIER(node).target, env);
- break;
- case N_EFFECT:
- r = setup_subexp_call(NEFFECT(node).target, env);
- break;
-
- case N_CALL:
- {
- int n, num, *refs;
- UChar *p;
- CallNode* cn = &(NCALL(node));
- Node** nodes = SCANENV_MEM_NODES(env);
-
-#ifdef USE_NAMED_GROUP
- n = onig_name_to_group_numbers(env->reg, cn->name, cn->name_end, &refs);
-#else
- n = -1;
-#endif
- if (n <= 0) {
- /* name not found, check group number. (?*ddd) */
- p = cn->name;
- num = onig_scan_unsigned_number(&p, cn->name_end, env->enc);
- if (num <= 0 || p != cn->name_end) {
- onig_scan_env_set_error_string(env,
- ONIGERR_UNDEFINED_NAME_REFERENCE, cn->name, cn->name_end);
- return ONIGERR_UNDEFINED_NAME_REFERENCE;
- }
-#ifdef USE_NAMED_GROUP
- if (env->num_named > 0 &&
- IS_SYNTAX_BV(env->syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) &&
- !ONIG_IS_OPTION_ON(env->option, ONIG_OPTION_CAPTURE_GROUP)) {
- return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED;
- }
-#endif
- if (num > env->num_mem) {
- onig_scan_env_set_error_string(env,
- ONIGERR_UNDEFINED_GROUP_REFERENCE, cn->name, cn->name_end);
- return ONIGERR_UNDEFINED_GROUP_REFERENCE;
- }
- cn->ref_num = num;
- goto set_call_attr;
- }
- else if (n > 1) {
- onig_scan_env_set_error_string(env,
- ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL, cn->name, cn->name_end);
- return ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL;
- }
- else {
- cn->ref_num = refs[0];
- set_call_attr:
- cn->target = nodes[cn->ref_num];
- if (IS_NULL(cn->target)) {
- onig_scan_env_set_error_string(env,
- ONIGERR_UNDEFINED_NAME_REFERENCE, cn->name, cn->name_end);
- return ONIGERR_UNDEFINED_NAME_REFERENCE;
- }
- SET_EFFECT_STATUS(cn->target, NST_CALLED);
- BIT_STATUS_ON_AT(env->bt_mem_start, cn->ref_num);
- cn->unset_addr_list = env->unset_addr_list;
- }
- }
- break;
-
- case N_ANCHOR:
- {
- AnchorNode* an = &(NANCHOR(node));
-
- switch (an->type) {
- case ANCHOR_PREC_READ:
- case ANCHOR_PREC_READ_NOT:
- case ANCHOR_LOOK_BEHIND:
- case ANCHOR_LOOK_BEHIND_NOT:
- r = setup_subexp_call(an->target, env);
- break;
- }
- }
- break;
-
- default:
- break;
- }
-
- return r;
-}
-#endif
-
-/* divide different length alternatives in look-behind.
- (?<=A|B) ==> (?<=A)|(?<=B)
- (?<!A|B) ==> (?<!A)(?<!B)
-*/
-static int
-divide_look_behind_alternatives(Node* node)
-{
- Node tmp_node;
- Node *head, *np, *insert_node;
- AnchorNode* an = &(NANCHOR(node));
- int anc_type = an->type;
-
- head = an->target;
- np = NCONS(head).left;
- tmp_node = *node; *node = *head; *head = tmp_node;
- NCONS(node).left = head;
- NANCHOR(head).target = np;
-
- np = node;
- while ((np = NCONS(np).right) != NULL_NODE) {
- insert_node = onig_node_new_anchor(anc_type);
- CHECK_NULL_RETURN_VAL(insert_node, ONIGERR_MEMORY);
- NANCHOR(insert_node).target = NCONS(np).left;
- NCONS(np).left = insert_node;
- }
-
- if (anc_type == ANCHOR_LOOK_BEHIND_NOT) {
- np = node;
- do {
- np->type = N_LIST; /* alt -> list */
- } while ((np = NCONS(np).right) != NULL_NODE);
- }
- return 0;
-}
-
-static int
-setup_look_behind(Node* node, regex_t* reg, ScanEnv* env)
-{
- int r, len;
- AnchorNode* an = &(NANCHOR(node));
-
- r = get_char_length_tree(an->target, reg, &len);
- if (r == 0)
- an->char_len = len;
- else if (r == GET_CHAR_LEN_VARLEN)
- r = ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
- else if (r == GET_CHAR_LEN_TOP_ALT_VARLEN) {
- if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND))
- r = divide_look_behind_alternatives(node);
- else
- r = ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
- }
-
- return r;
-}
-
-static int
-next_setup(Node* node, Node* next_node, regex_t* reg)
-{
- int type;
-
- retry:
- type = NTYPE(node);
- if (type == N_QUALIFIER) {
- QualifierNode* qn = &(NQUALIFIER(node));
- if (qn->greedy && IS_REPEAT_INFINITE(qn->upper)) {
-#ifdef USE_QUALIFIER_PEEK_NEXT
- qn->next_head_exact = get_head_value_node(next_node, 1, reg);
-#endif
- /* automatic posseivation a*b ==> (?>a*)b */
- if (qn->lower <= 1) {
- int ttype = NTYPE(qn->target);
- if (IS_NODE_TYPE_SIMPLE(ttype)) {
- Node *x, *y;
- x = get_head_value_node(qn->target, 0, reg);
- if (IS_NOT_NULL(x)) {
- y = get_head_value_node(next_node, 0, reg);
- if (IS_NOT_NULL(y) && is_not_included(x, y, reg)) {
- Node* en = onig_node_new_effect(EFFECT_STOP_BACKTRACK);
- CHECK_NULL_RETURN_VAL(en, ONIGERR_MEMORY);
- SET_EFFECT_STATUS(en, NST_STOP_BT_SIMPLE_REPEAT);
- swap_node(node, en);
- NEFFECT(node).target = en;
- }
- }
- }
- }
- }
- }
- else if (type == N_EFFECT) {
- EffectNode* en = &(NEFFECT(node));
- if (en->type == EFFECT_MEMORY) {
- node = en->target;
- goto retry;
- }
- }
- return 0;
-}
-
-
-static int
-divide_ambig_string_node_sub(regex_t* reg, int prev_ambig,
- UChar* prev_start, UChar* prev,
- UChar* end, Node*** tailp, Node** root)
-{
- UChar *tmp, *wp;
- Node* snode;
-
- if (prev_ambig != 0) {
- tmp = prev_start;
- wp = prev_start;
- while (tmp < prev) {
- wp += ONIGENC_MBC_TO_NORMALIZE(reg->enc, reg->ambig_flag,
- &tmp, end, wp);
- }
- snode = onig_node_new_str(prev_start, wp);
- CHECK_NULL_RETURN_VAL(snode, ONIGERR_MEMORY);
- NSTRING_SET_AMBIG(snode);
- if (wp != prev) NSTRING_SET_AMBIG_REDUCE(snode);
- }
- else {
- snode = onig_node_new_str(prev_start, prev);
- CHECK_NULL_RETURN_VAL(snode, ONIGERR_MEMORY);
- }
-
- if (*tailp == (Node** )0) {
- *root = onig_node_new_list(snode, NULL);
- CHECK_NULL_RETURN_VAL(*root, ONIGERR_MEMORY);
- *tailp = &(NCONS(*root).right);
- }
- else {
- **tailp = onig_node_new_list(snode, NULL);
- CHECK_NULL_RETURN_VAL(**tailp, ONIGERR_MEMORY);
- *tailp = &(NCONS(**tailp).right);
- }
-
- return 0;
-}
-
-static int
-divide_ambig_string_node(Node* node, regex_t* reg)
-{
- StrNode* sn = &NSTRING(node);
- int ambig, prev_ambig;
- UChar *prev, *p, *end, *prev_start, *start, *tmp, *wp;
- Node *root = NULL_NODE;
- Node **tailp = (Node** )0;
- int r;
-
- start = prev_start = p = sn->s;
- end = sn->end;
- if (p >= end) return 0;
-
- prev_ambig = ONIGENC_IS_MBC_AMBIGUOUS(reg->enc, reg->ambig_flag, &p, end);
-
- while (p < end) {
- prev = p;
- if (prev_ambig != (ambig = ONIGENC_IS_MBC_AMBIGUOUS(reg->enc,
- reg->ambig_flag, &p, end))) {
-
- r = divide_ambig_string_node_sub(reg, prev_ambig, prev_start, prev,
- end, &tailp, &root);
- if (r != 0) return r;
-
- prev_ambig = ambig;
- prev_start = prev;
- }
- }
-
- if (prev_start == start) {
- if (prev_ambig != 0) {
- NSTRING_SET_AMBIG(node);
- tmp = start;
- wp = start;
- while (tmp < end) {
- wp += ONIGENC_MBC_TO_NORMALIZE(reg->enc, reg->ambig_flag,
- &tmp, end, wp);
- }
- if (wp != sn->end) NSTRING_SET_AMBIG_REDUCE(node);
- sn->end = wp;
- }
- }
- else {
- r = divide_ambig_string_node_sub(reg, prev_ambig, prev_start, end,
- end, &tailp, &root);
- if (r != 0) return r;
-
- swap_node(node, root);
- onig_node_str_clear(root); /* should be after swap! */
- onig_node_free(root); /* free original string node */
- }
-
- return 0;
-}
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
-
-#define CEC_THRES_NUM_BIG_REPEAT 512
-#define CEC_INFINITE_NUM 0x7fffffff
-
-#define CEC_IN_INFINITE_REPEAT (1<<0)
-#define CEC_IN_FINITE_REPEAT (1<<1)
-#define CEC_CONT_BIG_REPEAT (1<<2)
-
-static int
-setup_comb_exp_check(Node* node, int state, ScanEnv* env)
-{
- int type;
- int r = state;
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- {
- Node* prev = NULL_NODE;
- do {
- r = setup_comb_exp_check(NCONS(node).left, r, env);
- prev = NCONS(node).left;
- } while (r >= 0 && IS_NOT_NULL(node = NCONS(node).right));
- }
- break;
-
- case N_ALT:
- {
- int ret;
- do {
- ret = setup_comb_exp_check(NCONS(node).left, state, env);
- r |= ret;
- } while (ret >= 0 && IS_NOT_NULL(node = NCONS(node).right));
- }
- break;
-
- case N_QUALIFIER:
- {
- int child_state = state;
- int add_state = 0;
- QualifierNode* qn = &(NQUALIFIER(node));
- Node* target = qn->target;
- int var_num;
-
- if (! IS_REPEAT_INFINITE(qn->upper)) {
- if (qn->upper > 1) {
- /* {0,1}, {1,1} are allowed */
- child_state |= CEC_IN_FINITE_REPEAT;
-
- /* check (a*){n,m}, (a+){n,m} => (a*){n,n}, (a+){n,n} */
- if (env->backrefed_mem == 0) {
- if (NTYPE(qn->target) == N_EFFECT) {
- EffectNode* en = &(NEFFECT(qn->target));
- if (en->type == EFFECT_MEMORY) {
- if (NTYPE(en->target) == N_QUALIFIER) {
- QualifierNode* q = &(NQUALIFIER(en->target));
- if (IS_REPEAT_INFINITE(q->upper)
- && q->greedy == qn->greedy) {
- qn->upper = (qn->lower == 0 ? 1 : qn->lower);
- if (qn->upper == 1)
- child_state = state;
- }
- }
- }
- }
- }
- }
- }
-
- if (state & CEC_IN_FINITE_REPEAT) {
- qn->comb_exp_check_num = -1;
- }
- else {
- if (IS_REPEAT_INFINITE(qn->upper)) {
- var_num = CEC_INFINITE_NUM;
- child_state |= CEC_IN_INFINITE_REPEAT;
- }
- else {
- var_num = qn->upper - qn->lower;
- }
-
- if (var_num >= CEC_THRES_NUM_BIG_REPEAT)
- add_state |= CEC_CONT_BIG_REPEAT;
-
- if (((state & CEC_IN_INFINITE_REPEAT) != 0 && var_num != 0) ||
- ((state & CEC_CONT_BIG_REPEAT) != 0 &&
- var_num >= CEC_THRES_NUM_BIG_REPEAT)) {
- if (qn->comb_exp_check_num == 0) {
- env->num_comb_exp_check++;
- qn->comb_exp_check_num = env->num_comb_exp_check;
- if (env->curr_max_regnum > env->comb_exp_max_regnum)
- env->comb_exp_max_regnum = env->curr_max_regnum;
- }
- }
- }
-
- r = setup_comb_exp_check(target, child_state, env);
- r |= add_state;
- }
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
-
- switch (en->type) {
- case EFFECT_MEMORY:
- {
- if (env->curr_max_regnum < en->regnum)
- env->curr_max_regnum = en->regnum;
-
- r = setup_comb_exp_check(en->target, state, env);
- }
- break;
-
- default:
- r = setup_comb_exp_check(en->target, state, env);
- break;
- }
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
- if (IS_CALL_RECURSION(&(NCALL(node))))
- env->has_recursion = 1;
- else
- r = setup_comb_exp_check(NCALL(node).target, state, env);
- break;
-#endif
-
- default:
- break;
- }
-
- return r;
-}
-#endif
-
-#define IN_ALT (1<<0)
-#define IN_NOT (1<<1)
-#define IN_REPEAT (1<<2)
-#define IN_VAR_REPEAT (1<<3)
-
-/* setup_tree does the following work.
- 1. check empty loop. (set qn->target_empty_info)
- 2. expand ignore-case in char class.
- 3. set memory status bit flags. (reg->mem_stats)
- 4. set qn->head_exact for [push, exact] -> [push_or_jump_exact1, exact].
- 5. find invalid patterns in look-behind.
- 6. expand repeated string.
- */
-static int
-setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
-{
- int type;
- int r = 0;
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- {
- Node* prev = NULL_NODE;
- do {
- r = setup_tree(NCONS(node).left, reg, state, env);
- if (IS_NOT_NULL(prev) && r == 0) {
- r = next_setup(prev, NCONS(node).left, reg);
- }
- prev = NCONS(node).left;
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- }
- break;
-
- case N_ALT:
- do {
- r = setup_tree(NCONS(node).left, reg, (state | IN_ALT), env);
- } while (r == 0 && IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- case N_CCLASS:
- break;
-
- case N_STRING:
- if (IS_IGNORECASE(reg->options) && !NSTRING_IS_RAW(node)) {
- r = divide_ambig_string_node(node, reg);
- }
- break;
-
- case N_CTYPE:
- case N_ANYCHAR:
- break;
-
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
- break;
-#endif
-
- case N_BACKREF:
- {
- int i;
- int* p;
- Node** nodes = SCANENV_MEM_NODES(env);
- BackrefNode* br = &(NBACKREF(node));
- p = BACKREFS_P(br);
- for (i = 0; i < br->back_num; i++) {
- if (p[i] > env->num_mem) return ONIGERR_INVALID_BACKREF;
- BIT_STATUS_ON_AT(env->backrefed_mem, p[i]);
- BIT_STATUS_ON_AT(env->bt_mem_start, p[i]);
-#ifdef USE_BACKREF_AT_LEVEL
- if (IS_BACKREF_NEST_LEVEL(br)) {
- BIT_STATUS_ON_AT(env->bt_mem_end, p[i]);
- }
-#endif
- SET_EFFECT_STATUS(nodes[p[i]], NST_MEM_BACKREFED);
- }
- }
- break;
-
- case N_QUALIFIER:
- {
- OnigDistance d;
- QualifierNode* qn = &(NQUALIFIER(node));
- Node* target = qn->target;
-
- if ((state & IN_REPEAT) != 0) {
- qn->state |= NST_IN_REPEAT;
- }
-
- if (IS_REPEAT_INFINITE(qn->upper) || qn->upper >= 1) {
- r = get_min_match_length(target, &d, env);
- if (r) break;
- if (d == 0) {
- qn->target_empty_info = NQ_TARGET_IS_EMPTY;
-#ifdef USE_INFINITE_REPEAT_MONOMANIAC_MEM_STATUS_CHECK
- r = qualifiers_memory_node_info(target);
- if (r < 0) break;
- if (r > 0) {
- qn->target_empty_info = r;
- }
-#endif
-#if 0
- r = get_max_match_length(target, &d, env);
- if (r == 0 && d == 0) {
- /* ()* ==> ()?, ()+ ==> () */
- qn->upper = 1;
- if (qn->lower > 1) qn->lower = 1;
- if (NTYPE(target) == N_STRING) {
- qn->upper = qn->lower = 0; /* /(?:)+/ ==> // */
- }
- }
-#endif
- }
- }
-
- state |= IN_REPEAT;
- if (qn->lower != qn->upper)
- state |= IN_VAR_REPEAT;
- r = setup_tree(target, reg, state, env);
- if (r) break;
-
- /* expand string */
-#define EXPAND_STRING_MAX_LENGTH 100
- if (NTYPE(target) == N_STRING) {
- if (!IS_REPEAT_INFINITE(qn->lower) && qn->lower == qn->upper &&
- qn->lower > 1 && qn->lower <= EXPAND_STRING_MAX_LENGTH) {
- int len = NSTRING_LEN(target);
- StrNode* sn = &(NSTRING(target));
-
- if (len * qn->lower <= EXPAND_STRING_MAX_LENGTH) {
- int i, n = qn->lower;
- onig_node_conv_to_str_node(node, NSTRING(target).flag);
- for (i = 0; i < n; i++) {
- r = onig_node_str_cat(node, sn->s, sn->end);
- if (r) break;
- }
- onig_node_free(target);
- break; /* break case N_QUALIFIER: */
- }
- }
- }
-
-#ifdef USE_OP_PUSH_OR_JUMP_EXACT
- if (qn->greedy && (qn->target_empty_info != 0)) {
- if (NTYPE(target) == N_QUALIFIER) {
- QualifierNode* tqn = &(NQUALIFIER(target));
- if (IS_NOT_NULL(tqn->head_exact)) {
- qn->head_exact = tqn->head_exact;
- tqn->head_exact = NULL;
- }
- }
- else {
- qn->head_exact = get_head_value_node(qn->target, 1, reg);
- }
- }
-#endif
- }
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
-
- switch (en->type) {
- case EFFECT_OPTION:
- {
- OnigOptionType options = reg->options;
- reg->options = NEFFECT(node).option;
- r = setup_tree(NEFFECT(node).target, reg, state, env);
- reg->options = options;
- }
- break;
-
- case EFFECT_MEMORY:
- if ((state & (IN_ALT | IN_NOT | IN_VAR_REPEAT)) != 0) {
- BIT_STATUS_ON_AT(env->bt_mem_start, en->regnum);
- /* SET_EFFECT_STATUS(node, NST_MEM_IN_ALT_NOT); */
- }
- r = setup_tree(en->target, reg, state, env);
- break;
-
- case EFFECT_STOP_BACKTRACK:
- {
- Node* target = en->target;
- r = setup_tree(target, reg, state, env);
- if (NTYPE(target) == N_QUALIFIER) {
- QualifierNode* tqn = &(NQUALIFIER(target));
- if (IS_REPEAT_INFINITE(tqn->upper) && tqn->lower <= 1 &&
- tqn->greedy != 0) { /* (?>a*), a*+ etc... */
- int qtype = NTYPE(tqn->target);
- if (IS_NODE_TYPE_SIMPLE(qtype))
- SET_EFFECT_STATUS(node, NST_STOP_BT_SIMPLE_REPEAT);
- }
- }
- }
- break;
- }
- }
- break;
-
- case N_ANCHOR:
- {
- AnchorNode* an = &(NANCHOR(node));
-
- switch (an->type) {
- case ANCHOR_PREC_READ:
- r = setup_tree(an->target, reg, state, env);
- break;
- case ANCHOR_PREC_READ_NOT:
- r = setup_tree(an->target, reg, (state | IN_NOT), env);
- break;
-
-/* allowed node types in look-behind */
-#define ALLOWED_TYPE_IN_LB \
- ( N_LIST | N_ALT | N_STRING | N_CCLASS | N_CTYPE | \
- N_ANYCHAR | N_ANCHOR | N_EFFECT | N_QUALIFIER | N_CALL )
-
-#define ALLOWED_EFFECT_IN_LB ( EFFECT_MEMORY )
-#define ALLOWED_EFFECT_IN_LB_NOT 0
-
-#define ALLOWED_ANCHOR_IN_LB \
-( ANCHOR_LOOK_BEHIND | ANCHOR_BEGIN_LINE | ANCHOR_END_LINE | ANCHOR_BEGIN_BUF | ANCHOR_BEGIN_POSITION )
-#define ALLOWED_ANCHOR_IN_LB_NOT \
-( ANCHOR_LOOK_BEHIND | ANCHOR_LOOK_BEHIND_NOT | ANCHOR_BEGIN_LINE | ANCHOR_END_LINE | ANCHOR_BEGIN_BUF | ANCHOR_BEGIN_POSITION )
-
- case ANCHOR_LOOK_BEHIND:
- {
- r = check_type_tree(an->target, ALLOWED_TYPE_IN_LB,
- ALLOWED_EFFECT_IN_LB, ALLOWED_ANCHOR_IN_LB);
- if (r < 0) return r;
- if (r > 0) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
- r = setup_look_behind(node, reg, env);
- if (r != 0) return r;
- r = setup_tree(an->target, reg, state, env);
- }
- break;
-
- case ANCHOR_LOOK_BEHIND_NOT:
- {
- r = check_type_tree(an->target, ALLOWED_TYPE_IN_LB,
- ALLOWED_EFFECT_IN_LB_NOT, ALLOWED_ANCHOR_IN_LB_NOT);
- if (r < 0) return r;
- if (r > 0) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
- r = setup_look_behind(node, reg, env);
- if (r != 0) return r;
- r = setup_tree(an->target, reg, (state | IN_NOT), env);
- }
- break;
- }
- }
- break;
-
- default:
- break;
- }
-
- return r;
-}
-
-/* set skip map for Boyer-Moor search */
-static int
-set_bm_skip(UChar* s, UChar* end, OnigEncoding enc,
- UChar skip[], int** int_skip)
-{
- int i, len;
-
- len = end - s;
- if (len < ONIG_CHAR_TABLE_SIZE) {
- for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) skip[i] = len;
-
- for (i = 0; i < len - 1; i++)
- skip[s[i]] = len - 1 - i;
- }
- else {
- if (IS_NULL(*int_skip)) {
- *int_skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
- if (IS_NULL(*int_skip)) return ONIGERR_MEMORY;
- }
- for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) (*int_skip)[i] = len;
-
- for (i = 0; i < len - 1; i++)
- (*int_skip)[s[i]] = len - 1 - i;
- }
- return 0;
-}
-
-#define OPT_EXACT_MAXLEN 24
-
-typedef struct {
- OnigDistance min; /* min byte length */
- OnigDistance max; /* max byte length */
-} MinMaxLen;
-
-typedef struct {
- MinMaxLen mmd;
- OnigEncoding enc;
- OnigOptionType options;
- OnigAmbigType ambig_flag;
- ScanEnv* scan_env;
-} OptEnv;
-
-typedef struct {
- int left_anchor;
- int right_anchor;
-} OptAncInfo;
-
-typedef struct {
- MinMaxLen mmd; /* info position */
- OptAncInfo anc;
-
- int reach_end;
- int ignore_case;
- int len;
- UChar s[OPT_EXACT_MAXLEN];
-} OptExactInfo;
-
-typedef struct {
- MinMaxLen mmd; /* info position */
- OptAncInfo anc;
-
- int value; /* weighted value */
- UChar map[ONIG_CHAR_TABLE_SIZE];
-} OptMapInfo;
-
-typedef struct {
- MinMaxLen len;
-
- OptAncInfo anc;
- OptExactInfo exb; /* boundary */
- OptExactInfo exm; /* middle */
- OptExactInfo expr; /* prec read (?=...) */
-
- OptMapInfo map; /* boundary */
-} NodeOptInfo;
-
-
-static int
-map_position_value(OnigEncoding enc, int i)
-{
- static const short int ByteValTable[] = {
- 5, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 1, 1, 10, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 12, 4, 7, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5,
- 5, 6, 6, 6, 6, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 5, 5, 5,
- 5, 6, 6, 6, 6, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 1
- };
-
- if (i < sizeof(ByteValTable)/sizeof(ByteValTable[0])) {
- if (i == 0 && ONIGENC_MBC_MINLEN(enc) > 1)
- return 20;
- else
- return (int )ByteValTable[i];
- }
- else
- return 4; /* Take it easy. */
-}
-
-static int
-distance_value(MinMaxLen* mm)
-{
- /* 1000 / (min-max-dist + 1) */
- static const short int dist_vals[] = {
- 1000, 500, 333, 250, 200, 167, 143, 125, 111, 100,
- 91, 83, 77, 71, 67, 63, 59, 56, 53, 50,
- 48, 45, 43, 42, 40, 38, 37, 36, 34, 33,
- 32, 31, 30, 29, 29, 28, 27, 26, 26, 25,
- 24, 24, 23, 23, 22, 22, 21, 21, 20, 20,
- 20, 19, 19, 19, 18, 18, 18, 17, 17, 17,
- 16, 16, 16, 16, 15, 15, 15, 15, 14, 14,
- 14, 14, 14, 14, 13, 13, 13, 13, 13, 13,
- 12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 10, 10, 10, 10, 10
- };
-
- int d;
-
- if (mm->max == ONIG_INFINITE_DISTANCE) return 0;
-
- d = mm->max - mm->min;
- if (d < sizeof(dist_vals)/sizeof(dist_vals[0]))
- /* return dist_vals[d] * 16 / (mm->min + 12); */
- return (int )dist_vals[d];
- else
- return 1;
-}
-
-static int
-comp_distance_value(MinMaxLen* d1, MinMaxLen* d2, int v1, int v2)
-{
- if (v2 <= 0) return -1;
- if (v1 <= 0) return 1;
-
- v1 *= distance_value(d1);
- v2 *= distance_value(d2);
-
- if (v2 > v1) return 1;
- if (v2 < v1) return -1;
-
- if (d2->min < d1->min) return 1;
- if (d2->min > d1->min) return -1;
- return 0;
-}
-
-static int
-is_equal_mml(MinMaxLen* a, MinMaxLen* b)
-{
- return (a->min == b->min && a->max == b->max) ? 1 : 0;
-}
-
-
-static void
-set_mml(MinMaxLen* mml, OnigDistance min, OnigDistance max)
-{
- mml->min = min;
- mml->max = max;
-}
-
-static void
-clear_mml(MinMaxLen* mml)
-{
- mml->min = mml->max = 0;
-}
-
-static void
-copy_mml(MinMaxLen* to, MinMaxLen* from)
-{
- to->min = from->min;
- to->max = from->max;
-}
-
-static void
-add_mml(MinMaxLen* to, MinMaxLen* from)
-{
- to->min = distance_add(to->min, from->min);
- to->max = distance_add(to->max, from->max);
-}
-
-#if 0
-static void
-add_len_mml(MinMaxLen* to, OnigDistance len)
-{
- to->min = distance_add(to->min, len);
- to->max = distance_add(to->max, len);
-}
-#endif
-
-static void
-alt_merge_mml(MinMaxLen* to, MinMaxLen* from)
-{
- if (to->min > from->min) to->min = from->min;
- if (to->max < from->max) to->max = from->max;
-}
-
-static void
-copy_opt_env(OptEnv* to, OptEnv* from)
-{
- *to = *from;
-}
-
-static void
-clear_opt_anc_info(OptAncInfo* anc)
-{
- anc->left_anchor = 0;
- anc->right_anchor = 0;
-}
-
-static void
-copy_opt_anc_info(OptAncInfo* to, OptAncInfo* from)
-{
- *to = *from;
-}
-
-static void
-concat_opt_anc_info(OptAncInfo* to, OptAncInfo* left, OptAncInfo* right,
- OnigDistance left_len, OnigDistance right_len)
-{
- clear_opt_anc_info(to);
-
- to->left_anchor = left->left_anchor;
- if (left_len == 0) {
- to->left_anchor |= right->left_anchor;
- }
-
- to->right_anchor = right->right_anchor;
- if (right_len == 0) {
- to->right_anchor |= left->right_anchor;
- }
-}
-
-static int
-is_left_anchor(int anc)
-{
- if (anc == ANCHOR_END_BUF || anc == ANCHOR_SEMI_END_BUF ||
- anc == ANCHOR_END_LINE || anc == ANCHOR_PREC_READ ||
- anc == ANCHOR_PREC_READ_NOT)
- return 0;
-
- return 1;
-}
-
-static int
-is_set_opt_anc_info(OptAncInfo* to, int anc)
-{
- if ((to->left_anchor & anc) != 0) return 1;
-
- return ((to->right_anchor & anc) != 0 ? 1 : 0);
-}
-
-static void
-add_opt_anc_info(OptAncInfo* to, int anc)
-{
- if (is_left_anchor(anc))
- to->left_anchor |= anc;
- else
- to->right_anchor |= anc;
-}
-
-static void
-remove_opt_anc_info(OptAncInfo* to, int anc)
-{
- if (is_left_anchor(anc))
- to->left_anchor &= ~anc;
- else
- to->right_anchor &= ~anc;
-}
-
-static void
-alt_merge_opt_anc_info(OptAncInfo* to, OptAncInfo* add)
-{
- to->left_anchor &= add->left_anchor;
- to->right_anchor &= add->right_anchor;
-}
-
-static int
-is_full_opt_exact_info(OptExactInfo* ex)
-{
- return (ex->len >= OPT_EXACT_MAXLEN ? 1 : 0);
-}
-
-static void
-clear_opt_exact_info(OptExactInfo* ex)
-{
- clear_mml(&ex->mmd);
- clear_opt_anc_info(&ex->anc);
- ex->reach_end = 0;
- ex->ignore_case = 0;
- ex->len = 0;
- ex->s[0] = '\0';
-}
-
-static void
-copy_opt_exact_info(OptExactInfo* to, OptExactInfo* from)
-{
- *to = *from;
-}
-
-static void
-concat_opt_exact_info(OptExactInfo* to, OptExactInfo* add, OnigEncoding enc)
-{
- int i, j, len;
- UChar *p, *end;
- OptAncInfo tanc;
-
- if (! to->ignore_case && add->ignore_case) {
- if (to->len >= add->len) return ; /* avoid */
-
- to->ignore_case = 1;
- }
-
- p = add->s;
- end = p + add->len;
- for (i = to->len; p < end; ) {
- len = enc_len(enc, p);
- if (i + len > OPT_EXACT_MAXLEN) break;
- for (j = 0; j < len && p < end; j++)
- to->s[i++] = *p++;
- }
-
- to->len = i;
- to->reach_end = (p == end ? add->reach_end : 0);
-
- concat_opt_anc_info(&tanc, &to->anc, &add->anc, 1, 1);
- if (! to->reach_end) tanc.right_anchor = 0;
- copy_opt_anc_info(&to->anc, &tanc);
-}
-
-static void
-concat_opt_exact_info_str(OptExactInfo* to,
- UChar* s, UChar* end, int raw, OnigEncoding enc)
-{
- int i, j, len;
- UChar *p;
-
- for (i = to->len, p = s; p < end && i < OPT_EXACT_MAXLEN; ) {
- len = enc_len(enc, p);
- if (i + len > OPT_EXACT_MAXLEN) break;
- for (j = 0; j < len && p < end; j++)
- to->s[i++] = *p++;
- }
-
- to->len = i;
-}
-
-static void
-alt_merge_opt_exact_info(OptExactInfo* to, OptExactInfo* add, OptEnv* env)
-{
- int i, j, len;
-
- if (add->len == 0 || to->len == 0) {
- clear_opt_exact_info(to);
- return ;
- }
-
- if (! is_equal_mml(&to->mmd, &add->mmd)) {
- clear_opt_exact_info(to);
- return ;
- }
-
- for (i = 0; i < to->len && i < add->len; ) {
- if (to->s[i] != add->s[i]) break;
- len = enc_len(env->enc, to->s + i);
-
- for (j = 1; j < len; j++) {
- if (to->s[i+j] != add->s[i+j]) break;
- }
- if (j < len) break;
- i += len;
- }
-
- if (! add->reach_end || i < add->len || i < to->len) {
- to->reach_end = 0;
- }
- to->len = i;
- to->ignore_case |= add->ignore_case;
-
- alt_merge_opt_anc_info(&to->anc, &add->anc);
- if (! to->reach_end) to->anc.right_anchor = 0;
-}
-
-static void
-select_opt_exact_info(OnigEncoding enc, OptExactInfo* now, OptExactInfo* alt)
-{
- int v1, v2;
-
- v1 = now->len;
- v2 = alt->len;
-
- if (v1 <= 2 && v2 <= 2) {
- /* ByteValTable[x] is big value --> low price */
- v2 = map_position_value(enc, now->s[0]);
- v1 = map_position_value(enc, alt->s[0]);
-
- if (now->len > 1) v1 += 5;
- if (alt->len > 1) v2 += 5;
- }
-
- if (now->ignore_case == 0) v1 *= 2;
- if (alt->ignore_case == 0) v2 *= 2;
-
- if (comp_distance_value(&now->mmd, &alt->mmd, v1, v2) > 0)
- copy_opt_exact_info(now, alt);
-}
-
-static void
-clear_opt_map_info(OptMapInfo* map)
-{
- static const OptMapInfo clean_info = {
- {0, 0}, {0, 0}, 0,
- {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- }
- };
-
- xmemcpy(map, &clean_info, sizeof(OptMapInfo));
-}
-
-static void
-copy_opt_map_info(OptMapInfo* to, OptMapInfo* from)
-{
- *to = *from;
-}
-
-static void
-add_char_opt_map_info(OptMapInfo* map, UChar c, OnigEncoding enc)
-{
- if (map->map[c] == 0) {
- map->map[c] = 1;
- map->value += map_position_value(enc, c);
- }
-}
-
-static int
-add_char_amb_opt_map_info(OptMapInfo* map, UChar* p, UChar* end,
- OnigEncoding enc, OnigAmbigType ambig_flag)
-{
- int i, j, n, len;
- UChar buf[ONIGENC_MBC_NORMALIZE_MAXLEN];
- OnigCodePoint code, ccode;
- const OnigCompAmbigCodes* ccs;
- const OnigPairAmbigCodes* pccs;
- OnigAmbigType amb;
-
- add_char_opt_map_info(map, p[0], enc);
- code = ONIGENC_MBC_TO_CODE(enc, p, end);
-
- for (amb = 0x01; amb <= ONIGENC_AMBIGUOUS_MATCH_LIMIT; amb <<= 1) {
- if ((amb & ambig_flag) == 0) continue;
-
- n = ONIGENC_GET_ALL_PAIR_AMBIG_CODES(enc, amb, &pccs);
- for (i = 0; i < n; i++) {
- if (pccs[i].from == code) {
- len = ONIGENC_CODE_TO_MBC(enc, pccs[i].to, buf);
- if (len < 0) return len;
- add_char_opt_map_info(map, buf[0], enc);
- }
- }
-
- if ((ambig_flag & ONIGENC_AMBIGUOUS_MATCH_COMPOUND) != 0) {
- n = ONIGENC_GET_ALL_COMP_AMBIG_CODES(enc, amb, &ccs);
- for (i = 0; i < n; i++) {
- if (ccs[i].code == code) {
- for (j = 0; j < ccs[i].n; j++) {
- ccode = ccs[i].items[j].code[0];
- len = ONIGENC_CODE_TO_MBC(enc, ccode, buf);
- if (len < 0) return len;
- add_char_opt_map_info(map, buf[0], enc);
- }
- break;
- }
- }
- }
- }
- return 0;
-}
-
-static void
-select_opt_map_info(OptMapInfo* now, OptMapInfo* alt)
-{
- static int z = 1<<15; /* 32768: something big value */
-
- int v1, v2;
-
- if (alt->value == 0) return ;
- if (now->value == 0) {
- copy_opt_map_info(now, alt);
- return ;
- }
-
- v1 = z / now->value;
- v2 = z / alt->value;
- if (comp_distance_value(&now->mmd, &alt->mmd, v1, v2) > 0)
- copy_opt_map_info(now, alt);
-}
-
-static int
-comp_opt_exact_or_map_info(OptExactInfo* e, OptMapInfo* m)
-{
-#define COMP_EM_BASE 20
- int ve, vm;
-
- if (m->value <= 0) return -1;
-
- ve = COMP_EM_BASE * e->len * (e->ignore_case ? 1 : 2);
- vm = COMP_EM_BASE * 5 * 2 / m->value;
- return comp_distance_value(&e->mmd, &m->mmd, ve, vm);
-}
-
-static void
-alt_merge_opt_map_info(OnigEncoding enc, OptMapInfo* to, OptMapInfo* add)
-{
- int i, val;
-
- /* if (! is_equal_mml(&to->mmd, &add->mmd)) return ; */
- if (to->value == 0) return ;
- if (add->value == 0 || to->mmd.max < add->mmd.min) {
- clear_opt_map_info(to);
- return ;
- }
-
- alt_merge_mml(&to->mmd, &add->mmd);
-
- val = 0;
- for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) {
- if (add->map[i])
- to->map[i] = 1;
-
- if (to->map[i])
- val += map_position_value(enc, i);
- }
- to->value = val;
-
- alt_merge_opt_anc_info(&to->anc, &add->anc);
-}
-
-static void
-set_bound_node_opt_info(NodeOptInfo* opt, MinMaxLen* mmd)
-{
- copy_mml(&(opt->exb.mmd), mmd);
- copy_mml(&(opt->expr.mmd), mmd);
- copy_mml(&(opt->map.mmd), mmd);
-}
-
-static void
-clear_node_opt_info(NodeOptInfo* opt)
-{
- clear_mml(&opt->len);
- clear_opt_anc_info(&opt->anc);
- clear_opt_exact_info(&opt->exb);
- clear_opt_exact_info(&opt->exm);
- clear_opt_exact_info(&opt->expr);
- clear_opt_map_info(&opt->map);
-}
-
-static void
-copy_node_opt_info(NodeOptInfo* to, NodeOptInfo* from)
-{
- *to = *from;
-}
-
-static void
-concat_left_node_opt_info(OnigEncoding enc, NodeOptInfo* to, NodeOptInfo* add)
-{
- int exb_reach, exm_reach;
- OptAncInfo tanc;
-
- concat_opt_anc_info(&tanc, &to->anc, &add->anc, to->len.max, add->len.max);
- copy_opt_anc_info(&to->anc, &tanc);
-
- if (add->exb.len > 0 && to->len.max == 0) {
- concat_opt_anc_info(&tanc, &to->anc, &add->exb.anc,
- to->len.max, add->len.max);
- copy_opt_anc_info(&add->exb.anc, &tanc);
- }
-
- if (add->map.value > 0 && to->len.max == 0) {
- if (add->map.mmd.max == 0)
- add->map.anc.left_anchor |= to->anc.left_anchor;
- }
-
- exb_reach = to->exb.reach_end;
- exm_reach = to->exm.reach_end;
-
- if (add->len.max != 0)
- to->exb.reach_end = to->exm.reach_end = 0;
-
- if (add->exb.len > 0) {
- if (exb_reach) {
- concat_opt_exact_info(&to->exb, &add->exb, enc);
- clear_opt_exact_info(&add->exb);
- }
- else if (exm_reach) {
- concat_opt_exact_info(&to->exm, &add->exb, enc);
- clear_opt_exact_info(&add->exb);
- }
- }
- select_opt_exact_info(enc, &to->exm, &add->exb);
- select_opt_exact_info(enc, &to->exm, &add->exm);
-
- if (to->expr.len > 0) {
- if (add->len.max > 0) {
- if (to->expr.len > (int )add->len.max)
- to->expr.len = add->len.max;
-
- if (to->expr.mmd.max == 0)
- select_opt_exact_info(enc, &to->exb, &to->expr);
- else
- select_opt_exact_info(enc, &to->exm, &to->expr);
- }
- }
- else if (add->expr.len > 0) {
- copy_opt_exact_info(&to->expr, &add->expr);
- }
-
- select_opt_map_info(&to->map, &add->map);
-
- add_mml(&to->len, &add->len);
-}
-
-static void
-alt_merge_node_opt_info(NodeOptInfo* to, NodeOptInfo* add, OptEnv* env)
-{
- alt_merge_opt_anc_info (&to->anc, &add->anc);
- alt_merge_opt_exact_info(&to->exb, &add->exb, env);
- alt_merge_opt_exact_info(&to->exm, &add->exm, env);
- alt_merge_opt_exact_info(&to->expr, &add->expr, env);
- alt_merge_opt_map_info(env->enc, &to->map, &add->map);
-
- alt_merge_mml(&to->len, &add->len);
-}
-
-
-#define MAX_NODE_OPT_INFO_REF_COUNT 5
-
-static int
-optimize_node_left(Node* node, NodeOptInfo* opt, OptEnv* env)
-{
- int type;
- int r = 0;
-
- clear_node_opt_info(opt);
- set_bound_node_opt_info(opt, &env->mmd);
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- {
- OptEnv nenv;
- NodeOptInfo nopt;
- Node* nd = node;
-
- copy_opt_env(&nenv, env);
- do {
- r = optimize_node_left(NCONS(nd).left, &nopt, &nenv);
- if (r == 0) {
- add_mml(&nenv.mmd, &nopt.len);
- concat_left_node_opt_info(env->enc, opt, &nopt);
- }
- } while (r == 0 && IS_NOT_NULL(nd = NCONS(nd).right));
- }
- break;
-
- case N_ALT:
- {
- NodeOptInfo nopt;
- Node* nd = node;
-
- do {
- r = optimize_node_left(NCONS(nd).left, &nopt, env);
- if (r == 0) {
- if (nd == node) copy_node_opt_info(opt, &nopt);
- else alt_merge_node_opt_info(opt, &nopt, env);
- }
- } while ((r == 0) && IS_NOT_NULL(nd = NCONS(nd).right));
- }
- break;
-
- case N_STRING:
- {
- StrNode* sn = &(NSTRING(node));
- int slen = sn->end - sn->s;
- int is_raw = NSTRING_IS_RAW(node);
-
- if (! NSTRING_IS_AMBIG(node)) {
- concat_opt_exact_info_str(&opt->exb, sn->s, sn->end,
- NSTRING_IS_RAW(node), env->enc);
- if (slen > 0) {
- add_char_opt_map_info(&opt->map, *(sn->s), env->enc);
- }
- set_mml(&opt->len, slen, slen);
- }
- else {
- int n, max;
-
- concat_opt_exact_info_str(&opt->exb, sn->s, sn->end,
- is_raw, env->enc);
- opt->exb.ignore_case = 1;
-
- if (slen > 0) {
- r = add_char_amb_opt_map_info(&opt->map, sn->s, sn->end,
- env->enc, env->ambig_flag);
- if (r != 0) break;
- }
-
- if (NSTRING_IS_AMBIG_REDUCE(node)) {
- n = onigenc_strlen(env->enc, sn->s, sn->end);
- max = ONIGENC_MBC_MAXLEN_DIST(env->enc) * n;
- }
- else {
- max = slen;
- }
- set_mml(&opt->len, slen, max);
- }
-
- if (opt->exb.len == slen)
- opt->exb.reach_end = 1;
- }
- break;
-
- case N_CCLASS:
- {
- int i, z;
- CClassNode* cc = &(NCCLASS(node));
-
- /* no need to check ignore case. (setted in setup_tree()) */
-
- if (IS_NOT_NULL(cc->mbuf) || IS_CCLASS_NOT(cc)) {
- OnigDistance min = ONIGENC_MBC_MINLEN(env->enc);
- OnigDistance max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
-
- set_mml(&opt->len, min, max);
- }
- else {
- for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
- z = BITSET_AT(cc->bs, i);
- if ((z && !IS_CCLASS_NOT(cc)) || (!z && IS_CCLASS_NOT(cc))) {
- add_char_opt_map_info(&opt->map, (UChar )i, env->enc);
- }
- }
- set_mml(&opt->len, 1, 1);
- }
- }
- break;
-
- case N_CTYPE:
- {
- int i, min, max;
-
- max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
-
- if (max == 1) {
- min = 1;
-
- switch (NCTYPE(node).type) {
- case CTYPE_NOT_WORD:
- for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
- if (! ONIGENC_IS_CODE_WORD(env->enc, i)) {
- add_char_opt_map_info(&opt->map, (UChar )i, env->enc);
- }
- }
- break;
-
- case CTYPE_WORD:
- for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
- if (ONIGENC_IS_CODE_WORD(env->enc, i)) {
- add_char_opt_map_info(&opt->map, (UChar )i, env->enc);
- }
- }
- break;
- }
- }
- else {
- min = ONIGENC_MBC_MINLEN(env->enc);
- }
- set_mml(&opt->len, min, max);
- }
- break;
-
- case N_ANYCHAR:
- {
- OnigDistance min = ONIGENC_MBC_MINLEN(env->enc);
- OnigDistance max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
- set_mml(&opt->len, min, max);
- }
- break;
-
- case N_ANCHOR:
- switch (NANCHOR(node).type) {
- case ANCHOR_BEGIN_BUF:
- case ANCHOR_BEGIN_POSITION:
- case ANCHOR_BEGIN_LINE:
- case ANCHOR_END_BUF:
- case ANCHOR_SEMI_END_BUF:
- case ANCHOR_END_LINE:
- add_opt_anc_info(&opt->anc, NANCHOR(node).type);
- break;
-
- case ANCHOR_PREC_READ:
- {
- NodeOptInfo nopt;
-
- r = optimize_node_left(NANCHOR(node).target, &nopt, env);
- if (r == 0) {
- if (nopt.exb.len > 0)
- copy_opt_exact_info(&opt->expr, &nopt.exb);
- else if (nopt.exm.len > 0)
- copy_opt_exact_info(&opt->expr, &nopt.exm);
-
- opt->expr.reach_end = 0;
-
- if (nopt.map.value > 0)
- copy_opt_map_info(&opt->map, &nopt.map);
- }
- }
- break;
-
- case ANCHOR_PREC_READ_NOT:
- case ANCHOR_LOOK_BEHIND: /* Sorry, I can't make use of it. */
- case ANCHOR_LOOK_BEHIND_NOT:
- break;
- }
- break;
-
- case N_BACKREF:
- {
- int i;
- int* backs;
- OnigDistance min, max, tmin, tmax;
- Node** nodes = SCANENV_MEM_NODES(env->scan_env);
- BackrefNode* br = &(NBACKREF(node));
-
- if (br->state & NST_RECURSION) {
- set_mml(&opt->len, 0, ONIG_INFINITE_DISTANCE);
- break;
- }
- backs = BACKREFS_P(br);
- r = get_min_match_length(nodes[backs[0]], &min, env->scan_env);
- if (r != 0) break;
- r = get_max_match_length(nodes[backs[0]], &max, env->scan_env);
- if (r != 0) break;
- for (i = 1; i < br->back_num; i++) {
- r = get_min_match_length(nodes[backs[i]], &tmin, env->scan_env);
- if (r != 0) break;
- r = get_max_match_length(nodes[backs[i]], &tmax, env->scan_env);
- if (r != 0) break;
- if (min > tmin) min = tmin;
- if (max < tmax) max = tmax;
- }
- if (r == 0) set_mml(&opt->len, min, max);
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
- if (IS_CALL_RECURSION(&(NCALL(node))))
- set_mml(&opt->len, 0, ONIG_INFINITE_DISTANCE);
- else {
- OnigOptionType save = env->options;
- env->options = NEFFECT(NCALL(node).target).option;
- r = optimize_node_left(NCALL(node).target, opt, env);
- env->options = save;
- }
- break;
-#endif
-
- case N_QUALIFIER:
- {
- int i;
- OnigDistance min, max;
- NodeOptInfo nopt;
- QualifierNode* qn = &(NQUALIFIER(node));
-
- r = optimize_node_left(qn->target, &nopt, env);
- if (r) break;
-
- if (qn->lower == 0 && IS_REPEAT_INFINITE(qn->upper)) {
- if (env->mmd.max == 0 &&
- NTYPE(qn->target) == N_ANYCHAR && qn->greedy) {
- if (IS_MULTILINE(env->options))
- add_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_STAR_ML);
- else
- add_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_STAR);
- }
- }
- else {
- if (qn->lower > 0) {
- copy_node_opt_info(opt, &nopt);
- if (nopt.exb.len > 0) {
- if (nopt.exb.reach_end) {
- for (i = 2; i < qn->lower &&
- ! is_full_opt_exact_info(&opt->exb); i++) {
- concat_opt_exact_info(&opt->exb, &nopt.exb, env->enc);
- }
- if (i < qn->lower) {
- opt->exb.reach_end = 0;
- }
- }
- }
-
- if (qn->lower != qn->upper) {
- opt->exb.reach_end = 0;
- opt->exm.reach_end = 0;
- }
- if (qn->lower > 1)
- opt->exm.reach_end = 0;
- }
- }
-
- min = distance_multiply(nopt.len.min, qn->lower);
- if (IS_REPEAT_INFINITE(qn->upper))
- max = (nopt.len.max > 0 ? ONIG_INFINITE_DISTANCE : 0);
- else
- max = distance_multiply(nopt.len.max, qn->upper);
-
- set_mml(&opt->len, min, max);
- }
- break;
-
- case N_EFFECT:
- {
- EffectNode* en = &(NEFFECT(node));
-
- switch (en->type) {
- case EFFECT_OPTION:
- {
- OnigOptionType save = env->options;
-
- env->options = en->option;
- r = optimize_node_left(en->target, opt, env);
- env->options = save;
- }
- break;
-
- case EFFECT_MEMORY:
-#ifdef USE_SUBEXP_CALL
- en->opt_count++;
- if (en->opt_count > MAX_NODE_OPT_INFO_REF_COUNT) {
- OnigDistance min, max;
-
- min = 0;
- max = ONIG_INFINITE_DISTANCE;
- if (IS_EFFECT_MIN_FIXED(en)) min = en->min_len;
- if (IS_EFFECT_MAX_FIXED(en)) max = en->max_len;
- set_mml(&opt->len, min, max);
- }
- else
-#endif
- {
- r = optimize_node_left(en->target, opt, env);
-
- if (is_set_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_STAR_MASK)) {
- if (BIT_STATUS_AT(env->scan_env->backrefed_mem, en->regnum))
- remove_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_STAR_MASK);
- }
- }
- break;
-
- case EFFECT_STOP_BACKTRACK:
- r = optimize_node_left(en->target, opt, env);
- break;
- }
- }
- break;
-
- default:
-#ifdef ONIG_DEBUG
- fprintf(stderr, "optimize_node_left: undefined node type %d\n",
- NTYPE(node));
-#endif
- r = ONIGERR_TYPE_BUG;
- break;
- }
-
- return r;
-}
-
-static int
-set_optimize_exact_info(regex_t* reg, OptExactInfo* e)
-{
- int r;
-
- if (e->len == 0) return 0;
-
- if (e->ignore_case) {
- reg->exact = (UChar* )xmalloc(e->len);
- CHECK_NULL_RETURN_VAL(reg->exact, ONIGERR_MEMORY);
- xmemcpy(reg->exact, e->s, e->len);
- reg->exact_end = reg->exact + e->len;
- reg->optimize = ONIG_OPTIMIZE_EXACT_IC;
- }
- else {
- int allow_reverse;
-
- reg->exact = k_strdup(e->s, e->s + e->len);
- CHECK_NULL_RETURN_VAL(reg->exact, ONIGERR_MEMORY);
- reg->exact_end = reg->exact + e->len;
-
- allow_reverse =
- ONIGENC_IS_ALLOWED_REVERSE_MATCH(reg->enc, reg->exact, reg->exact_end);
-
- if (e->len >= 3 || (e->len >= 2 && allow_reverse)) {
- r = set_bm_skip(reg->exact, reg->exact_end, reg->enc,
- reg->map, &(reg->int_map));
- if (r) return r;
-
- reg->optimize = (allow_reverse != 0
- ? ONIG_OPTIMIZE_EXACT_BM : ONIG_OPTIMIZE_EXACT_BM_NOT_REV);
- }
- else {
- reg->optimize = ONIG_OPTIMIZE_EXACT;
- }
- }
-
- reg->dmin = e->mmd.min;
- reg->dmax = e->mmd.max;
-
- if (reg->dmin != ONIG_INFINITE_DISTANCE) {
- reg->threshold_len = reg->dmin + (reg->exact_end - reg->exact);
- }
-
- return 0;
-}
-
-static void
-set_optimize_map_info(regex_t* reg, OptMapInfo* m)
-{
- int i;
-
- for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++)
- reg->map[i] = m->map[i];
-
- reg->optimize = ONIG_OPTIMIZE_MAP;
- reg->dmin = m->mmd.min;
- reg->dmax = m->mmd.max;
-
- if (reg->dmin != ONIG_INFINITE_DISTANCE) {
- reg->threshold_len = reg->dmin + 1;
- }
-}
-
-static void
-set_sub_anchor(regex_t* reg, OptAncInfo* anc)
-{
- reg->sub_anchor |= anc->left_anchor & ANCHOR_BEGIN_LINE;
- reg->sub_anchor |= anc->right_anchor & ANCHOR_END_LINE;
-}
-
-#ifdef ONIG_DEBUG
-static void print_optimize_info(FILE* f, regex_t* reg);
-#endif
-
-static int
-set_optimize_info_from_tree(Node* node, regex_t* reg, ScanEnv* scan_env)
-{
-
- int r;
- NodeOptInfo opt;
- OptEnv env;
-
- env.enc = reg->enc;
- env.options = reg->options;
- env.ambig_flag = reg->ambig_flag;
- env.scan_env = scan_env;
- clear_mml(&env.mmd);
-
- r = optimize_node_left(node, &opt, &env);
- if (r) return r;
-
- reg->anchor = opt.anc.left_anchor & (ANCHOR_BEGIN_BUF |
- ANCHOR_BEGIN_POSITION | ANCHOR_ANYCHAR_STAR | ANCHOR_ANYCHAR_STAR_ML);
-
- reg->anchor |= opt.anc.right_anchor & (ANCHOR_END_BUF | ANCHOR_SEMI_END_BUF);
-
- if (reg->anchor & (ANCHOR_END_BUF | ANCHOR_SEMI_END_BUF)) {
- reg->anchor_dmin = opt.len.min;
- reg->anchor_dmax = opt.len.max;
- }
-
- if (opt.exb.len > 0 || opt.exm.len > 0) {
- select_opt_exact_info(reg->enc, &opt.exb, &opt.exm);
- if (opt.map.value > 0 &&
- comp_opt_exact_or_map_info(&opt.exb, &opt.map) > 0) {
- goto set_map;
- }
- else {
- r = set_optimize_exact_info(reg, &opt.exb);
- set_sub_anchor(reg, &opt.exb.anc);
- }
- }
- else if (opt.map.value > 0) {
- set_map:
- set_optimize_map_info(reg, &opt.map);
- set_sub_anchor(reg, &opt.map.anc);
- }
- else {
- reg->sub_anchor |= opt.anc.left_anchor & ANCHOR_BEGIN_LINE;
- if (opt.len.max == 0)
- reg->sub_anchor |= opt.anc.right_anchor & ANCHOR_END_LINE;
- }
-
-#if defined(ONIG_DEBUG_COMPILE) || defined(ONIG_DEBUG_MATCH)
- print_optimize_info(stderr, reg);
-#endif
- return r;
-}
-
-static void
-clear_optimize_info(regex_t* reg)
-{
- reg->optimize = ONIG_OPTIMIZE_NONE;
- reg->anchor = 0;
- reg->anchor_dmin = 0;
- reg->anchor_dmax = 0;
- reg->sub_anchor = 0;
- reg->exact_end = (UChar* )NULL;
- reg->threshold_len = 0;
- if (IS_NOT_NULL(reg->exact)) {
- xfree(reg->exact);
- reg->exact = (UChar* )NULL;
- }
-}
-
-#ifdef ONIG_DEBUG
-
-static void
-print_distance_range(FILE* f, OnigDistance a, OnigDistance b)
-{
- if (a == ONIG_INFINITE_DISTANCE)
- fputs("inf", f);
- else
- fprintf(f, "(%u)", a);
-
- fputs("-", f);
-
- if (b == ONIG_INFINITE_DISTANCE)
- fputs("inf", f);
- else
- fprintf(f, "(%u)", b);
-}
-
-static void
-print_anchor(FILE* f, int anchor)
-{
- int q = 0;
-
- fprintf(f, "[");
-
- if (anchor & ANCHOR_BEGIN_BUF) {
- fprintf(f, "begin-buf");
- q = 1;
- }
- if (anchor & ANCHOR_BEGIN_LINE) {
- if (q) fprintf(f, ", ");
- q = 1;
- fprintf(f, "begin-line");
- }
- if (anchor & ANCHOR_BEGIN_POSITION) {
- if (q) fprintf(f, ", ");
- q = 1;
- fprintf(f, "begin-pos");
- }
- if (anchor & ANCHOR_END_BUF) {
- if (q) fprintf(f, ", ");
- q = 1;
- fprintf(f, "end-buf");
- }
- if (anchor & ANCHOR_SEMI_END_BUF) {
- if (q) fprintf(f, ", ");
- q = 1;
- fprintf(f, "semi-end-buf");
- }
- if (anchor & ANCHOR_END_LINE) {
- if (q) fprintf(f, ", ");
- q = 1;
- fprintf(f, "end-line");
- }
- if (anchor & ANCHOR_ANYCHAR_STAR) {
- if (q) fprintf(f, ", ");
- q = 1;
- fprintf(f, "anychar-star");
- }
- if (anchor & ANCHOR_ANYCHAR_STAR_ML) {
- if (q) fprintf(f, ", ");
- fprintf(f, "anychar-star-pl");
- }
-
- fprintf(f, "]");
-}
-
-static void
-print_optimize_info(FILE* f, regex_t* reg)
-{
- static const char* on[] = { "NONE", "EXACT", "EXACT_BM", "EXACT_BM_NOT_REV",
- "EXACT_IC", "MAP" };
-
- fprintf(f, "optimize: %s\n", on[reg->optimize]);
- fprintf(f, " anchor: "); print_anchor(f, reg->anchor);
- if ((reg->anchor & ANCHOR_END_BUF_MASK) != 0)
- print_distance_range(f, reg->anchor_dmin, reg->anchor_dmax);
- fprintf(f, "\n");
-
- if (reg->optimize) {
- fprintf(f, " sub anchor: "); print_anchor(f, reg->sub_anchor);
- fprintf(f, "\n");
- }
- fprintf(f, "\n");
-
- if (reg->exact) {
- UChar *p;
- fprintf(f, "exact: [");
- for (p = reg->exact; p < reg->exact_end; p++) {
- fputc(*p, f);
- }
- fprintf(f, "]: length: %d\n", (reg->exact_end - reg->exact));
- }
- else if (reg->optimize & ONIG_OPTIMIZE_MAP) {
- int c, i, n = 0;
-
- for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++)
- if (reg->map[i]) n++;
-
- fprintf(f, "map: n=%d\n", n);
- if (n > 0) {
- c = 0;
- fputc('[', f);
- for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) {
- if (reg->map[i] != 0) {
- if (c > 0) fputs(", ", f);
- c++;
- if (ONIGENC_MBC_MAXLEN(reg->enc) == 1 &&
- ONIGENC_IS_CODE_PRINT(reg->enc, (OnigCodePoint )i))
- fputc(i, f);
- else
- fprintf(f, "%d", i);
- }
- }
- fprintf(f, "]\n");
- }
- }
-}
-#endif /* ONIG_DEBUG */
-
-
-static void
-onig_free_body(regex_t* reg)
-{
- if (IS_NOT_NULL(reg->p)) xfree(reg->p);
- if (IS_NOT_NULL(reg->exact)) xfree(reg->exact);
- if (IS_NOT_NULL(reg->int_map)) xfree(reg->int_map);
- if (IS_NOT_NULL(reg->int_map_backward)) xfree(reg->int_map_backward);
- if (IS_NOT_NULL(reg->repeat_range)) xfree(reg->repeat_range);
- if (IS_NOT_NULL(reg->chain)) onig_free(reg->chain);
-
-#ifdef USE_NAMED_GROUP
- onig_names_free(reg);
-#endif
-}
-
-extern void
-onig_free(regex_t* reg)
-{
- if (IS_NOT_NULL(reg)) {
- onig_free_body(reg);
- xfree(reg);
- }
-}
-
-#define REGEX_TRANSFER(to,from) do {\
- (to)->state = ONIG_STATE_MODIFY;\
- onig_free_body(to);\
- xmemcpy(to, from, sizeof(regex_t));\
- xfree(from);\
-} while (0)
-
-extern void
-onig_transfer(regex_t* to, regex_t* from)
-{
- THREAD_ATOMIC_START;
- REGEX_TRANSFER(to, from);
- THREAD_ATOMIC_END;
-}
-
-#define REGEX_CHAIN_HEAD(reg) do {\
- while (IS_NOT_NULL((reg)->chain)) {\
- (reg) = (reg)->chain;\
- }\
-} while (0)
-
-extern void
-onig_chain_link_add(regex_t* to, regex_t* add)
-{
- THREAD_ATOMIC_START;
- REGEX_CHAIN_HEAD(to);
- to->chain = add;
- THREAD_ATOMIC_END;
-}
-
-extern void
-onig_chain_reduce(regex_t* reg)
-{
- regex_t *head, *prev;
-
- prev = reg;
- head = prev->chain;
- if (IS_NOT_NULL(head)) {
- reg->state = ONIG_STATE_MODIFY;
- while (IS_NOT_NULL(head->chain)) {
- prev = head;
- head = head->chain;
- }
- prev->chain = (regex_t* )NULL;
- REGEX_TRANSFER(reg, head);
- }
-}
-
-#if 0
-extern int
-onig_clone(regex_t** to, regex_t* from)
-{
- int r, size;
- regex_t* reg;
-
-#ifdef USE_MULTI_THREAD_SYSTEM
- if (ONIG_STATE(from) >= ONIG_STATE_NORMAL) {
- ONIG_STATE_INC(from);
- if (IS_NOT_NULL(from->chain) && ONIG_STATE(reg) == ONIG_STATE_NORMAL) {
- onig_chain_reduce(from);
- ONIG_STATE_INC(from);
- }
- }
- else {
- int n = 0;
- while (ONIG_STATE(from) < ONIG_STATE_NORMAL) {
- if (++n > THREAD_PASS_LIMIT_COUNT)
- return ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT;
- THREAD_PASS;
- }
- ONIG_STATE_INC(from);
- }
-#endif /* USE_MULTI_THREAD_SYSTEM */
-
- r = onig_alloc_init(&reg, ONIG_OPTION_NONE, ONIGENC_AMBIGUOUS_MATCH_DEFAULT,
- from->enc, ONIG_SYNTAX_DEFAULT);
- if (r != 0) {
- ONIG_STATE_DEC(from);
- return r;
- }
-
- xmemcpy(reg, from, sizeof(onig_t));
- reg->chain = (regex_t* )NULL;
- reg->state = ONIG_STATE_NORMAL;
-
- if (from->p) {
- reg->p = (UChar* )xmalloc(reg->alloc);
- if (IS_NULL(reg->p)) goto mem_error;
- xmemcpy(reg->p, from->p, reg->alloc);
- }
-
- if (from->exact) {
- reg->exact = (UChar* )xmalloc(from->exact_end - from->exact);
- if (IS_NULL(reg->exact)) goto mem_error;
- reg->exact_end = reg->exact + (from->exact_end - from->exact);
- xmemcpy(reg->exact, from->exact, reg->exact_end - reg->exact);
- }
-
- if (from->int_map) {
- size = sizeof(int) * ONIG_CHAR_TABLE_SIZE;
- reg->int_map = (int* )xmalloc(size);
- if (IS_NULL(reg->int_map)) goto mem_error;
- xmemcpy(reg->int_map, from->int_map, size);
- }
-
- if (from->int_map_backward) {
- size = sizeof(int) * ONIG_CHAR_TABLE_SIZE;
- reg->int_map_backward = (int* )xmalloc(size);
- if (IS_NULL(reg->int_map_backward)) goto mem_error;
- xmemcpy(reg->int_map_backward, from->int_map_backward, size);
- }
-
-#ifdef USE_NAMED_GROUP
- reg->name_table = names_clone(from); /* names_clone is not implemented */
-#endif
-
- ONIG_STATE_DEC(from);
- *to = reg;
- return 0;
-
- mem_error:
- ONIG_STATE_DEC(from);
- return ONIGERR_MEMORY;
-}
-#endif
-
-#ifdef ONIG_DEBUG
-static void print_compiled_byte_code_list P_((FILE* f, regex_t* reg));
-#endif
-#ifdef ONIG_DEBUG_PARSE_TREE
-static void print_tree P_((FILE* f, Node* node));
-#endif
-
-extern int
-onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
- OnigErrorInfo* einfo)
-{
-#define COMPILE_INIT_SIZE 20
-
- int r, init_size;
- Node* root;
- ScanEnv scan_env;
-#ifdef USE_SUBEXP_CALL
- UnsetAddrList uslist;
-#endif
-
- reg->state = ONIG_STATE_COMPILING;
-
- if (reg->alloc == 0) {
- init_size = (pattern_end - pattern) * 2;
- if (init_size <= 0) init_size = COMPILE_INIT_SIZE;
- r = BBUF_INIT(reg, init_size);
- if (r != 0) goto end;
- }
- else
- reg->used = 0;
-
- reg->num_mem = 0;
- reg->num_repeat = 0;
- reg->num_null_check = 0;
- reg->repeat_range_alloc = 0;
- reg->repeat_range = (OnigRepeatRange* )NULL;
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- reg->num_comb_exp_check = 0;
-#endif
-
- r = onig_parse_make_tree(&root, pattern, pattern_end, reg, &scan_env);
- if (r != 0) goto err;
-
-#ifdef USE_NAMED_GROUP
- /* mixed use named group and no-named group */
- if (scan_env.num_named > 0 &&
- IS_SYNTAX_BV(scan_env.syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) &&
- !ONIG_IS_OPTION_ON(reg->options, ONIG_OPTION_CAPTURE_GROUP)) {
- if (scan_env.num_named != scan_env.num_mem)
- r = disable_noname_group_capture(&root, reg, &scan_env);
- else
- r = numbered_ref_check(root);
-
- if (r != 0) goto err;
- }
-#endif
-
-#ifdef ONIG_DEBUG_PARSE_TREE
- print_tree(stderr, root);
-#endif
-
-#ifdef USE_SUBEXP_CALL
- if (scan_env.num_call > 0) {
- r = unset_addr_list_init(&uslist, scan_env.num_call);
- if (r != 0) goto err;
- scan_env.unset_addr_list = &uslist;
- r = setup_subexp_call(root, &scan_env);
- if (r != 0) goto err_unset;
- r = subexp_recursive_check_trav(root, &scan_env);
- if (r < 0) goto err_unset;
- r = subexp_inf_recursive_check_trav(root, &scan_env);
- if (r != 0) goto err_unset;
-
- reg->num_call = scan_env.num_call;
- }
- else
- reg->num_call = 0;
-#endif
-
- r = setup_tree(root, reg, 0, &scan_env);
- if (r != 0) goto err_unset;
-
- reg->capture_history = scan_env.capture_history;
- reg->bt_mem_start = scan_env.bt_mem_start;
- reg->bt_mem_start |= reg->capture_history;
- if (IS_FIND_CONDITION(reg->options))
- BIT_STATUS_ON_ALL(reg->bt_mem_end);
- else {
- reg->bt_mem_end = scan_env.bt_mem_end;
- reg->bt_mem_end |= reg->capture_history;
- }
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- if (scan_env.backrefed_mem == 0
-#ifdef USE_SUBEXP_CALL
- || scan_env.num_call == 0
-#endif
- ) {
- setup_comb_exp_check(root, 0, &scan_env);
-#ifdef USE_SUBEXP_CALL
- if (scan_env.has_recursion != 0) {
- scan_env.num_comb_exp_check = 0;
- }
- else
-#endif
- if (scan_env.comb_exp_max_regnum > 0) {
- int i;
- for (i = 1; i <= scan_env.comb_exp_max_regnum; i++) {
- if (BIT_STATUS_AT(scan_env.backrefed_mem, i) != 0) {
- scan_env.num_comb_exp_check = 0;
- break;
- }
- }
- }
- }
-
- reg->num_comb_exp_check = scan_env.num_comb_exp_check;
-#endif
-
- clear_optimize_info(reg);
-#ifndef ONIG_DONT_OPTIMIZE
- r = set_optimize_info_from_tree(root, reg, &scan_env);
- if (r != 0) goto err_unset;
-#endif
-
- if (IS_NOT_NULL(scan_env.mem_nodes_dynamic)) {
- xfree(scan_env.mem_nodes_dynamic);
- scan_env.mem_nodes_dynamic = (Node** )NULL;
- }
-
- r = compile_tree(root, reg);
- if (r == 0) {
- r = add_opcode(reg, OP_END);
-#ifdef USE_SUBEXP_CALL
- if (scan_env.num_call > 0) {
- r = unset_addr_list_fix(&uslist, reg);
- unset_addr_list_end(&uslist);
- if (r) goto err;
- }
-#endif
-
- if ((reg->num_repeat != 0) || (reg->bt_mem_end != 0))
- reg->stack_pop_level = STACK_POP_LEVEL_ALL;
- else {
- if (reg->bt_mem_start != 0)
- reg->stack_pop_level = STACK_POP_LEVEL_MEM_START;
- else
- reg->stack_pop_level = STACK_POP_LEVEL_FREE;
- }
- }
-#ifdef USE_SUBEXP_CALL
- else if (scan_env.num_call > 0) {
- unset_addr_list_end(&uslist);
- }
-#endif
- onig_node_free(root);
-
-#ifdef ONIG_DEBUG_COMPILE
-#ifdef USE_NAMED_GROUP
- onig_print_names(stderr, reg);
-#endif
- print_compiled_byte_code_list(stderr, reg);
-#endif
-
- end:
- reg->state = ONIG_STATE_NORMAL;
- return r;
-
- err_unset:
-#ifdef USE_SUBEXP_CALL
- if (scan_env.num_call > 0) {
- unset_addr_list_end(&uslist);
- }
-#endif
- err:
- if (IS_NOT_NULL(scan_env.error)) {
- if (IS_NOT_NULL(einfo)) {
- einfo->enc = scan_env.enc;
- einfo->par = scan_env.error;
- einfo->par_end = scan_env.error_end;
- }
- }
-
- if (IS_NOT_NULL(root)) onig_node_free(root);
- if (IS_NOT_NULL(scan_env.mem_nodes_dynamic))
- xfree(scan_env.mem_nodes_dynamic);
- return r;
-}
-
-#ifdef USE_RECOMPILE_API
-extern int
-onig_recompile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
- OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax,
- OnigErrorInfo* einfo)
-{
- int r;
- regex_t *new_reg;
-
- r = onig_new(&new_reg, pattern, pattern_end, option, enc, syntax, einfo);
- if (r) return r;
- if (ONIG_STATE(reg) == ONIG_STATE_NORMAL) {
- onig_transfer(reg, new_reg);
- }
- else {
- onig_chain_link_add(reg, new_reg);
- }
- return 0;
-}
-#endif
-
-static int onig_inited = 0;
-
-extern int
-onig_alloc_init(regex_t** reg, OnigOptionType option, OnigAmbigType ambig_flag,
- OnigEncoding enc, OnigSyntaxType* syntax)
-{
- if (! onig_inited)
- onig_init();
-
- if (ONIGENC_IS_UNDEF(enc))
- return ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED;
-
- if ((option & (ONIG_OPTION_DONT_CAPTURE_GROUP|ONIG_OPTION_CAPTURE_GROUP))
- == (ONIG_OPTION_DONT_CAPTURE_GROUP|ONIG_OPTION_CAPTURE_GROUP)) {
- return ONIGERR_INVALID_COMBINATION_OF_OPTIONS;
- }
-
- *reg = (regex_t* )xmalloc(sizeof(regex_t));
- if (IS_NULL(*reg)) return ONIGERR_MEMORY;
- (*reg)->state = ONIG_STATE_MODIFY;
-
- if ((option & ONIG_OPTION_NEGATE_SINGLELINE) != 0) {
- option |= syntax->options;
- option &= ~ONIG_OPTION_SINGLELINE;
- }
- else
- option |= syntax->options;
-
- (*reg)->enc = enc;
- (*reg)->options = option;
- (*reg)->syntax = syntax;
- (*reg)->optimize = 0;
- (*reg)->exact = (UChar* )NULL;
- (*reg)->int_map = (int* )NULL;
- (*reg)->int_map_backward = (int* )NULL;
- (*reg)->chain = (regex_t* )NULL;
-
- (*reg)->p = (UChar* )NULL;
- (*reg)->alloc = 0;
- (*reg)->used = 0;
- (*reg)->name_table = (void* )NULL;
-
- (*reg)->ambig_flag = ambig_flag;
- (*reg)->ambig_flag &= ONIGENC_SUPPORT_AMBIG_FLAG(enc);
-
- return 0;
-}
-
-extern int
-onig_new(regex_t** reg, const UChar* pattern, const UChar* pattern_end,
- OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax,
- OnigErrorInfo* einfo)
-{
- int r;
-
- if (IS_NOT_NULL(einfo)) einfo->par = (UChar* )NULL;
-
- r = onig_alloc_init(reg, option, ONIGENC_AMBIGUOUS_MATCH_DEFAULT,
- enc, syntax);
- if (r) return r;
-
- r = onig_compile(*reg, pattern, pattern_end, einfo);
- if (r) {
- onig_free(*reg);
- *reg = NULL;
- }
- return r;
-}
-
-extern int
-onig_init()
-{
- if (onig_inited != 0)
- return 0;
-
- onig_inited = 1;
-
- THREAD_ATOMIC_START;
-
- onigenc_init();
- onigenc_set_default_caseconv_table((UChar* )0);
-
-#ifdef ONIG_DEBUG_STATISTICS
- onig_statistics_init();
-#endif
-
- THREAD_ATOMIC_END;
- return 0;
-}
-
-
-extern int
-onig_end()
-{
- extern int onig_free_shared_cclass_table();
-
- THREAD_ATOMIC_START;
-
-#ifdef ONIG_DEBUG_STATISTICS
- onig_print_statistics(stderr);
-#endif
-
-#ifdef USE_SHARED_CCLASS_TABLE
- onig_free_shared_cclass_table();
-#endif
-
-#ifdef USE_RECYCLE_NODE
- onig_free_node_list();
-#endif
-
- onig_inited = 0;
-
- THREAD_ATOMIC_END;
- return 0;
-}
-
-
-#ifdef ONIG_DEBUG
-
-/* arguments type */
-#define ARG_SPECIAL -1
-#define ARG_NON 0
-#define ARG_RELADDR 1
-#define ARG_ABSADDR 2
-#define ARG_LENGTH 3
-#define ARG_MEMNUM 4
-#define ARG_OPTION 5
-#define ARG_STATE_CHECK 6
-
-OnigOpInfoType OnigOpInfo[] = {
- { OP_FINISH, "finish", ARG_NON },
- { OP_END, "end", ARG_NON },
- { OP_EXACT1, "exact1", ARG_SPECIAL },
- { OP_EXACT2, "exact2", ARG_SPECIAL },
- { OP_EXACT3, "exact3", ARG_SPECIAL },
- { OP_EXACT4, "exact4", ARG_SPECIAL },
- { OP_EXACT5, "exact5", ARG_SPECIAL },
- { OP_EXACTN, "exactn", ARG_SPECIAL },
- { OP_EXACTMB2N1, "exactmb2-n1", ARG_SPECIAL },
- { OP_EXACTMB2N2, "exactmb2-n2", ARG_SPECIAL },
- { OP_EXACTMB2N3, "exactmb2-n3", ARG_SPECIAL },
- { OP_EXACTMB2N, "exactmb2-n", ARG_SPECIAL },
- { OP_EXACTMB3N, "exactmb3n" , ARG_SPECIAL },
- { OP_EXACTMBN, "exactmbn", ARG_SPECIAL },
- { OP_EXACT1_IC, "exact1-ic", ARG_SPECIAL },
- { OP_EXACTN_IC, "exactn-ic", ARG_SPECIAL },
- { OP_CCLASS, "cclass", ARG_SPECIAL },
- { OP_CCLASS_MB, "cclass-mb", ARG_SPECIAL },
- { OP_CCLASS_MIX, "cclass-mix", ARG_SPECIAL },
- { OP_CCLASS_NOT, "cclass-not", ARG_SPECIAL },
- { OP_CCLASS_MB_NOT, "cclass-mb-not", ARG_SPECIAL },
- { OP_CCLASS_MIX_NOT, "cclass-mix-not", ARG_SPECIAL },
- { OP_CCLASS_NODE, "cclass-node", ARG_SPECIAL },
- { OP_ANYCHAR, "anychar", ARG_NON },
- { OP_ANYCHAR_ML, "anychar-ml", ARG_NON },
- { OP_ANYCHAR_STAR, "anychar*", ARG_NON },
- { OP_ANYCHAR_ML_STAR, "anychar-ml*", ARG_NON },
- { OP_ANYCHAR_STAR_PEEK_NEXT, "anychar*-peek-next", ARG_SPECIAL },
- { OP_ANYCHAR_ML_STAR_PEEK_NEXT, "anychar-ml*-peek-next", ARG_SPECIAL },
- { OP_WORD, "word", ARG_NON },
- { OP_NOT_WORD, "not-word", ARG_NON },
- { OP_WORD_BOUND, "word-bound", ARG_NON },
- { OP_NOT_WORD_BOUND, "not-word-bound", ARG_NON },
- { OP_WORD_BEGIN, "word-begin", ARG_NON },
- { OP_WORD_END, "word-end", ARG_NON },
- { OP_BEGIN_BUF, "begin-buf", ARG_NON },
- { OP_END_BUF, "end-buf", ARG_NON },
- { OP_BEGIN_LINE, "begin-line", ARG_NON },
- { OP_END_LINE, "end-line", ARG_NON },
- { OP_SEMI_END_BUF, "semi-end-buf", ARG_NON },
- { OP_BEGIN_POSITION, "begin-position", ARG_NON },
- { OP_BACKREF1, "backref1", ARG_NON },
- { OP_BACKREF2, "backref2", ARG_NON },
- { OP_BACKREFN, "backrefn", ARG_MEMNUM },
- { OP_BACKREFN_IC, "backrefn-ic", ARG_SPECIAL },
- { OP_BACKREF_MULTI, "backref_multi", ARG_SPECIAL },
- { OP_BACKREF_MULTI_IC, "backref_multi-ic", ARG_SPECIAL },
- { OP_BACKREF_AT_LEVEL, "backref_at_level", ARG_SPECIAL },
- { OP_MEMORY_START_PUSH, "mem-start-push", ARG_MEMNUM },
- { OP_MEMORY_START, "mem-start", ARG_MEMNUM },
- { OP_MEMORY_END_PUSH, "mem-end-push", ARG_MEMNUM },
- { OP_MEMORY_END_PUSH_REC, "mem-end-push-rec", ARG_MEMNUM },
- { OP_MEMORY_END, "mem-end", ARG_MEMNUM },
- { OP_MEMORY_END_REC, "mem-end-rec", ARG_MEMNUM },
- { OP_SET_OPTION_PUSH, "set-option-push", ARG_OPTION },
- { OP_SET_OPTION, "set-option", ARG_OPTION },
- { OP_FAIL, "fail", ARG_NON },
- { OP_JUMP, "jump", ARG_RELADDR },
- { OP_PUSH, "push", ARG_RELADDR },
- { OP_POP, "pop", ARG_NON },
- { OP_PUSH_OR_JUMP_EXACT1, "push-or-jump-e1", ARG_SPECIAL },
- { OP_PUSH_IF_PEEK_NEXT, "push-if-peek-next", ARG_SPECIAL },
- { OP_REPEAT, "repeat", ARG_SPECIAL },
- { OP_REPEAT_NG, "repeat-ng", ARG_SPECIAL },
- { OP_REPEAT_INC, "repeat-inc", ARG_MEMNUM },
- { OP_REPEAT_INC_NG, "repeat-inc-ng", ARG_MEMNUM },
- { OP_REPEAT_INC_SG, "repeat-inc-sg", ARG_MEMNUM },
- { OP_REPEAT_INC_NG_SG, "repeat-inc-ng-sg", ARG_MEMNUM },
- { OP_NULL_CHECK_START, "null-check-start", ARG_MEMNUM },
- { OP_NULL_CHECK_END, "null-check-end", ARG_MEMNUM },
- { OP_NULL_CHECK_END_MEMST,"null-check-end-memst", ARG_MEMNUM },
- { OP_NULL_CHECK_END_MEMST_PUSH,"null-check-end-memst-push", ARG_MEMNUM },
- { OP_PUSH_POS, "push-pos", ARG_NON },
- { OP_POP_POS, "pop-pos", ARG_NON },
- { OP_PUSH_POS_NOT, "push-pos-not", ARG_RELADDR },
- { OP_FAIL_POS, "fail-pos", ARG_NON },
- { OP_PUSH_STOP_BT, "push-stop-bt", ARG_NON },
- { OP_POP_STOP_BT, "pop-stop-bt", ARG_NON },
- { OP_LOOK_BEHIND, "look-behind", ARG_SPECIAL },
- { OP_PUSH_LOOK_BEHIND_NOT, "push-look-behind-not", ARG_SPECIAL },
- { OP_FAIL_LOOK_BEHIND_NOT, "fail-look-behind-not", ARG_NON },
- { OP_CALL, "call", ARG_ABSADDR },
- { OP_RETURN, "return", ARG_NON },
- { OP_STATE_CHECK_PUSH, "state-check-push", ARG_SPECIAL },
- { OP_STATE_CHECK_PUSH_OR_JUMP, "state-check-push-or-jump", ARG_SPECIAL },
- { OP_STATE_CHECK, "state-check", ARG_STATE_CHECK },
- { OP_STATE_CHECK_ANYCHAR_STAR, "state-check-anychar*", ARG_STATE_CHECK },
- { OP_STATE_CHECK_ANYCHAR_ML_STAR,
- "state-check-anychar-ml*", ARG_STATE_CHECK },
- { -1, "", ARG_NON }
-};
-
-static char*
-op2name(int opcode)
-{
- int i;
-
- for (i = 0; OnigOpInfo[i].opcode >= 0; i++) {
- if (opcode == OnigOpInfo[i].opcode)
- return OnigOpInfo[i].name;
- }
- return "";
-}
-
-static int
-op2arg_type(int opcode)
-{
- int i;
-
- for (i = 0; OnigOpInfo[i].opcode >= 0; i++) {
- if (opcode == OnigOpInfo[i].opcode)
- return OnigOpInfo[i].arg_type;
- }
- return ARG_SPECIAL;
-}
-
-static void
-Indent(FILE* f, int indent)
-{
- int i;
- for (i = 0; i < indent; i++) putc(' ', f);
-}
-
-static void
-p_string(FILE* f, int len, UChar* s)
-{
- fputs(":", f);
- while (len-- > 0) { fputc(*s++, f); }
-}
-
-static void
-p_len_string(FILE* f, LengthType len, int mb_len, UChar* s)
-{
- int x = len * mb_len;
-
- fprintf(f, ":%d:", len);
- while (x-- > 0) { fputc(*s++, f); }
-}
-
-extern void
-onig_print_compiled_byte_code(FILE* f, UChar* bp, UChar** nextp,
- OnigEncoding enc)
-{
- int i, n, arg_type;
- RelAddrType addr;
- LengthType len;
- MemNumType mem;
- StateCheckNumType scn;
- OnigCodePoint code;
- UChar *q;
-
- fprintf(f, "[%s", op2name(*bp));
- arg_type = op2arg_type(*bp);
- if (arg_type != ARG_SPECIAL) {
- bp++;
- switch (arg_type) {
- case ARG_NON:
- break;
- case ARG_RELADDR:
- GET_RELADDR_INC(addr, bp);
- fprintf(f, ":(%d)", addr);
- break;
- case ARG_ABSADDR:
- GET_ABSADDR_INC(addr, bp);
- fprintf(f, ":(%d)", addr);
- break;
- case ARG_LENGTH:
- GET_LENGTH_INC(len, bp);
- fprintf(f, ":%d", len);
- break;
- case ARG_MEMNUM:
- mem = *((MemNumType* )bp);
- bp += SIZE_MEMNUM;
- fprintf(f, ":%d", mem);
- break;
- case ARG_OPTION:
- {
- OnigOptionType option = *((OnigOptionType* )bp);
- bp += SIZE_OPTION;
- fprintf(f, ":%d", option);
- }
- break;
-
- case ARG_STATE_CHECK:
- scn = *((StateCheckNumType* )bp);
- bp += SIZE_STATE_CHECK_NUM;
- fprintf(f, ":%d", scn);
- break;
- }
- }
- else {
- switch (*bp++) {
- case OP_EXACT1:
- case OP_ANYCHAR_STAR_PEEK_NEXT:
- case OP_ANYCHAR_ML_STAR_PEEK_NEXT:
- p_string(f, 1, bp++); break;
- case OP_EXACT2:
- p_string(f, 2, bp); bp += 2; break;
- case OP_EXACT3:
- p_string(f, 3, bp); bp += 3; break;
- case OP_EXACT4:
- p_string(f, 4, bp); bp += 4; break;
- case OP_EXACT5:
- p_string(f, 5, bp); bp += 5; break;
- case OP_EXACTN:
- GET_LENGTH_INC(len, bp);
- p_len_string(f, len, 1, bp);
- bp += len;
- break;
-
- case OP_EXACTMB2N1:
- p_string(f, 2, bp); bp += 2; break;
- case OP_EXACTMB2N2:
- p_string(f, 4, bp); bp += 4; break;
- case OP_EXACTMB2N3:
- p_string(f, 6, bp); bp += 6; break;
- case OP_EXACTMB2N:
- GET_LENGTH_INC(len, bp);
- p_len_string(f, len, 2, bp);
- bp += len * 2;
- break;
- case OP_EXACTMB3N:
- GET_LENGTH_INC(len, bp);
- p_len_string(f, len, 3, bp);
- bp += len * 3;
- break;
- case OP_EXACTMBN:
- {
- int mb_len;
-
- GET_LENGTH_INC(mb_len, bp);
- GET_LENGTH_INC(len, bp);
- fprintf(f, ":%d:%d:", mb_len, len);
- n = len * mb_len;
- while (n-- > 0) { fputc(*bp++, f); }
- }
- break;
-
- case OP_EXACT1_IC:
- len = enc_len(enc, bp);
- p_string(f, len, bp);
- bp += len;
- break;
- case OP_EXACTN_IC:
- GET_LENGTH_INC(len, bp);
- p_len_string(f, len, 1, bp);
- bp += len;
- break;
-
- case OP_CCLASS:
- n = bitset_on_num((BitSetRef )bp);
- bp += SIZE_BITSET;
- fprintf(f, ":%d", n);
- break;
-
- case OP_CCLASS_NOT:
- n = bitset_on_num((BitSetRef )bp);
- bp += SIZE_BITSET;
- fprintf(f, ":%d", n);
- break;
-
- case OP_CCLASS_MB:
- case OP_CCLASS_MB_NOT:
- GET_LENGTH_INC(len, bp);
- q = bp;
-#ifndef PLATFORM_UNALIGNED_WORD_ACCESS
- ALIGNMENT_RIGHT(q);
-#endif
- GET_CODE_POINT(code, q);
- bp += len;
- fprintf(f, ":%d:%d", (int )code, len);
- break;
-
- case OP_CCLASS_MIX:
- case OP_CCLASS_MIX_NOT:
- n = bitset_on_num((BitSetRef )bp);
- bp += SIZE_BITSET;
- GET_LENGTH_INC(len, bp);
- q = bp;
-#ifndef PLATFORM_UNALIGNED_WORD_ACCESS
- ALIGNMENT_RIGHT(q);
-#endif
- GET_CODE_POINT(code, q);
- bp += len;
- fprintf(f, ":%d:%d:%d", n, (int )code, len);
- break;
-
- case OP_CCLASS_NODE:
- {
- CClassNode *cc;
-
- GET_POINTER_INC(cc, bp);
- n = bitset_on_num(cc->bs);
- fprintf(f, ":%u:%d", (unsigned int )cc, n);
- }
- break;
-
- case OP_BACKREFN_IC:
- mem = *((MemNumType* )bp);
- bp += SIZE_MEMNUM;
- fprintf(f, ":%d", mem);
- break;
-
- case OP_BACKREF_MULTI_IC:
- case OP_BACKREF_MULTI:
- fputs(" ", f);
- GET_LENGTH_INC(len, bp);
- for (i = 0; i < len; i++) {
- GET_MEMNUM_INC(mem, bp);
- if (i > 0) fputs(", ", f);
- fprintf(f, "%d", mem);
- }
- break;
-
- case OP_BACKREF_AT_LEVEL:
- {
- OnigOptionType option;
- LengthType level;
-
- GET_OPTION_INC(option, bp);
- fprintf(f, ":%d", option);
- GET_LENGTH_INC(level, bp);
- fprintf(f, ":%d", level);
-
- fputs(" ", f);
- GET_LENGTH_INC(len, bp);
- for (i = 0; i < len; i++) {
- GET_MEMNUM_INC(mem, bp);
- if (i > 0) fputs(", ", f);
- fprintf(f, "%d", mem);
- }
- }
- break;
-
- case OP_REPEAT:
- case OP_REPEAT_NG:
- {
- mem = *((MemNumType* )bp);
- bp += SIZE_MEMNUM;
- addr = *((RelAddrType* )bp);
- bp += SIZE_RELADDR;
- fprintf(f, ":%d:%d", mem, addr);
- }
- break;
-
- case OP_PUSH_OR_JUMP_EXACT1:
- case OP_PUSH_IF_PEEK_NEXT:
- addr = *((RelAddrType* )bp);
- bp += SIZE_RELADDR;
- fprintf(f, ":(%d)", addr);
- p_string(f, 1, bp);
- bp += 1;
- break;
-
- case OP_LOOK_BEHIND:
- GET_LENGTH_INC(len, bp);
- fprintf(f, ":%d", len);
- break;
-
- case OP_PUSH_LOOK_BEHIND_NOT:
- GET_RELADDR_INC(addr, bp);
- GET_LENGTH_INC(len, bp);
- fprintf(f, ":%d:(%d)", len, addr);
- break;
-
- case OP_STATE_CHECK_PUSH:
- case OP_STATE_CHECK_PUSH_OR_JUMP:
- scn = *((StateCheckNumType* )bp);
- bp += SIZE_STATE_CHECK_NUM;
- addr = *((RelAddrType* )bp);
- bp += SIZE_RELADDR;
- fprintf(f, ":%d:(%d)", scn, addr);
- break;
-
- default:
- fprintf(stderr, "onig_print_compiled_byte_code: undefined code %d\n",
- *--bp);
- }
- }
- fputs("]", f);
- if (nextp) *nextp = bp;
-}
-
-static void
-print_compiled_byte_code_list(FILE* f, regex_t* reg)
-{
- int ncode;
- UChar* bp = reg->p;
- UChar* end = reg->p + reg->used;
-
- fprintf(f, "code length: %d\n", reg->used);
-
- ncode = 0;
- while (bp < end) {
- ncode++;
- if (bp > reg->p) {
- if (ncode % 5 == 0)
- fprintf(f, "\n");
- else
- fputs(" ", f);
- }
- onig_print_compiled_byte_code(f, bp, &bp, reg->enc);
- }
-
- fprintf(f, "\n");
-}
-
-static void
-print_indent_tree(FILE* f, Node* node, int indent)
-{
- int i, type;
- int add = 3;
- UChar* p;
-
- Indent(f, indent);
- if (IS_NULL(node)) {
- fprintf(f, "ERROR: null node!!!\n");
- exit (0);
- }
-
- type = NTYPE(node);
- switch (type) {
- case N_LIST:
- case N_ALT:
- if (NTYPE(node) == N_LIST)
- fprintf(f, "<list:%x>\n", (int )node);
- else
- fprintf(f, "<alt:%x>\n", (int )node);
-
- print_indent_tree(f, NCONS(node).left, indent + add);
- while (IS_NOT_NULL(node = NCONS(node).right)) {
- if (NTYPE(node) != type) {
- fprintf(f, "ERROR: list/alt right is not a cons. %d\n", NTYPE(node));
- exit(0);
- }
- print_indent_tree(f, NCONS(node).left, indent + add);
- }
- break;
-
- case N_STRING:
- fprintf(f, "<string%s:%x>",
- (NSTRING_IS_RAW(node) ? "-raw" : ""), (int )node);
- for (p = NSTRING(node).s; p < NSTRING(node).end; p++) {
- if (*p >= 0x20 && *p < 0x7f)
- fputc(*p, f);
- else {
- fprintf(f, " 0x%02x", *p);
- }
- }
- break;
-
- case N_CCLASS:
- fprintf(f, "<cclass:%x>", (int )node);
- if (IS_CCLASS_NOT(&NCCLASS(node))) fputs(" not", f);
- if (NCCLASS(node).mbuf) {
- BBuf* bbuf = NCCLASS(node).mbuf;
- for (i = 0; i < bbuf->used; i++) {
- if (i > 0) fprintf(f, ",");
- fprintf(f, "%0x", bbuf->p[i]);
- }
- }
- break;
-
- case N_CTYPE:
- fprintf(f, "<ctype:%x> ", (int )node);
- switch (NCTYPE(node).type) {
- case CTYPE_WORD: fputs("word", f); break;
- case CTYPE_NOT_WORD: fputs("not word", f); break;
- default:
- fprintf(f, "ERROR: undefined ctype.\n");
- exit(0);
- }
- break;
-
- case N_ANYCHAR:
- fprintf(f, "<anychar:%x>", (int )node);
- break;
-
- case N_ANCHOR:
- fprintf(f, "<anchor:%x> ", (int )node);
- switch (NANCHOR(node).type) {
- case ANCHOR_BEGIN_BUF: fputs("begin buf", f); break;
- case ANCHOR_END_BUF: fputs("end buf", f); break;
- case ANCHOR_BEGIN_LINE: fputs("begin line", f); break;
- case ANCHOR_END_LINE: fputs("end line", f); break;
- case ANCHOR_SEMI_END_BUF: fputs("semi end buf", f); break;
- case ANCHOR_BEGIN_POSITION: fputs("begin position", f); break;
-
- case ANCHOR_WORD_BOUND: fputs("word bound", f); break;
- case ANCHOR_NOT_WORD_BOUND: fputs("not word bound", f); break;
-#ifdef USE_WORD_BEGIN_END
- case ANCHOR_WORD_BEGIN: fputs("word begin", f); break;
- case ANCHOR_WORD_END: fputs("word end", f); break;
-#endif
- case ANCHOR_PREC_READ: fputs("prec read", f); break;
- case ANCHOR_PREC_READ_NOT: fputs("prec read not", f); break;
- case ANCHOR_LOOK_BEHIND: fputs("look_behind", f); break;
- case ANCHOR_LOOK_BEHIND_NOT: fputs("look_behind_not",f); break;
-
- default:
- fprintf(f, "ERROR: undefined anchor type.\n");
- break;
- }
- break;
-
- case N_BACKREF:
- {
- int* p;
- BackrefNode* br = &(NBACKREF(node));
- p = BACKREFS_P(br);
- fprintf(f, "<backref:%x>", (int )node);
- for (i = 0; i < br->back_num; i++) {
- if (i > 0) fputs(", ", f);
- fprintf(f, "%d", p[i]);
- }
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case N_CALL:
- {
- CallNode* cn = &(NCALL(node));
- fprintf(f, "<call:%x>", (int )node);
- p_string(f, cn->name_end - cn->name, cn->name);
- }
- break;
-#endif
-
- case N_QUALIFIER:
- fprintf(f, "<qualifier:%x>{%d,%d}%s\n", (int )node,
- NQUALIFIER(node).lower, NQUALIFIER(node).upper,
- (NQUALIFIER(node).greedy ? "" : "?"));
- print_indent_tree(f, NQUALIFIER(node).target, indent + add);
- break;
-
- case N_EFFECT:
- fprintf(f, "<effect:%x> ", (int )node);
- switch (NEFFECT(node).type) {
- case EFFECT_OPTION:
- fprintf(f, "option:%d\n", NEFFECT(node).option);
- print_indent_tree(f, NEFFECT(node).target, indent + add);
- break;
- case EFFECT_MEMORY:
- fprintf(f, "memory:%d", NEFFECT(node).regnum);
- break;
- case EFFECT_STOP_BACKTRACK:
- fprintf(f, "stop-bt");
- break;
-
- default:
- break;
- }
- fprintf(f, "\n");
- print_indent_tree(f, NEFFECT(node).target, indent + add);
- break;
-
- default:
- fprintf(f, "print_indent_tree: undefined node type %d\n", NTYPE(node));
- break;
- }
-
- if (type != N_LIST && type != N_ALT && type != N_QUALIFIER &&
- type != N_EFFECT)
- fprintf(f, "\n");
- fflush(f);
-}
-#endif /* ONIG_DEBUG */
-
-#ifdef ONIG_DEBUG_PARSE_TREE
-static void
-print_tree(FILE* f, Node* node)
-{
- print_indent_tree(f, node, 0);
-}
-#endif
diff --git a/regenc.c b/regenc.c
deleted file mode 100644
index bbbf1a2f94..0000000000
--- a/regenc.c
+++ /dev/null
@@ -1,1028 +0,0 @@
-/**********************************************************************
- regenc.c - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2005 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "regint.h"
-
-OnigEncoding OnigEncDefaultCharEncoding = ONIG_ENCODING_INIT_DEFAULT;
-
-extern int
-onigenc_init()
-{
- return 0;
-}
-
-extern OnigEncoding
-onigenc_get_default_encoding()
-{
- return OnigEncDefaultCharEncoding;
-}
-
-extern int
-onigenc_set_default_encoding(OnigEncoding enc)
-{
- OnigEncDefaultCharEncoding = enc;
- return 0;
-}
-
-extern UChar*
-onigenc_get_right_adjust_char_head(OnigEncoding enc, const UChar* start, const UChar* s)
-{
- UChar* p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s);
- if (p < s) {
- p += enc_len(enc, p);
- }
- return p;
-}
-
-extern UChar*
-onigenc_get_right_adjust_char_head_with_prev(OnigEncoding enc,
- const UChar* start, const UChar* s, const UChar** prev)
-{
- UChar* p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s);
-
- if (p < s) {
- if (prev) *prev = (const UChar* )p;
- p += enc_len(enc, p);
- }
- else {
- if (prev) *prev = (const UChar* )NULL; /* Sorry */
- }
- return p;
-}
-
-extern UChar*
-onigenc_get_prev_char_head(OnigEncoding enc, const UChar* start, const UChar* s)
-{
- if (s <= start)
- return (UChar* )NULL;
-
- return ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s - 1);
-}
-
-extern UChar*
-onigenc_step_back(OnigEncoding enc, const UChar* start, const UChar* s, int n)
-{
- while (ONIG_IS_NOT_NULL(s) && n-- > 0) {
- if (s <= start)
- return (UChar* )NULL;
-
- s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s - 1);
- }
- return (UChar* )s;
-}
-
-extern UChar*
-onigenc_step(OnigEncoding enc, const UChar* p, const UChar* end, int n)
-{
- UChar* q = (UChar* )p;
- while (n-- > 0) {
- q += ONIGENC_MBC_ENC_LEN(enc, q);
- }
- return (q <= end ? q : NULL);
-}
-
-extern int
-onigenc_strlen(OnigEncoding enc, const UChar* p, const UChar* end)
-{
- int n = 0;
- UChar* q = (UChar* )p;
-
- while (q < end) {
- q += ONIGENC_MBC_ENC_LEN(enc, q);
- n++;
- }
- return n;
-}
-
-extern int
-onigenc_strlen_null(OnigEncoding enc, const UChar* s)
-{
- int n = 0;
- UChar* p = (UChar* )s;
-
- while (1) {
- if (*p == '\0') {
- UChar* q;
- int len = ONIGENC_MBC_MINLEN(enc);
-
- if (len == 1) return n;
- q = p + 1;
- while (len > 1) {
- if (*q != '\0') break;
- q++;
- len--;
- }
- if (len == 1) return n;
- }
- p += ONIGENC_MBC_ENC_LEN(enc, p);
- n++;
- }
-}
-
-extern int
-onigenc_str_bytelen_null(OnigEncoding enc, const UChar* s)
-{
- UChar* start = (UChar* )s;
- UChar* p = (UChar* )s;
-
- while (1) {
- if (*p == '\0') {
- UChar* q;
- int len = ONIGENC_MBC_MINLEN(enc);
-
- if (len == 1) return (int )(p - start);
- q = p + 1;
- while (len > 1) {
- if (*q != '\0') break;
- q++;
- len--;
- }
- if (len == 1) return (int )(p - start);
- }
- p += ONIGENC_MBC_ENC_LEN(enc, p);
- }
-}
-
-#ifndef ONIG_RUBY_M17N
-
-#ifndef NOT_RUBY
-
-#define USE_APPLICATION_TO_LOWER_CASE_TABLE
-
-const unsigned short OnigEnc_Unicode_ISO_8859_1_CtypeTable[256] = {
- 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008,
- 0x2008, 0x228c, 0x2289, 0x2288, 0x2288, 0x2288, 0x2008, 0x2008,
- 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008,
- 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008,
- 0x2284, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0,
- 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0,
- 0x38b0, 0x38b0, 0x38b0, 0x38b0, 0x38b0, 0x38b0, 0x38b0, 0x38b0,
- 0x38b0, 0x38b0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0,
- 0x21a0, 0x3ca2, 0x3ca2, 0x3ca2, 0x3ca2, 0x3ca2, 0x3ca2, 0x34a2,
- 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2,
- 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2,
- 0x34a2, 0x34a2, 0x34a2, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x31a0,
- 0x21a0, 0x38e2, 0x38e2, 0x38e2, 0x38e2, 0x38e2, 0x38e2, 0x30e2,
- 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2,
- 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2,
- 0x30e2, 0x30e2, 0x30e2, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x2008,
- 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0288, 0x0008, 0x0008,
- 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
- 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
- 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
- 0x0284, 0x01a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
- 0x00a0, 0x00a0, 0x10e2, 0x01a0, 0x00a0, 0x00a8, 0x00a0, 0x00a0,
- 0x00a0, 0x00a0, 0x10a0, 0x10a0, 0x00a0, 0x10e2, 0x00a0, 0x01a0,
- 0x00a0, 0x10a0, 0x10e2, 0x01a0, 0x10a0, 0x10a0, 0x10a0, 0x01a0,
- 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2,
- 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2,
- 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x00a0,
- 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x14a2, 0x10e2,
- 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2,
- 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2,
- 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x00a0,
- 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2, 0x10e2
-};
-#endif
-
-const UChar* OnigEncAsciiToLowerCaseTable = (const UChar* )0;
-
-#ifndef USE_APPLICATION_TO_LOWER_CASE_TABLE
-static const UChar BuiltInAsciiToLowerCaseTable[] = {
- '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
- '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
- '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
- '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
- '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
- '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
- '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
- '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
- '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
- '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
- '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
- '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
- '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
- '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
- '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
- '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
- '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
- '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
- '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
- '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
- '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
- '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
- '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
- '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
- '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
- '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
- '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
- '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
- '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
- '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
- '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
- '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
-};
-#endif /* not USE_APPLICATION_TO_LOWER_CASE_TABLE */
-
-#ifdef USE_UPPER_CASE_TABLE
-const UChar OnigEncAsciiToUpperCaseTable[256] = {
- '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
- '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
- '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
- '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
- '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
- '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
- '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
- '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
- '\100', '\101', '\102', '\103', '\104', '\105', '\106', '\107',
- '\110', '\111', '\112', '\113', '\114', '\115', '\116', '\117',
- '\120', '\121', '\122', '\123', '\124', '\125', '\126', '\127',
- '\130', '\131', '\132', '\133', '\134', '\135', '\136', '\137',
- '\140', '\101', '\102', '\103', '\104', '\105', '\106', '\107',
- '\110', '\111', '\112', '\113', '\114', '\115', '\116', '\117',
- '\120', '\121', '\122', '\123', '\124', '\125', '\126', '\127',
- '\130', '\131', '\132', '\173', '\174', '\175', '\176', '\177',
- '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
- '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
- '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
- '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
- '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
- '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
- '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
- '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
- '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
- '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
- '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
- '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
- '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
- '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
- '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
- '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
-};
-#endif
-
-const unsigned short OnigEncAsciiCtypeTable[256] = {
- 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008,
- 0x2008, 0x220c, 0x2209, 0x2208, 0x2208, 0x2208, 0x2008, 0x2008,
- 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008,
- 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008, 0x2008,
- 0x2284, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0,
- 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0,
- 0x38b0, 0x38b0, 0x38b0, 0x38b0, 0x38b0, 0x38b0, 0x38b0, 0x38b0,
- 0x38b0, 0x38b0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x21a0,
- 0x21a0, 0x3ca2, 0x3ca2, 0x3ca2, 0x3ca2, 0x3ca2, 0x3ca2, 0x34a2,
- 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2,
- 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2,
- 0x34a2, 0x34a2, 0x34a2, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x31a0,
- 0x21a0, 0x38e2, 0x38e2, 0x38e2, 0x38e2, 0x38e2, 0x38e2, 0x30e2,
- 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2,
- 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2,
- 0x30e2, 0x30e2, 0x30e2, 0x21a0, 0x21a0, 0x21a0, 0x21a0, 0x2008,
-
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
-};
-
-const UChar OnigEncISO_8859_1_ToLowerCaseTable[256] = {
- '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
- '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
- '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
- '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
- '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
- '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
- '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
- '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
- '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
- '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
- '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
- '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
- '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
- '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
- '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
- '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
- '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
- '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
- '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
- '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
- '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
- '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
- '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
- '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
- '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
- '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
- '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\327',
- '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\337',
- '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
- '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
- '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
- '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377'
-};
-
-#ifdef USE_UPPER_CASE_TABLE
-const UChar OnigEncISO_8859_1_ToUpperCaseTable[256] = {
- '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
- '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
- '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
- '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
- '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
- '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
- '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
- '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
- '\100', '\101', '\102', '\103', '\104', '\105', '\106', '\107',
- '\110', '\111', '\112', '\113', '\114', '\115', '\116', '\117',
- '\120', '\121', '\122', '\123', '\124', '\125', '\126', '\127',
- '\130', '\131', '\132', '\133', '\134', '\135', '\136', '\137',
- '\140', '\101', '\102', '\103', '\104', '\105', '\106', '\107',
- '\110', '\111', '\112', '\113', '\114', '\115', '\116', '\117',
- '\120', '\121', '\122', '\123', '\124', '\125', '\126', '\127',
- '\130', '\131', '\132', '\173', '\174', '\175', '\176', '\177',
- '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
- '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
- '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
- '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
- '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
- '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
- '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
- '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
- '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
- '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
- '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
- '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
- '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
- '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
- '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\367',
- '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\377',
-};
-#endif
-
-extern void
-onigenc_set_default_caseconv_table(const UChar* table)
-{
- if (table == (const UChar* )0) {
-#ifndef USE_APPLICATION_TO_LOWER_CASE_TABLE
- table = BuiltInAsciiToLowerCaseTable;
-#else
- return ;
-#endif
- }
-
- if (table != OnigEncAsciiToLowerCaseTable) {
- OnigEncAsciiToLowerCaseTable = table;
- }
-}
-
-extern UChar*
-onigenc_get_left_adjust_char_head(OnigEncoding enc, const UChar* start, const UChar* s)
-{
- return ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s);
-}
-
-const OnigPairAmbigCodes OnigAsciiPairAmbigCodes[] = {
- { 0x41, 0x61 },
- { 0x42, 0x62 },
- { 0x43, 0x63 },
- { 0x44, 0x64 },
- { 0x45, 0x65 },
- { 0x46, 0x66 },
- { 0x47, 0x67 },
- { 0x48, 0x68 },
- { 0x49, 0x69 },
- { 0x4a, 0x6a },
- { 0x4b, 0x6b },
- { 0x4c, 0x6c },
- { 0x4d, 0x6d },
- { 0x4e, 0x6e },
- { 0x4f, 0x6f },
- { 0x50, 0x70 },
- { 0x51, 0x71 },
- { 0x52, 0x72 },
- { 0x53, 0x73 },
- { 0x54, 0x74 },
- { 0x55, 0x75 },
- { 0x56, 0x76 },
- { 0x57, 0x77 },
- { 0x58, 0x78 },
- { 0x59, 0x79 },
- { 0x5a, 0x7a },
-
- { 0x61, 0x41 },
- { 0x62, 0x42 },
- { 0x63, 0x43 },
- { 0x64, 0x44 },
- { 0x65, 0x45 },
- { 0x66, 0x46 },
- { 0x67, 0x47 },
- { 0x68, 0x48 },
- { 0x69, 0x49 },
- { 0x6a, 0x4a },
- { 0x6b, 0x4b },
- { 0x6c, 0x4c },
- { 0x6d, 0x4d },
- { 0x6e, 0x4e },
- { 0x6f, 0x4f },
- { 0x70, 0x50 },
- { 0x71, 0x51 },
- { 0x72, 0x52 },
- { 0x73, 0x53 },
- { 0x74, 0x54 },
- { 0x75, 0x55 },
- { 0x76, 0x56 },
- { 0x77, 0x57 },
- { 0x78, 0x58 },
- { 0x79, 0x59 },
- { 0x7a, 0x5a }
-};
-
-extern int
-onigenc_ascii_get_all_pair_ambig_codes(OnigAmbigType flag,
- const OnigPairAmbigCodes** ccs)
-{
- if (flag == ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) {
- *ccs = OnigAsciiPairAmbigCodes;
- return (sizeof(OnigAsciiPairAmbigCodes) / sizeof(OnigPairAmbigCodes));
- }
- else {
- return 0;
- }
-}
-
-extern int
-onigenc_nothing_get_all_comp_ambig_codes(OnigAmbigType flag,
- const OnigCompAmbigCodes** ccs)
-{
- return 0;
-}
-
-extern int
-onigenc_iso_8859_1_get_all_pair_ambig_codes(OnigAmbigType flag,
- const OnigPairAmbigCodes** ccs)
-{
- static const OnigPairAmbigCodes cc[] = {
- { 0xc0, 0xe0 },
- { 0xc1, 0xe1 },
- { 0xc2, 0xe2 },
- { 0xc3, 0xe3 },
- { 0xc4, 0xe4 },
- { 0xc5, 0xe5 },
- { 0xc6, 0xe6 },
- { 0xc7, 0xe7 },
- { 0xc8, 0xe8 },
- { 0xc9, 0xe9 },
- { 0xca, 0xea },
- { 0xcb, 0xeb },
- { 0xcc, 0xec },
- { 0xcd, 0xed },
- { 0xce, 0xee },
- { 0xcf, 0xef },
-
- { 0xd0, 0xf0 },
- { 0xd1, 0xf1 },
- { 0xd2, 0xf2 },
- { 0xd3, 0xf3 },
- { 0xd4, 0xf4 },
- { 0xd5, 0xf5 },
- { 0xd6, 0xf6 },
- { 0xd8, 0xf8 },
- { 0xd9, 0xf9 },
- { 0xda, 0xfa },
- { 0xdb, 0xfb },
- { 0xdc, 0xfc },
- { 0xdd, 0xfd },
- { 0xde, 0xfe },
-
- { 0xe0, 0xc0 },
- { 0xe1, 0xc1 },
- { 0xe2, 0xc2 },
- { 0xe3, 0xc3 },
- { 0xe4, 0xc4 },
- { 0xe5, 0xc5 },
- { 0xe6, 0xc6 },
- { 0xe7, 0xc7 },
- { 0xe8, 0xc8 },
- { 0xe9, 0xc9 },
- { 0xea, 0xca },
- { 0xeb, 0xcb },
- { 0xec, 0xcc },
- { 0xed, 0xcd },
- { 0xee, 0xce },
- { 0xef, 0xcf },
-
- { 0xf0, 0xd0 },
- { 0xf1, 0xd1 },
- { 0xf2, 0xd2 },
- { 0xf3, 0xd3 },
- { 0xf4, 0xd4 },
- { 0xf5, 0xd5 },
- { 0xf6, 0xd6 },
- { 0xf8, 0xd8 },
- { 0xf9, 0xd9 },
- { 0xfa, 0xda },
- { 0xfb, 0xdb },
- { 0xfc, 0xdc },
- { 0xfd, 0xdd },
- { 0xfe, 0xde }
- };
-
- if (flag == ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) {
- *ccs = OnigAsciiPairAmbigCodes;
- return (sizeof(OnigAsciiPairAmbigCodes) / sizeof(OnigPairAmbigCodes));
- }
- else if (flag == ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE) {
- *ccs = cc;
- return sizeof(cc) / sizeof(OnigPairAmbigCodes);
- }
- else
- return 0;
-}
-
-extern int
-onigenc_ess_tsett_get_all_comp_ambig_codes(OnigAmbigType flag,
- const OnigCompAmbigCodes** ccs)
-{
- static const OnigCompAmbigCodes folds[] = {
- { 2, 0xdf, {{ 2, { 0x53, 0x53 } }, { 2, { 0x73, 0x73} } } }
- };
-
- if (flag == ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE) {
- *ccs = folds;
- return sizeof(folds) / sizeof(OnigCompAmbigCodes);
- }
- else
- return 0;
-}
-
-extern int
-onigenc_not_support_get_ctype_code_range(int ctype,
- const OnigCodePoint* sbr[], const OnigCodePoint* mbr[])
-{
- return ONIG_NO_SUPPORT_CONFIG;
-}
-
-extern int
-onigenc_is_mbc_newline_0x0a(const UChar* p, const UChar* end)
-{
- if (p < end) {
- if (*p == 0x0a) return 1;
- }
- return 0;
-}
-
-/* for single byte encodings */
-extern int
-onigenc_ascii_mbc_to_normalize(OnigAmbigType flag, const UChar** p, const UChar*end,
- UChar* lower)
-{
- if ((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0) {
- *lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(**p);
- }
- else {
- *lower = **p;
- }
-
- (*p)++;
- return 1; /* return byte length of converted char to lower */
-}
-
-extern int
-onigenc_ascii_is_mbc_ambiguous(OnigAmbigType flag,
- const UChar** pp, const UChar* end)
-{
- const UChar* p = *pp;
-
- (*pp)++;
- if ((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0) {
- return ONIGENC_IS_ASCII_CODE_CASE_AMBIG(*p);
- }
- else {
- return FALSE;
- }
-}
-
-extern int
-onigenc_single_byte_mbc_enc_len(const UChar* p)
-{
- return 1;
-}
-
-extern OnigCodePoint
-onigenc_single_byte_mbc_to_code(const UChar* p, const UChar* end)
-{
- return (OnigCodePoint )(*p);
-}
-
-extern int
-onigenc_single_byte_code_to_mbclen(OnigCodePoint code)
-{
- return 1;
-}
-
-extern int
-onigenc_single_byte_code_to_mbc_first(OnigCodePoint code)
-{
- return (code & 0xff);
-}
-
-extern int
-onigenc_single_byte_code_to_mbc(OnigCodePoint code, UChar *buf)
-{
- *buf = (UChar )(code & 0xff);
- return 1;
-}
-
-extern UChar*
-onigenc_single_byte_left_adjust_char_head(const UChar* start, const UChar* s)
-{
- return (UChar* )s;
-}
-
-extern int
-onigenc_always_true_is_allowed_reverse_match(const UChar* s, const UChar* end)
-{
- return TRUE;
-}
-
-extern int
-onigenc_always_false_is_allowed_reverse_match(const UChar* s, const UChar* end)
-{
- return FALSE;
-}
-
-extern OnigCodePoint
-onigenc_mbn_mbc_to_code(OnigEncoding enc, const UChar* p, const UChar* end)
-{
- int c, i, len;
- OnigCodePoint n;
-
- len = enc_len(enc, p);
- n = (OnigCodePoint )(*p++);
- if (len == 1) return n;
-
- for (i = 1; i < len; i++) {
- if (p >= end) break;
- c = *p++;
- n <<= 8; n += c;
- }
- return n;
-}
-
-extern int
-onigenc_mbn_mbc_to_normalize(OnigEncoding enc, OnigAmbigType flag,
- const UChar** pp, const UChar* end, UChar* lower)
-{
- int len;
- const UChar *p = *pp;
-
- if (ONIGENC_IS_MBC_ASCII(p)) {
- if ((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0) {
- *lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
- }
- else {
- *lower = *p;
- }
- (*pp)++;
- return 1;
- }
- else {
- len = enc_len(enc, p);
- if (lower != p) {
- int i;
- for (i = 0; i < len; i++) {
- *lower++ = *p++;
- }
- }
- (*pp) += len;
- return len; /* return byte length of converted to lower char */
- }
-}
-
-extern int
-onigenc_mbn_is_mbc_ambiguous(OnigEncoding enc, OnigAmbigType flag,
- const UChar** pp, const UChar* end)
-{
- const UChar* p = *pp;
-
- if (ONIGENC_IS_MBC_ASCII(p)) {
- (*pp)++;
- if ((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0) {
- return ONIGENC_IS_ASCII_CODE_CASE_AMBIG(*p);
- }
- else {
- return FALSE;
- }
- }
-
- (*pp) += enc_len(enc, p);
- return FALSE;
-}
-
-extern int
-onigenc_mb2_code_to_mbclen(OnigCodePoint code)
-{
- if ((code & 0xff00) != 0) return 2;
- else return 1;
-}
-
-extern int
-onigenc_mb4_code_to_mbclen(OnigCodePoint code)
-{
- if ((code & 0xff000000) != 0) return 4;
- else if ((code & 0xff0000) != 0) return 3;
- else if ((code & 0xff00) != 0) return 2;
- else return 1;
-}
-
-extern int
-onigenc_mb2_code_to_mbc_first(OnigCodePoint code)
-{
- int first;
-
- if ((code & 0xff00) != 0) {
- first = (code >> 8) & 0xff;
- }
- else {
- return (int )code;
- }
- return first;
-}
-
-extern int
-onigenc_mb4_code_to_mbc_first(OnigCodePoint code)
-{
- int first;
-
- if ((code & 0xff000000) != 0) {
- first = (code >> 24) & 0xff;
- }
- else if ((code & 0xff0000) != 0) {
- first = (code >> 16) & 0xff;
- }
- else if ((code & 0xff00) != 0) {
- first = (code >> 8) & 0xff;
- }
- else {
- return (int )code;
- }
- return first;
-}
-
-extern int
-onigenc_mb2_code_to_mbc(OnigEncoding enc, OnigCodePoint code, UChar *buf)
-{
- UChar *p = buf;
-
- if ((code & 0xff00) != 0) {
- *p++ = (UChar )((code >> 8) & 0xff);
- }
- *p++ = (UChar )(code & 0xff);
-
-#if 1
- if (enc_len(enc, buf) != (p - buf))
- return ONIGENCERR_INVALID_WIDE_CHAR_VALUE;
-#endif
- return p - buf;
-}
-
-extern int
-onigenc_mb4_code_to_mbc(OnigEncoding enc, OnigCodePoint code, UChar *buf)
-{
- UChar *p = buf;
-
- if ((code & 0xff000000) != 0) {
- *p++ = (UChar )((code >> 24) & 0xff);
- }
- if ((code & 0xff0000) != 0 || p != buf) {
- *p++ = (UChar )((code >> 16) & 0xff);
- }
- if ((code & 0xff00) != 0 || p != buf) {
- *p++ = (UChar )((code >> 8) & 0xff);
- }
- *p++ = (UChar )(code & 0xff);
-
-#if 1
- if (enc_len(enc, buf) != (p - buf))
- return ONIGENCERR_INVALID_WIDE_CHAR_VALUE;
-#endif
- return p - buf;
-}
-
-extern int
-onigenc_mb2_is_code_ctype(OnigEncoding enc, OnigCodePoint code,
- unsigned int ctype)
-{
- if (code < 128)
- return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
- else {
- if ((ctype & (ONIGENC_CTYPE_WORD |
- ONIGENC_CTYPE_GRAPH | ONIGENC_CTYPE_PRINT)) != 0) {
- return (ONIGENC_CODE_TO_MBCLEN(enc, code) > 1 ? TRUE : FALSE);
- }
- }
-
- return FALSE;
-}
-
-extern int
-onigenc_mb4_is_code_ctype(OnigEncoding enc, OnigCodePoint code,
- unsigned int ctype)
-{
- if (code < 128)
- return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
- else {
- if ((ctype & (ONIGENC_CTYPE_WORD |
- ONIGENC_CTYPE_GRAPH | ONIGENC_CTYPE_PRINT)) != 0) {
- return (ONIGENC_CODE_TO_MBCLEN(enc, code) > 1 ? TRUE : FALSE);
- }
- }
-
- return FALSE;
-}
-
-extern int
-onigenc_with_ascii_strncmp(OnigEncoding enc, const UChar* p, const UChar* end,
- const UChar* sascii /* ascii */, int n)
-{
- int x, c;
-
- while (n-- > 0) {
- if (p >= end) return (int )(*sascii);
-
- c = (int )ONIGENC_MBC_TO_CODE(enc, p, end);
- x = *sascii - c;
- if (x) return x;
-
- sascii++;
- p += enc_len(enc, p);
- }
- return 0;
-}
-
-#else /* ONIG_RUBY_M17N */
-
-extern int
-onigenc_is_code_ctype(OnigEncoding enc, OnigCodePoint code, int ctype)
-{
- switch (ctype) {
- case ONIGENC_CTYPE_NEWLINE:
- if (code == 0x0a) return 1;
- break;
-
- case ONIGENC_CTYPE_ALPHA:
- return m17n_isalpha(enc, code);
- break;
- case ONIGENC_CTYPE_BLANK:
- return ONIGENC_IS_CODE_BLANK(enc, (int )(code));
- break;
- case ONIGENC_CTYPE_CNTRL:
- return m17n_iscntrl(enc, code);
- break;
- case ONIGENC_CTYPE_DIGIT:
- return m17n_isdigit(enc, code);
- break;
- case ONIGENC_CTYPE_GRAPH:
- return ONIGENC_IS_CODE_GRAPH(enc, (int )(code));
- break;
- case ONIGENC_CTYPE_LOWER:
- return m17n_islower(enc, code);
- break;
- case ONIGENC_CTYPE_PRINT:
- return m17n_isprint(enc, code);
- break;
- case ONIGENC_CTYPE_PUNCT:
- return m17n_ispunct(enc, code);
- break;
- case ONIGENC_CTYPE_SPACE:
- return m17n_isspace(enc, code);
- break;
- case ONIGENC_CTYPE_UPPER:
- return m17n_isupper(enc, code);
- break;
- case ONIGENC_CTYPE_XDIGIT:
- return m17n_isxdigit(enc, code);
- break;
- case ONIGENC_CTYPE_WORD:
- return m17n_iswchar(enc, code);
- break;
- case ONIGENC_CTYPE_ASCII:
- return (code < 128 ? TRUE : FALSE);
- break;
- case ONIGENC_CTYPE_ALNUM:
- return m17n_isalnum(enc, code);
- break;
- default:
- break;
- }
-
- return 0;
-}
-
-extern int
-onigenc_code_to_mbc(OnigEncoding enc, OnigCodePoint code, UChar *buf)
-{
- int c, len;
-
- m17n_mbcput(enc, code, buf);
- c = m17n_firstbyte(enc, code);
- len = enc_len(enc, c);
- return len;
-}
-
-extern int
-onigenc_mbc_to_lower(OnigEncoding enc, UChar* p, UChar* buf)
-{
- unsigned int c, low;
-
- c = m17n_codepoint(enc, p, p + enc_len(enc, *p));
- low = m17n_tolower(enc, c);
- m17n_mbcput(enc, low, buf);
-
- return m17n_codelen(enc, low);
-}
-
-extern int
-onigenc_is_mbc_ambiguous(OnigEncoding enc, OnigAmbigType flag,
- UChar** pp, UChar* end)
-{
- int len;
- unsigned int c;
- UChar* p = *pp;
-
- len = enc_len(enc, *p);
- (*pp) += len;
- c = m17n_codepoint(enc, p, p + len);
-
- if ((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0) {
- if (m17n_isupper(enc, c) || m17n_islower(enc, c))
- return TRUE;
- }
-
- return FALSE;
-}
-
-extern UChar*
-onigenc_get_left_adjust_char_head(OnigEncoding enc, UChar* start, UChar* s)
-{
- UChar *p;
- int len;
-
- if (s <= start) return s;
- p = s;
-
- while (!m17n_islead(enc, *p) && p > start) p--;
- while (p + (len = enc_len(enc, *p)) < s) {
- p += len;
- }
- if (p + len == s) return s;
- return p;
-}
-
-extern int
-onigenc_is_allowed_reverse_match(OnigEncoding enc,
- const UChar* s, const UChar* end)
-{
- return ONIGENC_IS_SINGLEBYTE(enc);
-}
-
-extern void
-onigenc_set_default_caseconv_table(UChar* table) { }
-
-#endif /* ONIG_RUBY_M17N */
diff --git a/regenc.h b/regenc.h
deleted file mode 100644
index 58ee3e7f22..0000000000
--- a/regenc.h
+++ /dev/null
@@ -1,147 +0,0 @@
-#ifndef REGENC_H
-#define REGENC_H
-/**********************************************************************
- regenc.h - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef RUBY_PLATFORM
-#include "config.h"
-#endif
-#include "oniguruma.h"
-
-#ifndef NULL
-#define NULL ((void* )0)
-#endif
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-/* error codes */
-#define ONIGENCERR_MEMORY -5
-#define ONIGENCERR_TYPE_BUG -6
-#define ONIGENCERR_INVALID_WIDE_CHAR_VALUE -400
-#define ONIGENCERR_TOO_BIG_WIDE_CHAR_VALUE -401
-
-#define ONIG_IS_NULL(p) (((void*)(p)) == (void*)0)
-#define ONIG_IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
-#define ONIG_CHECK_NULL_RETURN(p) if (ONIG_IS_NULL(p)) return NULL
-#define ONIG_CHECK_NULL_RETURN_VAL(p,val) if (ONIG_IS_NULL(p)) return (val)
-
-
-#ifdef ONIG_RUBY_M17N
-
-#define ONIG_ENCODING_INIT_DEFAULT ONIG_ENCODING_UNDEF
-
-#else /* ONIG_RUBY_M17N */
-
-#define USE_UNICODE_FULL_RANGE_CTYPE
-/* following must not use with USE_CRNL_AS_LINE_TERMINATOR */
-/* #define USE_UNICODE_ALL_LINE_TERMINATORS */ /* see Unicode.org UTF#18 */
-
-#define ONIG_ENCODING_INIT_DEFAULT ONIG_ENCODING_ASCII
-
-/* for encoding system implementation (internal) */
-ONIG_EXTERN int onigenc_ascii_get_all_pair_ambig_codes P_((OnigAmbigType flag, const OnigPairAmbigCodes** acs));
-ONIG_EXTERN int onigenc_nothing_get_all_comp_ambig_codes P_((OnigAmbigType flag, const OnigCompAmbigCodes** acs));
-ONIG_EXTERN int onigenc_iso_8859_1_get_all_pair_ambig_codes P_((OnigAmbigType flag, const OnigPairAmbigCodes** acs));
-ONIG_EXTERN int onigenc_ess_tsett_get_all_comp_ambig_codes P_((OnigAmbigType flag, const OnigCompAmbigCodes** acs));
-ONIG_EXTERN int onigenc_not_support_get_ctype_code_range P_((int ctype, const OnigCodePoint* sbr[], const OnigCodePoint* mbr[]));
-ONIG_EXTERN int onigenc_is_mbc_newline_0x0a P_((const UChar* p, const UChar* end));
-
-/* methods for single byte encoding */
-ONIG_EXTERN int onigenc_ascii_mbc_to_normalize P_((OnigAmbigType flag, const UChar** p, const UChar* end, UChar* lower));
-ONIG_EXTERN int onigenc_ascii_is_mbc_ambiguous P_((OnigAmbigType flag, const UChar** p, const UChar* end));
-ONIG_EXTERN int onigenc_single_byte_mbc_enc_len P_((const UChar* p));
-ONIG_EXTERN OnigCodePoint onigenc_single_byte_mbc_to_code P_((const UChar* p, const UChar* end));
-ONIG_EXTERN int onigenc_single_byte_code_to_mbclen P_((OnigCodePoint code));
-ONIG_EXTERN int onigenc_single_byte_code_to_mbc_first P_((OnigCodePoint code));
-ONIG_EXTERN int onigenc_single_byte_code_to_mbc P_((OnigCodePoint code, UChar *buf));
-ONIG_EXTERN UChar* onigenc_single_byte_left_adjust_char_head P_((const UChar* start, const UChar* s));
-ONIG_EXTERN int onigenc_always_true_is_allowed_reverse_match P_((const UChar* s, const UChar* end));
-ONIG_EXTERN int onigenc_always_false_is_allowed_reverse_match P_((const UChar* s, const UChar* end));
-
-/* methods for multi byte encoding */
-ONIG_EXTERN OnigCodePoint onigenc_mbn_mbc_to_code P_((OnigEncoding enc, const UChar* p, const UChar* end));
-ONIG_EXTERN int onigenc_mbn_mbc_to_normalize P_((OnigEncoding enc, OnigAmbigType flag, const UChar** p, const UChar* end, UChar* lower));
-ONIG_EXTERN int onigenc_mbn_is_mbc_ambiguous P_((OnigEncoding enc, OnigAmbigType flag, const UChar** p, const UChar* end));
-ONIG_EXTERN int onigenc_mb2_code_to_mbclen P_((OnigCodePoint code));
-ONIG_EXTERN int onigenc_mb2_code_to_mbc_first P_((OnigCodePoint code));
-ONIG_EXTERN int onigenc_mb2_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf));
-ONIG_EXTERN int onigenc_mb2_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype));
-ONIG_EXTERN int onigenc_mb4_code_to_mbclen P_((OnigCodePoint code));
-ONIG_EXTERN int onigenc_mb4_code_to_mbc_first P_((OnigCodePoint code));
-ONIG_EXTERN int onigenc_mb4_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf));
-ONIG_EXTERN int onigenc_mb4_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype));
-
-ONIG_EXTERN int onigenc_get_all_fold_match_code_ss_0xdf P_((OnigCodePoint** codes));
-
-/* in enc/unicode.c */
-ONIG_EXTERN int onigenc_unicode_is_code_ctype P_((OnigCodePoint code, unsigned int ctype));
-ONIG_EXTERN int onigenc_unicode_get_ctype_code_range P_((int ctype, const OnigCodePoint* sbr[], const OnigCodePoint* mbr[]));
-
-
-#define ONIGENC_ISO_8859_1_TO_LOWER_CASE(c) \
- OnigEncISO_8859_1_ToLowerCaseTable[c]
-#define ONIGENC_ISO_8859_1_TO_UPPER_CASE(c) \
- OnigEncISO_8859_1_ToUpperCaseTable[c]
-#define ONIGENC_IS_UNICODE_ISO_8859_1_CTYPE(code,ctype) \
- ((OnigEnc_Unicode_ISO_8859_1_CtypeTable[code] & ctype) != 0)
-
-ONIG_EXTERN const UChar OnigEncISO_8859_1_ToLowerCaseTable[];
-ONIG_EXTERN const UChar OnigEncISO_8859_1_ToUpperCaseTable[];
-ONIG_EXTERN const unsigned short OnigEnc_Unicode_ISO_8859_1_CtypeTable[];
-ONIG_EXTERN const OnigPairAmbigCodes OnigAsciiPairAmbigCodes[];
-
-#endif /* is not ONIG_RUBY_M17N */
-
-ONIG_EXTERN int
-onigenc_with_ascii_strncmp P_((OnigEncoding enc, const UChar* p, const UChar* end, const UChar* sascii /* ascii */, int n));
-ONIG_EXTERN UChar*
-onigenc_step P_((OnigEncoding enc, const UChar* p, const UChar* end, int n));
-
-/* defined in regexec.c, but used in enc/xxx.c */
-extern int onig_is_in_code_range P_((const UChar* p, OnigCodePoint code));
-
-ONIG_EXTERN OnigEncoding OnigEncDefaultCharEncoding;
-ONIG_EXTERN const UChar* OnigEncAsciiToLowerCaseTable;
-ONIG_EXTERN const UChar OnigEncAsciiToUpperCaseTable[];
-ONIG_EXTERN const unsigned short OnigEncAsciiCtypeTable[];
-
-#define ONIGENC_ASCII_CODE_TO_LOWER_CASE(c) OnigEncAsciiToLowerCaseTable[c]
-#define ONIGENC_ASCII_CODE_TO_UPPER_CASE(c) OnigEncAsciiToUpperCaseTable[c]
-#define ONIGENC_IS_ASCII_CODE_CTYPE(code,ctype) \
- ((OnigEncAsciiCtypeTable[code] & ctype) != 0)
-#define ONIGENC_IS_ASCII_CODE_CASE_AMBIG(code) \
- ONIGENC_IS_ASCII_CODE_CTYPE(code, (ONIGENC_CTYPE_UPPER | ONIGENC_CTYPE_LOWER))
-
-#endif /* REGENC_H */
diff --git a/regerror.c b/regerror.c
deleted file mode 100644
index d6ec91856d..0000000000
--- a/regerror.c
+++ /dev/null
@@ -1,371 +0,0 @@
-/**********************************************************************
- regerror.c - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "regint.h"
-#include <stdio.h> /* for vsnprintf() */
-
-#ifdef HAVE_STDARG_PROTOTYPES
-#include <stdarg.h>
-#define va_init_list(a,b) va_start(a,b)
-#else
-#include <varargs.h>
-#define va_init_list(a,b) va_start(a)
-#endif
-
-extern UChar*
-onig_error_code_to_format(int code)
-{
- char *p;
-
- if (code >= 0) return (UChar* )0;
-
- switch (code) {
- case ONIG_MISMATCH:
- p = "mismatch"; break;
- case ONIG_NO_SUPPORT_CONFIG:
- p = "no support in this configuration"; break;
- case ONIGERR_MEMORY:
- p = "fail to memory allocation"; break;
- case ONIGERR_MATCH_STACK_LIMIT_OVER:
- p = "match-stack limit over"; break;
- case ONIGERR_TYPE_BUG:
- p = "undefined type (bug)"; break;
- case ONIGERR_PARSER_BUG:
- p = "internal parser error (bug)"; break;
- case ONIGERR_STACK_BUG:
- p = "stack error (bug)"; break;
- case ONIGERR_UNDEFINED_BYTECODE:
- p = "undefined bytecode (bug)"; break;
- case ONIGERR_UNEXPECTED_BYTECODE:
- p = "unexpected bytecode (bug)"; break;
- case ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED:
- p = "default multibyte-encoding is not setted"; break;
- case ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR:
- p = "can't convert to wide-char on specified multibyte-encoding"; break;
- case ONIGERR_INVALID_ARGUMENT:
- p = "invalid argument"; break;
- case ONIGERR_END_PATTERN_AT_LEFT_BRACE:
- p = "end pattern at left brace"; break;
- case ONIGERR_END_PATTERN_AT_LEFT_BRACKET:
- p = "end pattern at left bracket"; break;
- case ONIGERR_EMPTY_CHAR_CLASS:
- p = "empty char-class"; break;
- case ONIGERR_PREMATURE_END_OF_CHAR_CLASS:
- p = "premature end of char-class"; break;
- case ONIGERR_END_PATTERN_AT_ESCAPE:
- p = "end pattern at escape"; break;
- case ONIGERR_END_PATTERN_AT_META:
- p = "end pattern at meta"; break;
- case ONIGERR_END_PATTERN_AT_CONTROL:
- p = "end pattern at control"; break;
- case ONIGERR_META_CODE_SYNTAX:
- p = "illegal meta-code syntax"; break;
- case ONIGERR_CONTROL_CODE_SYNTAX:
- p = "illegal control-code syntax"; break;
- case ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE:
- p = "char-class value at end of range"; break;
- case ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE:
- p = "char-class value at start of range"; break;
- case ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS:
- p = "unmatched range specifier in char-class"; break;
- case ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED:
- p = "target of repeat operator is not specified"; break;
- case ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID:
- p = "target of repeat operator is invalid"; break;
- case ONIGERR_NESTED_REPEAT_OPERATOR:
- p = "nested repeat operator"; break;
- case ONIGERR_UNMATCHED_CLOSE_PARENTHESIS:
- p = "unmatched close parenthesis"; break;
- case ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS:
- p = "end pattern with unmatched parenthesis"; break;
- case ONIGERR_END_PATTERN_IN_GROUP:
- p = "end pattern in group"; break;
- case ONIGERR_UNDEFINED_GROUP_OPTION:
- p = "undefined group option"; break;
- case ONIGERR_INVALID_POSIX_BRACKET_TYPE:
- p = "invalid POSIX bracket type"; break;
- case ONIGERR_INVALID_LOOK_BEHIND_PATTERN:
- p = "invalid pattern in look-behind"; break;
- case ONIGERR_INVALID_REPEAT_RANGE_PATTERN:
- p = "invalid repeat range {lower,upper}"; break;
- case ONIGERR_TOO_BIG_NUMBER:
- p = "too big number"; break;
- case ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE:
- p = "too big number for repeat range"; break;
- case ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE:
- p = "upper is smaller than lower in repeat range"; break;
- case ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS:
- p = "empty range in char class"; break;
- case ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE:
- p = "mismatch multibyte code length in char-class range"; break;
- case ONIGERR_TOO_MANY_MULTI_BYTE_RANGES:
- p = "too many multibyte code ranges are specified"; break;
- case ONIGERR_TOO_SHORT_MULTI_BYTE_STRING:
- p = "too short multibyte code string"; break;
- case ONIGERR_TOO_BIG_BACKREF_NUMBER:
- p = "too big backref number"; break;
- case ONIGERR_INVALID_BACKREF:
-#ifdef USE_NAMED_GROUP
- p = "invalid backref number/name"; break;
-#else
- p = "invalid backref number"; break;
-#endif
- case ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED:
- p = "numbered backref/call is not allowed. (use name)"; break;
- case ONIGERR_TOO_BIG_WIDE_CHAR_VALUE:
- p = "too big wide-char value"; break;
- case ONIGERR_TOO_LONG_WIDE_CHAR_VALUE:
- p = "too long wide-char value"; break;
- case ONIGERR_INVALID_WIDE_CHAR_VALUE:
- p = "invalid wide-char value"; break;
- case ONIGERR_EMPTY_GROUP_NAME:
- p = "group name is empty"; break;
- case ONIGERR_INVALID_GROUP_NAME:
- p = "invalid group name <%n>"; break;
- case ONIGERR_INVALID_CHAR_IN_GROUP_NAME:
-#ifdef USE_NAMED_GROUP
- p = "invalid char in group name <%n>"; break;
-#else
- p = "invalid char in group number <%n>"; break;
-#endif
- case ONIGERR_UNDEFINED_NAME_REFERENCE:
- p = "undefined name <%n> reference"; break;
- case ONIGERR_UNDEFINED_GROUP_REFERENCE:
- p = "undefined group <%n> reference"; break;
- case ONIGERR_MULTIPLEX_DEFINED_NAME:
- p = "multiplex defined name <%n>"; break;
- case ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL:
- p = "multiplex definition name <%n> call"; break;
- case ONIGERR_NEVER_ENDING_RECURSION:
- p = "never ending recursion"; break;
- case ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY:
- p = "group number is too big for capture history"; break;
- case ONIGERR_INVALID_CHAR_PROPERTY_NAME:
- p = "invalid character property name {%n}"; break;
- case ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION:
- p = "not supported encoding combination"; break;
- case ONIGERR_INVALID_COMBINATION_OF_OPTIONS:
- p = "invalid combination of options"; break;
- case ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT:
- p = "over thread pass limit count"; break;
-
- default:
- p = "undefined error code"; break;
- }
-
- return (UChar* )p;
-}
-
-
-static int to_ascii(OnigEncoding enc, UChar *s, UChar *end,
- UChar buf[], int buf_size, int *is_over)
-{
- int len;
- UChar *p;
- OnigCodePoint code;
-
- if (ONIGENC_MBC_MINLEN(enc) > 1) {
- p = s;
- len = 0;
- while (p < end) {
- code = ONIGENC_MBC_TO_CODE(enc, p, end);
- if (code >= 0x80) {
- if (len + 5 <= buf_size) {
- sprintf((char* )(&(buf[len])), "\\%03o",
- (unsigned int)(code & 0377));
- len += 5;
- }
- else {
- break;
- }
- }
- else {
- buf[len++] = (UChar )code;
- }
-
- p += enc_len(enc, p);
- if (len >= buf_size) break;
- }
-
- *is_over = ((p < end) ? 1 : 0);
- }
- else {
- len = MIN((end - s), buf_size);
- xmemcpy(buf, s, (size_t )len);
- *is_over = ((buf_size < (end - s)) ? 1 : 0);
- }
-
- return len;
-}
-
-
-/* for ONIG_MAX_ERROR_MESSAGE_LEN */
-#define MAX_ERROR_PAR_LEN 30
-
-extern int
-#ifdef HAVE_STDARG_PROTOTYPES
-onig_error_code_to_str(UChar* s, int code, ...)
-#else
-onig_error_code_to_str(s, code, va_alist)
- UChar* s;
- int code;
- va_dcl
-#endif
-{
- UChar *p, *q;
- OnigErrorInfo* einfo;
- int len, is_over;
- UChar parbuf[MAX_ERROR_PAR_LEN];
- va_list vargs;
-
- va_init_list(vargs, code);
-
- switch (code) {
- case ONIGERR_UNDEFINED_NAME_REFERENCE:
- case ONIGERR_UNDEFINED_GROUP_REFERENCE:
- case ONIGERR_MULTIPLEX_DEFINED_NAME:
- case ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL:
- case ONIGERR_INVALID_GROUP_NAME:
- case ONIGERR_INVALID_CHAR_IN_GROUP_NAME:
- case ONIGERR_INVALID_CHAR_PROPERTY_NAME:
- einfo = va_arg(vargs, OnigErrorInfo*);
- len = to_ascii(einfo->enc, einfo->par, einfo->par_end,
- parbuf, MAX_ERROR_PAR_LEN - 3, &is_over);
- q = onig_error_code_to_format(code);
- p = s;
- while (*q != '\0') {
- if (*q == '%') {
- q++;
- if (*q == 'n') { /* '%n': name */
- xmemcpy(p, parbuf, len);
- p += len;
- if (is_over != 0) {
- xmemcpy(p, "...", 3);
- p += 3;
- }
- q++;
- }
- else
- goto normal_char;
- }
- else {
- normal_char:
- *p++ = *q++;
- }
- }
- *p = '\0';
- len = p - s;
- break;
-
- default:
- q = onig_error_code_to_format(code);
- len = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, q);
- xmemcpy(s, q, len);
- s[len] = '\0';
- break;
- }
-
- va_end(vargs);
- return len;
-}
-
-
-void
-#ifdef HAVE_STDARG_PROTOTYPES
-onig_snprintf_with_pattern(UChar buf[], int bufsize, OnigEncoding enc,
- UChar* pat, UChar* pat_end, const UChar *fmt, ...)
-#else
-onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist)
- UChar buf[];
- int bufsize;
- OnigEncoding enc;
- UChar* pat;
- UChar* pat_end;
- const UChar *fmt;
- va_dcl
-#endif
-{
- int n, need, len;
- UChar *p, *s, *bp;
- UChar bs[6];
- va_list args;
-
- va_init_list(args, fmt);
- n = vsnprintf((char* )buf, bufsize, (const char* )fmt, args);
- va_end(args);
-
- need = (pat_end - pat) * 4 + 4;
-
- if (n + need < bufsize) {
- strcat((char* )buf, ": /");
- s = buf + onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, buf);
-
- p = pat;
- while (p < pat_end) {
- if (*p == MC_ESC(enc)) {
- *s++ = *p++;
- len = enc_len(enc, p);
- while (len-- > 0) *s++ = *p++;
- }
- else if (*p == '/') {
- *s++ = (unsigned char )MC_ESC(enc);
- *s++ = *p++;
- }
- else if (ONIGENC_IS_MBC_HEAD(enc, p)) {
- len = enc_len(enc, p);
- if (ONIGENC_MBC_MINLEN(enc) == 1) {
- while (len-- > 0) *s++ = *p++;
- }
- else { /* for UTF16 */
- int blen;
-
- while (len-- > 0) {
- sprintf((char* )bs, "\\%03o", *p++ & 0377);
- blen = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, bs);
- bp = bs;
- while (blen-- > 0) *s++ = *bp++;
- }
- }
- }
- else if (!ONIGENC_IS_CODE_PRINT(enc, *p) &&
- !ONIGENC_IS_CODE_SPACE(enc, *p)) {
- sprintf((char* )bs, "\\%03o", *p++ & 0377);
- len = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, bs);
- bp = bs;
- while (len-- > 0) *s++ = *bp++;
- }
- else {
- *s++ = *p++;
- }
- }
-
- *s++ = '/';
- *s = '\0';
- }
-}
diff --git a/regex.c b/regex.c
new file mode 100644
index 0000000000..54f6b4c9a1
--- /dev/null
+++ b/regex.c
@@ -0,0 +1,4687 @@
+/* Extended regular expression matching and search library.
+ Copyright (C) 1993, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file LGPL. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+/* Multi-byte extension added May, 1993 by t^2 (Takahiro Tanimoto)
+ Last change: May 21, 1993 by t^2 */
+/* removed gapped buffer support, multiple syntax support by matz <matz@nts.co.jp> */
+/* Perl5 extension added by matz <matz@caelum.co.jp> */
+/* UTF-8 extension added Jan 16 1999 by Yoshida Masato <yoshidam@tau.bekkoame.ne.jp> */
+
+#include "config.h"
+
+#ifdef HAVE_STRING_H
+# include <string.h>
+#else
+# include <strings.h>
+#endif
+
+/* We write fatal error messages on standard error. */
+#include <stdio.h>
+
+/* isalpha(3) etc. are used for the character classes. */
+#include <ctype.h>
+#include <sys/types.h>
+
+#ifndef PARAMS
+# if defined __GNUC__ || (defined __STDC__ && __STDC__)
+# define PARAMS(args) args
+# else
+# define PARAMS(args) ()
+# endif /* GCC. */
+#endif /* Not PARAMS. */
+
+#if defined(STDC_HEADERS)
+# include <stddef.h>
+#else
+/* 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
+#endif
+
+#ifdef HAVE_PROTOTYPES
+# define _(args) args
+#else
+# define _(args) ()
+#endif
+
+#ifdef RUBY_PLATFORM
+#include "defines.h"
+#undef xmalloc
+#undef xrealloc
+#undef xcalloc
+#undef xfree
+
+# define RUBY
+extern int rb_prohibit_interrupt;
+extern int rb_trap_pending;
+void rb_trap_exec _((void));
+
+# define CHECK_INTS do {\
+ if (!rb_prohibit_interrupt) {\
+ if (rb_trap_pending) rb_trap_exec();\
+ }\
+} while (0)
+#endif
+
+/* Make alloca work the best possible way. */
+#ifdef __GNUC__
+# ifndef atarist
+# ifndef alloca
+# define alloca __builtin_alloca
+# endif
+# endif /* atarist */
+#else
+# ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+# else
+# ifdef _AIX
+ #pragma alloca
+# else
+# ifndef alloca /* predefined by HP cc +Olibcalls */
+void *alloca ();
+# endif
+# endif /* AIX */
+# endif /* HAVE_ALLOCA_H */
+
+#endif /* __GNUC__ */
+
+#ifdef HAVE_STRING_H
+# include <string.h>
+#else
+# 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
+#define FREE_VARIABLES()
+#endif
+
+#define FREE_AND_RETURN_VOID(stackb) do { \
+ FREE_VARIABLES(); \
+ if (stackb != stacka) xfree(stackb); \
+ return; \
+} while(0)
+
+#define FREE_AND_RETURN(stackb,val) do { \
+ FREE_VARIABLES(); \
+ if (stackb != stacka) xfree(stackb); \
+ return(val); \
+} while(0)
+
+#define DOUBLE_STACK(type) do { \
+ type *stackx; \
+ 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); \
+ stackb = stackx; \
+ stacke = stackb + 2 * xlen; \
+} while (0)
+
+#define RE_TALLOC(n,t) ((t*)alloca((n)*sizeof(t)))
+#define TMALLOC(n,t) ((t*)xmalloc((n)*sizeof(t)))
+#define TREALLOC(s,n,t) (s=((t*)xrealloc(s,(n)*sizeof(t))))
+
+#define EXPAND_FAIL_STACK() DOUBLE_STACK(unsigned char*)
+#define ENSURE_FAIL_STACK(n) \
+ do { \
+ if (stacke - stackp <= (n)) { \
+ /* if (len > re_max_failures * MAX_NUM_FAILURE_ITEMS) \
+ { \
+ FREE_AND_RETURN(stackb,(-2)); \
+ }*/ \
+ \
+ /* Roughly double the size of the stack. */ \
+ EXPAND_FAIL_STACK(); \
+ } \
+ } while (0)
+
+/* Get the interface, including the syntax bits. */
+#include "regex.h"
+
+/* Subroutines for re_compile_pattern. */
+static void store_jump _((char*, int, char*));
+static void insert_jump _((int, char*, char*, char*));
+static void store_jump_n _((char*, int, char*, unsigned));
+static void insert_jump_n _((int, char*, char*, char*, unsigned));
+static void insert_op _((int, char*, char*));
+static void insert_op_2 _((int, char*, char*, int, int));
+static int memcmp_translate _((unsigned char*, unsigned char*, int));
+
+/* Define the syntax stuff, so we can do the \<, \>, etc. */
+
+/* This must be nonzero for the wordchar and notwordchar pattern
+ commands in re_match. */
+#define Sword 1
+#define Sword2 2
+
+#define SYNTAX(c) re_syntax_table[c]
+
+static char re_syntax_table[256];
+static void init_syntax_once _((void));
+static const unsigned char *translate = 0;
+static void init_regs _((struct re_registers*, unsigned int));
+static void bm_init_skip _((int *, unsigned char*, int, const unsigned char*));
+static int current_mbctype = MBCTYPE_ASCII;
+
+#undef P
+
+#ifdef RUBY
+#include "util.h"
+void rb_warn _((const char*, ...));
+# define re_warning(x) rb_warn(x)
+#endif
+
+#ifndef re_warning
+# define re_warning(x)
+#endif
+
+static void
+init_syntax_once()
+{
+ register int c;
+ static int done = 0;
+
+ if (done)
+ return;
+
+ memset(re_syntax_table, 0, sizeof re_syntax_table);
+
+ for (c=0; c<=0x7f; c++)
+ if (isalnum(c))
+ re_syntax_table[c] = Sword;
+ re_syntax_table['_'] = Sword;
+
+ for (c=0x80; c<=0xff; c++)
+ if (isalnum(c))
+ re_syntax_table[c] = Sword2;
+ done = 1;
+}
+
+void
+re_set_casetable(table)
+ const char *table;
+{
+ translate = (const unsigned char*)table;
+}
+
+/* Jim Meyering writes:
+
+ "... Some ctype macros are valid only for character codes that
+ isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
+ using /bin/cc or gcc but without giving an ansi option). So, all
+ ctype uses should be through macros like ISPRINT... If
+ STDC_HEADERS is defined, then autoconf has verified that the ctype
+ macros don't need to be guarded with references to isascii. ...
+ Defining isascii to 1 should let any compiler worth its salt
+ eliminate the && through constant folding."
+ Solaris defines some of these symbols so we must undefine them first. */
+
+#undef ISASCII
+#if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)
+# define ISASCII(c) 1
+#else
+# define ISASCII(c) isascii(c)
+#endif
+
+#ifdef isblank
+# define ISBLANK(c) (ISASCII(c) && isblank(c))
+#else
+# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
+#endif
+#ifdef isgraph
+# define ISGRAPH(c) (ISASCII(c) && isgraph(c))
+#else
+# define ISGRAPH(c) (ISASCII(c) && isprint(c) && !isspace(c))
+#endif
+
+#undef ISPRINT
+#define ISPRINT(c) (ISASCII(c) && isprint(c))
+#define ISDIGIT(c) (ISASCII(c) && isdigit(c))
+#define ISALNUM(c) (ISASCII(c) && isalnum(c))
+#define ISALPHA(c) (ISASCII(c) && isalpha(c))
+#define ISCNTRL(c) (ISASCII(c) && iscntrl(c))
+#define ISLOWER(c) (ISASCII(c) && islower(c))
+#define ISPUNCT(c) (ISASCII(c) && ispunct(c))
+#define ISSPACE(c) (ISASCII(c) && isspace(c))
+#define ISUPPER(c) (ISASCII(c) && isupper(c))
+#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
+
+#ifndef NULL
+# define NULL (void *)0
+#endif
+
+/* We remove any previous definition of `SIGN_EXTEND_CHAR',
+ since ours (we hope) works properly with all combinations of
+ machines, compilers, `char' and `unsigned char' argument types.
+ (Per Bothner suggested the basic approach.) */
+#undef SIGN_EXTEND_CHAR
+#if __STDC__
+# define SIGN_EXTEND_CHAR(c) ((signed char)(c))
+#else /* not __STDC__ */
+/* As in Harbison and Steele. */
+# define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
+#endif
+
+/* These are the command codes that appear in compiled regular
+ expressions, one per byte. Some command codes are followed by
+ argument bytes. A command code can specify any interpretation
+ whatsoever for its arguments. Zero-bytes may appear in the compiled
+ regular expression.
+
+ The value of `exactn' is needed in search.c (search_buffer) in emacs.
+ So regex.h defines a symbol `RE_EXACTN_VALUE' to be 1; the value of
+ `exactn' we use here must also be 1. */
+
+enum regexpcode
+ {
+ unused=0,
+ exactn=1, /* Followed by one byte giving n, then by n literal bytes. */
+ begline, /* Fail unless at beginning of line. */
+ endline, /* Fail unless at end of line. */
+ begbuf, /* Succeeds if at beginning of buffer (if emacs) or at beginning
+ of string to be matched (if not). */
+ endbuf, /* Analogously, for end of buffer/string. */
+ endbuf2, /* End of buffer/string, or newline just before it. */
+ begpos, /* Matches where last scan//gsub left off. */
+ jump, /* Followed by two bytes giving relative address to jump to. */
+ jump_past_alt,/* Same as jump, but marks the end of an alternative. */
+ on_failure_jump, /* Followed by two bytes giving relative address of
+ place to resume at in case of failure. */
+ finalize_jump, /* Throw away latest failure point and then jump to
+ address. */
+ maybe_finalize_jump, /* Like jump but finalize if safe to do so.
+ This is used to jump back to the beginning
+ of a repeat. If the command that follows
+ this jump is clearly incompatible with the
+ one at the beginning of the repeat, such that
+ we can be sure that there is no use backtracking
+ out of repetitions already completed,
+ then we finalize. */
+ dummy_failure_jump, /* Jump, and push a dummy failure point. This
+ failure point will be thrown away if an attempt
+ is made to use it for a failure. A + construct
+ makes this before the first repeat. Also
+ use it as an intermediary kind of jump when
+ compiling an or construct. */
+ push_dummy_failure, /* Push a dummy failure point and continue. Used at the end of
+ alternatives. */
+ succeed_n, /* Used like on_failure_jump except has to succeed n times;
+ then gets turned into an on_failure_jump. The relative
+ address following it is useless until then. The
+ address is followed by two bytes containing n. */
+ jump_n, /* Similar to jump, but jump n times only; also the relative
+ address following is in turn followed by yet two more bytes
+ containing n. */
+ try_next, /* Jump to next pattern for the first time,
+ leaving this pattern on the failure stack. */
+ finalize_push, /* Finalize stack and push the beginning of the pattern
+ on the stack to retry (used for non-greedy match) */
+ finalize_push_n, /* Similar to finalize_push, buf finalize n time only */
+ set_number_at, /* Set the following relative location to the
+ subsequent number. */
+ anychar, /* Matches any (more or less) one character excluding newlines. */
+ anychar_repeat, /* Matches sequence of characters excluding newlines. */
+ charset, /* Matches any one char belonging to specified set.
+ First following byte is number of bitmap bytes.
+ Then come bytes for a bitmap saying which chars are in.
+ Bits in each byte are ordered low-bit-first.
+ A character is in the set if its bit is 1.
+ A character too large to have a bit in the map
+ is automatically not in the set. */
+ charset_not, /* Same parameters as charset, but match any character
+ that is not one of those specified. */
+ start_memory, /* Start remembering the text that is matched, for
+ storing in a memory register. Followed by one
+ byte containing the register number. Register numbers
+ must be in the range 0 through RE_NREGS. */
+ stop_memory, /* Stop remembering the text that is matched
+ and store it in a memory register. Followed by
+ one byte containing the register number. Register
+ numbers must be in the range 0 through RE_NREGS. */
+ start_paren, /* Place holder at the start of (?:..). */
+ stop_paren, /* Place holder at the end of (?:..). */
+ casefold_on, /* Turn on casefold flag. */
+ casefold_off, /* Turn off casefold flag. */
+ option_set, /* Turn on multi line match (match with newlines). */
+ start_nowidth, /* Save string point to the stack. */
+ stop_nowidth, /* Restore string place at the point start_nowidth. */
+ pop_and_fail, /* Fail after popping nowidth entry from stack. */
+ stop_backtrack, /* Restore backtrack stack at the point start_nowidth. */
+ duplicate, /* Match a duplicate of something remembered.
+ Followed by one byte containing the index of the memory
+ register. */
+ wordchar, /* Matches any word-constituent character. */
+ notwordchar, /* Matches any char that is not a word-constituent. */
+ wordbeg, /* Succeeds if at word beginning. */
+ wordend, /* Succeeds if at word end. */
+ wordbound, /* Succeeds if at a word boundary. */
+ notwordbound /* Succeeds if not at a word boundary. */
+ };
+
+
+/* Number of failure points to allocate space for initially,
+ when matching. If this number is exceeded, more space is allocated,
+ so it is not a hard limit. */
+
+#ifndef NFAILURES
+#define NFAILURES 160
+#endif
+
+/* Store NUMBER in two contiguous bytes starting at DESTINATION. */
+#define STORE_NUMBER(destination, number) \
+ do { (destination)[0] = (number) & 0377; \
+ (destination)[1] = (number) >> 8; } while (0)
+
+/* Same as STORE_NUMBER, except increment the destination pointer to
+ the byte after where the number is stored. Watch out that values for
+ DESTINATION such as p + 1 won't work, whereas p will. */
+#define STORE_NUMBER_AND_INCR(destination, number) \
+ do { STORE_NUMBER(destination, number); \
+ (destination) += 2; } while (0)
+
+
+/* Put into DESTINATION a number stored in two contingous bytes starting
+ at SOURCE. */
+#define EXTRACT_NUMBER(destination, source) \
+ do { (destination) = *(source) & 0377; \
+ (destination) += SIGN_EXTEND_CHAR(*(char*)((source) + 1)) << 8; } while (0)
+
+/* Same as EXTRACT_NUMBER, except increment the pointer for source to
+ point to second byte of SOURCE. Note that SOURCE has to be a value
+ such as p, not, e.g., p + 1. */
+#define EXTRACT_NUMBER_AND_INCR(destination, source) \
+ do { EXTRACT_NUMBER(destination, source); \
+ (source) += 2; } while (0)
+
+
+/* Specify the precise syntax of regexps for compilation. This provides
+ for compatibility for various utilities which historically have
+ different, incompatible syntaxes.
+
+ The argument SYNTAX is a bit-mask comprised of the various bits
+ defined in regex.h. */
+
+long
+re_set_syntax(syntax)
+ long syntax;
+{
+ /* obsolete */
+ return 0;
+}
+
+/* Macros for re_compile_pattern, which is found below these definitions. */
+
+#define TRANSLATE_P() ((options&RE_OPTION_IGNORECASE) && translate)
+#define MAY_TRANSLATE() ((bufp->options&(RE_OPTION_IGNORECASE|RE_MAY_IGNORECASE)) && translate)
+/* Fetch the next character in the uncompiled pattern---translating it
+ if necessary. Also cast from a signed character in the constant
+ string passed to us by the user to an unsigned char that we can use
+ as an array index (in, e.g., `translate'). */
+#define PATFETCH(c) \
+ do {if (p == pend) goto end_of_pattern; \
+ c = (unsigned char) *p++; \
+ if (TRANSLATE_P()) c = (unsigned char)translate[c]; \
+ } while (0)
+
+/* Fetch the next character in the uncompiled pattern, with no
+ translation. */
+#define PATFETCH_RAW(c) \
+ do {if (p == pend) goto end_of_pattern; \
+ c = (unsigned char)*p++; \
+ } while (0)
+
+/* Go backwards one character in the pattern. */
+#define PATUNFETCH p--
+
+#define MBC2WC(c, p) \
+ do { \
+ if (current_mbctype == MBCTYPE_UTF8) { \
+ int n = mbclen(c) - 1; \
+ c &= (1<<(BYTEWIDTH-2-n)) - 1; \
+ while (n--) { \
+ c = c << 6 | (*p++ & ((1<<6)-1)); \
+ } \
+ } \
+ else { \
+ c <<= 8; \
+ c |= (unsigned char)*(p)++; \
+ } \
+ } while (0)
+
+#define PATFETCH_MBC(c) \
+ do { \
+ if (p + mbclen(c) - 1 >= pend) goto end_of_pattern; \
+ MBC2WC(c, p); \
+ } while(0)
+
+#define WC2MBC1ST(c) \
+ ((current_mbctype != MBCTYPE_UTF8) ? ((c<0x100) ? (c) : (((c)>>8)&0xff)) : utf8_firstbyte(c))
+
+typedef unsigned int (*mbc_startpos_func_t) _((const char *string, unsigned int pos));
+
+static unsigned int asc_startpos _((const char *string, unsigned int pos));
+static unsigned int euc_startpos _((const char *string, unsigned int pos));
+static unsigned int sjis_startpos _((const char *string, unsigned int pos));
+static unsigned int utf8_startpos _((const char *string, unsigned int pos));
+
+static const mbc_startpos_func_t mbc_startpos_func[4] = {
+ asc_startpos, euc_startpos, sjis_startpos, utf8_startpos
+};
+
+#define mbc_startpos(start, pos) (*mbc_startpos_func[current_mbctype])((start), (pos))
+
+static unsigned int
+utf8_firstbyte(c)
+ unsigned long c;
+{
+ if (c < 0x80) return c;
+ if (c <= 0x7ff) return ((c>>6)&0xff)|0xc0;
+ if (c <= 0xffff) return ((c>>12)&0xff)|0xe0;
+ if (c <= 0x1fffff) return ((c>>18)&0xff)|0xf0;
+ if (c <= 0x3ffffff) return ((c>>24)&0xff)|0xf8;
+ if (c <= 0x7fffffff) return ((c>>30)&0xff)|0xfc;
+#if SIZEOF_INT > 4
+ if (c <= 0xfffffffff) return 0xfe;
+#else
+ return 0xfe;
+#endif
+}
+
+static void
+print_mbc(c)
+ unsigned int c;
+{
+ if (current_mbctype == MBCTYPE_UTF8) {
+ if (c < 0x80)
+ printf("%c", (int)c);
+ else if (c <= 0x7ff)
+ printf("%c%c", (int)utf8_firstbyte(c), (int)(c & 0x3f));
+ else if (c <= 0xffff)
+ printf("%c%c%c", (int)utf8_firstbyte(c), (int)((c >> 6) & 0x3f),
+ (int)(c & 0x3f));
+ else if (c <= 0x1fffff)
+ printf("%c%c%c%c", (int)utf8_firstbyte(c), (int)((c >> 12) & 0x3f),
+ (int)((c >> 6) & 0x3f), (int)(c & 0x3f));
+ else if (c <= 0x3ffffff)
+ printf("%c%c%c%c%c", (int)utf8_firstbyte(c), (int)((c >> 18) & 0x3f),
+ (int)((c >> 12) & 0x3f), (int)((c >> 6) & 0x3f), (int)(c & 0x3f));
+ else if (c <= 0x7fffffff)
+ printf("%c%c%c%c%c%c", (int)utf8_firstbyte(c), (int)((c >> 24) & 0x3f),
+ (int)((c >> 18) & 0x3f), (int)((c >> 12) & 0x3f),
+ (int)((c >> 6) & 0x3f), (int)(c & 0x3f));
+ }
+ else if (c < 0xff) {
+ printf("\\%o", (int)c);
+ }
+ else {
+ printf("%c%c", (int)(c >> BYTEWIDTH), (int)(c &0xff));
+ }
+}
+
+/* If the buffer isn't allocated when it comes in, use this. */
+#define INIT_BUF_SIZE 28
+
+/* Make sure we have at least N more bytes of space in buffer. */
+#define GET_BUFFER_SPACE(n) \
+ do { \
+ while (b - bufp->buffer + (n) >= bufp->allocated) \
+ EXTEND_BUFFER; \
+ } while (0)
+
+/* Make sure we have one more byte of buffer space and then add CH to it. */
+#define BUFPUSH(ch) \
+ do { \
+ GET_BUFFER_SPACE(1); \
+ *b++ = (char)(ch); \
+ } while (0)
+
+/* Extend the buffer by twice its current size via reallociation and
+ reset the pointers that pointed into the old allocation to point to
+ the correct places in the new allocation. If extending the buffer
+ results in it being larger than 1 << 16, then flag memory exhausted. */
+#define EXTEND_BUFFER \
+ do { char *old_buffer = bufp->buffer; \
+ if (bufp->allocated == (1L<<16)) goto too_big; \
+ bufp->allocated *= 2; \
+ if (bufp->allocated > (1L<<16)) bufp->allocated = (1L<<16); \
+ bufp->buffer = (char*)xrealloc(bufp->buffer, bufp->allocated); \
+ if (bufp->buffer == 0) \
+ goto memory_exhausted; \
+ b = (b - old_buffer) + bufp->buffer; \
+ if (fixup_alt_jump) \
+ fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer; \
+ if (laststart) \
+ laststart = (laststart - old_buffer) + bufp->buffer; \
+ begalt = (begalt - old_buffer) + bufp->buffer; \
+ if (pending_exact) \
+ pending_exact = (pending_exact - old_buffer) + bufp->buffer; \
+ } while (0)
+
+
+/* Set the bit for character C in a character set list. */
+#define SET_LIST_BIT(c) \
+ (b[(unsigned char)(c) / BYTEWIDTH] \
+ |= 1 << ((unsigned char)(c) % BYTEWIDTH))
+
+/* Get the next unsigned number in the uncompiled pattern. */
+#define GET_UNSIGNED_NUMBER(num) \
+ do { if (p != pend) { \
+ PATFETCH(c); \
+ while (ISDIGIT(c)) { \
+ if (num < 0) \
+ num = 0; \
+ num = num * 10 + c - '0'; \
+ if (p == pend) \
+ break; \
+ PATFETCH(c); \
+ } \
+ } \
+ } while (0)
+
+#define STREQ(s1, s2) ((strcmp(s1, s2) == 0))
+
+#define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
+
+#define IS_CHAR_CLASS(string) \
+ (STREQ(string, "alpha") || STREQ(string, "upper") \
+ || STREQ(string, "lower") || STREQ(string, "digit") \
+ || STREQ(string, "alnum") || STREQ(string, "xdigit") \
+ || STREQ(string, "space") || STREQ(string, "print") \
+ || STREQ(string, "punct") || STREQ(string, "graph") \
+ || STREQ(string, "cntrl") || STREQ(string, "blank"))
+
+#define STORE_MBC(p, c) \
+ do { \
+ (p)[0] = (unsigned char)(((c) >>24) & 0xff); \
+ (p)[1] = (unsigned char)(((c) >>16) & 0xff); \
+ (p)[2] = (unsigned char)(((c) >> 8) & 0xff); \
+ (p)[3] = (unsigned char)(((c) >> 0) & 0xff); \
+ } while (0)
+
+#define STORE_MBC_AND_INCR(p, c) \
+ do { \
+ *(p)++ = (unsigned char)(((c) >>24) & 0xff); \
+ *(p)++ = (unsigned char)(((c) >>16) & 0xff); \
+ *(p)++ = (unsigned char)(((c) >> 8) & 0xff); \
+ *(p)++ = (unsigned char)(((c) >> 0) & 0xff); \
+ } while (0)
+
+#define EXTRACT_MBC(p) \
+ ((unsigned int)((unsigned char)(p)[0] << 24 | \
+ (unsigned char)(p)[1] << 16 | \
+ (unsigned char)(p)[2] << 8 | \
+ (unsigned char)(p)[3]))
+
+#define EXTRACT_MBC_AND_INCR(p) \
+ ((unsigned int)((p) += 4, \
+ (unsigned char)(p)[-4] << 24 | \
+ (unsigned char)(p)[-3] << 16 | \
+ (unsigned char)(p)[-2] << 8 | \
+ (unsigned char)(p)[-1]))
+
+#define EXTRACT_UNSIGNED(p) \
+ ((unsigned char)(p)[0] | (unsigned char)(p)[1] << 8)
+#define EXTRACT_UNSIGNED_AND_INCR(p) \
+ ((p) += 2, (unsigned char)(p)[-2] | (unsigned char)(p)[-1] << 8)
+
+/* Handle (mb)?charset(_not)?.
+
+ Structure of mbcharset(_not)? in compiled pattern.
+
+ struct {
+ unsinged char id; mbcharset(_not)?
+ unsigned char sbc_size;
+ unsigned char sbc_map[sbc_size]; same as charset(_not)? up to here.
+ unsigned short mbc_size; number of intervals.
+ struct {
+ unsigned long beg; beginning of interval.
+ unsigned long end; end of interval.
+ } intervals[mbc_size];
+ }; */
+
+static void
+set_list_bits(c1, c2, b)
+ unsigned long c1, c2;
+ unsigned char *b;
+{
+ unsigned char sbc_size = b[-1];
+ unsigned short mbc_size = EXTRACT_UNSIGNED(&b[sbc_size]);
+ unsigned short beg, end, upb;
+
+ if (c1 > c2)
+ return;
+ b = &b[sbc_size + 2];
+
+ for (beg = 0, upb = mbc_size; beg < upb; ) {
+ unsigned short mid = (unsigned short)(beg + upb) >> 1;
+
+ if ((int)c1 - 1 > (int)EXTRACT_MBC(&b[mid*8+4]))
+ beg = mid + 1;
+ else
+ upb = mid;
+ }
+
+ for (end = beg, upb = mbc_size; end < upb; ) {
+ unsigned short mid = (unsigned short)(end + upb) >> 1;
+
+ if ((int)c2 >= (int)EXTRACT_MBC(&b[mid*8]) - 1)
+ end = mid + 1;
+ else
+ upb = mid;
+ }
+
+ if (beg != end) {
+ if (c1 > EXTRACT_MBC(&b[beg*8]))
+ c1 = EXTRACT_MBC(&b[beg*8]);
+ if (c2 < EXTRACT_MBC(&b[(end - 1)*8+4]))
+ c2 = EXTRACT_MBC(&b[(end - 1)*8+4]);
+ }
+ if (end < mbc_size && end != beg + 1)
+ /* NOTE: memcpy() would not work here. */
+ memmove(&b[(beg + 1)*8], &b[end*8], (mbc_size - end)*8);
+ STORE_MBC(&b[beg*8 + 0], c1);
+ STORE_MBC(&b[beg*8 + 4], c2);
+ mbc_size += beg - end + 1;
+ STORE_NUMBER(&b[-2], mbc_size);
+}
+
+static int
+is_in_list_sbc(c, b)
+ unsigned long c;
+ const unsigned char *b;
+{
+ unsigned short size;
+
+ size = *b++;
+ return ((int)c / BYTEWIDTH < (int)size && b[c / BYTEWIDTH] & 1 << c % BYTEWIDTH);
+}
+
+static int
+is_in_list_mbc(c, b)
+ unsigned long c;
+ const unsigned char *b;
+{
+ unsigned short size;
+ unsigned short i, j;
+
+ size = *b++;
+ b += size + 2;
+ size = EXTRACT_UNSIGNED(&b[-2]);
+ if (size == 0) return 0;
+
+ for (i = 0, j = size; i < j; ) {
+ unsigned short k = (unsigned short)(i + j) >> 1;
+
+ if (c > EXTRACT_MBC(&b[k*8+4]))
+ i = k + 1;
+ else
+ j = k;
+ }
+ if (i < size && EXTRACT_MBC(&b[i*8]) <= c)
+ return 1;
+
+ return 0;
+}
+
+static int
+is_in_list(c, b)
+ unsigned long c;
+ const unsigned char *b;
+{
+ return is_in_list_sbc(c, b) || (current_mbctype ? is_in_list_mbc(c, b) : 0);
+}
+
+static void
+print_partial_compiled_pattern(start, end)
+ unsigned char *start;
+ unsigned char *end;
+{
+ int mcnt, mcnt2;
+ unsigned char *p = start;
+ unsigned char *pend = end;
+
+ if (start == NULL) {
+ printf("(null)\n");
+ return;
+ }
+
+ /* Loop over pattern commands. */
+ while (p < pend) {
+ switch ((enum regexpcode)*p++) {
+ case unused:
+ printf("/unused");
+ break;
+
+ case exactn:
+ mcnt = *p++;
+ printf("/exactn/%d", mcnt);
+ do {
+ putchar('/');
+ printf("%c", *p++);
+ }
+ while (--mcnt);
+ break;
+
+ case start_memory:
+ mcnt = *p++;
+ printf("/start_memory/%d/%d", mcnt, *p++);
+ break;
+
+ case stop_memory:
+ mcnt = *p++;
+ printf("/stop_memory/%d/%d", mcnt, *p++);
+ break;
+
+ case start_paren:
+ printf("/start_paren");
+ break;
+
+ case stop_paren:
+ printf("/stop_paren");
+ break;
+
+ case casefold_on:
+ printf("/casefold_on");
+ break;
+
+ case casefold_off:
+ printf("/casefold_off");
+ break;
+
+ case option_set:
+ printf("/option_set/%d", *p++);
+ break;
+
+ case start_nowidth:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ printf("/start_nowidth//%d", mcnt);
+ break;
+
+ case stop_nowidth:
+ printf("/stop_nowidth//");
+ p += 2;
+ break;
+
+ case pop_and_fail:
+ printf("/pop_and_fail");
+ break;
+
+ case stop_backtrack:
+ printf("/stop_backtrack//");
+ p += 2;
+ break;
+
+ case duplicate:
+ printf("/duplicate/%d", *p++);
+ break;
+
+ case anychar:
+ printf("/anychar");
+ break;
+
+ case anychar_repeat:
+ printf("/anychar_repeat");
+ break;
+
+ case charset:
+ case charset_not:
+ {
+ register int c;
+
+ printf("/charset%s",
+ (enum regexpcode)*(p - 1) == charset_not ? "_not" : "");
+
+ mcnt = *p++;
+ printf("/%d", mcnt);
+ for (c = 0; c < mcnt; c++) {
+ unsigned bit;
+ unsigned char map_byte = p[c];
+
+ putchar('/');
+
+ for (bit = 0; bit < BYTEWIDTH; bit++)
+ if (map_byte & (1 << bit))
+ printf("%c", c * BYTEWIDTH + bit);
+ }
+ p += mcnt;
+ mcnt = EXTRACT_UNSIGNED_AND_INCR(p);
+ putchar('/');
+ while (mcnt--) {
+ print_mbc(EXTRACT_MBC_AND_INCR(p));
+ putchar('-');
+ print_mbc(EXTRACT_MBC_AND_INCR(p));
+ }
+ break;
+ }
+
+ case begline:
+ printf("/begline");
+ break;
+
+ case endline:
+ printf("/endline");
+ break;
+
+ case on_failure_jump:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ printf("/on_failure_jump//%d", mcnt);
+ break;
+
+ case dummy_failure_jump:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ printf("/dummy_failure_jump//%d", mcnt);
+ break;
+
+ case push_dummy_failure:
+ printf("/push_dummy_failure");
+ break;
+
+ case finalize_jump:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ printf("/finalize_jump//%d", mcnt);
+ break;
+
+ case maybe_finalize_jump:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ printf("/maybe_finalize_jump//%d", mcnt);
+ break;
+
+ case jump_past_alt:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ printf("/jump_past_alt//%d", mcnt);
+ break;
+
+ case jump:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ printf("/jump//%d", mcnt);
+ break;
+
+ case succeed_n:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt2, p);
+ printf("/succeed_n//%d//%d", mcnt, mcnt2);
+ break;
+
+ case jump_n:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt2, p);
+ printf("/jump_n//%d//%d", mcnt, mcnt2);
+ break;
+
+ case set_number_at:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt2, p);
+ printf("/set_number_at//%d//%d", mcnt, mcnt2);
+ break;
+
+ case try_next:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ printf("/try_next//%d", mcnt);
+ break;
+
+ case finalize_push:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ printf("/finalize_push//%d", mcnt);
+ break;
+
+ case finalize_push_n:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt2, p);
+ printf("/finalize_push_n//%d//%d", mcnt, mcnt2);
+ break;
+
+ case wordbound:
+ printf("/wordbound");
+ break;
+
+ case notwordbound:
+ printf("/notwordbound");
+ break;
+
+ case wordbeg:
+ printf("/wordbeg");
+ break;
+
+ case wordend:
+ printf("/wordend");
+
+ case wordchar:
+ printf("/wordchar");
+ break;
+
+ case notwordchar:
+ printf("/notwordchar");
+ break;
+
+ case begbuf:
+ printf("/begbuf");
+ break;
+
+ case endbuf:
+ printf("/endbuf");
+ break;
+
+ case endbuf2:
+ printf("/endbuf2");
+ break;
+
+ case begpos:
+ printf("/begpos");
+ break;
+
+ default:
+ printf("?%d", *(p-1));
+ }
+ }
+ printf("/\n");
+}
+
+
+static void
+print_compiled_pattern(bufp)
+ struct re_pattern_buffer *bufp;
+{
+ unsigned char *buffer = (unsigned char*)bufp->buffer;
+
+ print_partial_compiled_pattern(buffer, buffer + bufp->used);
+}
+
+static char*
+calculate_must_string(start, end)
+ char *start;
+ char *end;
+{
+ int mcnt;
+ int max = 0;
+ unsigned char *p = (unsigned char *)start;
+ unsigned char *pend = (unsigned char *)end;
+ char *must = 0;
+
+ if (start == NULL) return 0;
+
+ /* Loop over pattern commands. */
+ while (p < pend) {
+ switch ((enum regexpcode)*p++) {
+ case unused:
+ break;
+
+ case exactn:
+ mcnt = *p;
+ if (mcnt > max) {
+ must = (char *)p;
+ max = mcnt;
+ }
+ p += mcnt+1;
+ break;
+
+ case start_memory:
+ case stop_memory:
+ p += 2;
+ break;
+
+ case duplicate:
+ case option_set:
+ p++;
+ break;
+
+ case casefold_on:
+ case casefold_off:
+ return 0; /* should not check must_string */
+
+ case pop_and_fail:
+ case anychar:
+ case anychar_repeat:
+ case begline:
+ case endline:
+ case wordbound:
+ case notwordbound:
+ case wordbeg:
+ case wordend:
+ case wordchar:
+ case notwordchar:
+ case begbuf:
+ case endbuf:
+ case endbuf2:
+ case begpos:
+ case push_dummy_failure:
+ case start_paren:
+ case stop_paren:
+ break;
+
+ case charset:
+ case charset_not:
+ mcnt = *p++;
+ p += mcnt;
+ mcnt = EXTRACT_UNSIGNED_AND_INCR(p);
+ while (mcnt--) {
+ p += 8;
+ }
+ break;
+
+ case on_failure_jump:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ if (mcnt > 0) p += mcnt;
+ if ((enum regexpcode)p[-3] == jump) {
+ p -= 2;
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ if (mcnt > 0) p += mcnt;
+ }
+ break;
+
+ case dummy_failure_jump:
+ case succeed_n:
+ case try_next:
+ case jump:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ if (mcnt > 0) p += mcnt;
+ break;
+
+ case start_nowidth:
+ case stop_nowidth:
+ case stop_backtrack:
+ case finalize_jump:
+ case maybe_finalize_jump:
+ case finalize_push:
+ p += 2;
+ break;
+
+ case jump_n:
+ case set_number_at:
+ case finalize_push_n:
+ p += 4;
+ break;
+
+ default:
+ break;
+ }
+ }
+ return must;
+}
+
+static unsigned int
+read_backslash(c)
+ int c;
+{
+ switch (c) {
+ case 'n':
+ return '\n';
+
+ case 't':
+ return '\t';
+
+ case 'r':
+ return '\r';
+
+ case 'f':
+ return '\f';
+
+ case 'v':
+ return '\v';
+
+ case 'a':
+ return '\007';
+
+ case 'b':
+ return '\010';
+
+ case 'e':
+ return '\033';
+ }
+ return c;
+}
+
+static unsigned int
+read_special(p, pend, pp)
+ const char *p, *pend, **pp;
+{
+ int c;
+
+ PATFETCH_RAW(c);
+ switch (c) {
+ case 'M':
+ PATFETCH_RAW(c);
+ if (c != '-') return -1;
+ PATFETCH_RAW(c);
+ *pp = p;
+ if (c == '\\') {
+ return read_special(--p, pend, pp) | 0x80;
+ }
+ else if (c == -1) return ~0;
+ else {
+ return ((c & 0xff) | 0x80);
+ }
+
+ case 'C':
+ PATFETCH_RAW(c);
+ if (c != '-') return ~0;
+ case 'c':
+ PATFETCH_RAW(c);
+ *pp = p;
+ if (c == '\\') {
+ c = read_special(--p, pend, pp);
+ }
+ else if (c == '?') return 0177;
+ else if (c == -1) return ~0;
+ return c & 0x9f;
+ default:
+ *pp = p + 1;
+ return read_backslash(c);
+ }
+
+ end_of_pattern:
+ return ~0;
+}
+
+/* re_compile_pattern takes a regular-expression string
+ and converts it into a buffer full of byte commands for matching.
+
+ PATTERN is the address of the pattern string
+ SIZE is the length of it.
+ BUFP is a struct re_pattern_buffer * which points to the info
+ on where to store the byte commands.
+ This structure contains a char * which points to the
+ actual space, which should have been obtained with malloc.
+ re_compile_pattern may use realloc to grow the buffer space.
+
+ The number of bytes of commands can be found out by looking in
+ the `struct re_pattern_buffer' that bufp pointed to, after
+ re_compile_pattern returns. */
+
+char *
+re_compile_pattern(pattern, size, bufp)
+ const char *pattern;
+ int size;
+ struct re_pattern_buffer *bufp;
+{
+ register char *b = bufp->buffer;
+ register const char *p = pattern;
+ const char *nextp;
+ const char *pend = pattern + size;
+ register unsigned int c, c1 = 0;
+ const char *p0;
+ int numlen;
+#define ERROR_MSG_MAX_SIZE 200
+ static char error_msg[ERROR_MSG_MAX_SIZE+1];
+
+ /* Address of the count-byte of the most recently inserted `exactn'
+ command. This makes it possible to tell whether a new exact-match
+ character can be added to that command or requires a new `exactn'
+ command. */
+
+ char *pending_exact = 0;
+
+ /* Address of the place where a forward-jump should go to the end of
+ the containing expression. Each alternative of an `or', except the
+ last, ends with a forward-jump of this sort. */
+
+ char *fixup_alt_jump = 0;
+
+ /* Address of start of the most recently finished expression.
+ This tells postfix * where to find the start of its operand. */
+
+ char *laststart = 0;
+
+ /* In processing a repeat, 1 means zero matches is allowed. */
+
+ char zero_times_ok;
+
+ /* In processing a repeat, 1 means many matches is allowed. */
+
+ char many_times_ok;
+
+ /* In processing a repeat, 1 means non-greedy matches. */
+
+ char greedy;
+
+ /* Address of beginning of regexp, or inside of last (. */
+
+ char *begalt = b;
+
+ /* Place in the uncompiled pattern (i.e., the {) to
+ which to go back if the interval is invalid. */
+ const char *beg_interval;
+
+ /* In processing an interval, at least this many matches must be made. */
+ int lower_bound;
+
+ /* In processing an interval, at most this many matches can be made. */
+ int upper_bound;
+
+ /* Stack of information saved by ( and restored by ).
+ Five stack elements are pushed by each (:
+ First, the value of b.
+ Second, the value of fixup_alt_jump.
+ Third, the value of begalt.
+ Fourth, the value of regnum.
+ Fifth, the type of the paren. */
+
+ int stacka[40];
+ int *stackb = stacka;
+ int *stackp = stackb;
+ int *stacke = stackb + 40;
+
+ /* Counts ('s as they are encountered. Remembered for the matching ),
+ where it becomes the register number to put in the stop_memory
+ command. */
+
+ int regnum = 1;
+
+ int range = 0;
+ int had_mbchar = 0;
+ int had_num_literal = 0;
+ int had_char_class = 0;
+
+ int options = bufp->options;
+
+ bufp->fastmap_accurate = 0;
+ bufp->must = 0;
+ bufp->must_skip = 0;
+
+ /* Initialize the syntax table. */
+ init_syntax_once();
+
+ if (bufp->allocated == 0) {
+ bufp->allocated = INIT_BUF_SIZE;
+ /* EXTEND_BUFFER loses when bufp->allocated is 0. */
+ bufp->buffer = (char*)xrealloc(bufp->buffer, INIT_BUF_SIZE);
+ if (!bufp->buffer) goto memory_exhausted; /* this not happen */
+ begalt = b = bufp->buffer;
+ }
+
+ while (p != pend) {
+ PATFETCH(c);
+
+ switch (c) {
+ case '$':
+ if (bufp->options & RE_OPTION_SINGLELINE) {
+ BUFPUSH(endbuf);
+ }
+ else {
+ p0 = p;
+ /* When testing what follows the $,
+ look past the \-constructs that don't consume anything. */
+
+ while (p0 != pend) {
+ if (*p0 == '\\' && p0 + 1 != pend
+ && (p0[1] == 'b' || p0[1] == 'B'))
+ p0 += 2;
+ else
+ break;
+ }
+ BUFPUSH(endline);
+ }
+ break;
+
+ case '^':
+ if (bufp->options & RE_OPTION_SINGLELINE)
+ BUFPUSH(begbuf);
+ else
+ BUFPUSH(begline);
+ break;
+
+ case '+':
+ case '?':
+ case '*':
+ /* If there is no previous pattern, char not special. */
+ if (!laststart) {
+ snprintf(error_msg, ERROR_MSG_MAX_SIZE,
+ "invalid regular expression; there's no previous pattern, to which '%c' would define cardinality at %d",
+ c, p-pattern);
+ FREE_AND_RETURN(stackb, error_msg);
+ }
+ /* If there is a sequence of repetition chars,
+ collapse it down to just one. */
+ zero_times_ok = c != '+';
+ many_times_ok = c != '?';
+ greedy = 1;
+ if (p != pend) {
+ PATFETCH(c);
+ switch (c) {
+ case '?':
+ greedy = 0;
+ break;
+ case '*':
+ case '+':
+ goto nested_meta;
+ default:
+ PATUNFETCH;
+ break;
+ }
+ }
+
+ repeat:
+ /* Star, etc. applied to an empty pattern is equivalent
+ to an empty pattern. */
+ if (!laststart)
+ break;
+
+ if (greedy && many_times_ok && *laststart == anychar && b - laststart <= 2) {
+ if (b[-1] == stop_paren)
+ b--;
+ if (zero_times_ok)
+ *laststart = anychar_repeat;
+ else {
+ BUFPUSH(anychar_repeat);
+ }
+ break;
+ }
+ /* Now we know whether or not zero matches is allowed
+ and also whether or not two or more matches is allowed. */
+ if (many_times_ok) {
+ /* If more than one repetition is allowed, put in at the
+ end a backward relative jump from b to before the next
+ jump we're going to put in below (which jumps from
+ laststart to after this jump). */
+ GET_BUFFER_SPACE(3);
+ store_jump(b,greedy?maybe_finalize_jump:finalize_push,laststart-3);
+ b += 3; /* Because store_jump put stuff here. */
+ }
+
+ /* On failure, jump from laststart to next pattern, which will be the
+ end of the buffer after this jump is inserted. */
+ GET_BUFFER_SPACE(3);
+ insert_jump(on_failure_jump, laststart, b + 3, b);
+ b += 3;
+
+ if (zero_times_ok) {
+ if (greedy == 0) {
+ GET_BUFFER_SPACE(3);
+ insert_jump(try_next, laststart, b + 3, b);
+ b += 3;
+ }
+ }
+ else {
+ /* At least one repetition is required, so insert a
+ `dummy_failure_jump' before the initial
+ `on_failure_jump' instruction of the loop. This
+ effects a skip over that instruction the first time
+ we hit that loop. */
+ GET_BUFFER_SPACE(3);
+ insert_jump(dummy_failure_jump, laststart, laststart + 6, b);
+ b += 3;
+ }
+ break;
+
+ case '.':
+ laststart = b;
+ BUFPUSH(anychar);
+ break;
+
+ case '[':
+ if (p == pend)
+ FREE_AND_RETURN(stackb, "invalid regular expression; '[' can't be the last character ie. can't start range at the end of pattern");
+ while ((b - bufp->buffer + 9 + (1 << BYTEWIDTH) / BYTEWIDTH)
+ > bufp->allocated)
+ EXTEND_BUFFER;
+
+ laststart = b;
+ if (*p == '^') {
+ BUFPUSH(charset_not);
+ p++;
+ }
+ else
+ BUFPUSH(charset);
+ p0 = p;
+
+ BUFPUSH((1 << BYTEWIDTH) / BYTEWIDTH);
+ /* Clear the whole map */
+ memset(b, 0, (1 << BYTEWIDTH) / BYTEWIDTH + 2);
+
+ had_mbchar = 0;
+ had_num_literal = 0;
+ had_char_class = 0;
+
+ /* Read in characters and ranges, setting map bits. */
+ for (;;) {
+ int size;
+ unsigned last = (unsigned)-1;
+
+ if ((size = EXTRACT_UNSIGNED(&b[(1 << BYTEWIDTH) / BYTEWIDTH])) || current_mbctype) {
+ /* Ensure the space is enough to hold another interval
+ of multi-byte chars in charset(_not)?. */
+ size = (1 << BYTEWIDTH) / BYTEWIDTH + 2 + size*8 + 8;
+ while (b + size + 1 > bufp->buffer + bufp->allocated)
+ EXTEND_BUFFER;
+ }
+ range_retry:
+ if (range && had_char_class) {
+ FREE_AND_RETURN(stackb, "invalid regular expression; can't use character class as an end value of range");
+ }
+ PATFETCH_RAW(c);
+
+ if (c == ']') {
+ if (p == p0 + 1) {
+ if (p == pend)
+ FREE_AND_RETURN(stackb, "invalid regular expression; empty character class");
+ re_warning("character class has `]' without escape");
+ }
+ else
+ /* Stop if this isn't merely a ] inside a bracket
+ expression, but rather the end of a bracket
+ expression. */
+ break;
+ }
+ /* Look ahead to see if it's a range when the last thing
+ was a character class. */
+ if (had_char_class && c == '-' && *p != ']')
+ FREE_AND_RETURN(stackb, "invalid regular expression; can't use character class as a start value of range");
+ if (ismbchar(c)) {
+ PATFETCH_MBC(c);
+ had_mbchar++;
+ }
+ had_char_class = 0;
+
+ if (c == '-' && ((p != p0 + 1 && *p != ']') ||
+ (p[0] == '-' && p[1] != ']') ||
+ range))
+ re_warning("character class has `-' without escape");
+ if (c == '[' && *p != ':')
+ re_warning("character class has `[' without escape");
+
+ /* \ escapes characters when inside [...]. */
+ if (c == '\\') {
+ PATFETCH_RAW(c);
+ switch (c) {
+ case 'w':
+ for (c = 0; c < (1 << BYTEWIDTH); c++) {
+ if (SYNTAX(c) == Sword ||
+ (!current_mbctype && SYNTAX(c) == Sword2))
+ SET_LIST_BIT(c);
+ }
+ if (current_mbctype) {
+ set_list_bits(0x80, 0xffffffff, b);
+ }
+ had_char_class = 1;
+ last = -1;
+ continue;
+
+ case 'W':
+ for (c = 0; c < (1 << BYTEWIDTH); c++) {
+ if (SYNTAX(c) != Sword &&
+ ((current_mbctype && !re_mbctab[c]) ||
+ (!current_mbctype && SYNTAX(c) != Sword2)))
+ SET_LIST_BIT(c);
+ }
+ had_char_class = 1;
+ last = -1;
+ continue;
+
+ case 's':
+ for (c = 0; c < 256; c++)
+ if (ISSPACE(c))
+ SET_LIST_BIT(c);
+ had_char_class = 1;
+ last = -1;
+ continue;
+
+ case 'S':
+ for (c = 0; c < 256; c++)
+ if (!ISSPACE(c))
+ SET_LIST_BIT(c);
+ if (current_mbctype)
+ set_list_bits(0x80, 0xffffffff, b);
+ had_char_class = 1;
+ last = -1;
+ continue;
+
+ case 'd':
+ for (c = '0'; c <= '9'; c++)
+ SET_LIST_BIT(c);
+ had_char_class = 1;
+ last = -1;
+ continue;
+
+ case 'D':
+ for (c = 0; c < 256; c++)
+ if (!ISDIGIT(c))
+ SET_LIST_BIT(c);
+ if (current_mbctype)
+ set_list_bits(0x80, 0xffffffff, b);
+ had_char_class = 1;
+ last = -1;
+ continue;
+
+ case 'x':
+ c = scan_hex(p, 2, &numlen);
+ if (numlen == 0) goto invalid_escape;
+ p += numlen;
+ had_num_literal = 1;
+ break;
+
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ PATUNFETCH;
+ c = scan_oct(p, 3, &numlen);
+ p += numlen;
+ had_num_literal = 1;
+ break;
+
+ case 'M':
+ case 'C':
+ case 'c':
+ {
+ const char *pp;
+
+ --p;
+ c = read_special(p, pend, &pp);
+ if (c > 255) goto invalid_escape;
+ p = pp;
+ had_num_literal = 1;
+ }
+ break;
+
+ default:
+ c = read_backslash(c);
+ if (ismbchar(c)) {
+ PATFETCH_MBC(c);
+ had_mbchar++;
+ }
+ break;
+ }
+ }
+ else if (c == '[' && *p == ':') { /* [:...:] */
+ /* Leave room for the null. */
+ char str[CHAR_CLASS_MAX_LENGTH + 1];
+
+ PATFETCH_RAW(c);
+ c1 = 0;
+
+ /* If pattern is `[[:'. */
+ if (p == pend)
+ FREE_AND_RETURN(stackb, "invalid regular expression; re can't end '[[:'");
+
+ for (;;) {
+ PATFETCH_RAW(c);
+ if (c == ':' || c == ']' || p == pend
+ || c1 == CHAR_CLASS_MAX_LENGTH)
+ break;
+ str[c1++] = c;
+ }
+ str[c1] = '\0';
+
+ /* If isn't a word bracketed by `[:' and `:]':
+ undo the ending character, the letters, and
+ the leading `:' and `['. */
+ if (c == ':' && *p == ']') {
+ int ch;
+ char is_alnum = STREQ(str, "alnum");
+ char is_alpha = STREQ(str, "alpha");
+ char is_blank = STREQ(str, "blank");
+ char is_cntrl = STREQ(str, "cntrl");
+ char is_digit = STREQ(str, "digit");
+ char is_graph = STREQ(str, "graph");
+ char is_lower = STREQ(str, "lower");
+ char is_print = STREQ(str, "print");
+ char is_punct = STREQ(str, "punct");
+ char is_space = STREQ(str, "space");
+ char is_upper = STREQ(str, "upper");
+ char is_xdigit = STREQ(str, "xdigit");
+
+ if (!IS_CHAR_CLASS(str)){
+ snprintf(error_msg, ERROR_MSG_MAX_SIZE,
+ "invalid regular expression; [:%s:] is not a character class", str);
+ FREE_AND_RETURN(stackb, error_msg);
+ }
+
+ /* Throw away the ] at the end of the character class. */
+ PATFETCH(c);
+
+ if (p == pend)
+ FREE_AND_RETURN(stackb, "invalid regular expression; range doesn't have ending ']' after a character class");
+
+ for (ch = 0; ch < 1 << BYTEWIDTH; ch++) {
+ if ( (is_alnum && ISALNUM(ch))
+ || (is_alpha && ISALPHA(ch))
+ || (is_blank && ISBLANK(ch))
+ || (is_cntrl && ISCNTRL(ch))
+ || (is_digit && ISDIGIT(ch))
+ || (is_graph && ISGRAPH(ch))
+ || (is_lower && ISLOWER(ch))
+ || (is_print && ISPRINT(ch))
+ || (is_punct && ISPUNCT(ch))
+ || (is_space && ISSPACE(ch))
+ || (is_upper && ISUPPER(ch))
+ || (is_xdigit && ISXDIGIT(ch)))
+ SET_LIST_BIT(ch);
+ }
+ had_char_class = 1;
+ continue;
+ }
+ else {
+ c1 += 2;
+ while (c1--)
+ PATUNFETCH;
+ re_warning("character class has `[' without escape");
+ c = '[';
+ }
+ }
+
+ /* Get a range. */
+ if (range) {
+ if (last > c)
+ goto invalid_pattern;
+
+ range = 0;
+ if (had_mbchar == 0) {
+ if (TRANSLATE_P()) {
+ for (;last<=c;last++)
+ SET_LIST_BIT(translate[last]);
+ }
+ else {
+ for (;last<=c;last++)
+ SET_LIST_BIT(last);
+ }
+ }
+ else if (had_mbchar == 2) {
+ set_list_bits(last, c, b);
+ }
+ else {
+ /* restriction: range between sbc and mbc */
+ goto invalid_pattern;
+ }
+ }
+ else if (p[0] == '-' && p[1] != ']') {
+ last = c;
+ PATFETCH_RAW(c1);
+ range = 1;
+ goto range_retry;
+ }
+ else {
+ if (TRANSLATE_P() && c < 0x100) c = (unsigned char)translate[c];
+ if (had_mbchar == 0 && (!current_mbctype || !had_num_literal)) {
+ SET_LIST_BIT(c);
+ had_num_literal = 0;
+ }
+ else {
+ set_list_bits(c, c, b);
+ }
+ }
+ had_mbchar = 0;
+ }
+
+ /* Discard any character set/class bitmap bytes that are all
+ 0 at the end of the map. Decrement the map-length byte too. */
+ while ((int)b[-1] > 0 && b[b[-1] - 1] == 0)
+ b[-1]--;
+ if (b[-1] != (1 << BYTEWIDTH) / BYTEWIDTH)
+ memmove(&b[(unsigned char)b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH],
+ 2 + EXTRACT_UNSIGNED(&b[(1 << BYTEWIDTH) / BYTEWIDTH])*8);
+ b += b[-1] + 2 + EXTRACT_UNSIGNED(&b[(unsigned char)b[-1]])*8;
+ had_num_literal = 0;
+ break;
+
+ case '(':
+ {
+ int old_options = options;
+ int push_option = 0;
+ int casefold = 0;
+
+ PATFETCH(c);
+ if (c == '?') {
+ int negative = 0;
+
+ PATFETCH_RAW(c);
+ switch (c) {
+ case 'x': case 'm': case 'i': case '-':
+ for (;;) {
+ switch (c) {
+ case '-':
+ negative = 1;
+ break;
+
+ case ':':
+ case ')':
+ break;
+
+ case 'x':
+ if (negative)
+ options &= ~RE_OPTION_EXTENDED;
+ else
+ options |= RE_OPTION_EXTENDED;
+ break;
+
+ case 'm':
+ if (negative) {
+ if (options&RE_OPTION_MULTILINE) {
+ options &= ~RE_OPTION_MULTILINE;
+ }
+ }
+ else if (!(options&RE_OPTION_MULTILINE)) {
+ options |= RE_OPTION_MULTILINE;
+ }
+ push_option = 1;
+ break;
+
+ case 'i':
+ if (negative) {
+ if (options&RE_OPTION_IGNORECASE) {
+ options &= ~RE_OPTION_IGNORECASE;
+ }
+ }
+ else if (!(options&RE_OPTION_IGNORECASE)) {
+ options |= RE_OPTION_IGNORECASE;
+ }
+ casefold = 1;
+ break;
+
+ default:
+ FREE_AND_RETURN(stackb, "undefined (?...) inline option");
+ }
+ if (c == ')') {
+ c = '#'; /* read whole in-line options */
+ break;
+ }
+ if (c == ':') break;
+ PATFETCH_RAW(c);
+ }
+ break;
+
+ case '#':
+ for (;;) {
+ PATFETCH(c);
+ if (c == ')') break;
+ }
+ c = '#';
+ break;
+
+ case ':':
+ case '=':
+ case '!':
+ case '>':
+ break;
+
+ default:
+ FREE_AND_RETURN(stackb, "undefined (?...) sequence");
+ }
+ }
+ else {
+ PATUNFETCH;
+ c = '(';
+ }
+ if (c == '#') {
+ if (push_option) {
+ BUFPUSH(option_set);
+ BUFPUSH(options);
+ }
+ if (casefold) {
+ if (options & RE_OPTION_IGNORECASE)
+ BUFPUSH(casefold_on);
+ else
+ BUFPUSH(casefold_off);
+ }
+ break;
+ }
+ if (stackp+8 >= stacke) {
+ DOUBLE_STACK(int);
+ }
+
+ /* Laststart should point to the start_memory that we are about
+ to push (unless the pattern has RE_NREGS or more ('s). */
+ /* obsolete: now RE_NREGS is just a default register size. */
+ *stackp++ = b - bufp->buffer;
+ *stackp++ = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0;
+ *stackp++ = begalt - bufp->buffer;
+ switch (c) {
+ case '(':
+ BUFPUSH(start_memory);
+ BUFPUSH(regnum);
+ *stackp++ = regnum++;
+ *stackp++ = b - bufp->buffer;
+ BUFPUSH(0);
+ /* too many ()'s to fit in a byte. (max 254) */
+ if (regnum >= RE_REG_MAX) goto too_big;
+ break;
+
+ case '=':
+ case '!':
+ case '>':
+ BUFPUSH(start_nowidth);
+ *stackp++ = b - bufp->buffer;
+ BUFPUSH(0); /* temporary value */
+ BUFPUSH(0);
+ if (c != '!') break;
+
+ BUFPUSH(on_failure_jump);
+ *stackp++ = b - bufp->buffer;
+ BUFPUSH(0); /* temporary value */
+ BUFPUSH(0);
+ break;
+
+ case ':':
+ BUFPUSH(start_paren);
+ pending_exact = 0;
+ default:
+ break;
+ }
+ if (push_option) {
+ BUFPUSH(option_set);
+ BUFPUSH(options);
+ }
+ if (casefold) {
+ if (options & RE_OPTION_IGNORECASE)
+ BUFPUSH(casefold_on);
+ else
+ BUFPUSH(casefold_off);
+ }
+ *stackp++ = c;
+ *stackp++ = old_options;
+ fixup_alt_jump = 0;
+ laststart = 0;
+ begalt = b;
+ }
+ break;
+
+ case ')':
+ if (stackp == stackb)
+ FREE_AND_RETURN(stackb, "unmatched )");
+
+ pending_exact = 0;
+ if (fixup_alt_jump) {
+ /* Push a dummy failure point at the end of the
+ alternative for a possible future
+ `finalize_jump' to pop. See comments at
+ `push_dummy_failure' in `re_match'. */
+ BUFPUSH(push_dummy_failure);
+
+ /* We allocated space for this jump when we assigned
+ to `fixup_alt_jump', in the `handle_alt' case below. */
+ store_jump(fixup_alt_jump, jump, b);
+ }
+ if (options != stackp[-1]) {
+ if ((options ^ stackp[-1]) & RE_OPTION_IGNORECASE) {
+ BUFPUSH((options&RE_OPTION_IGNORECASE)?casefold_off:casefold_on);
+ }
+ if ((options ^ stackp[-1]) != RE_OPTION_IGNORECASE) {
+ BUFPUSH(option_set);
+ BUFPUSH(stackp[-1]);
+ }
+ }
+ p0 = b;
+ options = *--stackp;
+ switch (c = *--stackp) {
+ case '(':
+ {
+ char *loc = bufp->buffer + *--stackp;
+ *loc = regnum - stackp[-1];
+ BUFPUSH(stop_memory);
+ BUFPUSH(stackp[-1]);
+ BUFPUSH(regnum - stackp[-1]);
+ stackp--;
+ }
+ break;
+
+ case '!':
+ BUFPUSH(pop_and_fail);
+ /* back patch */
+ STORE_NUMBER(bufp->buffer+stackp[-1], b - bufp->buffer - stackp[-1] - 2);
+ stackp--;
+ /* fall through */
+ case '=':
+ BUFPUSH(stop_nowidth);
+ /* tell stack-pos place to start_nowidth */
+ STORE_NUMBER(bufp->buffer+stackp[-1], b - bufp->buffer - stackp[-1] - 2);
+ BUFPUSH(0); /* space to hold stack pos */
+ BUFPUSH(0);
+ stackp--;
+ break;
+
+ case '>':
+ BUFPUSH(stop_backtrack);
+ /* tell stack-pos place to start_nowidth */
+ STORE_NUMBER(bufp->buffer+stackp[-1], b - bufp->buffer - stackp[-1] - 2);
+ BUFPUSH(0); /* space to hold stack pos */
+ BUFPUSH(0);
+ stackp--;
+ break;
+
+ case ':':
+ BUFPUSH(stop_paren);
+ break;
+
+ default:
+ break;
+ }
+ begalt = *--stackp + bufp->buffer;
+ stackp--;
+ fixup_alt_jump = *stackp ? *stackp + bufp->buffer - 1 : 0;
+ laststart = *--stackp + bufp->buffer;
+ if (c == '!' || c == '=') laststart = b;
+ break;
+
+ case '|':
+ /* Insert before the previous alternative a jump which
+ jumps to this alternative if the former fails. */
+ GET_BUFFER_SPACE(3);
+ insert_jump(on_failure_jump, begalt, b + 6, b);
+ pending_exact = 0;
+ b += 3;
+ /* The alternative before this one has a jump after it
+ which gets executed if it gets matched. Adjust that
+ jump so it will jump to this alternative's analogous
+ jump (put in below, which in turn will jump to the next
+ (if any) alternative's such jump, etc.). The last such
+ jump jumps to the correct final destination. A picture:
+ _____ _____
+ | | | |
+ | v | v
+ a | b | c
+
+ If we are at `b', then fixup_alt_jump right now points to a
+ three-byte space after `a'. We'll put in the jump, set
+ fixup_alt_jump to right after `b', and leave behind three
+ bytes which we'll fill in when we get to after `c'. */
+
+ if (fixup_alt_jump)
+ store_jump(fixup_alt_jump, jump_past_alt, b);
+
+ /* Mark and leave space for a jump after this alternative,
+ to be filled in later either by next alternative or
+ when know we're at the end of a series of alternatives. */
+ fixup_alt_jump = b;
+ GET_BUFFER_SPACE(3);
+ b += 3;
+
+ laststart = 0;
+ begalt = b;
+ break;
+
+ case '{':
+ /* If there is no previous pattern, this is an invalid pattern. */
+ if (!laststart) {
+ snprintf(error_msg, ERROR_MSG_MAX_SIZE,
+ "invalid regular expression; there's no previous pattern, to which '{' would define cardinality at %d",
+ p-pattern);
+ FREE_AND_RETURN(stackb, error_msg);
+ }
+ if( p == pend)
+ FREE_AND_RETURN(stackb, "invalid regular expression; '{' can't be last character" );
+
+ beg_interval = p - 1;
+
+ lower_bound = -1; /* So can see if are set. */
+ upper_bound = -1;
+ GET_UNSIGNED_NUMBER(lower_bound);
+ if (c == ',') {
+ GET_UNSIGNED_NUMBER(upper_bound);
+ }
+ else
+ /* Interval such as `{1}' => match exactly once. */
+ upper_bound = lower_bound;
+
+ if (lower_bound < 0 || c != '}')
+ goto unfetch_interval;
+
+ if (lower_bound >= RE_DUP_MAX || upper_bound >= RE_DUP_MAX)
+ FREE_AND_RETURN(stackb, "too big quantifier in {,}");
+ if (upper_bound < 0) upper_bound = RE_DUP_MAX;
+ if (lower_bound > upper_bound)
+ FREE_AND_RETURN(stackb, "can't do {n,m} with n > m");
+
+ beg_interval = 0;
+ pending_exact = 0;
+
+ greedy = 1;
+ if (p != pend) {
+ PATFETCH(c);
+ if (c == '?') greedy = 0;
+ else PATUNFETCH;
+ }
+
+ if (lower_bound == 0) {
+ zero_times_ok = 1;
+ if (upper_bound == RE_DUP_MAX) {
+ many_times_ok = 1;
+ goto repeat;
+ }
+ if (upper_bound == 1) {
+ many_times_ok = 0;
+ goto repeat;
+ }
+ }
+ if (lower_bound == 1) {
+ if (upper_bound == 1) {
+ /* No need to repeat */
+ break;
+ }
+ if (upper_bound == RE_DUP_MAX) {
+ many_times_ok = 1;
+ zero_times_ok = 0;
+ goto repeat;
+ }
+ }
+
+ /* If upper_bound is zero, don't want to succeed at all;
+ jump from laststart to b + 3, which will be the end of
+ the buffer after this jump is inserted. */
+
+ if (upper_bound == 0) {
+ GET_BUFFER_SPACE(3);
+ insert_jump(jump, laststart, b + 3, b);
+ b += 3;
+ break;
+ }
+
+ /* If lower_bound == upper_bound, repeat count can be removed */
+ if (lower_bound == upper_bound) {
+ int mcnt;
+ int skip_stop_paren = 0;
+
+ if (b[-1] == stop_paren) {
+ skip_stop_paren = 1;
+ b--;
+ }
+
+ if (*laststart == exactn && laststart[1]+2 == b - laststart
+ && laststart[1]*lower_bound < 256) {
+ mcnt = laststart[1];
+ GET_BUFFER_SPACE((lower_bound-1)*mcnt);
+ laststart[1] = lower_bound*mcnt;
+ while (--lower_bound) {
+ memcpy(b, laststart+2, mcnt);
+ b += mcnt;
+ }
+ if (skip_stop_paren) BUFPUSH(stop_paren);
+ break;
+ }
+
+ if (lower_bound < 5 && b - laststart < 10) {
+ /* 5 and 10 are the magic numbers */
+
+ mcnt = b - laststart;
+ GET_BUFFER_SPACE((lower_bound-1)*mcnt);
+ while (--lower_bound) {
+ memcpy(b, laststart, mcnt);
+ b += mcnt;
+ }
+ if (skip_stop_paren) BUFPUSH(stop_paren);
+ break;
+ }
+ if (skip_stop_paren) b++; /* push back stop_paren */
+ }
+
+ /* Otherwise, we have a nontrivial interval. When
+ we're all done, the pattern will look like:
+ set_number_at <jump count> <upper bound>
+ set_number_at <succeed_n count> <lower bound>
+ succeed_n <after jump addr> <succed_n count>
+ <body of loop>
+ jump_n <succeed_n addr> <jump count>
+ (The upper bound and `jump_n' are omitted if
+ `upper_bound' is 1, though.) */
+ { /* If the upper bound is > 1, we need to insert
+ more at the end of the loop. */
+ unsigned nbytes = upper_bound == 1 ? 10 : 20;
+
+ GET_BUFFER_SPACE(nbytes);
+ /* Initialize lower bound of the `succeed_n', even
+ though it will be set during matching by its
+ attendant `set_number_at' (inserted next),
+ because `re_compile_fastmap' needs to know.
+ Jump to the `jump_n' we might insert below. */
+ insert_jump_n(succeed_n, laststart, b + (nbytes/2),
+ b, lower_bound);
+ b += 5; /* Just increment for the succeed_n here. */
+
+ /* Code to initialize the lower bound. Insert
+ before the `succeed_n'. The `5' is the last two
+ bytes of this `set_number_at', plus 3 bytes of
+ the following `succeed_n'. */
+ insert_op_2(set_number_at, laststart, b, 5, lower_bound);
+ b += 5;
+
+ if (upper_bound > 1) {
+ /* More than one repetition is allowed, so
+ append a backward jump to the `succeed_n'
+ that starts this interval.
+
+ When we've reached this during matching,
+ we'll have matched the interval once, so
+ jump back only `upper_bound - 1' times. */
+ GET_BUFFER_SPACE(5);
+ store_jump_n(b, greedy?jump_n:finalize_push_n, laststart + 5,
+ upper_bound - 1);
+ b += 5;
+
+ /* The location we want to set is the second
+ parameter of the `jump_n'; that is `b-2' as
+ an absolute address. `laststart' will be
+ the `set_number_at' we're about to insert;
+ `laststart+3' the number to set, the source
+ for the relative address. But we are
+ inserting into the middle of the pattern --
+ so everything is getting moved up by 5.
+ Conclusion: (b - 2) - (laststart + 3) + 5,
+ i.e., b - laststart.
+
+ We insert this at the beginning of the loop
+ so that if we fail during matching, we'll
+ reinitialize the bounds. */
+ insert_op_2(set_number_at, laststart, b, b - laststart,
+ upper_bound - 1);
+ b += 5;
+ }
+ }
+ break;
+
+ unfetch_interval:
+ /* If an invalid interval, match the characters as literals. */
+ re_warning("regexp has invalid interval");
+ p = beg_interval;
+ beg_interval = 0;
+
+ /* normal_char and normal_backslash need `c'. */
+ PATFETCH(c);
+ goto normal_char;
+
+ case '\\':
+ if (p == pend)
+ FREE_AND_RETURN(stackb, "invalid regular expression; '\\' can't be last character");
+ /* Do not translate the character after the \, so that we can
+ distinguish, e.g., \B from \b, even if we normally would
+ translate, e.g., B to b. */
+ PATFETCH_RAW(c);
+ switch (c) {
+ case 's':
+ case 'S':
+ case 'd':
+ case 'D':
+ while (b - bufp->buffer + 9 + (1 << BYTEWIDTH) / BYTEWIDTH
+ > bufp->allocated)
+ EXTEND_BUFFER;
+
+ laststart = b;
+ if (c == 's' || c == 'd') {
+ BUFPUSH(charset);
+ }
+ else {
+ BUFPUSH(charset_not);
+ }
+
+ BUFPUSH((1 << BYTEWIDTH) / BYTEWIDTH);
+ memset(b, 0, (1 << BYTEWIDTH) / BYTEWIDTH + 2);
+ if (c == 's' || c == 'S') {
+ SET_LIST_BIT(' ');
+ SET_LIST_BIT('\t');
+ SET_LIST_BIT('\n');
+ SET_LIST_BIT('\r');
+ SET_LIST_BIT('\f');
+ }
+ else {
+ char cc;
+
+ for (cc = '0'; cc <= '9'; cc++) {
+ SET_LIST_BIT(cc);
+ }
+ }
+
+ while ((int)b[-1] > 0 && b[b[-1] - 1] == 0)
+ b[-1]--;
+ if (b[-1] != (1 << BYTEWIDTH) / BYTEWIDTH)
+ memmove(&b[(unsigned char)b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH],
+ 2 + EXTRACT_UNSIGNED(&b[(1 << BYTEWIDTH) / BYTEWIDTH])*8);
+ b += b[-1] + 2 + EXTRACT_UNSIGNED(&b[(unsigned char)b[-1]])*8;
+ break;
+
+ case 'w':
+ laststart = b;
+ BUFPUSH(wordchar);
+ break;
+
+ case 'W':
+ laststart = b;
+ BUFPUSH(notwordchar);
+ break;
+
+#ifndef RUBY
+ case '<':
+ BUFPUSH(wordbeg);
+ break;
+
+ case '>':
+ BUFPUSH(wordend);
+ break;
+#endif
+
+ case 'b':
+ BUFPUSH(wordbound);
+ break;
+
+ case 'B':
+ BUFPUSH(notwordbound);
+ break;
+
+ case 'A':
+ BUFPUSH(begbuf);
+ break;
+
+ case 'Z':
+ if ((bufp->options & RE_OPTION_SINGLELINE) == 0) {
+ BUFPUSH(endbuf2);
+ break;
+ }
+ /* fall through */
+ case 'z':
+ BUFPUSH(endbuf);
+ break;
+
+ case 'G':
+ BUFPUSH(begpos);
+ break;
+
+ /* hex */
+ case 'x':
+ had_mbchar = 0;
+ c = scan_hex(p, 2, &numlen);
+ if (numlen == 0) goto invalid_escape;
+ p += numlen;
+ had_num_literal = 1;
+ goto numeric_char;
+
+ /* octal */
+ case '0':
+ had_mbchar = 0;
+ c = scan_oct(p, 2, &numlen);
+ p += numlen;
+ had_num_literal = 1;
+ goto numeric_char;
+
+ /* back-ref or octal */
+ case '1': case '2': case '3':
+ case '4': case '5': case '6':
+ case '7': case '8': case '9':
+ PATUNFETCH;
+ p0 = p;
+
+ had_mbchar = 0;
+ c1 = 0;
+ GET_UNSIGNED_NUMBER(c1);
+ if (!ISDIGIT(c)) PATUNFETCH;
+
+ if (9 < c1 && c1 >= regnum) {
+ /* need to get octal */
+ c = scan_oct(p0, 3, &numlen) & 0xff;
+ p = p0 + numlen;
+ c1 = 0;
+ had_num_literal = 1;
+ goto numeric_char;
+ }
+
+ laststart = b;
+ BUFPUSH(duplicate);
+ BUFPUSH(c1);
+ break;
+
+ case 'M':
+ case 'C':
+ case 'c':
+ p0 = --p;
+ c = read_special(p, pend, &p0);
+ if (c > 255) goto invalid_escape;
+ p = p0;
+ had_num_literal = 1;
+ goto numeric_char;
+
+ default:
+ c = read_backslash(c);
+ goto normal_char;
+ }
+ break;
+
+ case '#':
+ if (options & RE_OPTION_EXTENDED) {
+ while (p != pend) {
+ PATFETCH(c);
+ if (c == '\n') break;
+ }
+ break;
+ }
+ goto normal_char;
+
+ case ' ':
+ case '\t':
+ case '\f':
+ case '\r':
+ case '\n':
+ if (options & RE_OPTION_EXTENDED)
+ break;
+
+ default:
+ if (c == ']')
+ re_warning("regexp has `]' without escape");
+ else if (c == '}')
+ re_warning("regexp has `}' without escape");
+ normal_char: /* Expects the character in `c'. */
+ had_mbchar = 0;
+ if (ismbchar(c)) {
+ had_mbchar = 1;
+ c1 = p - pattern;
+ }
+ numeric_char:
+ nextp = p + mbclen(c) - 1;
+ if (!pending_exact || pending_exact + *pending_exact + 1 != b
+ || *pending_exact >= (c1 ? 0176 : 0177)
+ || (nextp < pend &&
+ ( *nextp == '+' || *nextp == '?'
+ || *nextp == '*' || *nextp == '^'
+ || *nextp == '{'))) {
+ laststart = b;
+ BUFPUSH(exactn);
+ pending_exact = b;
+ BUFPUSH(0);
+ }
+ if (had_num_literal || c == 0xff) {
+ BUFPUSH(0xff);
+ (*pending_exact)++;
+ had_num_literal = 0;
+ }
+ BUFPUSH(c);
+ (*pending_exact)++;
+ if (had_mbchar) {
+ int len = mbclen(c) - 1;
+ while (len--) {
+ PATFETCH_RAW(c);
+ BUFPUSH(c);
+ (*pending_exact)++;
+ }
+ }
+ }
+ }
+
+ if (fixup_alt_jump)
+ store_jump(fixup_alt_jump, jump, b);
+
+ if (stackp != stackb)
+ FREE_AND_RETURN(stackb, "unmatched (");
+
+ /* set optimize flags */
+ laststart = bufp->buffer;
+ if (laststart != b) {
+ if (*laststart == dummy_failure_jump) laststart += 3;
+ else if (*laststart == try_next) laststart += 3;
+ if (*laststart == anychar_repeat) {
+ bufp->options |= RE_OPTIMIZE_ANCHOR;
+ }
+ }
+
+ bufp->used = b - bufp->buffer;
+ bufp->re_nsub = regnum;
+ laststart = bufp->buffer;
+ if (laststart != b) {
+ if (*laststart == start_memory) laststart += 3;
+ if (*laststart == exactn) {
+ bufp->options |= RE_OPTIMIZE_EXACTN;
+ bufp->must = laststart+1;
+ }
+ }
+ if (!bufp->must) {
+ bufp->must = calculate_must_string(bufp->buffer, b);
+ }
+ if (current_mbctype == MBCTYPE_SJIS) bufp->options |= RE_OPTIMIZE_NO_BM;
+ else if (bufp->must) {
+ int i;
+ int len = (unsigned char)bufp->must[0];
+
+ for (i=1; i<len; i++) {
+ if ((unsigned char)bufp->must[i] == 0xff ||
+ (current_mbctype && ismbchar(bufp->must[i]))) {
+ bufp->options |= RE_OPTIMIZE_NO_BM;
+ break;
+ }
+ }
+ if (!(bufp->options & RE_OPTIMIZE_NO_BM)) {
+ bufp->must_skip = (int *) xmalloc((1 << BYTEWIDTH)*sizeof(int));
+ bm_init_skip(bufp->must_skip, (unsigned char*)bufp->must+1,
+ (unsigned char)bufp->must[0],
+ (unsigned char*)(MAY_TRANSLATE()?translate:0));
+ }
+ }
+
+ bufp->regstart = TMALLOC(regnum, unsigned char*);
+ bufp->regend = TMALLOC(regnum, unsigned char*);
+ bufp->old_regstart = TMALLOC(regnum, unsigned char*);
+ bufp->old_regend = TMALLOC(regnum, unsigned char*);
+ bufp->reg_info = TMALLOC(regnum, register_info_type);
+ bufp->best_regstart = TMALLOC(regnum, unsigned char*);
+ bufp->best_regend = TMALLOC(regnum, unsigned char*);
+ FREE_AND_RETURN(stackb, 0);
+
+ invalid_pattern:
+ FREE_AND_RETURN(stackb, "invalid regular expression");
+
+ end_of_pattern:
+ FREE_AND_RETURN(stackb, "premature end of regular expression");
+
+ too_big:
+ FREE_AND_RETURN(stackb, "regular expression too big");
+
+ memory_exhausted:
+ FREE_AND_RETURN(stackb, "memory exhausted");
+
+ nested_meta:
+ FREE_AND_RETURN(stackb, "nested *?+ in regexp");
+
+ invalid_escape:
+ FREE_AND_RETURN(stackb, "Invalid escape character syntax");
+}
+
+void
+re_free_pattern(bufp)
+ struct re_pattern_buffer *bufp;
+{
+ xfree(bufp->buffer);
+ xfree(bufp->fastmap);
+ if (bufp->must_skip) xfree(bufp->must_skip);
+
+ xfree(bufp->regstart);
+ xfree(bufp->regend);
+ xfree(bufp->old_regstart);
+ xfree(bufp->old_regend);
+ xfree(bufp->best_regstart);
+ xfree(bufp->best_regend);
+ xfree(bufp->reg_info);
+ xfree(bufp);
+}
+
+/* Store a jump of the form <OPCODE> <relative address>.
+ Store in the location FROM a jump operation to jump to relative
+ address FROM - TO. OPCODE is the opcode to store. */
+
+static void
+store_jump(from, opcode, to)
+ char *from, *to;
+ int opcode;
+{
+ from[0] = (char)opcode;
+ STORE_NUMBER(from + 1, to - (from + 3));
+}
+
+
+/* Open up space before char FROM, and insert there a jump to TO.
+ CURRENT_END gives the end of the storage not in use, so we know
+ how much data to copy up. OP is the opcode of the jump to insert.
+
+ If you call this function, you must zero out pending_exact. */
+
+static void
+insert_jump(op, from, to, current_end)
+ int op;
+ char *from, *to, *current_end;
+{
+ register char *pfrom = current_end; /* Copy from here... */
+ register char *pto = current_end + 3; /* ...to here. */
+
+ while (pfrom != from)
+ *--pto = *--pfrom;
+ store_jump(from, op, to);
+}
+
+
+/* Store a jump of the form <opcode> <relative address> <n> .
+
+ Store in the location FROM a jump operation to jump to relative
+ address FROM - TO. OPCODE is the opcode to store, N is a number the
+ jump uses, say, to decide how many times to jump.
+
+ If you call this function, you must zero out pending_exact. */
+
+static void
+store_jump_n(from, opcode, to, n)
+ char *from, *to;
+ int opcode;
+ unsigned n;
+{
+ from[0] = (char)opcode;
+ STORE_NUMBER(from + 1, to - (from + 3));
+ STORE_NUMBER(from + 3, n);
+}
+
+
+/* Similar to insert_jump, but handles a jump which needs an extra
+ number to handle minimum and maximum cases. Open up space at
+ location FROM, and insert there a jump to TO. CURRENT_END gives the
+ end of the storage in use, so we know how much data to copy up. OP is
+ the opcode of the jump to insert.
+
+ If you call this function, you must zero out pending_exact. */
+
+static void
+insert_jump_n(op, from, to, current_end, n)
+ int op;
+ char *from, *to, *current_end;
+ unsigned n;
+{
+ register char *pfrom = current_end; /* Copy from here... */
+ register char *pto = current_end + 5; /* ...to here. */
+
+ while (pfrom != from)
+ *--pto = *--pfrom;
+ store_jump_n(from, op, to, n);
+}
+
+
+/* Open up space at location THERE, and insert operation OP.
+ CURRENT_END gives the end of the storage in use, so
+ we know how much data to copy up.
+
+ If you call this function, you must zero out pending_exact. */
+
+static void
+insert_op(op, there, current_end)
+ int op;
+ char *there, *current_end;
+{
+ register char *pfrom = current_end; /* Copy from here... */
+ register char *pto = current_end + 1; /* ...to here. */
+
+ while (pfrom != there)
+ *--pto = *--pfrom;
+
+ there[0] = (char)op;
+}
+
+
+/* Open up space at location THERE, and insert operation OP followed by
+ NUM_1 and NUM_2. CURRENT_END gives the end of the storage in use, so
+ we know how much data to copy up.
+
+ If you call this function, you must zero out pending_exact. */
+
+static void
+insert_op_2(op, there, current_end, num_1, num_2)
+ int op;
+ char *there, *current_end;
+ int num_1, num_2;
+{
+ register char *pfrom = current_end; /* Copy from here... */
+ register char *pto = current_end + 5; /* ...to here. */
+
+ while (pfrom != there)
+ *--pto = *--pfrom;
+
+ there[0] = (char)op;
+ STORE_NUMBER(there + 1, num_1);
+ STORE_NUMBER(there + 3, num_2);
+}
+
+
+#define trans_eq(c1, c2, translate) (translate?(translate[c1]==translate[c2]):((c1)==(c2)))
+static int
+slow_match(little, lend, big, bend, translate)
+ const unsigned char *little, *lend;
+ const unsigned char *big, *bend;
+ const unsigned char *translate;
+{
+ int c;
+
+ while (little < lend && big < bend) {
+ c = *little++;
+ if (c == 0xff)
+ c = *little++;
+ if (!trans_eq(*big++, c, translate)) break;
+ }
+ if (little == lend) return 1;
+ return 0;
+}
+
+static int
+slow_search(little, llen, big, blen, translate)
+ const unsigned char *little;
+ int llen;
+ const unsigned char *big;
+ int blen;
+ const char *translate;
+{
+ const unsigned char *bsave = big;
+ const unsigned char *bend = big + blen;
+ register int c;
+ int fescape = 0;
+
+ c = *little;
+ if (c == 0xff) {
+ c = little[1];
+ fescape = 1;
+ }
+ else if (translate && !ismbchar(c)) {
+ c = translate[c];
+ }
+
+ while (big < bend) {
+ /* look for first character */
+ if (fescape) {
+ while (big < bend) {
+ if (*big == c) break;
+ big++;
+ }
+ }
+ else if (translate && !ismbchar(c)) {
+ while (big < bend) {
+ if (ismbchar(*big)) big+=mbclen(*big)-1;
+ else if (translate[*big] == c) break;
+ big++;
+ }
+ }
+ else {
+ while (big < bend) {
+ if (*big == c) break;
+ if (ismbchar(*big)) big+=mbclen(*big)-1;
+ big++;
+ }
+ }
+
+ if (slow_match(little, little+llen, big, bend, (unsigned char *)translate))
+ return big - bsave;
+
+ big+=mbclen(*big);
+ }
+ return -1;
+}
+
+static void
+bm_init_skip(skip, pat, m, translate)
+ int *skip;
+ unsigned char *pat;
+ int m;
+ const unsigned char *translate;
+{
+ int j, c;
+
+ for (c=0; c<256; c++) {
+ skip[c] = m;
+ }
+ if (translate) {
+ for (j=0; j<m-1; j++) {
+ skip[translate[pat[j]]] = m-1-j;
+ }
+ }
+ else {
+ for (j=0; j<m-1; j++) {
+ skip[pat[j]] = m-1-j;
+ }
+ }
+}
+
+static int
+bm_search(little, llen, big, blen, skip, translate)
+ const unsigned char *little;
+ int llen;
+ const unsigned char *big;
+ int blen;
+ int *skip;
+ const unsigned char *translate;
+{
+ int i, j, k;
+
+ i = llen-1;
+ if (translate) {
+ while (i < blen) {
+ k = i;
+ j = llen-1;
+ while (j >= 0 && translate[big[k]] == translate[little[j]]) {
+ k--;
+ j--;
+ }
+ if (j < 0) return k+1;
+
+ i += skip[translate[big[i]]];
+ }
+ return -1;
+ }
+ while (i < blen) {
+ k = i;
+ j = llen-1;
+ while (j >= 0 && big[k] == little[j]) {
+ k--;
+ j--;
+ }
+ if (j < 0) return k+1;
+
+ i += skip[big[i]];
+ }
+ return -1;
+}
+
+/* Given a pattern, compute a fastmap from it. The fastmap records
+ which of the (1 << BYTEWIDTH) possible characters can start a string
+ that matches the pattern. This fastmap is used by re_search to skip
+ quickly over totally implausible text.
+
+ 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)
+ struct re_pattern_buffer *bufp;
+{
+ unsigned char *pattern = (unsigned char*)bufp->buffer;
+ int size = bufp->used;
+ register char *fastmap = bufp->fastmap;
+ register unsigned char *p = pattern;
+ register unsigned char *pend = pattern + size;
+ register int j, k;
+ unsigned is_a_succeed_n;
+
+
+ unsigned char *stacka[NFAILURES];
+ unsigned char **stackb = stacka;
+ unsigned char **stackp = stackb;
+ unsigned char **stacke = stackb + NFAILURES;
+ int options = bufp->options;
+
+ memset(fastmap, 0, (1 << BYTEWIDTH));
+ bufp->fastmap_accurate = 1;
+ bufp->can_be_null = 0;
+
+ while (p) {
+ is_a_succeed_n = 0;
+ if (p == pend) {
+ bufp->can_be_null = 1;
+ break;
+ }
+#ifdef SWITCH_ENUM_BUG
+ switch ((int)((enum regexpcode)*p++))
+#else
+ switch ((enum regexpcode)*p++)
+#endif
+ {
+ case exactn:
+ if (p[1] == 0xff) {
+ if (TRANSLATE_P())
+ fastmap[translate[p[2]]] = 2;
+ else
+ fastmap[p[2]] = 2;
+ bufp->options |= RE_OPTIMIZE_BMATCH;
+ }
+ else if (TRANSLATE_P())
+ fastmap[translate[p[1]]] = 1;
+ else
+ fastmap[p[1]] = 1;
+ break;
+
+ case begline:
+ case begbuf:
+ case begpos:
+ case endbuf:
+ case endbuf2:
+ case wordbound:
+ case notwordbound:
+ case wordbeg:
+ case wordend:
+ case pop_and_fail:
+ case push_dummy_failure:
+ case start_paren:
+ case stop_paren:
+ continue;
+
+ case casefold_on:
+ bufp->options |= RE_MAY_IGNORECASE;
+ options |= RE_OPTION_IGNORECASE;
+ continue;
+
+ case casefold_off:
+ options &= ~RE_OPTION_IGNORECASE;
+ continue;
+
+ case option_set:
+ options = *p++;
+ continue;
+
+ case endline:
+ if (TRANSLATE_P())
+ fastmap[translate['\n']] = 1;
+ else
+ fastmap['\n'] = 1;
+ if ((options & RE_OPTION_SINGLELINE) == 0 && bufp->can_be_null == 0)
+ bufp->can_be_null = 2;
+ break;
+
+ case jump_n:
+ case finalize_jump:
+ case maybe_finalize_jump:
+ case jump:
+ case jump_past_alt:
+ case dummy_failure_jump:
+ case finalize_push:
+ case finalize_push_n:
+ EXTRACT_NUMBER_AND_INCR(j, p);
+ p += j;
+ if (j > 0)
+ continue;
+ /* Jump backward reached implies we just went through
+ the body of a loop and matched nothing.
+ Opcode jumped to should be an on_failure_jump.
+ Just treat it like an ordinary jump.
+ For a * loop, it has pushed its failure point already;
+ If so, discard that as redundant. */
+
+ if ((enum regexpcode)*p != on_failure_jump
+ && (enum regexpcode)*p != try_next
+ && (enum regexpcode)*p != succeed_n)
+ continue;
+ p++;
+ EXTRACT_NUMBER_AND_INCR(j, p);
+ p += j;
+ if (stackp != stackb && *stackp == p)
+ stackp--; /* pop */
+ continue;
+
+ case try_next:
+ case start_nowidth:
+ case stop_nowidth:
+ case stop_backtrack:
+ p += 2;
+ continue;
+
+ case succeed_n:
+ is_a_succeed_n = 1;
+ /* Get to the number of times to succeed. */
+ EXTRACT_NUMBER(k, p + 2);
+ /* Increment p past the n for when k != 0. */
+ if (k != 0) {
+ p += 4;
+ continue;
+ }
+ /* fall through */
+
+ case on_failure_jump:
+ EXTRACT_NUMBER_AND_INCR(j, p);
+ if (p + j < pend) {
+ if (stackp == stacke) {
+ EXPAND_FAIL_STACK();
+ }
+ *++stackp = p + j; /* push */
+ }
+ else {
+ bufp->can_be_null = 1;
+ }
+ if (is_a_succeed_n)
+ EXTRACT_NUMBER_AND_INCR(k, p); /* Skip the n. */
+ continue;
+
+ case set_number_at:
+ p += 4;
+ continue;
+
+ case start_memory:
+ case stop_memory:
+ p += 2;
+ continue;
+
+ case duplicate:
+ bufp->can_be_null = 1;
+ if (*p >= bufp->re_nsub) break;
+ fastmap['\n'] = 1;
+ case anychar_repeat:
+ case anychar:
+ for (j = 0; j < (1 << BYTEWIDTH); j++) {
+ if (j != '\n' || (options & RE_OPTION_MULTILINE))
+ fastmap[j] = 1;
+ }
+ if (bufp->can_be_null) {
+ FREE_AND_RETURN(stackb, 0);
+ }
+ /* Don't return; check the alternative paths
+ so we can set can_be_null if appropriate. */
+ if ((enum regexpcode)p[-1] == anychar_repeat) {
+ continue;
+ }
+ break;
+
+ case wordchar:
+ for (j = 0; j < 0x80; j++) {
+ if (SYNTAX(j) == Sword)
+ fastmap[j] = 1;
+ }
+ switch (current_mbctype) {
+ case MBCTYPE_ASCII:
+ for (j = 0x80; j < (1 << BYTEWIDTH); j++) {
+ if (SYNTAX(j) == Sword2)
+ fastmap[j] = 1;
+ }
+ break;
+ case MBCTYPE_EUC:
+ case MBCTYPE_SJIS:
+ case MBCTYPE_UTF8:
+ for (j = 0x80; j < (1 << BYTEWIDTH); j++) {
+ if (re_mbctab[j])
+ fastmap[j] = 1;
+ }
+ break;
+ }
+ break;
+
+ case notwordchar:
+ for (j = 0; j < 0x80; j++)
+ if (SYNTAX(j) != Sword)
+ fastmap[j] = 1;
+ switch (current_mbctype) {
+ case MBCTYPE_ASCII:
+ for (j = 0x80; j < (1 << BYTEWIDTH); j++) {
+ if (SYNTAX(j) != Sword2)
+ fastmap[j] = 1;
+ }
+ break;
+ case MBCTYPE_EUC:
+ case MBCTYPE_SJIS:
+ case MBCTYPE_UTF8:
+ for (j = 0x80; j < (1 << BYTEWIDTH); j++) {
+ if (!re_mbctab[j])
+ fastmap[j] = 1;
+ }
+ break;
+ }
+ break;
+
+ case charset:
+ /* NOTE: Charset for single-byte chars never contain
+ multi-byte char. See set_list_bits(). */
+ for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
+ if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) {
+ int tmp = TRANSLATE_P()?translate[j]:j;
+ fastmap[tmp] = 1;
+ }
+ {
+ unsigned short size;
+ unsigned long c, beg, end;
+
+ p += p[-1] + 2;
+ size = EXTRACT_UNSIGNED(&p[-2]);
+ for (j = 0; j < (int)size; j++) {
+ c = EXTRACT_MBC(&p[j*8]);
+ beg = WC2MBC1ST(c);
+ c = EXTRACT_MBC(&p[j*8+4]);
+ end = WC2MBC1ST(c);
+ /* set bits for 1st bytes of multi-byte chars. */
+ while (beg <= end) {
+ /* NOTE: Charset for multi-byte chars might contain
+ single-byte chars. We must reject them. */
+ if (c < 0x100) {
+ fastmap[beg] = 2;
+ bufp->options |= RE_OPTIMIZE_BMATCH;
+ }
+ else if (ismbchar(beg))
+ fastmap[beg] = 1;
+ beg++;
+ }
+ }
+ }
+ break;
+
+ case charset_not:
+ /* S: set of all single-byte chars.
+ M: set of all first bytes that can start multi-byte chars.
+ s: any set of single-byte chars.
+ m: any set of first bytes that can start multi-byte chars.
+
+ We assume S+M = U.
+ ___ _ _
+ s+m = (S*s+M*m). */
+ /* Chars beyond end of map must be allowed */
+ /* NOTE: Charset_not for single-byte chars might contain
+ multi-byte chars. See set_list_bits(). */
+ for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++)
+ if (!ismbchar(j))
+ fastmap[j] = 1;
+
+ for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
+ if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) {
+ if (!ismbchar(j))
+ fastmap[j] = 1;
+ }
+ {
+ unsigned short size;
+ unsigned long c, beg;
+ int num_literal = 0;
+
+ p += p[-1] + 2;
+ size = EXTRACT_UNSIGNED(&p[-2]);
+ if (size == 0) {
+ for (j = 0x80; j < (1 << BYTEWIDTH); j++)
+ if (ismbchar(j))
+ fastmap[j] = 1;
+ break;
+ }
+ for (j = 0,c = 0;j < (int)size; j++) {
+ unsigned int cc = EXTRACT_MBC(&p[j*8]);
+ beg = WC2MBC1ST(cc);
+ while (c <= beg) {
+ if (ismbchar(c))
+ fastmap[c] = 1;
+ c++;
+ }
+
+ cc = EXTRACT_MBC(&p[j*8+4]);
+ if (cc < 0xff) {
+ num_literal = 1;
+ while (c <= cc) {
+ if (ismbchar(c))
+ fastmap[c] = 1;
+ c++;
+ }
+ }
+ c = WC2MBC1ST(cc);
+ }
+
+ for (j = c; j < (1 << BYTEWIDTH); j++) {
+ if (num_literal)
+ fastmap[j] = 1;
+ if (ismbchar(j))
+ fastmap[j] = 1;
+ }
+ }
+ break;
+
+ case unused: /* pacify gcc -Wall */
+ break;
+ }
+
+ /* Get here means we have successfully found the possible starting
+ characters of one path of the pattern. We need not follow this
+ path any farther. Instead, look at the next alternative
+ remembered in the stack. */
+ if (stackp != stackb)
+ p = *stackp--; /* pop */
+ 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);
+}
+
+/* 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;
+ int 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;
+ }
+
+ /* Adjust startpos for mbc string */
+ if (current_mbctype && startpos>0 && !(bufp->options&RE_OPTIMIZE_BMATCH)) {
+ startpos = re_mbc_startpos(string, size, startpos, range);
+ }
+ return startpos;
+}
+
+
+static int re_match_exec _((struct re_pattern_buffer *, const char *, int, int, int,
+ struct re_registers *));
+
+/* Using the compiled pattern in BUFP->buffer, first tries to match
+ STRING, starting first at index STARTPOS, then at STARTPOS + 1, and
+ so on. RANGE is the number of places to try before giving up. If
+ RANGE is negative, it searches backwards, i.e., the starting
+ positions tried are STARTPOS, STARTPOS - 1, etc. STRING is of SIZE.
+ In REGS, return the indices of STRING that matched the entire
+ BUFP->buffer and its contained subexpressions.
+
+ The value returned is the position in the strings at which the match
+ was found, or -1 if no match was found, or -2 if error (such as
+ failure stack overflow). */
+
+int
+re_search(bufp, string, size, startpos, range, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string;
+ int size, startpos, range;
+ struct re_registers *regs;
+{
+ register char *fastmap = bufp->fastmap;
+ int val, anchor = 0, initpos = startpos;
+
+ /* 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;
+ }
+
+
+ /* If the search isn't to be a backwards one, don't waste time in a
+ search for a pattern that must be anchored. */
+ if (bufp->used > 0) {
+ switch ((enum regexpcode)bufp->buffer[0]) {
+ case begbuf:
+ begbuf_match:
+ if (range > 0) {
+ if (startpos > 0) return -1;
+ else {
+ val = re_match(bufp, string, size, 0, regs);
+ if (val >= 0) return 0;
+ return val;
+ }
+ }
+ break;
+
+ case begline:
+ anchor = 1;
+ break;
+
+ case begpos:
+ val = re_match(bufp, string, size, startpos, regs);
+ if (val >= 0) return startpos;
+ return val;
+
+ default:
+ break;
+ }
+ }
+ if (bufp->options & RE_OPTIMIZE_ANCHOR) {
+ if (bufp->options&RE_OPTION_MULTILINE && range > 0) {
+ goto begbuf_match;
+ }
+ anchor = 1;
+ }
+
+ if (bufp->must) {
+ int len = ((unsigned char*)bufp->must)[0];
+ int pos, pbeg, pend;
+
+ pbeg = startpos;
+ pend = startpos + range;
+ if (pbeg > pend) { /* swap pbeg,pend */
+ pos = pend; pend = pbeg; pbeg = pos;
+ }
+ pend = size;
+ if (bufp->options & RE_OPTIMIZE_NO_BM) {
+ pos = slow_search((unsigned char *)(bufp->must+1), len,
+ (unsigned char*)(string+pbeg), pend-pbeg,
+ (char *)(MAY_TRANSLATE()?translate:0));
+ }
+ else {
+ pos = bm_search((unsigned char *)(bufp->must+1), len,
+ (unsigned char *)(string+pbeg), pend-pbeg,
+ bufp->must_skip,
+ MAY_TRANSLATE()?translate:0);
+ }
+ if (pos == -1) return -1;
+ if (range > 0 && (bufp->options & RE_OPTIMIZE_EXACTN)) {
+ startpos += pos;
+ range -= pos;
+ if (range < 0) return -1;
+ }
+ }
+
+ for (;;) {
+ /* If a fastmap is supplied, skip quickly over characters that
+ cannot possibly be the start of a match. Note, however, that
+ if the pattern can possibly match the null string, we must
+ test it at each starting point so that we take the first null
+ string we get. */
+
+ if (fastmap && startpos < size
+ && bufp->can_be_null != 1 && !(anchor && startpos == 0)) {
+ if (range > 0) { /* Searching forwards. */
+ register unsigned char *p, c;
+ int irange = range;
+
+ p = (unsigned char*)string+startpos;
+
+ while (range > 0) {
+ c = *p++;
+ if (ismbchar(c)) {
+ int len;
+
+ if (fastmap[c])
+ break;
+ len = mbclen(c) - 1;
+ while (len--) {
+ c = *p++;
+ range--;
+ if (fastmap[c] == 2)
+ goto startpos_adjust;
+ }
+ }
+ else {
+ if (fastmap[MAY_TRANSLATE() ? translate[c] : c])
+ break;
+ }
+ range--;
+ }
+ startpos_adjust:
+ startpos += irange - range;
+ }
+ else { /* Searching backwards. */
+ register unsigned char c;
+
+ c = string[startpos];
+ c &= 0xff;
+ if (MAY_TRANSLATE() ? !fastmap[translate[c]] : !fastmap[c])
+ goto advance;
+ }
+ }
+
+ if (startpos > size) return -1;
+ if ((anchor || !bufp->can_be_null) && range > 0 && size > 0 && startpos == size)
+ return -1;
+ val = re_match_exec(bufp, string, size, startpos, initpos, regs);
+ if (val >= 0) return startpos;
+ if (val == -2) return -2;
+
+#ifndef NO_ALLOCA
+#ifdef C_ALLOCA
+ alloca(0);
+#endif /* C_ALLOCA */
+#endif /* NO_ALLOCA */
+
+ if (range > 0) {
+ if (anchor && startpos < size &&
+ (startpos < 1 || string[startpos-1] != '\n')) {
+ while (range > 0 && string[startpos] != '\n') {
+ range--;
+ startpos++;
+ }
+ }
+ }
+
+ advance:
+ if (!range)
+ break;
+ else if (range > 0) {
+ const char *d = string + startpos;
+
+ if (ismbchar(*d)) {
+ int len = mbclen(*d) - 1;
+ range-=len, startpos+=len;
+ if (!range)
+ break;
+ }
+ range--, startpos++;
+ }
+ else {
+ range++, startpos--;
+ {
+ const char *s, *d, *p;
+
+ s = string; d = string + startpos;
+ for (p = d; p-- > s && ismbchar(*p); )
+ /* --p >= s would not work on 80[12]?86.
+ (when the offset of s equals 0 other than huge model.) */
+ ;
+ if (!((d - p) & 1)) {
+ if (!range)
+ break;
+ range++, startpos--;
+ }
+ }
+ }
+ }
+ return -1;
+}
+
+
+
+
+/* The following are used for re_match, defined below: */
+
+/* Accessing macros used in re_match: */
+
+#define IS_ACTIVE(R) ((R).bits.is_active)
+#define MATCHED_SOMETHING(R) ((R).bits.matched_something)
+
+
+/* Macros used by re_match: */
+
+/* I.e., regstart, regend, and reg_info. */
+#define NUM_REG_ITEMS 3
+
+/* I.e., ptr and count. */
+#define NUM_COUNT_ITEMS 2
+
+/* Individual items aside from the registers. */
+#define NUM_NONREG_ITEMS 4
+
+/* We push at most this many things on the stack whenever we
+ fail. The `+ 2' refers to PATTERN_PLACE and STRING_PLACE, which are
+ arguments to the PUSH_FAILURE_POINT macro. */
+#define MAX_NUM_FAILURE_ITEMS (num_regs * NUM_REG_ITEMS + NUM_NONREG_ITEMS)
+
+/* We push this many things on the stack whenever we fail. */
+#define NUM_FAILURE_ITEMS (last_used_reg * NUM_REG_ITEMS + NUM_NONREG_ITEMS + 1)
+
+/* This pushes counter information for succeed_n and jump_n */
+#define PUSH_FAILURE_COUNT(ptr) \
+ do { \
+ int c; \
+ EXTRACT_NUMBER(c, ptr); \
+ ENSURE_FAIL_STACK(NUM_COUNT_ITEMS); \
+ *stackp++ = (unsigned char*)(long)c; \
+ *stackp++ = (ptr); \
+ num_failure_counts++; \
+ } while (0)
+
+/* This pushes most of the information about the current state we will want
+ if we ever fail back to it. */
+
+#define PUSH_FAILURE_POINT(pattern_place, string_place) \
+ do { \
+ long last_used_reg, this_reg; \
+ \
+ /* Find out how many registers are active or have been matched. \
+ (Aside from register zero, which is only set at the end.) */ \
+ for (last_used_reg = num_regs-1; last_used_reg > 0; last_used_reg--)\
+ if (!REG_UNSET(regstart[last_used_reg])) \
+ break; \
+ \
+ ENSURE_FAIL_STACK(NUM_FAILURE_ITEMS); \
+ *stackp++ = (unsigned char*)(long)num_failure_counts; \
+ num_failure_counts = 0; \
+ \
+ /* Now push the info for each of those registers. */ \
+ for (this_reg = 1; this_reg <= last_used_reg; this_reg++) { \
+ *stackp++ = regstart[this_reg]; \
+ *stackp++ = regend[this_reg]; \
+ *stackp++ = reg_info[this_reg].word; \
+ } \
+ \
+ /* Push how many registers we saved. */ \
+ *stackp++ = (unsigned char*)last_used_reg; \
+ \
+ *stackp++ = pattern_place; \
+ *stackp++ = string_place; \
+ *stackp++ = (unsigned char*)(long)options; /* current option status */ \
+ *stackp++ = (unsigned char*)0; /* non-greedy flag */ \
+ } while(0)
+
+#define NON_GREEDY ((unsigned char*)1)
+
+#define POP_FAILURE_COUNT() \
+ do { \
+ unsigned char *ptr = *--stackp; \
+ int count = (long)*--stackp; \
+ STORE_NUMBER(ptr, count); \
+ } while (0)
+
+/* This pops what PUSH_FAILURE_POINT pushes. */
+
+#define POP_FAILURE_POINT() \
+ do { \
+ long temp; \
+ stackp -= NUM_NONREG_ITEMS; /* Remove failure points (and flag). */ \
+ temp = (long)*--stackp; /* How many regs pushed. */ \
+ temp *= NUM_REG_ITEMS; /* How much to take off the stack. */ \
+ stackp -= temp; /* Remove the register info. */ \
+ temp = (long)*--stackp; /* How many counters pushed. */ \
+ while (temp--) { \
+ POP_FAILURE_COUNT(); /* Remove the counter info. */ \
+ } \
+ num_failure_counts = 0; /* Reset num_failure_counts. */ \
+ } while(0)
+
+ /* Registers are set to a sentinel when they haven't yet matched. */
+#define REG_UNSET_VALUE ((unsigned char*)-1)
+#define REG_UNSET(e) ((e) == REG_UNSET_VALUE)
+
+#define PREFETCH if (d == dend) goto fail
+
+ /* Call this when have matched something; it sets `matched' flags for the
+ registers corresponding to the subexpressions of which we currently
+ are inside. */
+#define SET_REGS_MATCHED \
+ do { unsigned this_reg; \
+ for (this_reg = 0; this_reg < num_regs; this_reg++) { \
+ if (IS_ACTIVE(reg_info[this_reg])) \
+ MATCHED_SOMETHING(reg_info[this_reg]) = 1; \
+ else \
+ MATCHED_SOMETHING(reg_info[this_reg]) = 0; \
+ } \
+ } while(0)
+
+#define AT_STRINGS_BEG(d) ((d) == string)
+#define AT_STRINGS_END(d) ((d) == dend)
+
+#define IS_A_LETTER(d) (SYNTAX(*(d)) == Sword || \
+ (current_mbctype ? \
+ (re_mbctab[*(d)] && ((d)+mbclen(*(d)))<=dend): \
+ SYNTAX(*(d)) == Sword2))
+
+#define PREV_IS_A_LETTER(d) ((current_mbctype == MBCTYPE_SJIS)? \
+ IS_A_LETTER((d)-(!AT_STRINGS_BEG((d)-1)&& \
+ ismbchar((d)[-2])?2:1)): \
+ ((current_mbctype && ((d)[-1] >= 0x80)) || \
+ IS_A_LETTER((d)-1)))
+
+static void
+init_regs(regs, num_regs)
+ struct re_registers *regs;
+ unsigned int num_regs;
+{
+ int i;
+
+ regs->num_regs = num_regs;
+ if (num_regs < RE_NREGS)
+ num_regs = RE_NREGS;
+
+ if (regs->allocated == 0) {
+ regs->beg = TMALLOC(num_regs, int);
+ regs->end = TMALLOC(num_regs, int);
+ regs->allocated = num_regs;
+ }
+ else if (regs->allocated < num_regs) {
+ TREALLOC(regs->beg, num_regs, int);
+ TREALLOC(regs->end, num_regs, int);
+ regs->allocated = num_regs;
+ }
+ for (i=0; i<num_regs; i++) {
+ regs->beg[i] = regs->end[i] = -1;
+ }
+}
+
+/* Match the pattern described by BUFP against STRING, which is of
+ SIZE. Start the match at index POS in STRING. In REGS, return the
+ indices of STRING that matched the entire BUFP->buffer and its
+ contained subexpressions.
+
+ If bufp->fastmap is nonzero, then it had better be up to date.
+
+ The reason that the data to match are specified as two components
+ which are to be regarded as concatenated is so this function can be
+ used directly on the contents of an Emacs buffer.
+
+ -1 is returned if there is no match. -2 is returned if there is an
+ error (such as match stack overflow). Otherwise the value is the
+ length of the substring which was matched. */
+
+int
+re_match(bufp, string_arg, size, pos, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string_arg;
+ int size, pos;
+ struct re_registers *regs;
+{
+ return re_match_exec(bufp, string_arg, size, pos, pos, regs);
+}
+
+static int
+re_match_exec(bufp, string_arg, size, pos, beg, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string_arg;
+ int size, pos, beg;
+ struct re_registers *regs;
+{
+ register unsigned char *p = (unsigned char*)bufp->buffer;
+ unsigned char *p1;
+
+ /* Pointer to beyond end of buffer. */
+ register unsigned char *pend = p + bufp->used;
+
+ unsigned num_regs = bufp->re_nsub;
+
+ unsigned char *string = (unsigned char*)string_arg;
+
+ register unsigned char *d, *dend;
+ register int mcnt; /* Multipurpose. */
+ int options = bufp->options;
+
+ /* Failure point stack. Each place that can handle a failure further
+ down the line pushes a failure point on this stack. It consists of
+ restart, regend, and reg_info for all registers corresponding to the
+ subexpressions we're currently inside, plus the number of such
+ registers, and, finally, two char *'s. The first char * is where to
+ resume scanning the pattern; the second one is where to resume
+ scanning the strings. If the latter is zero, the failure point is a
+ ``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 **stackb;
+ unsigned char **stackp;
+ unsigned char **stacke;
+
+ /* Information on the contents of registers. These are pointers into
+ the input strings; they record just what was matched (on this
+ attempt) by a subexpression part of the pattern, that is, the
+ regnum-th regstart pointer points to where in the pattern we began
+ matching and the regnum-th regend points to right after where we
+ stopped matching the regnum-th subexpression. (The zeroth register
+ keeps track of what the whole pattern matches.) */
+
+ unsigned char **regstart = bufp->regstart;
+ unsigned char **regend = bufp->regend;
+
+ /* If a group that's operated upon by a repetition operator fails to
+ match anything, then the register for its start will need to be
+ restored because it will have been set to wherever in the string we
+ are when we last see its open-group operator. Similarly for a
+ register's end. */
+ unsigned char **old_regstart = bufp->old_regstart;
+ unsigned char **old_regend = bufp->old_regend;
+
+ /* The is_active field of reg_info helps us keep track of which (possibly
+ nested) subexpressions we are currently in. The matched_something
+ field of reg_info[reg_num] helps us tell whether or not we have
+ matched any of the pattern so far this time through the reg_num-th
+ subexpression. These two fields get reset each time through any
+ loop their register is in. */
+
+ register_info_type *reg_info = bufp->reg_info;
+
+ /* The following record the register info as found in the above
+ variables when we find a match better than any we've seen before.
+ This happens as we backtrack through the failure points, which in
+ turn happens only if we have not yet matched the entire string. */
+
+ unsigned best_regs_set = 0;
+ unsigned char **best_regstart = bufp->best_regstart;
+ unsigned char **best_regend = bufp->best_regend;
+
+ int num_failure_counts = 0;
+
+ if (regs) {
+ init_regs(regs, num_regs);
+ }
+
+ /* Initialize the stack. */
+ stackb = TMALLOC(MAX_NUM_FAILURE_ITEMS * NFAILURES, unsigned char*);
+ stackp = stackb;
+ stacke = &stackb[MAX_NUM_FAILURE_ITEMS * NFAILURES];
+
+#ifdef DEBUG_REGEX
+ fprintf(stderr, "Entering re_match(%s)\n", string_arg);
+#endif
+
+ /* Initialize subexpression text positions to -1 to mark ones that no
+ ( or ( and ) or ) has been seen for. Also set all registers to
+ inactive and mark them as not having matched anything or ever
+ failed. */
+ for (mcnt = 0; mcnt < num_regs; mcnt++) {
+ regstart[mcnt] = regend[mcnt]
+ = old_regstart[mcnt] = old_regend[mcnt]
+ = best_regstart[mcnt] = best_regend[mcnt] = REG_UNSET_VALUE;
+#ifdef __CHECKER__
+ reg_info[mcnt].word = 0;
+#endif
+ IS_ACTIVE (reg_info[mcnt]) = 0;
+ MATCHED_SOMETHING (reg_info[mcnt]) = 0;
+ }
+
+ /* Set up pointers to ends of strings.
+ Don't allow the second string to be empty unless both are empty. */
+
+
+ /* `p' scans through the pattern as `d' scans through the data. `dend'
+ is the end of the input string that `d' points within. `d' is
+ advanced into the following input string whenever necessary, but
+ this happens before fetching; therefore, at the beginning of the
+ loop, `d' can be pointing at the end of a string, but it cannot
+ equal string2. */
+
+ d = string + pos, dend = string + size;
+
+ /* This loops over pattern commands. It exits by returning from the
+ function if match is complete, or it drops through if match fails
+ at this starting point in the input data. */
+
+ for (;;) {
+#ifdef DEBUG_REGEX
+ fprintf(stderr,
+ "regex loop(%d): matching 0x%02d\n",
+ p - (unsigned char*)bufp->buffer,
+ *p);
+#endif
+ /* End of pattern means we might have succeeded. */
+ if (p == pend) {
+ /* If not end of string, try backtracking. Otherwise done. */
+ if ((bufp->options & RE_OPTION_LONGEST) && d != dend) {
+ if (best_regs_set) /* non-greedy, no need to backtrack */
+ goto restore_best_regs;
+ while (stackp != stackb && stackp[-1] == NON_GREEDY) {
+ if (best_regs_set) /* non-greedy, no need to backtrack */
+ goto restore_best_regs;
+ POP_FAILURE_POINT();
+ }
+ if (stackp != stackb) {
+ /* More failure points to try. */
+
+ /* If exceeds best match so far, save it. */
+ if (! best_regs_set || (d > best_regend[0])) {
+ best_regs_set = 1;
+ best_regend[0] = d; /* Never use regstart[0]. */
+
+ for (mcnt = 1; mcnt < num_regs; mcnt++) {
+ best_regstart[mcnt] = regstart[mcnt];
+ best_regend[mcnt] = regend[mcnt];
+ }
+ }
+ goto fail;
+ }
+ /* If no failure points, don't restore garbage. */
+ else if (best_regs_set) {
+ restore_best_regs:
+ /* Restore best match. */
+ d = best_regend[0];
+
+ for (mcnt = 0; mcnt < num_regs; mcnt++) {
+ regstart[mcnt] = best_regstart[mcnt];
+ regend[mcnt] = best_regend[mcnt];
+ }
+ }
+ }
+
+ /* If caller wants register contents data back, convert it
+ to indices. */
+ if (regs) {
+ regs->beg[0] = pos;
+ regs->end[0] = d - string;
+ for (mcnt = 1; mcnt < num_regs; mcnt++) {
+ if (REG_UNSET(regend[mcnt])) {
+ regs->beg[mcnt] = -1;
+ regs->end[mcnt] = -1;
+ continue;
+ }
+ regs->beg[mcnt] = regstart[mcnt] - string;
+ regs->end[mcnt] = regend[mcnt] - string;
+ }
+ }
+ FREE_AND_RETURN(stackb, (d - pos - string));
+ }
+
+ /* Otherwise match next pattern command. */
+#ifdef SWITCH_ENUM_BUG
+ switch ((int)((enum regexpcode)*p++))
+#else
+ switch ((enum regexpcode)*p++)
+#endif
+ {
+ /* ( [or `(', as appropriate] is represented by start_memory,
+ ) by stop_memory. Both of those commands are followed by
+ a register number in the next byte. The text matched
+ within the ( and ) is recorded under that number. */
+ case start_memory:
+ old_regstart[*p] = regstart[*p];
+ regstart[*p] = d;
+ IS_ACTIVE(reg_info[*p]) = 1;
+ MATCHED_SOMETHING(reg_info[*p]) = 0;
+ p += 2;
+ continue;
+
+ case stop_memory:
+ old_regend[*p] = regend[*p];
+ regend[*p] = d;
+ IS_ACTIVE(reg_info[*p]) = 0;
+ p += 2;
+ continue;
+
+ case start_paren:
+ case stop_paren:
+ break;
+
+ /* \<digit> has been turned into a `duplicate' command which is
+ followed by the numeric value of <digit> as the register number. */
+ case duplicate:
+ {
+ int regno = *p++; /* Get which register to match against */
+ register unsigned char *d2, *dend2;
+
+ /* Check if there's corresponding group */
+ if (regno >= num_regs) goto fail;
+ /* Check if corresponding group is still open */
+ if (IS_ACTIVE(reg_info[regno])) goto fail;
+
+ /* Where in input to try to start matching. */
+ d2 = regstart[regno];
+ if (REG_UNSET(d2)) goto fail;
+
+ /* Where to stop matching; if both the place to start and
+ the place to stop matching are in the same string, then
+ set to the place to stop, otherwise, for now have to use
+ the end of the first string. */
+
+ dend2 = regend[regno];
+ if (REG_UNSET(dend2)) goto fail;
+ for (;;) {
+ /* At end of register contents => success */
+ if (d2 == dend2) break;
+
+ /* If necessary, advance to next segment in data. */
+ PREFETCH;
+
+ /* How many characters left in this segment to match. */
+ mcnt = dend - d;
+
+ /* Want how many consecutive characters we can match in
+ one shot, so, if necessary, adjust the count. */
+ if (mcnt > dend2 - d2)
+ mcnt = dend2 - d2;
+
+ /* Compare that many; failure if mismatch, else move
+ past them. */
+ if ((options & RE_OPTION_IGNORECASE)
+ ? memcmp_translate(d, d2, mcnt)
+ : memcmp((char*)d, (char*)d2, mcnt))
+ goto fail;
+ d += mcnt, d2 += mcnt;
+ }
+ }
+ break;
+
+ case start_nowidth:
+ PUSH_FAILURE_POINT(0, d);
+ if (stackp - stackb > RE_DUP_MAX) {
+ FREE_AND_RETURN(stackb,(-2));
+ }
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ STORE_NUMBER(p+mcnt, stackp - stackb);
+ continue;
+
+ case stop_nowidth:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ stackp = stackb + mcnt;
+ d = stackp[-3];
+ POP_FAILURE_POINT();
+ continue;
+
+ case stop_backtrack:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ stackp = stackb + mcnt;
+ POP_FAILURE_POINT();
+ continue;
+
+ case pop_and_fail:
+ EXTRACT_NUMBER(mcnt, p+1);
+ stackp = stackb + mcnt;
+ POP_FAILURE_POINT();
+ goto fail;
+
+ case anychar:
+ PREFETCH;
+ if (ismbchar(*d)) {
+ if (d + mbclen(*d) > dend)
+ goto fail;
+ SET_REGS_MATCHED;
+ d += mbclen(*d);
+ break;
+ }
+ if (!(options&RE_OPTION_MULTILINE)
+ && (TRANSLATE_P() ? translate[*d] : *d) == '\n')
+ goto fail;
+ SET_REGS_MATCHED;
+ d++;
+ break;
+
+ case anychar_repeat:
+ for (;;) {
+ PUSH_FAILURE_POINT(p, d);
+ PREFETCH;
+ if (ismbchar(*d)) {
+ if (d + mbclen(*d) > dend)
+ goto fail;
+ SET_REGS_MATCHED;
+ d += mbclen(*d);
+ continue;
+ }
+ if (!(options&RE_OPTION_MULTILINE) &&
+ (TRANSLATE_P() ? translate[*d] : *d) == '\n')
+ goto fail;
+ SET_REGS_MATCHED;
+ d++;
+ }
+ break;
+
+ case charset:
+ case charset_not:
+ {
+ int not; /* Nonzero for charset_not. */
+ int part = 0; /* true if matched part of mbc */
+ unsigned char *dsave = d + 1;
+ int cc, c;
+
+ PREFETCH;
+ c = (unsigned char)*d++;
+ if (ismbchar(c)) {
+ if (d + mbclen(c) - 1 <= dend) {
+ cc = c;
+ MBC2WC(c, d);
+ not = is_in_list_mbc(c, p);
+ if (!not) {
+ part = not = is_in_list_sbc(cc, p);
+ }
+ } else {
+ not = is_in_list(c, p);
+ }
+ }
+ else {
+ if (TRANSLATE_P())
+ c = (unsigned char)translate[c];
+ not = is_in_list(c, p);
+ }
+
+ if (*(p - 1) == (unsigned char)charset_not) {
+ not = !not;
+ }
+ if (!not) goto fail;
+
+ p += 1 + *p + 2 + EXTRACT_UNSIGNED(&p[1 + *p])*8;
+ SET_REGS_MATCHED;
+
+ if (part) d = dsave;
+ break;
+ }
+
+ case begline:
+ if (size == 0 || AT_STRINGS_BEG(d))
+ break;
+ if (d[-1] == '\n' && !AT_STRINGS_END(d))
+ break;
+ goto fail;
+
+ case endline:
+ if (AT_STRINGS_END(d)) {
+ break;
+ }
+ else if (*d == '\n')
+ break;
+ goto fail;
+
+ /* Match at the very beginning of the string. */
+ case begbuf:
+ if (AT_STRINGS_BEG(d))
+ break;
+ goto fail;
+
+ /* Match at the very end of the data. */
+ case endbuf:
+ if (AT_STRINGS_END(d))
+ break;
+ goto fail;
+
+ /* Match at the very end of the data. */
+ case endbuf2:
+ if (AT_STRINGS_END(d)) {
+ break;
+ }
+ /* .. or newline just before the end of the data. */
+ if (*d == '\n' && AT_STRINGS_END(d+1))
+ break;
+ goto fail;
+
+ /* `or' constructs are handled by starting each alternative with
+ an on_failure_jump that points to the start of the next
+ alternative. Each alternative except the last ends with a
+ jump to the joining point. (Actually, each jump except for
+ the last one really jumps to the following jump, because
+ tensioning the jumps is a hassle.) */
+
+ /* The start of a stupid repeat has an on_failure_jump that points
+ past the end of the repeat text. This makes a failure point so
+ that on failure to match a repetition, matching restarts past
+ as many repetitions have been found with no way to fail and
+ look for another one. */
+
+ /* A smart repeat is similar but loops back to the on_failure_jump
+ so that each repetition makes another failure point. */
+
+ /* Match at the starting position. */
+ case begpos:
+ if (d - string == beg)
+ break;
+ goto fail;
+
+ case on_failure_jump:
+ on_failure:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ PUSH_FAILURE_POINT(p + mcnt, d);
+ continue;
+
+ /* The end of a smart repeat has a maybe_finalize_jump back.
+ Change it either to a finalize_jump or an ordinary jump. */
+ case maybe_finalize_jump:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ p1 = p;
+
+ /* Compare the beginning of the repeat with what in the
+ pattern follows its end. If we can establish that there
+ is nothing that they would both match, i.e., that we
+ would have to backtrack because of (as in, e.g., `a*a')
+ then we can change to finalize_jump, because we'll
+ never have to backtrack.
+
+ This is not true in the case of alternatives: in
+ `(a|ab)*' we do need to backtrack to the `ab' alternative
+ (e.g., if the string was `ab'). But instead of trying to
+ detect that here, the alternative has put on a dummy
+ failure point which is what we will end up popping. */
+
+ /* Skip over open/close-group commands. */
+ while (p1 + 2 < pend) {
+ if ((enum regexpcode)*p1 == stop_memory ||
+ (enum regexpcode)*p1 == start_memory)
+ p1 += 3; /* Skip over args, too. */
+ else if (/*(enum regexpcode)*p1 == start_paren ||*/
+ (enum regexpcode)*p1 == stop_paren)
+ p1 += 1;
+ else
+ break;
+ }
+
+ if (p1 == pend)
+ p[-3] = (unsigned char)finalize_jump;
+ else if (*p1 == (unsigned char)exactn ||
+ *p1 == (unsigned char)endline) {
+ register int c = *p1 == (unsigned char)endline ? '\n' : p1[2];
+ register unsigned char *p2 = p + mcnt;
+ /* p2[0] ... p2[2] are an on_failure_jump.
+ Examine what follows that. */
+ if (p2[3] == (unsigned char)exactn && p2[5] != c)
+ p[-3] = (unsigned char)finalize_jump;
+ else if (p2[3] == (unsigned char)charset ||
+ p2[3] == (unsigned char)charset_not) {
+ int not;
+ if (ismbchar(c)) {
+ unsigned char *pp = p1+3;
+ MBC2WC(c, pp);
+ }
+ /* `is_in_list()' is TRUE if c would match */
+ /* That means it is not safe to finalize. */
+ not = is_in_list(c, p2 + 4);
+ if (p2[3] == (unsigned char)charset_not)
+ not = !not;
+ if (!not)
+ p[-3] = (unsigned char)finalize_jump;
+ }
+ }
+ p -= 2; /* Point at relative address again. */
+ if (p[-1] != (unsigned char)finalize_jump) {
+ p[-1] = (unsigned char)jump;
+ goto nofinalize;
+ }
+ /* Note fall through. */
+
+ /* The end of a stupid repeat has a finalize_jump back to the
+ start, where another failure point will be made which will
+ point to after all the repetitions found so far. */
+
+ /* Take off failure points put on by matching on_failure_jump
+ because didn't fail. Also remove the register information
+ put on by the on_failure_jump. */
+ case finalize_jump:
+ if (stackp > stackb && stackp[-3] == d) {
+ p = stackp[-4];
+ POP_FAILURE_POINT();
+ continue;
+ }
+ POP_FAILURE_POINT();
+ /* Note fall through. */
+
+ /* We need this opcode so we can detect where alternatives end
+ in `group_match_null_string_p' et al. */
+ case jump_past_alt:
+ /* fall through */
+
+ /* Jump without taking off any failure points. */
+ case jump:
+ nofinalize:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ if (mcnt < 0 && stackp > stackb && stackp[-3] == d) /* avoid infinite loop */
+ goto fail;
+ p += mcnt;
+ continue;
+
+ case dummy_failure_jump:
+ /* Normally, the on_failure_jump pushes a failure point, which
+ then gets popped at finalize_jump. We will end up at
+ finalize_jump, also, and with a pattern of, say, `a+', we
+ are skipping over the on_failure_jump, so we have to push
+ something meaningless for finalize_jump to pop. */
+ PUSH_FAILURE_POINT(0, 0);
+ goto nofinalize;
+
+ /* At the end of an alternative, we need to push a dummy failure
+ point in case we are followed by a `finalize_jump', because
+ we don't want the failure point for the alternative to be
+ popped. For example, matching `(a|ab)*' against `aab'
+ requires that we match the `ab' alternative. */
+ case push_dummy_failure:
+ /* See comments just above at `dummy_failure_jump' about the
+ two zeroes. */
+ p1 = p;
+ /* Skip over open/close-group commands. */
+ while (p1 + 2 < pend) {
+ if ((enum regexpcode)*p1 == stop_memory ||
+ (enum regexpcode)*p1 == start_memory)
+ p1 += 3; /* Skip over args, too. */
+ else if (/*(enum regexpcode)*p1 == start_paren ||*/
+ (enum regexpcode)*p1 == stop_paren)
+ p1 += 1;
+ else
+ break;
+ }
+ if (p1 < pend && (enum regexpcode)*p1 == jump)
+ p[-1] = unused;
+ else
+ PUSH_FAILURE_POINT(0, 0);
+ break;
+
+ /* Have to succeed matching what follows at least n times. Then
+ just handle like an on_failure_jump. */
+ case succeed_n:
+ EXTRACT_NUMBER(mcnt, p + 2);
+ /* Originally, this is how many times we HAVE to succeed. */
+ if (mcnt != 0) {
+ mcnt--;
+ p += 2;
+ PUSH_FAILURE_COUNT(p);
+ STORE_NUMBER_AND_INCR(p, mcnt);
+ PUSH_FAILURE_POINT(0, 0);
+ }
+ else {
+ goto on_failure;
+ }
+ continue;
+
+ case jump_n:
+ EXTRACT_NUMBER(mcnt, p + 2);
+ /* Originally, this is how many times we CAN jump. */
+ if (mcnt) {
+ mcnt--;
+ PUSH_FAILURE_COUNT(p + 2);
+ STORE_NUMBER(p + 2, mcnt);
+ goto nofinalize; /* Do the jump without taking off
+ any failure points. */
+ }
+ /* If don't have to jump any more, skip over the rest of command. */
+ else
+ p += 4;
+ continue;
+
+ case set_number_at:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ p1 = p + mcnt;
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ STORE_NUMBER(p1, mcnt);
+ continue;
+
+ case try_next:
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ if (p + mcnt < pend) {
+ PUSH_FAILURE_POINT(p, d);
+ stackp[-1] = NON_GREEDY;
+ }
+ p += mcnt;
+ continue;
+
+ case finalize_push:
+ POP_FAILURE_POINT();
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ if (mcnt < 0 && stackp > stackb && stackp[-3] == d) /* avoid infinite loop */
+ goto fail;
+ PUSH_FAILURE_POINT(p + mcnt, d);
+ stackp[-1] = NON_GREEDY;
+ continue;
+
+ case finalize_push_n:
+ EXTRACT_NUMBER(mcnt, p + 2);
+ /* Originally, this is how many times we CAN jump. */
+ if (mcnt) {
+ int pos, i;
+
+ mcnt--;
+ STORE_NUMBER(p + 2, mcnt);
+ EXTRACT_NUMBER(pos, p);
+ EXTRACT_NUMBER(i, p+pos+5);
+ if (i > 0) goto nofinalize;
+ POP_FAILURE_POINT();
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ PUSH_FAILURE_POINT(p + mcnt, d);
+ stackp[-1] = NON_GREEDY;
+ p += 2; /* skip n */
+ }
+ /* If don't have to push any more, skip over the rest of command. */
+ else
+ p += 4;
+ continue;
+
+ /* Ignore these. Used to ignore the n of succeed_n's which
+ currently have n == 0. */
+ case unused:
+ continue;
+
+ case casefold_on:
+ options |= RE_OPTION_IGNORECASE;
+ continue;
+
+ case casefold_off:
+ options &= ~RE_OPTION_IGNORECASE;
+ continue;
+
+ case option_set:
+ options = *p++;
+ continue;
+
+ case wordbound:
+ if (AT_STRINGS_BEG(d)) {
+ if (AT_STRINGS_END(d)) goto fail;
+ if (IS_A_LETTER(d)) break;
+ else goto fail;
+ }
+ if (AT_STRINGS_END(d)) {
+ if (PREV_IS_A_LETTER(d)) break;
+ else goto fail;
+ }
+ if (PREV_IS_A_LETTER(d) != IS_A_LETTER(d))
+ break;
+ goto fail;
+
+ case notwordbound:
+ if (AT_STRINGS_BEG(d)) {
+ if (IS_A_LETTER(d)) goto fail;
+ else break;
+ }
+ if (AT_STRINGS_END(d)) {
+ if (PREV_IS_A_LETTER(d)) goto fail;
+ else break;
+ }
+ if (PREV_IS_A_LETTER(d) != IS_A_LETTER(d))
+ goto fail;
+ break;
+
+ case wordbeg:
+ if (IS_A_LETTER(d) && (AT_STRINGS_BEG(d) || !PREV_IS_A_LETTER(d)))
+ break;
+ goto fail;
+
+ case wordend:
+ if (!AT_STRINGS_BEG(d) && PREV_IS_A_LETTER(d)
+ && (!IS_A_LETTER(d) || AT_STRINGS_END(d)))
+ break;
+ goto fail;
+
+ case wordchar:
+ PREFETCH;
+ if (!IS_A_LETTER(d))
+ goto fail;
+ if (ismbchar(*d) && d + mbclen(*d) - 1 < dend)
+ d += mbclen(*d) - 1;
+ d++;
+ SET_REGS_MATCHED;
+ break;
+
+ case notwordchar:
+ PREFETCH;
+ if (IS_A_LETTER(d))
+ goto fail;
+ if (ismbchar(*d) && d + mbclen(*d) - 1 < dend)
+ d += mbclen(*d) - 1;
+ d++;
+ SET_REGS_MATCHED;
+ break;
+
+ case exactn:
+ /* Match the next few pattern characters exactly.
+ mcnt is how many characters to match. */
+ mcnt = *p++;
+ /* This is written out as an if-else so we don't waste time
+ testing `translate' inside the loop. */
+ if (TRANSLATE_P()) {
+ do {
+ unsigned char c;
+
+ PREFETCH;
+ if (*p == 0xff) {
+ p++;
+ if (!--mcnt
+ || AT_STRINGS_END(d)
+ || (unsigned char)*d++ != (unsigned char)*p++)
+ goto fail;
+ continue;
+ }
+ c = *d++;
+ if (ismbchar(c)) {
+ int n;
+
+ if (c != (unsigned char)*p++)
+ goto fail;
+ for (n = mbclen(c) - 1; n > 0; n--)
+ if (!--mcnt /* redundant check if pattern was
+ compiled properly. */
+ || AT_STRINGS_END(d)
+ || (unsigned char)*d++ != (unsigned char)*p++)
+ goto fail;
+ continue;
+ }
+ /* compiled code translation needed for ruby */
+ if ((unsigned char)translate[c] != (unsigned char)translate[*p++])
+ goto fail;
+ }
+ while (--mcnt);
+ }
+ else {
+ do {
+ PREFETCH;
+ if (*p == 0xff) {p++; mcnt--;}
+ if (*d++ != *p++) goto fail;
+ }
+ while (--mcnt);
+ }
+ SET_REGS_MATCHED;
+ break;
+ }
+#ifdef RUBY
+ CHECK_INTS;
+#endif
+ continue; /* Successfully executed one pattern command; keep going. */
+
+ /* Jump here if any matching operation fails. */
+ fail:
+ if (stackp != stackb) {
+ /* A restart point is known. Restart there and pop it. */
+ short last_used_reg, this_reg;
+
+ /* If this failure point is from a dummy_failure_point, just
+ skip it. */
+ if (stackp[-4] == 0 || (best_regs_set && stackp[-1] == NON_GREEDY)) {
+ POP_FAILURE_POINT();
+ goto fail;
+ }
+ stackp--; /* discard greedy flag */
+ options = (long)*--stackp;
+ d = *--stackp;
+ p = *--stackp;
+ /* Restore register info. */
+ last_used_reg = (long)*--stackp;
+
+ /* Make the ones that weren't saved -1 or 0 again. */
+ for (this_reg = num_regs - 1; this_reg > last_used_reg; this_reg--) {
+ regend[this_reg] = REG_UNSET_VALUE;
+ regstart[this_reg] = REG_UNSET_VALUE;
+ IS_ACTIVE(reg_info[this_reg]) = 0;
+ MATCHED_SOMETHING(reg_info[this_reg]) = 0;
+ }
+
+ /* And restore the rest from the stack. */
+ for ( ; this_reg > 0; this_reg--) {
+ reg_info[this_reg].word = *--stackp;
+ regend[this_reg] = *--stackp;
+ regstart[this_reg] = *--stackp;
+ }
+ mcnt = (long)*--stackp;
+ while (mcnt--) {
+ POP_FAILURE_COUNT();
+ }
+ if (p < pend) {
+ int is_a_jump_n = 0;
+ int failed_paren = 0;
+
+ p1 = p;
+ /* If failed to a backwards jump that's part of a repetition
+ loop, need to pop this failure point and use the next one. */
+ switch ((enum regexpcode)*p1) {
+ case jump_n:
+ case finalize_push_n:
+ is_a_jump_n = 1;
+ case maybe_finalize_jump:
+ case finalize_jump:
+ case finalize_push:
+ case jump:
+ p1++;
+ EXTRACT_NUMBER_AND_INCR(mcnt, p1);
+
+ if (mcnt >= 0) break; /* should be backward jump */
+ p1 += mcnt;
+
+ if (( is_a_jump_n && (enum regexpcode)*p1 == succeed_n) ||
+ (!is_a_jump_n && (enum regexpcode)*p1 == on_failure_jump)) {
+ if (failed_paren) {
+ p1++;
+ EXTRACT_NUMBER_AND_INCR(mcnt, p1);
+ PUSH_FAILURE_POINT(p1 + mcnt, d);
+ }
+ goto fail;
+ }
+ break;
+ default:
+ /* do nothing */;
+ }
+ }
+ }
+ else
+ break; /* Matching at this starting point really fails. */
+ }
+
+ if (best_regs_set)
+ goto restore_best_regs;
+
+ FREE_AND_RETURN(stackb,(-1)); /* Failure to match. */
+ memory_exhausted:
+ FREE_AND_RETURN(stackb,(-2));
+}
+
+
+static int
+memcmp_translate(s1, s2, len)
+ unsigned char *s1, *s2;
+ register int len;
+{
+ register unsigned char *p1 = s1, *p2 = s2, c;
+ while (len) {
+ c = *p1++;
+ if (ismbchar(c)) {
+ int n;
+
+ if (c != *p2++) return 1;
+ for (n = mbclen(c) - 1; n > 0; n--)
+ if (!--len || *p1++ != *p2++)
+ return 1;
+ }
+ else
+ if (translate[c] != translate[*p2++])
+ return 1;
+ len--;
+ }
+ return 0;
+}
+
+void
+re_copy_registers(regs1, regs2)
+ struct re_registers *regs1, *regs2;
+{
+ int i;
+
+ if (regs1 == regs2) return;
+ if (regs1->allocated == 0) {
+ regs1->beg = TMALLOC(regs2->num_regs, int);
+ regs1->end = TMALLOC(regs2->num_regs, int);
+ regs1->allocated = regs2->num_regs;
+ }
+ else if (regs1->allocated < regs2->num_regs) {
+ TREALLOC(regs1->beg, regs2->num_regs, int);
+ TREALLOC(regs1->end, regs2->num_regs, int);
+ regs1->allocated = regs2->num_regs;
+ }
+ for (i=0; i<regs2->num_regs; i++) {
+ regs1->beg[i] = regs2->beg[i];
+ regs1->end[i] = regs2->end[i];
+ }
+ regs1->num_regs = regs2->num_regs;
+}
+
+void
+re_free_registers(regs)
+ struct re_registers *regs;
+{
+ if (regs->allocated == 0) return;
+ if (regs->beg) xfree(regs->beg);
+ if (regs->end) xfree(regs->end);
+}
+
+/* Functions for multi-byte support.
+ Created for grep multi-byte extension Jul., 1993 by t^2 (Takahiro Tanimoto)
+ Last change: Jul. 9, 1993 by t^2 */
+static const unsigned char mbctab_ascii[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+
+static const unsigned char mbctab_euc[] = { /* 0xA1-0xFE */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+};
+
+static const unsigned char mbctab_sjis[] = { /* 0x81-0x9F,0xE0-0xFC */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
+};
+
+static const unsigned char mbctab_sjis_trail[] = { /* 0x40-0x7E,0x80-0xFC */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
+};
+
+static const unsigned char mbctab_utf8[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 0, 0,
+};
+
+const unsigned char *re_mbctab = mbctab_ascii;
+
+void
+re_mbcinit(mbctype)
+ int mbctype;
+{
+ switch (mbctype) {
+ case MBCTYPE_ASCII:
+ re_mbctab = mbctab_ascii;
+ current_mbctype = MBCTYPE_ASCII;
+ break;
+ case MBCTYPE_EUC:
+ re_mbctab = mbctab_euc;
+ current_mbctype = MBCTYPE_EUC;
+ break;
+ case MBCTYPE_SJIS:
+ re_mbctab = mbctab_sjis;
+ current_mbctype = MBCTYPE_SJIS;
+ break;
+ case MBCTYPE_UTF8:
+ re_mbctab = mbctab_utf8;
+ current_mbctype = MBCTYPE_UTF8;
+ break;
+ }
+}
+
+#define mbc_isfirst(t, c) (t)[(unsigned char)(c)]
+#define mbc_len(t, c) ((t)[(unsigned char)(c)]+1)
+
+static unsigned int
+asc_startpos(string, pos)
+ const char *string;
+ unsigned int pos;
+{
+ return pos;
+}
+
+#define euc_islead(c) ((unsigned char)((c) - 0xa1) > 0xfe - 0xa1)
+#define euc_mbclen(c) mbc_len(mbctab_euc, (c))
+static unsigned int
+euc_startpos(string, pos)
+ const char *string;
+ unsigned int pos;
+{
+ unsigned int i = pos, w;
+
+ while (i > 0 && !euc_islead(string[i])) {
+ --i;
+ }
+ if (i == pos || i + (w = euc_mbclen(string[i])) > pos) {
+ return i;
+ }
+ i += w;
+ return i + ((pos - i) & ~1);
+}
+
+#define sjis_isfirst(c) mbc_isfirst(mbctab_sjis, (c))
+#define sjis_istrail(c) mbctab_sjis_trail[(unsigned char)(c)]
+#define sjis_mbclen(c) mbc_len(mbctab_sjis, (c))
+static unsigned int
+sjis_startpos(string, pos)
+ const char *string;
+ unsigned int pos;
+{
+ unsigned int i = pos, w;
+
+ if (i > 0 && sjis_istrail(string[i])) {
+ do {
+ if (!sjis_isfirst(string[--i])) {
+ ++i;
+ break;
+ }
+ } while (i > 0);
+ }
+ if (i == pos || i + (w = sjis_mbclen(string[i])) > pos) {
+ return i;
+ }
+ i += w;
+ return i + ((pos - i) & ~1);
+}
+
+#define utf8_islead(c) ((unsigned char)((c) & 0xc0) != 0x80)
+#define utf8_mbclen(c) mbc_len(mbctab_utf8, (c))
+static unsigned int
+utf8_startpos(string, pos)
+ const char *string;
+ unsigned int pos;
+{
+ unsigned int i = pos, w;
+
+ while (i > 0 && !utf8_islead(string[i])) {
+ --i;
+ }
+ if (i == pos || i + (w = utf8_mbclen(string[i])) > pos) {
+ return i;
+ }
+ return i + w;
+}
+
+/*
+ vi: sw=2 ts=8
+ Local variables:
+ mode : C
+ c-file-style : "gnu"
+ tab-width : 8
+ End
+*/
diff --git a/regex.h b/regex.h
index d2877937ca..88868e2b4c 100644
--- a/regex.h
+++ b/regex.h
@@ -1,28 +1,221 @@
-/**********************************************************************
+/* Definitions for data structures and routines for the regular
+ expression library, version 0.12.
+ Copyright (C) 1985,89,90,91,92,93,95,96,97,98 Free Software Foundation, Inc.
- regex.h -
+ This file is part of the GNU C Library. Its master source is NOT part of
+ the C library, however. The master source lives in /gd/gnu/lib.
- $Author$
- $Date$
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
- Copyright (C) 1993-2005 Yukihiro Matsumoto
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
-**********************************************************************/
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file LGPL. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+/* Multi-byte extension added May, 1993 by t^2 (Takahiro Tanimoto)
+ Last change: May 21, 1993 by t^2 */
+/* modified for Ruby by matz@netlab.co.jp */
#ifndef REGEX_H
#define REGEX_H
-#include "oniguruma.h"
+/* symbol mangling for ruby */
+#ifdef RUBY
+# define re_adjust_startpos ruby_re_adjust_startpos
+# define re_compile_fastmap ruby_re_compile_fastmap
+# define re_compile_pattern ruby_re_compile_pattern
+# define re_copy_registers ruby_re_copy_registers
+# define re_free_pattern ruby_re_free_pattern
+# define re_free_registers ruby_re_free_registers
+# define re_match ruby_re_match
+# define re_mbcinit ruby_re_mbcinit
+# define re_search ruby_re_search
+# define re_set_casetable ruby_re_set_casetable
+# define register_info_type ruby_register_info_type
+#endif
-#ifndef ONIG_RUBY_M17N
+#include <stddef.h>
-ONIG_EXTERN OnigEncoding OnigEncDefaultCharEncoding;
+/* Define number of parens for which we record the beginnings and ends.
+ This affects how much space the `struct re_registers' type takes up. */
+#ifndef RE_NREGS
+#define RE_NREGS 10
+#endif
+
+#define BYTEWIDTH 8
+
+#define RE_REG_MAX ((1<<BYTEWIDTH)-1)
+
+/* Maximum number of duplicates an interval can allow. */
+#ifndef RE_DUP_MAX
+#define RE_DUP_MAX ((1 << 15) - 1)
+#endif
+
+
+/* If this bit is set, then character classes are supported; they are:
+ [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
+ [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
+ If not set, then character classes are not supported. */
+#define RE_CHAR_CLASSES (1L << 9)
+
+/* match will be done case insensetively */
+#define RE_OPTION_IGNORECASE (1L)
+/* perl-style extended pattern available */
+#define RE_OPTION_EXTENDED (RE_OPTION_IGNORECASE<<1)
+/* newline will be included for . */
+#define RE_OPTION_MULTILINE (RE_OPTION_EXTENDED<<1)
+/* ^ and $ ignore newline */
+#define RE_OPTION_SINGLELINE (RE_OPTION_MULTILINE<<1)
+/* search for longest match, in accord with POSIX regexp */
+#define RE_OPTION_LONGEST (RE_OPTION_SINGLELINE<<1)
+
+#define RE_MAY_IGNORECASE (RE_OPTION_LONGEST<<1)
+#define RE_OPTIMIZE_ANCHOR (RE_MAY_IGNORECASE<<1)
+#define RE_OPTIMIZE_EXACTN (RE_OPTIMIZE_ANCHOR<<1)
+#define RE_OPTIMIZE_NO_BM (RE_OPTIMIZE_EXACTN<<1)
+#define RE_OPTIMIZE_BMATCH (RE_OPTIMIZE_NO_BM<<1)
+
+/* For multi-byte char support */
+#define MBCTYPE_ASCII 0
+#define MBCTYPE_EUC 1
+#define MBCTYPE_SJIS 2
+#define MBCTYPE_UTF8 3
+
+extern
+#if defined _WIN32 && !defined __GNUC__ && !defined RUBY_EXPORT
+__declspec(dllimport)
+# endif
+const unsigned char *re_mbctab;
+#if defined(__STDC__)
+void re_mbcinit (int);
+#else
+void re_mbcinit ();
+#endif
#undef ismbchar
-#define ismbchar(c) (mbclen((c)) != 1)
-#define mbclen(c) \
- ONIGENC_MBC_ENC_LEN(OnigEncDefaultCharEncoding, (UChar* )(&c))
+#define ismbchar(c) re_mbctab[(unsigned char)(c)]
+#define mbclen(c) (re_mbctab[(unsigned char)(c)]+1)
+
+/* Structure used in re_match() */
+
+typedef union
+{
+ unsigned char *word;
+ struct {
+ unsigned is_active : 1;
+ unsigned matched_something : 1;
+ } bits;
+} register_info_type;
+
+/* This data structure is used to represent a compiled pattern. */
+
+struct re_pattern_buffer
+ {
+ char *buffer; /* Space holding the compiled pattern commands. */
+ int allocated; /* Size of space that `buffer' points to. */
+ int used; /* Length of portion of buffer actually occupied */
+ char *fastmap; /* Pointer to fastmap, if any, or zero if none. */
+ /* re_search uses the fastmap, if there is one,
+ to skip over totally implausible characters. */
+ char *must; /* Pointer to exact pattern which strings should have
+ to be matched. */
+ int *must_skip; /* Pointer to exact pattern skip table for bm_search */
+ long options; /* Flags for options such as extended_pattern. */
+ long re_nsub; /* Number of subexpressions found by the compiler. */
+ char fastmap_accurate;
+ /* Set to zero when a new pattern is stored,
+ set to one when the fastmap is updated from it. */
+ char can_be_null; /* Set to one by compiling fastmap
+ if this pattern might match the null string.
+ It does not necessarily match the null string
+ in that case, but if this is zero, it cannot.
+ 2 as value means can match null string
+ but at end of range or before a character
+ listed in the fastmap. */
+
+ /* stack & working area for re_match() */
+ unsigned char **regstart;
+ unsigned char **regend;
+ unsigned char **old_regstart;
+ unsigned char **old_regend;
+ register_info_type *reg_info;
+ unsigned char **best_regstart;
+ unsigned char **best_regend;
+ };
+
+typedef struct re_pattern_buffer regex_t;
+
+/* Structure to store register contents data in.
+
+ Pass the address of such a structure as an argument to re_match, etc.,
+ if you want this information back.
+
+ For i from 1 to RE_NREGS - 1, start[i] records the starting index in
+ the string of where the ith subexpression matched, and end[i] records
+ one after the ending index. start[0] and end[0] are analogous, for
+ the entire pattern. */
+
+struct re_registers
+ {
+ int allocated;
+ int num_regs;
+ int *beg;
+ int *end;
+ };
+
+/* Type for byte offsets within the string. POSIX mandates this. */
+typedef size_t regoff_t;
+
+/* POSIX specification for registers. Aside from the different names than
+ `re_registers', POSIX uses an array of structures, instead of a
+ structure of arrays. */
+typedef struct
+{
+ regoff_t rm_so; /* Byte offset from string's start to substring's start. */
+ regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
+} regmatch_t;
+
+#ifdef __STDC__
+
+extern char *re_compile_pattern (const char *, int, struct re_pattern_buffer *);
+void re_free_pattern (struct re_pattern_buffer *);
+/* Is this really advertised? */
+extern int re_adjust_startpos (struct re_pattern_buffer *, const char*, int, int, int);
+extern void re_compile_fastmap (struct re_pattern_buffer *);
+extern int re_search (struct re_pattern_buffer *, const char*, int, int, int,
+ struct re_registers *);
+extern int re_match (struct re_pattern_buffer *, const char *, int, int,
+ struct re_registers *);
+extern void re_set_casetable (const char *table);
+extern void re_copy_registers (struct re_registers*, struct re_registers*);
+extern void re_free_registers (struct re_registers*);
+
+#ifndef RUBY
+/* 4.2 bsd compatibility. */
+extern char *re_comp (const char *);
+extern int re_exec (const char *);
+#endif
+
+#else /* !__STDC__ */
+
+extern char *re_compile_pattern ();
+void re_free_regexp ();
+/* Is this really advertised? */
+extern int re_adjust_startpos ();
+extern void re_compile_fastmap ();
+extern int re_search ();
+extern int re_match ();
+extern void re_set_casetable ();
+extern void re_copy_registers ();
+extern void re_free_registers ();
-#endif /* ifndef ONIG_RUBY_M17N */
+#endif /* __STDC__ */
#endif /* !REGEX_H */
diff --git a/regexec.c b/regexec.c
deleted file mode 100644
index ba2a1b1cd4..0000000000
--- a/regexec.c
+++ /dev/null
@@ -1,3920 +0,0 @@
-/**********************************************************************
- regexec.c - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "regint.h"
-
-#ifdef USE_CRNL_AS_LINE_TERMINATOR
-#define ONIGENC_IS_MBC_CRNL(enc,p,end) \
- (ONIGENC_MBC_TO_CODE(enc,p,end) == 13 && \
- ONIGENC_IS_MBC_NEWLINE(enc,(p+enc_len(enc,p)),end))
-#endif
-
-#ifdef USE_CAPTURE_HISTORY
-static void history_tree_free(OnigCaptureTreeNode* node);
-
-static void
-history_tree_clear(OnigCaptureTreeNode* node)
-{
- int i;
-
- if (IS_NOT_NULL(node)) {
- for (i = 0; i < node->num_childs; i++) {
- if (IS_NOT_NULL(node->childs[i])) {
- history_tree_free(node->childs[i]);
- }
- }
- for (i = 0; i < node->allocated; i++) {
- node->childs[i] = (OnigCaptureTreeNode* )0;
- }
- node->num_childs = 0;
- node->beg = ONIG_REGION_NOTPOS;
- node->end = ONIG_REGION_NOTPOS;
- node->group = -1;
- }
-}
-
-static void
-history_tree_free(OnigCaptureTreeNode* node)
-{
- history_tree_clear(node);
- xfree(node);
-}
-
-static void
-history_root_free(OnigRegion* r)
-{
- if (IS_NOT_NULL(r->history_root)) {
- history_tree_free(r->history_root);
- r->history_root = (OnigCaptureTreeNode* )0;
- }
-}
-
-static OnigCaptureTreeNode*
-history_node_new()
-{
- OnigCaptureTreeNode* node;
-
- node = (OnigCaptureTreeNode* )xmalloc(sizeof(OnigCaptureTreeNode));
- CHECK_NULL_RETURN(node);
- node->childs = (OnigCaptureTreeNode** )0;
- node->allocated = 0;
- node->num_childs = 0;
- node->group = -1;
- node->beg = ONIG_REGION_NOTPOS;
- node->end = ONIG_REGION_NOTPOS;
-
- return node;
-}
-
-static int
-history_tree_add_child(OnigCaptureTreeNode* parent, OnigCaptureTreeNode* child)
-{
-#define HISTORY_TREE_INIT_ALLOC_SIZE 8
-
- if (parent->num_childs >= parent->allocated) {
- int n, i;
-
- if (IS_NULL(parent->childs)) {
- n = HISTORY_TREE_INIT_ALLOC_SIZE;
- parent->childs =
- (OnigCaptureTreeNode** )xmalloc(sizeof(OnigCaptureTreeNode*) * n);
- }
- else {
- n = parent->allocated * 2;
- parent->childs =
- (OnigCaptureTreeNode** )xrealloc(parent->childs,
- sizeof(OnigCaptureTreeNode*) * n);
- }
- CHECK_NULL_RETURN_VAL(parent->childs, ONIGERR_MEMORY);
- for (i = parent->allocated; i < n; i++) {
- parent->childs[i] = (OnigCaptureTreeNode* )0;
- }
- parent->allocated = n;
- }
-
- parent->childs[parent->num_childs] = child;
- parent->num_childs++;
- return 0;
-}
-
-static OnigCaptureTreeNode*
-history_tree_clone(OnigCaptureTreeNode* node)
-{
- int i;
- OnigCaptureTreeNode *clone, *child;
-
- clone = history_node_new();
- CHECK_NULL_RETURN(clone);
-
- clone->beg = node->beg;
- clone->end = node->end;
- for (i = 0; i < node->num_childs; i++) {
- child = history_tree_clone(node->childs[i]);
- if (IS_NULL(child)) {
- history_tree_free(clone);
- return (OnigCaptureTreeNode* )0;
- }
- history_tree_add_child(clone, child);
- }
-
- return clone;
-}
-
-extern OnigCaptureTreeNode*
-onig_get_capture_tree(OnigRegion* region)
-{
- return region->history_root;
-}
-#endif /* USE_CAPTURE_HISTORY */
-
-extern void
-onig_region_clear(OnigRegion* region)
-{
- int i;
-
- for (i = 0; i < region->num_regs; i++) {
- region->beg[i] = region->end[i] = ONIG_REGION_NOTPOS;
- }
-#ifdef USE_CAPTURE_HISTORY
- history_root_free(region);
-#endif
-}
-
-extern int
-onig_region_resize(OnigRegion* region, int n)
-{
- region->num_regs = n;
-
- if (n < ONIG_NREGION)
- n = ONIG_NREGION;
-
- if (region->allocated == 0) {
- region->beg = (int* )xmalloc(n * sizeof(int));
- region->end = (int* )xmalloc(n * sizeof(int));
-
- if (region->beg == 0 || region->end == 0)
- return ONIGERR_MEMORY;
-
- region->allocated = n;
- }
- else if (region->allocated < n) {
- region->beg = (int* )xrealloc(region->beg, n * sizeof(int));
- region->end = (int* )xrealloc(region->end, n * sizeof(int));
-
- if (region->beg == 0 || region->end == 0)
- return ONIGERR_MEMORY;
-
- region->allocated = n;
- }
-
- return 0;
-}
-
-extern int
-onig_region_resize_clear(OnigRegion* region, int n)
-{
- int r;
-
- r = onig_region_resize(region, n);
- if (r != 0) return r;
- onig_region_clear(region);
- return 0;
-}
-
-extern int
-onig_region_set(OnigRegion* region, int at, int beg, int end)
-{
- if (at < 0) return ONIGERR_INVALID_ARGUMENT;
-
- if (at >= region->allocated) {
- int r = onig_region_resize(region, at + 1);
- if (r < 0) return r;
- }
-
- region->beg[at] = beg;
- region->end[at] = end;
- return 0;
-}
-
-extern void
-onig_region_init(OnigRegion* region)
-{
- region->num_regs = 0;
- region->allocated = 0;
- region->beg = (int* )0;
- region->end = (int* )0;
- region->history_root = (OnigCaptureTreeNode* )0;
-}
-
-extern OnigRegion*
-onig_region_new()
-{
- OnigRegion* r;
-
- r = (OnigRegion* )xmalloc(sizeof(OnigRegion));
- onig_region_init(r);
- return r;
-}
-
-extern void
-onig_region_free(OnigRegion* r, int free_self)
-{
- if (r) {
- if (r->allocated > 0) {
- if (r->beg) xfree(r->beg);
- if (r->end) xfree(r->end);
- r->allocated = 0;
- }
-#ifdef USE_CAPTURE_HISTORY
- history_root_free(r);
-#endif
- if (free_self) xfree(r);
- }
-}
-
-extern void
-onig_region_copy(OnigRegion* to, OnigRegion* from)
-{
-#define RREGC_SIZE (sizeof(int) * from->num_regs)
- int i;
-
- if (to == from) return;
-
- if (to->allocated == 0) {
- if (from->num_regs > 0) {
- to->beg = (int* )xmalloc(RREGC_SIZE);
- to->end = (int* )xmalloc(RREGC_SIZE);
- to->allocated = from->num_regs;
- }
- }
- else if (to->allocated < from->num_regs) {
- to->beg = (int* )xrealloc(to->beg, RREGC_SIZE);
- to->end = (int* )xrealloc(to->end, RREGC_SIZE);
- to->allocated = from->num_regs;
- }
-
- for (i = 0; i < from->num_regs; i++) {
- to->beg[i] = from->beg[i];
- to->end[i] = from->end[i];
- }
- to->num_regs = from->num_regs;
-
-#ifdef USE_CAPTURE_HISTORY
- history_root_free(to);
-
- if (IS_NOT_NULL(from->history_root)) {
- to->history_root = history_tree_clone(from->history_root);
- }
-#endif
-}
-
-
-/** stack **/
-#define INVALID_STACK_INDEX -1
-typedef long StackIndex;
-
-typedef struct _StackType {
- unsigned int type;
- union {
- struct {
- UChar *pcode; /* byte code position */
- UChar *pstr; /* string position */
- UChar *pstr_prev; /* previous char position of pstr */
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- unsigned int state_check;
-#endif
- } state;
- struct {
- int count; /* for OP_REPEAT_INC, OP_REPEAT_INC_NG */
- UChar *pcode; /* byte code position (head of repeated target) */
- int num; /* repeat id */
- } repeat;
- struct {
- StackIndex si; /* index of stack */
- } repeat_inc;
- struct {
- int num; /* memory num */
- UChar *pstr; /* start/end position */
- /* Following information is setted, if this stack type is MEM-START */
- StackIndex start; /* prev. info (for backtrack "(...)*" ) */
- StackIndex end; /* prev. info (for backtrack "(...)*" ) */
- } mem;
- struct {
- int num; /* null check id */
- UChar *pstr; /* start position */
- } null_check;
-#ifdef USE_SUBEXP_CALL
- struct {
- UChar *ret_addr; /* byte code position */
- int num; /* null check id */
- UChar *pstr; /* string position */
- } call_frame;
-#endif
- } u;
-} StackType;
-
-/* stack type */
-/* used by normal-POP */
-#define STK_ALT 0x0001
-#define STK_LOOK_BEHIND_NOT 0x0002
-#define STK_POS_NOT 0x0003
-/* handled by normal-POP */
-#define STK_MEM_START 0x0100
-#define STK_MEM_END 0x8200
-#define STK_REPEAT_INC 0x0300
-#define STK_STATE_CHECK_MARK 0x1000
-/* avoided by normal-POP */
-#define STK_NULL_CHECK_START 0x3000
-#define STK_NULL_CHECK_END 0x5000 /* for recursive call */
-#define STK_MEM_END_MARK 0x8400
-#define STK_POS 0x0500 /* used when POP-POS */
-#define STK_STOP_BT 0x0600 /* mark for "(?>...)" */
-#define STK_REPEAT 0x0700
-#define STK_CALL_FRAME 0x0800
-#define STK_RETURN 0x0900
-#define STK_VOID 0x0a00 /* for fill a blank */
-
-/* stack type check mask */
-#define STK_MASK_POP_USED 0x00ff
-#define STK_MASK_TO_VOID_TARGET 0x10ff
-#define STK_MASK_MEM_END_OR_MARK 0x8000 /* MEM_END or MEM_END_MARK */
-
-typedef struct {
- void* stack_p;
- int stack_n;
- OnigOptionType options;
- OnigRegion* region;
- const UChar* start; /* search start position (for \G: BEGIN_POSITION) */
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- void* state_check_buff;
- int state_check_buff_size;
-#endif
-} MatchArg;
-
-#define MATCH_ARG_INIT(msa, arg_option, arg_region, arg_start) do {\
- (msa).stack_p = (void* )0;\
- (msa).options = (arg_option);\
- (msa).region = (arg_region);\
- (msa).start = (arg_start);\
-} while (0)
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
-
-#define STATE_CHECK_BUFF_MALLOC_THRESHOLD_SIZE 16
-
-#define STATE_CHECK_BUFF_INIT(msa, str_len, offset, state_num) do { \
- if ((state_num) > 0 && str_len >= STATE_CHECK_STRING_THRESHOLD_LEN) {\
- unsigned int size = (unsigned int )(((str_len) + 1) * (state_num) + 7) >> 3;\
- offset = ((offset) * (state_num)) >> 3;\
- if (size > 0 && offset < size && size < STATE_CHECK_BUFF_MAX_SIZE) {\
- if (size >= STATE_CHECK_BUFF_MALLOC_THRESHOLD_SIZE) \
- (msa).state_check_buff = (void* )xmalloc(size);\
- else \
- (msa).state_check_buff = (void* )xalloca(size);\
- xmemset(((char* )((msa).state_check_buff)+(offset)), 0, \
- (size_t )(size - (offset))); \
- (msa).state_check_buff_size = size;\
- }\
- else {\
- (msa).state_check_buff = (void* )0;\
- (msa).state_check_buff_size = 0;\
- }\
- }\
- else {\
- (msa).state_check_buff = (void* )0;\
- (msa).state_check_buff_size = 0;\
- }\
-} while (0)
-
-#define MATCH_ARG_FREE(msa) do {\
- if ((msa).stack_p) xfree((msa).stack_p);\
- if ((msa).state_check_buff_size >= STATE_CHECK_BUFF_MALLOC_THRESHOLD_SIZE) { \
- if ((msa).state_check_buff) xfree((msa).state_check_buff);\
- }\
-} while (0);
-#else
-#define STATE_CHECK_BUFF_INIT(msa, str_len, offset, state_num)
-#define MATCH_ARG_FREE(msa) if ((msa).stack_p) xfree((msa).stack_p)
-#endif
-
-
-
-#define STACK_INIT(alloc_addr, ptr_num, stack_num) do {\
- if (msa->stack_p) {\
- alloc_addr = (char* )xalloca(sizeof(char*) * (ptr_num));\
- stk_alloc = (StackType* )(msa->stack_p);\
- stk_base = stk_alloc;\
- stk = stk_base;\
- stk_end = stk_base + msa->stack_n;\
- }\
- else {\
- alloc_addr = (char* )xalloca(sizeof(char*) * (ptr_num)\
- + sizeof(StackType) * (stack_num));\
- stk_alloc = (StackType* )(alloc_addr + sizeof(char*) * (ptr_num));\
- stk_base = stk_alloc;\
- stk = stk_base;\
- stk_end = stk_base + (stack_num);\
- }\
-} while(0)
-
-#define STACK_SAVE do{\
- if (stk_base != stk_alloc) {\
- msa->stack_p = stk_base;\
- msa->stack_n = stk_end - stk_base;\
- };\
-} while(0)
-
-static unsigned int MatchStackLimitSize = DEFAULT_MATCH_STACK_LIMIT_SIZE;
-
-extern unsigned int
-onig_get_match_stack_limit_size(void)
-{
- return MatchStackLimitSize;
-}
-
-extern int
-onig_set_match_stack_limit_size(unsigned int size)
-{
- MatchStackLimitSize = size;
- return 0;
-}
-
-static int
-stack_double(StackType** arg_stk_base, StackType** arg_stk_end,
- StackType** arg_stk, StackType* stk_alloc, MatchArg* msa)
-{
- unsigned int n;
- StackType *x, *stk_base, *stk_end, *stk;
-
- stk_base = *arg_stk_base;
- stk_end = *arg_stk_end;
- stk = *arg_stk;
-
- n = stk_end - stk_base;
- if (stk_base == stk_alloc && IS_NULL(msa->stack_p)) {
- x = (StackType* )xmalloc(sizeof(StackType) * n * 2);
- if (IS_NULL(x)) {
- STACK_SAVE;
- return ONIGERR_MEMORY;
- }
- xmemcpy(x, stk_base, n * sizeof(StackType));
- n *= 2;
- }
- else {
- n *= 2;
- if (MatchStackLimitSize != 0 && n > MatchStackLimitSize) {
- if ((unsigned int )(stk_end - stk_base) == MatchStackLimitSize)
- return ONIGERR_MATCH_STACK_LIMIT_OVER;
- else
- n = MatchStackLimitSize;
- }
- x = (StackType* )xrealloc(stk_base, sizeof(StackType) * n);
- if (IS_NULL(x)) {
- STACK_SAVE;
- return ONIGERR_MEMORY;
- }
- }
- *arg_stk = x + (stk - stk_base);
- *arg_stk_base = x;
- *arg_stk_end = x + n;
- return 0;
-}
-
-#define STACK_ENSURE(n) do {\
- if (stk_end - stk < (n)) {\
- int r = stack_double(&stk_base, &stk_end, &stk, stk_alloc, msa);\
- if (r != 0) { STACK_SAVE; return r; } \
- }\
-} while(0)
-
-#define STACK_AT(index) (stk_base + (index))
-#define GET_STACK_INDEX(stk) ((stk) - stk_base)
-
-#define STACK_PUSH_TYPE(stack_type) do {\
- STACK_ENSURE(1);\
- stk->type = (stack_type);\
- STACK_INC;\
-} while(0)
-
-#define IS_TO_VOID_TARGET(stk) (((stk)->type & STK_MASK_TO_VOID_TARGET) != 0)
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
-#define STATE_CHECK_POS(s,snum) \
- (((s) - str) * num_comb_exp_check + ((snum) - 1))
-#define STATE_CHECK_VAL(v,snum) do {\
- if (state_check_buff != NULL) {\
- int x = STATE_CHECK_POS(s,snum);\
- (v) = state_check_buff[x/8] & (1<<(x%8));\
- }\
- else (v) = 0;\
-} while(0)
-
-
-#define ELSE_IF_STATE_CHECK_MARK(stk) \
- else if ((stk)->type == STK_STATE_CHECK_MARK) { \
- int x = STATE_CHECK_POS(stk->u.state.pstr, stk->u.state.state_check);\
- state_check_buff[x/8] |= (1<<(x%8)); \
- }
-
-#define STACK_PUSH(stack_type,pat,s,sprev) do {\
- STACK_ENSURE(1);\
- stk->type = (stack_type);\
- stk->u.state.pcode = (pat);\
- stk->u.state.pstr = (s);\
- stk->u.state.pstr_prev = (sprev);\
- stk->u.state.state_check = 0;\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_ENSURED(stack_type,pat) do {\
- stk->type = (stack_type);\
- stk->u.state.pcode = (pat);\
- stk->u.state.state_check = 0;\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_ALT_WITH_STATE_CHECK(pat,s,sprev,snum) do {\
- STACK_ENSURE(1);\
- stk->type = STK_ALT;\
- stk->u.state.pcode = (pat);\
- stk->u.state.pstr = (s);\
- stk->u.state.pstr_prev = (sprev);\
- stk->u.state.state_check = ((state_check_buff != NULL) ? (snum) : 0);\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_STATE_CHECK(s,snum) do {\
- if (state_check_buff != NULL) {\
- STACK_ENSURE(1);\
- stk->type = STK_STATE_CHECK_MARK;\
- stk->u.state.pstr = (s);\
- stk->u.state.state_check = (snum);\
- STACK_INC;\
- }\
-} while(0)
-
-#else /* USE_COMBINATION_EXPLOSION_CHECK */
-
-#define ELSE_IF_STATE_CHECK_MARK(stk)
-
-#define STACK_PUSH(stack_type,pat,s,sprev) do {\
- STACK_ENSURE(1);\
- stk->type = (stack_type);\
- stk->u.state.pcode = (pat);\
- stk->u.state.pstr = (s);\
- stk->u.state.pstr_prev = (sprev);\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_ENSURED(stack_type,pat) do {\
- stk->type = (stack_type);\
- stk->u.state.pcode = (pat);\
- STACK_INC;\
-} while(0)
-#endif /* USE_COMBINATION_EXPLOSION_CHECK */
-
-#define STACK_PUSH_ALT(pat,s,sprev) STACK_PUSH(STK_ALT,pat,s,sprev)
-#define STACK_PUSH_POS(s,sprev) STACK_PUSH(STK_POS,NULL_UCHARP,s,sprev)
-#define STACK_PUSH_POS_NOT(pat,s,sprev) STACK_PUSH(STK_POS_NOT,pat,s,sprev)
-#define STACK_PUSH_STOP_BT STACK_PUSH_TYPE(STK_STOP_BT)
-#define STACK_PUSH_LOOK_BEHIND_NOT(pat,s,sprev) \
- STACK_PUSH(STK_LOOK_BEHIND_NOT,pat,s,sprev)
-
-#define STACK_PUSH_REPEAT(id, pat) do {\
- STACK_ENSURE(1);\
- stk->type = STK_REPEAT;\
- stk->u.repeat.num = (id);\
- stk->u.repeat.pcode = (pat);\
- stk->u.repeat.count = 0;\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_REPEAT_INC(sindex) do {\
- STACK_ENSURE(1);\
- stk->type = STK_REPEAT_INC;\
- stk->u.repeat_inc.si = (sindex);\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_MEM_START(mnum, s) do {\
- STACK_ENSURE(1);\
- stk->type = STK_MEM_START;\
- stk->u.mem.num = (mnum);\
- stk->u.mem.pstr = (s);\
- stk->u.mem.start = mem_start_stk[mnum];\
- stk->u.mem.end = mem_end_stk[mnum];\
- mem_start_stk[mnum] = GET_STACK_INDEX(stk);\
- mem_end_stk[mnum] = INVALID_STACK_INDEX;\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_MEM_END(mnum, s) do {\
- STACK_ENSURE(1);\
- stk->type = STK_MEM_END;\
- stk->u.mem.num = (mnum);\
- stk->u.mem.pstr = (s);\
- stk->u.mem.start = mem_start_stk[mnum];\
- stk->u.mem.end = mem_end_stk[mnum];\
- mem_end_stk[mnum] = GET_STACK_INDEX(stk);\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_MEM_END_MARK(mnum) do {\
- STACK_ENSURE(1);\
- stk->type = STK_MEM_END_MARK;\
- stk->u.mem.num = (mnum);\
- STACK_INC;\
-} while(0)
-
-#define STACK_GET_MEM_START(mnum, k) do {\
- int level = 0;\
- k = stk;\
- while (k > stk_base) {\
- k--;\
- if ((k->type & STK_MASK_MEM_END_OR_MARK) != 0 \
- && k->u.mem.num == (mnum)) {\
- level++;\
- }\
- else if (k->type == STK_MEM_START && k->u.mem.num == (mnum)) {\
- if (level == 0) break;\
- level--;\
- }\
- }\
-} while (0)
-
-#define STACK_GET_MEM_RANGE(k, mnum, start, end) do {\
- int level = 0;\
- while (k < stk) {\
- if (k->type == STK_MEM_START && k->u.mem.num == (mnum)) {\
- if (level == 0) (start) = k->u.mem.pstr;\
- level++;\
- }\
- else if (k->type == STK_MEM_END && k->u.mem.num == (mnum)) {\
- level--;\
- if (level == 0) {\
- (end) = k->u.mem.pstr;\
- break;\
- }\
- }\
- k++;\
- }\
-} while (0)
-
-#define STACK_PUSH_NULL_CHECK_START(cnum, s) do {\
- STACK_ENSURE(1);\
- stk->type = STK_NULL_CHECK_START;\
- stk->u.null_check.num = (cnum);\
- stk->u.null_check.pstr = (s);\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_NULL_CHECK_END(cnum) do {\
- STACK_ENSURE(1);\
- stk->type = STK_NULL_CHECK_END;\
- stk->u.null_check.num = (cnum);\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_CALL_FRAME(pat) do {\
- STACK_ENSURE(1);\
- stk->type = STK_CALL_FRAME;\
- stk->u.call_frame.ret_addr = (pat);\
- STACK_INC;\
-} while(0)
-
-#define STACK_PUSH_RETURN do {\
- STACK_ENSURE(1);\
- stk->type = STK_RETURN;\
- STACK_INC;\
-} while(0)
-
-
-#ifdef ONIG_DEBUG
-#define STACK_BASE_CHECK(p, at) \
- if ((p) < stk_base) {\
- fprintf(stderr, "at %s\n", at);\
- goto stack_error;\
- }
-#else
-#define STACK_BASE_CHECK(p, at)
-#endif
-
-#define STACK_POP_ONE do {\
- stk--;\
- STACK_BASE_CHECK(stk, "STACK_POP_ONE"); \
-} while(0)
-
-#define STACK_POP do {\
- switch (pop_level) {\
- case STACK_POP_LEVEL_FREE:\
- while (1) {\
- stk--;\
- STACK_BASE_CHECK(stk, "STACK_POP"); \
- if ((stk->type & STK_MASK_POP_USED) != 0) break;\
- ELSE_IF_STATE_CHECK_MARK(stk);\
- }\
- break;\
- case STACK_POP_LEVEL_MEM_START:\
- while (1) {\
- stk--;\
- STACK_BASE_CHECK(stk, "STACK_POP 2"); \
- if ((stk->type & STK_MASK_POP_USED) != 0) break;\
- else if (stk->type == STK_MEM_START) {\
- mem_start_stk[stk->u.mem.num] = stk->u.mem.start;\
- mem_end_stk[stk->u.mem.num] = stk->u.mem.end;\
- }\
- ELSE_IF_STATE_CHECK_MARK(stk);\
- }\
- break;\
- default:\
- while (1) {\
- stk--;\
- STACK_BASE_CHECK(stk, "STACK_POP 3"); \
- if ((stk->type & STK_MASK_POP_USED) != 0) break;\
- else if (stk->type == STK_MEM_START) {\
- mem_start_stk[stk->u.mem.num] = stk->u.mem.start;\
- mem_end_stk[stk->u.mem.num] = stk->u.mem.end;\
- }\
- else if (stk->type == STK_REPEAT_INC) {\
- STACK_AT(stk->u.repeat_inc.si)->u.repeat.count--;\
- }\
- else if (stk->type == STK_MEM_END) {\
- mem_start_stk[stk->u.mem.num] = stk->u.mem.start;\
- mem_end_stk[stk->u.mem.num] = stk->u.mem.end;\
- }\
- ELSE_IF_STATE_CHECK_MARK(stk);\
- }\
- break;\
- }\
-} while(0)
-
-#define STACK_POP_TIL_POS_NOT do {\
- while (1) {\
- stk--;\
- STACK_BASE_CHECK(stk, "STACK_POP_TIL_POS_NOT"); \
- if (stk->type == STK_POS_NOT) break;\
- else if (stk->type == STK_MEM_START) {\
- mem_start_stk[stk->u.mem.num] = stk->u.mem.start;\
- mem_end_stk[stk->u.mem.num] = stk->u.mem.end;\
- }\
- else if (stk->type == STK_REPEAT_INC) {\
- STACK_AT(stk->u.repeat_inc.si)->u.repeat.count--;\
- }\
- else if (stk->type == STK_MEM_END) {\
- mem_start_stk[stk->u.mem.num] = stk->u.mem.start;\
- mem_end_stk[stk->u.mem.num] = stk->u.mem.end;\
- }\
- ELSE_IF_STATE_CHECK_MARK(stk);\
- }\
-} while(0)
-
-#define STACK_POP_TIL_LOOK_BEHIND_NOT do {\
- while (1) {\
- stk--;\
- STACK_BASE_CHECK(stk, "STACK_POP_TIL_LOOK_BEHIND_NOT"); \
- if (stk->type == STK_LOOK_BEHIND_NOT) break;\
- else if (stk->type == STK_MEM_START) {\
- mem_start_stk[stk->u.mem.num] = stk->u.mem.start;\
- mem_end_stk[stk->u.mem.num] = stk->u.mem.end;\
- }\
- else if (stk->type == STK_REPEAT_INC) {\
- STACK_AT(stk->u.repeat_inc.si)->u.repeat.count--;\
- }\
- else if (stk->type == STK_MEM_END) {\
- mem_start_stk[stk->u.mem.num] = stk->u.mem.start;\
- mem_end_stk[stk->u.mem.num] = stk->u.mem.end;\
- }\
- ELSE_IF_STATE_CHECK_MARK(stk);\
- }\
-} while(0)
-
-#define STACK_POS_END(k) do {\
- k = stk;\
- while (1) {\
- k--;\
- STACK_BASE_CHECK(k, "STACK_POS_END"); \
- if (IS_TO_VOID_TARGET(k)) {\
- k->type = STK_VOID;\
- }\
- else if (k->type == STK_POS) {\
- k->type = STK_VOID;\
- break;\
- }\
- }\
-} while(0)
-
-#define STACK_STOP_BT_END do {\
- StackType *k = stk;\
- while (1) {\
- k--;\
- STACK_BASE_CHECK(k, "STACK_STOP_BT_END"); \
- if (IS_TO_VOID_TARGET(k)) {\
- k->type = STK_VOID;\
- }\
- else if (k->type == STK_STOP_BT) {\
- k->type = STK_VOID;\
- break;\
- }\
- }\
-} while(0)
-
-#define STACK_NULL_CHECK(isnull,id,s) do {\
- StackType* k = stk;\
- while (1) {\
- k--;\
- STACK_BASE_CHECK(k, "STACK_NULL_CHECK"); \
- if (k->type == STK_NULL_CHECK_START) {\
- if (k->u.null_check.num == (id)) {\
- (isnull) = (k->u.null_check.pstr == (s));\
- break;\
- }\
- }\
- }\
-} while(0)
-
-#define STACK_NULL_CHECK_REC(isnull,id,s) do {\
- int level = 0;\
- StackType* k = stk;\
- while (1) {\
- k--;\
- STACK_BASE_CHECK(k, "STACK_NULL_CHECK_REC"); \
- if (k->type == STK_NULL_CHECK_START) {\
- if (k->u.null_check.num == (id)) {\
- if (level == 0) {\
- (isnull) = (k->u.null_check.pstr == (s));\
- break;\
- }\
- else level--;\
- }\
- }\
- else if (k->type == STK_NULL_CHECK_END) {\
- level++;\
- }\
- }\
-} while(0)
-
-#define STACK_NULL_CHECK_MEMST(isnull,id,s,reg) do {\
- StackType* k = stk;\
- while (1) {\
- k--;\
- STACK_BASE_CHECK(k, "STACK_NULL_CHECK_MEMST"); \
- if (k->type == STK_NULL_CHECK_START) {\
- if (k->u.null_check.num == (id)) {\
- if (k->u.null_check.pstr != (s)) {\
- (isnull) = 0;\
- break;\
- }\
- else {\
- UChar* endp;\
- (isnull) = 1;\
- while (k < stk) {\
- if (k->type == STK_MEM_START) {\
- if (k->u.mem.end == INVALID_STACK_INDEX) {\
- (isnull) = 0; break;\
- }\
- if (BIT_STATUS_AT(reg->bt_mem_end, k->u.mem.num))\
- endp = STACK_AT(k->u.mem.end)->u.mem.pstr;\
- else\
- endp = (UChar* )k->u.mem.end;\
- if (STACK_AT(k->u.mem.start)->u.mem.pstr != endp) {\
- (isnull) = 0; break;\
- }\
- else if (endp != s) {\
- (isnull) = -1; /* empty, but position changed */ \
- }\
- }\
- k++;\
- }\
- break;\
- }\
- }\
- }\
- }\
-} while(0)
-
-#define STACK_NULL_CHECK_MEMST_REC(isnull,id,s,reg) do {\
- int level = 0;\
- StackType* k = stk;\
- while (1) {\
- k--;\
- STACK_BASE_CHECK(k, "STACK_NULL_CHECK_MEMST_REC"); \
- if (k->type == STK_NULL_CHECK_START) {\
- if (k->u.null_check.num == (id)) {\
- if (level == 0) {\
- if (k->u.null_check.pstr != (s)) {\
- (isnull) = 0;\
- break;\
- }\
- else {\
- UChar* endp;\
- (isnull) = 1;\
- while (k < stk) {\
- if (k->type == STK_MEM_START) {\
- if (k->u.mem.end == INVALID_STACK_INDEX) {\
- (isnull) = 0; break;\
- }\
- if (BIT_STATUS_AT(reg->bt_mem_end, k->u.mem.num))\
- endp = STACK_AT(k->u.mem.end)->u.mem.pstr;\
- else\
- endp = (UChar* )k->u.mem.end;\
- if (STACK_AT(k->u.mem.start)->u.mem.pstr != endp) {\
- (isnull) = 0; break;\
- }\
- else if (endp != s) {\
- (isnull) = -1; /* empty, but position changed */ \
- }\
- }\
- k++;\
- }\
- break;\
- }\
- }\
- else {\
- level--;\
- }\
- }\
- }\
- else if (k->type == STK_NULL_CHECK_END) {\
- if (k->u.null_check.num == (id)) level++;\
- }\
- }\
-} while(0)
-
-#define STACK_GET_REPEAT(id, k) do {\
- int level = 0;\
- k = stk;\
- while (1) {\
- k--;\
- STACK_BASE_CHECK(k, "STACK_GET_REPEAT"); \
- if (k->type == STK_REPEAT) {\
- if (level == 0) {\
- if (k->u.repeat.num == (id)) {\
- break;\
- }\
- }\
- }\
- else if (k->type == STK_CALL_FRAME) level--;\
- else if (k->type == STK_RETURN) level++;\
- }\
-} while (0)
-
-#define STACK_RETURN(addr) do {\
- int level = 0;\
- StackType* k = stk;\
- while (1) {\
- k--;\
- STACK_BASE_CHECK(k, "STACK_RETURN"); \
- if (k->type == STK_CALL_FRAME) {\
- if (level == 0) {\
- (addr) = k->u.call_frame.ret_addr;\
- break;\
- }\
- else level--;\
- }\
- else if (k->type == STK_RETURN)\
- level++;\
- }\
-} while(0)
-
-
-#define STRING_CMP(s1,s2,len) do {\
- while (len-- > 0) {\
- if (*s1++ != *s2++) goto fail;\
- }\
-} while(0)
-
-#define STRING_CMP_IC(ambig_flag,s1,ps2,len) do {\
- if (string_cmp_ic(encode, ambig_flag, s1, ps2, len) == 0) \
- goto fail; \
-} while(0)
-
-static int string_cmp_ic(OnigEncoding enc, int ambig_flag,
- UChar* s1, UChar** ps2, int mblen)
-{
- UChar buf1[ONIGENC_MBC_NORMALIZE_MAXLEN];
- UChar buf2[ONIGENC_MBC_NORMALIZE_MAXLEN];
- UChar *p1, *p2, *end, *s2, *end2;
- int len1, len2;
-
- s2 = *ps2;
- end = s1 + mblen;
- end2 = s2 + mblen;
- while (s1 < end) {
- len1 = ONIGENC_MBC_TO_NORMALIZE(enc, ambig_flag, &s1, end, buf1);
- len2 = ONIGENC_MBC_TO_NORMALIZE(enc, ambig_flag, &s2, end2, buf2);
- if (len1 != len2) return 0;
- p1 = buf1;
- p2 = buf2;
- while (len1-- > 0) {
- if (*p1 != *p2) return 0;
- p1++;
- p2++;
- }
- }
-
- *ps2 = s2;
- return 1;
-}
-
-#define STRING_CMP_VALUE(s1,s2,len,is_fail) do {\
- is_fail = 0;\
- while (len-- > 0) {\
- if (*s1++ != *s2++) {\
- is_fail = 1; break;\
- }\
- }\
-} while(0)
-
-#define STRING_CMP_VALUE_IC(ambig_flag,s1,ps2,len,is_fail) do {\
- if (string_cmp_ic(encode, ambig_flag, s1, ps2, len) == 0) \
- is_fail = 1; \
- else \
- is_fail = 0; \
-} while(0)
-
-
-#define ON_STR_BEGIN(s) ((s) == str)
-#define ON_STR_END(s) ((s) == end)
-#define IS_EMPTY_STR (str == end)
-
-#define DATA_ENSURE(n) \
- if (s + (n) > end) goto fail
-
-#define DATA_ENSURE_CHECK(n) (s + (n) <= end)
-
-#ifdef USE_CAPTURE_HISTORY
-static int
-make_capture_history_tree(OnigCaptureTreeNode* node, StackType** kp,
- StackType* stk_top, UChar* str, regex_t* reg)
-{
- int n, r;
- OnigCaptureTreeNode* child;
- StackType* k = *kp;
-
- while (k < stk_top) {
- if (k->type == STK_MEM_START) {
- n = k->u.mem.num;
- if (n <= ONIG_MAX_CAPTURE_HISTORY_GROUP &&
- BIT_STATUS_AT(reg->capture_history, n) != 0) {
- child = history_node_new();
- CHECK_NULL_RETURN_VAL(child, ONIGERR_MEMORY);
- child->group = n;
- child->beg = (int )(k->u.mem.pstr - str);
- r = history_tree_add_child(node, child);
- if (r != 0) return r;
- *kp = (k + 1);
- r = make_capture_history_tree(child, kp, stk_top, str, reg);
- if (r != 0) return r;
-
- k = *kp;
- child->end = (int )(k->u.mem.pstr - str);
- }
- }
- else if (k->type == STK_MEM_END) {
- if (k->u.mem.num == node->group) {
- node->end = (int )(k->u.mem.pstr - str);
- *kp = k;
- return 0;
- }
- }
- k++;
- }
-
- return 1; /* 1: root node ending. */
-}
-#endif
-
-#ifdef USE_BACKREF_AT_LEVEL
-static int mem_is_in_memp(int mem, int num, UChar* memp)
-{
- int i;
- MemNumType m;
-
- for (i = 0; i < num; i++) {
- GET_MEMNUM_INC(m, memp);
- if (mem == (int )m) return 1;
- }
- return 0;
-}
-
-static int backref_match_at_nested_level(regex_t* reg
- , StackType* top, StackType* stk_base
- , int ignore_case, int ambig_flag
- , int nest, int mem_num, UChar* memp, UChar** s, const UChar* send)
-{
- UChar *ss, *p, *pstart, *pend = NULL_UCHARP;
- int level;
- StackType* k;
-
- level = 0;
- k = top;
- k--;
- while (k >= stk_base) {
- if (k->type == STK_CALL_FRAME) {
- level--;
- }
- else if (k->type == STK_RETURN) {
- level++;
- }
- else if (level == nest) {
- if (k->type == STK_MEM_START) {
- if (mem_is_in_memp(k->u.mem.num, mem_num, memp)) {
- pstart = k->u.mem.pstr;
- if (pend != NULL_UCHARP) {
- if (pend - pstart > send - *s) return 0; /* or goto next_mem; */
- p = pstart;
- ss = *s;
-
- if (ignore_case != 0) {
- if (string_cmp_ic(reg->enc, ambig_flag,
- pstart, &ss, (int )(pend - pstart)) == 0)
- return 0; /* or goto next_mem; */
- }
- else {
- while (p < pend) {
- if (*p++ != *ss++) return 0; /* or goto next_mem; */
- }
- }
-
- *s = ss;
- return 1;
- }
- }
- }
- else if (k->type == STK_MEM_END) {
- if (mem_is_in_memp(k->u.mem.num, mem_num, memp)) {
- pend = k->u.mem.pstr;
- }
- }
- }
- k--;
- }
-
- return 0;
-}
-#endif /* USE_BACKREF_AT_LEVEL */
-
-
-#ifdef RUBY_PLATFORM
-
-typedef struct {
- int state;
- regex_t* reg;
- MatchArg* msa;
- StackType* stk_base;
-} TrapEnsureArg;
-
-static VALUE
-trap_ensure(VALUE arg)
-{
- TrapEnsureArg* ta = (TrapEnsureArg* )arg;
-
- if (ta->state == 0) { /* trap_exec() is not normal return */
- ONIG_STATE_DEC_THREAD(ta->reg);
- if (! IS_NULL(ta->msa->stack_p) && ta->stk_base != ta->msa->stack_p)
- xfree(ta->stk_base);
-
- MATCH_ARG_FREE(*(ta->msa));
- }
-
- return Qnil;
-}
-
-static VALUE
-trap_exec(VALUE arg)
-{
- TrapEnsureArg* ta;
-
- rb_trap_exec();
-
- ta = (TrapEnsureArg* )arg;
- ta->state = 1; /* normal return */
- return Qnil;
-}
-
-extern void
-onig_exec_trap(regex_t* reg, MatchArg* msa, StackType* stk_base)
-{
- VALUE arg;
- TrapEnsureArg ta;
-
- ta.state = 0;
- ta.reg = reg;
- ta.msa = msa;
- ta.stk_base = stk_base;
- arg = (VALUE )(&ta);
- rb_ensure(trap_exec, arg, trap_ensure, arg);
-}
-
-#define CHECK_INTERRUPT_IN_MATCH_AT do {\
- if (rb_trap_pending) {\
- if (! rb_prohibit_interrupt) {\
- onig_exec_trap(reg, msa, stk_base);\
- }\
- }\
-} while (0)
-#else
-#define CHECK_INTERRUPT_IN_MATCH_AT
-#endif /* RUBY_PLATFORM */
-
-#ifdef ONIG_DEBUG_STATISTICS
-
-#define USE_TIMEOFDAY
-
-#ifdef USE_TIMEOFDAY
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-static struct timeval ts, te;
-#define GETTIME(t) gettimeofday(&(t), (struct timezone* )0)
-#define TIMEDIFF(te,ts) (((te).tv_usec - (ts).tv_usec) + \
- (((te).tv_sec - (ts).tv_sec)*1000000))
-#else
-#ifdef HAVE_SYS_TIMES_H
-#include <sys/times.h>
-#endif
-static struct tms ts, te;
-#define GETTIME(t) times(&(t))
-#define TIMEDIFF(te,ts) ((te).tms_utime - (ts).tms_utime)
-#endif
-
-static int OpCounter[256];
-static int OpPrevCounter[256];
-static unsigned long OpTime[256];
-static int OpCurr = OP_FINISH;
-static int OpPrevTarget = OP_FAIL;
-static int MaxStackDepth = 0;
-
-#define STAT_OP_IN(opcode) do {\
- if (opcode == OpPrevTarget) OpPrevCounter[OpCurr]++;\
- OpCurr = opcode;\
- OpCounter[opcode]++;\
- GETTIME(ts);\
-} while (0)
-
-#define STAT_OP_OUT do {\
- GETTIME(te);\
- OpTime[OpCurr] += TIMEDIFF(te, ts);\
-} while (0)
-
-#ifdef RUBY_PLATFORM
-
-/*
- * :nodoc:
- */
-static VALUE onig_stat_print()
-{
- onig_print_statistics(stderr);
- return Qnil;
-}
-#endif
-
-extern void onig_statistics_init()
-{
- int i;
- for (i = 0; i < 256; i++) {
- OpCounter[i] = OpPrevCounter[i] = 0; OpTime[i] = 0;
- }
- MaxStackDepth = 0;
-
-#ifdef RUBY_PLATFORM
- rb_define_global_function("onig_stat_print", onig_stat_print, 0);
-#endif
-}
-
-extern void
-onig_print_statistics(FILE* f)
-{
- int i;
- fprintf(f, " count prev time\n");
- for (i = 0; OnigOpInfo[i].opcode >= 0; i++) {
- fprintf(f, "%8d: %8d: %10ld: %s\n",
- OpCounter[i], OpPrevCounter[i], OpTime[i], OnigOpInfo[i].name);
- }
- fprintf(f, "\nmax stack depth: %d\n", MaxStackDepth);
-}
-
-#define STACK_INC do {\
- stk++;\
- if (stk - stk_base > MaxStackDepth) \
- MaxStackDepth = stk - stk_base;\
-} while (0)
-
-#else
-#define STACK_INC stk++
-
-#define STAT_OP_IN(opcode)
-#define STAT_OP_OUT
-#endif
-
-extern int
-onig_is_in_code_range(const UChar* p, OnigCodePoint code)
-{
- OnigCodePoint n, *data;
- OnigCodePoint low, high, x;
-
- GET_CODE_POINT(n, p);
- data = (OnigCodePoint* )p;
- data++;
-
- for (low = 0, high = n; low < high; ) {
- x = (low + high) >> 1;
- if (code > data[x * 2 + 1])
- low = x + 1;
- else
- high = x;
- }
-
- return ((low < n && code >= data[low * 2]) ? 1 : 0);
-}
-
-static int
-is_code_in_cc(int enclen, OnigCodePoint code, CClassNode* cc)
-{
- int found;
-
- if (enclen > 1 || (code >= SINGLE_BYTE_SIZE)) {
- if (IS_NULL(cc->mbuf)) {
- found = 0;
- }
- else {
- found = (onig_is_in_code_range(cc->mbuf->p, code) != 0 ? 1 : 0);
- }
- }
- else {
- found = (BITSET_AT(cc->bs, code) == 0 ? 0 : 1);
- }
-
- if (IS_CCLASS_NOT(cc))
- return !found;
- else
- return found;
-}
-
-extern int
-onig_is_code_in_cc(OnigEncoding enc, OnigCodePoint code, CClassNode* cc)
-{
- int len;
-
- if (ONIGENC_MBC_MINLEN(enc) > 1) {
- len = 2;
- }
- else {
- len = ONIGENC_CODE_TO_MBCLEN(enc, code);
- }
- return is_code_in_cc(len, code, cc);
-}
-
-
-/* matching region of POSIX API */
-typedef int regoff_t;
-
-typedef struct {
- regoff_t rm_so;
- regoff_t rm_eo;
-} posix_regmatch_t;
-
-/* match data(str - end) from position (sstart). */
-/* if sstart == str then set sprev to NULL. */
-static int
-match_at(regex_t* reg, const UChar* str, const UChar* end, const UChar* sstart,
- UChar* sprev, MatchArg* msa)
-{
- static UChar FinishCode[] = { OP_FINISH };
-
- int i, n, num_mem, best_len, pop_level;
- LengthType tlen, tlen2;
- MemNumType mem;
- RelAddrType addr;
- OnigOptionType option = reg->options;
- OnigEncoding encode = reg->enc;
- OnigAmbigType ambig_flag = reg->ambig_flag;
- UChar *s, *q, *sbegin;
- UChar *p = reg->p;
- char *alloca_base;
- StackType *stk_alloc, *stk_base, *stk, *stk_end;
- StackType *stkp; /* used as any purpose. */
- StackIndex si;
- StackIndex *repeat_stk;
- StackIndex *mem_start_stk, *mem_end_stk;
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- int scv;
- unsigned char* state_check_buff = msa->state_check_buff;
- int num_comb_exp_check = reg->num_comb_exp_check;
-#endif
- n = reg->num_repeat + reg->num_mem * 2;
-
- STACK_INIT(alloca_base, n, INIT_MATCH_STACK_SIZE);
- pop_level = reg->stack_pop_level;
- num_mem = reg->num_mem;
- repeat_stk = (StackIndex* )alloca_base;
-
- mem_start_stk = (StackIndex* )(repeat_stk + reg->num_repeat);
- mem_end_stk = mem_start_stk + num_mem;
- mem_start_stk--; /* for index start from 1,
- mem_start_stk[1]..mem_start_stk[num_mem] */
- mem_end_stk--; /* for index start from 1,
- mem_end_stk[1]..mem_end_stk[num_mem] */
- for (i = 1; i <= num_mem; i++) {
- mem_start_stk[i] = mem_end_stk[i] = INVALID_STACK_INDEX;
- }
-
-#ifdef ONIG_DEBUG_MATCH
- fprintf(stderr, "match_at: str: %d, end: %d, start: %d, sprev: %d\n",
- (int )str, (int )end, (int )sstart, (int )sprev);
- fprintf(stderr, "size: %d, start offset: %d\n",
- (int )(end - str), (int )(sstart - str));
-#endif
-
- STACK_PUSH_ENSURED(STK_ALT, FinishCode); /* bottom stack */
- best_len = ONIG_MISMATCH;
- s = (UChar* )sstart;
- while (1) {
-#ifdef ONIG_DEBUG_MATCH
- {
- UChar *q, *bp, buf[50];
- int len;
- fprintf(stderr, "%4d> \"", (int )(s - str));
- bp = buf;
- for (i = 0, q = s; i < 7 && q < end; i++) {
- len = enc_len(encode, q);
- while (len-- > 0) *bp++ = *q++;
- }
- if (q < end) { xmemcpy(bp, "...\"", 4); bp += 4; }
- else { xmemcpy(bp, "\"", 1); bp += 1; }
- *bp = 0;
- fputs(buf, stderr);
- for (i = 0; i < 20 - (bp - buf); i++) fputc(' ', stderr);
- onig_print_compiled_byte_code(stderr, p, NULL, encode);
- fprintf(stderr, "\n");
- }
-#endif
-
- sbegin = s;
- switch (*p++) {
- case OP_END: STAT_OP_IN(OP_END);
- n = s - sstart;
- if (n > best_len) {
- OnigRegion* region = msa->region;
- best_len = n;
- if (region) {
-#ifdef USE_POSIX_REGION_OPTION
- if (IS_POSIX_REGION(msa->options)) {
- posix_regmatch_t* rmt = (posix_regmatch_t* )region;
-
- rmt[0].rm_so = sstart - str;
- rmt[0].rm_eo = s - str;
- for (i = 1; i <= num_mem; i++) {
- if (mem_end_stk[i] != INVALID_STACK_INDEX) {
- if (BIT_STATUS_AT(reg->bt_mem_start, i))
- rmt[i].rm_so = STACK_AT(mem_start_stk[i])->u.mem.pstr - str;
- else
- rmt[i].rm_so = (UChar* )((void* )(mem_start_stk[i])) - str;
-
- rmt[i].rm_eo = (BIT_STATUS_AT(reg->bt_mem_end, i)
- ? STACK_AT(mem_end_stk[i])->u.mem.pstr
- : (UChar* )((void* )mem_end_stk[i])) - str;
- }
- else {
- rmt[i].rm_so = rmt[i].rm_eo = ONIG_REGION_NOTPOS;
- }
- }
- }
- else {
-#endif /* USE_POSIX_REGION_OPTION */
- region->beg[0] = sstart - str;
- region->end[0] = s - str;
- for (i = 1; i <= num_mem; i++) {
- if (mem_end_stk[i] != INVALID_STACK_INDEX) {
- if (BIT_STATUS_AT(reg->bt_mem_start, i))
- region->beg[i] = STACK_AT(mem_start_stk[i])->u.mem.pstr - str;
- else
- region->beg[i] = (UChar* )((void* )mem_start_stk[i]) - str;
-
- region->end[i] = (BIT_STATUS_AT(reg->bt_mem_end, i)
- ? STACK_AT(mem_end_stk[i])->u.mem.pstr
- : (UChar* )((void* )mem_end_stk[i])) - str;
- }
- else {
- region->beg[i] = region->end[i] = ONIG_REGION_NOTPOS;
- }
- }
-
-#ifdef USE_CAPTURE_HISTORY
- if (reg->capture_history != 0) {
- int r;
- OnigCaptureTreeNode* node;
-
- if (IS_NULL(region->history_root)) {
- region->history_root = node = history_node_new();
- CHECK_NULL_RETURN_VAL(node, ONIGERR_MEMORY);
- }
- else {
- node = region->history_root;
- history_tree_clear(node);
- }
-
- node->group = 0;
- node->beg = sstart - str;
- node->end = s - str;
-
- stkp = stk_base;
- r = make_capture_history_tree(region->history_root, &stkp,
- stk, (UChar* )str, reg);
- if (r < 0) {
- best_len = r; /* error code */
- goto finish;
- }
- }
-#endif /* USE_CAPTURE_HISTORY */
-#ifdef USE_POSIX_REGION_OPTION
- } /* else IS_POSIX_REGION() */
-#endif
- } /* if (region) */
- } /* n > best_len */
- STAT_OP_OUT;
-
- if (IS_FIND_CONDITION(option)) {
- if (IS_FIND_NOT_EMPTY(option) && s == sstart) {
- best_len = ONIG_MISMATCH;
- goto fail; /* for retry */
- }
- if (IS_FIND_LONGEST(option) && s < end) {
- goto fail; /* for retry */
- }
- }
-
- /* default behavior: return first-matching result. */
- goto finish;
- break;
-
- case OP_EXACT1: STAT_OP_IN(OP_EXACT1);
-#if 0
- DATA_ENSURE(1);
- if (*p != *s) goto fail;
- p++; s++;
-#endif
- if (*p != *s++) goto fail;
- DATA_ENSURE(0);
- p++;
- STAT_OP_OUT;
- break;
-
- case OP_EXACT1_IC: STAT_OP_IN(OP_EXACT1_IC);
- {
- int len;
- UChar *q, *ss, *sp, lowbuf[ONIGENC_MBC_NORMALIZE_MAXLEN];
-
- DATA_ENSURE(1);
- ss = s;
- sp = p;
-
- exact1_ic_retry:
- len = ONIGENC_MBC_TO_NORMALIZE(encode, ambig_flag, &s, end, lowbuf);
- DATA_ENSURE(0);
- q = lowbuf;
- while (len-- > 0) {
- if (*p != *q) {
-#if 1
- if ((ambig_flag & ONIGENC_AMBIGUOUS_MATCH_COMPOUND) != 0) {
- ambig_flag &= ~ONIGENC_AMBIGUOUS_MATCH_COMPOUND;
- s = ss;
- p = sp;
- goto exact1_ic_retry;
- }
- else
- goto fail;
-#else
- goto fail;
-#endif
- }
- p++; q++;
- }
- }
- STAT_OP_OUT;
- break;
-
- case OP_EXACT2: STAT_OP_IN(OP_EXACT2);
- DATA_ENSURE(2);
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- sprev = s;
- p++; s++;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_EXACT3: STAT_OP_IN(OP_EXACT3);
- DATA_ENSURE(3);
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- sprev = s;
- p++; s++;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_EXACT4: STAT_OP_IN(OP_EXACT4);
- DATA_ENSURE(4);
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- sprev = s;
- p++; s++;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_EXACT5: STAT_OP_IN(OP_EXACT5);
- DATA_ENSURE(5);
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- sprev = s;
- p++; s++;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_EXACTN: STAT_OP_IN(OP_EXACTN);
- GET_LENGTH_INC(tlen, p);
- DATA_ENSURE(tlen);
- while (tlen-- > 0) {
- if (*p++ != *s++) goto fail;
- }
- sprev = s - 1;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_EXACTN_IC: STAT_OP_IN(OP_EXACTN_IC);
- {
- int len;
- UChar *ss, *sp, *q, *endp, lowbuf[ONIGENC_MBC_NORMALIZE_MAXLEN];
-
- GET_LENGTH_INC(tlen, p);
- endp = p + tlen;
-
- while (p < endp) {
- sprev = s;
- DATA_ENSURE(1);
- ss = s;
- sp = p;
-
- exactn_ic_retry:
- len = ONIGENC_MBC_TO_NORMALIZE(encode, ambig_flag, &s, end, lowbuf);
- DATA_ENSURE(0);
- q = lowbuf;
- while (len-- > 0) {
- if (*p != *q) {
-#if 1
- if ((ambig_flag & ONIGENC_AMBIGUOUS_MATCH_COMPOUND) != 0) {
- ambig_flag &= ~ONIGENC_AMBIGUOUS_MATCH_COMPOUND;
- s = ss;
- p = sp;
- goto exactn_ic_retry;
- }
- else
- goto fail;
-#else
- goto fail;
-#endif
- }
- p++; q++;
- }
- }
- }
-
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_EXACTMB2N1: STAT_OP_IN(OP_EXACTMB2N1);
- DATA_ENSURE(2);
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- STAT_OP_OUT;
- break;
-
- case OP_EXACTMB2N2: STAT_OP_IN(OP_EXACTMB2N2);
- DATA_ENSURE(4);
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- sprev = s;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_EXACTMB2N3: STAT_OP_IN(OP_EXACTMB2N3);
- DATA_ENSURE(6);
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- sprev = s;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_EXACTMB2N: STAT_OP_IN(OP_EXACTMB2N);
- GET_LENGTH_INC(tlen, p);
- DATA_ENSURE(tlen * 2);
- while (tlen-- > 0) {
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- }
- sprev = s - 2;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_EXACTMB3N: STAT_OP_IN(OP_EXACTMB3N);
- GET_LENGTH_INC(tlen, p);
- DATA_ENSURE(tlen * 3);
- while (tlen-- > 0) {
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- if (*p != *s) goto fail;
- p++; s++;
- }
- sprev = s - 3;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_EXACTMBN: STAT_OP_IN(OP_EXACTMBN);
- GET_LENGTH_INC(tlen, p); /* mb-len */
- GET_LENGTH_INC(tlen2, p); /* string len */
- tlen2 *= tlen;
- DATA_ENSURE(tlen2);
- while (tlen2-- > 0) {
- if (*p != *s) goto fail;
- p++; s++;
- }
- sprev = s - tlen;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_CCLASS: STAT_OP_IN(OP_CCLASS);
- DATA_ENSURE(1);
- if (BITSET_AT(((BitSetRef )p), *s) == 0) goto fail;
- p += SIZE_BITSET;
- s += enc_len(encode, s); /* OP_CCLASS can match mb-code. \D, \S */
- STAT_OP_OUT;
- break;
-
- case OP_CCLASS_MB: STAT_OP_IN(OP_CCLASS_MB);
- if (! ONIGENC_IS_MBC_HEAD(encode, s)) goto fail;
-
- cclass_mb:
- GET_LENGTH_INC(tlen, p);
- {
- OnigCodePoint code;
- UChar *ss;
- int mb_len;
-
- DATA_ENSURE(1);
- mb_len = enc_len(encode, s);
- DATA_ENSURE(mb_len);
- ss = s;
- s += mb_len;
- code = ONIGENC_MBC_TO_CODE(encode, ss, s);
-
-#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
- if (! onig_is_in_code_range(p, code)) goto fail;
-#else
- q = p;
- ALIGNMENT_RIGHT(q);
- if (! onig_is_in_code_range(q, code)) goto fail;
-#endif
- }
- p += tlen;
- STAT_OP_OUT;
- break;
-
- case OP_CCLASS_MIX: STAT_OP_IN(OP_CCLASS_MIX);
- DATA_ENSURE(1);
- if (ONIGENC_IS_MBC_HEAD(encode, s)) {
- p += SIZE_BITSET;
- goto cclass_mb;
- }
- else {
- if (BITSET_AT(((BitSetRef )p), *s) == 0)
- goto fail;
-
- p += SIZE_BITSET;
- GET_LENGTH_INC(tlen, p);
- p += tlen;
- s++;
- }
- STAT_OP_OUT;
- break;
-
- case OP_CCLASS_NOT: STAT_OP_IN(OP_CCLASS_NOT);
- DATA_ENSURE(1);
- if (BITSET_AT(((BitSetRef )p), *s) != 0) goto fail;
- p += SIZE_BITSET;
- s += enc_len(encode, s);
- STAT_OP_OUT;
- break;
-
- case OP_CCLASS_MB_NOT: STAT_OP_IN(OP_CCLASS_MB_NOT);
- DATA_ENSURE(1);
- if (! ONIGENC_IS_MBC_HEAD(encode, s)) {
- s++;
- GET_LENGTH_INC(tlen, p);
- p += tlen;
- goto cc_mb_not_success;
- }
-
- cclass_mb_not:
- GET_LENGTH_INC(tlen, p);
- {
- OnigCodePoint code;
- UChar *ss;
- int mb_len = enc_len(encode, s);
-
- if (s + mb_len > end) {
- DATA_ENSURE(1);
- s = (UChar* )end;
- p += tlen;
- goto cc_mb_not_success;
- }
-
- ss = s;
- s += mb_len;
- code = ONIGENC_MBC_TO_CODE(encode, ss, s);
-
-#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
- if (onig_is_in_code_range(p, code)) goto fail;
-#else
- q = p;
- ALIGNMENT_RIGHT(q);
- if (onig_is_in_code_range(q, code)) goto fail;
-#endif
- }
- p += tlen;
-
- cc_mb_not_success:
- STAT_OP_OUT;
- break;
-
- case OP_CCLASS_MIX_NOT: STAT_OP_IN(OP_CCLASS_MIX_NOT);
- DATA_ENSURE(1);
- if (ONIGENC_IS_MBC_HEAD(encode, s)) {
- p += SIZE_BITSET;
- goto cclass_mb_not;
- }
- else {
- if (BITSET_AT(((BitSetRef )p), *s) != 0)
- goto fail;
-
- p += SIZE_BITSET;
- GET_LENGTH_INC(tlen, p);
- p += tlen;
- s++;
- }
- STAT_OP_OUT;
- break;
-
- case OP_CCLASS_NODE: STAT_OP_IN(OP_CCLASS_NODE);
- {
- OnigCodePoint code;
- void *node;
- int mb_len;
- UChar *ss;
-
- DATA_ENSURE(1);
- GET_POINTER_INC(node, p);
- mb_len = enc_len(encode, s);
- ss = s;
- s += mb_len;
- DATA_ENSURE(0);
- code = ONIGENC_MBC_TO_CODE(encode, ss, s);
- if (is_code_in_cc(mb_len, code, node) == 0) goto fail;
- }
- STAT_OP_OUT;
- break;
-
- case OP_ANYCHAR: STAT_OP_IN(OP_ANYCHAR);
- DATA_ENSURE(1);
- n = enc_len(encode, s);
- DATA_ENSURE(n);
- if (ONIGENC_IS_MBC_NEWLINE(encode, s, end)) goto fail;
- s += n;
- STAT_OP_OUT;
- break;
-
- case OP_ANYCHAR_ML: STAT_OP_IN(OP_ANYCHAR_ML);
- DATA_ENSURE(1);
- n = enc_len(encode, s);
- DATA_ENSURE(n);
- s += n;
- STAT_OP_OUT;
- break;
-
- case OP_ANYCHAR_STAR: STAT_OP_IN(OP_ANYCHAR_STAR);
- while (s < end) {
- STACK_PUSH_ALT(p, s, sprev);
- n = enc_len(encode, s);
- DATA_ENSURE(n);
- if (ONIGENC_IS_MBC_NEWLINE(encode, s, end)) goto fail;
- sprev = s;
- s += n;
- }
- STAT_OP_OUT;
- break;
-
- case OP_ANYCHAR_ML_STAR: STAT_OP_IN(OP_ANYCHAR_ML_STAR);
- while (s < end) {
- STACK_PUSH_ALT(p, s, sprev);
- n = enc_len(encode, s);
- if (n > 1) {
- DATA_ENSURE(n);
- sprev = s;
- s += n;
- }
- else {
- sprev = s;
- s++;
- }
- }
- STAT_OP_OUT;
- break;
-
- case OP_ANYCHAR_STAR_PEEK_NEXT: STAT_OP_IN(OP_ANYCHAR_STAR_PEEK_NEXT);
- while (s < end) {
- if (*p == *s) {
- STACK_PUSH_ALT(p + 1, s, sprev);
- }
- n = enc_len(encode, s);
- DATA_ENSURE(n);
- if (ONIGENC_IS_MBC_NEWLINE(encode, s, end)) goto fail;
- sprev = s;
- s += n;
- }
- p++;
- STAT_OP_OUT;
- break;
-
- case OP_ANYCHAR_ML_STAR_PEEK_NEXT:STAT_OP_IN(OP_ANYCHAR_ML_STAR_PEEK_NEXT);
- while (s < end) {
- if (*p == *s) {
- STACK_PUSH_ALT(p + 1, s, sprev);
- }
- n = enc_len(encode, s);
- if (n >1) {
- DATA_ENSURE(n);
- sprev = s;
- s += n;
- }
- else {
- sprev = s;
- s++;
- }
- }
- p++;
- STAT_OP_OUT;
- break;
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- case OP_STATE_CHECK_ANYCHAR_STAR: STAT_OP_IN(OP_STATE_CHECK_ANYCHAR_STAR);
- GET_STATE_CHECK_NUM_INC(mem, p);
- while (s < end) {
- STATE_CHECK_VAL(scv, mem);
- if (scv) goto fail;
-
- STACK_PUSH_ALT_WITH_STATE_CHECK(p, s, sprev, mem);
- n = enc_len(encode, s);
- DATA_ENSURE(n);
- if (ONIGENC_IS_MBC_NEWLINE(encode, s, end)) goto fail;
- sprev = s;
- s += n;
- }
- STAT_OP_OUT;
- break;
-
- case OP_STATE_CHECK_ANYCHAR_ML_STAR:
- STAT_OP_IN(OP_STATE_CHECK_ANYCHAR_ML_STAR);
-
- GET_STATE_CHECK_NUM_INC(mem, p);
- while (s < end) {
- STATE_CHECK_VAL(scv, mem);
- if (scv) goto fail;
-
- STACK_PUSH_ALT_WITH_STATE_CHECK(p, s, sprev, mem);
- n = enc_len(encode, s);
- if (n > 1) {
- DATA_ENSURE(n);
- sprev = s;
- s += n;
- }
- else {
- sprev = s;
- s++;
- }
- }
- STAT_OP_OUT;
- break;
-#endif /* USE_COMBINATION_EXPLOSION_CHECK */
-
- case OP_WORD: STAT_OP_IN(OP_WORD);
- DATA_ENSURE(1);
- if (! ONIGENC_IS_MBC_WORD(encode, s, end))
- goto fail;
-
- s += enc_len(encode, s);
- STAT_OP_OUT;
- break;
-
- case OP_NOT_WORD: STAT_OP_IN(OP_NOT_WORD);
- DATA_ENSURE(1);
- if (ONIGENC_IS_MBC_WORD(encode, s, end))
- goto fail;
-
- s += enc_len(encode, s);
- STAT_OP_OUT;
- break;
-
- case OP_WORD_BOUND: STAT_OP_IN(OP_WORD_BOUND);
- if (ON_STR_BEGIN(s)) {
- DATA_ENSURE(1);
- if (! ONIGENC_IS_MBC_WORD(encode, s, end))
- goto fail;
- }
- else if (ON_STR_END(s)) {
- if (! ONIGENC_IS_MBC_WORD(encode, sprev, end))
- goto fail;
- }
- else {
- if (ONIGENC_IS_MBC_WORD(encode, s, end)
- == ONIGENC_IS_MBC_WORD(encode, sprev, end))
- goto fail;
- }
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_NOT_WORD_BOUND: STAT_OP_IN(OP_NOT_WORD_BOUND);
- if (ON_STR_BEGIN(s)) {
- if (DATA_ENSURE_CHECK(1) && ONIGENC_IS_MBC_WORD(encode, s, end))
- goto fail;
- }
- else if (ON_STR_END(s)) {
- if (ONIGENC_IS_MBC_WORD(encode, sprev, end))
- goto fail;
- }
- else {
- if (ONIGENC_IS_MBC_WORD(encode, s, end)
- != ONIGENC_IS_MBC_WORD(encode, sprev, end))
- goto fail;
- }
- STAT_OP_OUT;
- continue;
- break;
-
-#ifdef USE_WORD_BEGIN_END
- case OP_WORD_BEGIN: STAT_OP_IN(OP_WORD_BEGIN);
- if (DATA_ENSURE_CHECK(1) && ONIGENC_IS_MBC_WORD(encode, s, end)) {
- if (ON_STR_BEGIN(s) || !ONIGENC_IS_MBC_WORD(encode, sprev, end)) {
- STAT_OP_OUT;
- continue;
- }
- }
- goto fail;
- break;
-
- case OP_WORD_END: STAT_OP_IN(OP_WORD_END);
- if (!ON_STR_BEGIN(s) && ONIGENC_IS_MBC_WORD(encode, sprev, end)) {
- if (ON_STR_END(s) || !ONIGENC_IS_MBC_WORD(encode, s, end)) {
- STAT_OP_OUT;
- continue;
- }
- }
- goto fail;
- break;
-#endif
-
- case OP_BEGIN_BUF: STAT_OP_IN(OP_BEGIN_BUF);
- if (! ON_STR_BEGIN(s)) goto fail;
-
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_END_BUF: STAT_OP_IN(OP_END_BUF);
- if (! ON_STR_END(s)) goto fail;
-
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_BEGIN_LINE: STAT_OP_IN(OP_BEGIN_LINE);
- if (ON_STR_BEGIN(s)) {
- if (IS_NOTBOL(msa->options)) goto fail;
- STAT_OP_OUT;
- continue;
- }
- else if (ONIGENC_IS_MBC_NEWLINE(encode, sprev, end) && !ON_STR_END(s)) {
- STAT_OP_OUT;
- continue;
- }
- goto fail;
- break;
-
- case OP_END_LINE: STAT_OP_IN(OP_END_LINE);
- if (ON_STR_END(s)) {
-#ifndef USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE
- if (IS_EMPTY_STR || !ONIGENC_IS_MBC_NEWLINE(encode, sprev, end)) {
-#endif
- if (IS_NOTEOL(msa->options)) goto fail;
- STAT_OP_OUT;
- continue;
-#ifndef USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE
- }
-#endif
- }
- else if (ONIGENC_IS_MBC_NEWLINE(encode, s, end)) {
- STAT_OP_OUT;
- continue;
- }
-#ifdef USE_CRNL_AS_LINE_TERMINATOR
- else if (ONIGENC_IS_MBC_CRNL(encode, s, end)) {
- STAT_OP_OUT;
- continue;
- }
-#endif
- goto fail;
- break;
-
- case OP_SEMI_END_BUF: STAT_OP_IN(OP_SEMI_END_BUF);
- if (ON_STR_END(s)) {
-#ifndef USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE
- if (IS_EMPTY_STR || !ONIGENC_IS_MBC_NEWLINE(encode, sprev, end)) {
-#endif
- if (IS_NOTEOL(msa->options)) goto fail; /* Is it needed? */
- STAT_OP_OUT;
- continue;
-#ifndef USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE
- }
-#endif
- }
- else if (ONIGENC_IS_MBC_NEWLINE(encode, s, end) &&
- ON_STR_END(s + enc_len(encode, s))) {
- STAT_OP_OUT;
- continue;
- }
-#ifdef USE_CRNL_AS_LINE_TERMINATOR
- else if (ONIGENC_IS_MBC_CRNL(encode, s, end)) {
- UChar* ss = s + enc_len(encode, s);
- if (ON_STR_END(ss + enc_len(encode, ss))) {
- STAT_OP_OUT;
- continue;
- }
- }
-#endif
- goto fail;
- break;
-
- case OP_BEGIN_POSITION: STAT_OP_IN(OP_BEGIN_POSITION);
- if (s != msa->start)
- goto fail;
-
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_MEMORY_START_PUSH: STAT_OP_IN(OP_MEMORY_START_PUSH);
- GET_MEMNUM_INC(mem, p);
- STACK_PUSH_MEM_START(mem, s);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_MEMORY_START: STAT_OP_IN(OP_MEMORY_START);
- GET_MEMNUM_INC(mem, p);
- mem_start_stk[mem] = (StackIndex )((void* )s);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_MEMORY_END_PUSH: STAT_OP_IN(OP_MEMORY_END_PUSH);
- GET_MEMNUM_INC(mem, p);
- STACK_PUSH_MEM_END(mem, s);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_MEMORY_END: STAT_OP_IN(OP_MEMORY_END);
- GET_MEMNUM_INC(mem, p);
- mem_end_stk[mem] = (StackIndex )((void* )s);
- STAT_OP_OUT;
- continue;
- break;
-
-#ifdef USE_SUBEXP_CALL
- case OP_MEMORY_END_PUSH_REC: STAT_OP_IN(OP_MEMORY_END_PUSH_REC);
- GET_MEMNUM_INC(mem, p);
- STACK_GET_MEM_START(mem, stkp); /* should be before push mem-end. */
- STACK_PUSH_MEM_END(mem, s);
- mem_start_stk[mem] = GET_STACK_INDEX(stkp);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_MEMORY_END_REC: STAT_OP_IN(OP_MEMORY_END_REC);
- GET_MEMNUM_INC(mem, p);
- mem_end_stk[mem] = (StackIndex )((void* )s);
- STACK_GET_MEM_START(mem, stkp);
-
- if (BIT_STATUS_AT(reg->bt_mem_start, mem))
- mem_start_stk[mem] = GET_STACK_INDEX(stkp);
- else
- mem_start_stk[mem] = (StackIndex )((void* )stkp->u.mem.pstr);
-
- STACK_PUSH_MEM_END_MARK(mem);
- STAT_OP_OUT;
- continue;
- break;
-#endif
-
- case OP_BACKREF1: STAT_OP_IN(OP_BACKREF1);
- mem = 1;
- goto backref;
- break;
-
- case OP_BACKREF2: STAT_OP_IN(OP_BACKREF2);
- mem = 2;
- goto backref;
- break;
-
- case OP_BACKREFN: STAT_OP_IN(OP_BACKREFN);
- GET_MEMNUM_INC(mem, p);
- backref:
- {
- int len;
- UChar *pstart, *pend;
-
- /* if you want to remove following line,
- you should check in parse and compile time. */
- if (mem > num_mem) goto fail;
- if (mem_end_stk[mem] == INVALID_STACK_INDEX) goto fail;
- if (mem_start_stk[mem] == INVALID_STACK_INDEX) goto fail;
-
- if (BIT_STATUS_AT(reg->bt_mem_start, mem))
- pstart = STACK_AT(mem_start_stk[mem])->u.mem.pstr;
- else
- pstart = (UChar* )((void* )mem_start_stk[mem]);
-
- pend = (BIT_STATUS_AT(reg->bt_mem_end, mem)
- ? STACK_AT(mem_end_stk[mem])->u.mem.pstr
- : (UChar* )((void* )mem_end_stk[mem]));
- n = pend - pstart;
- DATA_ENSURE(n);
- sprev = s;
- STRING_CMP(pstart, s, n);
- while (sprev + (len = enc_len(encode, sprev)) < s)
- sprev += len;
-
- STAT_OP_OUT;
- continue;
- }
- break;
-
- case OP_BACKREFN_IC: STAT_OP_IN(OP_BACKREFN_IC);
- GET_MEMNUM_INC(mem, p);
- {
- int len;
- UChar *pstart, *pend;
-
- /* if you want to remove following line,
- you should check in parse and compile time. */
- if (mem > num_mem) goto fail;
- if (mem_end_stk[mem] == INVALID_STACK_INDEX) goto fail;
- if (mem_start_stk[mem] == INVALID_STACK_INDEX) goto fail;
-
- if (BIT_STATUS_AT(reg->bt_mem_start, mem))
- pstart = STACK_AT(mem_start_stk[mem])->u.mem.pstr;
- else
- pstart = (UChar* )((void* )mem_start_stk[mem]);
-
- pend = (BIT_STATUS_AT(reg->bt_mem_end, mem)
- ? STACK_AT(mem_end_stk[mem])->u.mem.pstr
- : (UChar* )((void* )mem_end_stk[mem]));
- n = pend - pstart;
- DATA_ENSURE(n);
- sprev = s;
- STRING_CMP_IC(ambig_flag, pstart, &s, n);
- while (sprev + (len = enc_len(encode, sprev)) < s)
- sprev += len;
-
- STAT_OP_OUT;
- continue;
- }
- break;
-
- case OP_BACKREF_MULTI: STAT_OP_IN(OP_BACKREF_MULTI);
- {
- int len, is_fail;
- UChar *pstart, *pend, *swork;
-
- GET_LENGTH_INC(tlen, p);
- for (i = 0; i < tlen; i++) {
- GET_MEMNUM_INC(mem, p);
-
- if (mem_end_stk[mem] == INVALID_STACK_INDEX) continue;
- if (mem_start_stk[mem] == INVALID_STACK_INDEX) continue;
-
- if (BIT_STATUS_AT(reg->bt_mem_start, mem))
- pstart = STACK_AT(mem_start_stk[mem])->u.mem.pstr;
- else
- pstart = (UChar* )((void* )mem_start_stk[mem]);
-
- pend = (BIT_STATUS_AT(reg->bt_mem_end, mem)
- ? STACK_AT(mem_end_stk[mem])->u.mem.pstr
- : (UChar* )((void* )mem_end_stk[mem]));
- n = pend - pstart;
- DATA_ENSURE(n);
- sprev = s;
- swork = s;
- STRING_CMP_VALUE(pstart, swork, n, is_fail);
- if (is_fail) continue;
- s = swork;
- while (sprev + (len = enc_len(encode, sprev)) < s)
- sprev += len;
-
- p += (SIZE_MEMNUM * (tlen - i - 1));
- break; /* success */
- }
- if (i == tlen) goto fail;
- STAT_OP_OUT;
- continue;
- }
- break;
-
- case OP_BACKREF_MULTI_IC: STAT_OP_IN(OP_BACKREF_MULTI_IC);
- {
- int len, is_fail;
- UChar *pstart, *pend, *swork;
-
- GET_LENGTH_INC(tlen, p);
- for (i = 0; i < tlen; i++) {
- GET_MEMNUM_INC(mem, p);
-
- if (mem_end_stk[mem] == INVALID_STACK_INDEX) continue;
- if (mem_start_stk[mem] == INVALID_STACK_INDEX) continue;
-
- if (BIT_STATUS_AT(reg->bt_mem_start, mem))
- pstart = STACK_AT(mem_start_stk[mem])->u.mem.pstr;
- else
- pstart = (UChar* )((void* )mem_start_stk[mem]);
-
- pend = (BIT_STATUS_AT(reg->bt_mem_end, mem)
- ? STACK_AT(mem_end_stk[mem])->u.mem.pstr
- : (UChar* )((void* )mem_end_stk[mem]));
- n = pend - pstart;
- DATA_ENSURE(n);
- sprev = s;
- swork = s;
- STRING_CMP_VALUE_IC(ambig_flag, pstart, &swork, n, is_fail);
- if (is_fail) continue;
- s = swork;
- while (sprev + (len = enc_len(encode, sprev)) < s)
- sprev += len;
-
- p += (SIZE_MEMNUM * (tlen - i - 1));
- break; /* success */
- }
- if (i == tlen) goto fail;
- STAT_OP_OUT;
- continue;
- }
- break;
-
-#ifdef USE_BACKREF_AT_LEVEL
- case OP_BACKREF_AT_LEVEL:
- {
- int len;
- OnigOptionType ic;
- LengthType level;
-
- GET_OPTION_INC(ic, p);
- GET_LENGTH_INC(level, p);
- GET_LENGTH_INC(tlen, p);
-
- sprev = s;
- if (backref_match_at_nested_level(reg, stk, stk_base, ic, ambig_flag
- , (int )level, (int )tlen, p, &s, end)) {
- while (sprev + (len = enc_len(encode, sprev)) < s)
- sprev += len;
-
- p += (SIZE_MEMNUM * tlen);
- }
- else
- goto fail;
-
- STAT_OP_OUT;
- continue;
- }
-
- break;
-#endif
-
- case OP_SET_OPTION_PUSH: STAT_OP_IN(OP_SET_OPTION_PUSH);
- GET_OPTION_INC(option, p);
- STACK_PUSH_ALT(p, s, sprev);
- p += SIZE_OP_SET_OPTION + SIZE_OP_FAIL;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_SET_OPTION: STAT_OP_IN(OP_SET_OPTION);
- GET_OPTION_INC(option, p);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_NULL_CHECK_START: STAT_OP_IN(OP_NULL_CHECK_START);
- GET_MEMNUM_INC(mem, p); /* mem: null check id */
- STACK_PUSH_NULL_CHECK_START(mem, s);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_NULL_CHECK_END: STAT_OP_IN(OP_NULL_CHECK_END);
- {
- int isnull;
-
- GET_MEMNUM_INC(mem, p); /* mem: null check id */
- STACK_NULL_CHECK(isnull, mem, s);
- if (isnull) {
-#ifdef ONIG_DEBUG_MATCH
- fprintf(stderr, "NULL_CHECK_END: skip id:%d, s:%d\n",
- (int )mem, (int )s);
-#endif
- null_check_found:
- /* empty loop founded, skip next instruction */
- switch (*p++) {
- case OP_JUMP:
- case OP_PUSH:
- p += SIZE_RELADDR;
- break;
- case OP_REPEAT_INC:
- case OP_REPEAT_INC_NG:
- case OP_REPEAT_INC_SG:
- case OP_REPEAT_INC_NG_SG:
- p += SIZE_MEMNUM;
- break;
- default:
- goto unexpected_bytecode_error;
- break;
- }
- }
- }
- STAT_OP_OUT;
- continue;
- break;
-
-#ifdef USE_INFINITE_REPEAT_MONOMANIAC_MEM_STATUS_CHECK
- case OP_NULL_CHECK_END_MEMST: STAT_OP_IN(OP_NULL_CHECK_END_MEMST);
- {
- int isnull;
-
- GET_MEMNUM_INC(mem, p); /* mem: null check id */
- STACK_NULL_CHECK_MEMST(isnull, mem, s, reg);
- if (isnull) {
-#ifdef ONIG_DEBUG_MATCH
- fprintf(stderr, "NULL_CHECK_END_MEMST: skip id:%d, s:%d\n",
- (int )mem, (int )s);
-#endif
- if (isnull == -1) goto fail;
- goto null_check_found;
- }
- }
- STAT_OP_OUT;
- continue;
- break;
-#endif
-
-#ifdef USE_SUBEXP_CALL
- case OP_NULL_CHECK_END_MEMST_PUSH:
- STAT_OP_IN(OP_NULL_CHECK_END_MEMST_PUSH);
- {
- int isnull;
-
- GET_MEMNUM_INC(mem, p); /* mem: null check id */
-#ifdef USE_INFINITE_REPEAT_MONOMANIAC_MEM_STATUS_CHECK
- STACK_NULL_CHECK_MEMST_REC(isnull, mem, s, reg);
-#else
- STACK_NULL_CHECK_REC(isnull, mem, s);
-#endif
- if (isnull) {
-#ifdef ONIG_DEBUG_MATCH
- fprintf(stderr, "NULL_CHECK_END_MEMST_PUSH: skip id:%d, s:%d\n",
- (int )mem, (int )s);
-#endif
- if (isnull == -1) goto fail;
- goto null_check_found;
- }
- else {
- STACK_PUSH_NULL_CHECK_END(mem);
- }
- }
- STAT_OP_OUT;
- continue;
- break;
-#endif
-
- case OP_JUMP: STAT_OP_IN(OP_JUMP);
- GET_RELADDR_INC(addr, p);
- p += addr;
- STAT_OP_OUT;
- CHECK_INTERRUPT_IN_MATCH_AT;
- continue;
- break;
-
- case OP_PUSH: STAT_OP_IN(OP_PUSH);
- GET_RELADDR_INC(addr, p);
- STACK_PUSH_ALT(p + addr, s, sprev);
- STAT_OP_OUT;
- continue;
- break;
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- case OP_STATE_CHECK_PUSH: STAT_OP_IN(OP_STATE_CHECK_PUSH);
- GET_STATE_CHECK_NUM_INC(mem, p);
- STATE_CHECK_VAL(scv, mem);
- if (scv) goto fail;
-
- GET_RELADDR_INC(addr, p);
- STACK_PUSH_ALT_WITH_STATE_CHECK(p + addr, s, sprev, mem);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_STATE_CHECK_PUSH_OR_JUMP: STAT_OP_IN(OP_STATE_CHECK_PUSH_OR_JUMP);
- GET_STATE_CHECK_NUM_INC(mem, p);
- GET_RELADDR_INC(addr, p);
- STATE_CHECK_VAL(scv, mem);
- if (scv) {
- p += addr;
- }
- else {
- STACK_PUSH_ALT_WITH_STATE_CHECK(p + addr, s, sprev, mem);
- }
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_STATE_CHECK: STAT_OP_IN(OP_STATE_CHECK);
- GET_STATE_CHECK_NUM_INC(mem, p);
- STATE_CHECK_VAL(scv, mem);
- if (scv) goto fail;
-
- STACK_PUSH_STATE_CHECK(s, mem);
- STAT_OP_OUT;
- continue;
- break;
-#endif /* USE_COMBINATION_EXPLOSION_CHECK */
-
- case OP_POP: STAT_OP_IN(OP_POP);
- STACK_POP_ONE;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_PUSH_OR_JUMP_EXACT1: STAT_OP_IN(OP_PUSH_OR_JUMP_EXACT1);
- GET_RELADDR_INC(addr, p);
- if (*p == *s && DATA_ENSURE_CHECK(1)) {
- p++;
- STACK_PUSH_ALT(p + addr, s, sprev);
- STAT_OP_OUT;
- continue;
- }
- p += (addr + 1);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_PUSH_IF_PEEK_NEXT: STAT_OP_IN(OP_PUSH_IF_PEEK_NEXT);
- GET_RELADDR_INC(addr, p);
- if (*p == *s) {
- p++;
- STACK_PUSH_ALT(p + addr, s, sprev);
- STAT_OP_OUT;
- continue;
- }
- p++;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_REPEAT: STAT_OP_IN(OP_REPEAT);
- {
- GET_MEMNUM_INC(mem, p); /* mem: OP_REPEAT ID */
- GET_RELADDR_INC(addr, p);
-
- STACK_ENSURE(1);
- repeat_stk[mem] = GET_STACK_INDEX(stk);
- STACK_PUSH_REPEAT(mem, p);
-
- if (reg->repeat_range[mem].lower == 0) {
- STACK_PUSH_ALT(p + addr, s, sprev);
- }
- }
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_REPEAT_NG: STAT_OP_IN(OP_REPEAT_NG);
- {
- GET_MEMNUM_INC(mem, p); /* mem: OP_REPEAT ID */
- GET_RELADDR_INC(addr, p);
-
- STACK_ENSURE(1);
- repeat_stk[mem] = GET_STACK_INDEX(stk);
- STACK_PUSH_REPEAT(mem, p);
-
- if (reg->repeat_range[mem].lower == 0) {
- STACK_PUSH_ALT(p, s, sprev);
- p += addr;
- }
- }
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_REPEAT_INC: STAT_OP_IN(OP_REPEAT_INC);
- GET_MEMNUM_INC(mem, p); /* mem: OP_REPEAT ID */
- si = repeat_stk[mem];
- stkp = STACK_AT(si);
-
- repeat_inc:
- stkp->u.repeat.count++;
- if (stkp->u.repeat.count >= reg->repeat_range[mem].upper) {
- /* end of repeat. Nothing to do. */
- }
- else if (stkp->u.repeat.count >= reg->repeat_range[mem].lower) {
- STACK_PUSH_ALT(p, s, sprev);
- p = STACK_AT(si)->u.repeat.pcode; /* Don't use stkp after PUSH. */
- }
- else {
- p = stkp->u.repeat.pcode;
- }
- STACK_PUSH_REPEAT_INC(si);
- STAT_OP_OUT;
- CHECK_INTERRUPT_IN_MATCH_AT;
- continue;
- break;
-
- case OP_REPEAT_INC_SG: STAT_OP_IN(OP_REPEAT_INC_SG);
- GET_MEMNUM_INC(mem, p); /* mem: OP_REPEAT ID */
- STACK_GET_REPEAT(mem, stkp);
- si = GET_STACK_INDEX(stkp);
- goto repeat_inc;
- break;
-
- case OP_REPEAT_INC_NG: STAT_OP_IN(OP_REPEAT_INC_NG);
- GET_MEMNUM_INC(mem, p); /* mem: OP_REPEAT ID */
- si = repeat_stk[mem];
- stkp = STACK_AT(si);
-
- repeat_inc_ng:
- stkp->u.repeat.count++;
- if (stkp->u.repeat.count < reg->repeat_range[mem].upper) {
- if (stkp->u.repeat.count >= reg->repeat_range[mem].lower) {
- UChar* pcode = stkp->u.repeat.pcode;
-
- STACK_PUSH_REPEAT_INC(si);
- STACK_PUSH_ALT(pcode, s, sprev);
- }
- else {
- p = stkp->u.repeat.pcode;
- STACK_PUSH_REPEAT_INC(si);
- }
- }
- else if (stkp->u.repeat.count == reg->repeat_range[mem].upper) {
- STACK_PUSH_REPEAT_INC(si);
- }
- STAT_OP_OUT;
- CHECK_INTERRUPT_IN_MATCH_AT;
- continue;
- break;
-
- case OP_REPEAT_INC_NG_SG: STAT_OP_IN(OP_REPEAT_INC_NG_SG);
- GET_MEMNUM_INC(mem, p); /* mem: OP_REPEAT ID */
- STACK_GET_REPEAT(mem, stkp);
- si = GET_STACK_INDEX(stkp);
- goto repeat_inc_ng;
- break;
-
- case OP_PUSH_POS: STAT_OP_IN(OP_PUSH_POS);
- STACK_PUSH_POS(s, sprev);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_POP_POS: STAT_OP_IN(OP_POP_POS);
- {
- STACK_POS_END(stkp);
- s = stkp->u.state.pstr;
- sprev = stkp->u.state.pstr_prev;
- }
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_PUSH_POS_NOT: STAT_OP_IN(OP_PUSH_POS_NOT);
- GET_RELADDR_INC(addr, p);
- STACK_PUSH_POS_NOT(p + addr, s, sprev);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_FAIL_POS: STAT_OP_IN(OP_FAIL_POS);
- STACK_POP_TIL_POS_NOT;
- goto fail;
- break;
-
- case OP_PUSH_STOP_BT: STAT_OP_IN(OP_PUSH_STOP_BT);
- STACK_PUSH_STOP_BT;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_POP_STOP_BT: STAT_OP_IN(OP_POP_STOP_BT);
- STACK_STOP_BT_END;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_LOOK_BEHIND: STAT_OP_IN(OP_LOOK_BEHIND);
- GET_LENGTH_INC(tlen, p);
- s = (UChar* )ONIGENC_STEP_BACK(encode, str, s, (int )tlen);
- if (IS_NULL(s)) goto fail;
- sprev = (UChar* )onigenc_get_prev_char_head(encode, str, s);
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_PUSH_LOOK_BEHIND_NOT: STAT_OP_IN(OP_PUSH_LOOK_BEHIND_NOT);
- GET_RELADDR_INC(addr, p);
- GET_LENGTH_INC(tlen, p);
- q = (UChar* )ONIGENC_STEP_BACK(encode, str, s, (int )tlen);
- if (IS_NULL(q)) {
- /* too short case -> success. ex. /(?<!XXX)a/.match("a")
- If you want to change to fail, replace following line. */
- p += addr;
- /* goto fail; */
- }
- else {
- STACK_PUSH_LOOK_BEHIND_NOT(p + addr, s, sprev);
- s = q;
- sprev = (UChar* )onigenc_get_prev_char_head(encode, str, s);
- }
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_FAIL_LOOK_BEHIND_NOT: STAT_OP_IN(OP_FAIL_LOOK_BEHIND_NOT);
- STACK_POP_TIL_LOOK_BEHIND_NOT;
- goto fail;
- break;
-
-#ifdef USE_SUBEXP_CALL
- case OP_CALL: STAT_OP_IN(OP_CALL);
- GET_ABSADDR_INC(addr, p);
- STACK_PUSH_CALL_FRAME(p);
- p = reg->p + addr;
- STAT_OP_OUT;
- continue;
- break;
-
- case OP_RETURN: STAT_OP_IN(OP_RETURN);
- STACK_RETURN(p);
- STACK_PUSH_RETURN;
- STAT_OP_OUT;
- continue;
- break;
-#endif
-
- case OP_FINISH:
- goto finish;
- break;
-
- fail:
- STAT_OP_OUT;
- /* fall */
- case OP_FAIL: STAT_OP_IN(OP_FAIL);
- STACK_POP;
- p = stk->u.state.pcode;
- s = stk->u.state.pstr;
- sprev = stk->u.state.pstr_prev;
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- if (stk->u.state.state_check != 0) {
- stk->type = STK_STATE_CHECK_MARK;
- stk++;
- }
-#endif
-
- STAT_OP_OUT;
- continue;
- break;
-
- default:
- goto bytecode_error;
-
- } /* end of switch */
- sprev = sbegin;
- } /* end of while(1) */
-
- finish:
- STACK_SAVE;
- return best_len;
-
-#ifdef ONIG_DEBUG
- stack_error:
- STACK_SAVE;
- return ONIGERR_STACK_BUG;
-#endif
-
- bytecode_error:
- STACK_SAVE;
- return ONIGERR_UNDEFINED_BYTECODE;
-
- unexpected_bytecode_error:
- STACK_SAVE;
- return ONIGERR_UNEXPECTED_BYTECODE;
-}
-
-
-static UChar*
-slow_search(OnigEncoding enc, UChar* target, UChar* target_end,
- const UChar* text, const UChar* text_end, UChar* text_range)
-{
- UChar *t, *p, *s, *end;
-
- end = (UChar* )text_end;
- end -= target_end - target - 1;
- if (end > text_range)
- end = text_range;
-
- s = (UChar* )text;
-
- while (s < end) {
- if (*s == *target) {
- p = s + 1;
- t = target + 1;
- while (t < target_end) {
- if (*t != *p++)
- break;
- t++;
- }
- if (t == target_end)
- return s;
- }
- s += enc_len(enc, s);
- }
-
- return (UChar* )NULL;
-}
-
-static int
-str_lower_case_match(OnigEncoding enc, int ambig_flag,
- const UChar* t, const UChar* tend,
- const UChar* p, const UChar* end)
-{
- int lowlen;
- UChar *q, lowbuf[ONIGENC_MBC_NORMALIZE_MAXLEN];
- const UChar* tsave;
- const UChar* psave;
-
- tsave = t;
- psave = p;
-
- retry:
- while (t < tend) {
- lowlen = ONIGENC_MBC_TO_NORMALIZE(enc, ambig_flag, &p, end, lowbuf);
- q = lowbuf;
- while (lowlen > 0) {
- if (*t++ != *q++) {
- if ((ambig_flag & ONIGENC_AMBIGUOUS_MATCH_COMPOUND) != 0) {
- ambig_flag &= ~ONIGENC_AMBIGUOUS_MATCH_COMPOUND;
- t = tsave;
- p = psave;
- goto retry;
- }
- else
- return 0;
- }
- lowlen--;
- }
- }
-
- return 1;
-}
-
-static UChar*
-slow_search_ic(OnigEncoding enc, int ambig_flag,
- UChar* target, UChar* target_end,
- const UChar* text, const UChar* text_end, UChar* text_range)
-{
- UChar *s, *end;
-
- end = (UChar* )text_end;
- end -= target_end - target - 1;
- if (end > text_range)
- end = text_range;
-
- s = (UChar* )text;
-
- while (s < end) {
- if (str_lower_case_match(enc, ambig_flag, target, target_end, s, text_end))
- return s;
-
- s += enc_len(enc, s);
- }
-
- return (UChar* )NULL;
-}
-
-static UChar*
-slow_search_backward(OnigEncoding enc, UChar* target, UChar* target_end,
- const UChar* text, const UChar* adjust_text,
- const UChar* text_end, const UChar* text_start)
-{
- UChar *t, *p, *s;
-
- s = (UChar* )text_end;
- s -= (target_end - target);
- if (s > text_start)
- s = (UChar* )text_start;
- else
- s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, adjust_text, s);
-
- while (s >= text) {
- if (*s == *target) {
- p = s + 1;
- t = target + 1;
- while (t < target_end) {
- if (*t != *p++)
- break;
- t++;
- }
- if (t == target_end)
- return s;
- }
- s = (UChar* )onigenc_get_prev_char_head(enc, adjust_text, s);
- }
-
- return (UChar* )NULL;
-}
-
-static UChar*
-slow_search_backward_ic(OnigEncoding enc, int ambig_flag,
- UChar* target, UChar* target_end,
- const UChar* text, const UChar* adjust_text,
- const UChar* text_end, const UChar* text_start)
-{
- UChar *s;
-
- s = (UChar* )text_end;
- s -= (target_end - target);
- if (s > text_start)
- s = (UChar* )text_start;
- else
- s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, adjust_text, s);
-
- while (s >= text) {
- if (str_lower_case_match(enc, ambig_flag,
- target, target_end, s, text_end))
- return s;
-
- s = (UChar* )onigenc_get_prev_char_head(enc, adjust_text, s);
- }
-
- return (UChar* )NULL;
-}
-
-static UChar*
-bm_search_notrev(regex_t* reg, const UChar* target, const UChar* target_end,
- const UChar* text, const UChar* text_end,
- const UChar* text_range)
-{
- const UChar *s, *se, *t, *p, *end;
- const UChar *tail;
- int skip, tlen1;
-
-#ifdef ONIG_DEBUG_SEARCH
- fprintf(stderr, "bm_search_notrev: text: %d, text_end: %d, text_range: %d\n",
- (int )text, (int )text_end, (int )text_range);
-#endif
-
- tail = target_end - 1;
- tlen1 = tail - target;
- end = text_range;
- if (end + tlen1 > text_end)
- end = text_end - tlen1;
-
- s = text;
-
- if (IS_NULL(reg->int_map)) {
- while (s < end) {
- p = se = s + tlen1;
- t = tail;
- while (t >= target && *p == *t) {
- p--; t--;
- }
- if (t < target) return (UChar* )s;
-
- skip = reg->map[*se];
- t = s;
- do {
- s += enc_len(reg->enc, s);
- } while ((s - t) < skip && s < end);
- }
- }
- else {
- while (s < end) {
- p = se = s + tlen1;
- t = tail;
- while (t >= target && *p == *t) {
- p--; t--;
- }
- if (t < target) return (UChar* )s;
-
- skip = reg->int_map[*se];
- t = s;
- do {
- s += enc_len(reg->enc, s);
- } while ((s - t) < skip && s < end);
- }
- }
-
- return (UChar* )NULL;
-}
-
-static UChar*
-bm_search(regex_t* reg, const UChar* target, const UChar* target_end,
- const UChar* text, const UChar* text_end, const UChar* text_range)
-{
- const UChar *s, *t, *p, *end;
- const UChar *tail;
-
- end = text_range + (target_end - target) - 1;
- if (end > text_end)
- end = text_end;
-
- tail = target_end - 1;
- s = text + (target_end - target) - 1;
- if (IS_NULL(reg->int_map)) {
- while (s < end) {
- p = s;
- t = tail;
- while (t >= target && *p == *t) {
- p--; t--;
- }
- if (t < target) return (UChar* )(p + 1);
- s += reg->map[*s];
- }
- }
- else { /* see int_map[] */
- while (s < end) {
- p = s;
- t = tail;
- while (t >= target && *p == *t) {
- p--; t--;
- }
- if (t < target) return (UChar* )(p + 1);
- s += reg->int_map[*s];
- }
- }
- return (UChar* )NULL;
-}
-
-static int
-set_bm_backward_skip(UChar* s, UChar* end, OnigEncoding enc, int** skip)
-
-{
- int i, len;
-
- if (IS_NULL(*skip)) {
- *skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
- if (IS_NULL(*skip)) return ONIGERR_MEMORY;
- }
-
- len = end - s;
- for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++)
- (*skip)[i] = len;
-
- for (i = len - 1; i > 0; i--)
- (*skip)[s[i]] = i;
-
- return 0;
-}
-
-static UChar*
-bm_search_backward(regex_t* reg, const UChar* target, const UChar* target_end,
- const UChar* text, const UChar* adjust_text,
- const UChar* text_end, const UChar* text_start)
-{
- const UChar *s, *t, *p;
-
- s = text_end - (target_end - target);
- if (text_start < s)
- s = text_start;
- else
- s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, adjust_text, s);
-
- while (s >= text) {
- p = s;
- t = target;
- while (t < target_end && *p == *t) {
- p++; t++;
- }
- if (t == target_end)
- return (UChar* )s;
-
- s -= reg->int_map_backward[*s];
- s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, adjust_text, s);
- }
-
- return (UChar* )NULL;
-}
-
-static UChar*
-map_search(OnigEncoding enc, UChar map[],
- const UChar* text, const UChar* text_range)
-{
- const UChar *s = text;
-
- while (s < text_range) {
- if (map[*s]) return (UChar* )s;
-
- s += enc_len(enc, s);
- }
- return (UChar* )NULL;
-}
-
-static UChar*
-map_search_backward(OnigEncoding enc, UChar map[],
- const UChar* text, const UChar* adjust_text,
- const UChar* text_start)
-{
- const UChar *s = text_start;
-
- while (s >= text) {
- if (map[*s]) return (UChar* )s;
-
- s = onigenc_get_prev_char_head(enc, adjust_text, s);
- }
- return (UChar* )NULL;
-}
-
-extern int
-onig_match(regex_t* reg, const UChar* str, const UChar* end, const UChar* at, OnigRegion* region,
- OnigOptionType option)
-{
- int r;
- UChar *prev;
- MatchArg msa;
-
-#if defined(USE_RECOMPILE_API) && defined(USE_MULTI_THREAD_SYSTEM)
- start:
- THREAD_ATOMIC_START;
- if (ONIG_STATE(reg) >= ONIG_STATE_NORMAL) {
- ONIG_STATE_INC(reg);
- if (IS_NOT_NULL(reg->chain) && ONIG_STATE(reg) == ONIG_STATE_NORMAL) {
- onig_chain_reduce(reg);
- ONIG_STATE_INC(reg);
- }
- }
- else {
- int n;
-
- THREAD_ATOMIC_END;
- n = 0;
- while (ONIG_STATE(reg) < ONIG_STATE_NORMAL) {
- if (++n > THREAD_PASS_LIMIT_COUNT)
- return ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT;
- THREAD_PASS;
- }
- goto start;
- }
- THREAD_ATOMIC_END;
-#endif /* USE_RECOMPILE_API && USE_MULTI_THREAD_SYSTEM */
-
- MATCH_ARG_INIT(msa, option, region, at);
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- {
- int offset = at - str;
- STATE_CHECK_BUFF_INIT(msa, end - str, offset, reg->num_comb_exp_check);
- }
-#endif
-
- if (region
-#ifdef USE_POSIX_REGION_OPTION
- && !IS_POSIX_REGION(option)
-#endif
- ) {
- r = onig_region_resize_clear(region, reg->num_mem + 1);
- }
- else
- r = 0;
-
- if (r == 0) {
- prev = (UChar* )onigenc_get_prev_char_head(reg->enc, str, at);
- r = match_at(reg, str, end, at, prev, &msa);
- }
-
- MATCH_ARG_FREE(msa);
- ONIG_STATE_DEC_THREAD(reg);
- return r;
-}
-
-static int
-forward_search_range(regex_t* reg, const UChar* str, const UChar* end, UChar* s,
- UChar* range, UChar** low, UChar** high, UChar** low_prev)
-{
- UChar *p, *pprev = (UChar* )NULL;
-
-#ifdef ONIG_DEBUG_SEARCH
- fprintf(stderr, "forward_search_range: str: %d, end: %d, s: %d, range: %d\n",
- (int )str, (int )end, (int )s, (int )range);
-#endif
-
- p = s;
- if (reg->dmin > 0) {
- if (ONIGENC_IS_SINGLEBYTE(reg->enc)) {
- p += reg->dmin;
- }
- else {
- UChar *q = p + reg->dmin;
- while (p < q) p += enc_len(reg->enc, p);
- }
- }
-
- retry:
- switch (reg->optimize) {
- case ONIG_OPTIMIZE_EXACT:
- p = slow_search(reg->enc, reg->exact, reg->exact_end, p, end, range);
- break;
- case ONIG_OPTIMIZE_EXACT_IC:
- p = slow_search_ic(reg->enc, reg->ambig_flag,
- reg->exact, reg->exact_end, p, end, range);
- break;
-
- case ONIG_OPTIMIZE_EXACT_BM:
- p = bm_search(reg, reg->exact, reg->exact_end, p, end, range);
- break;
-
- case ONIG_OPTIMIZE_EXACT_BM_NOT_REV:
- p = bm_search_notrev(reg, reg->exact, reg->exact_end, p, end, range);
- break;
-
- case ONIG_OPTIMIZE_MAP:
- p = map_search(reg->enc, reg->map, p, range);
- break;
- }
-
- if (p && p < range) {
- if (p - reg->dmin < s) {
- retry_gate:
- pprev = p;
- p += enc_len(reg->enc, p);
- goto retry;
- }
-
- if (reg->sub_anchor) {
- UChar* prev;
-
- switch (reg->sub_anchor) {
- case ANCHOR_BEGIN_LINE:
- if (!ON_STR_BEGIN(p)) {
- prev = onigenc_get_prev_char_head(reg->enc,
- (pprev ? pprev : str), p);
- if (!ONIGENC_IS_MBC_NEWLINE(reg->enc, prev, end))
- goto retry_gate;
- }
- break;
-
- case ANCHOR_END_LINE:
- if (ON_STR_END(p)) {
- prev = (UChar* )onigenc_get_prev_char_head(reg->enc,
- (pprev ? pprev : str), p);
- if (prev && ONIGENC_IS_MBC_NEWLINE(reg->enc, prev, end))
- goto retry_gate;
- }
- else if (! ONIGENC_IS_MBC_NEWLINE(reg->enc, p, end)
-#ifdef USE_CRNL_AS_LINE_TERMINATOR
- && ! ONIGENC_IS_MBC_CRNL(reg->enc, p, end)
-#endif
- )
- goto retry_gate;
- break;
- }
- }
-
- if (reg->dmax == 0) {
- *low = p;
- if (low_prev) {
- if (*low > s)
- *low_prev = onigenc_get_prev_char_head(reg->enc, s, p);
- else
- *low_prev = onigenc_get_prev_char_head(reg->enc,
- (pprev ? pprev : str), p);
- }
- }
- else {
- if (reg->dmax != ONIG_INFINITE_DISTANCE) {
- *low = p - reg->dmax;
- if (*low > s) {
- *low = onigenc_get_right_adjust_char_head_with_prev(reg->enc, s,
- *low, (const UChar** )low_prev);
- if (low_prev && IS_NULL(*low_prev))
- *low_prev = onigenc_get_prev_char_head(reg->enc,
- (pprev ? pprev : s), *low);
- }
- else {
- if (low_prev)
- *low_prev = onigenc_get_prev_char_head(reg->enc,
- (pprev ? pprev : str), *low);
- }
- }
- }
- /* no needs to adjust *high, *high is used as range check only */
- *high = p - reg->dmin;
-
-#ifdef ONIG_DEBUG_SEARCH
- fprintf(stderr,
- "forward_search_range success: low: %d, high: %d, dmin: %d, dmax: %d\n",
- (int )(*low - str), (int )(*high - str), reg->dmin, reg->dmax);
-#endif
- return 1; /* success */
- }
-
- return 0; /* fail */
-}
-
-static int set_bm_backward_skip P_((UChar* s, UChar* end, OnigEncoding enc,
- int** skip));
-
-#define BM_BACKWARD_SEARCH_LENGTH_THRESHOLD 100
-
-static int
-backward_search_range(regex_t* reg, const UChar* str, const UChar* end,
- UChar* s, const UChar* range, UChar* adjrange,
- UChar** low, UChar** high)
-{
- int r;
- UChar *p;
-
- range += reg->dmin;
- p = s;
-
- retry:
- switch (reg->optimize) {
- case ONIG_OPTIMIZE_EXACT:
- exact_method:
- p = slow_search_backward(reg->enc, reg->exact, reg->exact_end,
- range, adjrange, end, p);
- break;
-
- case ONIG_OPTIMIZE_EXACT_IC:
- p = slow_search_backward_ic(reg->enc, reg->ambig_flag,
- reg->exact, reg->exact_end,
- range, adjrange, end, p);
- break;
-
- case ONIG_OPTIMIZE_EXACT_BM:
- case ONIG_OPTIMIZE_EXACT_BM_NOT_REV:
- if (IS_NULL(reg->int_map_backward)) {
- if (s - range < BM_BACKWARD_SEARCH_LENGTH_THRESHOLD)
- goto exact_method;
-
- r = set_bm_backward_skip(reg->exact, reg->exact_end, reg->enc,
- &(reg->int_map_backward));
- if (r) return r;
- }
- p = bm_search_backward(reg, reg->exact, reg->exact_end, range, adjrange,
- end, p);
- break;
-
- case ONIG_OPTIMIZE_MAP:
- p = map_search_backward(reg->enc, reg->map, range, adjrange, p);
- break;
- }
-
- if (p) {
- if (reg->sub_anchor) {
- UChar* prev;
-
- switch (reg->sub_anchor) {
- case ANCHOR_BEGIN_LINE:
- if (!ON_STR_BEGIN(p)) {
- prev = onigenc_get_prev_char_head(reg->enc, str, p);
- if (!ONIGENC_IS_MBC_NEWLINE(reg->enc, prev, end)) {
- p = prev;
- goto retry;
- }
- }
- break;
-
- case ANCHOR_END_LINE:
- if (ON_STR_END(p)) {
- prev = onigenc_get_prev_char_head(reg->enc, adjrange, p);
- if (IS_NULL(prev)) goto fail;
- if (ONIGENC_IS_MBC_NEWLINE(reg->enc, prev, end)) {
- p = prev;
- goto retry;
- }
- }
- else if (! ONIGENC_IS_MBC_NEWLINE(reg->enc, p, end)
-#ifdef USE_CRNL_AS_LINE_TERMINATOR
- && ! ONIGENC_IS_MBC_CRNL(reg->enc, p, end)
-#endif
- ) {
- p = onigenc_get_prev_char_head(reg->enc, adjrange, p);
- if (IS_NULL(p)) goto fail;
- goto retry;
- }
- break;
- }
- }
-
- /* no needs to adjust *high, *high is used as range check only */
- if (reg->dmax != ONIG_INFINITE_DISTANCE) {
- *low = p - reg->dmax;
- *high = p - reg->dmin;
- *high = onigenc_get_right_adjust_char_head(reg->enc, adjrange, *high);
- }
-
-#ifdef ONIG_DEBUG_SEARCH
- fprintf(stderr, "backward_search_range: low: %d, high: %d\n",
- (int )(*low - str), (int )(*high - str));
-#endif
- return 1; /* success */
- }
-
- fail:
-#ifdef ONIG_DEBUG_SEARCH
- fprintf(stderr, "backward_search_range: fail.\n");
-#endif
- return 0; /* fail */
-}
-
-
-extern int
-onig_search(regex_t* reg, const UChar* str, const UChar* end,
- const UChar* start, const UChar* range, OnigRegion* region, OnigOptionType option)
-{
- int r;
- UChar *s, *prev;
- MatchArg msa;
- const UChar *orig_start = start;
-
-#if defined(USE_RECOMPILE_API) && defined(USE_MULTI_THREAD_SYSTEM)
- start:
- THREAD_ATOMIC_START;
- if (ONIG_STATE(reg) >= ONIG_STATE_NORMAL) {
- ONIG_STATE_INC(reg);
- if (IS_NOT_NULL(reg->chain) && ONIG_STATE(reg) == ONIG_STATE_NORMAL) {
- onig_chain_reduce(reg);
- ONIG_STATE_INC(reg);
- }
- }
- else {
- int n;
-
- THREAD_ATOMIC_END;
- n = 0;
- while (ONIG_STATE(reg) < ONIG_STATE_NORMAL) {
- if (++n > THREAD_PASS_LIMIT_COUNT)
- return ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT;
- THREAD_PASS;
- }
- goto start;
- }
- THREAD_ATOMIC_END;
-#endif /* USE_RECOMPILE_API && USE_MULTI_THREAD_SYSTEM */
-
-#ifdef ONIG_DEBUG_SEARCH
- fprintf(stderr,
- "onig_search (entry point): str: %d, end: %d, start: %d, range: %d\n",
- (int )str, (int )(end - str), (int )(start - str), (int )(range - str));
-#endif
-
- if (region
-#ifdef USE_POSIX_REGION_OPTION
- && !IS_POSIX_REGION(option)
-#endif
- ) {
- r = onig_region_resize_clear(region, reg->num_mem + 1);
- if (r) goto finish_no_msa;
- }
-
- if (start > end || start < str) goto mismatch_no_msa;
-
-#define MATCH_AND_RETURN_CHECK \
- r = match_at(reg, str, end, s, prev, &msa);\
- if (r != ONIG_MISMATCH) {\
- if (r >= 0) goto match;\
- goto finish; /* error */ \
- }
-
- /* anchor optimize: resume search range */
- if (reg->anchor != 0 && str < end) {
- UChar* semi_end;
-
- if (reg->anchor & ANCHOR_BEGIN_POSITION) {
- /* search start-position only */
- begin_position:
- if (range > start)
- range = start + 1;
- else
- range = start;
- }
- else if (reg->anchor & ANCHOR_BEGIN_BUF) {
- /* search str-position only */
- if (range > start) {
- if (start != str) goto mismatch_no_msa;
- range = str + 1;
- }
- else {
- if (range <= str) {
- start = str;
- range = str;
- }
- else
- goto mismatch_no_msa;
- }
- }
- else if (reg->anchor & ANCHOR_END_BUF) {
- semi_end = (UChar* )end;
-
- end_buf:
- if ((OnigDistance )(semi_end - str) < reg->anchor_dmin)
- goto mismatch_no_msa;
-
- if (range > start) {
- if ((OnigDistance )(semi_end - start) > reg->anchor_dmax) {
- start = semi_end - reg->anchor_dmax;
- if (start < end)
- start = onigenc_get_right_adjust_char_head(reg->enc, str, start);
- else { /* match with empty at end */
- start = onigenc_get_prev_char_head(reg->enc, str, end);
- }
- }
- if ((OnigDistance )(semi_end - (range - 1)) < reg->anchor_dmin) {
- range = semi_end - reg->anchor_dmin + 1;
- }
-
- if (start >= range) goto mismatch_no_msa;
- }
- else {
- if ((OnigDistance )(semi_end - range) > reg->anchor_dmax) {
- range = semi_end - reg->anchor_dmax;
- }
- if ((OnigDistance )(semi_end - start) < reg->anchor_dmin) {
- start = semi_end - reg->anchor_dmin;
- start = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, str, start);
- if (range > start) goto mismatch_no_msa;
- }
- }
- }
- else if (reg->anchor & ANCHOR_SEMI_END_BUF) {
- UChar* pre_end = ONIGENC_STEP_BACK(reg->enc, str, end, 1);
-
- if (ONIGENC_IS_MBC_NEWLINE(reg->enc, pre_end, end)) {
- semi_end = pre_end;
- if (semi_end > str && start <= semi_end) {
- goto end_buf;
- }
- }
- else {
- semi_end = (UChar* )end;
- goto end_buf;
- }
- }
- else if ((reg->anchor & ANCHOR_ANYCHAR_STAR_ML)) {
- goto begin_position;
- }
- }
- else if (str == end) { /* empty string */
- static const UChar* address_for_empty_string = (UChar* )"";
-
-#ifdef ONIG_DEBUG_SEARCH
- fprintf(stderr, "onig_search: empty string.\n");
-#endif
-
- if (reg->threshold_len == 0) {
- start = end = str = address_for_empty_string;
- s = (UChar* )start;
- prev = (UChar* )NULL;
-
- MATCH_ARG_INIT(msa, option, region, start);
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- msa.state_check_buff = (void* )0;
- msa.state_check_buff_size = 0;
-#endif
- MATCH_AND_RETURN_CHECK;
- goto mismatch;
- }
- goto mismatch_no_msa;
- }
-
-#ifdef ONIG_DEBUG_SEARCH
- fprintf(stderr, "onig_search(apply anchor): end: %d, start: %d, range: %d\n",
- (int )(end - str), (int )(start - str), (int )(range - str));
-#endif
-
- MATCH_ARG_INIT(msa, option, region, orig_start);
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- {
- int offset = (MIN(start, range) - str);
- STATE_CHECK_BUFF_INIT(msa, end - str, offset, reg->num_comb_exp_check);
- }
-#endif
-
- s = (UChar* )start;
- if (range > start) { /* forward search */
- if (s > str)
- prev = onigenc_get_prev_char_head(reg->enc, str, s);
- else
- prev = (UChar* )NULL;
-
- if (reg->optimize != ONIG_OPTIMIZE_NONE) {
- UChar *sch_range, *low, *high, *low_prev;
-
- sch_range = (UChar* )range;
- if (reg->dmax != 0) {
- if (reg->dmax == ONIG_INFINITE_DISTANCE)
- sch_range = (UChar* )end;
- else {
- sch_range += reg->dmax;
- if (sch_range > end) sch_range = (UChar* )end;
- }
- }
-
- if ((end - start) < reg->threshold_len)
- goto mismatch;
-
- if (reg->dmax != ONIG_INFINITE_DISTANCE) {
- do {
- if (! forward_search_range(reg, str, end, s, sch_range,
- &low, &high, &low_prev)) goto mismatch;
- if (s < low) {
- s = low;
- prev = low_prev;
- }
- while (s <= high) {
- MATCH_AND_RETURN_CHECK;
- prev = s;
- s += enc_len(reg->enc, s);
- }
- } while (s < range);
- goto mismatch;
- }
- else { /* check only. */
- if (! forward_search_range(reg, str, end, s, sch_range,
- &low, &high, (UChar** )NULL)) goto mismatch;
-
- if ((reg->anchor & ANCHOR_ANYCHAR_STAR) != 0) {
- do {
- MATCH_AND_RETURN_CHECK;
- prev = s;
- s += enc_len(reg->enc, s);
-
- while (!ONIGENC_IS_MBC_NEWLINE(reg->enc, prev, end) && s < range) {
- prev = s;
- s += enc_len(reg->enc, s);
- }
- } while (s < range);
- goto mismatch;
- }
- }
- }
-
- do {
- MATCH_AND_RETURN_CHECK;
- prev = s;
- s += enc_len(reg->enc, s);
- } while (s < range);
-
- if (s == range) { /* because empty match with /$/. */
- MATCH_AND_RETURN_CHECK;
- }
- }
- else { /* backward search */
- if (reg->optimize != ONIG_OPTIMIZE_NONE) {
- UChar *low, *high, *adjrange, *sch_start;
-
- if (range < end)
- adjrange = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, str, range);
- else
- adjrange = (UChar* )end;
-
- if (reg->dmax != ONIG_INFINITE_DISTANCE &&
- (end - range) >= reg->threshold_len) {
- do {
- sch_start = s + reg->dmax;
- if (sch_start > end) sch_start = (UChar* )end;
- if (backward_search_range(reg, str, end, sch_start, range, adjrange,
- &low, &high) <= 0)
- goto mismatch;
-
- if (s > high)
- s = high;
-
- while (s >= low) {
- prev = onigenc_get_prev_char_head(reg->enc, str, s);
- MATCH_AND_RETURN_CHECK;
- s = prev;
- }
- } while (s >= range);
- goto mismatch;
- }
- else { /* check only. */
- if ((end - range) < reg->threshold_len) goto mismatch;
-
- sch_start = s;
- if (reg->dmax != 0) {
- if (reg->dmax == ONIG_INFINITE_DISTANCE)
- sch_start = (UChar* )end;
- else {
- sch_start += reg->dmax;
- if (sch_start > end) sch_start = (UChar* )end;
- else
- sch_start = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc,
- start, sch_start);
- }
- }
- if (backward_search_range(reg, str, end, sch_start, range, adjrange,
- &low, &high) <= 0) goto mismatch;
- }
- }
-
- do {
- prev = onigenc_get_prev_char_head(reg->enc, str, s);
- MATCH_AND_RETURN_CHECK;
- s = prev;
- } while (s >= range);
- }
-
- mismatch:
- r = ONIG_MISMATCH;
-
- finish:
- MATCH_ARG_FREE(msa);
- ONIG_STATE_DEC_THREAD(reg);
-
- /* If result is mismatch and no FIND_NOT_EMPTY option,
- then the region is not setted in match_at(). */
- if (IS_FIND_NOT_EMPTY(reg->options) && region
-#ifdef USE_POSIX_REGION_OPTION
- && !IS_POSIX_REGION(option)
-#endif
- ) {
- onig_region_clear(region);
- }
-
-#ifdef ONIG_DEBUG
- if (r != ONIG_MISMATCH)
- fprintf(stderr, "onig_search: error %d\n", r);
-#endif
- return r;
-
- mismatch_no_msa:
- r = ONIG_MISMATCH;
- finish_no_msa:
- ONIG_STATE_DEC_THREAD(reg);
-#ifdef ONIG_DEBUG
- if (r != ONIG_MISMATCH)
- fprintf(stderr, "onig_search: error %d\n", r);
-#endif
- return r;
-
- match:
- ONIG_STATE_DEC_THREAD(reg);
- MATCH_ARG_FREE(msa);
- return s - str;
-}
-
-extern OnigEncoding
-onig_get_encoding(regex_t* reg)
-{
- return reg->enc;
-}
-
-extern OnigOptionType
-onig_get_options(regex_t* reg)
-{
- return reg->options;
-}
-
-extern OnigAmbigType
-onig_get_ambig_flag(regex_t* reg)
-{
- return reg->ambig_flag;
-}
-
-extern OnigSyntaxType*
-onig_get_syntax(regex_t* reg)
-{
- return reg->syntax;
-}
-
-extern int
-onig_number_of_captures(regex_t* reg)
-{
- return reg->num_mem;
-}
-
-extern int
-onig_number_of_capture_histories(regex_t* reg)
-{
-#ifdef USE_CAPTURE_HISTORY
- int i, n;
-
- n = 0;
- for (i = 0; i <= ONIG_MAX_CAPTURE_HISTORY_GROUP; i++) {
- if (BIT_STATUS_AT(reg->capture_history, i) != 0)
- n++;
- }
- return n;
-#else
- return 0;
-#endif
-}
-
-extern void
-onig_copy_encoding(OnigEncoding to, OnigEncoding from)
-{
- *to = *from;
-}
-
diff --git a/regint.h b/regint.h
deleted file mode 100644
index 138e05e0db..0000000000
--- a/regint.h
+++ /dev/null
@@ -1,829 +0,0 @@
-#ifndef REGINT_H
-#define REGINT_H
-/**********************************************************************
- regint.h - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* for debug */
-/* #define ONIG_DEBUG_PARSE_TREE */
-/* #define ONIG_DEBUG_COMPILE */
-/* #define ONIG_DEBUG_SEARCH */
-/* #define ONIG_DEBUG_MATCH */
-/* #define ONIG_DONT_OPTIMIZE */
-
-/* for byte-code statistical data. */
-/* #define ONIG_DEBUG_STATISTICS */
-
-#if defined(ONIG_DEBUG_PARSE_TREE) || defined(ONIG_DEBUG_MATCH) || \
- defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) || \
- defined(ONIG_DEBUG_STATISTICS)
-#ifndef ONIG_DEBUG
-#define ONIG_DEBUG
-#endif
-#endif
-
-#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
- (defined(__ppc__) && defined(__APPLE__)) || \
- defined(__x86_64) || defined(__x86_64__) || \
- defined(__mc68020__)
-#define PLATFORM_UNALIGNED_WORD_ACCESS
-#endif
-
-/* config */
-/* spec. config */
-/* #define USE_UNICODE_FULL_RANGE_CTYPE */ /* --> move to regenc.h */
-#define USE_NAMED_GROUP
-#define USE_SUBEXP_CALL
-#define USE_INFINITE_REPEAT_MONOMANIAC_MEM_STATUS_CHECK /* /(?:()|())*\2/ */
-#define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE /* /\n$/ =~ "\n" */
-#define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
-/* #define USE_RECOMPILE_API */
-/* treat \r\n as line terminator.
- !!! NO SUPPORT !!!
- use this configuration on your own responsibility */
-/* #define USE_CRNL_AS_LINE_TERMINATOR */
-
-/* internal config */
-#define USE_RECYCLE_NODE
-#define USE_OP_PUSH_OR_JUMP_EXACT
-#define USE_QUALIFIER_PEEK_NEXT
-#define USE_ST_HASH_TABLE
-#define USE_SHARED_CCLASS_TABLE
-
-#define INIT_MATCH_STACK_SIZE 160
-#define DEFAULT_MATCH_STACK_LIMIT_SIZE 0 /* unlimited */
-
-/* interface to external system */
-#ifdef NOT_RUBY /* given from Makefile */
-#include "config.h"
-#define USE_BACKREF_AT_LEVEL
-#define USE_CAPTURE_HISTORY
-#define USE_VARIABLE_META_CHARS
-#define USE_WORD_BEGIN_END /* "\<": word-begin, "\>": word-end */
-#define USE_POSIX_REGION_OPTION /* needed for POSIX API support */
-/* #define USE_COMBINATION_EXPLOSION_CHECK */ /* (X*)* */
-/* #define USE_MULTI_THREAD_SYSTEM */
-#define THREAD_ATOMIC_START /* depend on thread system */
-#define THREAD_ATOMIC_END /* depend on thread system */
-#define THREAD_PASS /* depend on thread system */
-#define CHECK_INTERRUPT /* depend on application */
-#define xmalloc malloc
-#define xrealloc realloc
-#define xcalloc calloc
-#define xfree free
-#else
-#include "ruby.h"
-#include "version.h"
-#include "rubysig.h" /* for DEFER_INTS, ENABLE_INTS */
-
-#define USE_COMBINATION_EXPLOSION_CHECK /* (X*)* */
-#define USE_MULTI_THREAD_SYSTEM
-
-#define THREAD_ATOMIC_START DEFER_INTS
-#define THREAD_ATOMIC_END ENABLE_INTS
-#define THREAD_PASS rb_thread_schedule()
-#define CHECK_INTERRUPT do {\
- if (rb_trap_pending) {\
- if (! rb_prohibit_interrupt) {\
- rb_trap_exec();\
- }\
- }\
-} while (0)
-
-#define DEFAULT_WARN_FUNCTION onig_rb_warn
-#define DEFAULT_VERB_WARN_FUNCTION onig_rb_warning
-
-#endif /* else NOT_RUBY */
-
-#define STATE_CHECK_STRING_THRESHOLD_LEN 7
-#define STATE_CHECK_BUFF_MAX_SIZE 0x8000
-
-#define THREAD_PASS_LIMIT_COUNT 8
-#define xmemset memset
-#define xmemcpy memcpy
-#define xmemmove memmove
-#if defined(_WIN32) && !defined(__GNUC__)
-#define xalloca _alloca
-#ifdef NOT_RUBY
-#define vsnprintf _vsnprintf
-#endif
-#else
-#define xalloca alloca
-#endif
-
-
-#if defined(USE_RECOMPILE_API) && defined(USE_MULTI_THREAD_SYSTEM)
-#define ONIG_STATE_INC(reg) (reg)->state++
-#define ONIG_STATE_DEC(reg) (reg)->state--
-
-#define ONIG_STATE_INC_THREAD(reg) do {\
- THREAD_ATOMIC_START;\
- (reg)->state++;\
- THREAD_ATOMIC_END;\
-} while(0)
-#define ONIG_STATE_DEC_THREAD(reg) do {\
- THREAD_ATOMIC_START;\
- (reg)->state--;\
- THREAD_ATOMIC_END;\
-} while(0)
-#else
-#define ONIG_STATE_INC(reg) /* Nothing */
-#define ONIG_STATE_DEC(reg) /* Nothing */
-#define ONIG_STATE_INC_THREAD(reg) /* Nothing */
-#define ONIG_STATE_DEC_THREAD(reg) /* Nothing */
-#endif /* USE_RECOMPILE_API && USE_MULTI_THREAD_SYSTEM */
-
-
-#define onig_st_is_member st_is_member
-
-#ifdef NOT_RUBY
-
-#define st_init_table onig_st_init_table
-#define st_init_table_with_size onig_st_init_table_with_size
-#define st_init_numtable onig_st_init_numtable
-#define st_init_numtable_with_size onig_st_init_numtable_with_size
-#define st_init_strtable onig_st_init_strtable
-#define st_init_strtable_with_size onig_st_init_strtable_with_size
-#define st_init_strend_table_with_size onig_st_init_strend_table_with_size
-#define st_delete onig_st_delete
-#define st_delete_safe onig_st_delete_safe
-#define st_insert onig_st_insert
-#define st_insert_strend onig_st_insert_strend
-#define st_lookup onig_st_lookup
-#define st_lookup_strend onig_st_lookup_strend
-#define st_foreach onig_st_foreach
-#define st_add_direct onig_st_add_direct
-#define st_add_direct_strend onig_st_add_direct_strend
-#define st_free_table onig_st_free_table
-#define st_cleanup_safe onig_st_cleanup_safe
-#define st_copy onig_st_copy
-#define st_nothing_key_clone onig_st_nothing_key_clone
-#define st_nothing_key_free onig_st_nothing_key_free
-
-#else /* NOT_RUBY */
-
-#define onig_st_init_table st_init_table
-#define onig_st_init_table_with_size st_init_table_with_size
-#define onig_st_init_numtable st_init_numtable
-#define onig_st_init_numtable_with_size st_init_numtable_with_size
-#define onig_st_init_strtable st_init_strtable
-#define onig_st_init_strtable_with_size st_init_strtable_with_size
-#define onig_st_init_strend_table_with_size st_init_strend_table_with_size
-#define onig_st_delete st_delete
-#define onig_st_delete_safe st_delete_safe
-#define onig_st_insert st_insert
-#define onig_st_insert_strend st_insert_strend
-#define onig_st_lookup st_lookup
-#define onig_st_lookup_strend st_lookup_strend
-#define onig_st_foreach st_foreach
-#define onig_st_add_direct st_add_direct
-#define onig_st_add_direct_strend st_add_direct_strend
-#define onig_st_free_table st_free_table
-#define onig_st_cleanup_safe st_cleanup_safe
-#define onig_st_copy st_copy
-#define onig_st_nothing_key_clone st_nothing_key_clone
-#define onig_st_nothing_key_free st_nothing_key_free
-
-#endif /* NOT_RUBY */
-
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#if defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
-#include <alloca.h>
-#endif
-
-#ifdef HAVE_STRING_H
-# include <string.h>
-#else
-# include <strings.h>
-#endif
-
-#include <ctype.h>
-#ifdef HAVE_SYS_TYPES_H
-#ifndef __BORLANDC__
-#include <sys/types.h>
-#endif
-#endif
-
-#ifdef ONIG_DEBUG
-# include <stdio.h>
-#endif
-
-#include "regenc.h"
-#include "oniguruma.h"
-
-#ifdef MIN
-#undef MIN
-#endif
-#ifdef MAX
-#undef MAX
-#endif
-#define MIN(a,b) (((a)>(b))?(b):(a))
-#define MAX(a,b) (((a)<(b))?(b):(a))
-
-#define IS_NULL(p) (((void*)(p)) == (void*)0)
-#define IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
-#define CHECK_NULL_RETURN(p) if (IS_NULL(p)) return NULL
-#define CHECK_NULL_RETURN_VAL(p,val) if (IS_NULL(p)) return (val)
-#define NULL_UCHARP ((UChar* )0)
-
-#ifndef PLATFORM_UNALIGNED_WORD_ACCESS
-#define WORD_ALIGNMENT_SIZE SIZEOF_INT
-
-#define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\
- (pad_size) = WORD_ALIGNMENT_SIZE \
- - ((unsigned int )(addr) % WORD_ALIGNMENT_SIZE);\
- if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\
-} while (0)
-
-#define ALIGNMENT_RIGHT(addr) do {\
- (addr) += (WORD_ALIGNMENT_SIZE - 1);\
- (addr) -= ((unsigned int )(addr) % WORD_ALIGNMENT_SIZE);\
-} while (0)
-
-
-#define B_SHIFT 8
-#define B_MASK 0xff
-
-#define SERIALIZE_2BYTE_INT(i,p) do {\
- *(p) = ((i) >> B_SHIFT) & B_MASK;\
- *((p)+1) = (i) & B_MASK;\
-} while (0)
-
-#define SERIALIZE_4BYTE_INT(i,p) do {\
- *(p) = ((i) >> B_SHIFT*3) & B_MASK;\
- *((p)+1) = ((i) >> B_SHIFT*2) & B_MASK;\
- *((p)+2) = ((i) >> B_SHIFT ) & B_MASK;\
- *((p)+3) = (i) & B_MASK;\
-} while (0)
-
-#define SERIALIZE_8BYTE_INT(i,p) do {\
- *(p) = ((i) >> B_SHIFT*7) & B_MASK;\
- *((p)+1) = ((i) >> B_SHIFT*6) & B_MASK;\
- *((p)+2) = ((i) >> B_SHIFT*5) & B_MASK;\
- *((p)+3) = ((i) >> B_SHIFT*4) & B_MASK;\
- *((p)+4) = ((i) >> B_SHIFT*3) & B_MASK;\
- *((p)+5) = ((i) >> B_SHIFT*2) & B_MASK;\
- *((p)+6) = ((i) >> B_SHIFT ) & B_MASK;\
- *((p)+7) = (i) & B_MASK;\
-} while (0)
-
-#define GET_2BYTE_INT_INC(type,i,p) do {\
- (i) = (type )(((unsigned int )(*(p)) << B_SHIFT) | (unsigned int )((p)[1]));\
- (p) += 2;\
-} while (0)
-
-#define GET_4BYTE_INT_INC(type,i,p) do {\
- (i) = (type )(((unsigned int )((p)[0]) << B_SHIFT*3) | \
- ((unsigned int )((p)[1]) << B_SHIFT*2) | \
- ((unsigned int )((p)[2]) << B_SHIFT ) | \
- ((unsigned int )((p)[3]) )); \
- (p) += 4;\
-} while (0)
-
-#define GET_8BYTE_INT_INC(type,i,p) do {\
- (i) = (type )(((unsigned long )((p)[0]) << B_SHIFT*7) | \
- ((unsigned long )((p)[1]) << B_SHIFT*6) | \
- ((unsigned long )((p)[2]) << B_SHIFT*5) | \
- ((unsigned long )((p)[3]) << B_SHIFT*4) | \
- ((unsigned long )((p)[4]) << B_SHIFT*3) | \
- ((unsigned long )((p)[5]) << B_SHIFT*2) | \
- ((unsigned long )((p)[6]) << B_SHIFT ) | \
- ((unsigned long )((p)[7]) )); \
- (p) += 8;\
-} while (0)
-
-#if SIZEOF_SHORT == 2
-#define GET_SHORT_INC(i,p) GET_2BYTE_INT_INC(short,i,p)
-#define SERIALIZE_SHORT(i,p) SERIALIZE_2BYTE_INT(i,p)
-#elif SIZEOF_SHORT == 4
-#define GET_SHORT_INC(i,p) GET_4BYTE_INT_INC(short,i,p)
-#define SERIALIZE_SHORT(i,p) SERIALIZE_4BYTE_INT(i,p)
-#elif SIZEOF_SHORT == 8
-#define GET_SHORT_INC(i,p) GET_8BYTE_INT_INC(short,i,p)
-#define SERIALIZE_SHORT(i,p) SERIALIZE_8BYTE_INT(i,p)
-#endif
-
-#if SIZEOF_INT == 2
-#define GET_INT_INC(i,p) GET_2BYTE_INT_INC(int,i,p)
-#define GET_UINT_INC(i,p) GET_2BYTE_INT_INC(unsigned,i,p)
-#define SERIALIZE_INT(i,p) SERIALIZE_2BYTE_INT(i,p)
-#define SERIALIZE_UINT(i,p) SERIALIZE_2BYTE_INT(i,p)
-#elif SIZEOF_INT == 4
-#define GET_INT_INC(i,p) GET_4BYTE_INT_INC(int,i,p)
-#define GET_UINT_INC(i,p) GET_4BYTE_INT_INC(unsigned,i,p)
-#define SERIALIZE_INT(i,p) SERIALIZE_4BYTE_INT(i,p)
-#define SERIALIZE_UINT(i,p) SERIALIZE_4BYTE_INT(i,p)
-#elif SIZEOF_INT == 8
-#define GET_INT_INC(i,p) GET_8BYTE_INT_INC(int,i,p)
-#define GET_UINT_INC(i,p) GET_8BYTE_INT_INC(unsigned,i,p)
-#define SERIALIZE_INT(i,p) SERIALIZE_8BYTE_INT(i,p)
-#define SERIALIZE_UINT(i,p) SERIALIZE_8BYTE_INT(i,p)
-#endif
-
-#endif /* PLATFORM_UNALIGNED_WORD_ACCESS */
-
-/* stack pop level */
-#define STACK_POP_LEVEL_FREE 0
-#define STACK_POP_LEVEL_MEM_START 1
-#define STACK_POP_LEVEL_ALL 2
-
-/* optimize flags */
-#define ONIG_OPTIMIZE_NONE 0
-#define ONIG_OPTIMIZE_EXACT 1 /* Slow Search */
-#define ONIG_OPTIMIZE_EXACT_BM 2 /* Boyer Moore Search */
-#define ONIG_OPTIMIZE_EXACT_BM_NOT_REV 3 /* BM (but not simple match) */
-#define ONIG_OPTIMIZE_EXACT_IC 4 /* Slow Search (ignore case) */
-#define ONIG_OPTIMIZE_MAP 5 /* char map */
-
-/* bit status */
-typedef unsigned int BitStatusType;
-
-#define BIT_STATUS_BITS_NUM (sizeof(BitStatusType) * 8)
-#define BIT_STATUS_CLEAR(stats) (stats) = 0
-#define BIT_STATUS_ON_ALL(stats) (stats) = ~((BitStatusType )0)
-#define BIT_STATUS_AT(stats,n) \
- ((n) < BIT_STATUS_BITS_NUM ? ((stats) & (1 << n)) : ((stats) & 1))
-
-#define BIT_STATUS_ON_AT(stats,n) do {\
- if ((n) < BIT_STATUS_BITS_NUM)\
- (stats) |= (1 << (n));\
- else\
- (stats) |= 1;\
-} while (0)
-
-#define BIT_STATUS_ON_AT_SIMPLE(stats,n) do {\
- if ((n) < BIT_STATUS_BITS_NUM)\
- (stats) |= (1 << (n));\
-} while (0)
-
-
-#define INT_MAX_LIMIT ((1UL << (SIZEOF_INT * 8 - 1)) - 1)
-
-#define DIGITVAL(code) ((code) - '0')
-#define ODIGITVAL(code) DIGITVAL(code)
-#define XDIGITVAL(enc,code) \
- (ONIGENC_IS_CODE_DIGIT(enc,code) ? DIGITVAL(code) \
- : (ONIGENC_IS_CODE_UPPER(enc,code) ? (code) - 'A' + 10 : (code) - 'a' + 10))
-
-#define IS_SINGLELINE(option) ((option) & ONIG_OPTION_SINGLELINE)
-#define IS_MULTILINE(option) ((option) & ONIG_OPTION_MULTILINE)
-#define IS_IGNORECASE(option) ((option) & ONIG_OPTION_IGNORECASE)
-#define IS_EXTEND(option) ((option) & ONIG_OPTION_EXTEND)
-#define IS_FIND_LONGEST(option) ((option) & ONIG_OPTION_FIND_LONGEST)
-#define IS_FIND_NOT_EMPTY(option) ((option) & ONIG_OPTION_FIND_NOT_EMPTY)
-#define IS_POSIXLINE(option) (IS_SINGLELINE(option) && IS_MULTILINE(option))
-#define IS_FIND_CONDITION(option) ((option) & \
- (ONIG_OPTION_FIND_LONGEST | ONIG_OPTION_FIND_NOT_EMPTY))
-#define IS_NOTBOL(option) ((option) & ONIG_OPTION_NOTBOL)
-#define IS_NOTEOL(option) ((option) & ONIG_OPTION_NOTEOL)
-#define IS_POSIX_REGION(option) ((option) & ONIG_OPTION_POSIX_REGION)
-
-/* OP_SET_OPTION is required for these options.
-#define IS_DYNAMIC_OPTION(option) \
- (((option) & (ONIG_OPTION_MULTILINE | ONIG_OPTION_IGNORECASE)) != 0)
-*/
-/* ignore-case and multibyte status are included in compiled code. */
-#define IS_DYNAMIC_OPTION(option) 0
-
-#define REPEAT_INFINITE -1
-#define IS_REPEAT_INFINITE(n) ((n) == REPEAT_INFINITE)
-
-/* bitset */
-#define BITS_PER_BYTE 8
-#define SINGLE_BYTE_SIZE (1 << BITS_PER_BYTE)
-#define BITS_IN_ROOM (sizeof(Bits) * BITS_PER_BYTE)
-#define BITSET_SIZE (SINGLE_BYTE_SIZE / BITS_IN_ROOM)
-
-#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
-typedef unsigned int Bits;
-#else
-typedef unsigned char Bits;
-#endif
-typedef Bits BitSet[BITSET_SIZE];
-typedef Bits* BitSetRef;
-
-#define SIZE_BITSET sizeof(BitSet)
-
-#define BITSET_CLEAR(bs) do {\
- int i;\
- for (i = 0; i < BITSET_SIZE; i++) { (bs)[i] = 0; }\
-} while (0)
-
-#define BS_ROOM(bs,pos) (bs)[pos / BITS_IN_ROOM]
-#define BS_BIT(pos) (1 << (pos % BITS_IN_ROOM))
-
-#define BITSET_AT(bs, pos) (BS_ROOM(bs,pos) & BS_BIT(pos))
-#define BITSET_SET_BIT(bs, pos) BS_ROOM(bs,pos) |= BS_BIT(pos)
-#define BITSET_CLEAR_BIT(bs, pos) BS_ROOM(bs,pos) &= ~(BS_BIT(pos))
-#define BITSET_INVERT_BIT(bs, pos) BS_ROOM(bs,pos) ^= BS_BIT(pos)
-
-/* bytes buffer */
-typedef struct _BBuf {
- UChar* p;
- unsigned int used;
- unsigned int alloc;
-} BBuf;
-
-#define BBUF_INIT(buf,size) onig_bbuf_init((BBuf* )(buf), (size))
-
-#define BBUF_SIZE_INC(buf,inc) do{\
- (buf)->alloc += (inc);\
- (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
- if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
-} while (0)
-
-#define BBUF_EXPAND(buf,low) do{\
- do { (buf)->alloc *= 2; } while ((buf)->alloc < (unsigned int )low);\
- (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
- if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
-} while (0)
-
-#define BBUF_ENSURE_SIZE(buf,size) do{\
- unsigned int new_alloc = (buf)->alloc;\
- while (new_alloc < (unsigned int )(size)) { new_alloc *= 2; }\
- if ((buf)->alloc != new_alloc) {\
- (buf)->p = (UChar* )xrealloc((buf)->p, new_alloc);\
- if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
- (buf)->alloc = new_alloc;\
- }\
-} while (0)
-
-#define BBUF_WRITE(buf,pos,bytes,n) do{\
- int used = (pos) + (n);\
- if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
- xmemcpy((buf)->p + (pos), (bytes), (n));\
- if ((buf)->used < (unsigned int )used) (buf)->used = used;\
-} while (0)
-
-#define BBUF_WRITE1(buf,pos,byte) do{\
- int used = (pos) + 1;\
- if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
- (buf)->p[(pos)] = (byte);\
- if ((buf)->used < (unsigned int )used) (buf)->used = used;\
-} while (0)
-
-#define BBUF_ADD(buf,bytes,n) BBUF_WRITE((buf),(buf)->used,(bytes),(n))
-#define BBUF_ADD1(buf,byte) BBUF_WRITE1((buf),(buf)->used,(byte))
-#define BBUF_GET_ADD_ADDRESS(buf) ((buf)->p + (buf)->used)
-#define BBUF_GET_OFFSET_POS(buf) ((buf)->used)
-
-/* from < to */
-#define BBUF_MOVE_RIGHT(buf,from,to,n) do {\
- if ((unsigned int )((to)+(n)) > (buf)->alloc) BBUF_EXPAND((buf),(to) + (n));\
- xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
- if ((unsigned int )((to)+(n)) > (buf)->used) (buf)->used = (to) + (n);\
-} while (0)
-
-/* from > to */
-#define BBUF_MOVE_LEFT(buf,from,to,n) do {\
- xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
-} while (0)
-
-/* from > to */
-#define BBUF_MOVE_LEFT_REDUCE(buf,from,to) do {\
- xmemmove((buf)->p + (to), (buf)->p + (from), (buf)->used - (from));\
- (buf)->used -= (from - to);\
-} while (0)
-
-#define BBUF_INSERT(buf,pos,bytes,n) do {\
- if (pos >= (buf)->used) {\
- BBUF_WRITE(buf,pos,bytes,n);\
- }\
- else {\
- BBUF_MOVE_RIGHT((buf),(pos),(pos) + (n),((buf)->used - (pos)));\
- xmemcpy((buf)->p + (pos), (bytes), (n));\
- }\
-} while (0)
-
-#define BBUF_GET_BYTE(buf, pos) (buf)->p[(pos)]
-
-
-#define ANCHOR_BEGIN_BUF (1<<0)
-#define ANCHOR_BEGIN_LINE (1<<1)
-#define ANCHOR_BEGIN_POSITION (1<<2)
-#define ANCHOR_END_BUF (1<<3)
-#define ANCHOR_SEMI_END_BUF (1<<4)
-#define ANCHOR_END_LINE (1<<5)
-
-#define ANCHOR_WORD_BOUND (1<<6)
-#define ANCHOR_NOT_WORD_BOUND (1<<7)
-#define ANCHOR_WORD_BEGIN (1<<8)
-#define ANCHOR_WORD_END (1<<9)
-#define ANCHOR_PREC_READ (1<<10)
-#define ANCHOR_PREC_READ_NOT (1<<11)
-#define ANCHOR_LOOK_BEHIND (1<<12)
-#define ANCHOR_LOOK_BEHIND_NOT (1<<13)
-
-#define ANCHOR_ANYCHAR_STAR (1<<14) /* ".*" optimize info */
-#define ANCHOR_ANYCHAR_STAR_ML (1<<15) /* ".*" optimize info (multi-line) */
-
-/* operation code */
-enum OpCode {
- OP_FINISH = 0, /* matching process terminator (no more alternative) */
- OP_END = 1, /* pattern code terminator (success end) */
-
- OP_EXACT1 = 2, /* single byte, N = 1 */
- OP_EXACT2, /* single byte, N = 2 */
- OP_EXACT3, /* single byte, N = 3 */
- OP_EXACT4, /* single byte, N = 4 */
- OP_EXACT5, /* single byte, N = 5 */
- OP_EXACTN, /* single byte */
- OP_EXACTMB2N1, /* mb-length = 2 N = 1 */
- OP_EXACTMB2N2, /* mb-length = 2 N = 2 */
- OP_EXACTMB2N3, /* mb-length = 2 N = 3 */
- OP_EXACTMB2N, /* mb-length = 2 */
- OP_EXACTMB3N, /* mb-length = 3 */
- OP_EXACTMBN, /* other length */
-
- OP_EXACT1_IC, /* single byte, N = 1, ignore case */
- OP_EXACTN_IC, /* single byte, ignore case */
-
- OP_CCLASS,
- OP_CCLASS_MB,
- OP_CCLASS_MIX,
- OP_CCLASS_NOT,
- OP_CCLASS_MB_NOT,
- OP_CCLASS_MIX_NOT,
- OP_CCLASS_NODE, /* pointer to CClassNode node */
-
- OP_ANYCHAR, /* "." */
- OP_ANYCHAR_ML, /* "." multi-line */
- OP_ANYCHAR_STAR, /* ".*" */
- OP_ANYCHAR_ML_STAR, /* ".*" multi-line */
- OP_ANYCHAR_STAR_PEEK_NEXT,
- OP_ANYCHAR_ML_STAR_PEEK_NEXT,
-
- OP_WORD,
- OP_NOT_WORD,
- OP_WORD_BOUND,
- OP_NOT_WORD_BOUND,
- OP_WORD_BEGIN,
- OP_WORD_END,
-
- OP_BEGIN_BUF,
- OP_END_BUF,
- OP_BEGIN_LINE,
- OP_END_LINE,
- OP_SEMI_END_BUF,
- OP_BEGIN_POSITION,
-
- OP_BACKREF1,
- OP_BACKREF2,
- OP_BACKREFN,
- OP_BACKREFN_IC,
- OP_BACKREF_MULTI,
- OP_BACKREF_MULTI_IC,
- OP_BACKREF_AT_LEVEL, /* \k<xxx+n>, \k<xxx-n> */
-
- OP_MEMORY_START,
- OP_MEMORY_START_PUSH, /* push back-tracker to stack */
- OP_MEMORY_END_PUSH, /* push back-tracker to stack */
- OP_MEMORY_END_PUSH_REC, /* push back-tracker to stack */
- OP_MEMORY_END,
- OP_MEMORY_END_REC, /* push marker to stack */
-
- OP_SET_OPTION_PUSH, /* set option and push recover option */
- OP_SET_OPTION, /* set option */
-
- OP_FAIL, /* pop stack and move */
- OP_JUMP,
- OP_PUSH,
- OP_POP,
- OP_PUSH_OR_JUMP_EXACT1, /* if match exact then push, else jump. */
- OP_PUSH_IF_PEEK_NEXT, /* if match exact then push, else none. */
- OP_REPEAT, /* {n,m} */
- OP_REPEAT_NG, /* {n,m}? (non greedy) */
- OP_REPEAT_INC,
- OP_REPEAT_INC_NG, /* non greedy */
- OP_REPEAT_INC_SG, /* search and get in stack */
- OP_REPEAT_INC_NG_SG, /* search and get in stack (non greedy) */
- OP_NULL_CHECK_START, /* null loop checker start */
- OP_NULL_CHECK_END, /* null loop checker end */
- OP_NULL_CHECK_END_MEMST, /* null loop checker end (with capture status) */
- OP_NULL_CHECK_END_MEMST_PUSH, /* with capture status and push check-end */
-
- OP_PUSH_POS, /* (?=...) start */
- OP_POP_POS, /* (?=...) end */
- OP_PUSH_POS_NOT, /* (?!...) start */
- OP_FAIL_POS, /* (?!...) end */
- OP_PUSH_STOP_BT, /* (?>...) start */
- OP_POP_STOP_BT, /* (?>...) end */
- OP_LOOK_BEHIND, /* (?<=...) start (no needs end opcode) */
- OP_PUSH_LOOK_BEHIND_NOT, /* (?<!...) start */
- OP_FAIL_LOOK_BEHIND_NOT, /* (?<!...) end */
-
- OP_CALL, /* \g<name> */
- OP_RETURN,
-
- OP_STATE_CHECK_PUSH, /* combination explosion check and push */
- OP_STATE_CHECK_PUSH_OR_JUMP, /* check ok -> push, else jump */
- OP_STATE_CHECK, /* check only */
- OP_STATE_CHECK_ANYCHAR_STAR,
- OP_STATE_CHECK_ANYCHAR_ML_STAR
-};
-
-typedef int RelAddrType;
-typedef int AbsAddrType;
-typedef int LengthType;
-typedef int RepeatNumType;
-typedef short int MemNumType;
-typedef short int StateCheckNumType;
-typedef void* PointerType;
-
-#define SIZE_OPCODE 1
-#define SIZE_RELADDR sizeof(RelAddrType)
-#define SIZE_ABSADDR sizeof(AbsAddrType)
-#define SIZE_LENGTH sizeof(LengthType)
-#define SIZE_MEMNUM sizeof(MemNumType)
-#define SIZE_STATE_CHECK_NUM sizeof(StateCheckNumType)
-#define SIZE_REPEATNUM sizeof(RepeatNumType)
-#define SIZE_OPTION sizeof(OnigOptionType)
-#define SIZE_CODE_POINT sizeof(OnigCodePoint)
-#define SIZE_POINTER sizeof(PointerType)
-
-
-#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
-
-#define PLATFORM_GET_INC(val,p,type) do{\
- val = *(type* )p;\
- (p) += sizeof(type);\
-} while(0)
-
-#else
-
-#define PLATFORM_GET_INC(val,p,type) do{\
- xmemcpy(&val, (p), sizeof(type));\
- (p) += sizeof(type);\
-} while(0)
-
-#endif /* PLATFORM_UNALIGNED_WORD_ACCESS */
-
-#define GET_RELADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, RelAddrType)
-#define GET_ABSADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, AbsAddrType)
-#define GET_LENGTH_INC(len,p) PLATFORM_GET_INC(len, p, LengthType)
-#define GET_MEMNUM_INC(num,p) PLATFORM_GET_INC(num, p, MemNumType)
-#define GET_REPEATNUM_INC(num,p) PLATFORM_GET_INC(num, p, RepeatNumType)
-#define GET_OPTION_INC(option,p) PLATFORM_GET_INC(option, p, OnigOptionType)
-#define GET_POINTER_INC(ptr,p) PLATFORM_GET_INC(ptr, p, PointerType)
-#define GET_STATE_CHECK_NUM_INC(num,p) PLATFORM_GET_INC(num, p, StateCheckNumType)
-
-/* code point's address must be aligned address. */
-#define GET_CODE_POINT(code,p) code = *((OnigCodePoint* )(p))
-#define GET_BYTE_INC(byte,p) do{\
- byte = *(p);\
- (p)++;\
-} while(0)
-
-
-/* op-code + arg size */
-#define SIZE_OP_ANYCHAR_STAR SIZE_OPCODE
-#define SIZE_OP_ANYCHAR_STAR_PEEK_NEXT (SIZE_OPCODE + 1)
-#define SIZE_OP_JUMP (SIZE_OPCODE + SIZE_RELADDR)
-#define SIZE_OP_PUSH (SIZE_OPCODE + SIZE_RELADDR)
-#define SIZE_OP_POP SIZE_OPCODE
-#define SIZE_OP_PUSH_OR_JUMP_EXACT1 (SIZE_OPCODE + SIZE_RELADDR + 1)
-#define SIZE_OP_PUSH_IF_PEEK_NEXT (SIZE_OPCODE + SIZE_RELADDR + 1)
-#define SIZE_OP_REPEAT_INC (SIZE_OPCODE + SIZE_MEMNUM)
-#define SIZE_OP_REPEAT_INC_NG (SIZE_OPCODE + SIZE_MEMNUM)
-#define SIZE_OP_PUSH_POS SIZE_OPCODE
-#define SIZE_OP_PUSH_POS_NOT (SIZE_OPCODE + SIZE_RELADDR)
-#define SIZE_OP_POP_POS SIZE_OPCODE
-#define SIZE_OP_FAIL_POS SIZE_OPCODE
-#define SIZE_OP_SET_OPTION (SIZE_OPCODE + SIZE_OPTION)
-#define SIZE_OP_SET_OPTION_PUSH (SIZE_OPCODE + SIZE_OPTION)
-#define SIZE_OP_FAIL SIZE_OPCODE
-#define SIZE_OP_MEMORY_START (SIZE_OPCODE + SIZE_MEMNUM)
-#define SIZE_OP_MEMORY_START_PUSH (SIZE_OPCODE + SIZE_MEMNUM)
-#define SIZE_OP_MEMORY_END_PUSH (SIZE_OPCODE + SIZE_MEMNUM)
-#define SIZE_OP_MEMORY_END_PUSH_REC (SIZE_OPCODE + SIZE_MEMNUM)
-#define SIZE_OP_MEMORY_END (SIZE_OPCODE + SIZE_MEMNUM)
-#define SIZE_OP_MEMORY_END_REC (SIZE_OPCODE + SIZE_MEMNUM)
-#define SIZE_OP_PUSH_STOP_BT SIZE_OPCODE
-#define SIZE_OP_POP_STOP_BT SIZE_OPCODE
-#define SIZE_OP_NULL_CHECK_START (SIZE_OPCODE + SIZE_MEMNUM)
-#define SIZE_OP_NULL_CHECK_END (SIZE_OPCODE + SIZE_MEMNUM)
-#define SIZE_OP_LOOK_BEHIND (SIZE_OPCODE + SIZE_LENGTH)
-#define SIZE_OP_PUSH_LOOK_BEHIND_NOT (SIZE_OPCODE + SIZE_RELADDR + SIZE_LENGTH)
-#define SIZE_OP_FAIL_LOOK_BEHIND_NOT SIZE_OPCODE
-#define SIZE_OP_CALL (SIZE_OPCODE + SIZE_ABSADDR)
-#define SIZE_OP_RETURN SIZE_OPCODE
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
-#define SIZE_OP_STATE_CHECK (SIZE_OPCODE + SIZE_STATE_CHECK_NUM)
-#define SIZE_OP_STATE_CHECK_PUSH (SIZE_OPCODE + SIZE_STATE_CHECK_NUM + SIZE_RELADDR)
-#define SIZE_OP_STATE_CHECK_PUSH_OR_JUMP (SIZE_OPCODE + SIZE_STATE_CHECK_NUM + SIZE_RELADDR)
-#define SIZE_OP_STATE_CHECK_ANYCHAR_STAR (SIZE_OPCODE + SIZE_STATE_CHECK_NUM)
-#endif
-
-#define MC_ESC(enc) (enc)->meta_char_table.esc
-#define MC_ANYCHAR(enc) (enc)->meta_char_table.anychar
-#define MC_ANYTIME(enc) (enc)->meta_char_table.anytime
-#define MC_ZERO_OR_ONE_TIME(enc) (enc)->meta_char_table.zero_or_one_time
-#define MC_ONE_OR_MORE_TIME(enc) (enc)->meta_char_table.one_or_more_time
-#define MC_ANYCHAR_ANYTIME(enc) (enc)->meta_char_table.anychar_anytime
-
-#define IS_MC_ESC_CODE(code, enc, syn) \
- ((code) == MC_ESC(enc) && \
- !IS_SYNTAX_OP2((syn), ONIG_SYN_OP2_INEFFECTIVE_ESCAPE))
-
-
-#define SYN_POSIX_COMMON_OP \
- ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_POSIX_BRACKET | \
- ONIG_SYN_OP_DECIMAL_BACKREF | \
- ONIG_SYN_OP_BRACKET_CC | ONIG_SYN_OP_ASTERISK_ZERO_INF | \
- ONIG_SYN_OP_LINE_ANCHOR | \
- ONIG_SYN_OP_ESC_CONTROL_CHARS )
-
-#define SYN_GNU_REGEX_OP \
- ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC | \
- ONIG_SYN_OP_POSIX_BRACKET | ONIG_SYN_OP_DECIMAL_BACKREF | \
- ONIG_SYN_OP_BRACE_INTERVAL | ONIG_SYN_OP_LPAREN_SUBEXP | \
- ONIG_SYN_OP_VBAR_ALT | \
- ONIG_SYN_OP_ASTERISK_ZERO_INF | ONIG_SYN_OP_PLUS_ONE_INF | \
- ONIG_SYN_OP_QMARK_ZERO_ONE | \
- ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR | ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR | \
- ONIG_SYN_OP_ESC_W_WORD | \
- ONIG_SYN_OP_ESC_B_WORD_BOUND | ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END | \
- ONIG_SYN_OP_ESC_S_WHITE_SPACE | ONIG_SYN_OP_ESC_D_DIGIT | \
- ONIG_SYN_OP_LINE_ANCHOR )
-
-#define SYN_GNU_REGEX_BV \
- ( ONIG_SYN_CONTEXT_INDEP_ANCHORS | ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS | \
- ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS | ONIG_SYN_ALLOW_INVALID_INTERVAL | \
- ONIG_SYN_BACKSLASH_ESCAPE_IN_CC | ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC )
-
-/* cclass node */
-#define FLAG_CCLASS_NOT 1
-#define FLAG_CCLASS_SHARE (1<<1)
-
-#define CCLASS_SET_NOT(cc) (cc)->flags |= FLAG_CCLASS_NOT
-#define CCLASS_CLEAR_NOT(cc) (cc)->flags &= ~FLAG_CCLASS_NOT
-#define CCLASS_SET_SHARE(cc) (cc)->flags |= FLAG_CCLASS_SHARE
-#define IS_CCLASS_NOT(cc) (((cc)->flags & FLAG_CCLASS_NOT) != 0)
-#define IS_CCLASS_SHARE(cc) (((cc)->flags & FLAG_CCLASS_SHARE) != 0)
-
-typedef struct {
- int flags;
- BitSet bs;
- BBuf* mbuf; /* multi-byte info or NULL */
-} CClassNode;
-
-
-#ifdef ONIG_DEBUG
-
-typedef struct {
- short int opcode;
- char* name;
- short int arg_type;
-} OnigOpInfoType;
-
-extern OnigOpInfoType OnigOpInfo[];
-
-extern void onig_print_compiled_byte_code P_((FILE* f, UChar* bp, UChar** nextp, OnigEncoding enc));
-
-#ifdef ONIG_DEBUG_STATISTICS
-extern void onig_statistics_init P_((void));
-extern void onig_print_statistics P_((FILE* f));
-#endif
-#endif
-
-extern UChar* onig_error_code_to_format P_((int code));
-extern void onig_snprintf_with_pattern PV_((UChar buf[], int bufsize, OnigEncoding enc, UChar* pat, UChar* pat_end, const UChar *fmt, ...));
-extern int onig_bbuf_init P_((BBuf* buf, int size));
-extern int onig_alloc_init P_((regex_t** reg, OnigOptionType option, OnigAmbigType ambig_flag, OnigEncoding enc, OnigSyntaxType* syntax));
-extern int onig_compile P_((regex_t* reg, const UChar* pattern, const UChar* pattern_end, OnigErrorInfo* einfo));
-extern void onig_chain_reduce P_((regex_t* reg));
-extern void onig_chain_link_add P_((regex_t* to, regex_t* add));
-extern void onig_transfer P_((regex_t* to, regex_t* from));
-extern int onig_is_code_in_cc P_((OnigEncoding enc, OnigCodePoint code, CClassNode* cc));
-
-#endif /* REGINT_H */
diff --git a/regparse.c b/regparse.c
deleted file mode 100644
index 5bbd6a09ad..0000000000
--- a/regparse.c
+++ /dev/null
@@ -1,5352 +0,0 @@
-/**********************************************************************
- regparse.c - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "regparse.h"
-
-#define WARN_BUFSIZE 256
-
-OnigSyntaxType OnigSyntaxRuby = {
- (( SYN_GNU_REGEX_OP | ONIG_SYN_OP_QMARK_NON_GREEDY |
- ONIG_SYN_OP_ESC_OCTAL3 | ONIG_SYN_OP_ESC_X_HEX2 |
- ONIG_SYN_OP_ESC_X_BRACE_HEX8 | ONIG_SYN_OP_ESC_CONTROL_CHARS |
- ONIG_SYN_OP_ESC_C_CONTROL )
- & ~ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END )
- , ( ONIG_SYN_OP2_QMARK_GROUP_EFFECT |
- ONIG_SYN_OP2_OPTION_RUBY |
- ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP | ONIG_SYN_OP2_ESC_K_NAMED_BACKREF |
- ONIG_SYN_OP2_ESC_G_SUBEXP_CALL |
- ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT |
- ONIG_SYN_OP2_CCLASS_SET_OP | ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL |
- ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META | ONIG_SYN_OP2_ESC_V_VTAB |
- ONIG_SYN_OP2_ESC_H_XDIGIT )
- , ( SYN_GNU_REGEX_BV |
- ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV |
- ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND |
- ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP |
- ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME |
- ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY |
- ONIG_SYN_WARN_CC_OP_NOT_ESCAPED |
- ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT )
- , ONIG_OPTION_NONE
-};
-
-OnigSyntaxType* OnigDefaultSyntax = ONIG_SYNTAX_RUBY;
-
-extern void onig_null_warn(const char* s) { }
-
-#ifdef RUBY_PLATFORM
-extern void
-onig_rb_warn(const char* s)
-{
- rb_warn("%s", s);
-}
-
-extern void
-onig_rb_warning(const char* s)
-{
- rb_warning("%s", s);
-}
-#endif
-
-#ifdef DEFAULT_WARN_FUNCTION
-static OnigWarnFunc onig_warn = (OnigWarnFunc )DEFAULT_WARN_FUNCTION;
-#else
-static OnigWarnFunc onig_warn = onig_null_warn;
-#endif
-
-#ifdef DEFAULT_VERB_WARN_FUNCTION
-static OnigWarnFunc onig_verb_warn = (OnigWarnFunc )DEFAULT_VERB_WARN_FUNCTION;
-#else
-static OnigWarnFunc onig_verb_warn = onig_null_warn;
-#endif
-
-extern void onig_set_warn_func(OnigWarnFunc f)
-{
- onig_warn = f;
-}
-
-extern void onig_set_verb_warn_func(OnigWarnFunc f)
-{
- onig_verb_warn = f;
-}
-
-static void
-bbuf_free(BBuf* bbuf)
-{
- if (IS_NOT_NULL(bbuf)) {
- if (IS_NOT_NULL(bbuf->p)) xfree(bbuf->p);
- xfree(bbuf);
- }
-}
-
-static int
-bbuf_clone(BBuf** rto, BBuf* from)
-{
- int r;
- BBuf *to;
-
- *rto = to = (BBuf* )xmalloc(sizeof(BBuf));
- CHECK_NULL_RETURN_VAL(to, ONIGERR_MEMORY);
- r = BBUF_INIT(to, from->alloc);
- if (r != 0) return r;
- to->used = from->used;
- xmemcpy(to->p, from->p, from->used);
- return 0;
-}
-
-#define ONOFF(v,f,negative) (negative) ? ((v) &= ~(f)) : ((v) |= (f))
-
-#define MBCODE_START_POS(enc) \
- (OnigCodePoint )(ONIGENC_MBC_MINLEN(enc) > 1 ? 0 : 0x80)
-
-#define SET_ALL_MULTI_BYTE_RANGE(enc, pbuf) \
- add_code_range_to_buf(pbuf, MBCODE_START_POS(enc), ~((OnigCodePoint )0))
-
-#define ADD_ALL_MULTI_BYTE_RANGE(enc, mbuf) do {\
- if (! ONIGENC_IS_SINGLEBYTE(enc)) {\
- r = SET_ALL_MULTI_BYTE_RANGE(enc, &(mbuf));\
- if (r) return r;\
- }\
-} while (0)
-
-
-#define BITSET_IS_EMPTY(bs,empty) do {\
- int i;\
- empty = 1;\
- for (i = 0; i < BITSET_SIZE; i++) {\
- if ((bs)[i] != 0) {\
- empty = 0; break;\
- }\
- }\
-} while (0)
-
-static void
-bitset_set_range(BitSetRef bs, int from, int to)
-{
- int i;
- for (i = from; i <= to && i < SINGLE_BYTE_SIZE; i++) {
- BITSET_SET_BIT(bs, i);
- }
-}
-
-#if 0
-static void
-bitset_set_all(BitSetRef bs)
-{
- int i;
- for (i = 0; i < BITSET_SIZE; i++) {
- bs[i] = ~((Bits )0);
- }
-}
-#endif
-
-static void
-bitset_invert(BitSetRef bs)
-{
- int i;
- for (i = 0; i < BITSET_SIZE; i++) {
- bs[i] = ~(bs[i]);
- }
-}
-
-static void
-bitset_invert_to(BitSetRef from, BitSetRef to)
-{
- int i;
- for (i = 0; i < BITSET_SIZE; i++) {
- to[i] = ~(from[i]);
- }
-}
-
-static void
-bitset_and(BitSetRef dest, BitSetRef bs)
-{
- int i;
- for (i = 0; i < BITSET_SIZE; i++) {
- dest[i] &= bs[i];
- }
-}
-
-static void
-bitset_or(BitSetRef dest, BitSetRef bs)
-{
- int i;
- for (i = 0; i < BITSET_SIZE; i++) {
- dest[i] |= bs[i];
- }
-}
-
-static void
-bitset_copy(BitSetRef dest, BitSetRef bs)
-{
- int i;
- for (i = 0; i < BITSET_SIZE; i++) {
- dest[i] = bs[i];
- }
-}
-
-extern int
-onig_strncmp(const UChar* s1, const UChar* s2, int n)
-{
- int x;
-
- while (n-- > 0) {
- x = *s2++ - *s1++;
- if (x) return x;
- }
- return 0;
-}
-
-static void
-k_strcpy(UChar* dest, const UChar* src, const UChar* end)
-{
- int len = end - src;
- if (len > 0) {
- xmemcpy(dest, src, len);
- dest[len] = (UChar )0;
- }
-}
-
-static UChar*
-strdup_with_null(OnigEncoding enc, UChar* s, UChar* end)
-{
- int slen, term_len, i;
- UChar *r;
-
- slen = end - s;
- term_len = ONIGENC_MBC_MINLEN(enc);
-
- r = (UChar* )xmalloc(slen + term_len);
- CHECK_NULL_RETURN(r);
- xmemcpy(r, s, slen);
-
- for (i = 0; i < term_len; i++)
- r[slen + i] = (UChar )0;
-
- return r;
-}
-
-
-/* scan pattern methods */
-#define PEND_VALUE 0
-
-#define PFETCH_READY UChar* pfetch_prev
-#define PEND (p < end ? 0 : 1)
-#define PUNFETCH p = pfetch_prev
-#define PINC do { \
- pfetch_prev = p; \
- p += ONIGENC_MBC_ENC_LEN(enc, p); \
-} while (0)
-#define PFETCH(c) do { \
- c = ONIGENC_MBC_TO_CODE(enc, p, end); \
- pfetch_prev = p; \
- p += ONIGENC_MBC_ENC_LEN(enc, p); \
-} while (0)
-
-#define PPEEK (p < end ? ONIGENC_MBC_TO_CODE(enc, p, end) : PEND_VALUE)
-#define PPEEK_IS(c) (PPEEK == (OnigCodePoint )c)
-
-static UChar*
-k_strcat_capa(UChar* dest, UChar* dest_end, const UChar* src, const UChar* src_end,
- int capa)
-{
- UChar* r;
-
- if (dest)
- r = (UChar* )xrealloc(dest, capa + 1);
- else
- r = (UChar* )xmalloc(capa + 1);
-
- CHECK_NULL_RETURN(r);
- k_strcpy(r + (dest_end - dest), src, src_end);
- return r;
-}
-
-/* dest on static area */
-static UChar*
-strcat_capa_from_static(UChar* dest, UChar* dest_end,
- const UChar* src, const UChar* src_end, int capa)
-{
- UChar* r;
-
- r = (UChar* )xmalloc(capa + 1);
- CHECK_NULL_RETURN(r);
- k_strcpy(r, dest, dest_end);
- k_strcpy(r + (dest_end - dest), src, src_end);
- return r;
-}
-
-#ifdef USE_NAMED_GROUP
-
-#define INIT_NAME_BACKREFS_ALLOC_NUM 8
-
-typedef struct {
- UChar* name;
- int name_len; /* byte length */
- int back_num; /* number of backrefs */
- int back_alloc;
- int back_ref1;
- int* back_refs;
-} NameEntry;
-
-#ifdef USE_ST_HASH_TABLE
-
-#include "st.h"
-
-typedef struct {
- unsigned char* s;
- unsigned char* end;
-} st_strend_key;
-
-static int strend_cmp(st_strend_key*, st_strend_key*);
-static int strend_hash(st_strend_key*);
-
-static struct st_hash_type type_strend_hash = {
- strend_cmp,
- strend_hash,
-};
-
-static st_table*
-onig_st_init_strend_table_with_size(int size)
-{
- return onig_st_init_table_with_size(&type_strend_hash, size);
-}
-
-static int
-onig_st_lookup_strend(st_table *table, const UChar* str_key, const UChar* end_key, st_data_t *value)
-{
- st_strend_key key;
-
- key.s = (unsigned char* )str_key;
- key.end = (unsigned char* )end_key;
-
- return onig_st_lookup(table, (st_data_t )(&key), value);
-}
-
-static int
-onig_st_insert_strend(st_table *table, const UChar* str_key, const UChar* end_key, st_data_t value)
-{
- st_strend_key* key;
- int result;
-
- key = (st_strend_key* )xmalloc(sizeof(st_strend_key));
- key->s = (unsigned char* )str_key;
- key->end = (unsigned char* )end_key;
- result = onig_st_insert(table, (st_data_t )key, value);
- if (result) {
- xfree(key);
- }
- return result;
-}
-
-static int
-strend_cmp(st_strend_key* x, st_strend_key* y)
-{
- unsigned char *p, *q;
- int c;
-
- if ((x->end - x->s) != (y->end - y->s))
- return 1;
-
- p = x->s;
- q = y->s;
- while (p < x->end) {
- c = (int )*p - (int )*q;
- if (c != 0) return c;
-
- p++; q++;
- }
-
- return 0;
-}
-
-static int
-strend_hash(st_strend_key* x)
-{
- int val;
- unsigned char *p;
-
- val = 0;
- p = x->s;
- while (p < x->end) {
- val = val * 997 + (int )*p++;
- }
-
- return val + (val >> 5);
-}
-
-typedef st_table NameTable;
-typedef st_data_t HashDataType; /* 1.6 st.h doesn't define st_data_t type */
-
-#define NAMEBUF_SIZE 24
-#define NAMEBUF_SIZE_1 25
-
-#ifdef ONIG_DEBUG
-static int
-i_print_name_entry(UChar* key, NameEntry* e, void* arg)
-{
- int i;
- FILE* fp = (FILE* )arg;
-
- fprintf(fp, "%s: ", e->name);
- if (e->back_num == 0)
- fputs("-", fp);
- else if (e->back_num == 1)
- fprintf(fp, "%d", e->back_ref1);
- else {
- for (i = 0; i < e->back_num; i++) {
- if (i > 0) fprintf(fp, ", ");
- fprintf(fp, "%d", e->back_refs[i]);
- }
- }
- fputs("\n", fp);
- return ST_CONTINUE;
-}
-
-extern int
-onig_print_names(FILE* fp, regex_t* reg)
-{
- NameTable* t = (NameTable* )reg->name_table;
-
- if (IS_NOT_NULL(t)) {
- fprintf(fp, "name table\n");
- onig_st_foreach(t, i_print_name_entry, (HashDataType )fp);
- fputs("\n", fp);
- }
- return 0;
-}
-#endif
-
-static int
-i_free_name_entry(UChar* key, NameEntry* e, void* arg)
-{
- xfree(e->name);
- if (IS_NOT_NULL(e->back_refs)) xfree(e->back_refs);
- xfree(key);
- xfree(e);
- return ST_DELETE;
-}
-
-static int
-names_clear(regex_t* reg)
-{
- NameTable* t = (NameTable* )reg->name_table;
-
- if (IS_NOT_NULL(t)) {
- onig_st_foreach(t, i_free_name_entry, 0);
- }
- return 0;
-}
-
-extern int
-onig_names_free(regex_t* reg)
-{
- int r;
- NameTable* t;
-
- r = names_clear(reg);
- if (r) return r;
-
- t = (NameTable* )reg->name_table;
- if (IS_NOT_NULL(t)) onig_st_free_table(t);
- reg->name_table = (void* )NULL;
- return 0;
-}
-
-static NameEntry*
-name_find(regex_t* reg, const UChar* name, const UChar* name_end)
-{
- NameEntry* e;
- NameTable* t = (NameTable* )reg->name_table;
-
- e = (NameEntry* )NULL;
- if (IS_NOT_NULL(t)) {
- onig_st_lookup_strend(t, name, name_end, (HashDataType* )((void* )(&e)));
- }
- return e;
-}
-
-typedef struct {
- int (*func)(const UChar*, const UChar*,int,int*,regex_t*,void*);
- regex_t* reg;
- void* arg;
- int ret;
- OnigEncoding enc;
-} INamesArg;
-
-static int
-i_names(UChar* key, NameEntry* e, INamesArg* arg)
-{
- int r = (*(arg->func))(e->name,
- /*e->name + onigenc_str_bytelen_null(arg->enc, e->name), */
- e->name + e->name_len,
- e->back_num,
- (e->back_num > 1 ? e->back_refs : &(e->back_ref1)),
- arg->reg, arg->arg);
- if (r != 0) {
- arg->ret = r;
- return ST_STOP;
- }
- return ST_CONTINUE;
-}
-
-extern int
-onig_foreach_name(regex_t* reg,
- int (*func)(const UChar*, const UChar*,int,int*,regex_t*,void*),
- void* arg)
-{
- INamesArg narg;
- NameTable* t = (NameTable* )reg->name_table;
-
- narg.ret = 0;
- if (IS_NOT_NULL(t)) {
- narg.func = func;
- narg.reg = reg;
- narg.arg = arg;
- narg.enc = reg->enc; /* should be pattern encoding. */
- onig_st_foreach(t, i_names, (HashDataType )&narg);
- }
- return narg.ret;
-}
-
-static int
-i_renumber_name(UChar* key, NameEntry* e, GroupNumRemap* map)
-{
- int i;
-
- if (e->back_num > 1) {
- for (i = 0; i < e->back_num; i++) {
- e->back_refs[i] = map[e->back_refs[i]].new_val;
- }
- }
- else if (e->back_num == 1) {
- e->back_ref1 = map[e->back_ref1].new_val;
- }
-
- return ST_CONTINUE;
-}
-
-extern int
-onig_renumber_name_table(regex_t* reg, GroupNumRemap* map)
-{
- NameTable* t = (NameTable* )reg->name_table;
-
- if (IS_NOT_NULL(t)) {
- onig_st_foreach(t, i_renumber_name, (HashDataType )map);
- }
- return 0;
-}
-
-
-extern int
-onig_number_of_names(regex_t* reg)
-{
- NameTable* t = (NameTable* )reg->name_table;
-
- if (IS_NOT_NULL(t))
- return t->num_entries;
- else
- return 0;
-}
-
-#else /* USE_ST_HASH_TABLE */
-
-#define INIT_NAMES_ALLOC_NUM 8
-
-typedef struct {
- NameEntry* e;
- int num;
- int alloc;
-} NameTable;
-
-
-#ifdef ONIG_DEBUG
-extern int
-onig_print_names(FILE* fp, regex_t* reg)
-{
- int i, j;
- NameEntry* e;
- NameTable* t = (NameTable* )reg->name_table;
-
- if (IS_NOT_NULL(t) && t->num > 0) {
- fprintf(fp, "name table\n");
- for (i = 0; i < t->num; i++) {
- e = &(t->e[i]);
- fprintf(fp, "%s: ", e->name);
- if (e->back_num == 0) {
- fputs("-", fp);
- }
- else if (e->back_num == 1) {
- fprintf(fp, "%d", e->back_ref1);
- }
- else {
- for (j = 0; j < e->back_num; j++) {
- if (j > 0) fprintf(fp, ", ");
- fprintf(fp, "%d", e->back_refs[j]);
- }
- }
- fputs("\n", fp);
- }
- fputs("\n", fp);
- }
- return 0;
-}
-#endif
-
-static int
-names_clear(regex_t* reg)
-{
- int i;
- NameEntry* e;
- NameTable* t = (NameTable* )reg->name_table;
-
- if (IS_NOT_NULL(t)) {
- for (i = 0; i < t->num; i++) {
- e = &(t->e[i]);
- if (IS_NOT_NULL(e->name)) {
- xfree(e->name);
- e->name = NULL;
- e->name_len = 0;
- e->back_num = 0;
- e->back_alloc = 0;
- if (IS_NOT_NULL(e->back_refs)) xfree(e->back_refs);
- e->back_refs = (int* )NULL;
- }
- }
- if (IS_NOT_NULL(t->e)) {
- xfree(t->e);
- t->e = NULL;
- }
- t->num = 0;
- }
- return 0;
-}
-
-extern int
-onig_names_free(regex_t* reg)
-{
- int r;
- NameTable* t;
-
- r = names_clear(reg);
- if (r) return r;
-
- t = (NameTable* )reg->name_table;
- if (IS_NOT_NULL(t)) xfree(t);
- reg->name_table = NULL;
- return 0;
-}
-
-static NameEntry*
-name_find(regex_t* reg, UChar* name, UChar* name_end)
-{
- int i, len;
- NameEntry* e;
- NameTable* t = (NameTable* )reg->name_table;
-
- if (IS_NOT_NULL(t)) {
- len = name_end - name;
- for (i = 0; i < t->num; i++) {
- e = &(t->e[i]);
- if (len == e->name_len && onig_strncmp(name, e->name, len) == 0)
- return e;
- }
- }
- return (NameEntry* )NULL;
-}
-
-extern int
-onig_foreach_name(regex_t* reg,
- int (*func)(const UChar*, const UChar*,int,int*,regex_t*,void*),
- void* arg)
-{
- int i, r;
- NameEntry* e;
- NameTable* t = (NameTable* )reg->name_table;
-
- if (IS_NOT_NULL(t)) {
- for (i = 0; i < t->num; i++) {
- e = &(t->e[i]);
- r = (*func)(e->name, e->name + e->name_len, e->back_num,
- (e->back_num > 1 ? e->back_refs : &(e->back_ref1)),
- reg, arg);
- if (r != 0) return r;
- }
- }
- return 0;
-}
-
-extern int
-onig_number_of_names(regex_t* reg)
-{
- NameTable* t = (NameTable* )reg->name_table;
-
- if (IS_NOT_NULL(t))
- return t->num;
- else
- return 0;
-}
-
-#endif /* else USE_ST_HASH_TABLE */
-
-static int
-name_add(regex_t* reg, UChar* name, UChar* name_end, int backref, ScanEnv* env)
-{
- int alloc;
- NameEntry* e;
- NameTable* t = (NameTable* )reg->name_table;
-
- if (name_end - name <= 0)
- return ONIGERR_EMPTY_GROUP_NAME;
-
- e = name_find(reg, name, name_end);
- if (IS_NULL(e)) {
-#ifdef USE_ST_HASH_TABLE
- if (IS_NULL(t)) {
- t = onig_st_init_strend_table_with_size(5);
- reg->name_table = (void* )t;
- }
- e = (NameEntry* )xmalloc(sizeof(NameEntry));
- CHECK_NULL_RETURN_VAL(e, ONIGERR_MEMORY);
-
- e->name = strdup_with_null(reg->enc, name, name_end);
- if (IS_NULL(e->name)) return ONIGERR_MEMORY;
- onig_st_insert_strend(t, e->name, (e->name + (name_end - name)),
- (HashDataType )e);
-
- e->name_len = name_end - name;
- e->back_num = 0;
- e->back_alloc = 0;
- e->back_refs = (int* )NULL;
-
-#else
-
- if (IS_NULL(t)) {
- alloc = INIT_NAMES_ALLOC_NUM;
- t = (NameTable* )xmalloc(sizeof(NameTable));
- CHECK_NULL_RETURN_VAL(t, ONIGERR_MEMORY);
- t->e = NULL;
- t->alloc = 0;
- t->num = 0;
-
- t->e = (NameEntry* )xmalloc(sizeof(NameEntry) * alloc);
- if (IS_NULL(t->e)) {
- xfree(t);
- return ONIGERR_MEMORY;
- }
- t->alloc = alloc;
- reg->name_table = t;
- goto clear;
- }
- else if (t->num == t->alloc) {
- int i;
-
- alloc = t->alloc * 2;
- t->e = (NameEntry* )xrealloc(t->e, sizeof(NameEntry) * alloc);
- CHECK_NULL_RETURN_VAL(t->e, ONIGERR_MEMORY);
- t->alloc = alloc;
-
- clear:
- for (i = t->num; i < t->alloc; i++) {
- t->e[i].name = NULL;
- t->e[i].name_len = 0;
- t->e[i].back_num = 0;
- t->e[i].back_alloc = 0;
- t->e[i].back_refs = (int* )NULL;
- }
- }
- e = &(t->e[t->num]);
- t->num++;
- e->name = strdup_with_null(reg->enc, name, name_end);
- e->name_len = name_end - name;
-#endif
- }
-
- if (e->back_num >= 1 &&
- ! IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME)) {
- onig_scan_env_set_error_string(env, ONIGERR_MULTIPLEX_DEFINED_NAME,
- name, name_end);
- return ONIGERR_MULTIPLEX_DEFINED_NAME;
- }
-
- e->back_num++;
- if (e->back_num == 1) {
- e->back_ref1 = backref;
- }
- else {
- if (e->back_num == 2) {
- alloc = INIT_NAME_BACKREFS_ALLOC_NUM;
- e->back_refs = (int* )xmalloc(sizeof(int) * alloc);
- CHECK_NULL_RETURN_VAL(e->back_refs, ONIGERR_MEMORY);
- e->back_alloc = alloc;
- e->back_refs[0] = e->back_ref1;
- e->back_refs[1] = backref;
- }
- else {
- if (e->back_num > e->back_alloc) {
- alloc = e->back_alloc * 2;
- e->back_refs = (int* )xrealloc(e->back_refs, sizeof(int) * alloc);
- CHECK_NULL_RETURN_VAL(e->back_refs, ONIGERR_MEMORY);
- e->back_alloc = alloc;
- }
- e->back_refs[e->back_num - 1] = backref;
- }
- }
-
- return 0;
-}
-
-extern int
-onig_name_to_group_numbers(regex_t* reg, const UChar* name,
- const UChar* name_end, int** nums)
-{
- NameEntry* e;
-
- e = name_find(reg, name, name_end);
- if (IS_NULL(e)) return ONIGERR_UNDEFINED_NAME_REFERENCE;
-
- switch (e->back_num) {
- case 0:
- break;
- case 1:
- *nums = &(e->back_ref1);
- break;
- default:
- *nums = e->back_refs;
- break;
- }
- return e->back_num;
-}
-
-extern int
-onig_name_to_backref_number(regex_t* reg, const UChar* name,
- const UChar* name_end, OnigRegion *region)
-{
- int i, n, *nums;
-
- n = onig_name_to_group_numbers(reg, name, name_end, &nums);
- if (n < 0)
- return n;
- else if (n == 0)
- return ONIGERR_PARSER_BUG;
- else if (n == 1)
- return nums[0];
- else {
- if (IS_NOT_NULL(region)) {
- for (i = n - 1; i >= 0; i--) {
- if (region->beg[nums[i]] != ONIG_REGION_NOTPOS)
- return nums[i];
- }
- }
- return nums[n - 1];
- }
-}
-
-#else /* USE_NAMED_GROUP */
-
-extern int
-onig_name_to_group_numbers(regex_t* reg, const UChar* name,
- const UChar* name_end, int** nums)
-{
- return ONIG_NO_SUPPORT_CONFIG;
-}
-
-extern int
-onig_name_to_backref_number(regex_t* reg, const UChar* name,
- const UChar* name_end, OnigRegion* region)
-{
- return ONIG_NO_SUPPORT_CONFIG;
-}
-
-extern int
-onig_foreach_name(regex_t* reg,
- int (*func)(const UChar*, const UChar*,int,int*,regex_t*,void*),
- void* arg)
-{
- return ONIG_NO_SUPPORT_CONFIG;
-}
-
-extern int
-onig_number_of_names(regex_t* reg)
-{
- return 0;
-}
-#endif /* else USE_NAMED_GROUP */
-
-extern int
-onig_noname_group_capture_is_active(regex_t* reg)
-{
- if (ONIG_IS_OPTION_ON(reg->options, ONIG_OPTION_DONT_CAPTURE_GROUP))
- return 0;
-
-#ifdef USE_NAMED_GROUP
- if (onig_number_of_names(reg) > 0 &&
- IS_SYNTAX_BV(reg->syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) &&
- !ONIG_IS_OPTION_ON(reg->options, ONIG_OPTION_CAPTURE_GROUP)) {
- return 0;
- }
-#endif
-
- return 1;
-}
-
-
-#define INIT_SCANENV_MEMNODES_ALLOC_SIZE 16
-
-static void
-scan_env_clear(ScanEnv* env)
-{
- int i;
-
- BIT_STATUS_CLEAR(env->capture_history);
- BIT_STATUS_CLEAR(env->bt_mem_start);
- BIT_STATUS_CLEAR(env->bt_mem_end);
- BIT_STATUS_CLEAR(env->backrefed_mem);
- env->error = (UChar* )NULL;
- env->error_end = (UChar* )NULL;
- env->num_call = 0;
- env->num_mem = 0;
-#ifdef USE_NAMED_GROUP
- env->num_named = 0;
-#endif
- env->mem_alloc = 0;
- env->mem_nodes_dynamic = (Node** )NULL;
-
- for (i = 0; i < SCANENV_MEMNODES_SIZE; i++)
- env->mem_nodes_static[i] = NULL_NODE;
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- env->num_comb_exp_check = 0;
- env->comb_exp_max_regnum = 0;
- env->curr_max_regnum = 0;
- env->has_recursion = 0;
-#endif
-}
-
-static int
-scan_env_add_mem_entry(ScanEnv* env)
-{
- int i, need, alloc;
- Node** p;
-
- need = env->num_mem + 1;
- if (need >= SCANENV_MEMNODES_SIZE) {
- if (env->mem_alloc <= need) {
- if (IS_NULL(env->mem_nodes_dynamic)) {
- alloc = INIT_SCANENV_MEMNODES_ALLOC_SIZE;
- p = (Node** )xmalloc(sizeof(Node*) * alloc);
- xmemcpy(p, env->mem_nodes_static,
- sizeof(Node*) * SCANENV_MEMNODES_SIZE);
- }
- else {
- alloc = env->mem_alloc * 2;
- p = (Node** )xrealloc(env->mem_nodes_dynamic, sizeof(Node*) * alloc);
- }
- CHECK_NULL_RETURN_VAL(p, ONIGERR_MEMORY);
-
- for (i = env->num_mem + 1; i < alloc; i++)
- p[i] = NULL_NODE;
-
- env->mem_nodes_dynamic = p;
- env->mem_alloc = alloc;
- }
- }
-
- env->num_mem++;
- return env->num_mem;
-}
-
-static int
-scan_env_set_mem_node(ScanEnv* env, int num, Node* node)
-{
- if (env->num_mem >= num)
- SCANENV_MEM_NODES(env)[num] = node;
- else
- return ONIGERR_PARSER_BUG;
- return 0;
-}
-
-
-#ifdef USE_RECYCLE_NODE
-typedef struct _FreeNode {
- struct _FreeNode* next;
-} FreeNode;
-
-static FreeNode* FreeNodeList = (FreeNode* )NULL;
-#endif
-
-extern void
-onig_node_free(Node* node)
-{
- start:
- if (IS_NULL(node)) return ;
-
- switch (NTYPE(node)) {
- case N_STRING:
- if (IS_NOT_NULL(NSTRING(node).s) && NSTRING(node).s != NSTRING(node).buf) {
- xfree(NSTRING(node).s);
- }
- break;
-
- case N_LIST:
- case N_ALT:
- onig_node_free(NCONS(node).left);
- /* onig_node_free(NCONS(node).right); */
- {
- Node* next_node = NCONS(node).right;
-
-#ifdef USE_RECYCLE_NODE
- {
- FreeNode* n = (FreeNode* )node;
-
- THREAD_ATOMIC_START;
- n->next = FreeNodeList;
- FreeNodeList = n;
- THREAD_ATOMIC_END;
- }
-#else
- xfree(node);
-#endif
-
- node = next_node;
- goto start;
- }
- break;
-
- case N_CCLASS:
- {
- CClassNode* cc = &(NCCLASS(node));
-
- if (IS_CCLASS_SHARE(cc))
- return ;
-
- if (cc->mbuf)
- bbuf_free(cc->mbuf);
- }
- break;
-
- case N_QUALIFIER:
- if (NQUALIFIER(node).target)
- onig_node_free(NQUALIFIER(node).target);
- break;
-
- case N_EFFECT:
- if (NEFFECT(node).target)
- onig_node_free(NEFFECT(node).target);
- break;
-
- case N_BACKREF:
- if (IS_NOT_NULL(NBACKREF(node).back_dynamic))
- xfree(NBACKREF(node).back_dynamic);
- break;
-
- case N_ANCHOR:
- if (NANCHOR(node).target)
- onig_node_free(NANCHOR(node).target);
- break;
- }
-
-#ifdef USE_RECYCLE_NODE
- {
- FreeNode* n = (FreeNode* )node;
-
- THREAD_ATOMIC_START;
- n->next = FreeNodeList;
- FreeNodeList = n;
- THREAD_ATOMIC_END;
- }
-#else
- xfree(node);
-#endif
-}
-
-#ifdef USE_RECYCLE_NODE
-extern int
-onig_free_node_list()
-{
- FreeNode* n;
-
- /* THREAD_ATOMIC_START; */
- while (IS_NOT_NULL(FreeNodeList)) {
- n = FreeNodeList;
- FreeNodeList = FreeNodeList->next;
- xfree(n);
- }
- /* THREAD_ATOMIC_END; */
- return 0;
-}
-#endif
-
-static Node*
-node_new()
-{
- Node* node;
-
-#ifdef USE_RECYCLE_NODE
- THREAD_ATOMIC_START;
- if (IS_NOT_NULL(FreeNodeList)) {
- node = (Node* )FreeNodeList;
- FreeNodeList = FreeNodeList->next;
- THREAD_ATOMIC_END;
- return node;
- }
- THREAD_ATOMIC_END;
-#endif
-
- node = (Node* )xmalloc(sizeof(Node));
- return node;
-}
-
-
-static void
-initialize_cclass(CClassNode* cc)
-{
- BITSET_CLEAR(cc->bs);
- cc->flags = 0;
- cc->mbuf = NULL;
-}
-
-static Node*
-node_new_cclass()
-{
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
- node->type = N_CCLASS;
-
- initialize_cclass(&(NCCLASS(node)));
- return node;
-}
-
-static Node*
-node_new_cclass_by_codepoint_range(int not,
- const OnigCodePoint sbr[], const OnigCodePoint mbr[])
-{
- CClassNode* cc;
- int n, i, j;
-
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
- node->type = N_CCLASS;
-
- cc = &(NCCLASS(node));
- cc->flags = 0;
- if (not != 0) CCLASS_SET_NOT(cc);
-
- BITSET_CLEAR(cc->bs);
- if (IS_NOT_NULL(sbr)) {
- n = ONIGENC_CODE_RANGE_NUM(sbr);
- for (i = 0; i < n; i++) {
- for (j = ONIGENC_CODE_RANGE_FROM(sbr, i);
- j <= (int )ONIGENC_CODE_RANGE_TO(sbr, i); j++) {
- BITSET_SET_BIT(cc->bs, j);
- }
- }
- }
-
- if (IS_NULL(mbr)) {
- is_null:
- cc->mbuf = NULL;
- }
- else {
- BBuf* bbuf;
-
- n = ONIGENC_CODE_RANGE_NUM(mbr);
- if (n == 0) goto is_null;
-
- bbuf = (BBuf* )xmalloc(sizeof(BBuf));
- CHECK_NULL_RETURN_VAL(bbuf, NULL);
- bbuf->alloc = n + 1;
- bbuf->used = n + 1;
- bbuf->p = (UChar* )((void* )mbr);
-
- cc->mbuf = bbuf;
- }
-
- return node;
-}
-
-static Node*
-node_new_ctype(int type)
-{
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
- node->type = N_CTYPE;
- NCTYPE(node).type = type;
- return node;
-}
-
-static Node*
-node_new_anychar()
-{
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
- node->type = N_ANYCHAR;
- return node;
-}
-
-static Node*
-node_new_list(Node* left, Node* right)
-{
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
- node->type = N_LIST;
- NCONS(node).left = left;
- NCONS(node).right = right;
- return node;
-}
-
-extern Node*
-onig_node_new_list(Node* left, Node* right)
-{
- return node_new_list(left, right);
-}
-
-static Node*
-node_new_alt(Node* left, Node* right)
-{
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
- node->type = N_ALT;
- NCONS(node).left = left;
- NCONS(node).right = right;
- return node;
-}
-
-extern Node*
-onig_node_new_anchor(int type)
-{
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
- node->type = N_ANCHOR;
- NANCHOR(node).type = type;
- NANCHOR(node).target = NULL;
- NANCHOR(node).char_len = -1;
- return node;
-}
-
-static Node*
-node_new_backref(int back_num, int* backrefs, int by_name,
-#ifdef USE_BACKREF_AT_LEVEL
- int exist_level, int nest_level,
-#endif
- ScanEnv* env)
-{
- int i;
- Node* node = node_new();
-
- CHECK_NULL_RETURN(node);
- node->type = N_BACKREF;
- NBACKREF(node).state = 0;
- NBACKREF(node).back_num = back_num;
- NBACKREF(node).back_dynamic = (int* )NULL;
- if (by_name != 0)
- NBACKREF(node).state |= NST_NAME_REF;
-
-#ifdef USE_BACKREF_AT_LEVEL
- if (exist_level != 0) {
- NBACKREF(node).state |= NST_NEST_LEVEL;
- NBACKREF(node).nest_level = nest_level;
- }
-#endif
-
- for (i = 0; i < back_num; i++) {
- if (backrefs[i] <= env->num_mem &&
- IS_NULL(SCANENV_MEM_NODES(env)[backrefs[i]])) {
- NBACKREF(node).state |= NST_RECURSION; /* /...(\1).../ */
- break;
- }
- }
-
- if (back_num <= NODE_BACKREFS_SIZE) {
- for (i = 0; i < back_num; i++)
- NBACKREF(node).back_static[i] = backrefs[i];
- }
- else {
- int* p = (int* )xmalloc(sizeof(int) * back_num);
- if (IS_NULL(p)) {
- onig_node_free(node);
- return NULL;
- }
- NBACKREF(node).back_dynamic = p;
- for (i = 0; i < back_num; i++)
- p[i] = backrefs[i];
- }
- return node;
-}
-
-#ifdef USE_SUBEXP_CALL
-static Node*
-node_new_call(UChar* name, UChar* name_end)
-{
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
-
- node->type = N_CALL;
- NCALL(node).state = 0;
- NCALL(node).ref_num = CALLNODE_REFNUM_UNDEF;
- NCALL(node).target = NULL_NODE;
- NCALL(node).name = name;
- NCALL(node).name_end = name_end;
- return node;
-}
-#endif
-
-static Node*
-node_new_qualifier(int lower, int upper, int by_number)
-{
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
- node->type = N_QUALIFIER;
- NQUALIFIER(node).state = 0;
- NQUALIFIER(node).target = NULL;
- NQUALIFIER(node).lower = lower;
- NQUALIFIER(node).upper = upper;
- NQUALIFIER(node).greedy = 1;
- NQUALIFIER(node).target_empty_info = NQ_TARGET_ISNOT_EMPTY;
- NQUALIFIER(node).head_exact = NULL_NODE;
- NQUALIFIER(node).next_head_exact = NULL_NODE;
- NQUALIFIER(node).is_refered = 0;
- if (by_number != 0)
- NQUALIFIER(node).state |= NST_BY_NUMBER;
-
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- NQUALIFIER(node).comb_exp_check_num = 0;
-#endif
-
- return node;
-}
-
-static Node*
-node_new_effect(int type)
-{
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
- node->type = N_EFFECT;
- NEFFECT(node).type = type;
- NEFFECT(node).state = 0;
- NEFFECT(node).regnum = 0;
- NEFFECT(node).option = 0;
- NEFFECT(node).target = NULL;
- NEFFECT(node).call_addr = -1;
- NEFFECT(node).opt_count = 0;
- return node;
-}
-
-extern Node*
-onig_node_new_effect(int type)
-{
- return node_new_effect(type);
-}
-
-static Node*
-node_new_effect_memory(OnigOptionType option, int is_named)
-{
- Node* node = node_new_effect(EFFECT_MEMORY);
- CHECK_NULL_RETURN(node);
- if (is_named != 0)
- SET_EFFECT_STATUS(node, NST_NAMED_GROUP);
-
-#ifdef USE_SUBEXP_CALL
- NEFFECT(node).option = option;
-#endif
- return node;
-}
-
-static Node*
-node_new_option(OnigOptionType option)
-{
- Node* node = node_new_effect(EFFECT_OPTION);
- CHECK_NULL_RETURN(node);
- NEFFECT(node).option = option;
- return node;
-}
-
-extern int
-onig_node_str_cat(Node* node, const UChar* s, const UChar* end)
-{
- int addlen = end - s;
-
- if (addlen > 0) {
- int len = NSTRING(node).end - NSTRING(node).s;
-
- if (NSTRING(node).capa > 0 || (len + addlen > NODE_STR_BUF_SIZE - 1)) {
- UChar* p;
- int capa = len + addlen + NODE_STR_MARGIN;
-
- if (capa <= NSTRING(node).capa) {
- k_strcpy(NSTRING(node).s + len, s, end);
- }
- else {
- if (NSTRING(node).s == NSTRING(node).buf)
- p = strcat_capa_from_static(NSTRING(node).s, NSTRING(node).end,
- s, end, capa);
- else
- p = k_strcat_capa(NSTRING(node).s, NSTRING(node).end, s, end, capa);
-
- CHECK_NULL_RETURN_VAL(p, ONIGERR_MEMORY);
- NSTRING(node).s = p;
- NSTRING(node).capa = capa;
- }
- }
- else {
- k_strcpy(NSTRING(node).s + len, s, end);
- }
- NSTRING(node).end = NSTRING(node).s + len + addlen;
- }
-
- return 0;
-}
-
-static int
-node_str_cat_char(Node* node, UChar c)
-{
- UChar s[1];
-
- s[0] = c;
- return onig_node_str_cat(node, s, s + 1);
-}
-
-extern void
-onig_node_conv_to_str_node(Node* node, int flag)
-{
- node->type = N_STRING;
-
- NSTRING(node).flag = flag;
- NSTRING(node).capa = 0;
- NSTRING(node).s = NSTRING(node).buf;
- NSTRING(node).end = NSTRING(node).buf;
-}
-
-extern void
-onig_node_str_clear(Node* node)
-{
- if (NSTRING(node).capa != 0 &&
- IS_NOT_NULL(NSTRING(node).s) && NSTRING(node).s != NSTRING(node).buf) {
- xfree(NSTRING(node).s);
- }
-
- NSTRING(node).capa = 0;
- NSTRING(node).flag = 0;
- NSTRING(node).s = NSTRING(node).buf;
- NSTRING(node).end = NSTRING(node).buf;
-}
-
-static Node*
-node_new_str(const UChar* s, const UChar* end)
-{
- Node* node = node_new();
- CHECK_NULL_RETURN(node);
-
- node->type = N_STRING;
- NSTRING(node).capa = 0;
- NSTRING(node).flag = 0;
- NSTRING(node).s = NSTRING(node).buf;
- NSTRING(node).end = NSTRING(node).buf;
- if (onig_node_str_cat(node, s, end)) {
- onig_node_free(node);
- return NULL;
- }
- return node;
-}
-
-extern Node*
-onig_node_new_str(const UChar* s, const UChar* end)
-{
- return node_new_str(s, end);
-}
-
-static Node*
-node_new_str_raw(UChar* s, UChar* end)
-{
- Node* node = node_new_str(s, end);
- NSTRING_SET_RAW(node);
- return node;
-}
-
-static Node*
-node_new_empty()
-{
- return node_new_str(NULL, NULL);
-}
-
-static Node*
-node_new_str_raw_char(UChar c)
-{
- UChar p[1];
-
- p[0] = c;
- return node_new_str_raw(p, p + 1);
-}
-
-static Node*
-str_node_split_last_char(StrNode* sn, OnigEncoding enc)
-{
- const UChar *p;
- Node* n = NULL_NODE;
-
- if (sn->end > sn->s) {
- p = onigenc_get_prev_char_head(enc, sn->s, sn->end);
- if (p && p > sn->s) { /* can be splitted. */
- n = node_new_str(p, sn->end);
- if ((sn->flag & NSTR_RAW) != 0)
- NSTRING_SET_RAW(n);
- sn->end = (UChar* )p;
- }
- }
- return n;
-}
-
-static int
-str_node_can_be_split(StrNode* sn, OnigEncoding enc)
-{
- if (sn->end > sn->s) {
- return ((enc_len(enc, sn->s) < sn->end - sn->s) ? 1 : 0);
- }
- return 0;
-}
-
-extern int
-onig_scan_unsigned_number(UChar** src, const UChar* end, OnigEncoding enc)
-{
- unsigned int num, val;
- OnigCodePoint c;
- UChar* p = *src;
- PFETCH_READY;
-
- num = 0;
- while (!PEND) {
- PFETCH(c);
- if (ONIGENC_IS_CODE_DIGIT(enc, c)) {
- val = (unsigned int )DIGITVAL(c);
- if ((INT_MAX_LIMIT - val) / 10UL < num)
- return -1; /* overflow */
-
- num = num * 10 + val;
- }
- else {
- PUNFETCH;
- break;
- }
- }
- *src = p;
- return num;
-}
-
-static int
-scan_unsigned_hexadecimal_number(UChar** src, UChar* end, int maxlen,
- OnigEncoding enc)
-{
- OnigCodePoint c;
- unsigned int num, val;
- UChar* p = *src;
- PFETCH_READY;
-
- num = 0;
- while (!PEND && maxlen-- != 0) {
- PFETCH(c);
- if (ONIGENC_IS_CODE_XDIGIT(enc, c)) {
- val = (unsigned int )XDIGITVAL(enc,c);
- if ((INT_MAX_LIMIT - val) / 16UL < num)
- return -1; /* overflow */
-
- num = (num << 4) + XDIGITVAL(enc,c);
- }
- else {
- PUNFETCH;
- break;
- }
- }
- *src = p;
- return num;
-}
-
-static int
-scan_unsigned_octal_number(UChar** src, UChar* end, int maxlen,
- OnigEncoding enc)
-{
- OnigCodePoint c;
- unsigned int num, val;
- UChar* p = *src;
- PFETCH_READY;
-
- num = 0;
- while (!PEND && maxlen-- != 0) {
- PFETCH(c);
- if (ONIGENC_IS_CODE_DIGIT(enc, c) && c < '8') {
- val = ODIGITVAL(c);
- if ((INT_MAX_LIMIT - val) / 8UL < num)
- return -1; /* overflow */
-
- num = (num << 3) + val;
- }
- else {
- PUNFETCH;
- break;
- }
- }
- *src = p;
- return num;
-}
-
-
-#define BBUF_WRITE_CODE_POINT(bbuf,pos,code) \
- BBUF_WRITE(bbuf, pos, &(code), SIZE_CODE_POINT)
-
-/* data format:
- [n][from-1][to-1][from-2][to-2] ... [from-n][to-n]
- (all data size is OnigCodePoint)
- */
-static int
-new_code_range(BBuf** pbuf)
-{
-#define INIT_MULTI_BYTE_RANGE_SIZE (SIZE_CODE_POINT * 5)
- int r;
- OnigCodePoint n;
- BBuf* bbuf;
-
- bbuf = *pbuf = (BBuf* )xmalloc(sizeof(BBuf));
- CHECK_NULL_RETURN_VAL(*pbuf, ONIGERR_MEMORY);
- r = BBUF_INIT(*pbuf, INIT_MULTI_BYTE_RANGE_SIZE);
- if (r) return r;
-
- n = 0;
- BBUF_WRITE_CODE_POINT(bbuf, 0, n);
- return 0;
-}
-
-static int
-add_code_range_to_buf(BBuf** pbuf, OnigCodePoint from, OnigCodePoint to)
-{
- int r, inc_n, pos;
- int low, high, bound, x;
- OnigCodePoint n, *data;
- BBuf* bbuf;
-
- if (from > to) {
- n = from; from = to; to = n;
- }
-
- if (IS_NULL(*pbuf)) {
- r = new_code_range(pbuf);
- if (r) return r;
- bbuf = *pbuf;
- n = 0;
- }
- else {
- bbuf = *pbuf;
- GET_CODE_POINT(n, bbuf->p);
- }
- data = (OnigCodePoint* )(bbuf->p);
- data++;
-
- for (low = 0, bound = n; low < bound; ) {
- x = (low + bound) >> 1;
- if (from > data[x*2 + 1])
- low = x + 1;
- else
- bound = x;
- }
-
- for (high = low, bound = n; high < bound; ) {
- x = (high + bound) >> 1;
- if (to >= data[x*2] - 1)
- high = x + 1;
- else
- bound = x;
- }
-
- inc_n = low + 1 - high;
- if (n + inc_n > ONIG_MAX_MULTI_BYTE_RANGES_NUM)
- return ONIGERR_TOO_MANY_MULTI_BYTE_RANGES;
-
- if (inc_n != 1) {
- if (from > data[low*2])
- from = data[low*2];
- if (to < data[(high - 1)*2 + 1])
- to = data[(high - 1)*2 + 1];
- }
-
- if (inc_n != 0 && (OnigCodePoint )high < n) {
- int from_pos = SIZE_CODE_POINT * (1 + high * 2);
- int to_pos = SIZE_CODE_POINT * (1 + (low + 1) * 2);
- int size = (n - high) * 2 * SIZE_CODE_POINT;
-
- if (inc_n > 0) {
- BBUF_MOVE_RIGHT(bbuf, from_pos, to_pos, size);
- }
- else {
- BBUF_MOVE_LEFT_REDUCE(bbuf, from_pos, to_pos);
- }
- }
-
- pos = SIZE_CODE_POINT * (1 + low * 2);
- BBUF_ENSURE_SIZE(bbuf, pos + SIZE_CODE_POINT * 2);
- BBUF_WRITE_CODE_POINT(bbuf, pos, from);
- BBUF_WRITE_CODE_POINT(bbuf, pos + SIZE_CODE_POINT, to);
- n += inc_n;
- BBUF_WRITE_CODE_POINT(bbuf, 0, n);
-
- return 0;
-}
-
-static int
-add_code_range(BBuf** pbuf, ScanEnv* env, OnigCodePoint from, OnigCodePoint to)
-{
- if (from > to) {
- if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC))
- return 0;
- else
- return ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS;
- }
-
- return add_code_range_to_buf(pbuf, from, to);
-}
-
-static int
-not_code_range_buf(OnigEncoding enc, BBuf* bbuf, BBuf** pbuf)
-{
- int r, i, n;
- OnigCodePoint pre, from, *data, to = 0;
-
- *pbuf = (BBuf* )NULL;
- if (IS_NULL(bbuf)) {
- set_all:
- return SET_ALL_MULTI_BYTE_RANGE(enc, pbuf);
- }
-
- data = (OnigCodePoint* )(bbuf->p);
- GET_CODE_POINT(n, data);
- data++;
- if (n <= 0) goto set_all;
-
- r = 0;
- pre = MBCODE_START_POS(enc);
- for (i = 0; i < n; i++) {
- from = data[i*2];
- to = data[i*2+1];
- if (pre <= from - 1) {
- r = add_code_range_to_buf(pbuf, pre, from - 1);
- if (r != 0) return r;
- }
- if (to == ~((OnigCodePoint )0)) break;
- pre = to + 1;
- }
- if (to < ~((OnigCodePoint )0)) {
- r = add_code_range_to_buf(pbuf, to + 1, ~((OnigCodePoint )0));
- }
- return r;
-}
-
-#define SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2) do {\
- BBuf *tbuf; \
- int tnot; \
- tnot = not1; not1 = not2; not2 = tnot; \
- tbuf = bbuf1; bbuf1 = bbuf2; bbuf2 = tbuf; \
-} while (0)
-
-static int
-or_code_range_buf(OnigEncoding enc, BBuf* bbuf1, int not1,
- BBuf* bbuf2, int not2, BBuf** pbuf)
-{
- int r;
- OnigCodePoint i, n1, *data1;
- OnigCodePoint from, to;
-
- *pbuf = (BBuf* )NULL;
- if (IS_NULL(bbuf1) && IS_NULL(bbuf2)) {
- if (not1 != 0 || not2 != 0)
- return SET_ALL_MULTI_BYTE_RANGE(enc, pbuf);
- return 0;
- }
-
- r = 0;
- if (IS_NULL(bbuf2))
- SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2);
-
- if (IS_NULL(bbuf1)) {
- if (not1 != 0) {
- return SET_ALL_MULTI_BYTE_RANGE(enc, pbuf);
- }
- else {
- if (not2 == 0) {
- return bbuf_clone(pbuf, bbuf2);
- }
- else {
- return not_code_range_buf(enc, bbuf2, pbuf);
- }
- }
- }
-
- if (not1 != 0)
- SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2);
-
- data1 = (OnigCodePoint* )(bbuf1->p);
- GET_CODE_POINT(n1, data1);
- data1++;
-
- if (not2 == 0 && not1 == 0) { /* 1 OR 2 */
- r = bbuf_clone(pbuf, bbuf2);
- }
- else if (not1 == 0) { /* 1 OR (not 2) */
- r = not_code_range_buf(enc, bbuf2, pbuf);
- }
- if (r != 0) return r;
-
- for (i = 0; i < n1; i++) {
- from = data1[i*2];
- to = data1[i*2+1];
- r = add_code_range_to_buf(pbuf, from, to);
- if (r != 0) return r;
- }
- return 0;
-}
-
-static int
-and_code_range1(BBuf** pbuf, OnigCodePoint from1, OnigCodePoint to1,
- OnigCodePoint* data, int n)
-{
- int i, r;
- OnigCodePoint from2, to2;
-
- for (i = 0; i < n; i++) {
- from2 = data[i*2];
- to2 = data[i*2+1];
- if (from2 < from1) {
- if (to2 < from1) continue;
- else {
- from1 = to2 + 1;
- }
- }
- else if (from2 <= to1) {
- if (to2 < to1) {
- if (from1 <= from2 - 1) {
- r = add_code_range_to_buf(pbuf, from1, from2-1);
- if (r != 0) return r;
- }
- from1 = to2 + 1;
- }
- else {
- to1 = from2 - 1;
- }
- }
- else {
- from1 = from2;
- }
- if (from1 > to1) break;
- }
- if (from1 <= to1) {
- r = add_code_range_to_buf(pbuf, from1, to1);
- if (r != 0) return r;
- }
- return 0;
-}
-
-static int
-and_code_range_buf(BBuf* bbuf1, int not1, BBuf* bbuf2, int not2, BBuf** pbuf)
-{
- int r;
- OnigCodePoint i, j, n1, n2, *data1, *data2;
- OnigCodePoint from, to, from1, to1, from2, to2;
-
- *pbuf = (BBuf* )NULL;
- if (IS_NULL(bbuf1)) {
- if (not1 != 0 && IS_NOT_NULL(bbuf2)) /* not1 != 0 -> not2 == 0 */
- return bbuf_clone(pbuf, bbuf2);
- return 0;
- }
- else if (IS_NULL(bbuf2)) {
- if (not2 != 0)
- return bbuf_clone(pbuf, bbuf1);
- return 0;
- }
-
- if (not1 != 0)
- SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2);
-
- data1 = (OnigCodePoint* )(bbuf1->p);
- data2 = (OnigCodePoint* )(bbuf2->p);
- GET_CODE_POINT(n1, data1);
- GET_CODE_POINT(n2, data2);
- data1++;
- data2++;
-
- if (not2 == 0 && not1 == 0) { /* 1 AND 2 */
- for (i = 0; i < n1; i++) {
- from1 = data1[i*2];
- to1 = data1[i*2+1];
- for (j = 0; j < n2; j++) {
- from2 = data2[j*2];
- to2 = data2[j*2+1];
- if (from2 > to1) break;
- if (to2 < from1) continue;
- from = MAX(from1, from2);
- to = MIN(to1, to2);
- r = add_code_range_to_buf(pbuf, from, to);
- if (r != 0) return r;
- }
- }
- }
- else if (not1 == 0) { /* 1 AND (not 2) */
- for (i = 0; i < n1; i++) {
- from1 = data1[i*2];
- to1 = data1[i*2+1];
- r = and_code_range1(pbuf, from1, to1, data2, n2);
- if (r != 0) return r;
- }
- }
-
- return 0;
-}
-
-static int
-clear_not_flag_cclass(CClassNode* cc, OnigEncoding enc)
-{
- BBuf *tbuf;
- int r;
-
- if (IS_CCLASS_NOT(cc)) {
- bitset_invert(cc->bs);
-
- if (! ONIGENC_IS_SINGLEBYTE(enc)) {
- r = not_code_range_buf(enc, cc->mbuf, &tbuf);
- if (r != 0) return r;
-
- bbuf_free(cc->mbuf);
- cc->mbuf = tbuf;
- }
-
- CCLASS_CLEAR_NOT(cc);
- }
-
- return 0;
-}
-
-static int
-and_cclass(CClassNode* dest, CClassNode* cc, OnigEncoding enc)
-{
- int r, not1, not2;
- BBuf *buf1, *buf2, *pbuf;
- BitSetRef bsr1, bsr2;
- BitSet bs1, bs2;
-
- not1 = IS_CCLASS_NOT(dest);
- bsr1 = dest->bs;
- buf1 = dest->mbuf;
- not2 = IS_CCLASS_NOT(cc);
- bsr2 = cc->bs;
- buf2 = cc->mbuf;
-
- if (not1 != 0) {
- bitset_invert_to(bsr1, bs1);
- bsr1 = bs1;
- }
- if (not2 != 0) {
- bitset_invert_to(bsr2, bs2);
- bsr2 = bs2;
- }
- bitset_and(bsr1, bsr2);
- if (bsr1 != dest->bs) {
- bitset_copy(dest->bs, bsr1);
- bsr1 = dest->bs;
- }
- if (not1 != 0) {
- bitset_invert(dest->bs);
- }
-
- if (! ONIGENC_IS_SINGLEBYTE(enc)) {
- if (not1 != 0 && not2 != 0) {
- r = or_code_range_buf(enc, buf1, 0, buf2, 0, &pbuf);
- }
- else {
- r = and_code_range_buf(buf1, not1, buf2, not2, &pbuf);
- if (r == 0 && not1 != 0) {
- BBuf *tbuf;
- r = not_code_range_buf(enc, pbuf, &tbuf);
- if (r != 0) {
- bbuf_free(pbuf);
- return r;
- }
- bbuf_free(pbuf);
- pbuf = tbuf;
- }
- }
- if (r != 0) return r;
-
- dest->mbuf = pbuf;
- bbuf_free(buf1);
- return r;
- }
- return 0;
-}
-
-static int
-or_cclass(CClassNode* dest, CClassNode* cc, OnigEncoding enc)
-{
- int r, not1, not2;
- BBuf *buf1, *buf2, *pbuf;
- BitSetRef bsr1, bsr2;
- BitSet bs1, bs2;
-
- not1 = IS_CCLASS_NOT(dest);
- bsr1 = dest->bs;
- buf1 = dest->mbuf;
- not2 = IS_CCLASS_NOT(cc);
- bsr2 = cc->bs;
- buf2 = cc->mbuf;
-
- if (not1 != 0) {
- bitset_invert_to(bsr1, bs1);
- bsr1 = bs1;
- }
- if (not2 != 0) {
- bitset_invert_to(bsr2, bs2);
- bsr2 = bs2;
- }
- bitset_or(bsr1, bsr2);
- if (bsr1 != dest->bs) {
- bitset_copy(dest->bs, bsr1);
- bsr1 = dest->bs;
- }
- if (not1 != 0) {
- bitset_invert(dest->bs);
- }
-
- if (! ONIGENC_IS_SINGLEBYTE(enc)) {
- if (not1 != 0 && not2 != 0) {
- r = and_code_range_buf(buf1, 0, buf2, 0, &pbuf);
- }
- else {
- r = or_code_range_buf(enc, buf1, not1, buf2, not2, &pbuf);
- if (r == 0 && not1 != 0) {
- BBuf *tbuf;
- r = not_code_range_buf(enc, pbuf, &tbuf);
- if (r != 0) {
- bbuf_free(pbuf);
- return r;
- }
- bbuf_free(pbuf);
- pbuf = tbuf;
- }
- }
- if (r != 0) return r;
-
- dest->mbuf = pbuf;
- bbuf_free(buf1);
- return r;
- }
- else
- return 0;
-}
-
-static int
-conv_backslash_value(int c, ScanEnv* env)
-{
- if (IS_SYNTAX_OP(env->syntax, ONIG_SYN_OP_ESC_CONTROL_CHARS)) {
- switch (c) {
- case 'n': return '\n';
- case 't': return '\t';
- case 'r': return '\r';
- case 'f': return '\f';
- case 'a': return '\007';
- case 'b': return '\010';
- case 'e': return '\033';
- case 'v':
- if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_ESC_V_VTAB))
- return '\v';
- break;
-
- default:
- break;
- }
- }
- return c;
-}
-
-static int
-is_invalid_qualifier_target(Node* node)
-{
- switch (NTYPE(node)) {
- case N_ANCHOR:
- return 1;
- break;
-
- case N_EFFECT:
- if (NEFFECT(node).type == EFFECT_OPTION)
- return is_invalid_qualifier_target(NEFFECT(node).target);
- break;
-
- case N_LIST: /* ex. (?:\G\A)* */
- do {
- if (! is_invalid_qualifier_target(NCONS(node).left)) return 0;
- } while (IS_NOT_NULL(node = NCONS(node).right));
- return 0;
- break;
-
- case N_ALT: /* ex. (?:abc|\A)* */
- do {
- if (is_invalid_qualifier_target(NCONS(node).left)) return 1;
- } while (IS_NOT_NULL(node = NCONS(node).right));
- break;
-
- default:
- break;
- }
- return 0;
-}
-
-/* ?:0, *:1, +:2, ??:3, *?:4, +?:5 */
-static int
-popular_qualifier_num(QualifierNode* qf)
-{
- if (qf->greedy) {
- if (qf->lower == 0) {
- if (qf->upper == 1) return 0;
- else if (IS_REPEAT_INFINITE(qf->upper)) return 1;
- }
- else if (qf->lower == 1) {
- if (IS_REPEAT_INFINITE(qf->upper)) return 2;
- }
- }
- else {
- if (qf->lower == 0) {
- if (qf->upper == 1) return 3;
- else if (IS_REPEAT_INFINITE(qf->upper)) return 4;
- }
- else if (qf->lower == 1) {
- if (IS_REPEAT_INFINITE(qf->upper)) return 5;
- }
- }
- return -1;
-}
-
-
-enum ReduceType {
- RQ_ASIS = 0, /* as is */
- RQ_DEL = 1, /* delete parent */
- RQ_A, /* to '*' */
- RQ_AQ, /* to '*?' */
- RQ_QQ, /* to '??' */
- RQ_P_QQ, /* to '+)??' */
- RQ_PQ_Q /* to '+?)?' */
-};
-
-static enum ReduceType ReduceTypeTable[6][6] = {
- {RQ_DEL, RQ_A, RQ_A, RQ_QQ, RQ_AQ, RQ_ASIS}, /* '?' */
- {RQ_DEL, RQ_DEL, RQ_DEL, RQ_P_QQ, RQ_P_QQ, RQ_DEL}, /* '*' */
- {RQ_A, RQ_A, RQ_DEL, RQ_ASIS, RQ_P_QQ, RQ_DEL}, /* '+' */
- {RQ_DEL, RQ_AQ, RQ_AQ, RQ_DEL, RQ_AQ, RQ_AQ}, /* '??' */
- {RQ_DEL, RQ_DEL, RQ_DEL, RQ_DEL, RQ_DEL, RQ_DEL}, /* '*?' */
- {RQ_ASIS, RQ_PQ_Q, RQ_DEL, RQ_AQ, RQ_AQ, RQ_DEL} /* '+?' */
-};
-
-extern void
-onig_reduce_nested_qualifier(Node* pnode, Node* cnode)
-{
- int pnum, cnum;
- QualifierNode *p, *c;
-
- p = &(NQUALIFIER(pnode));
- c = &(NQUALIFIER(cnode));
- pnum = popular_qualifier_num(p);
- cnum = popular_qualifier_num(c);
-
- switch(ReduceTypeTable[cnum][pnum]) {
- case RQ_DEL:
- *p = *c;
- break;
- case RQ_A:
- p->target = c->target;
- p->lower = 0; p->upper = REPEAT_INFINITE; p->greedy = 1;
- break;
- case RQ_AQ:
- p->target = c->target;
- p->lower = 0; p->upper = REPEAT_INFINITE; p->greedy = 0;
- break;
- case RQ_QQ:
- p->target = c->target;
- p->lower = 0; p->upper = 1; p->greedy = 0;
- break;
- case RQ_P_QQ:
- p->target = cnode;
- p->lower = 0; p->upper = 1; p->greedy = 0;
- c->lower = 1; c->upper = REPEAT_INFINITE; c->greedy = 1;
- return ;
- break;
- case RQ_PQ_Q:
- p->target = cnode;
- p->lower = 0; p->upper = 1; p->greedy = 1;
- c->lower = 1; c->upper = REPEAT_INFINITE; c->greedy = 0;
- return ;
- break;
- case RQ_ASIS:
- p->target = cnode;
- return ;
- break;
- }
-
- c->target = NULL_NODE;
- onig_node_free(cnode);
-}
-
-
-enum TokenSyms {
- TK_EOT = 0, /* end of token */
- TK_RAW_BYTE = 1,
- TK_CHAR,
- TK_STRING,
- TK_CODE_POINT,
- TK_ANYCHAR,
- TK_CHAR_TYPE,
- TK_BACKREF,
- TK_CALL,
- TK_ANCHOR,
- TK_OP_REPEAT,
- TK_INTERVAL,
- TK_ANYCHAR_ANYTIME, /* SQL '%' == .* */
- TK_ALT,
- TK_SUBEXP_OPEN,
- TK_SUBEXP_CLOSE,
- TK_CC_OPEN,
- TK_QUOTE_OPEN,
- TK_CHAR_PROPERTY, /* \p{...}, \P{...} */
- /* in cc */
- TK_CC_CLOSE,
- TK_CC_RANGE,
- TK_POSIX_BRACKET_OPEN,
- TK_CC_AND, /* && */
- TK_CC_CC_OPEN /* [ */
-};
-
-typedef struct {
- enum TokenSyms type;
- int escaped;
- int base; /* is number: 8, 16 (used in [....]) */
- UChar* backp;
- union {
- UChar* s;
- int c;
- OnigCodePoint code;
- int anchor;
- int subtype;
- struct {
- int lower;
- int upper;
- int greedy;
- int possessive;
- } repeat;
- struct {
- int num;
- int ref1;
- int* refs;
- int by_name;
-#ifdef USE_BACKREF_AT_LEVEL
- int exist_level;
- int level; /* \k<name+n> */
-#endif
- } backref;
- struct {
- UChar* name;
- UChar* name_end;
- } call;
- struct {
- int not;
- } prop;
- } u;
-} OnigToken;
-
-
-static int
-fetch_range_qualifier(UChar** src, UChar* end, OnigToken* tok, ScanEnv* env)
-{
- int low, up, syn_allow, non_low = 0;
- int r = 0;
- OnigCodePoint c;
- OnigEncoding enc = env->enc;
- UChar* p = *src;
- PFETCH_READY;
-
- syn_allow = IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_INVALID_INTERVAL);
-
- if (PEND) {
- if (syn_allow)
- return 1; /* "....{" : OK! */
- else
- return ONIGERR_END_PATTERN_AT_LEFT_BRACE; /* "....{" syntax error */
- }
-
- if (! syn_allow) {
- c = PPEEK;
- if (c == ')' || c == '(' || c == '|') {
- return ONIGERR_END_PATTERN_AT_LEFT_BRACE;
- }
- }
-
- low = onig_scan_unsigned_number(&p, end, env->enc);
- if (low < 0) return ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE;
- if (low > ONIG_MAX_REPEAT_NUM)
- return ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE;
-
- if (p == *src) { /* can't read low */
- if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV)) {
- /* allow {,n} as {0,n} */
- low = 0;
- non_low = 1;
- }
- else
- goto invalid;
- }
-
- if (PEND) goto invalid;
- PFETCH(c);
- if (c == ',') {
- UChar* prev = p;
- up = onig_scan_unsigned_number(&p, end, env->enc);
- if (up < 0) return ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE;
- if (up > ONIG_MAX_REPEAT_NUM)
- return ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE;
-
- if (p == prev) {
- if (non_low != 0)
- goto invalid;
- up = REPEAT_INFINITE; /* {n,} : {n,infinite} */
- }
- }
- else {
- if (non_low != 0)
- goto invalid;
-
- PUNFETCH;
- up = low; /* {n} : exact n times */
- r = 2; /* fixed */
- }
-
- if (PEND) goto invalid;
- PFETCH(c);
- if (IS_SYNTAX_OP(env->syntax, ONIG_SYN_OP_ESC_BRACE_INTERVAL)) {
- if (c != MC_ESC(enc)) goto invalid;
- PFETCH(c);
- }
- if (c != '}') goto invalid;
-
- if (!IS_REPEAT_INFINITE(up) && low > up) {
- return ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE;
- }
-
- tok->type = TK_INTERVAL;
- tok->u.repeat.lower = low;
- tok->u.repeat.upper = up;
- *src = p;
- return r; /* 0: normal {n,m}, 2: fixed {n} */
-
- invalid:
- if (syn_allow)
- return 1; /* OK */
- else
- return ONIGERR_INVALID_REPEAT_RANGE_PATTERN;
-}
-
-/* \M-, \C-, \c, or \... */
-static int
-fetch_escaped_value(UChar** src, UChar* end, ScanEnv* env)
-{
- int v;
- OnigCodePoint c;
- OnigEncoding enc = env->enc;
- UChar* p = *src;
- PFETCH_READY;
-
- if (PEND) return ONIGERR_END_PATTERN_AT_ESCAPE;
-
- PFETCH(c);
- switch (c) {
- case 'M':
- if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META)) {
- if (PEND) return ONIGERR_END_PATTERN_AT_META;
- PFETCH(c);
- if (c != '-') return ONIGERR_META_CODE_SYNTAX;
- if (PEND) return ONIGERR_END_PATTERN_AT_META;
- PFETCH(c);
- if (c == MC_ESC(enc)) {
- v = fetch_escaped_value(&p, end, env);
- if (v < 0) return v;
- c = (OnigCodePoint )v;
- }
- c = ((c & 0xff) | 0x80);
- }
- else
- goto backslash;
- break;
-
- case 'C':
- if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL)) {
- if (PEND) return ONIGERR_END_PATTERN_AT_CONTROL;
- PFETCH(c);
- if (c != '-') return ONIGERR_CONTROL_CODE_SYNTAX;
- goto control;
- }
- else
- goto backslash;
-
- case 'c':
- if (IS_SYNTAX_OP(env->syntax, ONIG_SYN_OP_ESC_C_CONTROL)) {
- control:
- if (PEND) return ONIGERR_END_PATTERN_AT_CONTROL;
- PFETCH(c);
- if (c == '?') {
- c = 0177;
- }
- else {
- if (c == MC_ESC(enc)) {
- v = fetch_escaped_value(&p, end, env);
- if (v < 0) return v;
- c = (OnigCodePoint )v;
- }
- c &= 0x9f;
- }
- break;
- }
- /* fall through */
-
- default:
- {
- backslash:
- c = conv_backslash_value(c, env);
- }
- break;
- }
-
- *src = p;
- return c;
-}
-
-static int fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env);
-
-#ifdef USE_NAMED_GROUP
-#ifdef USE_BACKREF_AT_LEVEL
-/*
- \k<name+n>, \k<name-n>
-*/
-static int
-fetch_name_with_level(UChar** src, UChar* end, UChar** rname_end
- , ScanEnv* env, int* level)
-{
- int r, exist_level = 0;
- OnigCodePoint c = 0;
- OnigCodePoint first_code;
- OnigEncoding enc = env->enc;
- UChar *name_end;
- UChar *p = *src;
- PFETCH_READY;
-
- name_end = end;
- r = 0;
- if (PEND) {
- return ONIGERR_EMPTY_GROUP_NAME;
- }
- else {
- PFETCH(c);
- first_code = c;
- if (c == '>')
- return ONIGERR_EMPTY_GROUP_NAME;
-
- if (!ONIGENC_IS_CODE_WORD(enc, c)) {
- r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
- }
- }
-
- while (!PEND) {
- name_end = p;
- PFETCH(c);
- if (c == '>' || c == ')' || c == '+' || c == '-') break;
-
- if (!ONIGENC_IS_CODE_WORD(enc, c)) {
- r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
- }
- }
-
- if (c != '>') {
- if (c == '+' || c == '-') {
- int num;
- int flag = (c == '-' ? -1 : 1);
-
- PFETCH(c);
- if (! ONIGENC_IS_CODE_DIGIT(enc, c)) goto err;
- PUNFETCH;
- num = onig_scan_unsigned_number(&p, end, enc);
- if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
- *level = (num * flag);
- exist_level = 1;
-
- PFETCH(c);
- if (c == '>')
- goto first_check;
- }
-
- err:
- r = ONIGERR_INVALID_GROUP_NAME;
- name_end = end;
- }
- else {
- first_check:
- if (ONIGENC_IS_CODE_ASCII(first_code) &&
- ONIGENC_IS_CODE_UPPER(enc, first_code))
- r = ONIGERR_INVALID_GROUP_NAME;
- }
-
- if (r == 0) {
- *rname_end = name_end;
- *src = p;
- return (exist_level ? 1 : 0);
- }
- else {
- onig_scan_env_set_error_string(env, r, *src, name_end);
- return r;
- }
-}
-#endif /* USE_BACKREF_AT_LEVEL */
-
-/*
- def: 0 -> define name (don't allow number name)
- 1 -> reference name (allow number name)
-*/
-static int
-fetch_name(UChar** src, UChar* end, UChar** rname_end, ScanEnv* env, int ref)
-{
- int r, is_num;
- OnigCodePoint c = 0;
- OnigCodePoint first_code;
- OnigEncoding enc = env->enc;
- UChar *name_end;
- UChar *p = *src;
- PFETCH_READY;
-
- name_end = end;
- r = 0;
- is_num = 0;
- if (PEND) {
- return ONIGERR_EMPTY_GROUP_NAME;
- }
- else {
- PFETCH(c);
- first_code = c;
- if (c == '>')
- return ONIGERR_EMPTY_GROUP_NAME;
-
- if (ONIGENC_IS_CODE_DIGIT(enc, c)) {
- if (ref == 1)
- is_num = 1;
- else {
- r = ONIGERR_INVALID_GROUP_NAME;
- }
- }
- else if (!ONIGENC_IS_CODE_WORD(enc, c)) {
- r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
- }
- }
-
- while (!PEND) {
- name_end = p;
- PFETCH(c);
- if (c == '>' || c == ')') break;
-
- if (is_num == 1) {
- if (! ONIGENC_IS_CODE_DIGIT(enc, c)) {
- if (!ONIGENC_IS_CODE_WORD(enc, c))
- r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
- else
- r = ONIGERR_INVALID_GROUP_NAME;
- }
- }
- else {
- if (!ONIGENC_IS_CODE_WORD(enc, c)) {
- r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
- }
- }
- }
-
- if (c != '>') {
- r = ONIGERR_INVALID_GROUP_NAME;
- name_end = end;
- }
- else {
- if (ONIGENC_IS_CODE_ASCII(first_code) &&
- ONIGENC_IS_CODE_UPPER(enc, first_code))
- r = ONIGERR_INVALID_GROUP_NAME;
- }
-
- if (r == 0) {
- *rname_end = name_end;
- *src = p;
- return 0;
- }
- else {
- onig_scan_env_set_error_string(env, r, *src, name_end);
- return r;
- }
-}
-#else
-static int
-fetch_name(UChar** src, UChar* end, UChar** rname_end, ScanEnv* env, int ref)
-{
- int r, len;
- OnigCodePoint c = 0;
- UChar *name_end;
- OnigEncoding enc = env->enc;
- UChar *p = *src;
- PFETCH_READY;
-
- r = 0;
- while (!PEND) {
- name_end = p;
- if (enc_len(enc, p) > 1)
- r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
-
- PFETCH(c);
- if (c == '>' || c == ')') break;
- if (! ONIGENC_IS_CODE_DIGIT(enc, c))
- r = ONIGERR_INVALID_CHAR_IN_GROUP_NAME;
- }
- if (c != '>') {
- r = ONIGERR_INVALID_GROUP_NAME;
- name_end = end;
- }
-
- if (r == 0) {
- *rname_end = name_end;
- *src = p;
- return 0;
- }
- else {
- err:
- onig_scan_env_set_error_string(env, r, *src, name_end);
- return r;
- }
-}
-#endif
-
-static void
-CC_ESC_WARN(ScanEnv* env, UChar *c)
-{
- if (onig_warn == onig_null_warn) return ;
-
- if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_WARN_CC_OP_NOT_ESCAPED) &&
- IS_SYNTAX_BV(env->syntax, ONIG_SYN_BACKSLASH_ESCAPE_IN_CC)) {
- UChar buf[WARN_BUFSIZE];
- onig_snprintf_with_pattern(buf, WARN_BUFSIZE, env->enc,
- env->pattern, env->pattern_end,
- (UChar* )"character class has '%s' without escape", c);
- (*onig_warn)((char* )buf);
- }
-}
-
-static void
-CCEND_ESC_WARN(ScanEnv* env, UChar* c)
-{
- if (onig_warn == onig_null_warn) return ;
-
- if (IS_SYNTAX_BV((env)->syntax, ONIG_SYN_WARN_CC_OP_NOT_ESCAPED)) {
- UChar buf[WARN_BUFSIZE];
- onig_snprintf_with_pattern(buf, WARN_BUFSIZE, (env)->enc,
- (env)->pattern, (env)->pattern_end,
- (UChar* )"regular expression has '%s' without escape", c);
- (*onig_warn)((char* )buf);
- }
-}
-
-static UChar*
-find_str_position(OnigCodePoint s[], int n, UChar* from, UChar* to,
- UChar **next, OnigEncoding enc)
-{
- int i;
- OnigCodePoint x;
- UChar *q;
- UChar *p = from;
-
- while (p < to) {
- x = ONIGENC_MBC_TO_CODE(enc, p, to);
- q = p + enc_len(enc, p);
- if (x == s[0]) {
- for (i = 1; i < n && q < to; i++) {
- x = ONIGENC_MBC_TO_CODE(enc, q, to);
- if (x != s[i]) break;
- q += enc_len(enc, q);
- }
- if (i >= n) {
- if (IS_NOT_NULL(next))
- *next = q;
- return p;
- }
- }
- p = q;
- }
- return NULL_UCHARP;
-}
-
-static int
-str_exist_check_with_esc(OnigCodePoint s[], int n, UChar* from, UChar* to,
- OnigCodePoint bad, OnigEncoding enc)
-{
- int i, in_esc;
- OnigCodePoint x;
- UChar *q;
- UChar *p = from;
-
- in_esc = 0;
- while (p < to) {
- if (in_esc) {
- in_esc = 0;
- p += enc_len(enc, p);
- }
- else {
- x = ONIGENC_MBC_TO_CODE(enc, p, to);
- q = p + enc_len(enc, p);
- if (x == s[0]) {
- for (i = 1; i < n && q < to; i++) {
- x = ONIGENC_MBC_TO_CODE(enc, q, to);
- if (x != s[i]) break;
- q += enc_len(enc, q);
- }
- if (i >= n) return 1;
- p += enc_len(enc, p);
- }
- else {
- x = ONIGENC_MBC_TO_CODE(enc, p, to);
- if (x == bad) return 0;
- else if (x == MC_ESC(enc)) in_esc = 1;
- p = q;
- }
- }
- }
- return 0;
-}
-
-static int
-fetch_token_in_cc(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env)
-{
- int num;
- OnigCodePoint c, c2;
- OnigSyntaxType* syn = env->syntax;
- OnigEncoding enc = env->enc;
- UChar* prev;
- UChar* p = *src;
- PFETCH_READY;
-
- if (PEND) {
- tok->type = TK_EOT;
- return tok->type;
- }
-
- PFETCH(c);
- tok->type = TK_CHAR;
- tok->base = 0;
- tok->u.c = c;
- tok->escaped = 0;
-
- if (c == ']') {
- tok->type = TK_CC_CLOSE;
- }
- else if (c == '-') {
- tok->type = TK_CC_RANGE;
- }
- else if (c == MC_ESC(enc)) {
- if (! IS_SYNTAX_BV(syn, ONIG_SYN_BACKSLASH_ESCAPE_IN_CC))
- goto end;
-
- if (PEND) return ONIGERR_END_PATTERN_AT_ESCAPE;
-
- PFETCH(c);
- tok->escaped = 1;
- tok->u.c = c;
- switch (c) {
- case 'w':
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_WORD;
- break;
- case 'W':
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_NOT_WORD;
- break;
- case 'd':
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_DIGIT;
- break;
- case 'D':
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_NOT_DIGIT;
- break;
- case 's':
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_WHITE_SPACE;
- break;
- case 'S':
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_NOT_WHITE_SPACE;
- break;
- case 'h':
- if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_XDIGIT;
- break;
- case 'H':
- if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_NOT_XDIGIT;
- break;
-
- case 'p':
- case 'P':
- c2 = PPEEK;
- if (c2 == '{' &&
- IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY)) {
- PINC;
- tok->type = TK_CHAR_PROPERTY;
- tok->u.prop.not = (c == 'P' ? 1 : 0);
-
- if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT)) {
- PFETCH(c2);
- if (c2 == '^') {
- tok->u.prop.not = (tok->u.prop.not == 0 ? 1 : 0);
- }
- else
- PUNFETCH;
- }
- }
- break;
-
- case 'x':
- if (PEND) break;
-
- prev = p;
- if (PPEEK_IS('{') && IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_BRACE_HEX8)) {
- PINC;
- num = scan_unsigned_hexadecimal_number(&p, end, 8, enc);
- if (num < 0) return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
- if (!PEND) {
- c2 = PPEEK;
- if (ONIGENC_IS_CODE_XDIGIT(enc, c2))
- return ONIGERR_TOO_LONG_WIDE_CHAR_VALUE;
- }
-
- if (p > prev + enc_len(enc, prev) && !PEND && (PPEEK_IS('}'))) {
- PINC;
- tok->type = TK_CODE_POINT;
- tok->base = 16;
- tok->u.code = (OnigCodePoint )num;
- }
- else {
- /* can't read nothing or invalid format */
- p = prev;
- }
- }
- else if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_HEX2)) {
- num = scan_unsigned_hexadecimal_number(&p, end, 2, enc);
- if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
- if (p == prev) { /* can't read nothing. */
- num = 0; /* but, it's not error */
- }
- tok->type = TK_RAW_BYTE;
- tok->base = 16;
- tok->u.c = num;
- }
- break;
-
- case 'u':
- if (PEND) break;
-
- prev = p;
- if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_U_HEX4)) {
- num = scan_unsigned_hexadecimal_number(&p, end, 4, enc);
- if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
- if (p == prev) { /* can't read nothing. */
- num = 0; /* but, it's not error */
- }
- tok->type = TK_CODE_POINT;
- tok->base = 16;
- tok->u.code = (OnigCodePoint )num;
- }
- break;
-
- case '0':
- case '1': case '2': case '3': case '4': case '5': case '6': case '7':
- if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_OCTAL3)) {
- PUNFETCH;
- prev = p;
- num = scan_unsigned_octal_number(&p, end, 3, enc);
- if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
- if (p == prev) { /* can't read nothing. */
- num = 0; /* but, it's not error */
- }
- tok->type = TK_RAW_BYTE;
- tok->base = 8;
- tok->u.c = num;
- }
- break;
-
- default:
- PUNFETCH;
- num = fetch_escaped_value(&p, end, env);
- if (num < 0) return num;
- if (tok->u.c != num) {
- tok->u.code = (OnigCodePoint )num;
- tok->type = TK_CODE_POINT;
- }
- break;
- }
- }
- else if (c == '[') {
- if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_POSIX_BRACKET) && (PPEEK_IS(':'))) {
- OnigCodePoint send[] = { (OnigCodePoint )':', (OnigCodePoint )']' };
- tok->backp = p; /* point at '[' is readed */
- PINC;
- if (str_exist_check_with_esc(send, 2, p, end,
- (OnigCodePoint )']', enc)) {
- tok->type = TK_POSIX_BRACKET_OPEN;
- }
- else {
- PUNFETCH;
- goto cc_in_cc;
- }
- }
- else {
- cc_in_cc:
- if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_CCLASS_SET_OP)) {
- tok->type = TK_CC_CC_OPEN;
- }
- else {
- CC_ESC_WARN(env, (UChar* )"[");
- }
- }
- }
- else if (c == '&') {
- if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_CCLASS_SET_OP) &&
- !PEND && (PPEEK_IS('&'))) {
- PINC;
- tok->type = TK_CC_AND;
- }
- }
-
- end:
- *src = p;
- return tok->type;
-}
-
-static int
-fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env)
-{
- int r, num;
- OnigCodePoint c;
- OnigEncoding enc = env->enc;
- OnigSyntaxType* syn = env->syntax;
- UChar* prev;
- UChar* p = *src;
- PFETCH_READY;
-
- start:
- if (PEND) {
- tok->type = TK_EOT;
- return tok->type;
- }
-
- tok->type = TK_STRING;
- tok->base = 0;
- tok->backp = p;
-
- PFETCH(c);
- if (IS_MC_ESC_CODE(c, enc, syn)) {
- if (PEND) return ONIGERR_END_PATTERN_AT_ESCAPE;
-
- tok->backp = p;
- PFETCH(c);
-
- tok->u.c = c;
- tok->escaped = 1;
- switch (c) {
- case '*':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF)) break;
- tok->type = TK_OP_REPEAT;
- tok->u.repeat.lower = 0;
- tok->u.repeat.upper = REPEAT_INFINITE;
- goto greedy_check;
- break;
-
- case '+':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_PLUS_ONE_INF)) break;
- tok->type = TK_OP_REPEAT;
- tok->u.repeat.lower = 1;
- tok->u.repeat.upper = REPEAT_INFINITE;
- goto greedy_check;
- break;
-
- case '?':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_QMARK_ZERO_ONE)) break;
- tok->type = TK_OP_REPEAT;
- tok->u.repeat.lower = 0;
- tok->u.repeat.upper = 1;
- greedy_check:
- if (!PEND && PPEEK_IS('?') &&
- IS_SYNTAX_OP(syn, ONIG_SYN_OP_QMARK_NON_GREEDY)) {
- PFETCH(c);
- tok->u.repeat.greedy = 0;
- tok->u.repeat.possessive = 0;
- }
- else {
- possessive_check:
- if (!PEND && PPEEK_IS('+') &&
- ((IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT) &&
- tok->type != TK_INTERVAL) ||
- (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL) &&
- tok->type == TK_INTERVAL))) {
- PFETCH(c);
- tok->u.repeat.greedy = 1;
- tok->u.repeat.possessive = 1;
- }
- else {
- tok->u.repeat.greedy = 1;
- tok->u.repeat.possessive = 0;
- }
- }
- break;
-
- case '{':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_BRACE_INTERVAL)) break;
- r = fetch_range_qualifier(&p, end, tok, env);
- if (r < 0) return r; /* error */
- if (r == 0) goto greedy_check;
- else if (r == 2) { /* {n} */
- if (IS_SYNTAX_BV(syn, ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY))
- goto possessive_check;
-
- goto greedy_check;
- }
- /* r == 1 : normal char */
- break;
-
- case '|':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_VBAR_ALT)) break;
- tok->type = TK_ALT;
- break;
-
- case '(':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LPAREN_SUBEXP)) break;
- tok->type = TK_SUBEXP_OPEN;
- break;
-
- case ')':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LPAREN_SUBEXP)) break;
- tok->type = TK_SUBEXP_CLOSE;
- break;
-
- case 'w':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_W_WORD)) break;
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_WORD;
- break;
-
- case 'W':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_W_WORD)) break;
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_NOT_WORD;
- break;
-
- case 'b':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_B_WORD_BOUND)) break;
- tok->type = TK_ANCHOR;
- tok->u.anchor = ANCHOR_WORD_BOUND;
- break;
-
- case 'B':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_B_WORD_BOUND)) break;
- tok->type = TK_ANCHOR;
- tok->u.anchor = ANCHOR_NOT_WORD_BOUND;
- break;
-
-#ifdef USE_WORD_BEGIN_END
- case '<':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END)) break;
- tok->type = TK_ANCHOR;
- tok->u.anchor = ANCHOR_WORD_BEGIN;
- break;
-
- case '>':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END)) break;
- tok->type = TK_ANCHOR;
- tok->u.anchor = ANCHOR_WORD_END;
- break;
-#endif
-
- case 's':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_S_WHITE_SPACE)) break;
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_WHITE_SPACE;
- break;
-
- case 'S':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_S_WHITE_SPACE)) break;
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_NOT_WHITE_SPACE;
- break;
-
- case 'd':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_D_DIGIT)) break;
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_DIGIT;
- break;
-
- case 'D':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_D_DIGIT)) break;
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_NOT_DIGIT;
- break;
-
- case 'h':
- if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_XDIGIT;
- break;
-
- case 'H':
- if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
- tok->type = TK_CHAR_TYPE;
- tok->u.subtype = CTYPE_NOT_XDIGIT;
- break;
-
- case 'A':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break;
- begin_buf:
- tok->type = TK_ANCHOR;
- tok->u.subtype = ANCHOR_BEGIN_BUF;
- break;
-
- case 'Z':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break;
- tok->type = TK_ANCHOR;
- tok->u.subtype = ANCHOR_SEMI_END_BUF;
- break;
-
- case 'z':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break;
- end_buf:
- tok->type = TK_ANCHOR;
- tok->u.subtype = ANCHOR_END_BUF;
- break;
-
- case 'G':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR)) break;
- tok->type = TK_ANCHOR;
- tok->u.subtype = ANCHOR_BEGIN_POSITION;
- break;
-
- case '`':
- if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR)) break;
- goto begin_buf;
- break;
-
- case '\'':
- if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR)) break;
- goto end_buf;
- break;
-
- case 'x':
- if (PEND) break;
-
- prev = p;
- if (PPEEK_IS('{') && IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_BRACE_HEX8)) {
- PINC;
- num = scan_unsigned_hexadecimal_number(&p, end, 8, enc);
- if (num < 0) return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
- if (!PEND) {
- if (ONIGENC_IS_CODE_XDIGIT(enc, PPEEK))
- return ONIGERR_TOO_LONG_WIDE_CHAR_VALUE;
- }
-
- if ((p > prev + enc_len(enc, prev)) && !PEND && PPEEK_IS('}')) {
- PINC;
- tok->type = TK_CODE_POINT;
- tok->u.code = (OnigCodePoint )num;
- }
- else {
- /* can't read nothing or invalid format */
- p = prev;
- }
- }
- else if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_HEX2)) {
- num = scan_unsigned_hexadecimal_number(&p, end, 2, enc);
- if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
- if (p == prev) { /* can't read nothing. */
- num = 0; /* but, it's not error */
- }
- tok->type = TK_RAW_BYTE;
- tok->base = 16;
- tok->u.c = num;
- }
- break;
-
- case 'u':
- if (PEND) break;
-
- prev = p;
- if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_U_HEX4)) {
- num = scan_unsigned_hexadecimal_number(&p, end, 4, enc);
- if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
- if (p == prev) { /* can't read nothing. */
- num = 0; /* but, it's not error */
- }
- tok->type = TK_CODE_POINT;
- tok->base = 16;
- tok->u.code = (OnigCodePoint )num;
- }
- break;
-
- case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- PUNFETCH;
- prev = p;
- num = onig_scan_unsigned_number(&p, end, enc);
- if (num < 0 || num > ONIG_MAX_BACKREF_NUM) {
- goto skip_backref;
- }
-
- if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_DECIMAL_BACKREF) &&
- (num <= env->num_mem || num <= 9)) { /* This spec. from GNU regex */
- if (IS_SYNTAX_BV(syn, ONIG_SYN_STRICT_CHECK_BACKREF)) {
- if (num > env->num_mem || IS_NULL(SCANENV_MEM_NODES(env)[num]))
- return ONIGERR_INVALID_BACKREF;
- }
-
- tok->type = TK_BACKREF;
- tok->u.backref.num = 1;
- tok->u.backref.ref1 = num;
- tok->u.backref.by_name = 0;
-#ifdef USE_BACKREF_AT_LEVEL
- tok->u.backref.exist_level = 0;
-#endif
- break;
- }
-
- skip_backref:
- if (c == '8' || c == '9') {
- /* normal char */
- p = prev; PINC;
- break;
- }
-
- p = prev;
- /* fall through */
- case '0':
- if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_OCTAL3)) {
- prev = p;
- num = scan_unsigned_octal_number(&p, end, (c == '0' ? 2:3), enc);
- if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
- if (p == prev) { /* can't read nothing. */
- num = 0; /* but, it's not error */
- }
- tok->type = TK_RAW_BYTE;
- tok->base = 8;
- tok->u.c = num;
- }
- else if (c != '0') {
- PINC;
- }
- break;
-
-#ifdef USE_NAMED_GROUP
- case 'k':
- if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_K_NAMED_BACKREF)) {
- PFETCH(c);
- if (c == '<') {
- UChar* name_end;
- int* backs;
-
- prev = p;
-
-#ifdef USE_BACKREF_AT_LEVEL
- name_end = NULL_UCHARP; /* no need. escape gcc warning. */
- r = fetch_name_with_level(&p, end, &name_end, env, &tok->u.backref.level);
- if (r == 1) tok->u.backref.exist_level = 1;
- else tok->u.backref.exist_level = 0;
-#else
- r = fetch_name(&p, end, &name_end, env, 1);
-#endif
- if (r < 0) return r;
-
- num = onig_name_to_group_numbers(env->reg, prev, name_end, &backs);
- if (num <= 0) {
- onig_scan_env_set_error_string(env,
- ONIGERR_UNDEFINED_NAME_REFERENCE, prev, name_end);
- return ONIGERR_UNDEFINED_NAME_REFERENCE;
- }
- if (IS_SYNTAX_BV(syn, ONIG_SYN_STRICT_CHECK_BACKREF)) {
- int i;
- for (i = 0; i < num; i++) {
- if (backs[i] > env->num_mem ||
- IS_NULL(SCANENV_MEM_NODES(env)[backs[i]]))
- return ONIGERR_INVALID_BACKREF;
- }
- }
-
- tok->type = TK_BACKREF;
- tok->u.backref.by_name = 1;
- if (num == 1) {
- tok->u.backref.num = 1;
- tok->u.backref.ref1 = backs[0];
- }
- else {
- tok->u.backref.num = num;
- tok->u.backref.refs = backs;
- }
- }
- else
- PUNFETCH;
- }
- break;
-#endif
-
-#ifdef USE_SUBEXP_CALL
- case 'g':
- if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_G_SUBEXP_CALL)) {
- PFETCH(c);
- if (c == '<') {
- UChar* name_end;
-
- prev = p;
- r = fetch_name(&p, end, &name_end, env, 1);
- if (r < 0) return r;
-
- tok->type = TK_CALL;
- tok->u.call.name = prev;
- tok->u.call.name_end = name_end;
- }
- else
- PUNFETCH;
- }
- break;
-#endif
-
- case 'Q':
- if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE)) {
- tok->type = TK_QUOTE_OPEN;
- }
- break;
-
- case 'p':
- case 'P':
- if (PPEEK_IS('{') &&
- IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY)) {
- PINC;
- tok->type = TK_CHAR_PROPERTY;
- tok->u.prop.not = (c == 'P' ? 1 : 0);
-
- if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT)) {
- PFETCH(c);
- if (c == '^') {
- tok->u.prop.not = (tok->u.prop.not == 0 ? 1 : 0);
- }
- else
- PUNFETCH;
- }
- }
- break;
-
- default:
- PUNFETCH;
- num = fetch_escaped_value(&p, end, env);
- if (num < 0) return num;
- /* set_raw: */
- if (tok->u.c != num) {
- tok->type = TK_CODE_POINT;
- tok->u.code = (OnigCodePoint )num;
- }
- else { /* string */
- p = tok->backp + enc_len(enc, tok->backp);
- }
- break;
- }
- }
- else {
- tok->u.c = c;
- tok->escaped = 0;
-
-#ifdef USE_VARIABLE_META_CHARS
- if ((c != ONIG_INEFFECTIVE_META_CHAR) &&
- IS_SYNTAX_OP(syn, ONIG_SYN_OP_VARIABLE_META_CHARACTERS)) {
- if (c == MC_ANYCHAR(enc))
- goto any_char;
- else if (c == MC_ANYTIME(enc))
- goto anytime;
- else if (c == MC_ZERO_OR_ONE_TIME(enc))
- goto zero_or_one_time;
- else if (c == MC_ONE_OR_MORE_TIME(enc))
- goto one_or_more_time;
- else if (c == MC_ANYCHAR_ANYTIME(enc)) {
- tok->type = TK_ANYCHAR_ANYTIME;
- goto out;
- }
- }
-#endif
-
- switch (c) {
- case '.':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_DOT_ANYCHAR)) break;
-#ifdef USE_VARIABLE_META_CHARS
- any_char:
-#endif
- tok->type = TK_ANYCHAR;
- break;
-
- case '*':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ASTERISK_ZERO_INF)) break;
-#ifdef USE_VARIABLE_META_CHARS
- anytime:
-#endif
- tok->type = TK_OP_REPEAT;
- tok->u.repeat.lower = 0;
- tok->u.repeat.upper = REPEAT_INFINITE;
- goto greedy_check;
- break;
-
- case '+':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_PLUS_ONE_INF)) break;
-#ifdef USE_VARIABLE_META_CHARS
- one_or_more_time:
-#endif
- tok->type = TK_OP_REPEAT;
- tok->u.repeat.lower = 1;
- tok->u.repeat.upper = REPEAT_INFINITE;
- goto greedy_check;
- break;
-
- case '?':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_QMARK_ZERO_ONE)) break;
-#ifdef USE_VARIABLE_META_CHARS
- zero_or_one_time:
-#endif
- tok->type = TK_OP_REPEAT;
- tok->u.repeat.lower = 0;
- tok->u.repeat.upper = 1;
- goto greedy_check;
- break;
-
- case '{':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_BRACE_INTERVAL)) break;
- r = fetch_range_qualifier(&p, end, tok, env);
- if (r < 0) return r; /* error */
- if (r == 0) goto greedy_check;
- else if (r == 2) { /* {n} */
- if (IS_SYNTAX_BV(syn, ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY))
- goto possessive_check;
-
- goto greedy_check;
- }
- /* r == 1 : normal char */
- break;
-
- case '|':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_VBAR_ALT)) break;
- tok->type = TK_ALT;
- break;
-
- case '(':
- if (PPEEK_IS('?') &&
- IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_QMARK_GROUP_EFFECT)) {
- PINC;
- if (PPEEK_IS('#')) {
- PFETCH(c);
- while (1) {
- if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
- PFETCH(c);
- if (c == MC_ESC(enc)) {
- if (!PEND) PFETCH(c);
- }
- else {
- if (c == ')') break;
- }
- }
- goto start;
- }
- PUNFETCH;
- }
-
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LPAREN_SUBEXP)) break;
- tok->type = TK_SUBEXP_OPEN;
- break;
-
- case ')':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LPAREN_SUBEXP)) break;
- tok->type = TK_SUBEXP_CLOSE;
- break;
-
- case '^':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LINE_ANCHOR)) break;
- tok->type = TK_ANCHOR;
- tok->u.subtype = (IS_SINGLELINE(env->option)
- ? ANCHOR_BEGIN_BUF : ANCHOR_BEGIN_LINE);
- break;
-
- case '$':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LINE_ANCHOR)) break;
- tok->type = TK_ANCHOR;
- tok->u.subtype = (IS_SINGLELINE(env->option)
- ? ANCHOR_END_BUF : ANCHOR_END_LINE);
- break;
-
- case '[':
- if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_BRACKET_CC)) break;
- tok->type = TK_CC_OPEN;
- break;
-
- case ']':
- if (*src > env->pattern) /* /].../ is allowed. */
- CCEND_ESC_WARN(env, (UChar* )"]");
- break;
-
- case '#':
- if (IS_EXTEND(env->option)) {
- while (!PEND) {
- PFETCH(c);
- if (ONIGENC_IS_CODE_NEWLINE(enc, c))
- break;
- }
- goto start;
- break;
- }
- break;
-
- case ' ': case '\t': case '\n': case '\r': case '\f':
- if (IS_EXTEND(env->option))
- goto start;
- break;
-
- default:
- /* string */
- break;
- }
- }
-
-#ifdef USE_VARIABLE_META_CHARS
- out:
-#endif
- *src = p;
- return tok->type;
-}
-
-static int
-add_ctype_to_cc_by_range(CClassNode* cc, int ctype, int not, OnigEncoding enc,
- const OnigCodePoint sbr[], const OnigCodePoint mbr[])
-{
- int i, r;
- OnigCodePoint j;
-
- int nsb = ONIGENC_CODE_RANGE_NUM(sbr);
- int nmb = ONIGENC_CODE_RANGE_NUM(mbr);
-
- if (not == 0) {
- for (i = 0; i < nsb; i++) {
- for (j = ONIGENC_CODE_RANGE_FROM(sbr, i);
- j <= ONIGENC_CODE_RANGE_TO(sbr, i); j++) {
- BITSET_SET_BIT(cc->bs, j);
- }
- }
-
- for (i = 0; i < nmb; i++) {
- r = add_code_range_to_buf(&(cc->mbuf),
- ONIGENC_CODE_RANGE_FROM(mbr, i),
- ONIGENC_CODE_RANGE_TO(mbr, i));
- if (r != 0) return r;
- }
- }
- else {
- OnigCodePoint prev = 0;
-
- if (ONIGENC_MBC_MINLEN(enc) == 1) {
- for (i = 0; i < nsb; i++) {
- for (j = prev;
- j < ONIGENC_CODE_RANGE_FROM(sbr, i); j++) {
- BITSET_SET_BIT(cc->bs, j);
- }
- prev = ONIGENC_CODE_RANGE_TO(sbr, i) + 1;
- }
- if (prev < 0x7f) {
- for (j = prev; j < 0x7f; j++) {
- BITSET_SET_BIT(cc->bs, j);
- }
- }
-
- prev = 0x80;
- }
-
- for (i = 0; i < nmb; i++) {
- if (prev < ONIGENC_CODE_RANGE_FROM(mbr, i)) {
- r = add_code_range_to_buf(&(cc->mbuf), prev,
- ONIGENC_CODE_RANGE_FROM(mbr, i) - 1);
- if (r != 0) return r;
- }
- prev = ONIGENC_CODE_RANGE_TO(mbr, i) + 1;
- }
- if (prev < 0x7fffffff) {
- r = add_code_range_to_buf(&(cc->mbuf), prev, 0x7fffffff);
- if (r != 0) return r;
- }
- }
-
- return 0;
-}
-
-static int
-add_ctype_to_cc(CClassNode* cc, int ctype, int not, ScanEnv* env)
-{
- int c, r;
- const OnigCodePoint *sbr, *mbr;
- OnigEncoding enc = env->enc;
-
- r = ONIGENC_GET_CTYPE_CODE_RANGE(enc, ctype, &sbr, &mbr);
- if (r == 0) {
- return add_ctype_to_cc_by_range(cc, ctype, not, env->enc, sbr, mbr);
- }
- else if (r != ONIG_NO_SUPPORT_CONFIG) {
- return r;
- }
-
- r = 0;
- switch (ctype) {
- case ONIGENC_CTYPE_ALPHA:
- case ONIGENC_CTYPE_BLANK:
- case ONIGENC_CTYPE_CNTRL:
- case ONIGENC_CTYPE_DIGIT:
- case ONIGENC_CTYPE_LOWER:
- case ONIGENC_CTYPE_PUNCT:
- case ONIGENC_CTYPE_SPACE:
- case ONIGENC_CTYPE_UPPER:
- case ONIGENC_CTYPE_XDIGIT:
- case ONIGENC_CTYPE_ASCII:
- case ONIGENC_CTYPE_ALNUM:
- if (not != 0) {
- for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
- if (! ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
- BITSET_SET_BIT(cc->bs, c);
- }
- ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
- }
- else {
- for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
- if (ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
- BITSET_SET_BIT(cc->bs, c);
- }
- }
- break;
-
- case ONIGENC_CTYPE_GRAPH:
- case ONIGENC_CTYPE_PRINT:
- if (not != 0) {
- for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
- if (! ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
- BITSET_SET_BIT(cc->bs, c);
- }
- }
- else {
- for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
- if (ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
- BITSET_SET_BIT(cc->bs, c);
- }
- ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
- }
- break;
-
- case ONIGENC_CTYPE_WORD:
- if (not == 0) {
- for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
- if (ONIGENC_IS_CODE_SB_WORD(enc, c)) BITSET_SET_BIT(cc->bs, c);
- }
- ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
- }
- else {
- for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
- if ((ONIGENC_CODE_TO_MBCLEN(enc, c) > 0) /* 0: invalid code point */
- && ! ONIGENC_IS_CODE_WORD(enc, c))
- BITSET_SET_BIT(cc->bs, c);
- }
- }
- break;
-
- default:
- return ONIGERR_PARSER_BUG;
- break;
- }
-
- return r;
-}
-
-static int
-parse_ctype_to_enc_ctype(int pctype, int* not)
-{
- int ctype;
-
- switch (pctype) {
- case CTYPE_WORD:
- ctype = ONIGENC_CTYPE_WORD;
- *not = 0;
- break;
- case CTYPE_NOT_WORD:
- ctype = ONIGENC_CTYPE_WORD;
- *not = 1;
- break;
- case CTYPE_WHITE_SPACE:
- ctype = ONIGENC_CTYPE_SPACE;
- *not = 0;
- break;
- case CTYPE_NOT_WHITE_SPACE:
- ctype = ONIGENC_CTYPE_SPACE;
- *not = 1;
- break;
- case CTYPE_DIGIT:
- ctype = ONIGENC_CTYPE_DIGIT;
- *not = 0;
- break;
- case CTYPE_NOT_DIGIT:
- ctype = ONIGENC_CTYPE_DIGIT;
- *not = 1;
- break;
- case CTYPE_XDIGIT:
- ctype = ONIGENC_CTYPE_XDIGIT;
- *not = 0;
- break;
- case CTYPE_NOT_XDIGIT:
- ctype = ONIGENC_CTYPE_XDIGIT;
- *not = 1;
- break;
- default:
- return ONIGERR_PARSER_BUG;
- break;
- }
- return ctype;
-}
-
-typedef struct {
- UChar *name;
- int ctype;
- short int len;
-} PosixBracketEntryType;
-
-static int
-parse_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ScanEnv* env)
-{
-#define POSIX_BRACKET_CHECK_LIMIT_LENGTH 20
-#define POSIX_BRACKET_NAME_MAX_LEN 6
-
- static PosixBracketEntryType PBS[] = {
- { (UChar* )"alnum", ONIGENC_CTYPE_ALNUM, 5 },
- { (UChar* )"alpha", ONIGENC_CTYPE_ALPHA, 5 },
- { (UChar* )"blank", ONIGENC_CTYPE_BLANK, 5 },
- { (UChar* )"cntrl", ONIGENC_CTYPE_CNTRL, 5 },
- { (UChar* )"digit", ONIGENC_CTYPE_DIGIT, 5 },
- { (UChar* )"graph", ONIGENC_CTYPE_GRAPH, 5 },
- { (UChar* )"lower", ONIGENC_CTYPE_LOWER, 5 },
- { (UChar* )"print", ONIGENC_CTYPE_PRINT, 5 },
- { (UChar* )"punct", ONIGENC_CTYPE_PUNCT, 5 },
- { (UChar* )"space", ONIGENC_CTYPE_SPACE, 5 },
- { (UChar* )"upper", ONIGENC_CTYPE_UPPER, 5 },
- { (UChar* )"xdigit", ONIGENC_CTYPE_XDIGIT, 6 },
- { (UChar* )"ascii", ONIGENC_CTYPE_ASCII, 5 },
- { (UChar* )NULL, -1, 0 }
- };
-
- PosixBracketEntryType *pb;
- int not, i, r;
- OnigCodePoint c;
- OnigEncoding enc = env->enc;
- UChar *p = *src;
- PFETCH_READY;
-
- if (PPEEK_IS('^')) {
- PINC;
- not = 1;
- }
- else
- not = 0;
-
- if (onigenc_strlen(enc, p, end) < POSIX_BRACKET_NAME_MAX_LEN + 2)
- goto not_posix_bracket;
-
- for (pb = PBS; IS_NOT_NULL(pb->name); pb++) {
- if (onigenc_with_ascii_strncmp(enc, p, end, pb->name, pb->len) == 0) {
- p = (UChar* )onigenc_step(enc, p, end, pb->len);
- if (onigenc_with_ascii_strncmp(enc, p, end, (UChar* )":]", 2) != 0)
- return ONIGERR_INVALID_POSIX_BRACKET_TYPE;
-
- r = add_ctype_to_cc(cc, pb->ctype, not, env);
- if (r != 0) return r;
-
- PINC; PINC;
- *src = p;
- return 0;
- }
- }
-
- not_posix_bracket:
- c = 0;
- i = 0;
- while (!PEND && ((c = PPEEK) != ':') && c != ']') {
- PINC;
- if (++i > POSIX_BRACKET_CHECK_LIMIT_LENGTH) break;
- }
- if (c == ':' && ! PEND) {
- PINC;
- if (! PEND) {
- PFETCH(c);
- if (c == ']')
- return ONIGERR_INVALID_POSIX_BRACKET_TYPE;
- }
- }
-
- return 1; /* 1: is not POSIX bracket, but no error. */
-}
-
-static int
-property_name_to_ctype(UChar* p, UChar* end, OnigEncoding enc)
-{
- static PosixBracketEntryType PBS[] = {
- { (UChar* )"Alnum", ONIGENC_CTYPE_ALNUM, 5 },
- { (UChar* )"Alpha", ONIGENC_CTYPE_ALPHA, 5 },
- { (UChar* )"Blank", ONIGENC_CTYPE_BLANK, 5 },
- { (UChar* )"Cntrl", ONIGENC_CTYPE_CNTRL, 5 },
- { (UChar* )"Digit", ONIGENC_CTYPE_DIGIT, 5 },
- { (UChar* )"Graph", ONIGENC_CTYPE_GRAPH, 5 },
- { (UChar* )"Lower", ONIGENC_CTYPE_LOWER, 5 },
- { (UChar* )"Print", ONIGENC_CTYPE_PRINT, 5 },
- { (UChar* )"Punct", ONIGENC_CTYPE_PUNCT, 5 },
- { (UChar* )"Space", ONIGENC_CTYPE_SPACE, 5 },
- { (UChar* )"Upper", ONIGENC_CTYPE_UPPER, 5 },
- { (UChar* )"XDigit", ONIGENC_CTYPE_XDIGIT, 6 },
- { (UChar* )"ASCII", ONIGENC_CTYPE_ASCII, 5 },
- { (UChar* )NULL, -1, 0 }
- };
-
- PosixBracketEntryType *pb;
- int len;
-
- len = onigenc_strlen(enc, p, end);
- for (pb = PBS; IS_NOT_NULL(pb->name); pb++) {
- if (len == pb->len &&
- onigenc_with_ascii_strncmp(enc, p, end, pb->name, pb->len) == 0)
- return pb->ctype;
- }
-
- return -1;
-}
-
-static int
-fetch_char_property_to_ctype(UChar** src, UChar* end, ScanEnv* env)
-{
- int ctype;
- OnigCodePoint c;
- OnigEncoding enc = env->enc;
- UChar *prev, *start, *p = *src;
- PFETCH_READY;
-
- /* 'IsXXXX' => 'XXXX' */
- if (!PEND &&
- IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS)) {
- c = PPEEK;
- if (c == 'I') {
- PINC;
- if (! PEND) {
- c = PPEEK;
- if (c == 's')
- PINC;
- else
- PUNFETCH;
- }
- }
- }
-
- start = prev = p;
-
- while (!PEND) {
- prev = p;
- PFETCH(c);
- if (c == '}') {
- ctype = property_name_to_ctype(start, prev, enc);
- if (ctype < 0) break;
-
- *src = p;
- return ctype;
- }
- else if (c == '(' || c == ')' || c == '{' || c == '|')
- break;
- }
-
- onig_scan_env_set_error_string(env, ONIGERR_INVALID_CHAR_PROPERTY_NAME,
- *src, prev);
- return ONIGERR_INVALID_CHAR_PROPERTY_NAME;
-}
-
-static int
-parse_char_property(Node** np, OnigToken* tok, UChar** src, UChar* end,
- ScanEnv* env)
-{
- int r, ctype;
- CClassNode* cc;
-
- ctype = fetch_char_property_to_ctype(src, end, env);
- if (ctype < 0) return ctype;
-
- *np = node_new_cclass();
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- cc = &(NCCLASS(*np));
- r = add_ctype_to_cc(cc, ctype, 0, env);
- if (r != 0) return r;
- if (tok->u.prop.not != 0) CCLASS_SET_NOT(cc);
-
- return 0;
-}
-
-
-enum CCSTATE {
- CCS_VALUE,
- CCS_RANGE,
- CCS_COMPLETE,
- CCS_START
-};
-
-enum CCVALTYPE {
- CCV_SB,
- CCV_CODE_POINT,
- CCV_CLASS
-};
-
-static int
-next_state_class(CClassNode* cc, OnigCodePoint* vs, enum CCVALTYPE* type,
- enum CCSTATE* state, ScanEnv* env)
-{
- int r;
-
- if (*state == CCS_RANGE)
- return ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE;
-
- if (*state == CCS_VALUE && *type != CCV_CLASS) {
- if (*type == CCV_SB)
- BITSET_SET_BIT(cc->bs, (int )(*vs));
- else if (*type == CCV_CODE_POINT) {
- r = add_code_range(&(cc->mbuf), env, *vs, *vs);
- if (r < 0) return r;
- }
- }
-
- *state = CCS_VALUE;
- *type = CCV_CLASS;
- return 0;
-}
-
-static int
-next_state_val(CClassNode* cc, OnigCodePoint *vs, OnigCodePoint v,
- int* vs_israw, int v_israw,
- enum CCVALTYPE intype, enum CCVALTYPE* type,
- enum CCSTATE* state, ScanEnv* env)
-{
- int r;
-
- switch (*state) {
- case CCS_VALUE:
- if (*type == CCV_SB)
- BITSET_SET_BIT(cc->bs, (int )(*vs));
- else if (*type == CCV_CODE_POINT) {
- r = add_code_range(&(cc->mbuf), env, *vs, *vs);
- if (r < 0) return r;
- }
- break;
-
- case CCS_RANGE:
- if (intype == *type) {
- if (intype == CCV_SB) {
- if (*vs > 0xff || v > 0xff)
- return ONIGERR_INVALID_WIDE_CHAR_VALUE;
-
- if (*vs > v) {
- if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC))
- goto ccs_range_end;
- else
- return ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS;
- }
- bitset_set_range(cc->bs, (int )*vs, (int )v);
- }
- else {
- r = add_code_range(&(cc->mbuf), env, *vs, v);
- if (r < 0) return r;
- }
- }
- else {
-#if 0
- if (intype == CCV_CODE_POINT && *type == CCV_SB) {
-#endif
- if (*vs > v) {
- if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC))
- goto ccs_range_end;
- else
- return ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS;
- }
- bitset_set_range(cc->bs, (int )*vs, (int )(v < 0xff ? v : 0xff));
- r = add_code_range(&(cc->mbuf), env, (OnigCodePoint )*vs, v);
- if (r < 0) return r;
-#if 0
- }
- else
- return ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE;
-#endif
- }
- ccs_range_end:
- *state = CCS_COMPLETE;
- break;
-
- case CCS_COMPLETE:
- case CCS_START:
- *state = CCS_VALUE;
- break;
-
- default:
- break;
- }
-
- *vs_israw = v_israw;
- *vs = v;
- *type = intype;
- return 0;
-}
-
-static int
-code_exist_check(OnigCodePoint c, UChar* from, UChar* end, int ignore_escaped,
- OnigEncoding enc)
-{
- int in_esc;
- OnigCodePoint code;
- UChar* p = from;
- PFETCH_READY;
-
- in_esc = 0;
- while (! PEND) {
- if (ignore_escaped && in_esc) {
- in_esc = 0;
- }
- else {
- PFETCH(code);
- if (code == c) return 1;
- if (code == MC_ESC(enc)) in_esc = 1;
- }
- }
- return 0;
-}
-
-static int
-parse_char_class(Node** np, OnigToken* tok, UChar** src, UChar* end,
- ScanEnv* env)
-{
- int r, neg, len, fetched, and_start;
- OnigCodePoint v, vs;
- UChar *p;
- Node* node;
- CClassNode *cc, *prev_cc;
- CClassNode work_cc;
-
- enum CCSTATE state;
- enum CCVALTYPE val_type, in_type;
- int val_israw, in_israw;
-
- prev_cc = (CClassNode* )NULL;
- *np = NULL_NODE;
- r = fetch_token_in_cc(tok, src, end, env);
- if (r == TK_CHAR && tok->u.c == '^' && tok->escaped == 0) {
- neg = 1;
- r = fetch_token_in_cc(tok, src, end, env);
- }
- else {
- neg = 0;
- }
-
- if (r < 0) return r;
- if (r == TK_CC_CLOSE) {
- if (! code_exist_check((OnigCodePoint )']',
- *src, env->pattern_end, 1, env->enc))
- return ONIGERR_EMPTY_CHAR_CLASS;
-
- CC_ESC_WARN(env, (UChar* )"]");
- r = tok->type = TK_CHAR; /* allow []...] */
- }
-
- *np = node = node_new_cclass();
- CHECK_NULL_RETURN_VAL(node, ONIGERR_MEMORY);
- cc = &(NCCLASS(node));
-
- and_start = 0;
- state = CCS_START;
- p = *src;
- while (r != TK_CC_CLOSE) {
- fetched = 0;
- switch (r) {
- case TK_CHAR:
- len = ONIGENC_CODE_TO_MBCLEN(env->enc, tok->u.c);
- if (len > 1) {
- in_type = CCV_CODE_POINT;
- }
- else {
- sb_char:
- in_type = CCV_SB;
- }
- v = (OnigCodePoint )tok->u.c;
- in_israw = 0;
- goto val_entry2;
- break;
-
- case TK_RAW_BYTE:
- /* tok->base != 0 : octal or hexadec. */
- if (! ONIGENC_IS_SINGLEBYTE(env->enc) && tok->base != 0) {
- UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
- UChar* bufe = buf + ONIGENC_CODE_TO_MBC_MAXLEN;
- UChar* psave = p;
- int i, base = tok->base;
-
- buf[0] = tok->u.c;
- for (i = 1; i < ONIGENC_MBC_MAXLEN(env->enc); i++) {
- r = fetch_token_in_cc(tok, &p, end, env);
- if (r < 0) goto err;
- if (r != TK_RAW_BYTE || tok->base != base) {
- fetched = 1;
- break;
- }
- buf[i] = tok->u.c;
- }
-
- if (i < ONIGENC_MBC_MINLEN(env->enc)) {
- r = ONIGERR_TOO_SHORT_MULTI_BYTE_STRING;
- goto err;
- }
-
- len = enc_len(env->enc, buf);
- if (i < len) {
- r = ONIGERR_TOO_SHORT_MULTI_BYTE_STRING;
- goto err;
- }
- else if (i > len) { /* fetch back */
- p = psave;
- for (i = 1; i < len; i++) {
- r = fetch_token_in_cc(tok, &p, end, env);
- }
- fetched = 0;
- }
-
- if (i == 1) {
- v = (OnigCodePoint )buf[0];
- goto raw_single;
- }
- else {
- v = ONIGENC_MBC_TO_CODE(env->enc, buf, bufe);
- in_type = CCV_CODE_POINT;
- }
- }
- else {
- v = (OnigCodePoint )tok->u.c;
- raw_single:
- in_type = CCV_SB;
- }
- in_israw = 1;
- goto val_entry2;
- break;
-
- case TK_CODE_POINT:
- v = tok->u.code;
- in_israw = 1;
- val_entry:
- len = ONIGENC_CODE_TO_MBCLEN(env->enc, v);
- if (len < 0) {
- r = len;
- goto err;
- }
- in_type = (len == 1 ? CCV_SB : CCV_CODE_POINT);
- val_entry2:
- r = next_state_val(cc, &vs, v, &val_israw, in_israw, in_type, &val_type,
- &state, env);
- if (r != 0) goto err;
- break;
-
- case TK_POSIX_BRACKET_OPEN:
- r = parse_posix_bracket(cc, &p, end, env);
- if (r < 0) goto err;
- if (r == 1) { /* is not POSIX bracket */
- CC_ESC_WARN(env, (UChar* )"[");
- p = tok->backp;
- v = (OnigCodePoint )tok->u.c;
- in_israw = 0;
- goto val_entry;
- }
- goto next_class;
- break;
-
- case TK_CHAR_TYPE:
- {
- int ctype, not;
- ctype = parse_ctype_to_enc_ctype(tok->u.subtype, &not);
- r = add_ctype_to_cc(cc, ctype, not, env);
- if (r != 0) return r;
- }
-
- next_class:
- r = next_state_class(cc, &vs, &val_type, &state, env);
- if (r != 0) goto err;
- break;
-
- case TK_CHAR_PROPERTY:
- {
- int ctype;
-
- ctype = fetch_char_property_to_ctype(&p, end, env);
- if (ctype < 0) return ctype;
- r = add_ctype_to_cc(cc, ctype, tok->u.prop.not, env);
- if (r != 0) return r;
- goto next_class;
- }
- break;
-
- case TK_CC_RANGE:
- if (state == CCS_VALUE) {
- r = fetch_token_in_cc(tok, &p, end, env);
- if (r < 0) goto err;
- fetched = 1;
- if (r == TK_CC_CLOSE) { /* allow [x-] */
- range_end_val:
- v = (OnigCodePoint )'-';
- in_israw = 0;
- goto val_entry;
- }
- else if (r == TK_CC_AND) {
- CC_ESC_WARN(env, (UChar* )"-");
- goto range_end_val;
- }
- state = CCS_RANGE;
- }
- else if (state == CCS_START) {
- /* [-xa] is allowed */
- v = (OnigCodePoint )tok->u.c;
- in_israw = 0;
-
- r = fetch_token_in_cc(tok, &p, end, env);
- if (r < 0) goto err;
- fetched = 1;
- /* [--x] or [a&&-x] is warned. */
- if (r == TK_CC_RANGE || and_start != 0)
- CC_ESC_WARN(env, (UChar* )"-");
-
- goto val_entry;
- }
- else if (state == CCS_RANGE) {
- CC_ESC_WARN(env, (UChar* )"-");
- goto sb_char; /* [!--x] is allowed */
- }
- else { /* CCS_COMPLETE */
- r = fetch_token_in_cc(tok, &p, end, env);
- if (r < 0) goto err;
- fetched = 1;
- if (r == TK_CC_CLOSE) goto range_end_val; /* allow [a-b-] */
- else if (r == TK_CC_AND) {
- CC_ESC_WARN(env, (UChar* )"-");
- goto range_end_val;
- }
-
- if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC)) {
- CC_ESC_WARN(env, (UChar* )"-");
- goto sb_char; /* [0-9-a] is allowed as [0-9\-a] */
- }
- r = ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS;
- goto err;
- }
- break;
-
- case TK_CC_CC_OPEN: /* [ */
- {
- Node *anode;
- CClassNode* acc;
-
- r = parse_char_class(&anode, tok, &p, end, env);
- if (r != 0) goto cc_open_err;
- acc = &(NCCLASS(anode));
- r = or_cclass(cc, acc, env->enc);
-
- onig_node_free(anode);
- cc_open_err:
- if (r != 0) goto err;
- }
- break;
-
- case TK_CC_AND: /* && */
- {
- if (state == CCS_VALUE) {
- r = next_state_val(cc, &vs, 0, &val_israw, 0, val_type,
- &val_type, &state, env);
- if (r != 0) goto err;
- }
- /* initialize local variables */
- and_start = 1;
- state = CCS_START;
-
- if (IS_NOT_NULL(prev_cc)) {
- r = and_cclass(prev_cc, cc, env->enc);
- if (r != 0) goto err;
- bbuf_free(cc->mbuf);
- }
- else {
- prev_cc = cc;
- cc = &work_cc;
- }
- initialize_cclass(cc);
- }
- break;
-
- case TK_EOT:
- r = ONIGERR_PREMATURE_END_OF_CHAR_CLASS;
- goto err;
- break;
- default:
- r = ONIGERR_PARSER_BUG;
- goto err;
- break;
- }
-
- if (fetched)
- r = tok->type;
- else {
- r = fetch_token_in_cc(tok, &p, end, env);
- if (r < 0) goto err;
- }
- }
-
- if (state == CCS_VALUE) {
- r = next_state_val(cc, &vs, 0, &val_israw, 0, val_type,
- &val_type, &state, env);
- if (r != 0) goto err;
- }
-
- if (IS_NOT_NULL(prev_cc)) {
- r = and_cclass(prev_cc, cc, env->enc);
- if (r != 0) goto err;
- bbuf_free(cc->mbuf);
- cc = prev_cc;
- }
-
- if (neg != 0)
- CCLASS_SET_NOT(cc);
- else
- CCLASS_CLEAR_NOT(cc);
- if (IS_CCLASS_NOT(cc) &&
- IS_SYNTAX_BV(env->syntax, ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC)) {
- int is_empty;
-
- is_empty = (IS_NULL(cc->mbuf) ? 1 : 0);
- if (is_empty != 0)
- BITSET_IS_EMPTY(cc->bs, is_empty);
-
- if (is_empty == 0) {
-#define NEWLINE_CODE 0x0a
-
- if (ONIGENC_IS_CODE_NEWLINE(env->enc, NEWLINE_CODE)) {
- if (ONIGENC_CODE_TO_MBCLEN(env->enc, NEWLINE_CODE) == 1)
- BITSET_SET_BIT(cc->bs, NEWLINE_CODE);
- else
- add_code_range(&(cc->mbuf), env, NEWLINE_CODE, NEWLINE_CODE);
- }
- }
- }
- *src = p;
- return 0;
-
- err:
- if (cc != &(NCCLASS(*np)))
- bbuf_free(cc->mbuf);
- onig_node_free(*np);
- return r;
-}
-
-static int parse_subexp(Node** top, OnigToken* tok, int term,
- UChar** src, UChar* end, ScanEnv* env);
-
-static int
-parse_effect(Node** np, OnigToken* tok, int term, UChar** src, UChar* end,
- ScanEnv* env)
-{
- int r, num;
- int list_capture;
- Node *target;
- OnigOptionType option;
- OnigEncoding enc = env->enc;
- OnigCodePoint c;
- UChar* p = *src;
- PFETCH_READY;
-
- *np = NULL;
- if (PEND) return ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS;
-
- option = env->option;
- if (PPEEK_IS('?') &&
- IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_GROUP_EFFECT)) {
- PINC;
- if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
-
- PFETCH(c);
- switch (c) {
- case ':': /* (?:...) grouping only */
- group:
- r = fetch_token(tok, &p, end, env);
- if (r < 0) return r;
- r = parse_subexp(np, tok, term, &p, end, env);
- if (r < 0) return r;
- *src = p;
- return 1; /* group */
- break;
-
- case '=':
- *np = onig_node_new_anchor(ANCHOR_PREC_READ);
- break;
- case '!': /* preceding read */
- *np = onig_node_new_anchor(ANCHOR_PREC_READ_NOT);
- break;
- case '>': /* (?>...) stop backtrack */
- *np = node_new_effect(EFFECT_STOP_BACKTRACK);
- break;
-
- case '<': /* look behind (?<=...), (?<!...) */
- PFETCH(c);
- if (c == '=')
- *np = onig_node_new_anchor(ANCHOR_LOOK_BEHIND);
- else if (c == '!')
- *np = onig_node_new_anchor(ANCHOR_LOOK_BEHIND_NOT);
-#ifdef USE_NAMED_GROUP
- else if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP)) {
- UChar *name;
- UChar *name_end;
-
- PUNFETCH;
- list_capture = 0;
-
- named_group:
- name = p;
- r = fetch_name(&p, end, &name_end, env, 0);
- if (r < 0) return r;
-
- num = scan_env_add_mem_entry(env);
- if (num < 0) return num;
- if (list_capture != 0 && num >= BIT_STATUS_BITS_NUM)
- return ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY;
-
- r = name_add(env->reg, name, name_end, num, env);
- if (r != 0) return r;
- *np = node_new_effect_memory(env->option, 1);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- NEFFECT(*np).regnum = num;
- if (list_capture != 0)
- BIT_STATUS_ON_AT_SIMPLE(env->capture_history, num);
- env->num_named++;
- }
-#endif
- else
- return ONIGERR_UNDEFINED_GROUP_OPTION;
- break;
-
- case '@':
- if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY)) {
-#ifdef USE_NAMED_GROUP
- if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP)) {
- PFETCH(c);
- if (c == '<') {
- list_capture = 1;
- goto named_group; /* (?@<name>...) */
- }
- PUNFETCH;
- }
-#endif
- *np = node_new_effect_memory(env->option, 0);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- num = scan_env_add_mem_entry(env);
- if (num < 0) {
- onig_node_free(*np);
- return num;
- }
- else if (num >= BIT_STATUS_BITS_NUM) {
- onig_node_free(*np);
- return ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY;
- }
- NEFFECT(*np).regnum = num;
- BIT_STATUS_ON_AT_SIMPLE(env->capture_history, num);
- }
- else {
- return ONIGERR_UNDEFINED_GROUP_OPTION;
- }
- break;
-
-#ifdef USE_POSIXLINE_OPTION
- case 'p':
-#endif
- case '-': case 'i': case 'm': case 's': case 'x':
- {
- int neg = 0;
-
- while (1) {
- switch (c) {
- case ':':
- case ')':
- break;
-
- case '-': neg = 1; break;
- case 'x': ONOFF(option, ONIG_OPTION_EXTEND, neg); break;
- case 'i': ONOFF(option, ONIG_OPTION_IGNORECASE, neg); break;
- case 's':
- if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_PERL)) {
- ONOFF(option, ONIG_OPTION_MULTILINE, neg);
- }
- else
- return ONIGERR_UNDEFINED_GROUP_OPTION;
- break;
-
- case 'm':
- if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_PERL)) {
- ONOFF(option, ONIG_OPTION_SINGLELINE, (neg == 0 ? 1 : 0));
- }
- else if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_OPTION_RUBY)) {
- ONOFF(option, ONIG_OPTION_MULTILINE, neg);
- }
- else
- return ONIGERR_UNDEFINED_GROUP_OPTION;
- break;
-#ifdef USE_POSIXLINE_OPTION
- case 'p':
- ONOFF(option, ONIG_OPTION_MULTILINE|ONIG_OPTION_SINGLELINE, neg);
- break;
-#endif
- default:
- return ONIGERR_UNDEFINED_GROUP_OPTION;
- }
-
- if (c == ')') {
- *np = node_new_option(option);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- *src = p;
- return 2; /* option only */
- }
- else if (c == ':') {
- OnigOptionType prev = env->option;
-
- env->option = option;
- r = fetch_token(tok, &p, end, env);
- if (r < 0) return r;
- r = parse_subexp(&target, tok, term, &p, end, env);
- env->option = prev;
- if (r < 0) return r;
- *np = node_new_option(option);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- NEFFECT(*np).target = target;
- *src = p;
- return 0;
- }
-
- if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
- PFETCH(c);
- }
- }
- break;
-
- default:
- return ONIGERR_UNDEFINED_GROUP_OPTION;
- }
- }
- else {
- if (ONIG_IS_OPTION_ON(env->option, ONIG_OPTION_DONT_CAPTURE_GROUP))
- goto group;
-
- *np = node_new_effect_memory(env->option, 0);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- num = scan_env_add_mem_entry(env);
- if (num < 0) return num;
- NEFFECT(*np).regnum = num;
- }
-
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- r = fetch_token(tok, &p, end, env);
- if (r < 0) return r;
- r = parse_subexp(&target, tok, term, &p, end, env);
- if (r < 0) return r;
-
- if (NTYPE(*np) == N_ANCHOR)
- NANCHOR(*np).target = target;
- else {
- NEFFECT(*np).target = target;
- if (NEFFECT(*np).type == EFFECT_MEMORY) {
- /* Don't move this to previous of parse_subexp() */
- r = scan_env_set_mem_node(env, NEFFECT(*np).regnum, *np);
- if (r != 0) return r;
- }
- }
-
- *src = p;
- return 0;
-}
-
-static const char* PopularQStr[] = {
- "?", "*", "+", "??", "*?", "+?"
-};
-
-static const char* ReduceQStr[] = {
- "", "", "*", "*?", "??", "+ and ??", "+? and ?"
-};
-
-static int
-set_qualifier(Node* qnode, Node* target, int group, ScanEnv* env)
-{
- QualifierNode* qn;
-
- qn = &(NQUALIFIER(qnode));
- if (qn->lower == 1 && qn->upper == 1) {
- return 1;
- }
-
- switch (NTYPE(target)) {
- case N_STRING:
- if (! group) {
- StrNode* sn = &(NSTRING(target));
- if (str_node_can_be_split(sn, env->enc)) {
- Node* n = str_node_split_last_char(sn, env->enc);
- if (IS_NOT_NULL(n)) {
- qn->target = n;
- return 2;
- }
- }
- }
- break;
-
- case N_QUALIFIER:
- { /* check redundant double repeat. */
- /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
- QualifierNode* qnt = &(NQUALIFIER(target));
- int nestq_num = popular_qualifier_num(qn);
- int targetq_num = popular_qualifier_num(qnt);
-
-#ifdef USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
- if (!IS_QUALIFIER_BY_NUMBER(qn) && !IS_QUALIFIER_BY_NUMBER(qnt) &&
- IS_SYNTAX_BV(env->syntax, ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT)) {
- UChar buf[WARN_BUFSIZE];
-
- switch(ReduceTypeTable[targetq_num][nestq_num]) {
- case RQ_ASIS:
- break;
-
- case RQ_DEL:
- if (onig_verb_warn != onig_null_warn) {
- onig_snprintf_with_pattern(buf, WARN_BUFSIZE, env->enc,
- env->pattern, env->pattern_end,
- (UChar* )"redundant nested repeat operator");
- (*onig_verb_warn)((char* )buf);
- }
- goto warn_exit;
- break;
-
- default:
- if (onig_verb_warn != onig_null_warn) {
- onig_snprintf_with_pattern(buf, WARN_BUFSIZE, env->enc,
- env->pattern, env->pattern_end,
- (UChar* )"nested repeat operator %s and %s was replaced with '%s'",
- PopularQStr[targetq_num], PopularQStr[nestq_num],
- ReduceQStr[ReduceTypeTable[targetq_num][nestq_num]]);
- (*onig_verb_warn)((char* )buf);
- }
- goto warn_exit;
- break;
- }
- }
-
- warn_exit:
-#endif
- if (targetq_num >= 0) {
- if (nestq_num >= 0) {
- onig_reduce_nested_qualifier(qnode, target);
- goto q_exit;
- }
- else if (targetq_num == 1 || targetq_num == 2) { /* * or + */
- /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
- if (! IS_REPEAT_INFINITE(qn->upper) && qn->upper > 1 && qn->greedy) {
- qn->upper = (qn->lower == 0 ? 1 : qn->lower);
- }
- }
- }
- }
- break;
-
- default:
- break;
- }
-
- qn->target = target;
- q_exit:
- return 0;
-}
-
-static int
-make_compound_alt_node_from_cc(OnigAmbigType ambig_flag, OnigEncoding enc,
- CClassNode* cc, Node** root)
-{
- int r, i, j, k, clen, len, ncode, n;
- UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
- Node **ptail, *snode = NULL_NODE;
- const OnigCompAmbigCodes* ccs;
- const OnigCompAmbigCodeItem* ci;
- OnigAmbigType amb;
-
- n = 0;
- *root = NULL_NODE;
- ptail = root;
-
-
- for (amb = 0x01; amb <= ONIGENC_AMBIGUOUS_MATCH_LIMIT; amb <<= 1) {
- if ((amb & ambig_flag) == 0) continue;
-
- ncode = ONIGENC_GET_ALL_COMP_AMBIG_CODES(enc, amb, &ccs);
- for (i = 0; i < ncode; i++) {
- if (onig_is_code_in_cc(enc, ccs[i].code, cc)) {
- for (j = 0; j < ccs[i].n; j++) {
- ci = &(ccs[i].items[j]);
- if (ci->len > 1) { /* compound only */
- if (IS_CCLASS_NOT(cc)) clear_not_flag_cclass(cc, enc);
-
- clen = ci->len;
- for (k = 0; k < clen; k++) {
- len = ONIGENC_CODE_TO_MBC(enc, ci->code[k], buf);
-
- if (k == 0) {
- snode = node_new_str_raw(buf, buf + len);
- CHECK_NULL_RETURN_VAL(snode, ONIGERR_MEMORY);
- }
- else {
- r = onig_node_str_cat(snode, buf, buf + len);
- if (r < 0) return r;
- }
- }
-
- *ptail = node_new_alt(snode, NULL_NODE);
- CHECK_NULL_RETURN_VAL(*ptail, ONIGERR_MEMORY);
- ptail = &(NCONS(*ptail).right);
- n++;
- }
- }
- }
- }
- }
-
- return n;
-}
-
-
-#ifdef USE_SHARED_CCLASS_TABLE
-
-#define THRESHOLD_RANGE_NUM_FOR_SHARE_CCLASS 8
-
-/* for ctype node hash table */
-
-typedef struct {
- OnigEncoding enc;
- int not;
- int type;
-} type_cclass_key;
-
-static int type_cclass_cmp(type_cclass_key* x, type_cclass_key* y)
-{
- if (x->type != y->type) return 1;
- if (x->enc != y->enc) return 1;
- if (x->not != y->not) return 1;
- return 0;
-}
-
-static int type_cclass_hash(type_cclass_key* key)
-{
- int i, val;
- unsigned char *p;
-
- val = 0;
-
- p = (unsigned char* )&(key->enc);
- for (i = 0; i < sizeof(key->enc); i++) {
- val = val * 997 + (int )*p++;
- }
-
- p = (unsigned char* )(&key->type);
- for (i = 0; i < sizeof(key->type); i++) {
- val = val * 997 + (int )*p++;
- }
-
- val += key->not;
- return val + (val >> 5);
-}
-
-static struct st_hash_type type_type_cclass_hash = {
- type_cclass_cmp,
- type_cclass_hash,
-};
-
-static st_table* OnigTypeCClassTable;
-
-
-static int
-i_free_shared_class(type_cclass_key* key, Node* node, void* arg)
-{
- if (IS_NOT_NULL(node)) {
- CClassNode* cc = &(NCCLASS(node));
- if (IS_NOT_NULL(cc->mbuf)) xfree(cc->mbuf);
- xfree(node);
- }
-
- if (IS_NOT_NULL(key)) xfree(key);
- return ST_DELETE;
-}
-
-extern int
-onig_free_shared_cclass_table()
-{
- if (IS_NOT_NULL(OnigTypeCClassTable)) {
- onig_st_foreach(OnigTypeCClassTable, i_free_shared_class, 0);
- onig_st_free_table(OnigTypeCClassTable);
- OnigTypeCClassTable = NULL;
- }
-
- return 0;
-}
-
-#endif /* USE_SHARED_CCLASS_TABLE */
-
-
-static int
-parse_exp(Node** np, OnigToken* tok, int term,
- UChar** src, UChar* end, ScanEnv* env)
-{
- int r, len, group = 0;
- Node* qn;
- Node** targetp;
-
- *np = NULL;
- if (tok->type == term)
- goto end_of_token;
-
- switch (tok->type) {
- case TK_ALT:
- case TK_EOT:
- end_of_token:
- *np = node_new_empty();
- return tok->type;
- break;
-
- case TK_SUBEXP_OPEN:
- r = parse_effect(np, tok, TK_SUBEXP_CLOSE, src, end, env);
- if (r < 0) return r;
- if (r == 1) group = 1;
- else if (r == 2) { /* option only */
- Node* target;
- OnigOptionType prev = env->option;
-
- env->option = NEFFECT(*np).option;
- r = fetch_token(tok, src, end, env);
- if (r < 0) return r;
- r = parse_subexp(&target, tok, term, src, end, env);
- env->option = prev;
- if (r < 0) return r;
- NEFFECT(*np).target = target;
- return tok->type;
- }
- break;
-
- case TK_SUBEXP_CLOSE:
- if (! IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP))
- return ONIGERR_UNMATCHED_CLOSE_PARENTHESIS;
-
- if (tok->escaped) goto tk_raw_byte;
- else goto tk_byte;
- break;
-
- case TK_STRING:
- tk_byte:
- {
- *np = node_new_str(tok->backp, *src);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
-
- while (1) {
- r = fetch_token(tok, src, end, env);
- if (r < 0) return r;
- if (r != TK_STRING) break;
-
- r = onig_node_str_cat(*np, tok->backp, *src);
- if (r < 0) return r;
- }
-
- string_end:
- targetp = np;
- goto repeat;
- }
- break;
-
- case TK_RAW_BYTE:
- tk_raw_byte:
- {
- *np = node_new_str_raw_char((UChar )tok->u.c);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- len = 1;
- while (1) {
- r = fetch_token(tok, src, end, env);
- if (r < 0) return r;
- if (r != TK_RAW_BYTE) {
-#ifndef NUMBERED_CHAR_IS_NOT_CASE_AMBIG
- if (len >= enc_len(env->enc, NSTRING(*np).s)) {
- NSTRING_CLEAR_RAW(*np);
- }
-#endif
- goto string_end;
- }
-
- r = node_str_cat_char(*np, (UChar )tok->u.c);
- if (r < 0) return r;
- len++;
- }
- }
- break;
-
- case TK_CODE_POINT:
- {
- UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
- int num = ONIGENC_CODE_TO_MBC(env->enc, tok->u.code, buf);
- if (num < 0) return num;
-#ifdef NUMBERED_CHAR_IS_NOT_CASE_AMBIG
- *np = node_new_str_raw(buf, buf + num);
-#else
- *np = node_new_str(buf, buf + num);
-#endif
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- }
- break;
-
- case TK_QUOTE_OPEN:
- {
- OnigCodePoint end_op[2];
- UChar *qstart, *qend, *nextp;
-
- end_op[0] = (OnigCodePoint )MC_ESC(env->enc);
- end_op[1] = (OnigCodePoint )'E';
- qstart = *src;
- qend = find_str_position(end_op, 2, qstart, end, &nextp, env->enc);
- if (IS_NULL(qend)) {
- nextp = qend = end;
- }
- *np = node_new_str(qstart, qend);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- *src = nextp;
- }
- break;
-
- case TK_CHAR_TYPE:
- {
- switch (tok->u.subtype) {
- case CTYPE_WORD:
- case CTYPE_NOT_WORD:
- *np = node_new_ctype(tok->u.subtype);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- break;
-
- case CTYPE_WHITE_SPACE:
- case CTYPE_NOT_WHITE_SPACE:
- case CTYPE_DIGIT:
- case CTYPE_NOT_DIGIT:
- case CTYPE_XDIGIT:
- case CTYPE_NOT_XDIGIT:
- {
- CClassNode* cc;
- int ctype, not;
-
-#ifdef USE_SHARED_CCLASS_TABLE
- const OnigCodePoint *sbr, *mbr;
-
- ctype = parse_ctype_to_enc_ctype(tok->u.subtype, &not);
- r = ONIGENC_GET_CTYPE_CODE_RANGE(env->enc, ctype, &sbr, &mbr);
- if (r == 0 &&
- ONIGENC_CODE_RANGE_NUM(mbr)
- >= THRESHOLD_RANGE_NUM_FOR_SHARE_CCLASS) {
- type_cclass_key key;
- type_cclass_key* new_key;
-
- key.enc = env->enc;
- key.not = not;
- key.type = ctype;
-
- THREAD_ATOMIC_START;
-
- if (IS_NULL(OnigTypeCClassTable)) {
- OnigTypeCClassTable
- = onig_st_init_table_with_size(&type_type_cclass_hash, 10);
- if (IS_NULL(OnigTypeCClassTable)) {
- THREAD_ATOMIC_END;
- return ONIGERR_MEMORY;
- }
- }
- else {
- if (onig_st_lookup(OnigTypeCClassTable, (st_data_t )&key,
- (st_data_t* )np)) {
- THREAD_ATOMIC_END;
- break;
- }
- }
-
- *np = node_new_cclass_by_codepoint_range(not, sbr, mbr);
- if (IS_NULL(*np)) {
- THREAD_ATOMIC_END;
- return ONIGERR_MEMORY;
- }
-
- CCLASS_SET_SHARE(&(NCCLASS(*np)));
- new_key = (type_cclass_key* )xmalloc(sizeof(type_cclass_key));
- onig_st_add_direct(OnigTypeCClassTable, (st_data_t )new_key,
- (st_data_t )*np);
-
- THREAD_ATOMIC_END;
- }
- else {
-#endif
- ctype = parse_ctype_to_enc_ctype(tok->u.subtype, &not);
- *np = node_new_cclass();
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- cc = &(NCCLASS(*np));
- add_ctype_to_cc(cc, ctype, 0, env);
- if (not != 0) CCLASS_SET_NOT(cc);
-#ifdef USE_SHARED_CCLASS_TABLE
- }
-#endif
- }
- break;
-
- default:
- return ONIGERR_PARSER_BUG;
- break;
- }
- }
- break;
-
- case TK_CHAR_PROPERTY:
- r = parse_char_property(np, tok, src, end, env);
- if (r != 0) return r;
- break;
-
- case TK_CC_OPEN:
- {
- CClassNode* cc;
-
- r = parse_char_class(np, tok, src, end, env);
- if (r != 0) return r;
-
- cc = &(NCCLASS(*np));
-
- if (IS_IGNORECASE(env->option)) {
- int i, n, in_cc;
- const OnigPairAmbigCodes* ccs;
- BitSetRef bs = cc->bs;
- OnigAmbigType amb;
-
- for (amb = 0x01; amb <= ONIGENC_AMBIGUOUS_MATCH_LIMIT; amb <<= 1) {
- if ((amb & env->ambig_flag) == 0) continue;
-
- n = ONIGENC_GET_ALL_PAIR_AMBIG_CODES(env->enc, amb, &ccs);
- for (i = 0; i < n; i++) {
- in_cc = onig_is_code_in_cc(env->enc, ccs[i].from, cc);
-
- if ((in_cc != 0 && !IS_CCLASS_NOT(cc)) ||
- (in_cc == 0 && IS_CCLASS_NOT(cc))) {
- if (ONIGENC_MBC_MINLEN(env->enc) > 1 ||
- ccs[i].from >= SINGLE_BYTE_SIZE) {
- /* if (cc->not) clear_not_flag_cclass(cc, env->enc); */
- add_code_range(&(cc->mbuf), env, ccs[i].to, ccs[i].to);
- }
- else {
- if (BITSET_AT(bs, ccs[i].from)) {
- /* /(?i:[^A-C])/.match("a") ==> fail. */
- BITSET_SET_BIT(bs, ccs[i].to);
- }
- if (BITSET_AT(bs, ccs[i].to)) {
- BITSET_SET_BIT(bs, ccs[i].from);
- }
- }
- }
- }
- }
- }
-
- if (IS_IGNORECASE(env->option) &&
- (env->ambig_flag & ONIGENC_AMBIGUOUS_MATCH_COMPOUND) != 0) {
- int res;
- Node *alt_root, *work;
-
- res = make_compound_alt_node_from_cc(env->ambig_flag, env->enc,
- cc, &alt_root);
- if (res < 0) return res;
- if (res > 0) {
- work = node_new_alt(*np, alt_root);
- if (IS_NULL(work)) {
- onig_node_free(alt_root);
- return ONIGERR_MEMORY;
- }
- *np = work;
- }
- }
- }
- break;
-
- case TK_ANYCHAR:
- *np = node_new_anychar();
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- break;
-
- case TK_ANYCHAR_ANYTIME:
- *np = node_new_anychar();
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- qn = node_new_qualifier(0, REPEAT_INFINITE, 0);
- CHECK_NULL_RETURN_VAL(qn, ONIGERR_MEMORY);
- NQUALIFIER(qn).target = *np;
- *np = qn;
- break;
-
- case TK_BACKREF:
- len = tok->u.backref.num;
- *np = node_new_backref(len,
- (len > 1 ? tok->u.backref.refs : &(tok->u.backref.ref1)),
- tok->u.backref.by_name,
-#ifdef USE_BACKREF_AT_LEVEL
- tok->u.backref.exist_level,
- tok->u.backref.level,
-#endif
- env);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- break;
-
-#ifdef USE_SUBEXP_CALL
- case TK_CALL:
- *np = node_new_call(tok->u.call.name, tok->u.call.name_end);
- CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
- env->num_call++;
- break;
-#endif
-
- case TK_ANCHOR:
- *np = onig_node_new_anchor(tok->u.anchor);
- break;
-
- case TK_OP_REPEAT:
- case TK_INTERVAL:
- if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS)) {
- if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS))
- return ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED;
- else
- *np = node_new_empty();
- }
- else {
- goto tk_byte;
- }
- break;
-
- default:
- return ONIGERR_PARSER_BUG;
- break;
- }
-
- {
- targetp = np;
-
- re_entry:
- r = fetch_token(tok, src, end, env);
- if (r < 0) return r;
-
- repeat:
- if (r == TK_OP_REPEAT || r == TK_INTERVAL) {
- if (is_invalid_qualifier_target(*targetp))
- return ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID;
-
- qn = node_new_qualifier(tok->u.repeat.lower, tok->u.repeat.upper,
- (r == TK_INTERVAL ? 1 : 0));
- CHECK_NULL_RETURN_VAL(qn, ONIGERR_MEMORY);
- NQUALIFIER(qn).greedy = tok->u.repeat.greedy;
- r = set_qualifier(qn, *targetp, group, env);
- if (r < 0) return r;
-
- if (tok->u.repeat.possessive != 0) {
- Node* en;
- en = node_new_effect(EFFECT_STOP_BACKTRACK);
- CHECK_NULL_RETURN_VAL(en, ONIGERR_MEMORY);
- NEFFECT(en).target = qn;
- qn = en;
- }
-
- if (r == 0) {
- *targetp = qn;
- }
- else if (r == 2) { /* split case: /abc+/ */
- Node *tmp;
-
- *targetp = node_new_list(*targetp, NULL);
- CHECK_NULL_RETURN_VAL(*targetp, ONIGERR_MEMORY);
- tmp = NCONS(*targetp).right = node_new_list(qn, NULL);
- CHECK_NULL_RETURN_VAL(tmp, ONIGERR_MEMORY);
- targetp = &(NCONS(tmp).left);
- }
- goto re_entry;
- }
- }
-
- return r;
-}
-
-static int
-parse_branch(Node** top, OnigToken* tok, int term,
- UChar** src, UChar* end, ScanEnv* env)
-{
- int r;
- Node *node, **headp;
-
- *top = NULL;
- r = parse_exp(&node, tok, term, src, end, env);
- if (r < 0) return r;
-
- if (r == TK_EOT || r == term || r == TK_ALT) {
- *top = node;
- }
- else {
- *top = node_new_list(node, NULL);
- headp = &(NCONS(*top).right);
- while (r != TK_EOT && r != term && r != TK_ALT) {
- r = parse_exp(&node, tok, term, src, end, env);
- if (r < 0) return r;
-
- if (NTYPE(node) == N_LIST) {
- *headp = node;
- while (IS_NOT_NULL(NCONS(node).right)) node = NCONS(node).right;
- headp = &(NCONS(node).right);
- }
- else {
- *headp = node_new_list(node, NULL);
- headp = &(NCONS(*headp).right);
- }
- }
- }
-
- return r;
-}
-
-/* term_tok: TK_EOT or TK_SUBEXP_CLOSE */
-static int
-parse_subexp(Node** top, OnigToken* tok, int term,
- UChar** src, UChar* end, ScanEnv* env)
-{
- int r;
- Node *node, **headp;
-
- *top = NULL;
- r = parse_branch(&node, tok, term, src, end, env);
- if (r < 0) {
- onig_node_free(node);
- return r;
- }
-
- if (r == term) {
- *top = node;
- }
- else if (r == TK_ALT) {
- *top = node_new_alt(node, NULL);
- headp = &(NCONS(*top).right);
- while (r == TK_ALT) {
- r = fetch_token(tok, src, end, env);
- if (r < 0) return r;
- r = parse_branch(&node, tok, term, src, end, env);
- if (r < 0) return r;
-
- *headp = node_new_alt(node, NULL);
- headp = &(NCONS(*headp).right);
- }
-
- if (tok->type != term)
- goto err;
- }
- else {
- err:
- if (term == TK_SUBEXP_CLOSE)
- return ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS;
- else
- return ONIGERR_PARSER_BUG;
- }
-
- return r;
-}
-
-static int
-parse_regexp(Node** top, UChar** src, UChar* end, ScanEnv* env)
-{
- int r;
- OnigToken tok;
-
- r = fetch_token(&tok, src, end, env);
- if (r < 0) return r;
- r = parse_subexp(top, &tok, TK_EOT, src, end, env);
- if (r < 0) return r;
- return 0;
-}
-
-extern int
-onig_parse_make_tree(Node** root, const UChar* pattern, const UChar* end, regex_t* reg,
- ScanEnv* env)
-{
- int r;
- UChar* p;
-
-#ifdef USE_NAMED_GROUP
- names_clear(reg);
-#endif
-
- scan_env_clear(env);
- env->option = reg->options;
- env->ambig_flag = reg->ambig_flag;
- env->enc = reg->enc;
- env->syntax = reg->syntax;
- env->pattern = (UChar* )pattern;
- env->pattern_end = (UChar* )end;
- env->reg = reg;
-
- *root = NULL;
- p = (UChar* )pattern;
- r = parse_regexp(root, &p, (UChar* )end, env);
- reg->num_mem = env->num_mem;
- return r;
-}
-
-extern void
-onig_scan_env_set_error_string(ScanEnv* env, int ecode,
- UChar* arg, UChar* arg_end)
-{
- env->error = arg;
- env->error_end = arg_end;
-}
diff --git a/regparse.h b/regparse.h
deleted file mode 100644
index ca62dddf7e..0000000000
--- a/regparse.h
+++ /dev/null
@@ -1,328 +0,0 @@
-#ifndef REGPARSE_H
-#define REGPARSE_H
-/**********************************************************************
- regparse.h - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "regint.h"
-
-/* node type */
-#define N_STRING (1<< 0)
-#define N_CCLASS (1<< 1)
-#define N_CTYPE (1<< 2)
-#define N_ANYCHAR (1<< 3)
-#define N_BACKREF (1<< 4)
-#define N_QUALIFIER (1<< 5)
-#define N_EFFECT (1<< 6)
-#define N_ANCHOR (1<< 7)
-#define N_LIST (1<< 8)
-#define N_ALT (1<< 9)
-#define N_CALL (1<<10)
-
-#define IS_NODE_TYPE_SIMPLE(type) \
- (((type) & (N_STRING | N_CCLASS | N_CTYPE | N_ANYCHAR | N_BACKREF)) != 0)
-
-#define NTYPE(node) ((node)->type)
-#define NCONS(node) ((node)->u.cons)
-#define NSTRING(node) ((node)->u.str)
-#define NCCLASS(node) ((node)->u.cclass)
-#define NCTYPE(node) ((node)->u.ctype)
-#define NQUALIFIER(node) ((node)->u.qualifier)
-#define NANCHOR(node) ((node)->u.anchor)
-#define NBACKREF(node) ((node)->u.backref)
-#define NEFFECT(node) ((node)->u.effect)
-#define NCALL(node) ((node)->u.call)
-
-#define CTYPE_WORD (1<<0)
-#define CTYPE_NOT_WORD (1<<1)
-#define CTYPE_WHITE_SPACE (1<<2)
-#define CTYPE_NOT_WHITE_SPACE (1<<3)
-#define CTYPE_DIGIT (1<<4)
-#define CTYPE_NOT_DIGIT (1<<5)
-#define CTYPE_XDIGIT (1<<6)
-#define CTYPE_NOT_XDIGIT (1<<7)
-
-#define ANCHOR_ANYCHAR_STAR_MASK (ANCHOR_ANYCHAR_STAR | ANCHOR_ANYCHAR_STAR_ML)
-#define ANCHOR_END_BUF_MASK (ANCHOR_END_BUF | ANCHOR_SEMI_END_BUF)
-
-#define EFFECT_MEMORY (1<<0)
-#define EFFECT_OPTION (1<<1)
-#define EFFECT_STOP_BACKTRACK (1<<2)
-
-#define NODE_STR_MARGIN 16
-#define NODE_STR_BUF_SIZE 24 /* sizeof(CClassNode) - sizeof(int)*4 */
-#define NODE_BACKREFS_SIZE 6
-
-#define NSTR_RAW (1<<0) /* by backslashed number */
-#define NSTR_AMBIG (1<<1)
-#define NSTR_AMBIG_REDUCE (1<<2)
-
-#define NSTRING_LEN(node) ((node)->u.str.end - (node)->u.str.s)
-#define NSTRING_SET_RAW(node) (node)->u.str.flag |= NSTR_RAW
-#define NSTRING_CLEAR_RAW(node) (node)->u.str.flag &= ~NSTR_RAW
-#define NSTRING_SET_AMBIG(node) (node)->u.str.flag |= NSTR_AMBIG
-#define NSTRING_SET_AMBIG_REDUCE(node) (node)->u.str.flag |= NSTR_AMBIG_REDUCE
-#define NSTRING_IS_RAW(node) (((node)->u.str.flag & NSTR_RAW) != 0)
-#define NSTRING_IS_AMBIG(node) (((node)->u.str.flag & NSTR_AMBIG) != 0)
-#define NSTRING_IS_AMBIG_REDUCE(node) \
- (((node)->u.str.flag & NSTR_AMBIG_REDUCE) != 0)
-
-#define BACKREFS_P(br) \
- (IS_NOT_NULL((br)->back_dynamic) ? (br)->back_dynamic : (br)->back_static);
-
-#define NQ_TARGET_ISNOT_EMPTY 0
-#define NQ_TARGET_IS_EMPTY 1
-#define NQ_TARGET_IS_EMPTY_MEM 2
-#define NQ_TARGET_IS_EMPTY_REC 3
-
-
-typedef struct {
- UChar* s;
- UChar* end;
- unsigned int flag;
- int capa; /* (allocated size - 1) or 0: use buf[] */
- UChar buf[NODE_STR_BUF_SIZE];
-} StrNode;
-
-/* move to regint.h */
-#if 0
-typedef struct {
- int flags;
- BitSet bs;
- BBuf* mbuf; /* multi-byte info or NULL */
-} CClassNode;
-#endif
-
-typedef struct {
- int state;
- struct _Node* target;
- int lower;
- int upper;
- int greedy;
- int target_empty_info;
- struct _Node* head_exact;
- struct _Node* next_head_exact;
- int is_refered; /* include called node. don't eliminate even if {0} */
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- int comb_exp_check_num; /* 1,2,3...: check, 0: no check */
-#endif
-} QualifierNode;
-
-/* status bits */
-#define NST_MIN_FIXED (1<<0)
-#define NST_MAX_FIXED (1<<1)
-#define NST_CLEN_FIXED (1<<2)
-#define NST_MARK1 (1<<3)
-#define NST_MARK2 (1<<4)
-#define NST_MEM_BACKREFED (1<<5)
-#define NST_STOP_BT_SIMPLE_REPEAT (1<<6)
-#define NST_RECURSION (1<<7)
-#define NST_CALLED (1<<8)
-#define NST_ADDR_FIXED (1<<9)
-#define NST_NAMED_GROUP (1<<10)
-#define NST_NAME_REF (1<<11)
-#define NST_IN_REPEAT (1<<12) /* STK_REPEAT is nested in stack. */
-#define NST_NEST_LEVEL (1<<13)
-#define NST_BY_NUMBER (1<<14) /* {n,m} */
-
-#define SET_EFFECT_STATUS(node,f) (node)->u.effect.state |= (f)
-#define CLEAR_EFFECT_STATUS(node,f) (node)->u.effect.state &= ~(f)
-
-#define IS_EFFECT_CALLED(en) (((en)->state & NST_CALLED) != 0)
-#define IS_EFFECT_ADDR_FIXED(en) (((en)->state & NST_ADDR_FIXED) != 0)
-#define IS_EFFECT_RECURSION(en) (((en)->state & NST_RECURSION) != 0)
-#define IS_EFFECT_MARK1(en) (((en)->state & NST_MARK1) != 0)
-#define IS_EFFECT_MARK2(en) (((en)->state & NST_MARK2) != 0)
-#define IS_EFFECT_MIN_FIXED(en) (((en)->state & NST_MIN_FIXED) != 0)
-#define IS_EFFECT_MAX_FIXED(en) (((en)->state & NST_MAX_FIXED) != 0)
-#define IS_EFFECT_CLEN_FIXED(en) (((en)->state & NST_CLEN_FIXED) != 0)
-#define IS_EFFECT_STOP_BT_SIMPLE_REPEAT(en) \
- (((en)->state & NST_STOP_BT_SIMPLE_REPEAT) != 0)
-#define IS_EFFECT_NAMED_GROUP(en) (((en)->state & NST_NAMED_GROUP) != 0)
-
-#define SET_CALL_RECURSION(node) (node)->u.call.state |= NST_RECURSION
-#define IS_CALL_RECURSION(cn) (((cn)->state & NST_RECURSION) != 0)
-#define IS_CALL_NAME_REF(cn) (((cn)->state & NST_NAME_REF) != 0)
-#define IS_BACKREF_NAME_REF(bn) (((bn)->state & NST_NAME_REF) != 0)
-#define IS_BACKREF_NEST_LEVEL(bn) (((bn)->state & NST_NEST_LEVEL) != 0)
-#define IS_QUALIFIER_IN_REPEAT(qn) (((qn)->state & NST_IN_REPEAT) != 0)
-#define IS_QUALIFIER_BY_NUMBER(qn) (((qn)->state & NST_BY_NUMBER) != 0)
-
-typedef struct {
- int state;
- int type;
- int regnum;
- OnigOptionType option;
- struct _Node* target;
- AbsAddrType call_addr;
- /* for multiple call reference */
- OnigDistance min_len; /* min length (byte) */
- OnigDistance max_len; /* max length (byte) */
- int char_len; /* character length */
- int opt_count; /* referenced count in optimize_node_left() */
-} EffectNode;
-
-#define CALLNODE_REFNUM_UNDEF -1
-
-#ifdef USE_SUBEXP_CALL
-
-typedef struct {
- int offset;
- struct _Node* target;
-} UnsetAddr;
-
-typedef struct {
- int num;
- int alloc;
- UnsetAddr* us;
-} UnsetAddrList;
-
-typedef struct {
- int state;
- int ref_num;
- UChar* name;
- UChar* name_end;
- struct _Node* target; /* EffectNode : EFFECT_MEMORY */
- UnsetAddrList* unset_addr_list;
-} CallNode;
-
-#endif
-
-typedef struct {
- int state;
- int back_num;
- int back_static[NODE_BACKREFS_SIZE];
- int* back_dynamic;
- int nest_level;
-} BackrefNode;
-
-typedef struct {
- int type;
- struct _Node* target;
- int char_len;
-} AnchorNode;
-
-typedef struct _Node {
- int type;
- union {
- StrNode str;
- CClassNode cclass;
- QualifierNode qualifier;
- EffectNode effect;
-#ifdef USE_SUBEXP_CALL
- CallNode call;
-#endif
- BackrefNode backref;
- AnchorNode anchor;
- struct {
- struct _Node* left;
- struct _Node* right;
- } cons;
- struct {
- int type;
- } ctype;
- } u;
-} Node;
-
-#define NULL_NODE ((Node* )0)
-
-#define SCANENV_MEMNODES_SIZE 8
-#define SCANENV_MEM_NODES(senv) \
- (IS_NOT_NULL((senv)->mem_nodes_dynamic) ? \
- (senv)->mem_nodes_dynamic : (senv)->mem_nodes_static)
-
-typedef struct {
- OnigOptionType option;
- OnigAmbigType ambig_flag;
- OnigEncoding enc;
- OnigSyntaxType* syntax;
- BitStatusType capture_history;
- BitStatusType bt_mem_start;
- BitStatusType bt_mem_end;
- BitStatusType backrefed_mem;
- UChar* pattern;
- UChar* pattern_end;
- UChar* error;
- UChar* error_end;
- regex_t* reg; /* for reg->names only */
- int num_call;
-#ifdef USE_SUBEXP_CALL
- UnsetAddrList* unset_addr_list;
-#endif
- int num_mem;
-#ifdef USE_NAMED_GROUP
- int num_named;
-#endif
- int mem_alloc;
- Node* mem_nodes_static[SCANENV_MEMNODES_SIZE];
- Node** mem_nodes_dynamic;
-#ifdef USE_COMBINATION_EXPLOSION_CHECK
- int num_comb_exp_check;
- int comb_exp_max_regnum;
- int curr_max_regnum;
- int has_recursion;
-#endif
-} ScanEnv;
-
-
-#define IS_SYNTAX_OP(syn, opm) (((syn)->op & (opm)) != 0)
-#define IS_SYNTAX_OP2(syn, opm) (((syn)->op2 & (opm)) != 0)
-#define IS_SYNTAX_BV(syn, bvm) (((syn)->behavior & (bvm)) != 0)
-
-
-#ifdef USE_NAMED_GROUP
-typedef struct {
- int new_val;
-} GroupNumRemap;
-
-extern int onig_renumber_name_table P_((regex_t* reg, GroupNumRemap* map));
-#endif
-
-extern int onig_strncmp P_((const UChar* s1, const UChar* s2, int n));
-extern void onig_scan_env_set_error_string P_((ScanEnv* env, int ecode, UChar* arg, UChar* arg_end));
-extern int onig_scan_unsigned_number P_((UChar** src, const UChar* end, OnigEncoding enc));
-extern void onig_reduce_nested_qualifier P_((Node* pnode, Node* cnode));
-extern void onig_node_conv_to_str_node P_((Node* node, int raw));
-extern int onig_node_str_cat P_((Node* node, const UChar* s, const UChar* end));
-extern void onig_node_free P_((Node* node));
-extern Node* onig_node_new_effect P_((int type));
-extern Node* onig_node_new_anchor P_((int type));
-extern Node* onig_node_new_str P_((const UChar* s, const UChar* end));
-extern Node* onig_node_new_list P_((Node* left, Node* right));
-extern void onig_node_str_clear P_((Node* node));
-extern int onig_free_node_list();
-extern int onig_names_free P_((regex_t* reg));
-extern int onig_parse_make_tree P_((Node** root, const UChar* pattern, const UChar* end, regex_t* reg, ScanEnv* env));
-
-#ifdef ONIG_DEBUG
-#ifdef USE_NAMED_GROUP
-extern int onig_print_names(FILE*, regex_t*);
-#endif
-#endif
-
-#endif /* REGPARSE_H */
diff --git a/ruby.c b/ruby.c
index 300b63450e..6fbb6d2dc0 100644
--- a/ruby.c
+++ b/ruby.c
@@ -12,9 +12,12 @@
**********************************************************************/
-#ifdef __CYGWIN__
+#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"
@@ -33,11 +36,11 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#ifdef HAVE_SYS_PARAM_H
-# include <sys/param.h>
-#endif
-#ifndef MAXPATHLEN
-# define MAXPATHLEN 1024
+
+#ifndef HAVE_STRING_H
+char *strchr _((const char*,const char));
+char *strrchr _((const char*,const char));
+char *strstr _((const char*,const char*));
#endif
#include "util.h"
@@ -54,24 +57,27 @@ extern int ruby_yydebug;
char *ruby_inplace_mode = Qfalse;
-static void load_stdin(void);
-static void load_file(const char *, int);
-static void forbid_setid(const char *);
+static void load_stdin _((void));
+static void load_file _((const char *, int));
+static void forbid_setid _((const char *));
static VALUE do_loop = Qfalse, do_print = Qfalse;
static VALUE do_check = Qfalse, do_line = Qfalse;
static VALUE do_split = Qfalse;
+static char *script;
+
static int origargc;
static char **origargv;
static void
-usage(const char *name)
+usage(name)
+ const char *name;
{
/* This message really ought to be max 23 lines.
* Removed -h because the user already knows that option. Others? */
- static const char *usage_msg[] = {
+ static char *usage_msg[] = {
"-0[octal] specify record separator (\\0, if no argument)",
"-a autosplit mode with -n or -p (splits $_ into $F)",
"-c check syntax only",
@@ -97,7 +103,7 @@ usage(const char *name)
"--version print the version",
NULL
};
- const char **p = usage_msg;
+ char **p = usage_msg;
printf("Usage: %s [switches] [--] [programfile] [arguments]\n", name);
while (*p)
@@ -106,155 +112,148 @@ NULL
extern VALUE rb_load_path;
-#define STATIC_FILE_LENGTH 255
+#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
#if defined _WIN32 || defined __CYGWIN__ || defined __DJGPP__
-static char *
-rubylib_mangle(const char *s, unsigned int l)
+static VALUE
+rubylib_mangled_path(const char *s, unsigned int l)
{
static char *newp, *oldp;
static int newl, oldl, notfound;
- static char newsub[STATIC_FILE_LENGTH+1];
+ char *ptr;
+ VALUE ret;
if (!newp && !notfound) {
newp = getenv("RUBYLIB_PREFIX");
if (newp) {
- char *s;
-
- oldp = newp;
+ oldp = newp = strdup(newp);
while (*newp && !ISSPACE(*newp) && *newp != ';') {
- newp++; oldl++; /* Skip digits. */
+ newp = CharNext(newp); /* Skip digits. */
}
+ oldl = newp - oldp;
while (*newp && (ISSPACE(*newp) || *newp == ';')) {
- newp++; /* Skip whitespace. */
+ newp = CharNext(newp); /* Skip whitespace. */
}
newl = strlen(newp);
- if (newl == 0 || oldl == 0 || newl > STATIC_FILE_LENGTH) {
+ if (newl == 0 || oldl == 0) {
rb_fatal("malformed RUBYLIB_PREFIX");
}
- strcpy(newsub, newp);
- s = newsub;
- while (*s) {
- if (*s == '\\') *s = '/';
- s++;
- }
+ translate_char(newp, '\\', '/');
}
else {
notfound = 1;
}
}
- if (l == 0) {
- l = strlen(s);
- }
if (!newp || l < oldl || strncasecmp(oldp, s, oldl) != 0) {
- static char ret[STATIC_FILE_LENGTH+1];
- strncpy(ret, s, l);
- ret[l] = 0;
- return ret;
+ return rb_str_new(s, l);
}
- 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;
+ 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));
}
-#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(s, l) rb_str_new((s), (l))
-#define rubylib_mangled_path2(s) rb_str_new2(s)
+#define rubylib_mangled_path rb_str_new
+#define rubylib_mangled_path2 rb_str_new2
#endif
-void
-ruby_push_include(const char *path, VALUE (*filter) (VALUE))
+static void push_include _((const char *path));
+
+static void
+push_include(path)
+ const char *path;
{
const char sep = PATH_SEP_CHAR;
+ const char *p, *s;
- if (path == 0) return;
-#if defined(__CYGWIN__)
- {
- char rubylib[FILENAME_MAX];
- conv_to_posix_path(path, rubylib, FILENAME_MAX);
- path = rubylib;
+ 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;
}
-#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, (*filter)(rubylib_mangled_path(p, (int)(s-p))));
- p = s + 1;
+}
+
+#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);
}
else {
- rb_ary_push(ary, (*filter)(rubylib_mangled_path2(p)));
- break;
+ rb_str_resize(buf, len);
+ p = strncpy(RSTRING_PTR(buf), p, len);
}
}
- rb_ary_concat(rb_load_path, ary);
- }
- else {
- rb_ary_push(rb_load_path, (*filter)(rubylib_mangled_path2(path)));
+ if (cygwin_conv_to_posix_path(p, rubylib) == 0)
+ p = rubylib;
+ push_include(p);
+ if (!*s) break;
+ p = s + 1;
}
}
-static VALUE
-identical_path(VALUE path)
-{
- return path;
-}
-
-void
-ruby_incpush(const char *path)
-{
- ruby_push_include(path, identical_path);
-}
-
-static VALUE
-expand_include_path(VALUE path)
-{
- char *p = RSTRING_PTR(path);
- if (!p) return path;
- if (*p == '.' && p[1] == '/') return path;
- return rb_file_expand_path(path, Qnil);
-}
-
+#define push_include push_include_cygwin
+#endif
-void
-ruby_incpush_expand(const char *path)
+void
+ruby_incpush(path)
+ const char *path;
{
- ruby_push_include(path, expand_include_path);
+ if (path == 0)
+ return;
+ push_include(path);
}
#if defined DOSISH || defined __CYGWIN__
#define LOAD_RELATIVE 1
#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;
-#ifdef CharNext /* defined as CharNext[AW] on Windows. */
- p = CharNext(p);
-#else
- p += mblen(p, RUBY_MBCHAR_MAXSIZE);
-#endif
- }
-}
-#endif
-
void
-ruby_init_loadpath(void)
+ruby_init_loadpath()
{
#if defined LOAD_RELATIVE
- char libpath[MAXPATHLEN+1];
+ char libpath[FILENAME_MAX+1];
char *p;
int rest;
#if defined _WIN32 || defined __CYGWIN__
@@ -269,22 +268,28 @@ ruby_init_loadpath(void)
GetModuleFileName(libruby, libpath, sizeof libpath);
#elif defined(DJGPP)
extern char *__dos_argv0;
- strncpy(libpath, __dos_argv0, sizeof(libpath) - 1);
+ strncpy(libpath, __dos_argv0, FILENAME_MAX);
#elif defined(__human68k__)
extern char **_argv;
- strncpy(libpath, _argv[0], sizeof(libpath) - 1);
+ strncpy(libpath, _argv[0], FILENAME_MAX);
#elif defined(__EMX__)
- _execname(libpath, sizeof(libpath) - 1);
+ _execname(libpath, FILENAME_MAX);
#endif
- libpath[sizeof(libpath) - 1] = '\0';
-#if defined DOSISH || defined __CYGWIN__
+ libpath[FILENAME_MAX] = '\0';
+#if defined DOSISH
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;
}
@@ -294,36 +299,37 @@ ruby_init_loadpath(void)
p = libpath + 1;
}
- rest = sizeof(libpath) - 1 - (p - libpath);
+ rest = FILENAME_MAX - (p - libpath);
#define RUBY_RELATIVE(path) (strncpy(p, (path), rest), libpath)
#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
- ruby_incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
+ incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
#endif
- ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));
+ incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));
#ifdef RUBY_SITE_THIN_ARCHLIB
- ruby_incpush(RUBY_RELATIVE(RUBY_SITE_THIN_ARCHLIB));
+ incpush(RUBY_RELATIVE(RUBY_SITE_THIN_ARCHLIB));
#endif
- ruby_incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB));
- ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB));
+ incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB));
+ incpush(RUBY_RELATIVE(RUBY_SITE_LIB));
- ruby_incpush(RUBY_RELATIVE(RUBY_LIB));
+ incpush(RUBY_RELATIVE(RUBY_LIB));
#ifdef RUBY_THIN_ARCHLIB
- ruby_incpush(RUBY_RELATIVE(RUBY_THIN_ARCHLIB));
+ incpush(RUBY_RELATIVE(RUBY_THIN_ARCHLIB));
#endif
- ruby_incpush(RUBY_RELATIVE(RUBY_ARCHLIB));
+ incpush(RUBY_RELATIVE(RUBY_ARCHLIB));
if (rb_safe_level() == 0) {
- ruby_incpush(".");
+ incpush(".");
}
}
@@ -334,7 +340,8 @@ struct req_list {
static struct req_list req_list_head, *req_list_last = &req_list_head;
static void
-add_modules(const char *mod)
+add_modules(mod)
+ const char *mod;
{
struct req_list *list;
@@ -346,22 +353,24 @@ add_modules(const char *mod)
req_list_last = list;
}
-extern void Init_ext(void);
+extern void Init_ext _((void));
static void
-require_libraries(void)
+require_libraries()
{
extern NODE *ruby_eval_tree;
+ extern NODE *ruby_eval_tree_begin;
NODE *save[3];
struct req_list *list = req_list_head.next;
struct req_list *tmp;
save[0] = ruby_eval_tree;
- save[1] = NEW_BEGIN(0);
- ruby_eval_tree = 0;
+ save[1] = ruby_eval_tree_begin;
+ save[2] = NEW_NEWLINE(0);
+ ruby_eval_tree = ruby_eval_tree_begin = 0;
ruby_current_node = 0;
Init_ext(); /* should be called here for some reason :-( */
- ruby_current_node = save[1];
+ ruby_current_node = save[2];
ruby_set_current_source();
req_list_last = 0;
while (list) {
@@ -374,24 +383,25 @@ require_libraries(void)
free(list->name);
free(list);
list = tmp;
- ruby_current_node = save[1];
+ ruby_current_node = save[2];
ruby_set_current_source();
}
req_list_head.next = 0;
ruby_eval_tree = save[0];
- rb_gc_force_recycle((VALUE)save[1]);
+ ruby_eval_tree_begin = save[1];
+ rb_gc_force_recycle((VALUE)save[2]);
ruby_current_node = 0;
}
static void
-process_sflag(void)
+process_sflag()
{
if (sflag) {
long n;
VALUE *args;
- n = RARRAY_LEN(rb_argv);
- args = RARRAY_PTR(rb_argv);
+ n = RARRAY(rb_argv)->len;
+ args = RARRAY(rb_argv)->ptr;
while (n > 0) {
VALUE v = *args++;
char *s = StringValuePtr(v);
@@ -434,7 +444,7 @@ process_sflag(void)
}
rb_gv_set(s, v);
}
- n = RARRAY_LEN(rb_argv) - n;
+ n = RARRAY(rb_argv)->len - n;
while (n--) {
rb_ary_shift(rb_argv);
}
@@ -442,13 +452,14 @@ process_sflag(void)
sflag = 0;
}
-static void proc_options(int argc, char **argv);
+static void proc_options _((int argc, char **argv));
static char*
-moreswitches(const char *s)
+moreswitches(s)
+ char *s;
{
int argc; char *argv[3];
- const char *p = s;
+ char *p = s;
argc = 2; argv[0] = argv[2] = 0;
while (*s && !ISSPACE(*s))
@@ -460,18 +471,17 @@ moreswitches(const char *s)
proc_options(argc, argv);
while (*s && ISSPACE(*s))
s++;
- return (char *)s;
+ return s;
}
-NODE *ruby_eval_tree;
-
static void
-proc_options(int argc, char **argv)
+proc_options(argc, argv)
+ int argc;
+ char **argv;
{
char *argv0 = argv[0];
int do_search;
- const char *s;
- char *script = 0;
+ char *s;
NODE *volatile script_node = 0;
int version = 0;
@@ -661,9 +671,9 @@ proc_options(int argc, char **argv)
case 'I':
forbid_setid("-I");
if (*++s)
- ruby_incpush_expand(s);
+ ruby_incpush(s);
else if (argv[1]) {
- ruby_incpush_expand(argv[1]);
+ ruby_incpush(argv[1]);
argc--,argv++;
}
break;
@@ -765,7 +775,7 @@ proc_options(int argc, char **argv)
}
}
if (!*s) break;
- if (!strchr("IdvwrK", *s))
+ if (!strchr("IdvwWrK", *s))
rb_raise(rb_eRuntimeError, "illegal switch in RUBYOPT: -%c", *s);
s = moreswitches(s);
}
@@ -807,10 +817,9 @@ proc_options(int argc, char **argv)
}
if (!script) script = argv[0];
script = ruby_sourcefile = rb_source_filename(script);
- script_node = NEW_BEGIN(0);
+ script_node = NEW_NEWLINE(0);
}
#if defined DOSISH || defined __CYGWIN__
- /* assume that we can change argv[n] if never change its length. */
translate_char(script, '\\', '/');
#endif
argc--; argv++;
@@ -825,7 +834,7 @@ proc_options(int argc, char **argv)
ruby_sourcefile = rb_source_filename(argv0);
if (e_script) {
require_libraries();
- ruby_eval_tree = rb_compile_string(script, e_script, 1);
+ rb_compile_string(script, e_script, 1);
}
else if (strlen(script) == 1 && script[0] == '-') {
load_stdin();
@@ -843,11 +852,14 @@ proc_options(int argc, char **argv)
}
}
+extern int ruby__end__seen;
+
static void
-load_file(const char *fname, int script)
+load_file(fname, script)
+ const char *fname;
+ int script;
{
extern VALUE rb_stdin;
- VALUE parser;
VALUE f;
int line_start = 1;
@@ -883,10 +895,10 @@ load_file(const char *fname, int script)
xflag = Qfalse;
while (!NIL_P(line = rb_io_gets(f))) {
line_start++;
- if (RSTRING_LEN(line) > 2
- && RSTRING_PTR(line)[0] == '#'
- && RSTRING_PTR(line)[1] == '!') {
- if ((p = strstr(RSTRING_PTR(line), "ruby")) != 0) {
+ if (RSTRING(line)->len > 2
+ && RSTRING(line)->ptr[0] == '#'
+ && RSTRING(line)->ptr[1] == '!') {
+ if ((p = strstr(RSTRING(line)->ptr, "ruby")) != 0) {
goto start_read;
}
}
@@ -896,18 +908,18 @@ load_file(const char *fname, int script)
c = rb_io_getc(f);
if (c == INT2FIX('#')) {
- c = rb_io_getc(f);
- if (c == INT2FIX('!')) {
- line = rb_io_gets(f);
- if (NIL_P(line)) return;
+ line = rb_io_gets(f);
+ if (NIL_P(line)) return;
+ line_start++;
- if ((p = strstr(RSTRING_PTR(line), "ruby")) == 0) {
+ if (RSTRING(line)->len > 2 && RSTRING(line)->ptr[0] == '!') {
+ if ((p = strstr(RSTRING(line)->ptr, "ruby")) == 0) {
/* not ruby script, kick the program */
char **argv;
char *path;
- char *pend = RSTRING_PTR(line) + RSTRING_LEN(line);
+ char *pend = RSTRING(line)->ptr + RSTRING(line)->len;
- p = RSTRING_PTR(line); /* skip `#!' */
+ p = RSTRING(line)->ptr + 1; /* skip `#!' */
if (pend[-1] == '\n') pend--; /* chomp line */
if (pend[-1] == '\r') pend--;
*pend = '\0';
@@ -935,24 +947,16 @@ load_file(const char *fname, int script)
start_read:
p += 4;
- RSTRING_PTR(line)[RSTRING_LEN(line)-1] = '\0';
- if (RSTRING_PTR(line)[RSTRING_LEN(line)-2] == '\r')
- RSTRING_PTR(line)[RSTRING_LEN(line)-2] = '\0';
+ RSTRING(line)->ptr[RSTRING(line)->len-1] = '\0';
+ if (RSTRING(line)->ptr[RSTRING(line)->len-2] == '\r')
+ RSTRING(line)->ptr[RSTRING(line)->len-2] = '\0';
if ((p = strstr(p, " -")) != 0) {
p++; /* skip space before `-' */
while (*p == '-') {
p = moreswitches(p+1);
}
}
-
- /* push back shebang for pragma may exist in next line */
- rb_io_ungetc(f, INT2FIX('\n'));
- rb_io_ungetc(f, INT2FIX('!'));
}
- else if (!NIL_P(c)) {
- rb_io_ungetc(f, c);
- }
- rb_io_ungetc(f, INT2FIX('#'));
}
else if (!NIL_P(c)) {
rb_io_ungetc(f, c);
@@ -960,24 +964,28 @@ load_file(const char *fname, int script)
require_libraries(); /* Why here? unnatural */
if (NIL_P(c)) return;
}
- parser = rb_parser_new();
- ruby_eval_tree = rb_parser_compile_file(parser, fname, f, line_start);
- if (script && rb_parser_end_seen_p(parser)) {
+ rb_compile_file(fname, f, line_start);
+ if (script && ruby__end__seen) {
rb_define_global_const("DATA", f);
}
else if (f != rb_stdin) {
rb_io_close(f);
}
+
+ if (ruby_parser_stack_on_heap()) {
+ rb_gc();
+ }
}
void
-rb_load_file(const char *fname)
+rb_load_file(fname)
+ const char *fname;
{
load_file(fname, 0);
}
static void
-load_stdin(void)
+load_stdin()
{
forbid_setid("program input from stdin");
load_file("-", 1);
@@ -1021,25 +1029,62 @@ 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(VALUE val, ID id)
+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;
+ static int len = 0;
#endif
if (origargv == 0) rb_raise(rb_eRuntimeError, "$0 not initialized");
StringValue(val);
- s = RSTRING_PTR(val);
- i = RSTRING_LEN(val);
+ s = RSTRING(val)->ptr;
+ i = RSTRING(val)->len;
#if defined(PSTAT_SETCMD)
if (i >= PST_CLEN) {
union pstun j;
j.pst_command = s;
i = PST_CLEN;
- RSTRING_LEN(val) = i;
+ RSTRING(val)->len = i;
*(s + i) = '\0';
pstat(PSTAT_SETCMD, j, PST_CLEN, 0, 0);
}
@@ -1048,33 +1093,13 @@ set_arg0(VALUE val, ID id)
j.pst_command = s;
pstat(PSTAT_SETCMD, j, i, 0, 0);
}
- rb_progname = rb_tainted_str_new(s, i);
+ progname = rb_tainted_str_new(s, i);
#elif defined(HAVE_SETPROCTITLE)
setproctitle("%.*s", (int)i, s);
- rb_progname = rb_tainted_str_new(s, i);
+ progname = rb_tainted_str_new(s, i);
#else
if (len == 0) {
- 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];
+ len = get_arglen(origargc, origargv);
}
if (i >= len) {
@@ -1084,17 +1109,21 @@ set_arg0(VALUE val, ID id)
s = origargv[0] + i;
*s = '\0';
if (++i < len) memset(s + 1, ' ', len - i);
- for (i = 1; i < origargc; i++)
- origargv[i] = s;
- rb_progname = rb_tainted_str_new2(origargv[0]);
+ 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]);
#endif
+ rb_progname = rb_obj_freeze(progname);
}
void
-ruby_script(const char *name)
+ruby_script(name)
+ const char *name;
{
if (name) {
- rb_progname = rb_tainted_str_new2(name);
+ rb_progname = rb_obj_freeze(rb_tainted_str_new2(name));
ruby_sourcefile = rb_source_filename(name);
}
}
@@ -1102,7 +1131,7 @@ ruby_script(const char *name)
static int uid, euid, gid, egid;
static void
-init_ids(void)
+init_ids()
{
uid = (int)getuid();
euid = (int)geteuid();
@@ -1118,7 +1147,8 @@ init_ids(void)
}
static void
-forbid_setid(const char *s)
+forbid_setid(s)
+ const char *s;
{
if (euid != uid)
rb_raise(rb_eSecurityError, "no %s allowed while running setuid", s);
@@ -1129,22 +1159,16 @@ forbid_setid(const char *s)
}
static void
-verbose_setter(VALUE val, ID id, VALUE *variable)
+verbose_setter(val, id, variable)
+ VALUE val;
+ ID id;
+ VALUE *variable;
{
ruby_verbose = RTEST(val) ? Qtrue : val;
}
-static VALUE
-opt_W_getter(VALUE val, ID id)
-{
- if (ruby_verbose == Qnil) return INT2FIX(0);
- if (ruby_verbose == Qfalse) return INT2FIX(1);
- if (ruby_verbose == Qtrue) return INT2FIX(2);
- return Qnil; /* not reached */
-}
-
void
-ruby_prog_init(void)
+ruby_prog_init()
{
init_ids();
@@ -1152,7 +1176,6 @@ ruby_prog_init(void)
rb_define_hooked_variable("$VERBOSE", &ruby_verbose, 0, verbose_setter);
rb_define_hooked_variable("$-v", &ruby_verbose, 0, verbose_setter);
rb_define_hooked_variable("$-w", &ruby_verbose, 0, verbose_setter);
- rb_define_virtual_variable("$-W", opt_W_getter, 0);
rb_define_variable("$DEBUG", &ruby_debug);
rb_define_variable("$-d", &ruby_debug);
rb_define_readonly_variable("$-p", &do_print);
@@ -1178,7 +1201,9 @@ ruby_prog_init(void)
}
void
-ruby_set_argv(int argc, char **argv)
+ruby_set_argv(argc, argv)
+ int argc;
+ char **argv;
{
int i;
@@ -1195,11 +1220,10 @@ ruby_set_argv(int argc, char **argv)
}
}
-NODE *rb_parser_append_print(NODE*);
-NODE *rb_parser_while_loop(NODE*, int, int);
-
void
-ruby_process_options(int argc, char **argv)
+ruby_process_options(argc, argv)
+ int argc;
+ char **argv;
{
origargc = argc; origargv = argv;
@@ -1216,9 +1240,9 @@ ruby_process_options(int argc, char **argv)
exit(0);
}
if (do_print) {
- ruby_eval_tree = rb_parser_append_print(ruby_eval_tree);
+ rb_parser_append_print();
}
if (do_loop) {
- ruby_eval_tree = rb_parser_while_loop(ruby_eval_tree, do_line, do_split);
+ rb_parser_while_loop(do_line, do_split);
}
}
diff --git a/ruby.h b/ruby.h
index 3ec19e1a91..2701f0dc77 100644
--- a/ruby.h
+++ b/ruby.h
@@ -30,19 +30,11 @@ extern "C" {
#ifndef NORETURN
# define NORETURN(x) x
#endif
-#ifndef DEPRECATED
-# define DEPRECATED(x) x
-#endif
#ifndef NOINLINE
# define NOINLINE(x) x
#endif
-#ifdef __GNUC__
-#define PRINTF_ARGS(decl, string_index, first_to_check) \
- decl __attribute__((format(printf, string_index, first_to_check)))
-#else
-#define PRINTF_ARGS(decl, string_index, first_to_check) decl
-#endif
+#include "defines.h"
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
@@ -61,8 +53,6 @@ extern "C" {
#include <stddef.h>
#include <stdio.h>
-#include "defines.h"
-
/* need to include <ctype.h> to use these macros */
#ifndef ISPRINT
#define ISASCII(c) isascii((int)(unsigned char)(c))
@@ -90,22 +80,13 @@ extern "C" {
# define alloca __alloca
#endif
-#if SIZEOF_LONG == SIZEOF_VOIDP
+#if SIZEOF_LONG != SIZEOF_VOIDP
+# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
+#else
typedef unsigned long VALUE;
typedef unsigned long ID;
-# define SIGNED_VALUE long
-# define SIZEOF_VALUE SIZEOF_LONG
-#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
-typedef unsigned LONG_LONG VALUE;
-typedef unsigned LONG_LONG ID;
-# define SIGNED_VALUE LONG_LONG
-# define LONG_LONG_VALUE 1
-# define SIZEOF_VALUE SIZEOF_LONG_LONG
-#else
-# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
#endif
-
#ifdef __STDC__
# include <limits.h>
#else
@@ -151,55 +132,51 @@ typedef unsigned LONG_LONG ID;
# endif
#endif
-#ifdef LONG_LONG_VALUE
-# define FIXNUM_MAX (LLONG_MAX>>1)
-# define FIXNUM_MIN RSHIFT((LONG_LONG)LLONG_MIN,1)
-#else
-# define FIXNUM_MAX (LONG_MAX>>1)
-# define FIXNUM_MIN RSHIFT((long)LONG_MIN,1)
-#endif
+#define FIXNUM_MAX (LONG_MAX>>1)
+#define FIXNUM_MIN RSHIFT((long)LONG_MIN,1)
#define FIXNUM_FLAG 0x01
-#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
+#define INT2FIX(i) ((VALUE)(((long)(i))<<1 | FIXNUM_FLAG))
#define LONG2FIX(i) INT2FIX(i)
#define rb_fix_new(v) INT2FIX(v)
-VALUE rb_int2inum(SIGNED_VALUE);
+VALUE rb_int2inum _((long));
#define INT2NUM(v) rb_int2inum(v)
#define LONG2NUM(v) INT2NUM(v)
#define rb_int_new(v) rb_int2inum(v)
-VALUE rb_uint2inum(VALUE);
+VALUE rb_uint2inum _((unsigned long));
#define UINT2NUM(v) rb_uint2inum(v)
#define ULONG2NUM(v) UINT2NUM(v)
#define rb_uint_new(v) rb_uint2inum(v)
#ifdef HAVE_LONG_LONG
-VALUE rb_ll2inum(LONG_LONG);
+VALUE rb_ll2inum _((LONG_LONG));
#define LL2NUM(v) rb_ll2inum(v)
-VALUE rb_ull2inum(unsigned LONG_LONG);
+VALUE rb_ull2inum _((unsigned LONG_LONG));
#define ULL2NUM(v) rb_ull2inum(v)
#endif
#if SIZEOF_OFF_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
# define OFFT2NUM(v) LL2NUM(v)
+#elif SIZEOF_OFF_T == SIZEOF_LONG
+# define OFFT2NUM(v) LONG2NUM(v)
#else
# define OFFT2NUM(v) INT2NUM(v)
#endif
-#define FIX2LONG(x) RSHIFT((SIGNED_VALUE)x,1)
-#define FIX2ULONG(x) (((VALUE)(x))>>1)
-#define FIXNUM_P(f) (((SIGNED_VALUE)(f))&FIXNUM_FLAG)
-#define POSFIXABLE(f) ((f) <= FIXNUM_MAX)
+#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 NEGFIXABLE(f) ((f) >= FIXNUM_MIN)
#define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
#define IMMEDIATE_MASK 0x03
#define IMMEDIATE_P(x) ((VALUE)(x) & IMMEDIATE_MASK)
-#define SYMBOL_P(x) (!SPECIAL_CONST_P(x) && RBASIC(x)->klass == rb_cSymbol)
-VALUE rb_id2sym(ID);
-ID rb_sym2id(VALUE);
-#define ID2SYM(x) rb_id2sym(x)
-#define SYM2ID(x) rb_sym2id(x)
+#define SYMBOL_FLAG 0x0e
+#define SYMBOL_P(x) (((VALUE)(x)&0xff)==SYMBOL_FLAG)
+#define ID2SYM(x) ((VALUE)(((long)(x))<<8|SYMBOL_FLAG))
+#define SYM2ID(x) RSHIFT((unsigned long)x,8)
/* special contants - i.e. non-zero and non-fixnum constants */
#define Qfalse ((VALUE)0)
@@ -229,38 +206,38 @@ ID rb_sym2id(VALUE);
#define T_BIGNUM 0x0d
#define T_FILE 0x0e
-#define T_TRUE 0x10
-#define T_FALSE 0x11
-#define T_DATA 0x12
-#define T_MATCH 0x13
-#define T_SYMBOL 0x14
+#define T_TRUE 0x20
+#define T_FALSE 0x21
+#define T_DATA 0x22
+#define T_MATCH 0x23
+#define T_SYMBOL 0x24
-#define T_BLOCK 0x1b
-#define T_UNDEF 0x1c
-#define T_VARMAP 0x1d
-#define T_SCOPE 0x1e
-#define T_NODE 0x1f
+#define T_BLKTAG 0x3b
+#define T_UNDEF 0x3c
+#define T_VARMAP 0x3d
+#define T_SCOPE 0x3e
+#define T_NODE 0x3f
-#define T_MASK 0x1f
+#define T_MASK 0x3f
#define BUILTIN_TYPE(x) (((struct RBasic*)(x))->flags & T_MASK)
#define TYPE(x) rb_type((VALUE)(x))
-void rb_check_type(VALUE,int);
+void rb_check_type _((VALUE,int));
#define Check_Type(v,t) rb_check_type((VALUE)(v),t)
-VALUE rb_str_to_str(VALUE);
-VALUE rb_string_value(volatile VALUE*);
-char *rb_string_value_ptr(volatile VALUE*);
-char *rb_string_value_cstr(volatile VALUE*);
+VALUE rb_str_to_str _((VALUE));
+VALUE rb_string_value _((volatile VALUE*));
+char *rb_string_value_ptr _((volatile VALUE*));
+char *rb_string_value_cstr _((volatile VALUE*));
#define StringValue(v) rb_string_value(&(v))
#define StringValuePtr(v) rb_string_value_ptr(&(v))
#define StringValueCStr(v) rb_string_value_cstr(&(v))
-void rb_check_safe_obj(VALUE);
-void rb_check_safe_str(VALUE);
+void rb_check_safe_obj _((VALUE));
+void rb_check_safe_str _((VALUE));
#define SafeStringValue(v) do {\
StringValue(v);\
rb_check_safe_obj(v);\
@@ -268,27 +245,24 @@ void rb_check_safe_str(VALUE);
/* obsolete macro - use SafeStringValue(v) */
#define Check_SafeStr(v) rb_check_safe_str((VALUE)(v))
-VALUE rb_get_path(VALUE);
-#define FilePathValue(v) ((v) = rb_get_path(v))
-
-void rb_secure(int);
+void rb_secure _((int));
RUBY_EXTERN int ruby_safe_level;
#define rb_safe_level() (ruby_safe_level)
-void rb_set_safe_level(int);
-void rb_secure_update(VALUE);
+void rb_set_safe_level _((int));
+void rb_secure_update _((VALUE));
-SIGNED_VALUE rb_num2long(VALUE);
-VALUE rb_num2ulong(VALUE);
+long rb_num2long _((VALUE));
+unsigned long rb_num2ulong _((VALUE));
#define NUM2LONG(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2long((VALUE)x))
#define NUM2ULONG(x) rb_num2ulong((VALUE)x)
#if SIZEOF_INT < SIZEOF_LONG
-long rb_num2int(VALUE);
+long rb_num2int _((VALUE));
#define NUM2INT(x) (FIXNUM_P(x)?FIX2INT(x):rb_num2int((VALUE)x))
-long rb_fix2int(VALUE);
+long rb_fix2int _((VALUE));
#define FIX2INT(x) rb_fix2int((VALUE)x)
-unsigned long rb_num2uint(VALUE);
+unsigned long rb_num2uint _((VALUE));
#define NUM2UINT(x) rb_num2uint(x)
-unsigned long rb_fix2uint(VALUE);
+unsigned long rb_fix2uint _((VALUE));
#define FIX2UINT(x) rb_fix2uint(x)
#else
#define NUM2INT(x) ((int)NUM2LONG(x))
@@ -298,8 +272,8 @@ unsigned long rb_fix2uint(VALUE);
#endif
#ifdef HAVE_LONG_LONG
-LONG_LONG rb_num2ll(VALUE);
-unsigned LONG_LONG rb_num2ull(VALUE);
+LONG_LONG rb_num2ll _((VALUE));
+unsigned LONG_LONG rb_num2ull _((VALUE));
# define NUM2LL(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2ll((VALUE)x))
# define NUM2ULL(x) rb_num2ull((VALUE)x)
#endif
@@ -310,19 +284,19 @@ unsigned LONG_LONG rb_num2ull(VALUE);
# define NUM2OFFT(x) NUM2LONG(x)
#endif
-double rb_num2dbl(VALUE);
+double rb_num2dbl _((VALUE));
#define NUM2DBL(x) rb_num2dbl((VALUE)(x))
/* obsolete API - use StringValue() */
-char *rb_str2cstr(VALUE,long*);
+char *rb_str2cstr _((VALUE,long*));
/* obsolete API - use StringValuePtr() */
#define STR2CSTR(x) rb_str2cstr((VALUE)(x),0)
-#define NUM2CHR(x) (((TYPE(x) == T_STRING)&&(RSTRING_LEN(x)>=1))?\
- RSTRING_PTR(x)[0]:(char)(NUM2INT(x)&0xff))
+#define NUM2CHR(x) (((TYPE(x) == T_STRING)&&(RSTRING(x)->len>=1))?\
+ RSTRING(x)->ptr[0]:(char)(NUM2INT(x)&0xff))
#define CHR2FIX(x) INT2FIX((long)((x)&0xff))
-VALUE rb_newobj(void);
+VALUE rb_newobj _((void));
#define NEWOBJ(obj,type) type *obj = (type*)rb_newobj()
#define OBJSETUP(obj,c,t) do {\
RBASIC(obj)->flags = (t);\
@@ -340,7 +314,7 @@ VALUE rb_newobj(void);
} while (0)
struct RBasic {
- VALUE flags;
+ unsigned long flags;
VALUE klass;
};
@@ -363,33 +337,17 @@ struct RFloat {
#define ELTS_SHARED FL_USER2
-#define RSTRING_EMBED_LEN_MAX ((sizeof(VALUE)*3)/sizeof(char)-1)
struct RString {
struct RBasic basic;
+ long len;
+ char *ptr;
union {
- struct {
- long len;
- char *ptr;
- union {
- long capa;
- VALUE shared;
- } aux;
- } heap;
- char ary[RSTRING_EMBED_LEN_MAX];
- } as;
+ long capa;
+ VALUE shared;
+ } aux;
};
-#define RSTRING_NOEMBED FL_USER1
-#define RSTRING_EMBED_LEN_MASK (FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6)
-#define RSTRING_EMBED_LEN_SHIFT (FL_USHIFT+2)
-#define RSTRING_LEN(str) \
- (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
- (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
- (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT)) : \
- RSTRING(str)->as.heap.len)
-#define RSTRING_PTR(str) \
- (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
- RSTRING(str)->as.ary : \
- RSTRING(str)->as.heap.ptr)
+#define RSTRING_PTR(s) (RSTRING(s)->ptr)
+#define RSTRING_LEN(s) (RSTRING(s)->len)
struct RArray {
struct RBasic basic;
@@ -400,8 +358,8 @@ struct RArray {
} aux;
VALUE *ptr;
};
-#define RARRAY_LEN(a) RARRAY(a)->len
-#define RARRAY_PTR(a) RARRAY(a)->ptr
+#define RARRAY_PTR(s) (RARRAY(s)->ptr)
+#define RARRAY_LEN(s) (RARRAY(s)->len)
struct RRegexp {
struct RBasic basic;
@@ -424,19 +382,19 @@ struct RFile {
struct RData {
struct RBasic basic;
- void (*dmark)(void*);
- void (*dfree)(void*);
+ void (*dmark) _((void*));
+ void (*dfree) _((void*));
void *data;
};
#define DATA_PTR(dta) (RDATA(dta)->data)
/*
-#define RUBY_DATA_FUNC(func) ((void (*)(void*))func)
+#define RUBY_DATA_FUNC(func) ((void (*)_((void*)))func)
*/
-typedef void (*RUBY_DATA_FUNC)(void*);
+typedef void (*RUBY_DATA_FUNC) _((void*));
-VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC);
+VALUE rb_data_object_alloc _((VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC));
#define Data_Wrap_Struct(klass,mark,free,sval)\
rb_data_object_alloc(klass,sval,(RUBY_DATA_FUNC)mark,(RUBY_DATA_FUNC)free)
@@ -452,28 +410,13 @@ VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC);
sval = (type*)DATA_PTR(obj);\
} while (0)
-#define RSTRUCT_EMBED_LEN_MAX 3
struct RStruct {
struct RBasic basic;
- union {
- struct {
- long len;
- VALUE *ptr;
- } heap;
- VALUE ary[RSTRUCT_EMBED_LEN_MAX];
- } as;
+ long len;
+ VALUE *ptr;
};
-#define RSTRUCT_EMBED_LEN_MASK (FL_USER2|FL_USER1)
-#define RSTRUCT_EMBED_LEN_SHIFT (FL_USHIFT+1)
-#define RSTRUCT_LEN(st) \
- ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
- (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \
- (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) : \
- RSTRUCT(st)->as.heap.len)
-#define RSTRUCT_PTR(st) \
- ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
- RSTRUCT(st)->as.ary : \
- RSTRUCT(st)->as.heap.ptr)
+#define RSTRUCT_LEN(st) (RSTRUCT(st)->len)
+#define RSTRUCT_PTR(st) (RSTRUCT(st)->ptr)
struct RBignum {
struct RBasic basic;
@@ -498,8 +441,7 @@ struct RBignum {
#define RFILE(obj) (R_CAST(RFile)(obj))
#define FL_SINGLETON FL_USER0
-#define FL_MARK (1<<5)
-#define FL_RESERVED (1<<6) /* will be used in the future GC */
+#define FL_MARK (1<<6)
#define FL_FINALIZE (1<<7)
#define FL_TAINT (1<<8)
#define FL_EXIVAR (1<<9)
@@ -516,12 +458,12 @@ struct RBignum {
#define FL_USER6 (1<<(FL_USHIFT+6))
#define FL_USER7 (1<<(FL_USHIFT+7))
+#define FL_UMASK (0xff<<FL_USHIFT)
+
#define SPECIAL_CONST_P(x) (IMMEDIATE_P(x) || !RTEST(x))
-#define FL_ABLE(x) (!SPECIAL_CONST_P(x) && BUILTIN_TYPE(x) != T_NODE)
+#define FL_ABLE(x) (!SPECIAL_CONST_P(x))
#define FL_TEST(x,f) (FL_ABLE(x)?(RBASIC(x)->flags&(f)):0)
-#define FL_ANY(x,f) FL_TEST(x,f)
-#define FL_ALL(x,f) (FL_TEST(x,f) == (f))
#define FL_SET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags |= (f);} while (0)
#define FL_UNSET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags &= ~(f);} while (0)
#define FL_REVERSE(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags ^= (f);} while (0)
@@ -533,9 +475,9 @@ struct RBignum {
#define OBJ_FROZEN(x) FL_TEST((x), FL_FREEZE)
#define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE)
-#define ALLOC_N(type,n) (type*)xmalloc2((n),sizeof(type))
+#define ALLOC_N(type,n) (type*)xmalloc(sizeof(type)*(n))
#define ALLOC(type) (type*)xmalloc(sizeof(type))
-#define REALLOC_N(var,type,n) (var)=(type*)xrealloc2((char*)(var),(n),sizeof(type))
+#define REALLOC_N(var,type,n) (var)=(type*)xrealloc((char*)(var),sizeof(type)*(n))
#define ALLOCA_N(type,n) (type*)alloca(sizeof(type)*(n))
@@ -544,100 +486,97 @@ struct RBignum {
#define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(n))
#define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), sizeof(type)*(n))
-void rb_obj_infect(VALUE,VALUE);
+void rb_obj_infect _((VALUE,VALUE));
typedef int ruby_glob_func(const char*,VALUE);
-void rb_glob(const char*,void(*)(const char*,VALUE),VALUE);
-int ruby_glob(const char*,int,ruby_glob_func*,VALUE);
-int ruby_brace_expand(const char*,int,ruby_glob_func*,VALUE);
-int ruby_brace_glob(const char*,int,ruby_glob_func*,VALUE);
-
-VALUE rb_define_class(const char*,VALUE);
-VALUE rb_define_module(const char*);
-VALUE rb_define_class_under(VALUE, const char*, VALUE);
-VALUE rb_define_module_under(VALUE, const char*);
-
-void rb_include_module(VALUE,VALUE);
-void rb_extend_object(VALUE,VALUE);
-
-void rb_define_variable(const char*,VALUE*);
-void rb_define_virtual_variable(const char*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
-void rb_define_hooked_variable(const char*,VALUE*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
-void rb_define_readonly_variable(const char*,VALUE*);
-void rb_define_const(VALUE,const char*,VALUE);
-void rb_define_global_const(const char*,VALUE);
+void rb_glob _((const char*,void(*)(const char*,VALUE),VALUE));
+void rb_globi _((const char*,void(*)(const char*,VALUE),VALUE));
+int ruby_brace_expand _((const char*,int,ruby_glob_func*,VALUE));
+int ruby_brace_glob _((const char*,int,ruby_glob_func*,VALUE));
+
+VALUE rb_define_class _((const char*,VALUE));
+VALUE rb_define_module _((const char*));
+VALUE rb_define_class_under _((VALUE, const char*, VALUE));
+VALUE rb_define_module_under _((VALUE, const char*));
+
+void rb_include_module _((VALUE,VALUE));
+void rb_extend_object _((VALUE,VALUE));
+
+void rb_define_variable _((const char*,VALUE*));
+void rb_define_virtual_variable _((const char*,VALUE(*)(ANYARGS),void(*)(ANYARGS)));
+void rb_define_hooked_variable _((const char*,VALUE*,VALUE(*)(ANYARGS),void(*)(ANYARGS)));
+int ruby_glob _((const char*,int,int(*)(const char*,VALUE),VALUE));
+int ruby_globi _((const char*,int,int(*)(const char*,VALUE),VALUE));
+void rb_define_readonly_variable _((const char*,VALUE*));
+void rb_define_const _((VALUE,const char*,VALUE));
+void rb_define_global_const _((const char*,VALUE));
#define RUBY_METHOD_FUNC(func) ((VALUE (*)(ANYARGS))func)
-void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int);
-void rb_define_module_function(VALUE,const char*,VALUE(*)(ANYARGS),int);
-void rb_define_global_function(const char*,VALUE(*)(ANYARGS),int);
+void rb_define_method _((VALUE,const char*,VALUE(*)(ANYARGS),int));
+void rb_define_module_function _((VALUE,const char*,VALUE(*)(ANYARGS),int));
+void rb_define_global_function _((const char*,VALUE(*)(ANYARGS),int));
-void rb_undef_method(VALUE,const char*);
-void rb_define_alias(VALUE,const char*,const char*);
-void rb_define_attr(VALUE,const char*,int,int);
+void rb_undef_method _((VALUE,const char*));
+void rb_define_alias _((VALUE,const char*,const char*));
+void rb_define_attr _((VALUE,const char*,int,int));
-void rb_global_variable(VALUE*);
-void rb_gc_register_address(VALUE*);
-void rb_gc_unregister_address(VALUE*);
+void rb_global_variable _((VALUE*));
+void rb_gc_register_address _((VALUE*));
+void rb_gc_unregister_address _((VALUE*));
-ID rb_intern(const char*);
-ID rb_intern2(const char*, long);
-const char *rb_id2name(ID);
-ID rb_to_id(VALUE);
+ID rb_intern _((const char*));
+char *rb_id2name _((ID));
+ID rb_to_id _((VALUE));
-char *rb_class2name(VALUE);
-char *rb_obj_classname(VALUE);
+char *rb_class2name _((VALUE));
+char *rb_obj_classname _((VALUE));
-void rb_p(VALUE);
+void rb_p _((VALUE));
-VALUE rb_eval_string(const char*);
-VALUE rb_eval_string_protect(const char*, int*);
-VALUE rb_eval_string_wrap(const char*, int*);
-VALUE rb_funcall(VALUE, ID, int, ...);
-VALUE rb_funcall2(VALUE, ID, int, const VALUE*);
-VALUE rb_funcall3(VALUE, ID, int, const VALUE*);
-int rb_scan_args(int, const VALUE*, const char*, ...);
-VALUE rb_call_super(int, const VALUE*);
+VALUE rb_eval_string _((const char*));
+VALUE rb_eval_string_protect _((const char*, int*));
+VALUE rb_eval_string_wrap _((const char*, int*));
+VALUE rb_funcall __((VALUE, ID, int, ...));
+VALUE rb_funcall2 _((VALUE, ID, int, const VALUE*));
+VALUE rb_funcall3 _((VALUE, ID, int, const VALUE*));
+int rb_scan_args __((int, const VALUE*, const char*, ...));
+VALUE rb_call_super _((int, const VALUE*));
-VALUE rb_gv_set(const char*, VALUE);
-VALUE rb_gv_get(const char*);
-VALUE rb_iv_get(VALUE, const char*);
-VALUE rb_iv_set(VALUE, const char*, VALUE);
+VALUE rb_gv_set _((const char*, VALUE));
+VALUE rb_gv_get _((const char*));
+VALUE rb_iv_get _((VALUE, const char*));
+VALUE rb_iv_set _((VALUE, const char*, VALUE));
-VALUE rb_equal(VALUE,VALUE);
+VALUE rb_equal _((VALUE,VALUE));
RUBY_EXTERN VALUE ruby_verbose, ruby_debug;
-PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
-PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2);
-PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2);
-NORETURN(void rb_sys_fail(const char*));
-NORETURN(void rb_iter_break(void));
-NORETURN(void rb_exit(int));
-NORETURN(void rb_notimplement(void));
-
-/* reports if `-w' specified */
-PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2);
-/* reports if `-w' specified */
-PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2);
-/* reports always */
-PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
-
-VALUE rb_each(VALUE);
-VALUE rb_yield(VALUE);
-VALUE rb_yield_values(int n, ...);
-VALUE rb_yield_splat(VALUE);
-int rb_block_given_p(void);
-void rb_need_block(void);
-VALUE rb_iterate(VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE);
-VALUE rb_block_call(VALUE,ID,int,VALUE*,VALUE(*)(ANYARGS),VALUE);
-VALUE rb_rescue(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
-VALUE rb_rescue2(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...);
-VALUE rb_ensure(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
-VALUE rb_catch(const char*,VALUE(*)(ANYARGS),VALUE);
-NORETURN(void rb_throw(const char*,VALUE));
-
-VALUE rb_require(const char*);
+NORETURN(void rb_raise __((VALUE, const char*, ...)));
+NORETURN(void rb_fatal __((const char*, ...)));
+NORETURN(void rb_bug __((const char*, ...)));
+NORETURN(void rb_sys_fail _((const char*)));
+NORETURN(void rb_iter_break _((void)));
+NORETURN(void rb_exit _((int)));
+NORETURN(void rb_notimplement _((void)));
+
+void rb_warning __((const char*, ...)); /* reports if `-w' specified */
+void rb_sys_warning __((const char*, ...)); /* reports if `-w' specified */
+void rb_warn __((const char*, ...)); /* reports always */
+
+VALUE rb_each _((VALUE));
+VALUE rb_yield _((VALUE));
+VALUE rb_yield_values __((int n, ...));
+VALUE rb_yield_splat _((VALUE));
+int rb_block_given_p _((void));
+void rb_need_block _((void));
+VALUE rb_iterate _((VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE));
+VALUE rb_rescue _((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE));
+VALUE rb_rescue2 __((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...));
+VALUE rb_ensure _((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE));
+VALUE rb_catch _((const char*,VALUE(*)(ANYARGS),VALUE));
+NORETURN(void rb_throw _((const char*,VALUE)));
+
+VALUE rb_require _((const char*));
#ifdef __ia64
void ruby_init_stack(VALUE*, void*);
@@ -650,9 +589,9 @@ void ruby_init_stack(VALUE*);
VALUE variable_in_this_stack_frame; \
ruby_init_stack(&variable_in_this_stack_frame);
#endif
-void ruby_init(void);
-void ruby_options(int, char**);
-NORETURN(void ruby_run(void));
+void ruby_init _((void));
+void ruby_options _((int, char**));
+NORETURN(void ruby_run _((void)));
RUBY_EXTERN VALUE rb_mKernel;
RUBY_EXTERN VALUE rb_mComparable;
@@ -664,7 +603,6 @@ RUBY_EXTERN VALUE rb_mGC;
RUBY_EXTERN VALUE rb_mMath;
RUBY_EXTERN VALUE rb_mProcess;
-RUBY_EXTERN VALUE rb_cBasicObject;
RUBY_EXTERN VALUE rb_cObject;
RUBY_EXTERN VALUE rb_cArray;
RUBY_EXTERN VALUE rb_cBignum;
@@ -707,7 +645,6 @@ RUBY_EXTERN VALUE rb_eFatal;
RUBY_EXTERN VALUE rb_eArgError;
RUBY_EXTERN VALUE rb_eEOFError;
RUBY_EXTERN VALUE rb_eIndexError;
-RUBY_EXTERN VALUE rb_eKeyError;
RUBY_EXTERN VALUE rb_eRangeError;
RUBY_EXTERN VALUE rb_eIOError;
RUBY_EXTERN VALUE rb_eRuntimeError;
@@ -733,38 +670,46 @@ RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr;
RUBY_EXTERN VALUE ruby_errinfo;
static inline VALUE
+#if defined(HAVE_PROTOTYPES)
rb_class_of(VALUE obj)
+#else
+rb_class_of(obj)
+ VALUE obj;
+#endif
{
- if (IMMEDIATE_P(obj)) {
- if (FIXNUM_P(obj)) return rb_cFixnum;
- if (obj == Qtrue) return rb_cTrueClass;
- if (SYMBOL_P(obj)) return rb_cSymbol;
- }
- else if (!RTEST(obj)) {
- if (obj == Qnil) return rb_cNilClass;
- if (obj == Qfalse) return rb_cFalseClass;
- }
+ if (FIXNUM_P(obj)) return rb_cFixnum;
+ if (obj == Qnil) return rb_cNilClass;
+ if (obj == Qfalse) return rb_cFalseClass;
+ if (obj == Qtrue) return rb_cTrueClass;
+ if (SYMBOL_P(obj)) return rb_cSymbol;
+
return RBASIC(obj)->klass;
}
static inline int
+#if defined(HAVE_PROTOTYPES)
rb_type(VALUE obj)
+#else
+rb_type(obj)
+ VALUE obj;
+#endif
{
- if (IMMEDIATE_P(obj)) {
- if (FIXNUM_P(obj)) return T_FIXNUM;
- if (obj == Qtrue) return T_TRUE;
- if (SYMBOL_P(obj)) return T_SYMBOL;
- if (obj == Qundef) return T_UNDEF;
- }
- else if (!RTEST(obj)) {
- if (obj == Qnil) return T_NIL;
- if (obj == Qfalse) return T_FALSE;
- }
+ if (FIXNUM_P(obj)) return T_FIXNUM;
+ if (obj == Qnil) return T_NIL;
+ if (obj == Qfalse) return T_FALSE;
+ if (obj == Qtrue) return T_TRUE;
+ if (obj == Qundef) return T_UNDEF;
+ if (SYMBOL_P(obj)) return T_SYMBOL;
return BUILTIN_TYPE(obj);
}
static inline int
+#if defined(HAVE_PROTOTYPES)
rb_special_const_p(VALUE obj)
+#else
+rb_special_const_p(obj)
+ VALUE obj;
+#endif
{
if (SPECIAL_CONST_P(obj)) return Qtrue;
return Qfalse;
@@ -796,12 +741,12 @@ typedef DWORD rb_nativethread_t;
# define HAVE_NATIVETHREAD
#endif
#ifdef HAVE_NATIVETHREAD
-int is_ruby_native_thread(void);
+int is_ruby_native_thread _((void));
#else
#define is_ruby_native_thread() (1)
#endif
#ifdef HAVE_NATIVETHREAD_KILL
-void ruby_native_thread_kill(int);
+void ruby_native_thread_kill _((int));
#endif
#if defined(__cplusplus)
diff --git a/rubyio.h b/rubyio.h
index 00a5facf23..ac28ead77b 100644
--- a/rubyio.h
+++ b/rubyio.h
@@ -21,22 +21,13 @@
#endif
typedef struct OpenFile {
- int fd; /* file descriptor */
- FILE *stdio_file; /* stdio ptr for read/write if available */
+ FILE *f; /* stdio ptr for read/write */
+ FILE *f2; /* additional ptr for rw pipes */
int mode; /* mode flags */
int pid; /* child's pid (for pipes) */
int lineno; /* number of lines read */
char *path; /* pathname for file */
- void (*finalize)(struct OpenFile*,int); /* finalize proc */
- long refcnt;
- char *wbuf; /* wbuf_off + wbuf_len <= wbuf_capa */
- int wbuf_off;
- int wbuf_len;
- int wbuf_capa;
- char *rbuf; /* rbuf_off + rbuf_len <= rbuf_capa */
- int rbuf_off;
- int rbuf_len;
- int rbuf_capa;
+ void (*finalize) _((struct OpenFile*,int)); /* finalize proc */
} OpenFile;
#define FMODE_READABLE 1
@@ -46,8 +37,8 @@ typedef struct OpenFile {
#define FMODE_CREATE 128
#define FMODE_BINMODE 4
#define FMODE_SYNC 8
-#define FMODE_TTY 16
-#define FMODE_DUPLEX 32
+#define FMODE_WBUF 16
+#define FMODE_RBUF 32
#define FMODE_WSPLIT 0x200
#define FMODE_WSPLIT_INITIALIZED 0x400
@@ -61,49 +52,37 @@ typedef struct OpenFile {
}\
fp = 0;\
fp = RFILE(obj)->fptr = ALLOC(OpenFile);\
- fp->fd = -1;\
- fp->stdio_file = NULL;\
+ fp->f = fp->f2 = NULL;\
fp->mode = 0;\
fp->pid = 0;\
fp->lineno = 0;\
fp->path = NULL;\
fp->finalize = 0;\
- fp->refcnt = 1;\
- fp->wbuf = NULL;\
- fp->wbuf_off = 0;\
- fp->wbuf_len = 0;\
- fp->wbuf_capa = 0;\
- fp->rbuf = NULL;\
- fp->rbuf_off = 0;\
- fp->rbuf_len = 0;\
- fp->rbuf_capa = 0;\
} while (0)
-FILE *rb_io_stdio_file(OpenFile *fptr);
-
-FILE *rb_fopen(const char*, const char*);
-FILE *rb_fdopen(int, const char*);
-int rb_io_mode_flags(const char*);
-int rb_io_modenum_flags(int);
-void rb_io_check_writable(OpenFile*);
-void rb_io_check_readable(OpenFile*);
-int rb_io_fptr_finalize(OpenFile*);
-void rb_io_synchronized(OpenFile*);
-void rb_io_check_initialized(OpenFile*);
-void rb_io_check_closed(OpenFile*);
-int rb_io_wait_readable(int);
-int rb_io_wait_writable(int);
+#define GetReadFile(fptr) ((fptr)->f)
+#define GetWriteFile(fptr) (((fptr)->f2) ? (fptr)->f2 : (fptr)->f)
+
+FILE *rb_fopen _((const char*, const char*));
+FILE *rb_fdopen _((int, const char*));
+int rb_getc _((FILE*));
+long rb_io_fread _((char *, long, FILE *));
+long rb_io_fwrite _((const char *, long, FILE *));
+int rb_io_mode_flags _((const char*));
+int rb_io_modenum_flags _((int));
+void rb_io_check_writable _((OpenFile*));
+void rb_io_check_readable _((OpenFile*));
+void rb_io_fptr_finalize _((OpenFile*));
+void rb_io_synchronized _((OpenFile*));
+void rb_io_check_initialized _((OpenFile*));
+void rb_io_check_closed _((OpenFile*));
+int rb_io_wait_readable _((int));
+int rb_io_wait_writable _((int));
void rb_io_set_nonblock(OpenFile *fptr);
-VALUE rb_io_taint_check(VALUE);
-NORETURN(void rb_eof_error(void));
-
-void rb_io_read_check(OpenFile*);
-int rb_io_read_pending(OpenFile*);
-void rb_read_check(FILE*);
+VALUE rb_io_taint_check _((VALUE));
+NORETURN(void rb_eof_error _((void)));
-DEPRECATED(int rb_getc(FILE*));
-DEPRECATED(long rb_io_fread(char *, long, FILE *));
-DEPRECATED(long rb_io_fwrite(const char *, long, FILE *));
-DEPRECATED(int rb_read_pending(FILE*));
+void rb_read_check _((FILE*));
+int rb_read_pending _((FILE*));
#endif
diff --git a/rubysig.h b/rubysig.h
index bce1c4f2aa..3eb877855e 100644
--- a/rubysig.h
+++ b/rubysig.h
@@ -10,8 +10,8 @@
**********************************************************************/
-#ifndef RUBYSIG_H
-#define RUBYSIG_H
+#ifndef SIG_H
+#define SIG_H
#include <errno.h>
#ifdef _WIN32
@@ -72,18 +72,18 @@ RUBY_EXTERN int rb_prohibit_interrupt;
} while (0)
#define ENABLE_INTS (rb_prohibit_interrupt--)
-VALUE rb_with_disable_interrupt(VALUE(*)(ANYARGS),VALUE);
+VALUE rb_with_disable_interrupt _((VALUE(*)(ANYARGS),VALUE));
RUBY_EXTERN rb_atomic_t rb_trap_pending;
-void rb_trap_restore_mask(void);
+void rb_trap_restore_mask _((void));
RUBY_EXTERN int rb_thread_critical;
-void rb_thread_schedule(void);
-#if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE)
RUBY_EXTERN int rb_thread_pending;
+void rb_thread_schedule _((void));
+#if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE)
# 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,13 +93,13 @@ RUBY_EXTERN int rb_thread_tick;
#define THREAD_TICK 500
#define CHECK_INTS do {\
if (!(rb_prohibit_interrupt || rb_thread_critical)) {\
- if (rb_thread_tick-- <= 0) {\
+ if (rb_thread_pending || rb_thread_tick-- <= 0) {\
rb_thread_tick = THREAD_TICK;\
- rb_thread_schedule();\
+ rb_thread_schedule();\
}\
}\
- if (rb_trap_pending) rb_trap_exec();\
+ if (rb_trap_pending) rb_trap_exec();\
} while (0)
#endif
-#endif /* ifndef RUBYSIG_H */
+#endif
diff --git a/rubytest.rb b/rubytest.rb
index e5cc9ba1ab..8ae637c00e 100644..100755
--- a/rubytest.rb
+++ b/rubytest.rb
@@ -2,7 +2,7 @@
exit if defined?(CROSS_COMPILING)
load './rbconfig.rb'
-include RbConfig
+include Config
ruby = "./#{CONFIG['ruby_install_name']}#{CONFIG['EXEEXT']}"
unless File.exist? ruby
@@ -37,13 +37,13 @@ $stderr.reopen($stdout)
error = ''
srcdir = File.dirname(__FILE__)
-`#{ruby} -I#{srcdir}/lib #{srcdir}/sample/test.rb`.each_line do |line|
+`#{ruby} -I#{srcdir}/lib #{srcdir}/sample/test.rb`.each do |line|
if line =~ /^end of test/
print "test succeeded\n"
- exit true
+ exit 0
end
error << line if line =~ %r:^(sample/test.rb|not):
end
print error
print "test failed\n"
-exit false
+exit 1
diff --git a/runruby.rb b/runruby.rb
index 8dbe8f714f..f442d90a9c 100755
--- a/runruby.rb
+++ b/runruby.rb
@@ -25,25 +25,24 @@ abs_archdir = File.expand_path(archdir)
$:.unshift(abs_archdir)
require 'rbconfig'
-config = RbConfig::CONFIG
+config = Config::CONFIG
ruby = File.join(archdir, config["RUBY_INSTALL_NAME"]+config['EXEEXT'])
unless File.exist?(ruby)
abort "#{ruby} is not found.\nTry `make' first, then `make test', please.\n"
end
-libs = [abs_archdir, File.expand_path("lib", srcdir)]
+libs = [abs_archdir]
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)
-if e = ENV["RUBYLIB"]
- libs |= e.split(File::PATH_SEPARATOR)
-end
+ libs << File.expand_path("ext", srcdir) << "-"
ENV["RUBYLIB"] = $:.replace(libs).join(File::PATH_SEPARATOR)
libruby_so = File.join(abs_archdir, config['LIBRUBY_SO'])
@@ -56,4 +55,7 @@ if File.file?(libruby_so)
end
end
-exec ruby, *ARGV
+cmd = [ruby]
+cmd << "-rpurelib.rb"
+cmd.concat(ARGV)
+exec(*cmd)
diff --git a/sample/cal.rb b/sample/cal.rb
index 197cdfe3a6..fa20352f71 100644
--- a/sample/cal.rb
+++ b/sample/cal.rb
@@ -1,7 +1,7 @@
#! /usr/bin/env ruby
# cal.rb: Written by Tadayoshi Funaba 1998-2004
-# $Id: cal.rb,v 2.8 2004-09-25 12:50:10+09 tadf Exp $
+# $Id: cal.rb,v 2.7 2004-01-10 23:52:51+09 tadf Exp $
require 'date'
@@ -121,36 +121,17 @@ end
if __FILE__ == $0
- require 'getoptlong'
+ require 'getopts'
def usage
warn 'usage: cal [-c iso3166] [-jmty] [[month] year]'
exit 1
end
- cal = Cal.new
-
- begin
- GetoptLong.new(['-c', GetoptLong::REQUIRED_ARGUMENT],
- ['-j', GetoptLong::NO_ARGUMENT],
- ['-m', GetoptLong::NO_ARGUMENT],
- ['-t', GetoptLong::NO_ARGUMENT],
- ['-y', GetoptLong::NO_ARGUMENT]).
- each do |opt, arg|
- case opt
- when '-c'; cal.opt_c(arg) || raise
- when '-j'; cal.opt_j(true)
- when '-m'; cal.opt_m(true)
- when '-t'; cal.opt_t(true)
- when '-y'; cal.opt_y(true)
- end
- end
- rescue
- usage
- end
+ usage unless getopts('jmty', "c:#{Cal::DEFAULT_START}")
y, m = ARGV.values_at(1, 0).compact.collect{|x| x.to_i}
- cal.opt_y(true) if y and not m
+ $OPT_y ||= (y and not m)
to = Date.today
y ||= to.year
@@ -158,6 +139,15 @@ if __FILE__ == $0
usage unless m >= 1 and m <= 12
usage unless y >= -4712
+ usage if Cal::START[$OPT_c].nil?
+
+ cal = Cal.new
+
+ cal.opt_j($OPT_j)
+ cal.opt_m($OPT_m)
+ cal.opt_t($OPT_t)
+ cal.opt_y($OPT_y)
+ cal.opt_c($OPT_c)
print cal.print(y, m)
diff --git a/sample/occur.rb b/sample/occur.rb
index 4ec6ae479b..8bb09e15ad 100644
--- a/sample/occur.rb
+++ b/sample/occur.rb
@@ -1,8 +1,8 @@
# word occurrence listing
# usege: ruby occur.rb file..
freq = Hash.new(0)
-while line = gets()
- for word in line.split(/\W+/)
+while gets()
+ for word in split(/\W+/)
freq[word] += 1
end
end
diff --git a/sample/openssl/cipher.rb b/sample/openssl/cipher.rb
index 58b10d6046..6e8cdb9427 100644
--- a/sample/openssl/cipher.rb
+++ b/sample/openssl/cipher.rb
@@ -1,54 +1,33 @@
#!/usr/bin/env ruby
require 'openssl'
-def crypt_by_password(alg, pass, salt, text)
- puts "--Setup--"
- puts %(cipher alg: "#{alg}")
- puts %(plain text: "#{text}")
- puts %(password: "#{pass}")
- puts %(salt: "#{salt}")
- puts
-
- puts "--Encrypting--"
- enc = OpenSSL::Cipher::Cipher.new(alg)
- enc.encrypt
- enc.pkcs5_keyivgen(pass, salt)
- cipher = enc.update(text)
- cipher << enc.final
- puts %(encrypted text: #{cipher.inspect})
- puts
-
- puts "--Decrypting--"
- dec = OpenSSL::Cipher::Cipher.new(alg)
- dec.decrypt
- dec.pkcs5_keyivgen(pass, salt)
- plain = dec.update(cipher)
- plain << dec.final
- puts %(decrypted text: "#{plain}")
- puts
-end
-
-def ciphers
- ciphers = OpenSSL::Cipher.ciphers.sort
- ciphers.each{|i|
- if i.upcase != i && ciphers.include?(i.upcase)
- ciphers.delete(i)
- end
- }
- return ciphers
-end
+text = "abcdefghijklmnopqrstuvwxyz"
+pass = "secret password"
+salt = "8 octets" # or nil
+alg = "DES-EDE3-CBC"
+#alg = "AES-128-CBC"
-puts "Supported ciphers in #{OpenSSL::OPENSSL_VERSION}:"
-ciphers.each_with_index{|name, i|
- printf("%-15s", name)
- puts if (i + 1) % 5 == 0
-}
-puts
+puts "--Setup--"
+puts %(clear text: "#{text}")
+puts %(password: "#{pass}")
+puts %(salt: "#{salt}")
+puts %(cipher alg: "#{alg}")
puts
-alg = ARGV.shift || ciphers.first
-pass = "secret password"
-salt = "8 octets" # or nil
-text = "abcdefghijklmnopqrstuvwxyz"
+puts "--Encrypting--"
+des = OpenSSL::Cipher::Cipher.new(alg)
+des.pkcs5_keyivgen(pass, salt)
+des.encrypt
+cipher = des.update(text)
+cipher << des.final
+puts %(encrypted text: #{cipher.inspect})
+puts
-crypt_by_password(alg, pass, salt, text)
+puts "--Decrypting--"
+des = OpenSSL::Cipher::Cipher.new(alg)
+des.pkcs5_keyivgen(pass, salt)
+des.decrypt
+out = des.update(cipher)
+out << des.final
+puts %(decrypted text: "#{out}")
+puts
diff --git a/sample/openssl/gen_csr.rb b/sample/openssl/gen_csr.rb
index d3da5741bc..5858acd9f2 100644
--- a/sample/openssl/gen_csr.rb
+++ b/sample/openssl/gen_csr.rb
@@ -21,6 +21,7 @@ keyout = $OPT_keyout || "keypair.pem"
$stdout.sync = true
name_str = ARGV.shift or usage()
+p name_str
name = X509::Name.parse(name_str)
keypair = nil
diff --git a/sample/optparse/opttest.rb b/sample/optparse/opttest.rb
index e2c6d1e048..61b157bce5 100644
--- a/sample/optparse/opttest.rb
+++ b/sample/optparse/opttest.rb
@@ -23,49 +23,49 @@ ARGV.options do
# mandatory argument
opts.on("-r", "--require=LIBRARY", String,
"require the LIBRARY, before",
- "executing your script") {|lib|@library=lib}
+ "executing your script") {|@library|}
# optional argument
opts.on("-i", "--inplace=[EXTENSION]",
"edit ARGV files in place", # multiline description
- "(make backup if EXTENSION supplied)") {|inplace| @inplace = inplace || ''}
+ "(make backup if EXTENSION supplied)") {|@inplace| @inplace ||= ''}
- opts.on("-N=[NUM]", Integer) {|num|@number=num}
+ opts.on("-N=[NUM]", Integer) {|@number|}
# additional class
- opts.on("-t", "--[no-]time[=TIME]", Time, "it's the time") {|time|@time=time}
+ opts.on("-t", "--[no-]time[=TIME]", Time, "it's the time") {|@time|}
# limit argument syntax
opts.on("-[0-7]", "-F", "--irs=[OCTAL]", OptionParser::OctalInteger,
- "specify record separator", "(\\0, if no argument)") {|irs|@irs=irs}
+ "specify record separator", "(\\0, if no argument)") {|@irs|}
# boolean switch(default true)
@exec = true
- opts.on("-n", "--no-exec[=FLAG]", TrueClass, "not really execute") {|exec|@exec=exec}
+ opts.on("-n", "--no-exec[=FLAG]", TrueClass, "not really execute") {|@exec|}
# array
- opts.on("-a", "--list[=LIST,LIST]", Array, "list") {|list|@list=list}
+ opts.on("-a", "--list[=LIST,LIST]", Array, "list") {|@list|}
# fixed size array
- opts.on("--pair[=car,cdr]", Array, "pair") {|x,y|@x=x; @y=y}
+ opts.on("--pair[=car,cdr]", Array, "pair") {|@x, @y|}
# keyword completion
opts.on("--code=CODE", CODES, CODE_ALIASES, "select coding system",
- "("+CODES.join(",")+",", " "+CODE_ALIASES.keys.join(",")+")") {|c|@code=c}
+ "("+CODES.join(",")+",", " "+CODE_ALIASES.keys.join(",")+")") {|@code|}
# optional argument with keyword completion
- opts.on("--type[=TYPE]", [:text, :binary], "select type(text, binary)") {|t|@type=t}
+ opts.on("--type[=TYPE]", [:text, :binary], "select type(text, binary)") {|@type|}
# boolean switch with optional argument(default false)
- opts.on("-v", "--[no-]verbose=[FLAG]", "run verbosely") {|v|@verbose=v}
+ opts.on("-v", "--[no-]verbose=[FLAG]", "run verbosely") {|@verbose|}
# easy way, set local variable
- opts.on("-q", "--quit", "quit when ARGV is empty") {|q|@quit=q}
+ opts.on("-q", "--quit", "quit when ARGV is empty") {|@quit|}
# adding on the fly
opts.on("--add=SWITCH=[ARG]", "add option on the fly", /\A(\w+)(?:=.+)?\Z/) do
|opt, var|
- opts.on("--#{opt}", "added in runtime", &eval("proc {|x|@#{var}=x}"))
+ opts.on("--#{opt}", "added in runtime", &eval("proc {|@#{var}|}"))
end
opts.on_head("specific options:")
@@ -79,7 +79,7 @@ ARGV.options do
end
pp self
-begin print ARGV.options; exit end if @quit
+(print ARGV.options; exit) if @quit
ARGV.options = nil # no more parse
puts "ARGV = #{ARGV.join(' ')}" if !ARGV.empty?
#opts.variable.each {|sym| puts "#{sym} = #{opts.send(sym).inspect}"}
diff --git a/sample/ripper/ruby2html.rb b/sample/ripper/ruby2html.rb
deleted file mode 100644
index 8f64f5a713..0000000000
--- a/sample/ripper/ruby2html.rb
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/usr/bin/env ruby
-# $originalId: ruby2html.rb,v 1.2 2005/09/23 22:53:47 aamine Exp $
-
-TEMPLATE_LINE = __LINE__ + 2
-TEMPLATE = <<-EndTemplate
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=<%= encoding %>">
-<% if css %>
- <link rel="stylesheet" type="text/css" href="<%= css %>">
-<% end %>
- <title><%= File.basename(f.path) %></title>
-</head>
-<body>
-<pre>
-<%
- if print_line_number
- Ruby2HTML.compile(f).each_with_index do |line, idx|
-%><%= sprintf('%4d %s', idx+1, line) %><%
- end
- else
-%><%= Ruby2HTML.compile(f) %><%
- end
-%>
-</pre>
-</body>
-</html>
-EndTemplate
-
-require 'ripper'
-require 'stringio'
-require 'cgi'
-require 'erb'
-require 'optparse'
-
-def main
- encoding = 'us-ascii'
- css = nil
- print_line_number = false
- parser = OptionParser.new
- parser.banner = "Usage: #{File.basename($0)} [-l] [<file>...]"
- parser.on('--encoding=NAME', 'Character encoding [us-ascii].') {|name|
- encoding = name
- }
- parser.on('--css=URL', 'Set a link to CSS.') {|url|
- css = url
- }
- parser.on('-l', '--line-number', 'Show line number.') {
- print_line_number = true
- }
- parser.on('--help', 'Prints this message and quit.') {
- puts parser.help
- exit 0
- }
- begin
- parser.parse!
- rescue OptionParser::ParseError => err
- $stderr.puts err
- $stderr.puts parser.help
- exit 1
- end
- puts ruby2html(ARGF, encoding, css, print_line_number)
-end
-
-class ERB
- attr_accessor :lineno
-
- remove_method :result
- def result(b)
- eval(@src, b, (@filename || '(erb)'), (@lineno || 1))
- end
-end
-
-def ruby2html(f, encoding, css, print_line_number)
- erb = ERB.new(TEMPLATE, nil, '>')
- erb.filename = __FILE__
- erb.lineno = TEMPLATE_LINE
- erb.result(binding())
-end
-
-class Ruby2HTML < Ripper::Filter
- def Ruby2HTML.compile(f)
- buf = StringIO.new
- Ruby2HTML.new(f).parse(buf)
- buf.string
- end
-
- def on_default(event, tok, f)
- f << CGI.escapeHTML(tok)
- end
-
- def on_kw(tok, f)
- f << %Q[<span class="resword">#{CGI.escapeHTML(tok)}</span>]
- end
-
- def on_comment(tok, f)
- f << %Q[<span class="comment">#{CGI.escapeHTML(tok.rstrip)}</span>\n]
- end
-
- def on_tstring_beg(tok, f)
- f << %Q[<span class="string">#{CGI.escapeHTML(tok)}]
- end
-
- def on_tstring_end(tok, f)
- f << %Q[#{CGI.escapeHTML(tok)}</span>]
- end
-end
-
-if $0 == __FILE__
- main
-end
diff --git a/sample/ripper/strip-comment.rb b/sample/ripper/strip-comment.rb
deleted file mode 100644
index bd26b6a377..0000000000
--- a/sample/ripper/strip-comment.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# $Id$
-
-require 'ripper/filter'
-
-class CommentStripper < Ripper::Filter
- def CommentStripper.strip(src)
- new(src).parse(nil)
- end
-
- def on_default(event, token, data)
- print token
- end
-
- def on_comment(token, data)
- puts
- end
-end
-
-CommentStripper.strip(ARGF)
diff --git a/sample/rss/convert.rb b/sample/rss/convert.rb
new file mode 100755
index 0000000000..394b13e8eb
--- /dev/null
+++ b/sample/rss/convert.rb
@@ -0,0 +1,69 @@
+#!/usr/bin/env ruby
+
+require "rss"
+
+feeds = []
+verbose = false
+encoding = "UTF-8"
+to_version = "1.0"
+
+def error(exception)
+ mark = "=" * 20
+ mark = "#{mark} error #{mark}"
+ STDERR.puts mark
+ STDERR.puts exception.class
+ STDERR.puts exception.message
+ STDERR.puts exception.backtrace
+ STDERR.puts mark
+end
+
+before_time = Time.now
+ARGV.each do |fname|
+ case fname
+ when '-v'
+ verbose = true
+ next
+ when /^-t(0\.91|1\.0|2\.0)$/
+ to_version = $1
+ next
+ end
+ rss = nil
+ f = File.read(fname)
+ begin
+ ## do validate parse
+ rss = RSS::Parser.parse(f)
+ rescue RSS::InvalidRSSError
+ error($!) if verbose
+ ## do non validate parse for invalid RSS 1.0
+ begin
+ rss = RSS::Parser.parse(f, false)
+ rescue RSS::Error
+ ## invalid RSS.
+ error($!) if verbose
+ end
+ rescue RSS::Error
+ error($!) if verbose
+ end
+ if rss.nil?
+ STDERR.puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
+ else
+ begin
+ rss.output_encoding = encoding
+ rescue RSS::UnknownConversionMethodError
+ error($!) if verbose
+ end
+ feeds << [fname, rss]
+ end
+end
+processing_time = Time.now - before_time
+
+feeds.each do |fname, rss|
+ converted_rss = rss.to_xml(to_version)
+ output_name = fname.sub(/(\.[^\.]+)$/, "-#{to_version}\\1")
+ File.open(output_name, "w") do |output|
+ output.print(converted_rss)
+ end
+end
+
+STDERR.puts "Used XML parser: #{RSS::Parser.default_parser}"
+STDERR.puts "Processing time: #{processing_time}s"
diff --git a/sample/test.rb b/sample/test.rb
index aad5a094c3..741e96ee9d 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -54,48 +54,30 @@ a = [*[]]; test_ok(a == [])
a = [*[1]]; test_ok(a == [1])
a = [*[1,2]]; test_ok(a == [1,2])
-a = *[]; test_ok(a == [])
-a = *[1]; test_ok(a == [1])
-a = *[nil]; test_ok(a == [nil])
-a = *[[]]; test_ok(a == [[]])
+a = *nil; test_ok(a == nil)
+a = *1; test_ok(a == 1)
+a = *[]; test_ok(a == nil)
+a = *[1]; test_ok(a == 1)
+a = *[nil]; test_ok(a == nil)
+a = *[[]]; test_ok(a == [])
a = *[1,2]; test_ok(a == [1,2])
-a = *[*[]]; test_ok(a == [])
-a = *[*[1]]; test_ok(a == [1])
+a = *[*[]]; test_ok(a == nil)
+a = *[*[1]]; test_ok(a == 1)
a = *[*[1,2]]; test_ok(a == [1,2])
-a, = nil; test_ok(a == nil)
-a, = 1; test_ok(a == 1)
-a, = []; test_ok(a == nil)
-a, = [1]; test_ok(a == 1)
-a, = [nil]; test_ok(a == nil)
-a, = [[]]; test_ok(a == [])
-a, = 1,2; test_ok(a == 1)
-a, = [1,2]; test_ok(a == 1)
-a, = [*[]]; test_ok(a == nil)
-a, = [*[1]]; test_ok(a == 1)
-a, = *[1,2]; test_ok(a == 1)
-a, = [*[1,2]]; test_ok(a == 1)
-
-a, = *[]; test_ok(a == nil)
-a, = *[1]; test_ok(a == 1)
-a, = *[nil]; test_ok(a == nil)
-a, = *[[]]; test_ok(a == [])
-a, = *[1,2]; test_ok(a == 1)
-a, = *[*[]]; test_ok(a == nil)
-a, = *[*[1]]; test_ok(a == 1)
-a, = *[*[1,2]]; test_ok(a == 1)
-
*a = nil; test_ok(a == [nil])
*a = 1; test_ok(a == [1])
-*a = []; test_ok(a == [])
-*a = [1]; test_ok(a == [1])
-*a = [nil]; test_ok(a == [nil])
-*a = [[]]; test_ok(a == [[]])
-*a = [1,2]; test_ok(a == [1,2])
-*a = [*[]]; test_ok(a == [])
-*a = [*[1]]; test_ok(a == [1])
-*a = [*[1,2]]; test_ok(a == [1,2])
-
+*a = []; test_ok(a == [[]])
+*a = [1]; test_ok(a == [[1]])
+*a = [nil]; test_ok(a == [[nil]])
+*a = [[]]; test_ok(a == [[[]]])
+*a = [1,2]; test_ok(a == [[1,2]])
+*a = [*[]]; test_ok(a == [[]])
+*a = [*[1]]; test_ok(a == [[1]])
+*a = [*[1,2]]; test_ok(a == [[1,2]])
+
+*a = *nil; test_ok(a == [nil])
+*a = *1; test_ok(a == [1])
*a = *[]; test_ok(a == [])
*a = *[1]; test_ok(a == [1])
*a = *[nil]; test_ok(a == [nil])
@@ -116,6 +98,8 @@ a,b,*c = [*[]]; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = [*[1]]; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = [*[1,2]]; test_ok([a,b,c] == [1,2,[]])
+a,b,*c = *nil; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = *1; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = *[]; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = *[1]; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = *[nil]; test_ok([a,b,c] == [nil,nil,[]])
@@ -134,45 +118,28 @@ def f; yield [[]]; end; f {|a| test_ok(a == [[]])}
def f; yield [*[]]; end; f {|a| test_ok(a == [])}
def f; yield [*[1]]; end; f {|a| test_ok(a == [1])}
def f; yield [*[1,2]]; end; f {|a| test_ok(a == [1,2])}
-def f; yield *[]; end; f {|a| test_ok(a == [])}
-def f; yield *[1]; end; f {|a| test_ok(a == [1])}
-def f; yield *[nil]; end; f {|a| test_ok(a == [nil])}
-def f; yield *[[]]; end; f {|a| test_ok(a == [[]])}
-def f; yield *[*[]]; end; f {|a| test_ok(a == [])}
-def f; yield *[*[1]]; end; f {|a| test_ok(a == [1])}
-def f; yield *[*[1,2]]; end; f {|a| test_ok(a == [1,2])}
-
-def f; yield; end; f {|a,| test_ok(a == nil)}
-def f; yield nil; end; f {|a,| test_ok(a == nil)}
-def f; yield 1; end; f {|a,| test_ok(a == 1)}
-def f; yield []; end; f {|a,| test_ok(a == nil)}
-def f; yield [1]; end; f {|a,| test_ok(a == 1)}
-def f; yield [nil]; end; f {|a,| test_ok(a == nil)}
-def f; yield [[]]; end; f {|a,| test_ok(a == [])}
-def f; yield [*[]]; end; f {|a,| test_ok(a == nil)}
-def f; yield [*[1]]; end; f {|a,| test_ok(a == 1)}
-def f; yield [*[1,2]]; end; f {|a,| test_ok(a == 1)}
-
-def f; yield *[]; end; f {|a,| test_ok(a == nil)}
-def f; yield *[1]; end; f {|a,| test_ok(a == 1)}
-def f; yield *[nil]; end; f {|a,| test_ok(a == nil)}
-def f; yield *[[]]; end; f {|a,| test_ok(a == [])}
-def f; yield *[*[]]; end; f {|a,| test_ok(a == nil)}
-def f; yield *[*[1]]; end; f {|a,| test_ok(a == 1)}
-def f; yield *[*[1,2]]; end; f {|a,| test_ok(a == 1)}
+
+def f; yield *nil; end; f {|a| test_ok(a == nil)}
+def f; yield *1; end; f {|a| test_ok(a == 1)}
+def f; yield *[1]; end; f {|a| test_ok(a == 1)}
+def f; yield *[nil]; end; f {|a| test_ok(a == nil)}
+def f; yield *[[]]; end; f {|a| test_ok(a == [])}
+def f; yield *[*[1]]; end; f {|a| test_ok(a == 1)}
def f; yield; end; f {|*a| test_ok(a == [])}
def f; yield nil; end; f {|*a| test_ok(a == [nil])}
def f; yield 1; end; f {|*a| test_ok(a == [1])}
-def f; yield []; end; f {|*a| test_ok(a == [])}
-def f; yield [1]; end; f {|*a| test_ok(a == [1])}
-def f; yield [nil]; end; f {|*a| test_ok(a == [nil])}
-def f; yield [[]]; end; f {|*a| test_ok(a == [[]])}
-def f; yield [1,2]; end; f {|*a| test_ok(a == [1,2])}
-def f; yield [*[]]; end; f {|*a| test_ok(a == [])}
-def f; yield [*[1]]; end; f {|*a| test_ok(a == [1])}
-def f; yield [*[1,2]]; end; f {|*a| test_ok(a == [1,2])}
-
+def f; yield []; end; f {|*a| test_ok(a == [[]])}
+def f; yield [1]; end; f {|*a| test_ok(a == [[1]])}
+def f; yield [nil]; end; f {|*a| test_ok(a == [[nil]])}
+def f; yield [[]]; end; f {|*a| test_ok(a == [[[]]])}
+def f; yield [1,2]; end; f {|*a| test_ok(a == [[1,2]])}
+def f; yield [*[]]; end; f {|*a| test_ok(a == [[]])}
+def f; yield [*[1]]; end; f {|*a| test_ok(a == [[1]])}
+def f; yield [*[1,2]]; end; f {|*a| test_ok(a == [[1,2]])}
+
+def f; yield *nil; end; f {|*a| test_ok(a == [nil])}
+def f; yield *1; end; f {|*a| test_ok(a == [1])}
def f; yield *[]; end; f {|*a| test_ok(a == [])}
def f; yield *[1]; end; f {|*a| test_ok(a == [1])}
def f; yield *[nil]; end; f {|*a| test_ok(a == [nil])}
@@ -192,6 +159,8 @@ def f; yield [*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield [*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
def f; yield [*[1,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,2,[]])}
+def f; yield *nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield *1; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
def f; yield *[]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield *[1]; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
def f; yield *[nil]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
@@ -211,40 +180,58 @@ def r; return [*[]]; end; a = r(); test_ok(a == [])
def r; return [*[1]]; end; a = r(); test_ok(a == [1])
def r; return [*[1,2]]; end; a = r(); test_ok(a == [1,2])
-def r; return *[]; end; a = r(); test_ok(a == [])
-def r; return *[1]; end; a = r(); test_ok(a == [1])
-def r; return *[nil]; end; a = r(); test_ok(a == [nil])
-def r; return *[[]]; end; a = r(); test_ok(a == [[]])
-def r; return *[*[]]; end; a = r(); test_ok(a == [])
-def r; return *[*[1]]; end; a = r(); test_ok(a == [1])
+def r; return *nil; end; a = r(); test_ok(a == nil)
+def r; return *1; end; a = r(); test_ok(a == 1)
+def r; return *[]; end; a = r(); test_ok(a == nil)
+def r; return *[1]; end; a = r(); test_ok(a == 1)
+def r; return *[nil]; end; a = r(); test_ok(a == nil)
+def r; return *[[]]; end; a = r(); test_ok(a == [])
+def r; return *[*[]]; end; a = r(); test_ok(a == nil)
+def r; return *[*[1]]; end; a = r(); test_ok(a == 1)
def r; return *[*[1,2]]; end; a = r(); test_ok(a == [1,2])
-def r; return *[[]]; end; a = *r(); test_ok(a == [[]])
+def r; return *nil; end; a = *r(); test_ok(a == nil)
+def r; return *1; end; a = *r(); test_ok(a == 1)
+def r; return *[]; end; a = *r(); test_ok(a == nil)
+def r; return *[1]; end; a = *r(); test_ok(a == 1)
+def r; return *[nil]; end; a = *r(); test_ok(a == nil)
+def r; return *[[]]; end; a = *r(); test_ok(a == nil)
+def r; return *[*[]]; end; a = *r(); test_ok(a == nil)
+def r; return *[*[1]]; end; a = *r(); test_ok(a == 1)
def r; return *[*[1,2]]; end; a = *r(); test_ok(a == [1,2])
def r; return; end; *a = r(); test_ok(a == [nil])
def r; return nil; end; *a = r(); test_ok(a == [nil])
def r; return 1; end; *a = r(); test_ok(a == [1])
-def r; return []; end; *a = r(); test_ok(a == [])
-def r; return [1]; end; *a = r(); test_ok(a == [1])
-def r; return [nil]; end; *a = r(); test_ok(a == [nil])
-def r; return [[]]; end; *a = r(); test_ok(a == [[]])
-def r; return [1,2]; end; *a = r(); test_ok(a == [1,2])
-def r; return [*[]]; end; *a = r(); test_ok(a == [])
-def r; return [*[1]]; end; *a = r(); test_ok(a == [1])
-def r; return [*[1,2]]; end; *a = r(); test_ok(a == [1,2])
-
-def r; return *[]; end; *a = r(); test_ok(a == [])
+def r; return []; end; *a = r(); test_ok(a == [[]])
+def r; return [1]; end; *a = r(); test_ok(a == [[1]])
+def r; return [nil]; end; *a = r(); test_ok(a == [[nil]])
+def r; return [[]]; end; *a = r(); test_ok(a == [[[]]])
+def r; return [1,2]; end; *a = r(); test_ok(a == [[1,2]])
+def r; return [*[]]; end; *a = r(); test_ok(a == [[]])
+def r; return [*[1]]; end; *a = r(); test_ok(a == [[1]])
+def r; return [*[1,2]]; end; *a = r(); test_ok(a == [[1,2]])
+
+def r; return *nil; end; *a = r(); test_ok(a == [nil])
+def r; return *1; end; *a = r(); test_ok(a == [1])
+def r; return *[]; end; *a = r(); test_ok(a == [nil])
def r; return *[1]; end; *a = r(); test_ok(a == [1])
def r; return *[nil]; end; *a = r(); test_ok(a == [nil])
def r; return *[[]]; end; *a = r(); test_ok(a == [[]])
-def r; return *[1,2]; end; *a = r(); test_ok(a == [1,2])
-def r; return *[*[]]; end; *a = r(); test_ok(a == [])
+def r; return *[1,2]; end; *a = r(); test_ok(a == [[1,2]])
+def r; return *[*[]]; end; *a = r(); test_ok(a == [nil])
def r; return *[*[1]]; end; *a = r(); test_ok(a == [1])
-def r; return *[*[1,2]]; end; *a = r(); test_ok(a == [1,2])
-
-def r; return *[[]]; end; *a = *r(); test_ok(a == [[]])
+def r; return *[*[1,2]]; end; *a = r(); test_ok(a == [[1,2]])
+
+def r; return *nil; end; *a = *r(); test_ok(a == [nil])
+def r; return *1; end; *a = *r(); test_ok(a == [1])
+def r; return *[]; end; *a = *r(); test_ok(a == [nil])
+def r; return *[1]; end; *a = *r(); test_ok(a == [1])
+def r; return *[nil]; end; *a = *r(); test_ok(a == [nil])
+def r; return *[[]]; end; *a = *r(); test_ok(a == [])
def r; return *[1,2]; end; *a = *r(); test_ok(a == [1,2])
+def r; return *[*[]]; end; *a = *r(); test_ok(a == [nil])
+def r; return *[*[1]]; end; *a = *r(); test_ok(a == [1])
def r; return *[*[1,2]]; end; *a = *r(); test_ok(a == [1,2])
def r; return; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]])
@@ -259,10 +246,12 @@ def r; return [*[]]; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]])
def r; return [*[1]]; end; a,b,*c = r(); test_ok([a,b,c] == [1,nil,[]])
def r; return [*[1,2]]; end; a,b,*c = r(); test_ok([a,b,c] == [1,2,[]])
+def r; return *nil; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]])
+def r; return *1; end; a,b,*c = r(); test_ok([a,b,c] == [1,nil,[]])
def r; return *[]; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]])
def r; return *[1]; end; a,b,*c = r(); test_ok([a,b,c] == [1,nil,[]])
def r; return *[nil]; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]])
-def r; return *[[]]; end; a,b,*c = r(); test_ok([a,b,c] == [[],nil,[]])
+def r; return *[[]]; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]])
def r; return *[1,2]; end; a,b,*c = r(); test_ok([a,b,c] == [1,2,[]])
def r; return *[*[]]; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]])
def r; return *[*[1]]; end; a,b,*c = r(); test_ok([a,b,c] == [1,nil,[]])
@@ -318,37 +307,48 @@ a = loop do break [*[]]; end; test_ok(a == [])
a = loop do break [*[1]]; end; test_ok(a == [1])
a = loop do break [*[1,2]]; end; test_ok(a == [1,2])
-a = loop do break *[]; end; test_ok(a == [])
-a = loop do break *[1]; end; test_ok(a == [1])
-a = loop do break *[nil]; end; test_ok(a == [nil])
-a = loop do break *[[]]; end; test_ok(a == [[]])
-a = loop do break *[*[]]; end; test_ok(a == [])
-a = loop do break *[*[1]]; end; test_ok(a == [1])
+a = loop do break *nil; end; test_ok(a == nil)
+a = loop do break *1; end; test_ok(a == 1)
+a = loop do break *[]; end; test_ok(a == nil)
+a = loop do break *[1]; end; test_ok(a == 1)
+a = loop do break *[nil]; end; test_ok(a == nil)
+a = loop do break *[[]]; end; test_ok(a == [])
+a = loop do break *[*[]]; end; test_ok(a == nil)
+a = loop do break *[*[1]]; end; test_ok(a == 1)
a = loop do break *[*[1,2]]; end; test_ok(a == [1,2])
*a = loop do break; end; test_ok(a == [nil])
*a = loop do break nil; end; test_ok(a == [nil])
*a = loop do break 1; end; test_ok(a == [1])
-*a = loop do break []; end; test_ok(a == [])
-*a = loop do break [1]; end; test_ok(a == [1])
-*a = loop do break [nil]; end; test_ok(a == [nil])
-*a = loop do break [[]]; end; test_ok(a == [[]])
-*a = loop do break [1,2]; end; test_ok(a == [1,2])
-*a = loop do break [*[]]; end; test_ok(a == [])
-*a = loop do break [*[1]]; end; test_ok(a == [1])
-*a = loop do break [*[1,2]]; end; test_ok(a == [1,2])
-
-*a = loop do break *[]; end; test_ok(a == [])
+*a = loop do break []; end; test_ok(a == [[]])
+*a = loop do break [1]; end; test_ok(a == [[1]])
+*a = loop do break [nil]; end; test_ok(a == [[nil]])
+*a = loop do break [[]]; end; test_ok(a == [[[]]])
+*a = loop do break [1,2]; end; test_ok(a == [[1,2]])
+*a = loop do break [*[]]; end; test_ok(a == [[]])
+*a = loop do break [*[1]]; end; test_ok(a == [[1]])
+*a = loop do break [*[1,2]]; end; test_ok(a == [[1,2]])
+
+*a = loop do break *nil; end; test_ok(a == [nil])
+*a = loop do break *1; end; test_ok(a == [1])
+*a = loop do break *[]; end; test_ok(a == [nil])
*a = loop do break *[1]; end; test_ok(a == [1])
*a = loop do break *[nil]; end; test_ok(a == [nil])
*a = loop do break *[[]]; end; test_ok(a == [[]])
-*a = loop do break *[1,2]; end; test_ok(a == [1,2])
-*a = loop do break *[*[]]; end; test_ok(a == [])
+*a = loop do break *[1,2]; end; test_ok(a == [[1,2]])
+*a = loop do break *[*[]]; end; test_ok(a == [nil])
*a = loop do break *[*[1]]; end; test_ok(a == [1])
-*a = loop do break *[*[1,2]]; end; test_ok(a == [1,2])
-
-*a = *loop do break *[[]]; end; test_ok(a == [[]])
+*a = loop do break *[*[1,2]]; end; test_ok(a == [[1,2]])
+
+*a = *loop do break *nil; end; test_ok(a == [nil])
+*a = *loop do break *1; end; test_ok(a == [1])
+*a = *loop do break *[]; end; test_ok(a == [nil])
+*a = *loop do break *[1]; end; test_ok(a == [1])
+*a = *loop do break *[nil]; end; test_ok(a == [nil])
+*a = *loop do break *[[]]; end; test_ok(a == [])
*a = *loop do break *[1,2]; end; test_ok(a == [1,2])
+*a = *loop do break *[*[]]; end; test_ok(a == [nil])
+*a = *loop do break *[*[1]]; end; test_ok(a == [1])
*a = *loop do break *[*[1,2]]; end; test_ok(a == [1,2])
a,b,*c = loop do break; end; test_ok([a,b,c] == [nil,nil,[]])
@@ -363,10 +363,12 @@ a,b,*c = loop do break [*[]]; end; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = loop do break [*[1]]; end; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = loop do break [*[1,2]]; end; test_ok([a,b,c] == [1,2,[]])
+a,b,*c = loop do break *nil; end; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = loop do break *1; end; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = loop do break *[]; end; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = loop do break *[1]; end; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = loop do break *[nil]; end; test_ok([a,b,c] == [nil,nil,[]])
-a,b,*c = loop do break *[[]]; end; test_ok([a,b,c] == [[],nil,[]])
+a,b,*c = loop do break *[[]]; end; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = loop do break *[1,2]; end; test_ok([a,b,c] == [1,2,[]])
a,b,*c = loop do break *[*[]]; end; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = loop do break *[*[1]]; end; test_ok([a,b,c] == [1,nil,[]])
@@ -384,30 +386,39 @@ r([]){next [*[]]}
r([1]){next [*[1]]}
r([1,2]){next [*[1,2]]}
-r([]){next *[]}
-r([1]){next *[1]}
-r([nil]){next *[nil]}
-r([[]]){next *[[]]}
-r([]){next *[*[]]}
-r([1]){next *[*[1]]}
+r(nil){next *nil}
+r(1){next *1}
+r(nil){next *[]}
+r(1){next *[1]}
+r(nil){next *[nil]}
+r([]){next *[[]]}
+r(nil){next *[*[]]}
+r(1){next *[*[1]]}
r([1,2]){next *[*[1,2]]}
def r(val); *a = yield(); test_ok(a == val, 2); end
r([nil]){next}
r([nil]){next nil}
r([1]){next 1}
-r([]){next []}
-r([1]){next [1]}
-r([nil]){next [nil]}
-r([[]]){next [[]]}
-r([1,2]){next [1,2]}
-r([]){next [*[]]}
-r([1]){next [*[1]]}
-r([1,2]){next [*[1,2]]}
+r([[]]){next []}
+r([[1]]){next [1]}
+r([[nil]]){next [nil]}
+r([[[]]]){next [[]]}
+r([[1,2]]){next [1,2]}
+r([[]]){next [*[]]}
+r([[1]]){next [*[1]]}
+r([[1,2]]){next [*[1,2]]}
def r(val); *a = *yield(); test_ok(a == val, 2); end
-r([[]]){next *[[]]}
+r([nil]){next *nil}
+r([1]){next *1}
+r([nil]){next *[]}
+r([1]){next *[1]}
+r([nil]){next *[nil]}
+r([]){next *[[]]}
r([1,2]){next *[1,2]}
+r([nil]){next *[*[]]}
+r([1]){next *[*[1]]}
r([1,2]){next *[*[1,2]]}
def r(val); a,b,*c = yield(); test_ok([a,b,c] == val, 2); end
@@ -424,8 +435,15 @@ r([1,nil,[]]){next [*[1]]}
r([1,2,[]]){next [*[1,2]]}
def r(val); a,b,*c = *yield(); test_ok([a,b,c] == val, 2); end
-r([[],nil,[]]){next *[[]]}
+r([nil,nil,[]]){next *nil}
+r([1,nil,[]]){next *1}
+r([nil,nil,[]]){next *[]}
+r([1,nil,[]]){next *[1]}
+r([nil,nil,[]]){next *[nil]}
+r([nil,nil,[]]){next *[[]]}
r([1,2,[]]){next *[1,2]}
+r([nil,nil,[]]){next *[*[]]}
+r([1,nil,[]]){next *[*[1]]}
r([1,2,[]]){next *[*[1,2]]}
test_check "condition"
@@ -522,15 +540,15 @@ tmp.close
# test redo
$bad = false
tmp = open("while_tmp", "r")
-while line = tmp.gets()
- lastline = line
- line = line.gsub(/vt100/, 'VT100')
- if lastline != line
- line.gsub!('VT100', 'Vt100')
+while tmp.gets()
+ line = $_
+ gsub(/vt100/, 'VT100')
+ if $_ != line
+ $_.gsub!('VT100', 'Vt100')
redo
end
- $bad = 1 if /vt100/ =~ line
- $bad = 1 if /VT100/ =~ line
+ $bad = 1 if /vt100/ =~ $_
+ $bad = 1 if /VT100/ =~ $_
end
test_ok(tmp.eof? && !$bad)
tmp.close
@@ -846,9 +864,8 @@ def tt
}
end
-i=0
tt{|i| break if i == 5}
-test_ok(i == 0)
+test_ok(i == 5)
def tt2(dummy)
yield 1
@@ -963,41 +980,35 @@ test_ok(IterTest.new(nil).method(:f).to_proc.call([m]) == [m])
IterTest.new([0]).each0 {|x| test_ok(x == 0)}
IterTest.new([1]).each1 {|x| test_ok(x == 1)}
IterTest.new([2]).each2 {|x| test_ok(x == [2])}
-#IterTest.new([3]).each3 {|x| test_ok(x == 3)}
+IterTest.new([3]).each3 {|x| test_ok(x == 3)}
IterTest.new([4]).each4 {|x| test_ok(x == 4)}
-IterTest.new([5]).each5 {|x| test_ok(x == [5])}
+IterTest.new([5]).each5 {|x| test_ok(x == 5)}
IterTest.new([6]).each6 {|x| test_ok(x == [6])}
-#IterTest.new([7]).each7 {|x| test_ok(x == 7)}
+IterTest.new([7]).each7 {|x| test_ok(x == 7)}
IterTest.new([8]).each8 {|x| test_ok(x == 8)}
IterTest.new([[0]]).each0 {|x| test_ok(x == [0])}
-IterTest.new([[1]]).each1 {|x| test_ok(x == 1)}
-IterTest.new([[2]]).each2 {|x| test_ok(x == [2])}
+IterTest.new([[1]]).each1 {|x| test_ok(x == [1])}
+IterTest.new([[2]]).each2 {|x| test_ok(x == [[2]])}
IterTest.new([[3]]).each3 {|x| test_ok(x == 3)}
IterTest.new([[4]]).each4 {|x| test_ok(x == [4])}
IterTest.new([[5]]).each5 {|x| test_ok(x == [5])}
-IterTest.new([[6]]).each6 {|x| test_ok(x == [6])}
-IterTest.new([[7]]).each7 {|x| test_ok(x == [7])}
+IterTest.new([[6]]).each6 {|x| test_ok(x == [[6]])}
+IterTest.new([[7]]).each7 {|x| test_ok(x == 7)}
IterTest.new([[8]]).each8 {|x| test_ok(x == [8])}
-IterTest.new([[0,0]]).each0 {|*x| test_ok(x == [0,0])}
-IterTest.new([[8,8]]).each8 {|*x| test_ok(x == [8,8])}
-
-def m0(v)
- v
-end
+IterTest.new([[0,0]]).each0 {|x| test_ok(x == [0,0])}
+IterTest.new([[8,8]]).each8 {|x| test_ok(x == [8,8])}
-def m1
- m0(block_given?)
+def m
+ test_ok(block_given?)
end
-test_ok(m1{p 'test'})
-test_ok(!m1)
+m{p 'test'}
def m
- m0(block_given?,&Proc.new{})
+ test_ok(block_given?,&proc{})
end
-test_ok(m1{p 'test'})
-test_ok(!m1)
+m{p 'test'}
class C
include Enumerable
@@ -1021,7 +1032,7 @@ end
block_test(NilClass)
block_test(Proc){}
-def call_argument_test(state, proc, *args)
+def argument_test(state, proc, *args)
x = state
begin
proc.call(*args)
@@ -1031,56 +1042,47 @@ def call_argument_test(state, proc, *args)
test_ok(x,2)
end
-call_argument_test(true, lambda{||})
-call_argument_test(false, lambda{||}, 1)
-call_argument_test(true, lambda{|a,|}, 1)
-call_argument_test(false, lambda{|a,|})
-call_argument_test(false, lambda{|a,|}, 1,2)
-
-call_argument_test(true, Proc.new{||})
-call_argument_test(true, Proc.new{||}, 1)
-call_argument_test(true, Proc.new{|a,|}, 1)
-call_argument_test(true, Proc.new{|a,|})
-call_argument_test(true, Proc.new{|a,|}, 1,2)
+argument_test(true, lambda{||})
+argument_test(false, lambda{||}, 1)
+argument_test(true, lambda{|a,|}, 1)
+argument_test(false, lambda{|a,|})
+argument_test(false, lambda{|a,|}, 1,2)
-def block_get(&block)
+def get_block(&block)
block
end
-test_ok(Proc == block_get{}.class)
-call_argument_test(true, block_get{||})
-call_argument_test(true, block_get{||}, 1)
-call_argument_test(true, block_get{|a,|}, 1)
-call_argument_test(true, block_get{|a,|})
-call_argument_test(true, block_get{|a,|}, 1,2)
-
-call_argument_test(true, block_get(&lambda{||}))
-call_argument_test(false, block_get(&lambda{||}),1)
-call_argument_test(true, block_get(&lambda{|a,|}),1)
-call_argument_test(false, block_get(&lambda{|a,|}),1,2)
+test_ok(Proc == get_block{}.class)
+argument_test(true, get_block{||})
+argument_test(true, get_block{||}, 1)
+argument_test(true, get_block{|a,|}, 1)
+argument_test(true, get_block{|a,|})
+argument_test(true, get_block{|a,|}, 1,2)
-blk = block_get{11}
-test_ok(blk.class == Proc)
-test_ok(blk.to_proc.class == Proc)
-test_ok(blk.clone.call == 11)
-test_ok(block_get(&blk).class == Proc)
+argument_test(true, get_block(&lambda{||}))
+argument_test(false, get_block(&lambda{||}),1)
+argument_test(true, get_block(&lambda{|a,|}),1)
+argument_test(false, get_block(&lambda{|a,|}),1,2)
-lmd = lambda{44}
-test_ok(lmd.class == Proc)
-test_ok(lmd.to_proc.class == Proc)
-test_ok(lmd.clone.call == 44)
-test_ok(block_get(&lmd).class == Proc)
+block = get_block{11}
+test_ok(block.class == Proc)
+test_ok(block.to_proc.class == Proc)
+test_ok(block.clone.call == 11)
+test_ok(get_block(&block).class == Proc)
-test_ok(Proc.new{|a,| a}.yield(1,2,3) == 1)
-call_argument_test(true, Proc.new{|a,|}, 1,2)
+lambda = lambda{44}
+test_ok(lambda.class == Proc)
+test_ok(lambda.to_proc.class == Proc)
+test_ok(lambda.clone.call == 44)
+test_ok(get_block(&lambda).class == Proc)
-test_ok(Proc.new{|&b| b.call(10)}.call {|x| x} == 10)
-test_ok(Proc.new{|a,&b| b.call(a)}.call(12) {|x| x} == 12)
+test_ok(Proc.new{|a,| a}.call(1,2,3) == 1)
+argument_test(true, Proc.new{|a,|}, 1,2)
def test_return1
Proc.new {
return 55
- }.yield + 5
+ }.call + 5
end
test_ok(test_return1() == 55)
def test_return2
@@ -1097,23 +1099,15 @@ def proc_yield()
yield
end
def proc_return1
- lambda{return 42}.call+1
-end
-test_ok(proc_return1() == 43)
-def proc_return2
- ->{return 42}.call+1
-end
-test_ok(proc_return2() == 43)
-def proc_return3
proc_call{return 42}+1
end
-test_ok(proc_return3() == 42)
-def proc_return4
+test_ok(proc_return1() == 42)
+def proc_return2
proc_yield{return 42}+1
end
-test_ok(proc_return4() == 42)
+test_ok(proc_return2() == 42)
-def ljump_test(state, proc, *args)
+def ljump_test(state, proc, *args)
x = state
begin
proc.call(*args)
@@ -1123,165 +1117,26 @@ def ljump_test(state, proc, *args)
test_ok(x,2)
end
-ljump_test(false, block_get{break})
+ljump_test(false, get_block{break})
ljump_test(true, lambda{break})
-def exit_value_test(&block)
- block.call
-rescue LocalJumpError
- $!.exit_value
-end
-
-test_ok(45 == exit_value_test{break 45})
-
-test_ok(55 == begin
- block_get{break 55}.call
- rescue LocalJumpError
- $!.exit_value
- end)
-
-def block_call(&block)
- block.call
-end
-
-def test_b1
- block_call{break 11}
-end
-test_ok(test_b1() == 11)
-
-def ljump_rescue(r)
- begin
- yield
- rescue LocalJumpError => e
- r if /from proc-closure/ =~ e.message
- end
-end
-
-def test_b2
- ljump_rescue(22) do
- block_get{break 21}.call
- end
-end
-test_ok(test_b2() == 22)
-
-def test_b3
- ljump_rescue(33) do
- Proc.new{break 31}.yield
- end
-end
-test_ok(test_b3() == 33)
-
-def test_b4
- lambda{break 44}.call
-end
-test_ok(test_b4() == 44)
-
-def test_b5
- ljump_rescue(55) do
- b = block_get{break 54}
- block_call(&b)
- end
-end
-test_ok(test_b5() == 55)
-
-def test_b6
- b = lambda{break 67}
- block_call(&b)
- 66
-end
-test_ok(test_b6() == 66)
-
-def util_r7
- block_get{break 78}
-end
-
-def test_b7
- b = util_r7()
- ljump_rescue(77) do
- block_call(&b)
- end
-end
-test_ok(test_b7() == 77)
-
-def util_b8(&block)
- block_call(&block)
-end
-
-def test_b8
- util_b8{break 88}
-end
-test_ok(test_b8() == 88)
-
-def util_b9(&block)
- lambda{block.call; 98}.call
-end
-
-def test_b9
- util_b9{break 99}
-end
-test_ok(test_b9() == 99)
-
-def util_b10
- util_b9{break 100}
-end
-
-def test_b10
- util_b10()
-end
-test_ok(test_b10() == 100)
-
-def test_b11
- ljump_rescue(111) do
- loop do
- Proc.new{break 110}.yield
- break 112
- end
- end
-end
-test_ok(test_b11() == 111)
-
-def test_b12
- loop do
- break lambda{break 122}.call
- break 121
- end
-end
-test_ok(test_b12() == 122)
-
-def test_b13
- ljump_rescue(133) do
- while true
- Proc.new{break 130}.yield
- break 131
- end
- end
-end
-test_ok(test_b13() == 133)
-
-def test_b14
- while true
- break lambda{break 144}.call
- break 143
- end
-end
-test_ok(test_b14() == 144)
-
-def test_b15
- [0].each {|c| yield 1 }
- 156
-end
-test_ok(test_b15{|e| break 155 } == 155)
+test_ok(block.arity == -1)
+test_ok(lambda.arity == -1)
+test_ok(lambda{||}.arity == 0)
+test_ok(lambda{|a|}.arity == 1)
+test_ok(lambda{|a,|}.arity == 1)
+test_ok(lambda{|a,b|}.arity == 2)
def marity_test(m)
method = method(m)
- test_ok(method.arity == method.to_proc.arity, 2)
+ test_ok(method.arity == method.to_proc.arity)
end
marity_test(:test_ok)
marity_test(:marity_test)
marity_test(:p)
lambda(&method(:test_ok)).call(true)
-lambda(&block_get{|a,n| test_ok(a,n)}).call(true, 2)
+lambda(&get_block{|a,n| test_ok(a,n)}).call(true, 2)
class ITER_TEST1
def a
@@ -1313,37 +1168,6 @@ end
ITER_TEST4.new.foo(44){55}
-class ITER_TEST5
- def tt(aa)
- aa
- end
-
- def uu(a)
- class << self
- define_method(:tt) do |sym|
- super(sym)
- end
- end
- end
-
- def xx(*x)
- x.size
- end
-end
-
-a = ITER_TEST5.new
-a.uu(12)
-test_ok(a.tt(1) == 1)
-
-class ITER_TEST6 < ITER_TEST5
- def xx(*a)
- a << 12
- super
- end
-end
-
-test_ok(ITER_TEST6.new.xx([24]) == 2)
-
test_check "float"
test_ok(2.6.floor == 2)
test_ok((-2.6).floor == -3)
@@ -1434,6 +1258,7 @@ $good = true;
for i in 4000..4096
n1 = 1 << i;
if (n1**2-1) / (n1+1) != (n1-1)
+ p i
$good = false
end
end
@@ -1537,9 +1362,9 @@ test_ok($x.sub(/.*\.([^\.]+)$/, '<\&>') == "<a.gif>")
# character constants(assumes ASCII)
test_ok("a"[0] == ?a)
test_ok(?a == ?a)
-test_ok(?\C-a == "\1")
-test_ok(?\M-a == "\341")
-test_ok(?\M-\C-a == "\201")
+test_ok(?\C-a == 1)
+test_ok(?\M-a == 225)
+test_ok(?\M-\C-a == 129)
test_ok("a".upcase![0] == ?A)
test_ok("A".downcase![0] == ?a)
test_ok("abc".tr!("a-z", "A-Z") == "ABC")
@@ -1551,7 +1376,7 @@ $x = "abcdef"
$y = [ ?a, ?b, ?c, ?d, ?e, ?f ]
$bad = false
$x.each_byte {|i|
- if i.chr != $y.shift
+ if i != $y.shift
$bad = true
break
end
@@ -1640,20 +1465,20 @@ test_ok(aaa(1, 2, 3, 4) == [1, 2, 3, 4])
test_ok(aaa(1, *[2, 3, 4]) == [1, 2, 3, 4])
test_check "proc"
-$proc = Proc.new{|i| i}
+$proc = proc{|i| i}
test_ok($proc.call(2) == 2)
test_ok($proc.call(3) == 3)
-$proc = Proc.new{|i| i*2}
+$proc = proc{|i| i*2}
test_ok($proc.call(2) == 4)
test_ok($proc.call(3) == 6)
-Proc.new{
+proc{
iii=5 # nested local variable
- $proc = Proc.new{|i|
+ $proc = proc{|i|
iii = i
}
- $proc2 = Proc.new {
+ $proc2 = proc {
$x = iii # nested variables shared by procs
}
# scope of nested variables
@@ -1682,12 +1507,12 @@ if defined? Process.kill
test_check "signal"
$x = 0
- trap "SIGINT", Proc.new{|sig| $x = 2}
+ trap "SIGINT", proc{|sig| $x = 2}
Process.kill "SIGINT", $$
sleep 0.1
test_ok($x == 2)
- trap "SIGINT", Proc.new{raise "Interrupt"}
+ trap "SIGINT", proc{raise "Interrupt"}
x = false
begin
@@ -1761,51 +1586,51 @@ rescue NameError # must raise error
end
test_ok(!$bad)
-x = Proc.new{}
+x = proc{}
eval "i4 = 1", x
test_ok(eval("i4", x) == 1)
-x = Proc.new{Proc.new{}}.call
+x = proc{proc{}}.call
eval "i4 = 22", x
test_ok(eval("i4", x) == 22)
$x = []
-x = Proc.new{Proc.new{}}.call
-eval "(0..9).each{|i5| $x[i5] = Proc.new{i5*2}}", x
+x = proc{proc{}}.call
+eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x
test_ok($x[4].call == 8)
x = binding
eval "i = 1", x
test_ok(eval("i", x) == 1)
-x = Proc.new{binding}.call
+x = proc{binding}.call
eval "i = 22", x
test_ok(eval("i", x) == 22)
$x = []
-x = Proc.new{binding}.call
-eval "(0..9).each{|i5| $x[i5] = Proc.new{i5*2}}", x
+x = proc{binding}.call
+eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x
test_ok($x[4].call == 8)
-x = Proc.new{binding}.call
+x = proc{binding}.call
eval "for i6 in 1..1; j6=i6; end", x
test_ok(eval("defined? i6", x))
test_ok(eval("defined? j6", x))
-Proc.new {
+proc {
p = binding
eval "foo11 = 1", p
foo22 = 5
- Proc.new{foo11=22}.call
- Proc.new{foo22=55}.call
+ proc{foo11=22}.call
+ proc{foo22=55}.call
test_ok(eval("foo11", p) == eval("foo11"))
test_ok(eval("foo11") == 1)
test_ok(eval("foo22", p) == eval("foo22"))
test_ok(eval("foo22") == 55)
}.call
-p1 = Proc.new{i7 = 0; Proc.new{i7}}.call
+p1 = proc{i7 = 0; proc{i7}}.call
test_ok(p1.call == 0)
eval "i7=5", p1
test_ok(p1.call == 5)
test_ok(!defined?(i7))
-p1 = Proc.new{i7 = 0; Proc.new{i7}}.call
+p1 = proc{i7 = 0; proc{i7}}.call
i7 = nil
test_ok(p1.call == 0)
eval "i7=1", p1
@@ -1840,7 +1665,7 @@ tmp.print "__END__\n";
tmp.print "this is a trailing junk\n";
tmp.close
-test_ok(`./miniruby -x script_tmp` == '')
+test_ok(`./miniruby -x script_tmp` == 'nil')
test_ok(`./miniruby -x script_tmp -zzz=555` == '555')
tmp = open("script_tmp", "w")
@@ -1849,7 +1674,7 @@ for i in 1..5
end
tmp.close
-`./miniruby -i.bak -pe '$_.sub!(/^[0-9]+$/){$&.to_i * 5}' script_tmp`
+`./miniruby -i.bak -pe 'sub(/^[0-9]+$/){$&.to_i * 5}' script_tmp`
done = true
tmp = open("script_tmp", "r")
while tmp.gets
@@ -1872,7 +1697,10 @@ else
end
def valid_syntax?(code, fname)
- eval("BEGIN {return true}\n#{code}", nil, fname, 0)
+ code = code.sub(/\A(?:\s*\#.*$)*(\n)?/n) {
+ "#$&#{"\n" if $1 && !$2}BEGIN{return true}\n"
+ }
+ eval(code, nil, fname, 0)
rescue Exception
puts $!.message
false
@@ -2011,7 +1839,7 @@ $_ = foobar
test_ok($_ == foobar)
class Gods
- @@rule = "Uranus" # private to Gods
+ @@rule = "Uranus"
def ruler0
@@rule
end
@@ -2027,34 +1855,30 @@ class Gods
end
module Olympians
- @@rule ="Zeus"
- def ruler3
+ @@rule ="Zeus"
+ def ruler3
@@rule
end
end
class Titans < Gods
- @@rule = "Cronus" # do not affect @@rule in Gods
- include Olympians
- def ruler4
- @@rule
- end
+ @@rule = "Cronus"
+ include Olympians # OK to cause warning (intentional)
end
-test_ok(Gods.new.ruler0 == "Uranus")
-test_ok(Gods.ruler1 == "Uranus")
-test_ok(Gods.ruler2 == "Uranus")
-test_ok(Titans.ruler1 == "Uranus")
-test_ok(Titans.ruler2 == "Uranus")
+test_ok(Gods.new.ruler0 == "Cronus")
+test_ok(Gods.ruler1 == "Cronus")
+test_ok(Gods.ruler2 == "Cronus")
+test_ok(Titans.ruler1 == "Cronus")
+test_ok(Titans.ruler2 == "Cronus")
atlas = Titans.new
-test_ok(atlas.ruler0 == "Uranus")
+test_ok(atlas.ruler0 == "Cronus")
test_ok(atlas.ruler3 == "Zeus")
-test_ok(atlas.ruler4 == "Cronus")
test_check "trace"
$x = 1234
$y = 0
-trace_var :$x, Proc.new{$y = $x}
+trace_var :$x, proc{$y = $x}
$x = 40414
test_ok($y == $x)
@@ -2062,7 +1886,7 @@ untrace_var :$x
$x = 19660208
test_ok($y != $x)
-trace_var :$x, Proc.new{$x *= 2}
+trace_var :$x, proc{$x *= 2}
$x = 5
test_ok($x == 10)
diff --git a/signal.c b/signal.c
index 4b154b8301..b6cad9dc84 100644
--- a/signal.c
+++ b/signal.c
@@ -21,6 +21,12 @@
#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
@@ -30,7 +36,7 @@
#endif
static struct signals {
- const char *signm;
+ char *signm;
int signo;
} siglist [] = {
{"EXIT", 0},
@@ -169,7 +175,8 @@ static struct signals {
};
static int
-signm2signo(const char *nm)
+signm2signo(nm)
+ const char *nm;
{
struct signals *sigs;
@@ -179,8 +186,9 @@ signm2signo(const char *nm)
return 0;
}
-static const char*
-signo2signm(int no)
+static char*
+signo2signm(no)
+ int no;
{
struct signals *sigs;
@@ -191,12 +199,100 @@ signo2signm(int no)
}
const char *
-ruby_signal_name(int no)
+ruby_signal_name(no)
+ int no;
{
return signo2signm(no);
}
/*
+ * call-seq:
+ * SignalException.new(sig) => signal_exception
+ *
+ * Construct a new SignalException object. +sig+ should be a known
+ * signal name, or a signal number.
+ */
+
+static VALUE
+esignal_init(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ int argnum = 1;
+ VALUE sig = Qnil;
+ int signo;
+ const char *signm;
+ char tmpnm[(sizeof(int)*CHAR_BIT)/3+4];
+
+ if (argc > 0) {
+ sig = argv[0];
+ if (FIXNUM_P(sig)) argnum = 2;
+ }
+ if (argc < 1 || argnum < argc) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
+ argc, argnum);
+ }
+ if (argnum == 2) {
+ signo = FIX2INT(sig);
+ if (signo < 0 || signo > NSIG) {
+ rb_raise(rb_eArgError, "invalid signal number (%d)", signo);
+ }
+ if (argc > 1) {
+ sig = argv[1];
+ }
+ else {
+ signm = signo2signm(signo);
+ if (signm) {
+ snprintf(tmpnm, sizeof(tmpnm), "SIG%s", signm);
+ }
+ else {
+ snprintf(tmpnm, sizeof(tmpnm), "SIG%u", signo);
+ }
+ sig = rb_str_new2(signm = tmpnm);
+ }
+ }
+ else {
+ signm = SYMBOL_P(sig) ? rb_id2name(SYM2ID(sig)) : StringValuePtr(sig);
+ if (strncmp(signm, "SIG", 3) == 0) signm += 3;
+ signo = signm2signo(signm);
+ if (!signo) {
+ rb_raise(rb_eArgError, "unsupported name `SIG%s'", signm);
+ }
+ if (SYMBOL_P(sig)) {
+ sig = rb_str_new2(signm);
+ }
+ }
+ rb_call_super(1, &sig);
+ rb_iv_set(self, "signo", INT2NUM(signo));
+
+ return self;
+}
+
+static VALUE
+interrupt_init(self, mesg)
+ VALUE self, mesg;
+{
+ VALUE argv[2];
+
+ argv[0] = INT2FIX(SIGINT);
+ argv[1] = mesg;
+ return rb_call_super(2, argv);
+}
+
+void
+ruby_default_signal(sig)
+ int sig;
+{
+#ifndef MACOS_UNUSE_SIGNAL
+ extern rb_pid_t getpid _((void));
+
+ signal(sig, SIG_DFL);
+ kill(getpid(), sig);
+#endif
+}
+
+/*
* call-seq:
* Process.kill(signal, pid, ...) => fixnum
*
@@ -221,12 +317,14 @@ ruby_signal_name(int no)
*/
VALUE
-rb_f_kill(int argc, VALUE *argv)
+rb_f_kill(argc, argv)
+ int argc;
+ VALUE *argv;
{
int negative = 0;
int sig;
int i;
- const char *s;
+ char *s;
rb_secure(2);
if (argc < 2)
@@ -242,7 +340,7 @@ rb_f_kill(int argc, VALUE *argv)
goto str_signal;
case T_STRING:
- s = RSTRING_PTR(argv[0]);
+ s = RSTRING(argv[0])->ptr;
if (s[0] == '-') {
negative++;
s++;
@@ -263,7 +361,7 @@ rb_f_kill(int argc, VALUE *argv)
str = rb_check_string_type(argv[0]);
if (!NIL_P(str)) {
- s = RSTRING_PTR(str);
+ s = RSTRING(str)->ptr;
goto str_signal;
}
rb_raise(rb_eArgError, "bad signal type %s",
@@ -305,7 +403,7 @@ rb_atomic_t rb_trap_immediate;
int rb_prohibit_interrupt = 1;
void
-rb_gc_mark_trap_list(void)
+rb_gc_mark_trap_list()
{
#ifndef MACOS_UNUSE_SIGNAL
int i;
@@ -321,11 +419,13 @@ rb_gc_mark_trap_list(void)
#define sighandler_t sh_t
#endif
-typedef RETSIGTYPE (*sighandler_t)(int);
+typedef RETSIGTYPE (*sighandler_t)_((int));
#ifdef POSIX_SIGNAL
static sighandler_t
-ruby_signal(int signum, sighandler_t handler)
+ruby_signal(signum, handler)
+ int signum;
+ sighandler_t handler;
{
struct sigaction sigact, old;
@@ -334,23 +434,27 @@ ruby_signal(int signum, sighandler_t handler)
sigact.sa_handler = handler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
-#ifdef SA_NOCLDWAIT
+# ifdef SA_NOCLDWAIT
if (signum == SIGCHLD && handler == SIG_IGN)
sigact.sa_flags |= SA_NOCLDWAIT;
-#endif
+# endif
sigaction(signum, &sigact, &old);
return old.sa_handler;
}
void
-posix_signal(int signum, sighandler_t handler)
+posix_signal(signum, handler)
+ int signum;
+ sighandler_t handler;
{
ruby_signal(signum, handler);
}
-#ifdef HAVE_NATIVETHREAD
+# ifdef HAVE_NATIVETHREAD
static sighandler_t
-ruby_nativethread_signal(int signum, sighandler_t handler)
+ruby_nativethread_signal(signum, handler)
+ int signum;
+ sighandler_t handler;
{
sighandler_t old;
@@ -360,16 +464,22 @@ ruby_nativethread_signal(int signum, sighandler_t handler)
}
void
-posix_nativethread_signal(int signum, sighandler_t handler)
+posix_nativethread_signal(signum, handler)
+ int signum;
+ sighandler_t handler;
{
ruby_nativethread_signal(signum, handler);
}
-#endif
+# endif
+
#else /* !POSIX_SIGNAL */
#define ruby_signal(sig,handler) (rb_trap_accept_nativethreads[sig] = 0, signal((sig),(handler)))
-#ifdef HAVE_NATIVETHREAD
+
+# ifdef HAVE_NATIVETHREAD
static sighandler_t
-ruby_nativethread_signal(int signum, sighandler_t handler)
+ruby_nativethread_signal(signum, handler)
+ int signum;
+ sighandler_t handler;
{
sighandler_t old;
@@ -377,11 +487,13 @@ ruby_nativethread_signal(int signum, sighandler_t handler)
rb_trap_accept_nativethreads[signum] = 1;
return old;
}
-#endif
-#endif
+# endif
+#endif /* POSIX_SIGNAL */
+static void signal_exec _((int sig));
static void
-signal_exec(int sig)
+signal_exec(sig)
+ int sig;
{
if (trap_list[sig].cmd == 0) {
switch (sig) {
@@ -394,6 +506,9 @@ signal_exec(int sig)
#ifdef SIGQUIT
case SIGQUIT:
#endif
+#ifdef SIGTERM
+ case SIGTERM:
+#endif
#ifdef SIGALRM
case SIGALRM:
#endif
@@ -403,7 +518,7 @@ signal_exec(int sig)
#ifdef SIGUSR2
case SIGUSR2:
#endif
- rb_thread_signal_raise(signo2signm(sig));
+ rb_thread_signal_raise(sig);
break;
}
}
@@ -419,48 +534,52 @@ signal_exec(int sig)
static void
sigsend_to_ruby_thread(int sig)
{
-#ifdef HAVE_SIGPROCMASK
+# ifdef HAVE_SIGPROCMASK
sigset_t mask, old_mask;
-#else
+# else
int mask, old_mask;
-#endif
+# endif
-#ifdef HAVE_SIGPROCMASK
+# ifdef HAVE_SIGPROCMASK
sigfillset(&mask);
sigprocmask(SIG_BLOCK, &mask, &old_mask);
-#else
+# else
mask = sigblock(~0);
sigsetmask(mask);
-#endif
+# endif
ruby_native_thread_kill(sig);
}
#endif
+static RETSIGTYPE sighandler _((int));
static RETSIGTYPE
-sighandler(int sig)
+sighandler(sig)
+ int sig;
{
#ifdef _WIN32
#define IN_MAIN_CONTEXT(f, a) (rb_w32_main_context(a, f) ? (void)0 : f(a))
#else
#define IN_MAIN_CONTEXT(f, a) f(a)
#endif
+
if (sig >= NSIG) {
rb_bug("trap_handler: Bad signal %d", 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
@@ -471,12 +590,17 @@ sighandler(int sig)
else {
ATOMIC_INC(rb_trap_pending);
ATOMIC_INC(trap_pending_list[sig]);
+#ifdef _WIN32
+ rb_w32_interrupted();
+#endif
}
}
#ifdef SIGBUS
+static RETSIGTYPE sigbus _((int));
static RETSIGTYPE
-sigbus(int sig)
+sigbus(sig)
+ int sig;
{
#if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
@@ -490,8 +614,10 @@ sigbus(int sig)
#endif
#ifdef SIGSEGV
+static RETSIGTYPE sigsegv _((int));
static RETSIGTYPE
-sigsegv(int sig)
+sigsegv(sig)
+ int sig;
{
#if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
@@ -505,15 +631,17 @@ sigsegv(int sig)
#endif
#ifdef SIGPIPE
+static RETSIGTYPE sigpipe _((int));
static RETSIGTYPE
-sigpipe(int sig)
+sigpipe(sig)
+ int sig;
{
/* do nothing */
}
#endif
void
-rb_trap_exit(void)
+rb_trap_exit()
{
#ifndef MACOS_UNUSE_SIGNAL
if (trap_list[0].cmd) {
@@ -526,7 +654,7 @@ rb_trap_exit(void)
}
void
-rb_trap_exec(void)
+rb_trap_exec()
{
#ifndef MACOS_UNUSE_SIGNAL
int i;
@@ -542,7 +670,7 @@ rb_trap_exec(void)
}
struct trap_arg {
-#ifndef _WIN32
+#if USE_TRAP_MASK
# ifdef HAVE_SIGPROCMASK
sigset_t mask;
# else
@@ -558,56 +686,58 @@ static sigset_t trap_last_mask;
static int trap_last_mask;
# endif
+static RETSIGTYPE sigexit _((int));
+static RETSIGTYPE
+sigexit(sig)
+ int sig;
+{
+ rb_thread_signal_exit();
+}
+
static VALUE
-trap(struct trap_arg *arg)
+trap(arg)
+ struct trap_arg *arg;
{
sighandler_t func, oldfunc;
VALUE command, oldcmd;
int sig = -1;
- const char *s;
+ char *s;
func = sighandler;
- if (NIL_P(arg->cmd)) {
+ command = arg->cmd;
+ if (NIL_P(command)) {
func = SIG_IGN;
}
- else {
- command = rb_check_string_type(arg->cmd);
- if (!NIL_P(command)) {
- SafeStringValue(command); /* taint check */
- switch (RSTRING_LEN(command)) {
- case 0:
+ else if (TYPE(command) == T_STRING) {
+ SafeStringValue(command); /* taint check */
+ if (RSTRING(command)->len == 0) {
+ func = SIG_IGN;
+ }
+ else if (RSTRING(command)->len == 7) {
+ if (strncmp(RSTRING(command)->ptr, "SIG_IGN", 7) == 0) {
func = SIG_IGN;
- break;
- case 7:
- if (strncmp(RSTRING_PTR(command), "SIG_IGN", 7) == 0) {
- func = SIG_IGN;
- }
- else if (strncmp(RSTRING_PTR(command), "SIG_DFL", 7) == 0) {
- func = SIG_DFL;
- }
- else if (strncmp(RSTRING_PTR(command), "DEFAULT", 7) == 0) {
- func = SIG_DFL;
- }
- break;
- case 6:
- if (strncmp(RSTRING_PTR(command), "IGNORE", 6) == 0) {
- func = SIG_IGN;
- }
- break;
- case 4:
- if (strncmp(RSTRING_PTR(command), "EXIT", 4) == 0) {
- arg->cmd = Qundef;
- }
- break;
+ }
+ else if (strncmp(RSTRING(command)->ptr, "SIG_DFL", 7) == 0) {
+ func = SIG_DFL;
+ }
+ else if (strncmp(RSTRING(command)->ptr, "DEFAULT", 7) == 0) {
+ func = SIG_DFL;
+ }
+ }
+ else if (RSTRING(command)->len == 6) {
+ if (strncmp(RSTRING(command)->ptr, "IGNORE", 6) == 0) {
+ func = SIG_IGN;
+ }
+ }
+ else if (RSTRING(command)->len == 4) {
+ if (strncmp(RSTRING(command)->ptr, "EXIT", 4) == 0) {
+ func = sigexit;
}
}
}
if (func == SIG_IGN || func == SIG_DFL) {
command = 0;
}
- else {
- command = arg->cmd;
- }
switch (TYPE(arg->sig)) {
case T_FIXNUM:
@@ -620,7 +750,7 @@ trap(struct trap_arg *arg)
goto str_signal;
case T_STRING:
- s = RSTRING_PTR(arg->sig);
+ s = RSTRING(arg->sig)->ptr;
str_signal:
if (strncmp("SIG", s, 3) == 0)
@@ -647,6 +777,9 @@ trap(struct trap_arg *arg)
#ifdef SIGQUIT
case SIGQUIT:
#endif
+#ifdef SIGTERM
+ case SIGTERM:
+#endif
#ifdef SIGALRM
case SIGALRM:
#endif
@@ -686,7 +819,7 @@ trap(struct trap_arg *arg)
trap_list[sig].cmd = command;
trap_list[sig].safe = ruby_safe_level;
/* enable at least specified signal. */
-#ifndef _WIN32
+#if USE_TRAP_MASK
#ifdef HAVE_SIGPROCMASK
sigdelset(&arg->mask, sig);
#else
@@ -696,9 +829,10 @@ trap(struct trap_arg *arg)
return oldcmd;
}
-#ifndef _WIN32
+#if USE_TRAP_MASK
static VALUE
-trap_ensure(struct trap_arg *arg)
+trap_ensure(arg)
+ struct trap_arg *arg;
{
/* enable interrupt */
#ifdef HAVE_SIGPROCMASK
@@ -712,9 +846,9 @@ trap_ensure(struct trap_arg *arg)
#endif
void
-rb_trap_restore_mask(void)
+rb_trap_restore_mask()
{
-#ifndef _WIN32
+#if USE_TRAP_MASK
# ifdef HAVE_SIGPROCMASK
sigprocmask(SIG_SETMASK, &trap_last_mask, NULL);
# else
@@ -752,7 +886,9 @@ rb_trap_restore_mask(void)
* Terminating: 27460
*/
static VALUE
-sig_trap(int argc, VALUE *argv)
+sig_trap(argc, argv)
+ int argc;
+ VALUE *argv;
{
struct trap_arg arg;
@@ -772,7 +908,7 @@ sig_trap(int argc, VALUE *argv)
if (OBJ_TAINTED(arg.cmd)) {
rb_raise(rb_eSecurityError, "Insecure: tainted signal trap");
}
-#ifndef _WIN32
+#if USE_TRAP_MASK
/* disable interrupt */
# ifdef HAVE_SIGPROCMASK
sigfillset(&arg.mask);
@@ -797,7 +933,7 @@ sig_trap(int argc, VALUE *argv)
* Signal.list #=> {"ABRT"=>6, "ALRM"=>14, "BUS"=>7, "CHLD"=>17, "CLD"=>17, "CONT"=>18, "FPE"=>8, "HUP"=>1, "ILL"=>4, "INT"=>2, "IO"=>29, "IOT"=>6, "KILL"=>9, "PIPE"=>13, "POLL"=>29, "PROF"=>27, "PWR"=>30, "QUIT"=>3, "SEGV"=>11, "STOP"=>19, "SYS"=>31, "TERM"=>15, "TRAP"=>5, "TSTP"=>20, "TTIN"=>21, "TTOU"=>22, "URG"=>23, "USR1"=>10, "USR2"=>12, "VTALRM"=>26, "WINCH"=>28, "XCPU"=>24, "XFSZ"=>25}
*/
static VALUE
-sig_list(void)
+sig_list()
{
VALUE h = rb_hash_new();
struct signals *sigs;
@@ -809,7 +945,9 @@ sig_list(void)
}
static void
-install_sighandler(int signum, sighandler_t handler)
+install_sighandler(signum, handler)
+ int signum;
+ sighandler_t handler;
{
sighandler_t old;
@@ -828,7 +966,9 @@ install_sighandler(int signum, sighandler_t handler)
*/
#ifdef HAVE_NATIVETHREAD
static void
-install_nativethread_sighandler(int signum, sighandler_t handler)
+install_nativethread_sighandler(signum, handler)
+ int signum;
+ sighandler_t handler;
{
sighandler_t old;
int old_st;
@@ -847,10 +987,11 @@ install_nativethread_sighandler(int signum, sighandler_t handler)
#endif
static void
-init_sigchld(int sig)
+init_sigchld(sig)
+ int sig;
{
sighandler_t oldfunc;
-#ifndef _WIN32
+#if USE_TRAP_MASK
# ifdef HAVE_SIGPROCMASK
sigset_t mask;
# else
@@ -858,7 +999,7 @@ init_sigchld(int sig)
# endif
#endif
-#ifndef _WIN32
+#if USE_TRAP_MASK
/* disable interrupt */
# ifdef HAVE_SIGPROCMASK
sigfillset(&mask);
@@ -875,7 +1016,7 @@ init_sigchld(int sig)
trap_list[sig].cmd = 0;
}
-#ifndef _WIN32
+#if USE_TRAP_MASK
#ifdef HAVE_SIGPROCMASK
sigdelset(&mask, sig);
sigprocmask(SIG_SETMASK, &mask, NULL);
@@ -925,7 +1066,7 @@ init_sigchld(int sig)
* systems; in particular signal delivery may not always be reliable.
*/
void
-Init_signal(void)
+Init_signal()
{
#ifndef MACOS_UNUSE_SIGNAL
VALUE mSignal = rb_define_module("Signal");
@@ -934,6 +1075,11 @@ Init_signal(void)
rb_define_module_function(mSignal, "trap", sig_trap, -1);
rb_define_module_function(mSignal, "list", sig_list, 0);
+ rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
+ rb_attr(rb_eSignal, rb_intern("signo"), 1, 0, 0);
+ rb_alias(rb_eSignal, rb_intern("signm"), rb_intern("message"));
+ rb_define_method(rb_eInterrupt, "initialize", interrupt_init, 1);
+
install_sighandler(SIGINT, sighandler);
#ifdef SIGHUP
install_sighandler(SIGHUP, sighandler);
@@ -955,14 +1101,10 @@ Init_signal(void)
#endif
#ifdef SIGBUS
-# ifndef RUBY_GC_STRESS
install_sighandler(SIGBUS, sigbus);
-# endif
#endif
#ifdef SIGSEGV
-# ifndef RUBY_GC_STRESS
install_sighandler(SIGSEGV, sigsegv);
-# endif
#endif
#ifdef SIGPIPE
install_sighandler(SIGPIPE, sigpipe);
diff --git a/sjis.c b/sjis.c
deleted file mode 100644
index f7d7d52265..0000000000
--- a/sjis.c
+++ /dev/null
@@ -1,238 +0,0 @@
-/**********************************************************************
- sjis.c - Oniguruma (regular expression library)
-**********************************************************************/
-/*-
- * Copyright (c) 2002-2005 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "regenc.h"
-
-static const int EncLen_SJIS[] = {
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1
-};
-
-static const char SJIS_CAN_BE_TRAIL_TABLE[256] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
-};
-
-#define SJIS_ISMB_FIRST(byte) (EncLen_SJIS[byte] > 1)
-#define SJIS_ISMB_TRAIL(byte) SJIS_CAN_BE_TRAIL_TABLE[(byte)]
-
-static int
-sjis_mbc_enc_len(const UChar* p)
-{
- return EncLen_SJIS[*p];
-}
-
-static int
-sjis_code_to_mbclen(OnigCodePoint code)
-{
- if (code < 256) {
- if (EncLen_SJIS[(int )code] == 1)
- return 1;
- else
- return 0;
- }
- else if (code <= 0xffff) {
- return 2;
- }
- else
- return 0;
-}
-
-static OnigCodePoint
-sjis_mbc_to_code(const UChar* p, const UChar* end)
-{
- int c, i, len;
- OnigCodePoint n;
-
- len = enc_len(ONIG_ENCODING_SJIS, p);
- c = *p++;
- n = c;
- if (len == 1) return n;
-
- for (i = 1; i < len; i++) {
- if (p >= end) break;
- c = *p++;
- n <<= 8; n += c;
- }
- return n;
-}
-
-static int
-sjis_code_to_mbc(OnigCodePoint code, UChar *buf)
-{
- UChar *p = buf;
-
- if ((code & 0xff00) != 0) *p++ = (UChar )(((code >> 8) & 0xff));
- *p++ = (UChar )(code & 0xff);
-
-#if 0
- if (enc_len(ONIG_ENCODING_SJIS, buf) != (p - buf))
- return REGERR_INVALID_WIDE_CHAR_VALUE;
-#endif
- return p - buf;
-}
-
-static int
-sjis_mbc_to_normalize(OnigAmbigType flag,
- const UChar** pp, const UChar* end, UChar* lower)
-{
- const UChar* p = *pp;
-
- if (ONIGENC_IS_MBC_ASCII(p)) {
- if ((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0) {
- *lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
- }
- else {
- *lower = *p;
- }
-
- (*pp)++;
- return 1;
- }
- else {
- int len = enc_len(ONIG_ENCODING_SJIS, p);
-
- if (lower != p) {
- int i;
- for (i = 0; i < len; i++) {
- *lower++ = *p++;
- }
- }
- (*pp) += len;
- return len; /* return byte length of converted char to lower */
- }
-}
-
-static int
-sjis_is_mbc_ambiguous(OnigAmbigType flag, const UChar** pp, const UChar* end)
-{
- return onigenc_mbn_is_mbc_ambiguous(ONIG_ENCODING_SJIS, flag, pp, end);
-
-}
-
-static int
-sjis_is_code_ctype(OnigCodePoint code, unsigned int ctype)
-{
- if (code < 128)
- return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
- else {
- if ((ctype & (ONIGENC_CTYPE_WORD |
- ONIGENC_CTYPE_GRAPH | ONIGENC_CTYPE_PRINT)) != 0) {
- return (sjis_code_to_mbclen(code) > 1 ? TRUE : FALSE);
- }
- }
-
- return FALSE;
-}
-
-static UChar*
-sjis_left_adjust_char_head(const UChar* start, const UChar* s)
-{
- const UChar *p;
- int len;
-
- if (s <= start) return (UChar* )s;
- p = s;
-
- if (SJIS_ISMB_TRAIL(*p)) {
- while (p > start) {
- if (! SJIS_ISMB_FIRST(*--p)) {
- p++;
- break;
- }
- }
- }
- len = enc_len(ONIG_ENCODING_SJIS, p);
- if (p + len > s) return (UChar* )p;
- p += len;
- return (UChar* )(p + ((s - p) & ~1));
-}
-
-static int
-sjis_is_allowed_reverse_match(const UChar* s, const UChar* end)
-{
- const UChar c = *s;
- return (SJIS_ISMB_TRAIL(c) ? FALSE : TRUE);
-}
-
-OnigEncodingType OnigEncodingSJIS = {
- sjis_mbc_enc_len,
- "Shift_JIS", /* name */
- 2, /* max byte length */
- 1, /* min byte length */
- ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE,
- {
- (OnigCodePoint )'\\' /* esc */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar '.' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anytime '*' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* zero or one time '?' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* one or more time '+' */
- , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar anytime */
- },
- onigenc_is_mbc_newline_0x0a,
- sjis_mbc_to_code,
- sjis_code_to_mbclen,
- sjis_code_to_mbc,
- sjis_mbc_to_normalize,
- sjis_is_mbc_ambiguous,
- onigenc_ascii_get_all_pair_ambig_codes,
- onigenc_nothing_get_all_comp_ambig_codes,
- sjis_is_code_ctype,
- onigenc_not_support_get_ctype_code_range,
- sjis_left_adjust_char_head,
- sjis_is_allowed_reverse_match
-};
diff --git a/sprintf.c b/sprintf.c
index 41661f1134..ba1c40022b 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -16,14 +16,17 @@
#include "re.h"
#include <ctype.h>
#include <math.h>
-#include <stdarg.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);
+static void fmt_setup _((char*,int,int,int,int));
static char*
-remove_sign_bits(char *str, int base)
+remove_sign_bits(str, base)
+ char *str;
+ int base;
{
char *s, *t;
@@ -35,7 +38,7 @@ remove_sign_bits(char *str, int base)
}
}
else if (base == 8) {
- if (*t == '3') t++;
+ *t |= EXTENDSIGN(3, strlen(t));
while (*t == '7') {
t++;
}
@@ -54,7 +57,9 @@ remove_sign_bits(char *str, int base)
}
static char
-sign_bits(int base, const char *p)
+sign_bits(base, p)
+ int base;
+ const char *p;
{
char c = '.';
@@ -79,13 +84,14 @@ sign_bits(int base, const char *p)
#define FSPACE 16
#define FWIDTH 32
#define FPREC 64
+#define FPREC0 128
#define CHECK(l) do {\
while (blen + (l) >= bsiz) {\
bsiz*=2;\
}\
rb_str_resize(result, bsiz);\
- buf = RSTRING_PTR(result);\
+ buf = RSTRING(result)->ptr;\
} while (0)
#define PUSH(s, l) do { \
@@ -94,12 +100,6 @@ sign_bits(int base, const char *p)
blen += (l);\
} while (0)
-#define FILL(c, l) do { \
- CHECK(l);\
- memset(&buf[blen], c, l);\
- blen += (l);\
-} while (0)
-
#define GETARG() (nextvalue != Qundef ? nextvalue : \
posarg < 0 ? \
(rb_raise(rb_eArgError, "unnumbered(%d) mixed with numbered", nextarg), 0) : \
@@ -113,9 +113,7 @@ sign_bits(int base, const char *p)
#define GETNTHARG(nth) \
((nth >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[nth])
-#define GETASTER(val) do { \
- t = p++; \
- n = 0; \
+#define GETNUM(n, val) \
for (; p < end && ISDIGIT(*p); p++) { \
int next_n = 10 * n + (*p - '0'); \
if (next_n / 10 != n) {\
@@ -125,7 +123,12 @@ sign_bits(int base, const char *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); \
} \
@@ -242,13 +245,18 @@ sign_bits(int base, const char *p)
*/
VALUE
-rb_f_sprintf(int argc, const VALUE *argv)
+rb_f_sprintf(argc, argv)
+ int argc;
+ VALUE *argv;
{
return rb_str_format(argc - 1, argv + 1, GETNTHARG(0));
}
VALUE
-rb_str_format(int argc, const VALUE *argv, VALUE fmt)
+rb_str_format(argc, argv, fmt)
+ int argc;
+ VALUE *argv;
+ VALUE fmt;
{
const char *p, *end;
char *buf;
@@ -263,17 +271,32 @@ rb_str_format(int argc, const VALUE *argv, VALUE 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;
if (OBJ_TAINTED(fmt)) tainted = 1;
StringValue(fmt);
fmt = rb_str_new4(fmt);
- p = RSTRING_PTR(fmt);
- end = p + RSTRING_LEN(fmt);
+ p = RSTRING(fmt)->ptr;
+ end = p + RSTRING(fmt)->len;
blen = 0;
bsiz = 120;
result = rb_str_buf_new(bsiz);
- buf = RSTRING_PTR(result);
+ buf = RSTRING(result)->ptr;
for (; p < end; p++) {
const char *t;
@@ -299,26 +322,31 @@ rb_str_format(int argc, const VALUE *argv, VALUE 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;
@@ -326,16 +354,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
n = 0;
- 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 = next_n;
- }
- if (p >= end) {
- rb_raise(rb_eArgError, "malformed format string - %%[0-9]");
- }
+ GETNUM(n, width);
if (*p == '$') {
if (nextvalue != Qundef) {
rb_raise(rb_eArgError, "value given twice - %d$", n);
@@ -344,14 +363,13 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
p++;
goto retry;
}
+ CHECK_FOR_WIDTH(flags);
width = n;
flags |= FWIDTH;
goto retry;
case '*':
- if (flags & FWIDTH) {
- rb_raise(rb_eArgError, "width given twice");
- }
+ CHECK_FOR_WIDTH(flags);
flags |= FWIDTH;
GETASTER(width);
if (width < 0) {
@@ -362,10 +380,10 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
goto retry;
case '.':
- if (flags & FPREC) {
+ if (flags & FPREC0) {
rb_raise(rb_eArgError, "precision given twice");
}
- flags |= FPREC;
+ flags |= FPREC|FPREC0;
prec = 0;
p++;
@@ -378,17 +396,12 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
goto retry;
}
- for (; p < end && ISDIGIT(*p); p++) {
- prec = 10 * prec + (*p - '0');
- }
- if (p >= end) {
- rb_raise(rb_eArgError, "malformed format string - %%.[0-9]");
- }
+ GETNUM(prec, precision);
goto retry;
case '\n':
- p--;
case '\0':
+ p--;
case '%':
if (flags != FNONE) {
rb_raise(rb_eArgError, "illegal format character - %%");
@@ -399,26 +412,15 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
case 'c':
{
VALUE val = GETARG();
- VALUE tmp;
char c;
- tmp = rb_check_string_type(val);
- if (!NIL_P(tmp)) {
- if (RSTRING_LEN(tmp) != 1) {
- rb_raise(rb_eArgError, "%%c requires a character");
- }
- c = RSTRING_PTR(tmp)[0];
- }
- else {
- c = NUM2INT(val) & 0xff;
- }
- if (!(flags & FWIDTH)) {
- PUSH(&c, 1);
- }
- else {
- FILL(' ', width);
- buf[blen - ((flags & FMINUS) ? width : 1)] = c;
- }
+ if (!(flags & FMINUS))
+ while (--width > 0)
+ PUSH(" ", 1);
+ c = NUM2INT(val) & 0xff;
+ PUSH(&c, 1);
+ while (--width > 0)
+ PUSH(" ", 1);
}
break;
@@ -431,7 +433,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (*p == 'p') arg = rb_inspect(arg);
str = rb_obj_as_string(arg);
if (OBJ_TAINTED(str)) tainted = 1;
- len = RSTRING_LEN(str);
+ len = RSTRING(str)->len;
if (flags&FPREC) {
if (prec < len) {
len = prec;
@@ -457,7 +459,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
break;
}
}
- PUSH(RSTRING_PTR(str), len);
+ PUSH(RSTRING(str)->ptr, len);
}
break;
@@ -478,6 +480,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
long v = 0;
int base, bignum = 0;
int len, pos;
+ volatile VALUE tmp;
+ volatile VALUE tmp1;
switch (*p) {
case 'd':
@@ -571,89 +575,89 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
}
sprintf(fbuf, "%%l%c", c);
sprintf(nbuf, fbuf, v);
- }
- else {
s = nbuf;
- if (v < 0) {
- if (base == 10) {
- rb_warning("negative number for %%u specifier");
- }
- else if (!(flags&(FPREC|FZERO))) {
- strcpy(s, "..");
- s += 2;
- }
- }
- sprintf(fbuf, "%%l%c", *p == 'X' ? 'x' : *p);
- sprintf(s, fbuf, v);
- if (v < 0) {
- char d = 0;
-
- remove_sign_bits(s, base);
- switch (base) {
- case 16:
- d = 'f'; break;
- case 8:
- d = '7'; break;
- }
- if (d && *s != d) {
- memmove(s+1, s, strlen(s)+1);
- *s = d;
- }
- }
+ goto format_integer;
}
s = nbuf;
- }
- else {
- if (sign) {
- tmp = rb_big2str(val, base);
- s = RSTRING_PTR(tmp);
- if (s[0] == '-') {
- s++;
- sc = '-';
- width--;
+ if (v < 0) {
+ if (base == 10) {
+ rb_warning("negative number for %%u specifier");
}
- else if (flags & FPLUS) {
- sc = '+';
- width--;
- }
- else if (flags & FSPACE) {
- sc = ' ';
- width--;
+ if (!(flags&(FPREC|FZERO))) {
+ strcpy(s, "..");
+ s += 2;
}
}
- else {
- volatile VALUE tmp1;
- if (!RBIGNUM(val)->sign) {
- val = rb_big_clone(val);
- rb_big_2comp(val);
+ sprintf(fbuf, "%%l%c", *p == 'X' ? 'x' : *p);
+ sprintf(s, fbuf, v);
+ if (v < 0) {
+ char d = 0;
+
+ remove_sign_bits(s, base);
+ switch (base) {
+ case 16:
+ d = 'f'; break;
+ case 8:
+ d = '7'; break;
}
- tmp1 = tmp = rb_big2str0(val, base, RBIGNUM(val)->sign);
- s = RSTRING_PTR(tmp);
- if (*s == '-') {
- if (base == 10) {
- rb_warning("negative number for %%u specifier");
- }
- remove_sign_bits(++s, base);
- tmp = rb_str_new(0, 3+strlen(s));
- t = RSTRING_PTR(tmp);
- if (!(flags&(FPREC|FZERO))) {
- strcpy(t, "..");
- t += 2;
- }
- switch (base) {
- case 16:
- if (s[0] != 'f') strcpy(t++, "f"); break;
- case 8:
- if (s[0] != '7') strcpy(t++, "7"); break;
- case 2:
- if (s[0] != '1') strcpy(t++, "1"); break;
- }
- strcpy(t, s);
- s = RSTRING_PTR(tmp);
+ if (d && *s != d) {
+ memmove(s+1, s, strlen(s)+1);
+ *s = d;
}
}
+ s = nbuf;
+ goto format_integer;
}
+ if (sign) {
+ tmp = rb_big2str(val, base);
+ s = RSTRING(tmp)->ptr;
+ if (s[0] == '-') {
+ s++;
+ sc = '-';
+ width--;
+ }
+ else if (flags & FPLUS) {
+ sc = '+';
+ width--;
+ }
+ else if (flags & FSPACE) {
+ sc = ' ';
+ width--;
+ }
+ goto format_integer;
+ }
+ if (!RBIGNUM(val)->sign) {
+ val = rb_big_clone(val);
+ rb_big_2comp(val);
+ }
+ tmp1 = tmp = rb_big2str0(val, base, RBIGNUM(val)->sign);
+ s = RSTRING(tmp)->ptr;
+ if (*s == '-') {
+ if (base == 10) {
+ rb_warning("negative number for %%u specifier");
+ }
+ remove_sign_bits(++s, base);
+ tmp = rb_str_new(0, 3+strlen(s));
+ t = RSTRING(tmp)->ptr;
+ if (!(flags&(FPREC|FZERO))) {
+ strcpy(t, "..");
+ t += 2;
+ }
+ switch (base) {
+ case 16:
+ if (s[0] != 'f') strcpy(t++, "f"); break;
+ case 8:
+ if (s[0] != '7') strcpy(t++, "7"); break;
+ case 2:
+ if (s[0] != '1') strcpy(t++, "1"); break;
+ }
+ strcpy(t, s);
+ bignum = 2;
+ }
+ s = RSTRING(tmp)->ptr;
+
+ format_integer:
pos = -1;
len = strlen(s);
@@ -721,8 +725,9 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
char fbuf[32];
fval = RFLOAT(rb_Float(val))->value;
+#if defined(_WIN32) && !defined(__BORLANDC__)
if (isnan(fval) || isinf(fval)) {
- const char *expr;
+ char *expr;
if (isnan(fval)) {
expr = "NaN";
@@ -733,6 +738,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE 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;
@@ -776,7 +783,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
blen += strlen(&buf[blen]);
break;
}
-
+#endif /* defined(_WIN32) && !defined(__BORLANDC__) */
fmt_setup(fbuf, *p, flags, width, prec);
need = 0;
if (*p != 'e' && *p != 'E') {
@@ -814,7 +821,10 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
}
static void
-fmt_setup(char *buf, int c, int flags, int width, int prec)
+fmt_setup(buf, c, flags, width, prec)
+ char *buf;
+ int c;
+ int flags, width, prec;
{
*buf++ = '%';
if (flags & FSHARP) *buf++ = '#';
@@ -836,83 +846,3 @@ fmt_setup(char *buf, int c, int flags, int width, int prec)
*buf++ = c;
*buf = '\0';
}
-
-#undef FILE
-#define FILE rb_printf_buffer
-#define __sbuf rb_printf_sbuf
-#define __sFILE rb_printf_sfile
-#undef feof
-#undef ferror
-#undef clearerr
-#undef fileno
-#if SIZEOF_LONG < SIZEOF_VOIDP
-# if SIZEOF_LONG_LONG == SIZEOF_VOIDP
-# define _HAVE_SANE_QUAD_
-# define _HAVE_LLP64_
-# define quad_t LONG_LONG
-# define u_quad_t unsigned LONG_LONG
-# endif
-#endif
-#undef vsnprintf
-#undef snprintf
-#include "missing/vsnprintf.c"
-
-static int
-ruby__sfvwrite(register rb_printf_buffer *fp, register struct __suio *uio)
-{
- struct __siov *iov;
- VALUE result = (VALUE)fp->_bf._base;
- char *buf = (char*)fp->_p;
- size_t len, n;
- int blen = buf - RSTRING_PTR(result), bsiz = fp->_w;
-
- if (RBASIC(result)->klass) {
- rb_raise(rb_eRuntimeError, "rb_vsprintf reentered");
- }
- if ((len = uio->uio_resid) == 0)
- return 0;
- CHECK(len);
- buf += blen;
- fp->_w = bsiz;
- for (iov = uio->uio_iov; len > 0; ++iov) {
- MEMCPY(buf, iov->iov_base, char, n = iov->iov_len);
- buf += n;
- len -= n;
- }
- fp->_p = (unsigned char *)buf;
- return 0;
-}
-
-VALUE
-rb_vsprintf(const char *fmt, va_list ap)
-{
- rb_printf_buffer f;
- VALUE result;
-
- f._flags = __SWR | __SSTR;
- f._bf._size = 0;
- f._w = 120;
- result = rb_str_buf_new(f._w);
- f._bf._base = (unsigned char *)result;
- f._p = (unsigned char *)RSTRING_PTR(result);
- RBASIC(result)->klass = 0;
- f.vwrite = ruby__sfvwrite;
- BSD_vfprintf(&f, fmt, ap);
- RBASIC(result)->klass = rb_cString;
- rb_str_resize(result, (char *)f._p - RSTRING_PTR(result));
-
- return result;
-}
-
-VALUE
-rb_sprintf(const char *format, ...)
-{
- VALUE result;
- va_list ap;
-
- va_start(ap, format);
- result = rb_vsprintf(format, ap);
- va_end(ap);
-
- return result;
-}
diff --git a/st.c b/st.c
index 88d79f8d70..c16c3109a8 100644
--- a/st.c
+++ b/st.c
@@ -3,17 +3,12 @@
/* static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */
#include "config.h"
+#include "defines.h"
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <string.h>
-#include "defines.h"
-
-#ifdef NOT_RUBY
-#include "regint.h"
-#endif
-
#include "st.h"
typedef struct st_table_entry st_table_entry;
@@ -37,10 +32,11 @@ struct st_table_entry {
* allocated initially
*
*/
-
+static int numcmp(long, long);
+static int numhash(long);
static struct st_hash_type type_numhash = {
- st_numcmp,
- st_numhash,
+ numcmp,
+ numhash,
};
/* extern int strcmp(const char *, const char *); */
@@ -57,7 +53,7 @@ static void rehash(st_table *);
#define calloc xcalloc
#endif
-#define alloc(type) (type*)malloc((size_t)sizeof(type))
+#define alloc(type) (type*)malloc((unsigned)sizeof(type))
#define Calloc(n,s) (char*)calloc((n),(s))
#define EQUAL(table,x,y) ((x)==(y) || (*table->type->compare)((x),(y)) == 0)
@@ -107,7 +103,8 @@ static long primes[] = {
};
static int
-new_size(int size)
+new_size(size)
+ int size;
{
int i;
@@ -120,7 +117,7 @@ new_size(int size)
int newsize;
for (i = 0, newsize = MINSIZE;
- i < (int )(sizeof(primes)/sizeof(primes[0]));
+ i < sizeof(primes)/sizeof(primes[0]);
i++, newsize <<= 1)
{
if (newsize > size) return primes[i];
@@ -144,7 +141,9 @@ stat_col()
#endif
st_table*
-st_init_table_with_size(struct st_hash_type *type, int size)
+st_init_table_with_size(type, size)
+ struct st_hash_type *type;
+ int size;
{
st_table *tbl;
@@ -167,7 +166,8 @@ st_init_table_with_size(struct st_hash_type *type, int size)
}
st_table*
-st_init_table(struct st_hash_type *type)
+st_init_table(type)
+ struct st_hash_type *type;
{
return st_init_table_with_size(type, 0);
}
@@ -179,7 +179,8 @@ st_init_numtable(void)
}
st_table*
-st_init_numtable_with_size(int size)
+st_init_numtable_with_size(size)
+ int size;
{
return st_init_table_with_size(&type_numhash, size);
}
@@ -191,13 +192,15 @@ st_init_strtable(void)
}
st_table*
-st_init_strtable_with_size(int size)
+st_init_strtable_with_size(size)
+ int size;
{
return st_init_table_with_size(&type_strhash, size);
}
void
-st_free_table(st_table *table)
+st_free_table(table)
+ st_table *table;
{
register st_table_entry *ptr, *next;
int i;
@@ -236,7 +239,10 @@ st_free_table(st_table *table)
} while (0)
int
-st_lookup(st_table *table, register st_data_t key, st_data_t *value)
+st_lookup(table, key, value)
+ st_table *table;
+ register st_data_t key;
+ st_data_t *value;
{
unsigned int hash_val, bin_pos;
register st_table_entry *ptr;
@@ -272,7 +278,10 @@ do {\
} while (0)
int
-st_insert(register st_table *table, register st_data_t key, st_data_t value)
+st_insert(table, key, value)
+ register st_table *table;
+ register st_data_t key;
+ st_data_t value;
{
unsigned int hash_val, bin_pos;
register st_table_entry *ptr;
@@ -291,7 +300,10 @@ st_insert(register st_table *table, register st_data_t key, st_data_t value)
}
void
-st_add_direct(st_table *table, st_data_t key, st_data_t value)
+st_add_direct(table, key, value)
+ st_table *table;
+ st_data_t key;
+ st_data_t value;
{
unsigned int hash_val, bin_pos;
@@ -301,7 +313,8 @@ st_add_direct(st_table *table, st_data_t key, st_data_t value)
}
static void
-rehash(register st_table *table)
+rehash(table)
+ register st_table *table;
{
register st_table_entry *ptr, *next, **new_bins;
int i, old_num_bins = table->num_bins, new_num_bins;
@@ -326,7 +339,8 @@ rehash(register st_table *table)
}
st_table*
-st_copy(st_table *old_table)
+st_copy(old_table)
+ st_table *old_table;
{
st_table *new_table;
st_table_entry *ptr, *entry;
@@ -366,7 +380,10 @@ st_copy(st_table *old_table)
}
int
-st_delete(register st_table *table, register st_data_t *key, st_data_t *value)
+st_delete(table, key, value)
+ register st_table *table;
+ register st_data_t *key;
+ st_data_t *value;
{
unsigned int hash_val;
st_table_entry *tmp;
@@ -405,7 +422,11 @@ st_delete(register st_table *table, register st_data_t *key, st_data_t *value)
}
int
-st_delete_safe(register st_table *table, register st_data_t *key, st_data_t *value, st_data_t never)
+st_delete_safe(table, key, value, never)
+ register st_table *table;
+ register st_data_t *key;
+ st_data_t *value;
+ st_data_t never;
{
unsigned int hash_val;
register st_table_entry *ptr;
@@ -432,14 +453,17 @@ st_delete_safe(register st_table *table, register st_data_t *key, st_data_t *val
}
static int
-delete_never(st_data_t key, st_data_t value, st_data_t never)
+delete_never(key, value, never)
+ st_data_t key, value, never;
{
if (value == never) return ST_DELETE;
return ST_CONTINUE;
}
void
-st_cleanup_safe(st_table *table, st_data_t never)
+st_cleanup_safe(table, never)
+ st_table *table;
+ st_data_t never;
{
int num_entries = table->num_entries;
@@ -448,7 +472,10 @@ st_cleanup_safe(st_table *table, st_data_t never)
}
int
-st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
+st_foreach(table, func, arg)
+ st_table *table;
+ int (*func)();
+ st_data_t arg;
{
st_table_entry *ptr, *last, *tmp;
enum st_retval retval;
@@ -494,107 +521,55 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
return 0;
}
-/*
- * hash_32 - 32 bit Fowler/Noll/Vo FNV-1a hash code
- *
- * @(#) $Revision$
- * @(#) $Id$
- * @(#) $Source$
- *
- ***
- *
- * Fowler/Noll/Vo hash
- *
- * The basis of this hash algorithm was taken from an idea sent
- * as reviewer comments to the IEEE POSIX P1003.2 committee by:
- *
- * Phong Vo (http://www.research.att.com/info/kpv/)
- * Glenn Fowler (http://www.research.att.com/~gsf/)
- *
- * In a subsequent ballot round:
- *
- * Landon Curt Noll (http://www.isthe.com/chongo/)
- *
- * improved on their algorithm. Some people tried this hash
- * and found that it worked rather well. In an EMail message
- * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash.
- *
- * FNV hashes are designed to be fast while maintaining a low
- * collision rate. The FNV speed allows one to quickly hash lots
- * of data while maintaining a reasonable collision rate. See:
- *
- * http://www.isthe.com/chongo/tech/comp/fnv/index.html
- *
- * for more details as well as other forms of the FNV hash.
- ***
- *
- * To use the recommended 32 bit FNV-1a hash, pass FNV1_32A_INIT as the
- * Fnv32_t hashval argument to fnv_32a_buf() or fnv_32a_str().
- *
- ***
- *
- * Please do not copyright this code. This code is in the public domain.
- *
- * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
- * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
- * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
- * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * By:
- * chongo <Landon Curt Noll> /\oo/\
- * http://www.isthe.com/chongo/
- *
- * Share and Enjoy! :-)
- */
-
-/*
- * 32 bit FNV-1 and FNV-1a non-zero initial basis
- *
- * The FNV-1 initial basis is the FNV-0 hash of the following 32 octets:
- *
- * chongo <Landon Curt Noll> /\../\
- *
- * NOTE: The \'s above are not back-slashing escape characters.
- * They are literal ASCII backslash 0x5c characters.
- *
- * NOTE: The FNV-1a initial basis is the same value as FNV-1 by definition.
- */
-#define FNV1_32A_INIT 0x811c9dc5
-
-/*
- * 32 bit magic FNV-1a prime
- */
-#define FNV_32_PRIME 0x01000193
-
static int
-strhash(register const char *string)
+strhash(string)
+ register const char *string;
{
- register unsigned int hval = FNV1_32A_INIT;
+ register int c;
- /*
- * FNV-1a hash each octet in the buffer
- */
- while (*string) {
- /* xor the bottom with the current octet */
- hval ^= (unsigned int)*string++;
+#ifdef HASH_ELFHASH
+ register unsigned int h = 0, g;
+
+ while ((c = *string++) != '\0') {
+ h = ( h << 4 ) + c;
+ if ( g = h & 0xF0000000 )
+ h ^= g >> 24;
+ h &= ~g;
+ }
+ return h;
+#elif defined(HASH_PERL)
+ register int val = 0;
+
+ while ((c = *string++) != '\0') {
+ val += c;
+ val += (val << 10);
+ val ^= (val >> 6);
+ }
+ val += (val << 3);
+ val ^= (val >> 11);
+
+ return val + (val << 15);
+#else
+ register int val = 0;
- /* multiply by the 32 bit FNV magic prime mod 2^32 */
- hval *= FNV_32_PRIME;
+ while ((c = *string++) != '\0') {
+ val = val*997 + c;
}
- return hval;
+
+ return val + (val>>5);
+#endif
}
-int
-st_numcmp(long x, long y)
+static int
+numcmp(x, y)
+ long x, y;
{
return x != y;
}
-int
-st_numhash(long n)
+static int
+numhash(n)
+ long n;
{
return n;
}
diff --git a/st.h b/st.h
index 45609ddeb1..fb56f5ffad 100644
--- a/st.h
+++ b/st.h
@@ -45,22 +45,28 @@ enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK};
# endif
#endif
-st_table *st_init_table(struct st_hash_type *);
-st_table *st_init_table_with_size(struct st_hash_type *, int);
-st_table *st_init_numtable(void);
-st_table *st_init_numtable_with_size(int);
-st_table *st_init_strtable(void);
-st_table *st_init_strtable_with_size(int);
-int st_delete(st_table *, st_data_t *, st_data_t *);
-int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t);
-int st_insert(st_table *, st_data_t, st_data_t);
-int st_lookup(st_table *, st_data_t, st_data_t *);
-int st_foreach(st_table *, int (*)(ANYARGS), st_data_t);
-void st_add_direct(st_table *, st_data_t, st_data_t);
-void st_free_table(st_table *);
-void st_cleanup_safe(st_table *, st_data_t);
-st_table *st_copy(st_table *);
-int st_numcmp(long, long);
-int st_numhash(long);
+st_table *st_init_table _((struct st_hash_type *));
+st_table *st_init_table_with_size _((struct st_hash_type *, int));
+st_table *st_init_numtable _((void));
+st_table *st_init_numtable_with_size _((int));
+st_table *st_init_strtable _((void));
+st_table *st_init_strtable_with_size _((int));
+int st_delete _((st_table *, st_data_t *, st_data_t *));
+int st_delete_safe _((st_table *, st_data_t *, st_data_t *, st_data_t));
+int st_insert _((st_table *, st_data_t, st_data_t));
+int st_lookup _((st_table *, st_data_t, st_data_t *));
+int st_foreach _((st_table *, int (*)(ANYARGS), st_data_t));
+void st_add_direct _((st_table *, st_data_t, st_data_t));
+void st_free_table _((st_table *));
+void st_cleanup_safe _((st_table *, st_data_t));
+st_table *st_copy _((st_table *));
+
+#define ST_NUMCMP ((int (*)()) 0)
+#define ST_NUMHASH ((int (*)()) -2)
+
+#define st_numcmp ST_NUMCMP
+#define st_numhash ST_NUMHASH
+
+int st_strhash();
#endif /* ST_INCLUDED */
diff --git a/string.c b/string.c
index 8fc5c9836a..2f380e1ec7 100644
--- a/string.c
+++ b/string.c
@@ -6,7 +6,7 @@
$Date$
created at: Mon Aug 9 17:12:58 JST 1993
- Copyright (C) 1993-2006 Yukihiro Matsumoto
+ Copyright (C) 1993-2003 Yukihiro Matsumoto
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
Copyright (C) 2000 Information-technology Promotion Agency, Japan
@@ -26,112 +26,59 @@
#endif
VALUE rb_cString;
-VALUE rb_cSymbol;
-#define STR_TMPLOCK FL_USER7
-#define STR_NOEMBED FL_USER1
+#define STR_TMPLOCK FL_USER1
#define STR_ASSOC FL_USER3
-#define STR_SHARED_P(s) FL_ALL(s, STR_NOEMBED|ELTS_SHARED)
-#define STR_ASSOC_P(s) FL_ALL(s, STR_NOEMBED|STR_ASSOC)
-#define STR_NOCAPA (STR_NOEMBED|ELTS_SHARED|STR_ASSOC)
-#define STR_NOCAPA_P(s) (FL_TEST(s,STR_NOEMBED) && FL_ANY(s,ELTS_SHARED|STR_ASSOC))
-#define STR_UNSET_NOCAPA(s) do {\
- if (FL_TEST(s,STR_NOEMBED)) FL_UNSET(s,(ELTS_SHARED|STR_ASSOC));\
-} while (0)
-
+#define STR_NOCAPA (ELTS_SHARED|STR_ASSOC)
-#define STR_SET_NOEMBED(str) do {\
- FL_SET(str, STR_NOEMBED);\
- STR_SET_EMBED_LEN(str, 0);\
-} while (0)
-#define STR_SET_EMBED(str) FL_UNSET(str, STR_NOEMBED)
-#define STR_EMBED_P(str) (!FL_TEST(str, STR_NOEMBED))
-#define STR_SET_EMBED_LEN(str, n) do { \
- long tmp_n = (n);\
- RBASIC(str)->flags &= ~RSTRING_EMBED_LEN_MASK;\
- RBASIC(str)->flags |= (tmp_n) << RSTRING_EMBED_LEN_SHIFT;\
-} while (0)
-
-#define STR_SET_LEN(str, n) do { \
- if (STR_EMBED_P(str)) {\
- STR_SET_EMBED_LEN(str, n);\
- }\
- else {\
- RSTRING(str)->as.heap.len = (n);\
- }\
-} while (0)
-
-#define STR_DEC_LEN(str) do {\
- if (STR_EMBED_P(str)) {\
- long n = RSTRING_LEN(str);\
- n--;\
- STR_SET_EMBED_LEN(str, n);\
- }\
- else {\
- RSTRING(str)->as.heap.len--;\
- }\
-} while (0)
-
#define RESIZE_CAPA(str,capacity) do {\
- if (STR_EMBED_P(str)) {\
- if ((capacity) > RSTRING_EMBED_LEN_MAX) {\
- char *tmp = ALLOC_N(char, capacity+1);\
- memcpy(tmp, RSTRING_PTR(str), RSTRING_LEN(str));\
- RSTRING(str)->as.heap.ptr = tmp;\
- RSTRING(str)->as.heap.len = RSTRING_LEN(str);\
- STR_SET_NOEMBED(str);\
- RSTRING(str)->as.heap.aux.capa = (capacity);\
- }\
- }\
- else {\
- REALLOC_N(RSTRING(str)->as.heap.ptr, char, (capacity)+1);\
- if (!STR_NOCAPA_P(str))\
- RSTRING(str)->as.heap.aux.capa = (capacity);\
- }\
+ REALLOC_N(RSTRING(str)->ptr, char, (capacity)+1);\
+ if (!FL_TEST(str, STR_NOCAPA))\
+ RSTRING(str)->aux.capa = (capacity);\
} while (0)
-char *
-rb_str_ptr(VALUE str) {
- return RSTRING_PTR(str);
-}
-
VALUE rb_fs;
static inline void
-str_mod_check(VALUE s, char *p, long len)
+str_mod_check(s, p, len)
+ VALUE s;
+ char *p;
+ long len;
{
- if (RSTRING_PTR(s) != p || RSTRING_LEN(s) != len){
+ if (RSTRING(s)->ptr != p || RSTRING(s)->len != len) {
rb_raise(rb_eRuntimeError, "string modified");
}
}
static inline void
-str_frozen_check(VALUE s)
+str_frozen_check(s)
+ VALUE s;
{
if (OBJ_FROZEN(s)) {
rb_raise(rb_eRuntimeError, "string frozen");
}
}
+static VALUE str_alloc _((VALUE));
static VALUE
-str_alloc(VALUE klass)
+str_alloc(klass)
+ VALUE klass;
{
NEWOBJ(str, struct RString);
OBJSETUP(str, klass, T_STRING);
- if (klass == rb_cSymbol) {
- /* need to be registered in table */
- RBASIC(str)->klass = rb_cString;
- }
- str->as.heap.ptr = 0;
- str->as.heap.len = 0;
- str->as.heap.aux.capa = 0;
+ str->ptr = 0;
+ str->len = 0;
+ str->aux.capa = 0;
return (VALUE)str;
}
static VALUE
-str_new(VALUE klass, const char *ptr, long len)
+str_new(klass, ptr, len)
+ VALUE klass;
+ const char *ptr;
+ long len;
{
VALUE str;
@@ -140,27 +87,27 @@ str_new(VALUE klass, const char *ptr, long len)
}
str = str_alloc(klass);
- if (len > RSTRING_EMBED_LEN_MAX) {
- RSTRING(str)->as.heap.aux.capa = len;
- RSTRING(str)->as.heap.ptr = ALLOC_N(char,len+1);
- STR_SET_NOEMBED(str);
- }
+ RSTRING(str)->len = len;
+ RSTRING(str)->aux.capa = len;
+ RSTRING(str)->ptr = ALLOC_N(char,len+1);
if (ptr) {
- memcpy(RSTRING_PTR(str), ptr, len);
+ memcpy(RSTRING(str)->ptr, ptr, len);
}
- STR_SET_LEN(str, len);
- RSTRING_PTR(str)[len] = '\0';
+ RSTRING(str)->ptr[len] = '\0';
return str;
}
VALUE
-rb_str_new(const char *ptr, long len)
+rb_str_new(ptr, len)
+ const char *ptr;
+ long len;
{
return str_new(rb_cString, ptr, len);
}
VALUE
-rb_str_new2(const char *ptr)
+rb_str_new2(ptr)
+ const char *ptr;
{
if (!ptr) {
rb_raise(rb_eArgError, "NULL pointer given");
@@ -169,7 +116,9 @@ rb_str_new2(const char *ptr)
}
VALUE
-rb_tainted_str_new(const char *ptr, long len)
+rb_tainted_str_new(ptr, len)
+ const char *ptr;
+ long len;
{
VALUE str = rb_str_new(ptr, len);
@@ -178,7 +127,8 @@ rb_tainted_str_new(const char *ptr, long len)
}
VALUE
-rb_tainted_str_new2(const char *ptr)
+rb_tainted_str_new2(ptr)
+ const char *ptr;
{
VALUE str = rb_str_new2(ptr);
@@ -187,28 +137,22 @@ rb_tainted_str_new2(const char *ptr)
}
static VALUE
-str_new3(VALUE klass, VALUE str)
+str_new3(klass, str)
+ VALUE klass, str;
{
VALUE str2 = str_alloc(klass);
- if (RSTRING_LEN(str) <= RSTRING_EMBED_LEN_MAX) {
- STR_SET_EMBED(str);
- memcpy(RSTRING_PTR(str2), RSTRING_PTR(str), RSTRING_LEN(str)+1);
- STR_SET_EMBED_LEN(str2, RSTRING_LEN(str));
- }
- else {
- FL_SET(str2, STR_NOEMBED);
- RSTRING(str2)->as.heap.len = RSTRING_LEN(str);
- RSTRING(str2)->as.heap.ptr = RSTRING_PTR(str);
- RSTRING(str2)->as.heap.aux.shared = str;
- FL_SET(str2, ELTS_SHARED);
- }
+ RSTRING(str2)->len = RSTRING(str)->len;
+ RSTRING(str2)->ptr = RSTRING(str)->ptr;
+ RSTRING(str2)->aux.shared = str;
+ FL_SET(str2, ELTS_SHARED);
return str2;
}
VALUE
-rb_str_new3(VALUE str)
+rb_str_new3(str)
+ VALUE str;
{
VALUE str2 = str_new3(rb_obj_class(str), str);
@@ -217,45 +161,44 @@ rb_str_new3(VALUE str)
}
static VALUE
-str_new4(VALUE klass, VALUE str)
+str_new4(klass, str)
+ VALUE klass, str;
{
- VALUE str2;
+ VALUE str2 = str_alloc(klass);
- str2 = str_alloc(klass);
- STR_SET_NOEMBED(str2);
- RSTRING(str2)->as.heap.len = RSTRING_LEN(str);
- RSTRING(str2)->as.heap.ptr = RSTRING_PTR(str);
- if (STR_SHARED_P(str)) {
+ RSTRING(str2)->len = RSTRING(str)->len;
+ RSTRING(str2)->ptr = RSTRING(str)->ptr;
+ if (FL_TEST(str, ELTS_SHARED)) {
FL_SET(str2, ELTS_SHARED);
- RSTRING(str2)->as.heap.aux.shared = RSTRING(str)->as.heap.aux.shared;
+ RSTRING(str2)->aux.shared = RSTRING(str)->aux.shared;
}
else {
FL_SET(str, ELTS_SHARED);
- RSTRING(str)->as.heap.aux.shared = str2;
+ RSTRING(str)->aux.shared = str2;
}
- OBJ_INFECT(str2, str);
+
return str2;
}
VALUE
-rb_str_new4(VALUE orig)
+rb_str_new4(orig)
+ VALUE orig;
{
VALUE klass, str;
if (OBJ_FROZEN(orig)) return orig;
klass = rb_obj_class(orig);
- if (STR_SHARED_P(orig) && (str = RSTRING(orig)->as.heap.aux.shared)
- && klass == RBASIC(str)->klass) {
+ if (FL_TEST(orig, ELTS_SHARED) && (str = RSTRING(orig)->aux.shared) && klass == RBASIC(str)->klass) {
long ofs;
- ofs = RSTRING_LEN(str) - RSTRING_LEN(orig);
+ ofs = RSTRING(str)->len - RSTRING(orig)->len;
if ((ofs > 0) || (!OBJ_TAINTED(str) && OBJ_TAINTED(orig))) {
str = str_new3(klass, str);
- RSTRING(str)->as.heap.ptr += ofs;
- RSTRING(str)->as.heap.len -= ofs;
+ RSTRING(str)->ptr += ofs;
+ RSTRING(str)->len -= ofs;
}
}
- else if (STR_ASSOC_P(orig) || STR_EMBED_P(orig)) {
- str = str_new(klass, RSTRING_PTR(orig), RSTRING_LEN(orig));
+ else if (FL_TEST(orig, STR_ASSOC)) {
+ str = str_new(klass, RSTRING(orig)->ptr, RSTRING(orig)->len);
}
else {
str = str_new4(klass, orig);
@@ -266,7 +209,10 @@ rb_str_new4(VALUE orig)
}
VALUE
-rb_str_new5(VALUE obj, const char *ptr, long len)
+rb_str_new5(obj, ptr, len)
+ VALUE obj;
+ const char *ptr;
+ long len;
{
return str_new(rb_obj_class(obj), ptr, len);
}
@@ -274,23 +220,26 @@ rb_str_new5(VALUE obj, const char *ptr, long len)
#define STR_BUF_MIN_SIZE 128
VALUE
-rb_str_buf_new(long capa)
+rb_str_buf_new(capa)
+ long capa;
{
VALUE str = str_alloc(rb_cString);
if (capa < STR_BUF_MIN_SIZE) {
capa = STR_BUF_MIN_SIZE;
}
- FL_SET(str, STR_NOEMBED);
- RSTRING(str)->as.heap.aux.capa = capa;
- RSTRING(str)->as.heap.ptr = ALLOC_N(char, capa+1);
- RSTRING(str)->as.heap.ptr[0] = '\0';
+ RSTRING(str)->ptr = 0;
+ RSTRING(str)->len = 0;
+ RSTRING(str)->aux.capa = capa;
+ RSTRING(str)->ptr = ALLOC_N(char, capa+1);
+ RSTRING(str)->ptr[0] = '\0';
return str;
}
VALUE
-rb_str_buf_new2(const char *ptr)
+rb_str_buf_new2(ptr)
+ const char *ptr;
{
VALUE str;
long len = strlen(ptr);
@@ -301,56 +250,49 @@ rb_str_buf_new2(const char *ptr)
return str;
}
-void
-rb_str_free(VALUE str)
-{
- if (!STR_EMBED_P(str) && !STR_SHARED_P(str)) {
- xfree(RSTRING(str)->as.heap.ptr);
- }
-}
-
VALUE
-rb_str_to_str(VALUE str)
+rb_str_to_str(str)
+ VALUE str;
{
return rb_convert_type(str, T_STRING, "String", "to_str");
}
static void
-rb_str_shared_replace(VALUE str, VALUE str2)
+rb_str_shared_replace(str, str2)
+ VALUE str, str2;
{
if (str == str2) return;
rb_str_modify(str);
- if (OBJ_TAINTED(str2)) OBJ_TAINT(str);
- if (RSTRING_LEN(str2) <= RSTRING_EMBED_LEN_MAX) {
- STR_SET_EMBED(str);
- memcpy(RSTRING_PTR(str), RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
- STR_SET_EMBED_LEN(str, RSTRING_LEN(str2));
+ if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr);
+ if (NIL_P(str2)) {
+ RSTRING(str)->ptr = 0;
+ RSTRING(str)->len = 0;
+ RSTRING(str)->aux.capa = 0;
+ FL_UNSET(str, STR_NOCAPA);
return;
}
- STR_SET_NOEMBED(str);
- if (!STR_SHARED_P(str) && !STR_EMBED_P(str)) {
- free(RSTRING_PTR(str));
- }
- STR_UNSET_NOCAPA(str);
- RSTRING(str)->as.heap.ptr = RSTRING_PTR(str2);
- RSTRING(str)->as.heap.len = RSTRING_LEN(str2);
- if (STR_NOCAPA_P(str2)) {
+ RSTRING(str)->ptr = RSTRING(str2)->ptr;
+ RSTRING(str)->len = RSTRING(str2)->len;
+ FL_UNSET(str, STR_NOCAPA);
+ if (FL_TEST(str2, STR_NOCAPA)) {
FL_SET(str, RBASIC(str2)->flags & STR_NOCAPA);
- RSTRING(str)->as.heap.aux.shared = RSTRING(str2)->as.heap.aux.shared;
+ RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared;
}
else {
- RSTRING(str)->as.heap.aux.capa = RSTRING(str2)->as.heap.aux.capa;
+ RSTRING(str)->aux.capa = RSTRING(str2)->aux.capa;
}
- RSTRING(str2)->as.heap.ptr = 0; /* abandon str2 */
- RSTRING(str2)->as.heap.len = 0;
- RSTRING(str2)->as.heap.aux.capa = 0;
- STR_UNSET_NOCAPA(str2);
+ RSTRING(str2)->ptr = 0; /* abandon str2 */
+ RSTRING(str2)->len = 0;
+ RSTRING(str2)->aux.capa = 0;
+ FL_UNSET(str2, STR_NOCAPA);
+ if (OBJ_TAINTED(str2)) OBJ_TAINT(str);
}
static ID id_to_s;
VALUE
-rb_obj_as_string(VALUE obj)
+rb_obj_as_string(obj)
+ VALUE obj;
{
VALUE str;
@@ -364,10 +306,11 @@ rb_obj_as_string(VALUE obj)
return str;
}
-static VALUE rb_str_replace(VALUE, VALUE);
+static VALUE rb_str_replace _((VALUE, VALUE));
VALUE
-rb_str_dup(VALUE str)
+rb_str_dup(str)
+ VALUE str;
{
VALUE dup = str_alloc(rb_obj_class(str));
rb_str_replace(dup, str);
@@ -383,7 +326,10 @@ rb_str_dup(VALUE str)
*/
static VALUE
-rb_str_init(int argc, VALUE *argv, VALUE str)
+rb_str_init(argc, argv, str)
+ int argc;
+ VALUE *argv;
+ VALUE str;
{
VALUE orig;
@@ -400,10 +346,10 @@ rb_str_init(int argc, VALUE *argv, VALUE str)
*/
static VALUE
-rb_str_length(VALUE str)
+rb_str_length(str)
+ VALUE str;
{
- long len = RSTRING_LEN(str);
- return LONG2NUM(len);
+ return LONG2NUM(RSTRING(str)->len);
}
/*
@@ -417,9 +363,10 @@ rb_str_length(VALUE str)
*/
static VALUE
-rb_str_empty(VALUE str)
+rb_str_empty(str)
+ VALUE str;
{
- if (RSTRING_LEN(str) == 0)
+ if (RSTRING(str)->len == 0)
return Qtrue;
return Qfalse;
}
@@ -435,16 +382,17 @@ rb_str_empty(VALUE str)
*/
VALUE
-rb_str_plus(VALUE str1, VALUE str2)
+rb_str_plus(str1, str2)
+ VALUE str1, str2;
{
VALUE str3;
StringValue(str2);
- str3 = rb_str_new(0, RSTRING_LEN(str1)+RSTRING_LEN(str2));
- memcpy(RSTRING_PTR(str3), RSTRING_PTR(str1), RSTRING_LEN(str1));
- memcpy(RSTRING_PTR(str3) + RSTRING_LEN(str1),
- RSTRING_PTR(str2), RSTRING_LEN(str2));
- RSTRING_PTR(str3)[RSTRING_LEN(str3)] = '\0';
+ str3 = rb_str_new(0, RSTRING(str1)->len+RSTRING(str2)->len);
+ memcpy(RSTRING(str3)->ptr, RSTRING(str1)->ptr, RSTRING(str1)->len);
+ memcpy(RSTRING(str3)->ptr + RSTRING(str1)->len,
+ RSTRING(str2)->ptr, RSTRING(str2)->len);
+ RSTRING(str3)->ptr[RSTRING(str3)->len] = '\0';
if (OBJ_TAINTED(str1) || OBJ_TAINTED(str2))
OBJ_TAINT(str3);
@@ -462,7 +410,9 @@ rb_str_plus(VALUE str1, VALUE str2)
*/
VALUE
-rb_str_times(VALUE str, VALUE times)
+rb_str_times(str, times)
+ VALUE str;
+ VALUE times;
{
VALUE str2;
long i, len;
@@ -471,16 +421,16 @@ rb_str_times(VALUE str, VALUE times)
if (len < 0) {
rb_raise(rb_eArgError, "negative argument");
}
- if (len && LONG_MAX/len < RSTRING_LEN(str)) {
+ if (len && LONG_MAX/len < RSTRING(str)->len) {
rb_raise(rb_eArgError, "argument too big");
}
- str2 = rb_str_new5(str, 0, len *= RSTRING_LEN(str));
- for (i = 0; i < len; i += RSTRING_LEN(str)) {
- memcpy(RSTRING_PTR(str2) + i,
- RSTRING_PTR(str), RSTRING_LEN(str));
+ str2 = rb_str_new5(str,0, len *= RSTRING(str)->len);
+ for (i = 0; i < len; i += RSTRING(str)->len) {
+ memcpy(RSTRING(str2)->ptr + i,
+ RSTRING(str)->ptr, RSTRING(str)->len);
}
- RSTRING_PTR(str2)[RSTRING_LEN(str2)] = '\0';
+ RSTRING(str2)->ptr[RSTRING(str2)->len] = '\0';
OBJ_INFECT(str2, str);
@@ -502,16 +452,20 @@ rb_str_times(VALUE str, VALUE times)
*/
static VALUE
-rb_str_format_m(VALUE str, VALUE arg)
+rb_str_format_m(str, arg)
+ VALUE str, arg;
{
- if (TYPE(arg) == T_ARRAY) {
- return rb_str_format(RARRAY_LEN(arg), RARRAY_PTR(arg), str);
+ volatile VALUE tmp = rb_check_array_type(arg);
+
+ if (!NIL_P(tmp)) {
+ return rb_str_format(RARRAY_LEN(tmp), RARRAY_PTR(tmp), str);
}
return rb_str_format(1, &arg, str);
}
static int
-str_independent(VALUE str)
+str_independent(str)
+ VALUE str;
{
if (FL_TEST(str, STR_TMPLOCK)) {
rb_raise(rb_eRuntimeError, "can't modify string; temporarily locked");
@@ -519,115 +473,129 @@ str_independent(VALUE 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 (!STR_SHARED_P(str)) return 1;
- if (STR_EMBED_P(str)) return 1;
+ if (!FL_TEST(str, ELTS_SHARED)) return 1;
return 0;
}
static void
-str_make_independent(VALUE str)
+str_make_independent(str)
+ VALUE str;
{
char *ptr;
- long len = RSTRING_LEN(str);
- ptr = ALLOC_N(char, len+1);
- if (RSTRING_PTR(str)) {
- memcpy(ptr, RSTRING_PTR(str), len);
+ ptr = ALLOC_N(char, RSTRING(str)->len+1);
+ if (RSTRING(str)->ptr) {
+ memcpy(ptr, RSTRING(str)->ptr, RSTRING(str)->len);
}
- STR_SET_NOEMBED(str);
- ptr[len] = 0;
- RSTRING(str)->as.heap.ptr = ptr;
- RSTRING(str)->as.heap.aux.capa = len;
- STR_UNSET_NOCAPA(str);
+ ptr[RSTRING(str)->len] = 0;
+ RSTRING(str)->ptr = ptr;
+ RSTRING(str)->aux.capa = RSTRING(str)->len;
+ FL_UNSET(str, STR_NOCAPA);
}
void
-rb_str_modify(VALUE str)
+rb_str_modify(str)
+ VALUE str;
{
if (!str_independent(str))
str_make_independent(str);
}
void
-rb_str_associate(VALUE str, VALUE add)
+rb_str_associate(str, add)
+ VALUE str, add;
{
- if (STR_ASSOC_P(str)) {
- /* sanity check */
- if (OBJ_FROZEN(str)) rb_error_frozen("string");
+ if (FL_TEST(str, STR_ASSOC)) {
/* already associated */
- rb_ary_concat(RSTRING(str)->as.heap.aux.shared, add);
+ rb_ary_concat(RSTRING(str)->aux.shared, add);
}
else {
- if (STR_SHARED_P(str) || STR_EMBED_P(str)) {
+ if (FL_TEST(str, ELTS_SHARED)) {
str_make_independent(str);
}
- else if (RSTRING(str)->as.heap.aux.capa != RSTRING_LEN(str)) {
- RESIZE_CAPA(str, RSTRING_LEN(str));
+ else if (RSTRING(str)->aux.capa != RSTRING(str)->len) {
+ RESIZE_CAPA(str, RSTRING(str)->len);
}
+ RSTRING(str)->aux.shared = add;
FL_SET(str, STR_ASSOC);
- RSTRING(str)->as.heap.aux.shared = add;
}
}
VALUE
-rb_str_associated(VALUE str)
+rb_str_associated(str)
+ VALUE str;
{
- if (STR_ASSOC_P(str)) {
- if (OBJ_FROZEN(str)) return Qfalse;
- return RSTRING(str)->as.heap.aux.shared;
+ if (FL_TEST(str, STR_ASSOC)) {
+ return RSTRING(str)->aux.shared;
}
return Qfalse;
}
+static char *null_str = "";
+
VALUE
-rb_string_value(volatile VALUE *ptr)
+rb_string_value(ptr)
+ volatile VALUE *ptr;
{
VALUE s = *ptr;
if (TYPE(s) != T_STRING) {
s = rb_str_to_str(s);
*ptr = s;
}
+ if (!RSTRING(s)->ptr) {
+ FL_SET(s, ELTS_SHARED);
+ RSTRING(s)->ptr = null_str;
+ }
return s;
}
char *
-rb_string_value_ptr(volatile VALUE *ptr)
+rb_string_value_ptr(ptr)
+ volatile VALUE *ptr;
{
- return RSTRING_PTR(rb_string_value(ptr));
+ return RSTRING(rb_string_value(ptr))->ptr;
}
char *
-rb_string_value_cstr(volatile VALUE *ptr)
+rb_string_value_cstr(ptr)
+ volatile VALUE *ptr;
{
VALUE str = rb_string_value(ptr);
- char *s = RSTRING_PTR(str);
+ char *s = RSTRING(str)->ptr;
- if (!s || RSTRING_LEN(str) != strlen(s)) {
+ if (!s || RSTRING(str)->len != strlen(s)) {
rb_raise(rb_eArgError, "string contains null byte");
}
return s;
}
VALUE
-rb_check_string_type(VALUE str)
+rb_check_string_type(str)
+ VALUE str;
{
str = rb_check_convert_type(str, T_STRING, "String", "to_str");
+ if (!NIL_P(str) && !RSTRING(str)->ptr) {
+ FL_SET(str, ELTS_SHARED);
+ RSTRING(str)->ptr = null_str;
+ }
return str;
}
VALUE
-rb_str_substr(VALUE str, long beg, long len)
+rb_str_substr(str, beg, len)
+ VALUE str;
+ long beg, len;
{
VALUE str2;
if (len < 0) return Qnil;
- if (beg > RSTRING_LEN(str)) return Qnil;
+ if (beg > RSTRING(str)->len) return Qnil;
if (beg < 0) {
- beg += RSTRING_LEN(str);
+ beg += RSTRING(str)->len;
if (beg < 0) return Qnil;
}
- if (beg + len > RSTRING_LEN(str)) {
- len = RSTRING_LEN(str) - beg;
+ if (beg + len > RSTRING(str)->len) {
+ len = RSTRING(str)->len - beg;
}
if (len < 0) {
len = 0;
@@ -635,15 +603,15 @@ rb_str_substr(VALUE str, long beg, long len)
if (len == 0) {
str2 = rb_str_new5(str,0,0);
}
- else if (len > RSTRING_EMBED_LEN_MAX &&
- beg + len == RSTRING_LEN(str) && !STR_ASSOC_P(str)) {
+ else if (len > sizeof(struct RString)/2 &&
+ beg + len == RSTRING(str)->len && !FL_TEST(str, STR_ASSOC)) {
str2 = rb_str_new4(str);
str2 = str_new3(rb_obj_class(str2), str2);
- RSTRING(str2)->as.heap.ptr += RSTRING_LEN(str2) - len;
- RSTRING(str2)->as.heap.len = len;
+ RSTRING(str2)->ptr += RSTRING(str2)->len - len;
+ RSTRING(str2)->len = len;
}
else {
- str2 = rb_str_new5(str, RSTRING_PTR(str)+beg, len);
+ str2 = rb_str_new5(str, RSTRING(str)->ptr+beg, len);
}
OBJ_INFECT(str2, str);
@@ -651,17 +619,19 @@ rb_str_substr(VALUE str, long beg, long len)
}
VALUE
-rb_str_freeze(VALUE str)
+rb_str_freeze(str)
+ VALUE str;
{
return rb_obj_freeze(str);
}
VALUE
-rb_str_dup_frozen(VALUE str)
+rb_str_dup_frozen(str)
+ VALUE str;
{
- if (STR_SHARED_P(str) && RSTRING(str)->as.heap.aux.shared) {
- VALUE shared = RSTRING(str)->as.heap.aux.shared;
- if (RSTRING_LEN(shared) == RSTRING_LEN(str)) {
+ if (FL_TEST(str, ELTS_SHARED) && RSTRING(str)->aux.shared) {
+ VALUE shared = RSTRING(str)->aux.shared;
+ if (RSTRING(shared)->len == RSTRING(str)->len) {
OBJ_FREEZE(shared);
return shared;
}
@@ -673,7 +643,8 @@ rb_str_dup_frozen(VALUE str)
}
VALUE
-rb_str_locktmp(VALUE str)
+rb_str_locktmp(str)
+ VALUE str;
{
if (FL_TEST(str, STR_TMPLOCK)) {
rb_raise(rb_eRuntimeError, "temporal locking already locked string");
@@ -683,7 +654,8 @@ rb_str_locktmp(VALUE str)
}
VALUE
-rb_str_unlocktmp(VALUE str)
+rb_str_unlocktmp(str)
+ VALUE str;
{
if (!FL_TEST(str, STR_TMPLOCK)) {
rb_raise(rb_eRuntimeError, "temporal unlocking already unlocked string");
@@ -692,99 +664,109 @@ rb_str_unlocktmp(VALUE str)
return str;
}
-void
-rb_str_set_len(VALUE str, long len)
-{
- STR_SET_LEN(str, len);
- RSTRING_PTR(str)[len] = '\0';
-}
-
VALUE
-rb_str_resize(VALUE str, long len)
+rb_str_resize(str, len)
+ VALUE str;
+ long len;
{
if (len < 0) {
rb_raise(rb_eArgError, "negative string size (or size too big)");
}
rb_str_modify(str);
- if (len != RSTRING_LEN(str)) {
- if (STR_EMBED_P(str)) {
- char *ptr;
- if (len <= RSTRING_EMBED_LEN_MAX) {
- STR_SET_EMBED_LEN(str, len);
- RSTRING_PTR(str)[len] = '\0';
- return str;
+ if (len != RSTRING(str)->len) {
+ if (RSTRING(str)->len < len || RSTRING(str)->len - len > 1024) {
+ REALLOC_N(RSTRING(str)->ptr, char, len+1);
+ if (!FL_TEST(str, STR_NOCAPA)) {
+ RSTRING(str)->aux.capa = len;
}
- ptr = ALLOC_N(char,len+1);
- MEMCPY(ptr, RSTRING_PTR(str), char, RSTRING_LEN(str));
- RSTRING(str)->as.heap.ptr = ptr;
- STR_SET_NOEMBED(str);
}
- else if (RSTRING_LEN(str) < len || RSTRING_LEN(str) - len > 1024) {
- REALLOC_N(RSTRING(str)->as.heap.ptr, char, len+1);
- }
- if (!STR_NOCAPA_P(str)) {
- RSTRING(str)->as.heap.aux.capa = len;
- }
- RSTRING(str)->as.heap.len = len;
- RSTRING(str)->as.heap.ptr[len] = '\0'; /* sentinel */
+ RSTRING(str)->len = len;
+ RSTRING(str)->ptr[len] = '\0'; /* sentinel */
}
return str;
}
-VALUE
-rb_str_buf_cat(VALUE str, const char *ptr, long len)
+static VALUE
+str_buf_cat(str, ptr, len)
+ VALUE str;
+ const char *ptr;
+ long len;
{
- long capa, total;
+ long capa, total, off = -1;;
- if (len == 0) return str;
- if (len < 0) {
- rb_raise(rb_eArgError, "negative string size (or size too big)");
- }
rb_str_modify(str);
- if (STR_ASSOC_P(str)) {
- FL_UNSET(str, STR_ASSOC);
- capa = RSTRING(str)->as.heap.aux.capa = RSTRING_LEN(str);
+ if (ptr >= RSTRING(str)->ptr && ptr <= RSTRING(str)->ptr + RSTRING(str)->len) {
+ off = ptr - RSTRING(str)->ptr;
}
- else if (STR_EMBED_P(str)) {
- capa = RSTRING_EMBED_LEN_MAX;
+ if (len == 0) return 0;
+ if (FL_TEST(str, STR_ASSOC)) {
+ FL_UNSET(str, STR_ASSOC);
+ capa = RSTRING(str)->aux.capa = RSTRING(str)->len;
}
else {
- capa = RSTRING(str)->as.heap.aux.capa;
+ capa = RSTRING(str)->aux.capa;
+ }
+ if (RSTRING(str)->len >= LONG_MAX - len) {
+ rb_raise(rb_eArgError, "string sizes too big");
}
- total = RSTRING_LEN(str)+len;
+ 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);
}
- memcpy(RSTRING_PTR(str) + RSTRING_LEN(str), ptr, len);
- STR_SET_LEN(str, total);
- RSTRING_PTR(str)[total] = '\0'; /* sentinel */
+ 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 */
return str;
}
VALUE
-rb_str_buf_cat2(VALUE str, const char *ptr)
+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;
{
return rb_str_buf_cat(str, ptr, strlen(ptr));
}
VALUE
-rb_str_cat(VALUE str, const char *ptr, long len)
+rb_str_cat(str, ptr, len)
+ VALUE str;
+ const char *ptr;
+ long len;
{
if (len < 0) {
rb_raise(rb_eArgError, "negative string size (or size too big)");
}
- if (STR_ASSOC_P(str)) {
+ if (FL_TEST(str, STR_ASSOC)) {
rb_str_modify(str);
- if (STR_EMBED_P(str)) str_make_independent(str);
- REALLOC_N(RSTRING(str)->as.heap.ptr, char, RSTRING(str)->as.heap.len+len);
- memcpy(RSTRING(str)->as.heap.ptr + RSTRING(str)->as.heap.len, ptr, len);
- RSTRING(str)->as.heap.len += len;
- RSTRING(str)->as.heap.ptr[RSTRING(str)->as.heap.len] = '\0'; /* sentinel */
+ REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len+len+1);
+ memcpy(RSTRING(str)->ptr + RSTRING(str)->len, ptr, len);
+ RSTRING(str)->len += len;
+ RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; /* sentinel */
return str;
}
@@ -792,54 +774,36 @@ rb_str_cat(VALUE str, const char *ptr, long len)
}
VALUE
-rb_str_cat2(VALUE str, const char *ptr)
+rb_str_cat2(str, ptr)
+ VALUE str;
+ const char *ptr;
{
return rb_str_cat(str, ptr, strlen(ptr));
}
VALUE
-rb_str_buf_append(VALUE str, VALUE str2)
+rb_str_buf_append(str, str2)
+ VALUE str, str2;
{
- long capa, len;
-
- rb_str_modify(str);
- if (STR_ASSOC_P(str)) {
- FL_UNSET(str, STR_ASSOC);
- capa = RSTRING(str)->as.heap.aux.capa = RSTRING_LEN(str);
- }
- else if (STR_EMBED_P(str)) {
- capa = RSTRING_EMBED_LEN_MAX;
- }
- else {
- capa = RSTRING(str)->as.heap.aux.capa;
- }
- len = RSTRING_LEN(str)+RSTRING_LEN(str2);
- if (capa <= len) {
- while (len > capa) {
- capa = (capa + 1) * 2;
- }
- RESIZE_CAPA(str, capa);
- }
- memcpy(RSTRING_PTR(str) + RSTRING_LEN(str),
- RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
- STR_SET_LEN(str, len);
+ str_buf_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
OBJ_INFECT(str, str2);
-
return str;
}
VALUE
-rb_str_append(VALUE str, VALUE str2)
+rb_str_append(str, str2)
+ VALUE str, str2;
{
StringValue(str2);
rb_str_modify(str);
- if (RSTRING_LEN(str2) > 0) {
- if (STR_ASSOC_P(str)) {
- long len = RSTRING_LEN(str)+RSTRING_LEN(str2);
- REALLOC_N(RSTRING(str)->as.heap.ptr, char, len+1);
- memcpy(RSTRING(str)->as.heap.ptr + RSTRING(str)->as.heap.len,
- RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
- RSTRING(str)->as.heap.len = len;
+ if (RSTRING(str2)->len > 0) {
+ if (FL_TEST(str, STR_ASSOC)) {
+ long len = RSTRING(str)->len+RSTRING(str2)->len;
+ REALLOC_N(RSTRING(str)->ptr, char, len+1);
+ memcpy(RSTRING(str)->ptr + RSTRING(str)->len,
+ RSTRING(str2)->ptr, RSTRING(str2)->len);
+ RSTRING(str)->ptr[len] = '\0'; /* sentinel */
+ RSTRING(str)->len = len;
}
else {
return rb_str_buf_append(str, str2);
@@ -867,7 +831,8 @@ rb_str_append(VALUE str, VALUE str2)
*/
VALUE
-rb_str_concat(VALUE str1, VALUE str2)
+rb_str_concat(str1, str2)
+ VALUE str1, str2;
{
if (FIXNUM_P(str2)) {
int i = FIX2INT(str2);
@@ -876,137 +841,45 @@ rb_str_concat(VALUE str1, VALUE str2)
return rb_str_cat(str1, &c, 1);
}
}
- return rb_str_append(str1, str2);
-}
-
-typedef unsigned int ub4; /* unsigned 4-byte quantities */
-typedef unsigned char ub1; /* unsigned 1-byte quantities */
+ str1 = rb_str_append(str1, str2);
-#define hashsize(n) ((ub4)1<<(n))
-#define hashmask(n) (hashsize(n)-1)
-
-/*
---------------------------------------------------------------------
-mix -- mix 3 32-bit values reversibly.
-For every delta with one or two bits set, and the deltas of all three
- high bits or all three low bits, whether the original value of a,b,c
- is almost all zero or is uniformly distributed,
-* If mix() is run forward or backward, at least 32 bits in a,b,c
- have at least 1/4 probability of changing.
-* If mix() is run forward, every bit of c will change between 1/3 and
- 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
-mix() was built out of 36 single-cycle latency instructions in a
- structure that could supported 2x parallelism, like so:
- a -= b;
- a -= c; x = (c>>13);
- b -= c; a ^= x;
- b -= a; x = (a<<8);
- c -= a; b ^= x;
- c -= b; x = (b>>13);
- ...
- Unfortunately, superscalar Pentiums and Sparcs can't take advantage
- of that parallelism. They've also turned some of those single-cycle
- latency instructions into multi-cycle latency instructions. Still,
- this is the fastest good hash I could find. There were about 2^^68
- to choose from. I only looked at a billion or so.
---------------------------------------------------------------------
-*/
-#define mix(a,b,c) \
-{ \
- a -= b; a -= c; a ^= (c>>13); \
- b -= c; b -= a; b ^= (a<<8); \
- c -= a; c -= b; c ^= (b>>13); \
- a -= b; a -= c; a ^= (c>>12); \
- b -= c; b -= a; b ^= (a<<16); \
- c -= a; c -= b; c ^= (b>>5); \
- a -= b; a -= c; a ^= (c>>3); \
- b -= c; b -= a; b ^= (a<<10); \
- c -= a; c -= b; c ^= (b>>15); \
-}
-
-/*
---------------------------------------------------------------------
-hash() -- hash a variable-length key into a 32-bit value
- k : the key (the unaligned variable-length array of bytes)
- len : the length of the key, counting by bytes
- initval : can be any 4-byte value
-Returns a 32-bit value. Every bit of the key affects every bit of
-the return value. Every 1-bit and 2-bit delta achieves avalanche.
-About 6*len+35 instructions.
-
-The best hash table sizes are powers of 2. There is no need to do
-mod a prime (mod is sooo slow!). If you need less than 32 bits,
-use a bitmask. For example, if you need only 10 bits, do
- h = (h & hashmask(10));
-In which case, the hash table should have hashsize(10) elements.
-
-If you are hashing n strings (ub1 **)k, do it like this:
- for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
-
-By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this
-code any way you wish, private, educational, or commercial. It's free.
-
-See http://burtleburtle.net/bob/hash/evahash.html
-Use for hash table lookup, or anything where one collision in 2^^32 is
-acceptable. Do NOT use for cryptographic purposes.
---------------------------------------------------------------------
-*/
-
-static ub4
-hash(const ub1 *k, ub4 length, ub4 initval)
- /* k: the key */
- /* length: the length of the key */
- /* initval: the previous hash, or an arbitrary value */
-{
- register ub4 a,b,c,len;
-
- /* Set up the internal state */
- len = length;
- a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
- c = initval; /* the previous hash value */
-
- /*---------------------------------------- handle most of the key */
- while (len >= 12) {
- a += (k[0] +((ub4)k[1]<<8) +((ub4)k[2]<<16) +((ub4)k[3]<<24));
- b += (k[4] +((ub4)k[5]<<8) +((ub4)k[6]<<16) +((ub4)k[7]<<24));
- c += (k[8] +((ub4)k[9]<<8) +((ub4)k[10]<<16)+((ub4)k[11]<<24));
- mix(a,b,c);
- k += 12; len -= 12;
- }
-
- /*------------------------------------- handle the last 11 bytes */
- c += length;
- switch(len) /* all the case statements fall through */
- {
- case 11: c+=((ub4)k[10]<<24);
- case 10: c+=((ub4)k[9]<<16);
- case 9 : c+=((ub4)k[8]<<8);
- /* the first byte of c is reserved for the length */
- case 8 : b+=((ub4)k[7]<<24);
- case 7 : b+=((ub4)k[6]<<16);
- case 6 : b+=((ub4)k[5]<<8);
- case 5 : b+=k[4];
- case 4 : a+=((ub4)k[3]<<24);
- case 3 : a+=((ub4)k[2]<<16);
- case 2 : a+=((ub4)k[1]<<8);
- case 1 : a+=k[0];
- /* case 0: nothing left to add */
- }
- mix(a,b,c);
- /*-------------------------------------------- report the result */
- return c;
-}
-
-int
-rb_memhash(const void *ptr, long len)
-{
- return hash(ptr, len, 0);
+ return str1;
}
int
-rb_str_hash(VALUE str)
+rb_str_hash(str)
+ VALUE str;
{
- return rb_memhash(RSTRING_PTR(str), RSTRING_LEN(str));
+ register long len = RSTRING(str)->len;
+ register char *p = RSTRING(str)->ptr;
+ register int key = 0;
+
+#if defined(HASH_ELFHASH)
+ register unsigned int g;
+
+ while (len--) {
+ key = (key << 4) + *p++;
+ if (g = key & 0xF0000000)
+ key ^= g >> 24;
+ key &= ~g;
+ }
+#elif defined(HASH_PERL)
+ while (len--) {
+ key += *p++;
+ key += (key << 10);
+ key ^= (key >> 6);
+ }
+ key += (key << 3);
+ key ^= (key >> 11);
+ key += (key << 15);
+#else
+ while (len--) {
+ key = key*65599 + *p;
+ p++;
+ }
+ key = key + (key>>5);
+#endif
+ return key;
}
/*
@@ -1017,25 +890,27 @@ rb_str_hash(VALUE str)
*/
static VALUE
-rb_str_hash_m(VALUE str)
+rb_str_hash_m(str)
+ VALUE str;
{
- int hval = rb_str_hash(str);
- return INT2FIX(hval);
+ int key = rb_str_hash(str);
+ return INT2FIX(key);
}
#define lesser(a,b) (((a)>(b))?(b):(a))
int
-rb_str_cmp(VALUE str1, VALUE str2)
+rb_str_cmp(str1, str2)
+ VALUE str1, str2;
{
long len;
int retval;
- len = lesser(RSTRING_LEN(str1), RSTRING_LEN(str2));
- retval = rb_memcmp(RSTRING_PTR(str1), RSTRING_PTR(str2), len);
+ len = lesser(RSTRING(str1)->len, RSTRING(str2)->len);
+ retval = rb_memcmp(RSTRING(str1)->ptr, RSTRING(str2)->ptr, len);
if (retval == 0) {
- if (RSTRING_LEN(str1) == RSTRING_LEN(str2)) return 0;
- if (RSTRING_LEN(str1) > RSTRING_LEN(str2)) return 1;
+ if (RSTRING(str1)->len == RSTRING(str2)->len) return 0;
+ if (RSTRING(str1)->len > RSTRING(str2)->len) return 1;
return -1;
}
if (retval > 0) return 1;
@@ -1053,7 +928,8 @@ rb_str_cmp(VALUE str1, VALUE str2)
*/
static VALUE
-rb_str_equal(VALUE str1, VALUE str2)
+rb_str_equal(str1, str2)
+ VALUE str1, str2;
{
if (str1 == str2) return Qtrue;
if (TYPE(str2) != T_STRING) {
@@ -1062,13 +938,15 @@ rb_str_equal(VALUE str1, VALUE str2)
}
return rb_equal(str2, str1);
}
- if (RSTRING_LEN(str1) == RSTRING_LEN(str2) &&
+ if (RSTRING(str1)->len == RSTRING(str2)->len &&
rb_str_cmp(str1, str2) == 0) {
return Qtrue;
}
return Qfalse;
}
+#define IS_EVSTR(p,e) ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))
+
/*
* call-seq:
* str.eql?(other) => true or false
@@ -1077,13 +955,14 @@ rb_str_equal(VALUE str1, VALUE str2)
*/
static VALUE
-rb_str_eql(VALUE str1, VALUE str2)
+rb_str_eql(str1, str2)
+ VALUE str1, str2;
{
- if (TYPE(str2) != T_STRING || RSTRING_LEN(str1) != RSTRING_LEN(str2))
+ if (TYPE(str2) != T_STRING || RSTRING(str1)->len != RSTRING(str2)->len)
return Qfalse;
- if (memcmp(RSTRING_PTR(str1), RSTRING_PTR(str2),
- lesser(RSTRING_LEN(str1), RSTRING_LEN(str2))) == 0)
+ if (memcmp(RSTRING(str1)->ptr, RSTRING(str2)->ptr,
+ lesser(RSTRING(str1)->len, RSTRING(str2)->len)) == 0)
return Qtrue;
return Qfalse;
@@ -1115,7 +994,8 @@ rb_str_eql(VALUE str1, VALUE str2)
*/
static VALUE
-rb_str_cmp_m(VALUE str1, VALUE str2)
+rb_str_cmp_m(str1, str2)
+ VALUE str1, str2;
{
long result;
@@ -1155,17 +1035,18 @@ rb_str_cmp_m(VALUE str1, VALUE str2)
*/
static VALUE
-rb_str_casecmp(VALUE str1, VALUE str2)
+rb_str_casecmp(str1, str2)
+ VALUE str1, str2;
{
long len;
int retval;
StringValue(str2);
- len = lesser(RSTRING_LEN(str1), RSTRING_LEN(str2));
- retval = rb_memcicmp(RSTRING_PTR(str1), RSTRING_PTR(str2), len);
+ len = lesser(RSTRING(str1)->len, RSTRING(str2)->len);
+ retval = rb_memcicmp(RSTRING(str1)->ptr, RSTRING(str2)->ptr, len);
if (retval == 0) {
- if (RSTRING_LEN(str1) == RSTRING_LEN(str2)) return INT2FIX(0);
- if (RSTRING_LEN(str1) > RSTRING_LEN(str2)) return INT2FIX(1);
+ if (RSTRING(str1)->len == RSTRING(str2)->len) return INT2FIX(0);
+ if (RSTRING(str1)->len > RSTRING(str2)->len) return INT2FIX(1);
return INT2FIX(-1);
}
if (retval == 0) return INT2FIX(0);
@@ -1174,18 +1055,20 @@ rb_str_casecmp(VALUE str1, VALUE str2)
}
static long
-rb_str_index(VALUE str, VALUE sub, long offset)
+rb_str_index(str, sub, offset)
+ VALUE str, sub;
+ long offset;
{
long pos;
if (offset < 0) {
- offset += RSTRING_LEN(str);
+ offset += RSTRING(str)->len;
if (offset < 0) return -1;
}
- if (RSTRING_LEN(str) - offset < RSTRING_LEN(sub)) return -1;
- if (RSTRING_LEN(sub) == 0) return offset;
- pos = rb_memsearch(RSTRING_PTR(sub), RSTRING_LEN(sub),
- RSTRING_PTR(str)+offset, RSTRING_LEN(str)-offset);
+ if (RSTRING(str)->len - offset < RSTRING(sub)->len) return -1;
+ if (RSTRING(sub)->len == 0) return offset;
+ pos = rb_memsearch(RSTRING(sub)->ptr, RSTRING(sub)->len,
+ RSTRING(str)->ptr+offset, RSTRING(str)->len-offset);
if (pos < 0) return pos;
return pos + offset;
}
@@ -1210,7 +1093,10 @@ rb_str_index(VALUE str, VALUE sub, long offset)
*/
static VALUE
-rb_str_index_m(int argc, VALUE *argv, VALUE str)
+rb_str_index_m(argc, argv, str)
+ int argc;
+ VALUE *argv;
+ VALUE str;
{
VALUE sub;
VALUE initpos;
@@ -1223,7 +1109,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
pos = 0;
}
if (pos < 0) {
- pos += RSTRING_LEN(str);
+ pos += RSTRING(str)->len;
if (pos < 0) {
if (TYPE(sub) == T_REGEXP) {
rb_backref_set(Qnil);
@@ -1241,11 +1127,11 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
case T_FIXNUM:
{
int c = FIX2INT(sub);
- long len = RSTRING_LEN(str);
- char *p = RSTRING_PTR(str);
+ long len = RSTRING(str)->len;
+ unsigned char *p = (unsigned char*)RSTRING(str)->ptr;
for (;pos<len;pos++) {
- if ((unsigned char)p[pos] == c) return LONG2NUM(pos);
+ if (p[pos] == c) return LONG2NUM(pos);
}
return Qnil;
}
@@ -1271,23 +1157,25 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
}
static long
-rb_str_rindex(VALUE str, VALUE sub, long pos)
+rb_str_rindex(str, sub, pos)
+ VALUE str, sub;
+ long pos;
{
- long len = RSTRING_LEN(sub);
+ long len = RSTRING(sub)->len;
char *s, *sbeg, *t;
/* substring longer than string */
- if (RSTRING_LEN(str) < len) return -1;
- if (RSTRING_LEN(str) - pos < len) {
- pos = RSTRING_LEN(str) - len;
+ if (RSTRING(str)->len < len) return -1;
+ if (RSTRING(str)->len - pos < len) {
+ pos = RSTRING(str)->len - len;
}
- sbeg = RSTRING_PTR(str);
- s = RSTRING_PTR(str) + pos;
- t = RSTRING_PTR(sub);
+ sbeg = RSTRING(str)->ptr;
+ s = RSTRING(str)->ptr + pos;
+ t = RSTRING(sub)->ptr;
if (len) {
while (sbeg <= s) {
if (rb_memcmp(s, t, len) == 0) {
- return s - RSTRING_PTR(str);
+ return s - RSTRING(str)->ptr;
}
s--;
}
@@ -1319,7 +1207,10 @@ rb_str_rindex(VALUE str, VALUE sub, long pos)
*/
static VALUE
-rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
+rb_str_rindex_m(argc, argv, str)
+ int argc;
+ VALUE *argv;
+ VALUE str;
{
VALUE sub;
VALUE position;
@@ -1328,7 +1219,7 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
if (rb_scan_args(argc, argv, "11", &sub, &position) == 2) {
pos = NUM2LONG(position);
if (pos < 0) {
- pos += RSTRING_LEN(str);
+ pos += RSTRING(str)->len;
if (pos < 0) {
if (TYPE(sub) == T_REGEXP) {
rb_backref_set(Qnil);
@@ -1336,10 +1227,10 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
return Qnil;
}
}
- if (pos > RSTRING_LEN(str)) pos = RSTRING_LEN(str);
+ if (pos > RSTRING(str)->len) pos = RSTRING(str)->len;
}
else {
- pos = RSTRING_LEN(str);
+ pos = RSTRING(str)->len;
}
switch (TYPE(sub)) {
@@ -1359,16 +1250,15 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
case T_FIXNUM:
{
int c = FIX2INT(sub);
- char *p = RSTRING_PTR(str) + pos;
- char *pbeg = RSTRING_PTR(str);
+ unsigned char *p = (unsigned char*)RSTRING(str)->ptr + pos;
+ unsigned char *pbeg = (unsigned char*)RSTRING(str)->ptr;
- if (pos == RSTRING_LEN(str)) {
+ if (pos == RSTRING(str)->len) {
if (pos == 0) return Qnil;
--p;
}
while (pbeg <= p) {
- if ((unsigned char)*p == c)
- return LONG2NUM((char*)p - RSTRING_PTR(str));
+ if (*p == c) return LONG2NUM((char*)p - RSTRING(str)->ptr);
p--;
}
return Qnil;
@@ -1396,7 +1286,8 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
*/
static VALUE
-rb_str_match(VALUE x, VALUE y)
+rb_str_match(x, y)
+ VALUE x, y;
{
switch (TYPE(y)) {
case T_STRING:
@@ -1411,7 +1302,7 @@ rb_str_match(VALUE x, VALUE y)
}
-static VALUE get_pat(VALUE, int);
+static VALUE get_pat _((VALUE, int));
/*
@@ -1419,9 +1310,7 @@ static VALUE get_pat(VALUE, int);
* str.match(pattern) => matchdata or nil
*
* Converts <i>pattern</i> to a <code>Regexp</code> (if it isn't already one),
- * then invokes its <code>match</code> method on <i>str</i>. If the second
- * parameter is present, it specifies the position in the string to begin the
- * search.
+ * then invokes its <code>match</code> method on <i>str</i>.
*
* 'hello'.match('(.)\1') #=> #<MatchData:0x401b3d30>
* 'hello'.match('(.)\1')[0] #=> "ll"
@@ -1430,18 +1319,15 @@ static VALUE get_pat(VALUE, int);
*/
static VALUE
-rb_str_match_m(int argc, VALUE *argv, VALUE str)
+rb_str_match_m(str, re)
+ VALUE str, re;
{
- VALUE re;
- if (argc < 1)
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
- re = argv[0];
- argv[0] = str;
- return rb_funcall2(get_pat(re, 0), rb_intern("match"), argc, argv);
+ return rb_funcall(get_pat(re, 0), rb_intern("match"), 1, str);
}
static char
-succ_char(char *s)
+succ_char(s)
+ char *s;
{
char c = *s;
@@ -1491,18 +1377,19 @@ succ_char(char *s)
*/
static VALUE
-rb_str_succ(VALUE orig)
+rb_str_succ(orig)
+ VALUE orig;
{
VALUE str;
char *sbeg, *s;
int c = -1;
long n = 0;
- str = rb_str_new5(orig, RSTRING_PTR(orig), RSTRING_LEN(orig));
+ str = rb_str_new5(orig, RSTRING(orig)->ptr, RSTRING(orig)->len);
OBJ_INFECT(str, orig);
- if (RSTRING_LEN(str) == 0) return str;
+ if (RSTRING(str)->len == 0) return str;
- sbeg = RSTRING_PTR(str); s = sbeg + RSTRING_LEN(str) - 1;
+ sbeg = RSTRING(str)->ptr; s = sbeg + RSTRING(str)->len - 1;
while (sbeg <= s) {
if (ISALNUM(*s)) {
@@ -1512,7 +1399,7 @@ rb_str_succ(VALUE orig)
s--;
}
if (c == -1) { /* str contains no alnum */
- sbeg = RSTRING_PTR(str); s = sbeg + RSTRING_LEN(str) - 1;
+ sbeg = RSTRING(str)->ptr; s = sbeg + RSTRING(str)->len - 1;
c = '\001';
while (sbeg <= s) {
if ((*s += 1) != 0) break;
@@ -1520,12 +1407,12 @@ rb_str_succ(VALUE orig)
}
}
if (s < sbeg) {
- RESIZE_CAPA(str, RSTRING_LEN(str) + 1);
- s = RSTRING_PTR(str) + n;
- memmove(s+1, s, RSTRING_LEN(str) - n);
+ RESIZE_CAPA(str, RSTRING(str)->len + 1);
+ s = RSTRING(str)->ptr + n;
+ memmove(s+1, s, RSTRING(str)->len - n);
*s = c;
- STR_SET_LEN(str, RSTRING_LEN(str) + 1);
- RSTRING_PTR(str)[RSTRING_LEN(str)] = '\0';
+ RSTRING(str)->len += 1;
+ RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
}
return str;
@@ -1542,7 +1429,8 @@ rb_str_succ(VALUE orig)
*/
static VALUE
-rb_str_succ_bang(VALUE str)
+rb_str_succ_bang(str)
+ VALUE str;
{
rb_str_shared_replace(str, rb_str_succ(str));
@@ -1550,7 +1438,9 @@ rb_str_succ_bang(VALUE str)
}
VALUE
-rb_str_upto(VALUE beg, VALUE end, int excl)
+rb_str_upto(beg, end, excl)
+ VALUE beg, end;
+ int excl;
{
VALUE current, after_end;
ID succ = rb_intern("succ");
@@ -1568,7 +1458,7 @@ rb_str_upto(VALUE beg, VALUE end, int excl)
StringValue(current);
if (excl && rb_str_equal(current, end)) break;
StringValue(current);
- if (RSTRING_LEN(current) > RSTRING_LEN(end))
+ if (RSTRING(current)->len > RSTRING(end)->len || RSTRING(current)->len == 0)
break;
}
@@ -1597,13 +1487,16 @@ rb_str_upto(VALUE beg, VALUE end, int excl)
*/
static VALUE
-rb_str_upto_m(VALUE beg, VALUE end)
+rb_str_upto_m(beg, end)
+ VALUE beg, end;
{
return rb_str_upto(beg, end, Qfalse);
}
static VALUE
-rb_str_subpat(VALUE str, VALUE re, int nth)
+rb_str_subpat(str, re, nth)
+ VALUE str, re;
+ int nth;
{
if (rb_reg_search(re, str, 0, 0) >= 0) {
return rb_reg_nth_match(nth, rb_backref_get());
@@ -1612,7 +1505,9 @@ rb_str_subpat(VALUE str, VALUE re, int nth)
}
static VALUE
-rb_str_aref(VALUE str, VALUE indx)
+rb_str_aref(str, indx)
+ VALUE str;
+ VALUE indx;
{
long idx;
@@ -1622,12 +1517,12 @@ rb_str_aref(VALUE str, VALUE indx)
num_index:
if (idx < 0) {
- idx = RSTRING_LEN(str) + idx;
+ idx = RSTRING(str)->len + idx;
}
- if (idx < 0 || RSTRING_LEN(str) <= idx) {
+ if (idx < 0 || RSTRING(str)->len <= idx) {
return Qnil;
}
- return rb_str_substr(str, idx, 1);
+ return INT2FIX(RSTRING(str)->ptr[idx] & 0xff);
case T_REGEXP:
return rb_str_subpat(str, indx, 0);
@@ -1643,7 +1538,7 @@ rb_str_aref(VALUE str, VALUE indx)
long beg, len;
VALUE tmp;
- switch (rb_range_beg_len(indx, &beg, &len, RSTRING_LEN(str), 0)) {
+ switch (rb_range_beg_len(indx, &beg, &len, RSTRING(str)->len, 0)) {
case Qfalse:
break;
case Qnil:
@@ -1663,21 +1558,21 @@ rb_str_aref(VALUE str, VALUE indx)
/*
* call-seq:
- * str[fixnum] => new_str or nil
+ * str[fixnum] => fixnum or nil
* str[fixnum, fixnum] => new_str or nil
* str[range] => new_str or nil
* str[regexp] => new_str or nil
* str[regexp, fixnum] => new_str or nil
* str[other_str] => new_str or nil
- * str.slice(fixnum) => new_str or nil
+ * str.slice(fixnum) => fixnum or nil
* str.slice(fixnum, fixnum) => new_str or nil
* str.slice(range) => new_str or nil
* str.slice(regexp) => new_str or nil
* str.slice(regexp, fixnum) => new_str or nil
* str.slice(other_str) => new_str or nil
*
- * Element Reference---If passed a single <code>Fixnum</code>, returns a
- * substring of one character at that position. If passed two <code>Fixnum</code>
+ * Element Reference---If passed a single <code>Fixnum</code>, returns the code
+ * of the character at that position. If passed two <code>Fixnum</code>
* objects, returns a substring starting at the offset given by the first, and
* a length given by the second. If given a range, a substring containing
* characters at offsets given by the range is returned. In all three cases, if
@@ -1693,7 +1588,7 @@ rb_str_aref(VALUE str, VALUE indx)
* match.
*
* a = "hello there"
- * a[1] #=> "e"
+ * a[1] #=> 101
* a[1,3] #=> "ell"
* a[1..3] #=> "ell"
* a[-3,2] #=> "er"
@@ -1709,7 +1604,10 @@ rb_str_aref(VALUE str, VALUE indx)
*/
static VALUE
-rb_str_aref_m(int argc, VALUE *argv, VALUE str)
+rb_str_aref_m(argc, argv, str)
+ int argc;
+ VALUE *argv;
+ VALUE str;
{
if (argc == 2) {
if (TYPE(argv[0]) == T_REGEXP) {
@@ -1724,58 +1622,67 @@ rb_str_aref_m(int argc, VALUE *argv, VALUE str)
}
static void
-rb_str_splice(VALUE str, long beg, long len, VALUE val)
+rb_str_splice(str, beg, len, val)
+ VALUE str;
+ long beg, len;
+ VALUE val;
{
if (len < 0) rb_raise(rb_eIndexError, "negative length %ld", len);
StringValue(val);
rb_str_modify(str);
- if (RSTRING_LEN(str) < beg) {
+ if (RSTRING(str)->len < beg) {
out_of_range:
rb_raise(rb_eIndexError, "index %ld out of string", beg);
}
if (beg < 0) {
- if (-beg > RSTRING_LEN(str)) {
+ if (-beg > RSTRING(str)->len) {
goto out_of_range;
}
- beg += RSTRING_LEN(str);
+ beg += RSTRING(str)->len;
}
- if (RSTRING_LEN(str) < beg + len) {
- len = RSTRING_LEN(str) - beg;
+ if (RSTRING(str)->len < len || RSTRING(str)->len < beg + len) {
+ len = RSTRING(str)->len - beg;
}
- if (len < RSTRING_LEN(val)) {
+ if (len < RSTRING(val)->len) {
/* expand string */
- RESIZE_CAPA(str, RSTRING_LEN(str) + RSTRING_LEN(val) - len + 1);
+ RESIZE_CAPA(str, RSTRING(str)->len + RSTRING(val)->len - len + 1);
}
- if (RSTRING_LEN(val) != len) {
- memmove(RSTRING_PTR(str) + beg + RSTRING_LEN(val),
- RSTRING_PTR(str) + beg + len,
- RSTRING_LEN(str) - (beg + len));
+ if (RSTRING(val)->len != len) {
+ memmove(RSTRING(str)->ptr + beg + RSTRING(val)->len,
+ RSTRING(str)->ptr + beg + len,
+ RSTRING(str)->len - (beg + len));
}
- if (RSTRING_LEN(str) < beg && len < 0) {
- MEMZERO(RSTRING_PTR(str) + RSTRING_LEN(str), char, -len);
+ if (RSTRING(str)->len < beg && len < 0) {
+ MEMZERO(RSTRING(str)->ptr + RSTRING(str)->len, char, -len);
}
- if (RSTRING_LEN(val) > 0) {
- memmove(RSTRING_PTR(str)+beg, RSTRING_PTR(val), RSTRING_LEN(val));
+ if (RSTRING(val)->len > 0) {
+ memmove(RSTRING(str)->ptr+beg, RSTRING(val)->ptr, RSTRING(val)->len);
}
- STR_SET_LEN(str, RSTRING_LEN(str) + RSTRING_LEN(val) - len);
- if (RSTRING_PTR(str)) {
- RSTRING_PTR(str)[RSTRING_LEN(str)] = '\0';
+ RSTRING(str)->len += RSTRING(val)->len - len;
+ if (RSTRING(str)->ptr) {
+ RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
}
OBJ_INFECT(str, val);
}
void
-rb_str_update(VALUE str, long beg, long len, VALUE val)
+rb_str_update(str, beg, len, val)
+ VALUE str;
+ long beg, len;
+ VALUE val;
{
rb_str_splice(str, beg, len, val);
}
static void
-rb_str_subpat_set(VALUE str, VALUE re, int nth, VALUE val)
+rb_str_subpat_set(str, re, nth, val)
+ VALUE str, re;
+ int nth;
+ VALUE val;
{
VALUE match;
long start, end, len;
@@ -1805,24 +1712,36 @@ rb_str_subpat_set(VALUE str, VALUE re, int nth, VALUE val)
}
static VALUE
-rb_str_aset(VALUE str, VALUE indx, VALUE val)
+rb_str_aset(str, indx, val)
+ VALUE str;
+ VALUE indx, val;
{
long idx, beg;
switch (TYPE(indx)) {
case T_FIXNUM:
- num_index:
idx = FIX2LONG(indx);
- if (RSTRING_LEN(str) <= idx) {
+ num_index:
+ if (RSTRING(str)->len <= idx) {
out_of_range:
rb_raise(rb_eIndexError, "index %ld out of string", idx);
}
if (idx < 0) {
- if (-idx > RSTRING_LEN(str))
+ if (-idx > RSTRING(str)->len)
goto out_of_range;
- idx += RSTRING_LEN(str);
+ idx += RSTRING(str)->len;
+ }
+ if (FIXNUM_P(val)) {
+ rb_str_modify(str);
+ if (RSTRING(str)->len == idx) {
+ RSTRING(str)->len += 1;
+ RESIZE_CAPA(str, RSTRING(str)->len);
+ }
+ RSTRING(str)->ptr[idx] = FIX2INT(val) & 0xff;
+ }
+ else {
+ rb_str_splice(str, idx, 1, val);
}
- rb_str_splice(str, idx, 1, val);
return val;
case T_REGEXP:
@@ -1834,14 +1753,14 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val)
if (beg < 0) {
rb_raise(rb_eIndexError, "string not matched");
}
- rb_str_splice(str, beg, RSTRING_LEN(indx), val);
+ rb_str_splice(str, beg, RSTRING(indx)->len, val);
return val;
default:
/* check if indx is Range */
{
long beg, len;
- if (rb_range_beg_len(indx, &beg, &len, RSTRING_LEN(str), 2)) {
+ if (rb_range_beg_len(indx, &beg, &len, RSTRING(str)->len, 2)) {
rb_str_splice(str, beg, len, val);
return val;
}
@@ -1853,6 +1772,7 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val)
/*
* call-seq:
+ * str[fixnum] = fixnum
* str[fixnum] = new_str
* str[fixnum, fixnum] = new_str
* str[range] = aString
@@ -1876,7 +1796,10 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val)
*/
static VALUE
-rb_str_aset_m(int argc, VALUE *argv, VALUE str)
+rb_str_aset_m(argc, argv, str)
+ int argc;
+ VALUE *argv;
+ VALUE str;
{
if (argc == 3) {
if (TYPE(argv[0]) == T_REGEXP) {
@@ -1911,12 +1834,13 @@ rb_str_aset_m(int argc, VALUE *argv, VALUE str)
*/
static VALUE
-rb_str_insert(VALUE str, VALUE idx, VALUE str2)
+rb_str_insert(str, idx, str2)
+ VALUE str, idx, str2;
{
long pos = NUM2LONG(idx);
if (pos == -1) {
- pos = RSTRING_LEN(str);
+ pos = RSTRING(str)->len;
}
else if (pos < 0) {
pos++;
@@ -1925,7 +1849,6 @@ rb_str_insert(VALUE str, VALUE idx, VALUE str2)
return str;
}
-
/*
* call-seq:
* str.slice!(fixnum) => fixnum or nil
@@ -1949,7 +1872,10 @@ rb_str_insert(VALUE str, VALUE idx, VALUE str2)
*/
static VALUE
-rb_str_slice_bang(int argc, VALUE *argv, VALUE str)
+rb_str_slice_bang(argc, argv, str)
+ int argc;
+ VALUE *argv;
+ VALUE str;
{
VALUE result;
VALUE buf[3];
@@ -1970,7 +1896,9 @@ rb_str_slice_bang(int argc, VALUE *argv, VALUE str)
}
static VALUE
-get_pat(VALUE pat, int quote)
+get_pat(pat, quote)
+ VALUE pat;
+ int quote;
{
VALUE val;
@@ -2008,7 +1936,10 @@ get_pat(VALUE pat, int quote)
*/
static VALUE
-rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
+rb_str_sub_bang(argc, argv, str)
+ int argc;
+ VALUE *argv;
+ VALUE str;
{
VALUE pat, repl, match;
struct re_registers *regs;
@@ -2030,12 +1961,11 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
pat = get_pat(argv[0], 1);
if (rb_reg_search(pat, str, 0, 0) >= 0) {
- rb_str_modify(str);
match = rb_backref_get();
regs = RMATCH(match)->regs;
if (iter) {
- char *p = RSTRING_PTR(str); long len = RSTRING_LEN(str);
+ char *p = RSTRING(str)->ptr; long len = RSTRING(str)->len;
rb_match_busy(match);
repl = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
@@ -2044,22 +1974,23 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
rb_backref_set(match);
}
else {
- repl = rb_reg_regsub(repl, str, regs, pat);
+ repl = rb_reg_regsub(repl, str, regs);
}
+ rb_str_modify(str);
if (OBJ_TAINTED(repl)) tainted = 1;
plen = END(0) - BEG(0);
- if (RSTRING_LEN(repl) > plen) {
- RESIZE_CAPA(str, RSTRING_LEN(str) + RSTRING_LEN(repl) - plen);
+ if (RSTRING(repl)->len > plen) {
+ RESIZE_CAPA(str, RSTRING(str)->len + RSTRING(repl)->len - plen);
}
- if (RSTRING_LEN(repl) != plen) {
- memmove(RSTRING_PTR(str) + BEG(0) + RSTRING_LEN(repl),
- RSTRING_PTR(str) + BEG(0) + plen,
- RSTRING_LEN(str) - BEG(0) - plen);
+ if (RSTRING(repl)->len != plen) {
+ memmove(RSTRING(str)->ptr + BEG(0) + RSTRING(repl)->len,
+ RSTRING(str)->ptr + BEG(0) + plen,
+ RSTRING(str)->len - BEG(0) - plen);
}
- memcpy(RSTRING_PTR(str) + BEG(0),
- RSTRING_PTR(repl), RSTRING_LEN(repl));
- STR_SET_LEN(str, RSTRING_LEN(str) + RSTRING_LEN(repl) - plen);
- RSTRING_PTR(str)[RSTRING_LEN(str)] = '\0';
+ memcpy(RSTRING(str)->ptr + BEG(0),
+ RSTRING(repl)->ptr, RSTRING(repl)->len);
+ RSTRING(str)->len += RSTRING(repl)->len - plen;
+ RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
if (tainted) OBJ_TAINT(str);
return str;
@@ -2083,7 +2014,7 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
* If the method call specifies <i>replacement</i>, special variables such as
* <code>$&</code> will not be useful, as substitution into the string occurs
* before the pattern match starts. However, the sequences <code>\1</code>,
- * <code>\2</code>, <code>\k<group_name></code>, etc., may be used.
+ * <code>\2</code>, etc., may be used.
*
* In the block form, the current match string is passed in as a parameter, and
* variables such as <code>$1</code>, <code>$2</code>, <code>$`</code>,
@@ -2093,14 +2024,16 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
* The result inherits any tainting in the original string or any supplied
* replacement string.
*
- * "hello".sub(/[aeiou]/, '*') #=> "h*llo"
- * "hello".sub(/([aeiou])/, '<\1>') #=> "h<e>llo"
- * "hello".sub(/./) {|s| s[0].to_s + ' ' } #=> "104 ello"
- * "hello".sub(/(?<foo>[aeiou])/, '*\k<foo>*') #=> "h*e*llo"
+ * "hello".sub(/[aeiou]/, '*') #=> "h*llo"
+ * "hello".sub(/([aeiou])/, '<\1>') #=> "h<e>llo"
+ * "hello".sub(/./) {|s| s[0].to_s + ' ' } #=> "104 ello"
*/
static VALUE
-rb_str_sub(int argc, VALUE *argv, VALUE str)
+rb_str_sub(argc, argv, str)