Skip to content

Commit

Permalink
Merge pull request #26 from github/dbussink/ruby-2-1-6
Browse files Browse the repository at this point in the history
Update to Ruby 2.1.6
  • Loading branch information
dbussink committed Apr 15, 2015
2 parents 71c83aa + b432a4f commit 220f6fe
Show file tree
Hide file tree
Showing 77 changed files with 4,879 additions and 251 deletions.
396 changes: 395 additions & 1 deletion ChangeLog

Large diffs are not rendered by default.

61 changes: 26 additions & 35 deletions class.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,6 @@ rb_class_new(VALUE super)
return rb_class_boot(super);
}

static void
rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr)
{
NODE *new_node;
while (node) {
if (node->nd_clss == old_klass) {
new_node = NEW_CREF(new_klass);
RB_OBJ_WRITE(new_node, &new_node->nd_next, node->nd_next);
*new_cref_ptr = new_node;
return;
}
new_node = NEW_CREF(node->nd_clss);
node = node->nd_next;
*new_cref_ptr = new_node;
new_cref_ptr = &new_node->nd_next;
}
*new_cref_ptr = NULL;
}

static void
clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
{
Expand All @@ -261,7 +242,7 @@ clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
NODE *new_cref;
newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
GetISeqPtr(newiseqval, iseq);
rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass, &new_cref);
rb_vm_rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass, &new_cref);
RB_OBJ_WRITE(iseq->self, &iseq->cref_stack, new_cref);
rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
RB_GC_GUARD(newiseqval);
Expand Down Expand Up @@ -957,7 +938,7 @@ rb_prepend_module(VALUE klass, VALUE module)
OBJ_WB_UNPROTECT(origin); /* TODO: conservertive shading. Need more survery. */
RCLASS_SET_SUPER(origin, RCLASS_SUPER(klass));
RCLASS_SET_SUPER(klass, origin);
RCLASS_ORIGIN(klass) = origin;
RB_OBJ_WRITE(klass, &RCLASS_ORIGIN(klass), origin);
RCLASS_M_TBL_WRAPPER(origin) = RCLASS_M_TBL_WRAPPER(klass);
RCLASS_M_TBL_INIT(klass);
st_foreach(RCLASS_M_TBL(origin), move_refined_method,
Expand Down Expand Up @@ -1118,25 +1099,32 @@ ins_methods_pub_i(st_data_t name, st_data_t type, st_data_t ary)
return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PUBLIC);
}

struct method_entry_arg {
st_table *list;
int recur;
};

static int
method_entry_i(st_data_t key, st_data_t value, st_data_t data)
{
const rb_method_entry_t *me = (const rb_method_entry_t *)value;
st_table *list = (st_table *)data;
struct method_entry_arg *arg = (struct method_entry_arg *)data;
long type;

if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
VALUE klass = me->klass;
me = rb_resolve_refined_method(Qnil, me, NULL);
if (!me) return ST_CONTINUE;
if (!arg->recur && me->klass != klass) return ST_CONTINUE;
}
if (!st_lookup(list, key, 0)) {
if (!st_lookup(arg->list, key, 0)) {
if (UNDEFINED_METHOD_ENTRY_P(me)) {
type = -1; /* none */
}
else {
type = VISI(me->flag);
}
st_add_direct(list, key, type);
st_add_direct(arg->list, key, type);
}
return ST_CONTINUE;
}
Expand All @@ -1146,7 +1134,7 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func
{
VALUE ary;
int recur, prepended = 0;
st_table *list;
struct method_entry_arg me_arg;

if (argc == 0) {
recur = TRUE;
Expand All @@ -1162,16 +1150,17 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func
prepended = 1;
}

list = st_init_numtable();
me_arg.list = st_init_numtable();
me_arg.recur = recur;
for (; mod; mod = RCLASS_SUPER(mod)) {
if (RCLASS_M_TBL(mod)) st_foreach(RCLASS_M_TBL(mod), method_entry_i, (st_data_t)list);
if (RCLASS_M_TBL(mod)) st_foreach(RCLASS_M_TBL(mod), method_entry_i, (st_data_t)&me_arg);
if (BUILTIN_TYPE(mod) == T_ICLASS && !prepended) continue;
if (obj && FL_TEST(mod, FL_SINGLETON)) continue;
if (!recur) break;
}
ary = rb_ary_new();
st_foreach(list, func, ary);
st_free_table(list);
st_foreach(me_arg.list, func, ary);
st_free_table(me_arg.list);

return ary;
}
Expand Down Expand Up @@ -1393,7 +1382,8 @@ VALUE
rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
{
VALUE recur, ary, klass, origin;
st_table *list, *mtbl;
struct method_entry_arg me_arg;
st_table *mtbl;

if (argc == 0) {
recur = Qtrue;
Expand All @@ -1403,22 +1393,23 @@ rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
}
klass = CLASS_OF(obj);
origin = RCLASS_ORIGIN(klass);
list = st_init_numtable();
me_arg.list = st_init_numtable();
me_arg.recur = recur;
if (klass && FL_TEST(klass, FL_SINGLETON)) {
if ((mtbl = RCLASS_M_TBL(origin)) != 0)
st_foreach(mtbl, method_entry_i, (st_data_t)list);
st_foreach(mtbl, method_entry_i, (st_data_t)&me_arg);
klass = RCLASS_SUPER(klass);
}
if (RTEST(recur)) {
while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
if (klass != origin && (mtbl = RCLASS_M_TBL(klass)) != 0)
st_foreach(mtbl, method_entry_i, (st_data_t)list);
st_foreach(mtbl, method_entry_i, (st_data_t)&me_arg);
klass = RCLASS_SUPER(klass);
}
}
ary = rb_ary_new();
st_foreach(list, ins_methods_i, ary);
st_free_table(list);
st_foreach(me_arg.list, ins_methods_i, ary);
st_free_table(me_arg.list);

return ary;
}
Expand Down
2 changes: 1 addition & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUBYLIB = $(PATH_SEPARATOR)
RUBYOPT = -
RUN_OPTS = --disable-gems

SPEC_GIT_BASE = git://github.com/nurse
SPEC_GIT_BASE = git://github.com/ruby
MSPEC_GIT_URL = $(SPEC_GIT_BASE)/mspec.git
RUBYSPEC_GIT_URL = $(SPEC_GIT_BASE)/rubyspec.git

Expand Down
2 changes: 2 additions & 0 deletions complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ f_complex_new2(VALUE klass, VALUE x, VALUE y)
*
* Complex(1, 2) #=> (1+2i)
* Complex('1+2i') #=> (1+2i)
* Complex(nil) #=> TypeError
* Complex(1, nil) #=> TypeError
*
* Syntax of string form:
*
Expand Down
25 changes: 14 additions & 11 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,13 @@ if test "$GCC" = yes; then
],
[
# ANSI (no XCFLAGS because this is C only)
RUBY_TRY_CFLAGS(-ansi -std=iso9899:199409, [
RUBY_APPEND_OPTION(warnflags, -ansi -std=iso9899:199409)
RUBY_APPEND_OPTION(strict_warnflags, -ansi -std=iso9899:199409)
])
for ansi_options in -std=iso9899:1999 "-ansi -std=iso9899:199409"; do
RUBY_TRY_CFLAGS(${ansi_options}, [
RUBY_APPEND_OPTIONS(warnflags, ${ansi_options})
RUBY_APPEND_OPTIONS(strict_warnflags, ${ansi_options})
], [ansi_options=])
test "x${ansi_options}" = x || break
done
])

# suppress annoying -Wstrict-overflow warnings
Expand Down Expand Up @@ -1054,8 +1057,8 @@ main()
ac_cv_func_malloc_usable_size=no
{ test "$target_cpu" = x64 && ac_cv_func___builtin_setjmp=no; }
AC_CHECK_TYPE([NET_LUID], [], [],
[@%:@include <windows.h>
@%:@include <iphlpapi.h>])
[@%:@include <winsock2.h>
@%:@include <iphlpapi.h>])
if test x"$ac_cv_type_NET_LUID" = xyes; then
AC_DEFINE(HAVE_TYPE_NET_LUID, 1)
fi
Expand Down Expand Up @@ -2075,7 +2078,7 @@ if test ${setjmp_prefix+set}; then
if test "${setjmp_prefix}" && eval test '$ac_cv_func_'${setjmp_prefix}setjmp${setjmp_suffix} = no; then
AC_MSG_ERROR(${setjmp_prefix}setjmp${setjmp_suffix} is not available)
fi
elif { AS_CASE("$ac_cv_func___builtin_setjmp", [yes*], [true], [false]); }; then
elif { AS_CASE("$ac_cv_func___builtin_setjmp", [yes*], [true], [false]) }; then
setjmp_cast=`expr "$ac_cv_func___builtin_setjmp" : "yes with cast (\(.*\))"`
setjmp_prefix=__builtin_
setjmp_suffix=
Expand Down Expand Up @@ -2617,8 +2620,8 @@ AC_ARG_WITH(dln-a-out,

AC_CACHE_CHECK(whether ELF binaries are produced, rb_cv_binary_elf,
[AC_TRY_LINK([],[], [
AS_CASE(["`head -1 conftest$EXEEXT | cat -e`"],
['^?ELF'*], [rb_cv_binary_elf=yes], [rb_cv_binary_elf=no])],
AS_CASE(["`head -1 conftest$EXEEXT | tr -dc '\177ELF' | tr '\177' .`"],
[.ELF*], [rb_cv_binary_elf=yes], [rb_cv_binary_elf=no])],
rb_cv_binary_elf=no)])

if test "$rb_cv_binary_elf" = yes; then
Expand Down Expand Up @@ -2699,7 +2702,7 @@ if test "$with_dln_a_out" != yes; then
RPATHFLAG=' +b %1$-s'
fi
rb_cv_dlopen=yes],
[solaris*], [ if test "$GCC" = yes; then
[solaris*], [ if test "$GCC" = yes; then
: ${LDSHARED='$(CC) -shared'}
if test "$rb_cv_prog_gnu_ld" = yes; then
LDFLAGS="$LDFLAGS -Wl,-E"
Expand Down Expand Up @@ -2818,7 +2821,7 @@ if test "$with_dln_a_out" != yes; then
[os2-emx*], [ LDFLAGS="$LDFLAGS -Zomf"
],
[nacl], [ LDSHARED='$(CC) -shared' ],
[ : ${LDSHARED='$(LD)'}])
[ : ${LDSHARED='$(LD)'}])
AC_MSG_RESULT($rb_cv_dlopen)
fi
if test "${LDSHAREDXX}" = ""; then
Expand Down
13 changes: 13 additions & 0 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,19 @@ prev_frame_func(void)
return frame_func_id(prev_cfp);
}

ID
rb_frame_last_func(void)
{
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = th->cfp;
ID mid;

while (!(mid = frame_func_id(cfp)) &&
(cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp),
!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)));
return mid;
}

/*
* call-seq:
* append_features(mod) -> mod
Expand Down
11 changes: 9 additions & 2 deletions ext/etc/etc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ etc_getlogin(VALUE obj)
login = getenv("USER");
#endif

if (login)
return rb_tainted_str_new2(login);
if (login) {
#ifdef _WIN32
rb_encoding *extenc = rb_utf8_encoding();
#else
rb_encoding *extenc = rb_locale_encoding();
#endif
return rb_external_str_new_with_enc(login, strlen(login), extenc);
}

return Qnil;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/io/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ console_dev(VALUE klass)
if ((fptr = RFILE(con)->fptr) && GetReadFD(fptr) != -1)
return con;
}
rb_mod_remove_const(klass, ID2SYM(id_console));
rb_const_remove(klass, id_console);
}
{
VALUE args[2];
Expand Down
2 changes: 1 addition & 1 deletion ext/io/console/io-console.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- ruby -*-
_VERSION = "0.4.2"
_VERSION = "0.4.3"
date = %w$Date:: $[1]

Gem::Specification.new do |s|
Expand Down
2 changes: 1 addition & 1 deletion ext/io/wait/wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ io_nread(VALUE io)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
len = rb_io_read_pending(fptr);
if (len > 0) return len;
if (len > 0) return INT2FIX(len);
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0);
if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0);
if (n > 0) return ioctl_arg2num(n);
Expand Down
62 changes: 58 additions & 4 deletions ext/openssl/lib/openssl/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ def verify_certificate_identity(cert, hostname)
case san.tag
when 2 # dNSName in GeneralName (RFC5280)
should_verify_common_name = false
reg = Regexp.escape(san.value).gsub(/\\\*/, "[^.]+")
return true if /\A#{reg}\z/i =~ hostname
return true if verify_hostname(hostname, san.value)
when 7 # iPAddress in GeneralName (RFC5280)
should_verify_common_name = false
# follows GENERAL_NAME_print() in x509v3/v3_alt.c
Expand All @@ -159,20 +158,75 @@ def verify_certificate_identity(cert, hostname)
if should_verify_common_name
cert.subject.to_a.each{|oid, value|
if oid == "CN"
reg = Regexp.escape(value).gsub(/\\\*/, "[^.]+")
return true if /\A#{reg}\z/i =~ hostname
return true if verify_hostname(hostname, value)
end
}
end
return false
end
module_function :verify_certificate_identity

def verify_hostname(hostname, san) # :nodoc:
# RFC 5280, IA5String is limited to the set of ASCII characters
return false unless san.ascii_only?
return false unless hostname.ascii_only?

# See RFC 6125, section 6.4.1
# Matching is case-insensitive.
san_parts = san.downcase.split(".")

# TODO: this behavior should probably be more strict
return san == hostname if san_parts.size < 2

# Matching is case-insensitive.
host_parts = hostname.downcase.split(".")

# RFC 6125, section 6.4.3, subitem 2.
# If the wildcard character is the only character of the left-most
# label in the presented identifier, the client SHOULD NOT compare
# against anything but the left-most label of the reference
# identifier (e.g., *.example.com would match foo.example.com but
# not bar.foo.example.com or example.com).
return false unless san_parts.size == host_parts.size

# RFC 6125, section 6.4.3, subitem 1.
# The client SHOULD NOT attempt to match a presented identifier in
# which the wildcard character comprises a label other than the
# left-most label (e.g., do not match bar.*.example.net).
return false unless verify_wildcard(host_parts.shift, san_parts.shift)

san_parts.join(".") == host_parts.join(".")
end
module_function :verify_hostname

def verify_wildcard(domain_component, san_component) # :nodoc:
parts = san_component.split("*", -1)

return false if parts.size > 2
return san_component == domain_component if parts.size == 1

# RFC 6125, section 6.4.3, subitem 3.
# The client SHOULD NOT attempt to match a presented identifier
# where the wildcard character is embedded within an A-label or
# U-label of an internationalized domain name.
return false if domain_component.start_with?("xn--") && san_component != "*"

parts[0].length + parts[1].length < domain_component.length &&
domain_component.start_with?(parts[0]) &&
domain_component.end_with?(parts[1])
end
module_function :verify_wildcard

class SSLSocket
include Buffering
include SocketForwarder
include Nonblock

##
# Perform hostname verification after an SSL connection is established
#
# This method MUST be called after calling #connect to ensure that the
# hostname of a remote peer has been verified.
def post_connection_check(hostname)
unless OpenSSL::SSL.verify_certificate_identity(peer_cert, hostname)
raise SSLError, "hostname \"#{hostname}\" does not match the server certificate"
Expand Down
Loading

0 comments on commit 220f6fe

Please sign in to comment.