ruby-changes:54324
From: naruse <ko1@a...>
Date: Tue, 25 Dec 2018 07:32:23 +0900 (JST)
Subject: [ruby-changes:54324] naruse:r66532: Release branch of Ruby 2.6
naruse 2018-12-25 07:13:36 +0900 (Tue, 25 Dec 2018) New Revision: 66532 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66532 Log: Release branch of Ruby 2.6 Added directories: branches/ruby_2_6/ Index: ruby_2_6/ext/cgi/escape/escape.c =================================================================== --- ruby_2_6/ext/cgi/escape/escape.c (nonexistent) +++ ruby_2_6/ext/cgi/escape/escape.c (revision 66532) @@ -0,0 +1,422 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/ext/cgi/escape/escape.c#L1 +#include "ruby.h" +#include "ruby/encoding.h" + +RUBY_EXTERN unsigned long ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow); +RUBY_EXTERN const char ruby_hexdigits[]; +RUBY_EXTERN const signed char ruby_digit36_to_number_table[]; +#define lower_hexdigits (ruby_hexdigits+0) +#define upper_hexdigits (ruby_hexdigits+16) +#define char_to_number(c) ruby_digit36_to_number_table[(unsigned char)(c)] + +static VALUE rb_cCGI, rb_mUtil, rb_mEscape; +static ID id_accept_charset; + +static void +html_escaped_cat(VALUE str, char c) +{ + switch (c) { + case '\'': + rb_str_cat_cstr(str, "'"); + break; + case '&': + rb_str_cat_cstr(str, "&"); + break; + case '"': + rb_str_cat_cstr(str, """); + break; + case '<': + rb_str_cat_cstr(str, "<"); + break; + case '>': + rb_str_cat_cstr(str, ">"); + break; + } +} + +static inline void +preserve_original_state(VALUE orig, VALUE dest) +{ + rb_enc_associate(dest, rb_enc_get(orig)); + + RB_OBJ_INFECT_RAW(dest, orig); +} + +static VALUE +optimized_escape_html(VALUE str) +{ + long i, len, beg = 0; + VALUE dest = 0; + const char *cstr; + + len = RSTRING_LEN(str); + cstr = RSTRING_PTR(str); + + for (i = 0; i < len; i++) { + switch (cstr[i]) { + case '\'': + case '&': + case '"': + case '<': + case '>': + if (!dest) { + dest = rb_str_buf_new(len); + } + + rb_str_cat(dest, cstr + beg, i - beg); + beg = i + 1; + + html_escaped_cat(dest, cstr[i]); + break; + } + } + + if (dest) { + rb_str_cat(dest, cstr + beg, len - beg); + preserve_original_state(str, dest); + return dest; + } + else { + return rb_str_dup(str); + } +} + +static VALUE +optimized_unescape_html(VALUE str) +{ + enum {UNICODE_MAX = 0x10ffff}; + rb_encoding *enc = rb_enc_get(str); + unsigned long charlimit = (strcasecmp(rb_enc_name(enc), "UTF-8") == 0 ? UNICODE_MAX : + strcasecmp(rb_enc_name(enc), "ISO-8859-1") == 0 ? 256 : + 128); + long i, len, beg = 0; + size_t clen, plen; + int overflow; + const char *cstr; + char buf[6]; + VALUE dest = 0; + + len = RSTRING_LEN(str); + cstr = RSTRING_PTR(str); + + for (i = 0; i < len; i++) { + unsigned long cc; + char c = cstr[i]; + if (c != '&') continue; + plen = i - beg; + if (++i >= len) break; + c = (unsigned char)cstr[i]; +#define MATCH(s) (len - i >= (int)rb_strlen_lit(s) && \ + memcmp(&cstr[i], s, rb_strlen_lit(s)) == 0 && \ + (i += rb_strlen_lit(s) - 1, 1)) + switch (c) { + case 'a': + ++i; + if (MATCH("pos;")) { + c = '\''; + } + else if (MATCH("mp;")) { + c = '&'; + } + else continue; + break; + case 'q': + ++i; + if (MATCH("uot;")) { + c = '"'; + } + else continue; + break; + case 'g': + ++i; + if (MATCH("t;")) { + c = '>'; + } + else continue; + break; + case 'l': + ++i; + if (MATCH("t;")) { + c = '<'; + } + else continue; + break; + case '#': + if (len - ++i >= 2 && ISDIGIT(cstr[i])) { + cc = ruby_scan_digits(&cstr[i], len-i, 10, &clen, &overflow); + } + else if ((cstr[i] == 'x' || cstr[i] == 'X') && len - ++i >= 2 && ISXDIGIT(cstr[i])) { + cc = ruby_scan_digits(&cstr[i], len-i, 16, &clen, &overflow); + } + else continue; + i += clen; + if (overflow || cc >= charlimit || cstr[i] != ';') continue; + if (!dest) { + dest = rb_str_buf_new(len); + } + rb_str_cat(dest, cstr + beg, plen); + if (charlimit > 256) { + rb_str_cat(dest, buf, rb_enc_mbcput((OnigCodePoint)cc, buf, enc)); + } + else { + c = (unsigned char)cc; + rb_str_cat(dest, &c, 1); + } + beg = i + 1; + continue; + default: + --i; + continue; + } + if (!dest) { + dest = rb_str_buf_new(len); + } + rb_str_cat(dest, cstr + beg, plen); + rb_str_cat(dest, &c, 1); + beg = i + 1; + } + + if (dest) { + rb_str_cat(dest, cstr + beg, len - beg); + preserve_original_state(str, dest); + return dest; + } + else { + return rb_str_dup(str); + } +} + +static unsigned char +url_unreserved_char(unsigned char c) +{ + switch (c) { + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': + case '-': case '.': case '_': case '~': + return 1; + default: + break; + } + return 0; +} + +static VALUE +optimized_escape(VALUE str) +{ + long i, len, beg = 0; + VALUE dest = 0; + const char *cstr; + char buf[4] = {'%'}; + + len = RSTRING_LEN(str); + cstr = RSTRING_PTR(str); + + for (i = 0; i < len; ++i) { + const unsigned char c = (unsigned char)cstr[i]; + if (!url_unreserved_char(c)) { + if (!dest) { + dest = rb_str_buf_new(len); + } + + rb_str_cat(dest, cstr + beg, i - beg); + beg = i + 1; + + if (c == ' ') { + rb_str_cat_cstr(dest, "+"); + } + else { + buf[1] = upper_hexdigits[(c >> 4) & 0xf]; + buf[2] = upper_hexdigits[c & 0xf]; + rb_str_cat(dest, buf, 3); + } + } + } + + if (dest) { + rb_str_cat(dest, cstr + beg, len - beg); + preserve_original_state(str, dest); + return dest; + } + else { + return rb_str_dup(str); + } +} + +static VALUE +optimized_unescape(VALUE str, VALUE encoding) +{ + long i, len, beg = 0; + VALUE dest = 0; + const char *cstr; + rb_encoding *enc = rb_to_encoding(encoding); + int cr, origenc, encidx = rb_enc_to_index(enc); + + len = RSTRING_LEN(str); + cstr = RSTRING_PTR(str); + + for (i = 0; i < len; ++i) { + char buf[1]; + const char c = cstr[i]; + int clen = 0; + if (c == '%') { + if (i + 3 > len) break; + if (!ISXDIGIT(cstr[i+1])) continue; + if (!ISXDIGIT(cstr[i+2])) continue; + buf[0] = ((char_to_number(cstr[i+1]) << 4) + | char_to_number(cstr[i+2])); + clen = 2; + } + else if (c == '+') { + buf[0] = ' '; + } + else { + continue; + } + + if (!dest) { + dest = rb_str_buf_new(len); + } + + rb_str_cat(dest, cstr + beg, i - beg); + i += clen; + beg = i + 1; + + rb_str_cat(dest, buf, 1); + } + + if (dest) { + rb_str_cat(dest, cstr + beg, len - beg); + preserve_original_state(str, dest); + cr = ENC_CODERANGE_UNKNOWN; + } + else { + dest = rb_str_dup(str); + cr = ENC_CODERANGE(str); + } + origenc = rb_enc_get_index(str); + if (origenc != encidx) { + rb_enc_associate_index(dest, encidx); + if (!ENC_CODERANGE_CLEAN_P(rb_enc_str_coderange(dest))) { + rb_enc_associate_index(dest, origenc); + if (cr != ENC_CODERANGE_UNKNOWN) + ENC_CODERANGE_SET(dest, cr); + } + } + return dest; +} + +/* + * call-seq: + * CGI.escapeHTML(string) -> string + * + * Returns HTML-escaped string. + * + */ +static VALUE +cgiesc_escape_html(VALUE self, VALUE str) +{ + StringValue(str); + + if (rb_enc_str_asciicompat_p(str)) { + return optimized_escape_html(str); + } + else { + return rb_call_super(1, &str); + } +} + +/* + * call-seq: + * CGI.unescapeHTML(string) -> string + * + * Returns HTML-unescaped string. + * + */ +static VALUE +cgiesc_unescape_html(VALUE self, VALUE str) +{ + StringValue(str); + + if (rb_enc_str_asciicompat_p(str)) { + return optimized_unescape_html(str); + } + else { + return rb_call_super(1, &str); + } +} + +/* + * call-seq: + * CGI.escape(string) -> string + * + * Returns URL-escaped string. + * + */ +static VALUE +cgiesc_escape(VALUE self, VALUE str) +{ + StringValue(str); + + if (rb_enc_str_asciicompat_p(str)) { + return optimized_escape(str); + } + else { + return rb_call_super(1, &str); + } +} + +static VALUE +accept_charset(int argc, VALUE *argv, VALUE self) +{ + if (argc > 0) + return argv[0]; + return rb_cvar_get(CLASS_OF(self), id_accept_charset); +} + +/* + * call-seq: + * CGI.unescape(string, encoding=@@accept_charset) -> string + * + * Returns URL-unescaped string. + * + */ +static VALUE +cgiesc_unescape(int argc, VALUE *argv, VALUE self) +{ + VALUE str = (rb_check_arity(argc, 1, 2), argv[0]); + + StringValue(str); + + if (rb_enc_str_asciicompat_p(str)) { + VALUE enc = accept_charset(argc-1, argv+1, self); + return optimized_unescape(str, enc); + } + else { + return rb_call_super(argc, argv); + } +} + +void +Init_escape(void) +{ + id_accept_charset = rb_intern_const("@@accept_charset"); + InitVM(escape); +} + +void +InitVM_escape(void) +{ + rb_cCGI = rb_define_class("CGI", rb_cObject); + rb_mEscape = rb_define_module_under(rb_cCGI, "Escape"); + rb_mUtil = rb_define_module_under(rb_cCGI, "Util"); + rb_define_method(rb_mEscape, "escapeHTML", cgiesc_escape_html, 1); + rb_define_method(rb_mEscape, "unescapeHTML", cgiesc_unescape_html, 1); + rb_define_method(rb_mEscape, "escape", cgiesc_escape, 1); + rb_define_method(rb_mEscape, "unescape", cgiesc_unescape, -1); + rb_prepend_module(rb_mUtil, rb_mEscape); + rb_extend_object(rb_cCGI, rb_mEscape); +} Property changes on: ruby_2_6/ext/cgi/escape/escape.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: ruby_2_6/ext/win32ole/win32ole_error.c =================================================================== --- ruby_2_6/ext/win32ole/win32ole_error.c (nonexistent) +++ ruby_2_6/ext/win32ole/win32ole_error.c (revision 66532) @@ -0,0 +1,84 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/ext/win32ole/win32ole_error.c#L1 +#include "win32ole.h" + +static VALUE ole_hresult2msg(HRESULT hr); + +static VALUE +ole_hresult2msg(HRESULT hr) +{ + VALUE msg = Qnil; + char *p_msg = NULL; + char *term = NULL; + DWORD dwCount; + + char strhr[100]; + sprintf(strhr, " HRESULT error code:0x%08x\n ", (unsigned)hr); + msg = rb_str_new2(strhr); + dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, hr, + MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), + (LPTSTR)&p_msg, 0, NULL); + if (dwCount == 0) { + dwCount = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, hr, cWIN32OLE_lcid, + (LPTSTR)&p_msg, 0, NULL); + } + if (dwCount > 0) { + term = p_msg + strlen(p_msg); + while (p_msg < term) { + term--; + if (*term == '\r' || *term == '\n') + *term = '\0'; + else break; + } + if (p_msg[0] != '\0') { + rb_str_cat2(msg, p_msg); + } + } + LocalFree(p_msg); + return msg; +} + +void +ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...) +{ + va_list args; + VALUE msg; + VALUE err_msg; + va_init_list(args, fmt); + msg = rb_vsprintf(fmt, args); + va_end(args); + + err_msg = ole_hresult2msg(hr); + if(err_msg != Qnil) { + rb_str_cat2(msg, "\n"); + rb_str_append(msg, err_msg); + } + rb_exc_raise(rb_exc_new_str(ecs, msg)); +} + +void +Init_win32ole_error(void) +{ + /* + * Document-class: WIN32OLERuntimeError + * + * Raised when OLE processing failed. + * + * EX: + * + * obj = WIN32OLE.new("NonExistProgID") + * + * raises the exception: + * + * WIN32OLERuntimeError: unknown OLE server: `NonExistProgID' + * HRESULT error code:0x800401f3 + * Invalid class string + * + */ + eWIN32OLERuntimeError = rb_define_class("WIN32OLERuntimeError", rb_eRuntimeError); + eWIN32OLEQueryInterfaceError = rb_define_class("WIN32OLEQueryInterfaceError", eWIN32OLERuntimeError); +} Property changes on: ruby_2_6/ext/win32ole/win32ole_error.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: ruby_2_6/ext/win32ole/win32ole_error.h =================================================================== --- ruby_2_6/ext/win32ole/win32ole_error.h (nonexistent) +++ ruby_2_6/ext/win32ole/win32ole_error.h (revision 66532) @@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/ext/win32ole/win32ole_error.h#L1 +#ifndef WIN32OLE_ERROR_H +#define WIN32OLE_ERROR_H 1 + +VALUE eWIN32OLERuntimeError; +VALUE eWIN32OLEQueryInterfaceError; +NORETURN(PRINTF_ARGS(void ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...), 3, 4)); +void Init_win32ole_error(void); + +#endif Property changes on: ruby_2_6/ext/win32ole/win32ole_error.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: ruby_2_6/ext/.document =================================================================== --- ruby_2_6/ext/.document (nonexistent) +++ ruby_2_6/ext/.document (revision 66532) @@ -0,0 +1,91 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/ext/.document#L1 +# Add files to this as they become documented + +bigdecimal/bigdecimal.c +bigdecimal/lib +continuation/continuation.c +coverage/coverage.c +date/date_core.c +dbm/dbm.c +digest/bubblebabble/bubblebabble.c +digest/digest.c +digest/lib +digest/md5/md5init.c +digest/rmd160/rmd160init.c +digest/sha1/sha1init.c +digest/sha2/sha2init.c +etc/etc.c +fcntl/fcntl.c +fiber/fiber.c +fiddle/closure.c +fiddle/conversions.c +fiddle/fiddle.c +fiddle/function.c +fiddle/pointer.c +fiddle/handle.c +fiddle/lib +gdbm/gdbm.c +io/console/console.c +io/nonblock/nonblock.c +io/wait/wait.c +json/generator/generator.c +json/lib +json/parser/parser.c +nkf/lib +nkf/nkf.c +objspace/objspace.c +objspace/objspace_dump.c +objspace/object_tracing.c +openssl/lib +openssl/ossl.c +openssl/ossl_asn1.c +openssl/ossl_bio.c +openssl/ossl_bn.c +openssl/ossl_cipher.c +openssl/ossl_config.c +openssl/ossl_digest.c +openssl/ossl_engine.c +openssl/ossl_hmac.c +openssl/ossl_kdf.c +openssl/ossl_ns_spki.c +openssl/ossl_ocsp.c +openssl/ossl_pkcs12.c +openssl/ossl_pkcs7.c +openssl/ossl_pkey.c +openssl/ossl_pkey_dh.c +openssl/ossl_pkey_dsa.c +openssl/ossl_pkey_ec.c +openssl/ossl_pkey_rsa.c +openssl/ossl_rand.c +openssl/ossl_ssl.c +openssl/ossl_ssl_session.c +openssl/ossl_x509.c +openssl/ossl_x509attr.c +openssl/ossl_x509cert.c +openssl/ossl_x509crl.c +openssl/ossl_x509ext.c +openssl/ossl_x509name.c +openssl/ossl_x509req.c +openssl/ossl_x509revoked.c +openssl/ossl_x509store.c +pathname/lib +pathname/pathname.c +psych/lib +psych/psych.c +psych/psych_emitter.c +psych/psych_parser.c +psych/psych_to_ruby.c +psych/psych_yaml_tree.c +pty/lib +pty/pty.c +racc/cparse/cparse.c +readline/readline.c +ripper/lib +sdbm/init.c +socket +stringio/stringio.c +strscan/strscan.c +syslog/syslog.c +syslog/lib +win32ole/lib +win32ole/*.c +zlib/zlib.c Property changes on: ruby_2_6/ext/.document ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: ruby_2_6/ext/zlib/extconf.rb =================================================================== --- ruby_2_6/ext/zlib/extconf.rb (nonexistent) +++ ruby_2_6/ext/zlib/extconf.rb (revision 66532) @@ -0,0 +1,132 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/ext/zlib/extconf.rb#L1 +# frozen_string_literal: true +# +# extconf.rb +# +# $Id$ +# + +require 'mkmf' +require 'rbconfig' + +dir_config 'zlib' + + +if %w'z libz zlib1 zlib zdll zlibwapi'.find {|z| have_library(z, 'deflateReset')} and + have_header('zlib.h') then + have_zlib = true +else + unless File.directory?(zsrc = "#{$srcdir}/zlib") + dirs = Dir.open($srcdir) {|z| z.grep(/\Azlib-\d+[.\d]*\z/) {|x|"#{$srcdir}/#{x}"}} + dirs.delete_if {|x| !File.directory?(x)} + zsrc = dirs.max_by {|x| x.scan(/\d+/).map(&:to_i)} + end + if zsrc + addconf = [ + "ZSRC = $(srcdir)/#{File.basename(zsrc)}\n", + "all:\n", + ] + $INCFLAGS << " -I$(ZSRC)" + if $mswin or $mingw + dll = "zlib1.dll" + $extso << dll + $cleanfiles << "$(topdir)/#{dll}" << "$(ZIMPLIB)" + zmk = "\t$(MAKE) -f $(ZMKFILE) TOP=$(ZSRC)" + if $nmake + zmkfile = "$(ZSRC)/win32/Makefile.msc" + m = "#{zsrc}/win32/Makefile.msc" + else + zmkfile = "$(ZSRC)/win32/Makefile.gcc" + m = "#{zsrc}/win32/Makefile.gcc" + zmk += " PREFIX=" + zmk << CONFIG['CC'][/(.*-)gcc([^\/]*)\z/, 1] + zmk << " CC=$(CC)" if $2 + end + m = File.read(m) + zimplib = m[/^IMPLIB[ \t]*=[ \t]*(\S+)/, 1] + $LOCAL_LIBS << " " << zimplib + unless $nmake or /^TOP[ \t]/ =~ m + m.gsub!(/win32\/zlib\.def/, '$(TOP)/\&') + m.gsub!(/^(\t.*[ \t])(\S+\.rc)/, '\1-I$(<D) $<') + m = "TOP = .\n""VPATH=$(TOP)\n" + m + zmkfile = File.basename(zmkfile) + File.rename(zmkfile, zmkfile+".orig") if File.exist?(zmkfile) + File.write(zmkfile, m) + end + addconf.push( + "ZMKFILE = #{zmkfile}\n", + "ZIMPLIB = #{zimplib}\n", + "$(TARGET_SO): $(ZIMPLIB)\n", + "$(ZIMPLIB):\n", + "#{zmk} $@\n", + "install-so: $(topdir)/#{dll}", + "$(topdir)/#{dll}: $(ZIMPLIB)\n", + "\t$(Q) $(COPY) #{dll} $(@D)\n", + "clean: clean-zsrc\n", + "clean-zsrc:\n", + "#{zmk} clean\n", + ) + end + Logging.message "using zlib in #{zsrc}\n" + $defs << "-DHAVE_ZLIB_H" + have_zlib = true + end +end + +if have_zlib + defines = [] + + Logging::message 'checking for kind of operating system... ' + os_code = with_config('os-code') || + case RUBY_PLATFORM.split('-',2)[1] + when 'amigaos' then + os_code = 'AMIGA' + when /mswin|mingw|bccwin/ then + # NOTE: cygwin should be regarded as Unix. + os_code = 'WIN32' + else + os_code = 'UNIX' + end + os_code = 'OS_' + os_code.upcase + + OS_NAMES = { + 'OS_MSDOS' => 'MS-DOS', + 'OS_AMIGA' => 'Amiga', + 'OS_VMS' => 'VMS', + 'OS_UNIX' => 'Unix', + 'OS_ATARI' => 'Atari', + 'OS_MACOS' => 'MacOS', + 'OS_TOPS20' => 'TOPS20', + 'OS_WIN32' => 'Win32', + 'OS_VMCMS' => 'VM/CMS', + 'OS_ZSYSTEM' => 'Z-System', + 'OS_CPM' => 'CP/M', + 'OS_QDOS' => 'QDOS', + 'OS_RISCOS' => 'RISCOS', + 'OS_UNKNOWN' => 'Unknown', + } + unless OS_NAMES.key? os_code then + raise "invalid OS_CODE `#{os_code}'" + end + Logging::message "#{OS_NAMES[os_code]}\n" + defines << "OS_CODE=#{os_code}" + + $defs.concat(defines.collect{|d|' -D'+d}) + + if zsrc + $defs << "-DHAVE_CRC32_COMBINE" + $defs << "-DHAVE_ADLER32_COMBINE" + $defs << "-DHAVE_TYPE_Z_CRC_T" + else + have_func('crc32_combine', 'zlib.h') + have_func('adler32_combine', 'zlib.h') + have_type('z_crc_t', 'zlib.h') + end + + create_makefile('zlib') {|conf| + if zsrc + conf.concat addconf if addconf + end + conf + } + +end Property changes on: ruby_2_6/ext/zlib/extconf.rb __ (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/