Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 13 additions & 31 deletions enumerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,11 @@ lazy_init_block_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, m))
#define LAZY_MEMO_SET_PACKED(memo) ((memo)->memo_flags |= LAZY_MEMO_PACKED)
#define LAZY_MEMO_RESET_PACKED(memo) ((memo)->memo_flags &= ~LAZY_MEMO_PACKED)

#define LAZY_NEED_BLOCK(func) \
if (!rb_block_given_p()) { \
rb_raise(rb_eArgError, "tried to call lazy " #func " without a block"); \
}

static VALUE lazy_yielder_result(struct MEMO *result, VALUE yielder, VALUE procs_array, VALUE memos, long i);

static VALUE
Expand Down Expand Up @@ -1805,9 +1810,7 @@ lazy_initialize(int argc, VALUE *argv, VALUE self)
VALUE generator;

rb_check_arity(argc, 1, 2);
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy new without a block");
}
LAZY_NEED_BLOCK(new);
obj = argv[0];
if (argc > 1) {
size = argv[1];
Expand Down Expand Up @@ -2065,10 +2068,7 @@ static const lazyenum_funcs lazy_map_funcs = {
static VALUE
lazy_map(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy map without a block");
}

LAZY_NEED_BLOCK(map);
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_map_funcs);
}

Expand Down Expand Up @@ -2150,10 +2150,7 @@ static const lazyenum_funcs lazy_flat_map_funcs = {
static VALUE
lazy_flat_map(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy flat_map without a block");
}

LAZY_NEED_BLOCK(flat_map);
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_flat_map_funcs);
}

Expand All @@ -2180,10 +2177,7 @@ static const lazyenum_funcs lazy_select_funcs = {
static VALUE
lazy_select(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy select without a block");
}

LAZY_NEED_BLOCK(select);
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_select_funcs);
}

Expand Down Expand Up @@ -2214,10 +2208,7 @@ static const lazyenum_funcs lazy_filter_map_funcs = {
static VALUE
lazy_filter_map(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy filter_map without a block");
}

LAZY_NEED_BLOCK(filter_map);
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_filter_map_funcs);
}

Expand All @@ -2243,10 +2234,7 @@ static const lazyenum_funcs lazy_reject_funcs = {
static VALUE
lazy_reject(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy reject without a block");
}

LAZY_NEED_BLOCK(reject);
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_reject_funcs);
}

Expand Down Expand Up @@ -2529,10 +2517,7 @@ static const lazyenum_funcs lazy_take_while_funcs = {
static VALUE
lazy_take_while(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy take_while without a block");
}

LAZY_NEED_BLOCK(take_while);
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_take_while_funcs);
}

Expand Down Expand Up @@ -2627,10 +2612,7 @@ static const lazyenum_funcs lazy_drop_while_funcs = {
static VALUE
lazy_drop_while(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy drop_while without a block");
}

LAZY_NEED_BLOCK(drop_while);
return lazy_add_method(obj, 0, 0, Qfalse, Qnil, &lazy_drop_while_funcs);
}

Expand Down
56 changes: 28 additions & 28 deletions symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ sym_set_create(VALUE sym, void *data)
RB_OBJ_WRITE((VALUE)obj, &obj->fstr, str);

int id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
if (id < 0) id = ID_JUNK;
if (id < 0) id = ID_INTERNAL;
obj->id = id;

obj->hashval = rb_str_hash(str);
Expand All @@ -291,7 +291,7 @@ sym_set_create(VALUE sym, void *data)
VALUE static_sym = static_sym_entry->sym;
if (static_sym == 0) {
ID id = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
if (id == (ID)-1) id = ID_JUNK;
if (id == (ID)-1) id = ID_INTERNAL;

ID nid = next_id_base();
if (nid == (ID)-1) {
Expand Down Expand Up @@ -431,7 +431,7 @@ rb_id_attrset(ID id)
scope = id_type(id);
switch (scope) {
case ID_LOCAL: case ID_INSTANCE: case ID_GLOBAL:
case ID_CONST: case ID_CLASS: case ID_JUNK:
case ID_CONST: case ID_CLASS: case ID_INTERNAL:
break;
case ID_ATTRSET:
return id;
Expand Down Expand Up @@ -476,7 +476,7 @@ rb_id_attrset(ID id)
"attrset",
"const",
"class",
"junk",
"internal",
};
rb_name_error(id, "cannot make anonymous %.*s ID %"PRIxVALUE" attrset",
(int)sizeof(id_types[0]), id_types[scope], (VALUE)id);
Expand Down Expand Up @@ -602,66 +602,66 @@ enc_synmane_type_leading_chars(const char *name, long len, rb_encoding *enc, int

case '<':
switch (*++m) {
default: return (t) { stophere, ID_JUNK, 1, };
case '<': return (t) { stophere, ID_JUNK, 2, };
default: return (t) { stophere, ID_INTERNAL, 1, };
case '<': return (t) { stophere, ID_INTERNAL, 2, };
case '=':
switch (*++m) {
default: return (t) { stophere, ID_JUNK, 2, };
case '>': return (t) { stophere, ID_JUNK, 3, };
default: return (t) { stophere, ID_INTERNAL, 2, };
case '>': return (t) { stophere, ID_INTERNAL, 3, };
}
}

case '>':
switch (*++m) {
default: return (t) { stophere, ID_JUNK, 1, };
case '>': case '=': return (t) { stophere, ID_JUNK, 2, };
default: return (t) { stophere, ID_INTERNAL, 1, };
case '>': case '=': return (t) { stophere, ID_INTERNAL, 2, };
}

case '=':
switch (*++m) {
default: return (t) { invalid, 0, 1, };
case '~': return (t) { stophere, ID_JUNK, 2, };
default: return (t) { invalid, 0, 1, };
case '~': return (t) { stophere, ID_INTERNAL, 2, };
case '=':
switch (*++m) {
default: return (t) { stophere, ID_JUNK, 2, };
case '=': return (t) { stophere, ID_JUNK, 3, };
default: return (t) { stophere, ID_INTERNAL, 2, };
case '=': return (t) { stophere, ID_INTERNAL, 3, };
}
}

case '*':
switch (*++m) {
default: return (t) { stophere, ID_JUNK, 1, };
case '*': return (t) { stophere, ID_JUNK, 2, };
default: return (t) { stophere, ID_INTERNAL, 1, };
case '*': return (t) { stophere, ID_INTERNAL, 2, };
}

case '+': case '-':
switch (*++m) {
default: return (t) { stophere, ID_JUNK, 1, };
case '@': return (t) { stophere, ID_JUNK, 2, };
default: return (t) { stophere, ID_INTERNAL, 1, };
case '@': return (t) { stophere, ID_INTERNAL, 2, };
}

case '|': case '^': case '&': case '/': case '%': case '~': case '`':
return (t) { stophere, ID_JUNK, 1, };
return (t) { stophere, ID_INTERNAL, 1, };

case '[':
switch (*++m) {
default: return (t) { needmore, ID_JUNK, 0, };
default: return (t) { needmore, ID_INTERNAL, 0, };
case ']':
switch (*++m) {
default: return (t) { stophere, ID_JUNK, 2, };
case '=': return (t) { stophere, ID_JUNK, 3, };
default: return (t) { stophere, ID_INTERNAL, 2, };
case '=': return (t) { stophere, ID_INTERNAL, 3, };
}
}

case '!':
switch (*++m) {
case '=': case '~': return (t) { stophere, ID_JUNK, 2, };
case '=': case '~': return (t) { stophere, ID_INTERNAL, 2, };
default:
if (allowed_attrset & (1U << ID_JUNK)) {
return (t) { needmore, ID_JUNK, 1, };
if (allowed_attrset & (1U << ID_INTERNAL)) {
return (t) { needmore, ID_INTERNAL, 1, };
}
else {
return (t) { stophere, ID_JUNK, 1, };
return (t) { stophere, ID_INTERNAL, 1, };
}
}

Expand Down Expand Up @@ -702,7 +702,7 @@ rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int a
switch (*m) {
case '!': case '?':
if (type == ID_GLOBAL || type == ID_CLASS || type == ID_INSTANCE) return -1;
type = ID_JUNK;
type = ID_INTERNAL;
++m;
if (m + 1 < e || *m != '=') break;
/* fall through */
Expand Down Expand Up @@ -1144,7 +1144,7 @@ rb_is_local_id(ID id)
int
rb_is_junk_id(ID id)
{
return is_junk_id(id);
return is_internal_id(id);
}

int
Expand Down
4 changes: 2 additions & 2 deletions symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct RSymbol {
#define is_attrset_id(id) ((id)==idASET||id_type(id)==ID_ATTRSET)
#define is_const_id(id) (id_type(id)==ID_CONST)
#define is_class_id(id) (id_type(id)==ID_CLASS)
#define is_junk_id(id) (id_type(id)==ID_JUNK)
#define is_internal_id(id) (id_type(id)==ID_INTERNAL)

static inline int
id_type(ID id)
Expand Down Expand Up @@ -91,7 +91,7 @@ sym_type(VALUE sym)
#define is_attrset_sym(sym) (sym_type(sym)==ID_ATTRSET)
#define is_const_sym(sym) (sym_type(sym)==ID_CONST)
#define is_class_sym(sym) (sym_type(sym)==ID_CLASS)
#define is_junk_sym(sym) (sym_type(sym)==ID_JUNK)
#define is_internal_sym(sym) (sym_type(sym)==ID_INTERNAL)

#ifndef RIPPER
RUBY_FUNC_EXPORTED
Expand Down
8 changes: 3 additions & 5 deletions template/id.h.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%# -*- c -*-
/* DO NOT EDIT THIS FILE DIRECTLY */
/* DO NOT EDIT THIS FILE DIRECTLY: source is at template/id.h.tmpl */
/**********************************************************************

id.h -
Expand All @@ -19,15 +19,14 @@ types = ids.keys.grep(/^[A-Z]/)
#define RUBY_ID_H

enum ruby_id_types {
RUBY_ID_STATIC_SYM = 0x01,
RUBY_ID_LOCAL = 0x00,
RUBY_ID_STATIC_SYM = 0x01,
RUBY_ID_INSTANCE = (0x01<<1),
RUBY_ID_GLOBAL = (0x03<<1),
RUBY_ID_ATTRSET = (0x04<<1),
RUBY_ID_CONST = (0x05<<1),
RUBY_ID_CLASS = (0x06<<1),
RUBY_ID_JUNK = (0x07<<1),
RUBY_ID_INTERNAL = RUBY_ID_JUNK,
RUBY_ID_INTERNAL = (0x07<<1),
RUBY_ID_SCOPE_SHIFT = 4,
RUBY_ID_SCOPE_MASK = (~(~0U<<(RUBY_ID_SCOPE_SHIFT-1))<<1)
};
Expand All @@ -41,7 +40,6 @@ enum ruby_id_types {
#define ID_ATTRSET RUBY_ID_ATTRSET
#define ID_CONST RUBY_ID_CONST
#define ID_CLASS RUBY_ID_CLASS
#define ID_JUNK RUBY_ID_JUNK
#define ID_INTERNAL RUBY_ID_INTERNAL

#define symIFUNC ID2SYM(idIFUNC)
Expand Down
10 changes: 5 additions & 5 deletions test/rubygems/test_gem_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,19 @@ def test_verify_certificate
def test_verify_certificate_extra_message
pend if Gem.java_platform?

error_number = OpenSSL::X509::V_ERR_INVALID_CA
error_number = OpenSSL::X509::V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY

store = OpenSSL::X509::Store.new
context = OpenSSL::X509::StoreContext.new store
context.error = error_number
context = OpenSSL::X509::StoreContext.new store, CHILD_CERT
context.verify

use_ui @ui do
Gem::Request.verify_certificate context
end

expected = <<-ERROR
ERROR: SSL verification error at depth 0: invalid CA certificate (#{error_number})
ERROR: Certificate is an invalid CA certificate
ERROR: SSL verification error at depth 0: unable to get local issuer certificate (#{error_number})
ERROR: You must add #{CHILD_CERT.issuer} to your local trusted store
ERROR

assert_equal expected, @ui.error
Expand Down