diff options
Diffstat (limited to 'object.c')
| -rw-r--r-- | object.c | 1296 |
1 files changed, 752 insertions, 544 deletions
@@ -31,6 +31,7 @@ #include "internal/object.h" #include "internal/struct.h" #include "internal/string.h" +#include "internal/st.h" #include "internal/symbol.h" #include "internal/variable.h" #include "variable.h" @@ -41,6 +42,14 @@ #include "ruby/assert.h" #include "builtin.h" #include "shape.h" +#include "yjit.h" + +/* Flags of RObject + * + * 4: ROBJECT_HEAP + * The object has its instance variables in a separately allocated buffer. + * This can be either a flat buffer of reference, or an st_table for complex objects. + */ /*! * \addtogroup object @@ -73,6 +82,7 @@ static VALUE rb_cFalseClass_to_s; #define id_init_dup idInitialize_dup #define id_const_missing idConst_missing #define id_to_f idTo_f +static ID id_instance_variables_to_inspect; #define CLASS_OR_MODULE_P(obj) \ (!SPECIAL_CONST_P(obj) && \ @@ -80,6 +90,7 @@ static VALUE rb_cFalseClass_to_s; /*! \endcond */ + VALUE rb_obj_hide(VALUE obj) { @@ -98,21 +109,29 @@ rb_obj_reveal(VALUE obj, VALUE klass) return obj; } + VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type) { - RBASIC(obj)->flags = type; + VALUE ignored_flags = RUBY_FL_PROMOTED; + RBASIC(obj)->flags = (type & ~ignored_flags) | (RBASIC(obj)->flags & ignored_flags); RBASIC_SET_CLASS(obj, klass); return obj; } -/** - * call-seq: - * obj === other -> true or false +/* + * call-seq: + * true === other -> true or false + * false === other -> true or false + * nil === other -> true or false * - * Case Equality -- For class Object, effectively the same as calling - * <code>#==</code>, but typically overridden by descendants to provide - * meaningful semantics in +case+ statements. + * Returns +true+ or +false+. + * + * Like Object#==, if +other+ is an instance of \Object + * (and not an instance of one of its many subclasses). + * + * This method is commonly overridden by those subclasses, + * to provide meaningful semantics in +case+ statements. */ #define case_equal rb_equal /* The default implementation of #=== is @@ -146,14 +165,18 @@ rb_eql(VALUE obj1, VALUE obj2) /** * call-seq: - * obj == other -> true or false - * obj.equal?(other) -> true or false - * obj.eql?(other) -> true or false + * self == other -> true or false + * equal?(other) -> true or false + * eql?(other) -> true or false + * + * Returns whether +self+ and +other+ are the same object: * - * Equality --- At the Object level, #== returns <code>true</code> - * only if +obj+ and +other+ are the same object. Typically, this - * method is overridden in descendant classes to provide - * class-specific meaning. + * object = Object.new + * object == object # => true + * object == Object.new # => false + * + * Here in class \Object, #==, #equal?, and #eql? are the same method. + * A subclass may override #== to provide class-specific meaning. * * Unlike #==, the #equal? method should never be overridden by * subclasses as it is used to determine object identity (that is, @@ -185,7 +208,7 @@ rb_eql(VALUE obj1, VALUE obj2) * \private *++ */ -MJIT_FUNC_EXPORTED VALUE +VALUE rb_obj_equal(VALUE obj1, VALUE obj2) { return RBOOL(obj1 == obj2); @@ -203,7 +226,7 @@ VALUE rb_obj_hash(VALUE obj); *++ */ -MJIT_FUNC_EXPORTED VALUE +VALUE rb_obj_not(VALUE obj) { return RBOOL(!RTEST(obj)); @@ -219,19 +242,45 @@ rb_obj_not(VALUE obj) *++ */ -MJIT_FUNC_EXPORTED VALUE +VALUE rb_obj_not_equal(VALUE obj1, VALUE obj2) { VALUE result = rb_funcall(obj1, id_eq, 1, obj2); return rb_obj_not(result); } +static inline VALUE +fake_class_p(VALUE klass) +{ + RUBY_ASSERT(klass); + RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE) || RB_TYPE_P(klass, T_ICLASS)); + STATIC_ASSERT(t_iclass_overlap_t_class, !(T_CLASS & T_ICLASS)); + STATIC_ASSERT(t_iclass_overlap_t_module, !(T_MODULE & T_ICLASS)); + + return FL_TEST_RAW(klass, T_ICLASS | FL_SINGLETON); +} + +static inline VALUE +class_real(VALUE cl) +{ + RUBY_ASSERT(cl); + + // TODO: In the future we should only call this with T_CLASS + RUBY_ASSERT(RB_TYPE_P(cl, T_CLASS) || RB_TYPE_P(cl, T_ICLASS) || RB_TYPE_P(cl, T_MODULE)); + + while (RB_UNLIKELY(fake_class_p(cl))) { + // All paths through super in any box will eventually result in the + // same class. + cl = RCLASSEXT_SUPER(RCLASS_EXT_PRIME(cl)); + } + return cl; +} + VALUE rb_class_real(VALUE cl) { - while (cl && - ((RBASIC(cl)->flags & FL_SINGLETON) || BUILTIN_TYPE(cl) == T_ICLASS)) { - cl = RCLASS_SUPER(cl); + if (cl) { + cl = class_real(cl); } return cl; } @@ -239,7 +288,17 @@ rb_class_real(VALUE cl) VALUE rb_obj_class(VALUE obj) { - return rb_class_real(CLASS_OF(obj)); + VALUE cl = CLASS_OF(obj); + if (cl) { + cl = class_real(cl); + } + return cl; +} + +static inline VALUE +rb_obj_class_must(VALUE obj) +{ + return class_real(CLASS_OF(obj)); } /* @@ -266,64 +325,50 @@ rb_obj_singleton_class(VALUE obj) } /*! \private */ -MJIT_FUNC_EXPORTED void +void rb_obj_copy_ivar(VALUE dest, VALUE obj) { - RUBY_ASSERT(!RB_TYPE_P(obj, T_CLASS) && !RB_TYPE_P(obj, T_MODULE)); - - RUBY_ASSERT(BUILTIN_TYPE(dest) == BUILTIN_TYPE(obj)); - rb_shape_t * src_shape = rb_shape_get_shape(obj); - - if (rb_shape_id(src_shape) == OBJ_TOO_COMPLEX_SHAPE_ID) { - struct rb_id_table * table = rb_id_table_create(rb_id_table_size(ROBJECT_IV_HASH(obj))); - - rb_ivar_foreach(obj, rb_obj_evacuate_ivs_to_hash_table, (st_data_t)table); - rb_shape_set_too_complex(dest); - - ROBJECT(dest)->as.heap.ivptr = (VALUE *)table; + RUBY_ASSERT(RB_TYPE_P(obj, T_OBJECT)); + RUBY_ASSERT(RB_TYPE_P(dest, T_OBJECT)); + unsigned long src_num_ivs = rb_ivar_count(obj); + if (!src_num_ivs) { return; } - uint32_t src_num_ivs = RBASIC_IV_COUNT(obj); - rb_shape_t * shape_to_set_on_dest = src_shape; - VALUE * src_buf; - VALUE * dest_buf; + shape_id_t src_shape_id = RBASIC_SHAPE_ID(obj); - if (!src_num_ivs) { + if (rb_shape_complex_p(src_shape_id)) { + rb_shape_copy_complex_ivars(dest, obj, src_shape_id, ROBJECT_FIELDS_HASH(obj)); return; } - // The copy should be mutable, so we don't want the frozen shape - if (rb_shape_frozen_shape_p(src_shape)) { - shape_to_set_on_dest = rb_shape_get_parent(src_shape); - } - - src_buf = ROBJECT_IVPTR(obj); - dest_buf = ROBJECT_IVPTR(dest); - - rb_shape_t * initial_shape = rb_shape_get_shape(dest); + shape_id_t initial_shape_id = RBASIC_SHAPE_ID(dest); + RUBY_ASSERT(RSHAPE_TYPE_P(initial_shape_id, SHAPE_ROOT)); - if (initial_shape->size_pool_index != src_shape->size_pool_index) { - RUBY_ASSERT(initial_shape->type == SHAPE_T_OBJECT); + shape_id_t dest_shape_id = rb_shape_rebuild(initial_shape_id, src_shape_id); + if (UNLIKELY(rb_shape_complex_p(dest_shape_id))) { + st_table *table = rb_st_init_numtable_with_size(src_num_ivs); + rb_obj_copy_ivs_to_hash_table(obj, table); + rb_obj_init_complex(dest, table); - shape_to_set_on_dest = rb_shape_rebuild_shape(initial_shape, src_shape); + return; } - RUBY_ASSERT(src_num_ivs <= shape_to_set_on_dest->capacity); - if (initial_shape->capacity < shape_to_set_on_dest->capacity) { - rb_ensure_iv_list_size(dest, initial_shape->capacity, shape_to_set_on_dest->capacity); - dest_buf = ROBJECT_IVPTR(dest); - } + VALUE *src_buf = ROBJECT_FIELDS(obj); + VALUE *dest_buf = ROBJECT_FIELDS(dest); - MEMCPY(dest_buf, src_buf, VALUE, src_num_ivs); + attr_index_t initial_capa = RSHAPE_CAPACITY(initial_shape_id); + attr_index_t dest_capa = RSHAPE_CAPACITY(dest_shape_id); - // Fire write barriers - for (uint32_t i = 0; i < src_num_ivs; i++) { - RB_OBJ_WRITTEN(dest, Qundef, dest_buf[i]); + RUBY_ASSERT(src_num_ivs <= dest_capa); + if (initial_capa < dest_capa) { + rb_ensure_iv_list_size(dest, 0, dest_capa); + dest_buf = ROBJECT_FIELDS(dest); } - rb_shape_set_shape(dest, shape_to_set_on_dest); + rb_shape_copy_fields(dest, dest_buf, dest_shape_id, src_buf, src_shape_id); + RBASIC_SET_SHAPE_ID(dest, dest_shape_id); } static void @@ -332,16 +377,25 @@ init_copy(VALUE dest, VALUE 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 &= ~T_MASK; // Copies the shape id from obj to dest - RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR); - rb_copy_wb_protected_attribute(dest, obj); - rb_copy_generic_ivar(dest, obj); - rb_gc_copy_finalizer(dest, obj); - - if (RB_TYPE_P(obj, T_OBJECT)) { + RBASIC(dest)->flags |= RBASIC(obj)->flags & T_MASK; + switch (BUILTIN_TYPE(obj)) { + case T_IMEMO: + rb_bug("Unreachable"); + break; + case T_CLASS: + case T_MODULE: + rb_mod_init_copy(dest, obj); + break; + case T_OBJECT: rb_obj_copy_ivar(dest, obj); + break; + default: + rb_copy_generic_ivar(dest, obj); + break; } + rb_gc_copy_attributes(dest, obj); } static VALUE immutable_obj_clone(VALUE obj, VALUE kwfreeze); @@ -424,17 +478,14 @@ immutable_obj_clone(VALUE obj, VALUE kwfreeze) return obj; } -static VALUE -mutable_obj_clone(VALUE obj, VALUE kwfreeze) +VALUE +rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze) { - VALUE clone, singleton; VALUE argv[2]; - clone = rb_obj_alloc(rb_obj_class(obj)); - - singleton = rb_singleton_class_clone_and_attach(obj, clone); + VALUE singleton = rb_singleton_class_clone_and_attach(obj, clone); RBASIC_SET_CLASS(clone, singleton); - if (FL_TEST(singleton, FL_SINGLETON)) { + if (RCLASS_SINGLETON_P(singleton)) { rb_singleton_class_attached(singleton, clone); } @@ -444,16 +495,21 @@ mutable_obj_clone(VALUE obj, VALUE kwfreeze) case Qnil: rb_funcall(clone, id_init_clone, 1, obj); RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE; + + if (RB_TYPE_P(obj, T_STRING)) { + FL_SET_RAW(clone, FL_TEST_RAW(obj, STR_CHILLED)); + } + if (RB_OBJ_FROZEN(obj)) { - rb_shape_transition_shape_frozen(clone); + shape_id_t next_shape_id = rb_obj_shape_transition_frozen(clone); + RBASIC_SET_SHAPE_ID(clone, next_shape_id); } break; - case Qtrue: - { + case Qtrue: { static VALUE freeze_true_hash; if (!freeze_true_hash) { freeze_true_hash = rb_hash_new(); - rb_gc_register_mark_object(freeze_true_hash); + rb_vm_register_global_object(freeze_true_hash); rb_hash_aset(freeze_true_hash, ID2SYM(idFreeze), Qtrue); rb_obj_freeze(freeze_true_hash); } @@ -461,16 +517,14 @@ mutable_obj_clone(VALUE obj, VALUE kwfreeze) argv[0] = obj; argv[1] = freeze_true_hash; rb_funcallv_kw(clone, id_init_clone, 2, argv, RB_PASS_KEYWORDS); - RBASIC(clone)->flags |= FL_FREEZE; - rb_shape_transition_shape_frozen(clone); + OBJ_FREEZE(clone); break; - } - case Qfalse: - { + } + case Qfalse: { static VALUE freeze_false_hash; if (!freeze_false_hash) { freeze_false_hash = rb_hash_new(); - rb_gc_register_mark_object(freeze_false_hash); + rb_vm_register_global_object(freeze_false_hash); rb_hash_aset(freeze_false_hash, ID2SYM(idFreeze), Qfalse); rb_obj_freeze(freeze_false_hash); } @@ -479,7 +533,7 @@ mutable_obj_clone(VALUE obj, VALUE kwfreeze) argv[1] = freeze_false_hash; rb_funcallv_kw(clone, id_init_clone, 2, argv, RB_PASS_KEYWORDS); break; - } + } default: rb_bug("invalid kwfreeze passed to mutable_obj_clone"); } @@ -487,6 +541,13 @@ mutable_obj_clone(VALUE obj, VALUE kwfreeze) return clone; } +static VALUE +mutable_obj_clone(VALUE obj, VALUE kwfreeze) +{ + VALUE clone = rb_obj_alloc(rb_obj_class(obj)); + return rb_obj_clone_setup(obj, clone, kwfreeze); +} + VALUE rb_obj_clone(VALUE obj) { @@ -494,6 +555,15 @@ rb_obj_clone(VALUE obj) return mutable_obj_clone(obj, Qnil); } +VALUE +rb_obj_dup_setup(VALUE obj, VALUE dup) +{ + init_copy(dup, obj); + rb_funcall(dup, id_init_dup, 1, obj); + + return dup; +} + /* * call-seq: * obj.dup -> an_object @@ -542,10 +612,7 @@ rb_obj_dup(VALUE obj) return obj; } dup = rb_obj_alloc(rb_obj_class(obj)); - init_copy(dup, obj); - rb_funcall(dup, id_init_dup, 1, obj); - - return dup; + return rb_obj_dup_setup(obj, dup); } /* @@ -571,18 +638,12 @@ rb_obj_size(VALUE self, VALUE args, VALUE obj) return LONG2FIX(1); } -static VALUE -block_given_p(rb_execution_context_t *ec, VALUE self) -{ - return RBOOL(rb_block_given_p()); -} - /** * :nodoc: *-- - * Default implementation of \c #initialize_copy - * \param[in,out] obj the receiver being initialized - * \param[in] orig the object to be copied from. + * Default implementation of `#initialize_copy` + * @param[in,out] obj the receiver being initialized + * @param[in] orig the object to be copied from. *++ */ VALUE @@ -596,13 +657,13 @@ rb_obj_init_copy(VALUE obj, VALUE orig) return obj; } -/*! +/** * :nodoc: *-- - * Default implementation of \c #initialize_dup + * Default implementation of `#initialize_dup` * - * \param[in,out] obj the receiver being initialized - * \param[in] orig the object to be dup from. + * @param[in,out] obj the receiver being initialized + * @param[in] orig the object to be dup from. *++ **/ VALUE @@ -612,14 +673,14 @@ rb_obj_init_dup_clone(VALUE obj, VALUE orig) return obj; } -/*! +/** * :nodoc: *-- - * Default implementation of \c #initialize_clone + * Default implementation of `#initialize_clone` * - * \param[in] The number of arguments - * \param[in] The array of arguments - * \param[in] obj the receiver being initialized + * @param[in] The number of arguments + * @param[in] The array of arguments + * @param[in] obj the receiver being initialized *++ **/ static VALUE @@ -673,15 +734,19 @@ rb_inspect(VALUE obj) } static int -inspect_i(st_data_t k, st_data_t v, st_data_t a) +inspect_i(ID id, VALUE value, st_data_t a) { - ID id = (ID)k; - VALUE value = (VALUE)v; - VALUE str = (VALUE)a; + VALUE *args = (VALUE *)a, str = args[0], ivars = args[1]; /* need not to show internal data */ if (CLASS_OF(value) == 0) return ST_CONTINUE; if (!rb_is_instance_id(id)) return ST_CONTINUE; + if (!NIL_P(ivars)) { + VALUE name = ID2SYM(id); + for (long i = 0; RARRAY_AREF(ivars, i) != name; ) { + if (++i >= RARRAY_LEN(ivars)) return ST_CONTINUE; + } + } if (RSTRING_PTR(str)[0] == '-') { /* first element */ RSTRING_PTR(str)[0] = '#'; rb_str_cat2(str, " "); @@ -696,13 +761,15 @@ inspect_i(st_data_t k, st_data_t v, st_data_t a) } static VALUE -inspect_obj(VALUE obj, VALUE str, int recur) +inspect_obj(VALUE obj, VALUE a, int recur) { + VALUE *args = (VALUE *)a, str = args[0]; + if (recur) { rb_str_cat2(str, " ..."); } else { - rb_ivar_foreach(obj, inspect_i, str); + rb_ivar_foreach_buffered(obj, inspect_i, a); } rb_str_cat2(str, ">"); RSTRING_PTR(str)[0] = '#'; @@ -735,23 +802,67 @@ inspect_obj(VALUE obj, VALUE str, int recur) * end * end * Bar.new.inspect #=> "#<Bar:0x0300c868 @bar=1>" + * + * If _obj_ responds to +instance_variables_to_inspect+, then only + * the instance variables listed in the returned array will be included + * in the inspect string. + * + * + * class DatabaseConfig + * def initialize(host, user, password) + * @host = host + * @user = user + * @password = password + * end + * + * private + * def instance_variables_to_inspect = [:@host, :@user] + * end + * + * conf = DatabaseConfig.new("localhost", "root", "hunter2") + * conf.inspect #=> #<DatabaseConfig:0x0000000104def350 @host="localhost", @user="root"> */ static VALUE rb_obj_inspect(VALUE obj) { - if (rb_ivar_count(obj) > 0) { - VALUE str; - VALUE c = rb_class_name(CLASS_OF(obj)); + VALUE ivars = rb_check_funcall(obj, id_instance_variables_to_inspect, 0, 0); + st_index_t n = 0; + if (UNDEF_P(ivars) || NIL_P(ivars)) { + n = rb_ivar_count(obj); + ivars = Qnil; + } + else if (RB_TYPE_P(ivars, T_ARRAY)) { + n = RARRAY_LEN(ivars); + } + else { + rb_raise( + rb_eTypeError, + "Expected #instance_variables_to_inspect to return an Array or nil, but it returned %"PRIsVALUE, + rb_obj_class(ivars) + ); + } - str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void*)obj); - return rb_exec_recursive(inspect_obj, obj, str); + if (n > 0) { + VALUE c = rb_class_name(CLASS_OF(obj)); + VALUE args[2] = { + rb_sprintf("-<%"PRIsVALUE":%p", c, (void*)obj), + ivars + }; + return rb_exec_recursive(inspect_obj, obj, (VALUE)args); } else { return rb_any_to_s(obj); } } +/* :nodoc: */ +static VALUE +rb_obj_instance_variables_to_inspect(VALUE obj) +{ + return Qnil; +} + static VALUE class_or_module_required(VALUE c) { @@ -793,7 +904,7 @@ rb_obj_is_instance_of(VALUE obj, VALUE c) return RBOOL(rb_obj_class(obj) == c); } -// Returns whether c is a proper (c != cl) subclass of cl +// Returns whether c is a proper (c != cl) superclass of cl // Both c and cl must be T_CLASS static VALUE class_search_class_ancestor(VALUE cl, VALUE c) @@ -806,7 +917,7 @@ class_search_class_ancestor(VALUE cl, VALUE c) VALUE *classes = RCLASS_SUPERCLASSES(cl); // If c's inheritance chain is longer, it cannot be an ancestor - // We are checking for a proper subclass so don't check if they are equal + // We are checking for a proper superclass so don't check if they are equal if (cl_depth <= c_depth) return Qfalse; @@ -1115,6 +1226,30 @@ rb_class_search_ancestor(VALUE cl, VALUE c) * * Added :FOO * + * If we define a class using the <tt>class</tt> keyword, <tt>const_added</tt> + * runs before <tt>inherited</tt>: + * + * module M + * def self.const_added(const_name) + * super + * p :const_added + * end + * + * parent = Class.new do + * def self.inherited(subclass) + * super + * p :inherited + * end + * end + * + * class Child < parent + * end + * end + * + * <em>produces:</em> + * + * :const_added + * :inherited */ #define rb_obj_mod_const_added rb_obj_dummy1 @@ -1259,17 +1394,51 @@ rb_obj_frozen_p(VALUE obj) /* * Document-class: NilClass * - * The class of the singleton object <code>nil</code>. + * The class of the singleton object +nil+. + * + * Several of its methods act as operators: + * + * - #& + * - #| + * - #=== + * - #=~ + * - #^ + * + * Others act as converters, carrying the concept of _nullity_ + * to other classes: + * + * - #rationalize + * - #to_a + * - #to_c + * - #to_h + * - #to_r + * - #to_s + * + * While +nil+ doesn't have an explicitly defined #to_hash method, + * it can be used in <code>**</code> unpacking, not adding any + * keyword arguments. + * + * Another method provides inspection: + * + * - #inspect + * + * Finally, there is this query method: + * + * - #nil? + * */ /* - * call-seq: - * nil.to_s -> "" + * call-seq: + * to_s -> '' + * + * Returns an empty String: + * + * nil.to_s # => "" * - * Always returns the empty string. */ -MJIT_FUNC_EXPORTED VALUE +VALUE rb_nil_to_s(VALUE obj) { return rb_cNilClass_to_s; @@ -1278,12 +1447,13 @@ rb_nil_to_s(VALUE obj) /* * Document-method: to_a * - * call-seq: - * nil.to_a -> [] + * call-seq: + * to_a -> [] + * + * Returns an empty Array. * - * Always returns an empty array. + * nil.to_a # => [] * - * nil.to_a #=> [] */ static VALUE @@ -1295,12 +1465,13 @@ nil_to_a(VALUE obj) /* * Document-method: to_h * - * call-seq: - * nil.to_h -> {} + * call-seq: + * to_h -> {} + * + * Returns an empty Hash. * - * Always returns an empty hash. + * nil.to_h #=> {} * - * nil.to_h #=> {} */ static VALUE @@ -1310,10 +1481,13 @@ nil_to_h(VALUE obj) } /* - * call-seq: - * nil.inspect -> "nil" + * call-seq: + * inspect -> 'nil' + * + * Returns string <tt>'nil'</tt>: + * + * nil.inspect # => "nil" * - * Always returns the string "nil". */ static VALUE @@ -1323,12 +1497,17 @@ nil_inspect(VALUE obj) } /* - * call-seq: - * nil =~ other -> nil + * call-seq: + * nil =~ object -> nil + * + * Returns +nil+. + * + * This method makes it useful to write: * - * Dummy pattern matching -- always returns nil. + * while gets =~ /re/ + * # ... + * end * - * This method makes it possible to `while gets =~ /re/ do`. */ static VALUE @@ -1337,24 +1516,38 @@ nil_match(VALUE obj1, VALUE obj2) return Qnil; } -/*********************************************************************** +/* * Document-class: TrueClass * - * The global value <code>true</code> is the only instance of class - * TrueClass and represents a logically true value in - * boolean expressions. The class provides operators allowing - * <code>true</code> to be used in logical expressions. + * The class of the singleton object +true+. + * + * Several of its methods act as operators: + * + * - #& + * - #| + * - #=== + * - #^ + * + * One other method: + * + * - #to_s and its alias #inspect. + * */ /* * call-seq: - * true.to_s -> "true" + * true.to_s -> 'true' + * + * Returns string <tt>'true'</tt>: + * + * true.to_s # => "true" + * + * TrueClass#inspect is an alias for TrueClass#to_s. * - * The string representation of <code>true</code> is "true". */ -MJIT_FUNC_EXPORTED VALUE +VALUE rb_true_to_s(VALUE obj) { return rb_cTrueClass_to_s; @@ -1362,11 +1555,15 @@ rb_true_to_s(VALUE obj) /* - * call-seq: - * true & obj -> true or false + * call-seq: + * true & object -> true or false + * + * Returns +false+ if +object+ is +false+ or +nil+, +true+ otherwise: + * + * true & Object.new # => true + * true & false # => false + * true & nil # => false * - * And---Returns <code>false</code> if <i>obj</i> is - * <code>nil</code> or <code>false</code>, <code>true</code> otherwise. */ static VALUE @@ -1377,18 +1574,21 @@ true_and(VALUE obj, VALUE obj2) /* * call-seq: - * true | obj -> true + * true | object -> true * - * Or---Returns <code>true</code>. As <i>obj</i> is an argument to - * a method call, it is always evaluated; there is no short-circuit - * evaluation in this case. + * Returns +true+: * - * true | puts("or") - * true || puts("logical or") + * true | Object.new # => true + * true | false # => true + * true | nil # => true * - * <em>produces:</em> + * Argument +object+ is evaluated. + * This is different from +true+ with the short-circuit operator, + * whose operand is evaluated only if necessary: + * + * true | raise # => Raises RuntimeError. + * true || raise # => true * - * or */ static VALUE @@ -1400,11 +1600,14 @@ true_or(VALUE obj, VALUE obj2) /* * call-seq: - * true ^ obj -> !obj + * true ^ object -> !object + * + * Returns +true+ if +object+ is +false+ or +nil+, +false+ otherwise: + * + * true ^ Object.new # => false + * true ^ false # => true + * true ^ nil # => true * - * Exclusive Or---Returns <code>true</code> if <i>obj</i> is - * <code>nil</code> or <code>false</code>, <code>false</code> - * otherwise. */ static VALUE @@ -1431,22 +1634,27 @@ true_xor(VALUE obj, VALUE obj2) * The string representation of <code>false</code> is "false". */ -MJIT_FUNC_EXPORTED VALUE +VALUE rb_false_to_s(VALUE obj) { return rb_cFalseClass_to_s; } /* - * call-seq: - * false & obj -> false - * nil & obj -> false + * call-seq: + * false & object -> false + * nil & object -> false + * + * Returns +false+: + * + * false & true # => false + * false & Object.new # => false + * + * Argument +object+ is evaluated: + * + * false & raise # Raises RuntimeError. * - * And---Returns <code>false</code>. <i>obj</i> is always - * evaluated as it is the argument to a method call---there is no - * short-circuit evaluation in this case. */ - static VALUE false_and(VALUE obj, VALUE obj2) { @@ -1455,24 +1663,30 @@ false_and(VALUE obj, VALUE obj2) /* - * call-seq: - * false | obj -> true or false - * nil | obj -> true or false + * call-seq: + * false | object -> true or false + * nil | object -> true or false + * + * Returns +false+ if +object+ is +nil+ or +false+, +true+ otherwise: + * + * nil | nil # => false + * nil | false # => false + * nil | Object.new # => true * - * Or---Returns <code>false</code> if <i>obj</i> is - * <code>nil</code> or <code>false</code>; <code>true</code> otherwise. */ #define false_or true_and /* - * call-seq: - * false ^ obj -> true or false - * nil ^ obj -> true or false + * call-seq: + * false ^ object -> true or false + * nil ^ object -> true or false + * + * Returns +false+ if +object+ is +nil+ or +false+, +true+ otherwise: * - * Exclusive Or---If <i>obj</i> is <code>nil</code> or - * <code>false</code>, returns <code>false</code>; otherwise, returns - * <code>true</code>. + * nil ^ nil # => false + * nil ^ false # => false + * nil ^ Object.new # => true * */ @@ -1480,9 +1694,10 @@ false_and(VALUE obj, VALUE obj2) /* * call-seq: - * nil.nil? -> true + * nil.nil? -> true * - * Only the object <i>nil</i> responds <code>true</code> to <code>nil?</code>. + * Returns +true+. + * For all other objects, method <tt>nil?</tt> returns +false+. */ static VALUE @@ -1502,7 +1717,7 @@ rb_true(VALUE obj) */ -MJIT_FUNC_EXPORTED VALUE +VALUE rb_false(VALUE obj) { return Qfalse; @@ -1526,21 +1741,33 @@ rb_obj_not_match(VALUE obj1, VALUE obj2) /* * call-seq: - * obj <=> other -> 0 or nil + * self <=> other -> 0 or nil + * + * Compares +self+ and +other+. + * + * Returns: * - * Returns 0 if +obj+ and +other+ are the same object - * or <code>obj == other</code>, otherwise nil. + * - +0+, if +self+ and +other+ are the same object, + * or if <tt>self == other</tt>. + * - +nil+, otherwise. + * + * Examples: * - * The #<=> is used by various methods to compare objects, for example - * Enumerable#sort, Enumerable#max etc. + * o = Object.new + * o <=> o # => 0 + * o <=> o.dup # => nil * - * Your implementation of #<=> should return one of the following values: -1, 0, - * 1 or nil. -1 means self is smaller than other. 0 means self is equal to other. - * 1 means self is bigger than other. Nil means the two values could not be - * compared. + * A class that includes module Comparable + * should override this method by defining an instance method that: + * + * - Take one argument, +other+. + * - Returns: + * + * - +-1+, if +self+ is less than +other+. + * - +0+, if +self+ is equal to +other+. + * - +1+, if +self+ is greater than +other+. + * - +nil+, if the two values are incommensurate. * - * When you define #<=>, you can include Comparable to gain the - * methods #<=, #<, #==, #>=, #> and #between?. */ static VALUE rb_obj_cmp(VALUE obj1, VALUE obj2) @@ -1587,15 +1814,15 @@ rb_obj_cmp(VALUE obj1, VALUE obj2) * show information on the thing we're attached to as well. */ -MJIT_FUNC_EXPORTED VALUE +VALUE rb_mod_to_s(VALUE klass) { ID id_defined_at; VALUE refined_class, defined_at; - if (FL_TEST(klass, FL_SINGLETON)) { + if (RCLASS_SINGLETON_P(klass)) { VALUE s = rb_usascii_str_new2("#<Class:"); - VALUE v = rb_ivar_get(klass, id__attached__); + VALUE v = RCLASS_ATTACHED_OBJECT(klass); if (CLASS_OR_MODULE_P(v)) { rb_str_append(s, rb_inspect(v)); @@ -1640,11 +1867,12 @@ rb_mod_freeze(VALUE mod) /* * call-seq: - * mod === obj -> true or false + * self === other -> true or false * - * Case Equality---Returns <code>true</code> if <i>obj</i> is an - * instance of <i>mod</i> or an instance of one of <i>mod</i>'s descendants. - * Of limited use for modules, but can be used in <code>case</code> statements + * Returns whether +other+ is an instance of +self+, + * or is an instance of a subclass of +self+. + * + * Of limited use for modules, but can be used in +case+ statements * to classify objects by class. */ @@ -1656,13 +1884,27 @@ rb_mod_eqq(VALUE mod, VALUE arg) /* * call-seq: - * mod <= other -> true, false, or nil + * self <= other -> true, false, or nil + * + * Compares +self+ and +other+ with respect to ancestry and inclusion. + * + * Returns +nil+ if there is no such relationship between the two: + * + * Array <= Hash # => nil + * + * Otherwise, returns +true+ if +other+ is an ancestor of +self+, + * or if +self+ includes +other+, + * or if the two are the same: + * + * File <= IO # => true # IO is an ancestor of File. + * Array <= Enumerable # => true # Array includes Enumerable. + * Array <= Array # => true + * + * Otherwise, returns +false+: + * + * IO <= File # => false + * Enumerable <= Array # => false * - * Returns true if <i>mod</i> is a subclass of <i>other</i> or - * is the same as <i>other</i>. Returns - * <code>nil</code> if there's no relationship between the two. - * (Think of the relationship in terms of the class definition: - * "class A < B" implies "A < B".) */ VALUE @@ -1708,14 +1950,26 @@ rb_class_inherited_p(VALUE mod, VALUE arg) /* * call-seq: - * mod < other -> true, false, or nil + * self < other -> true, false, or nil * - * Returns true if <i>mod</i> is a subclass of <i>other</i>. Returns - * <code>false</code> if <i>mod</i> is the same as <i>other</i> - * or <i>mod</i> is an ancestor of <i>other</i>. - * Returns <code>nil</code> if there's no relationship between the two. - * (Think of the relationship in terms of the class definition: - * "class A < B" implies "A < B".) + * Returns +true+ if +self+ is a descendant of +other+ + * (+self+ is a subclass of +other+ or +self+ includes +other+): + * + * Float < Numeric # => true + * Array < Enumerable # => true + * + * Returns +false+ if +self+ is an ancestor of +other+ + * (+self+ is a superclass of +other+ or +self+ is included in +other+) or + * if +self+ is the same as +other+: + * + * Numeric < Float # => false + * Enumerable < Array # => false + * Float < Float # => false + * + * Returns +nil+ if there is no relationship between the two: + * + * Float < Hash # => nil + * Enumerable < String # => nil * */ @@ -1729,13 +1983,28 @@ rb_mod_lt(VALUE mod, VALUE arg) /* * call-seq: - * mod >= other -> true, false, or nil + * self >= other -> true, false, or nil + * + * Compares +self+ and +other+ with respect to ancestry and inclusion. + * + * Returns +true+ if +self+ is an ancestor of +other+ + * (+self+ is a superclass of +other+ or +self+ is included in +other+) or + * if +self+ is the same as +other+: + * + * Numeric >= Float # => true + * Enumerable >= Array # => true + * Float >= Float # => true + * + * Returns +false+ if +self+ is a descendant of +other+ + * (+self+ is a subclass of +other+ or +self+ includes +other+): + * + * Float >= Numeric # => false + * Array >= Enumerable # => false + * + * Returns +nil+ if there is no relationship between the two: * - * Returns true if <i>mod</i> is an ancestor of <i>other</i>, or the - * two modules are the same. Returns - * <code>nil</code> if there's no relationship between the two. - * (Think of the relationship in terms of the class definition: - * "class A < B" implies "B > A".) + * Float >= Hash # => nil + * Enumerable >= String # => nil * */ @@ -1751,14 +2020,26 @@ rb_mod_ge(VALUE mod, VALUE arg) /* * call-seq: - * mod > other -> true, false, or nil + * self > other -> true, false, or nil * - * Returns true if <i>mod</i> is an ancestor of <i>other</i>. Returns - * <code>false</code> if <i>mod</i> is the same as <i>other</i> - * or <i>mod</i> is a descendant of <i>other</i>. - * Returns <code>nil</code> if there's no relationship between the two. - * (Think of the relationship in terms of the class definition: - * "class A < B" implies "B > A".) + * Returns +true+ if +self+ is an ancestor of +other+ + * (+self+ is a superclass of +other+ or +self+ is included in +other+): + * + * Numeric > Float # => true + * Enumerable > Array # => true + * + * Returns +false+ if +self+ is a descendant of +other+ + * (+self+ is a subclass of +other+ or +self+ includes +other+) or + * if +self+ is the same as +other+: + * + * Float > Numeric # => false + * Array > Enumerable # => false + * Float > Float # => false + * + * Returns +nil+ if there is no relationship between the two: + * + * Float > Hash # => nil + * Enumerable > String # => nil * */ @@ -1771,14 +2052,30 @@ rb_mod_gt(VALUE mod, VALUE arg) /* * call-seq: - * module <=> other_module -> -1, 0, +1, or nil + * self <=> other -> -1, 0, 1, or nil + * + * Compares +self+ and +other+. * - * Comparison---Returns -1, 0, +1 or nil depending on whether +module+ - * includes +other_module+, they are the same, or if +module+ is included by - * +other_module+. + * Returns: + * + * - +-1+, if +self+ includes +other+, if or +self+ is a subclass of +other+. + * - +0+, if +self+ and +other+ are the same. + * - +1+, if +other+ includes +self+, or if +other+ is a subclass of +self+. + * - +nil+, if none of the above is true. + * + * Examples: + * + * # Class Array includes module Enumerable. + * Array <=> Enumerable # => -1 + * Enumerable <=> Enumerable # => 0 + * Enumerable <=> Array # => 1 + * # Class File is a subclass of class IO. + * File <=> IO # => -1 + * File <=> File # => 0 + * IO <=> File # => 1 + * # Class File has no relationship to class String. + * File <=> String # => nil * - * Returns +nil+ if +module+ has no relationship with +other_module+, if - * +other_module+ is not a module, or if the two values are incomparable. */ static VALUE @@ -1803,28 +2100,52 @@ static VALUE rb_mod_initialize_exec(VALUE module); /* * call-seq: - * Module.new -> mod - * Module.new {|mod| block } -> mod + * Module.new -> new_module + * Module.new {|module| ... } -> new_module * - * Creates a new anonymous module. If a block is given, it is passed - * the module object, and the block is evaluated in the context of this - * module like #module_eval. + * Returns a new anonymous module. * - * fred = Module.new do - * def meth1 - * "hello" - * end - * def meth2 - * "bye" - * end - * end - * a = "my string" - * a.extend(fred) #=> "my string" - * a.meth1 #=> "hello" - * a.meth2 #=> "bye" + * The module may be assigned to a name, + * which should be a constant name + * in capitalized {camel case}[https://en.wikipedia.org/wiki/Camel_case] + * (e.g., +MyModule+, not +MY_MODULE+). + * + * With no block given, returns the new module. + * + * MyModule = Module.new + * MyModule.class # => Module + * MyModule.name # => "MyModule" + * + * With a block given, calls the block with the new (not yet named) module: + * + * MyModule = Module.new {|m| p [m.class, m.name] } + * # => MyModule + * MyModule.class # => Module + MyModule.name # => "MyModule" + * + * Output (from the block): + * + * [Module, nil] + * + * The block may define methods and constants for the module: + * + * MyModule = Module.new do |m| + * MY_CONSTANT = "#{MyModule} constant value" + * def self.method1 = "#{MyModule} first method (singleton)" + * def method2 = "#{MyModule} Second method (instance)" + * end + * MyModule.method1 # => "MyModule first method (singleton)" + * class Foo + * include MyModule + * def speak + * MY_CONSTANT + * end + * end + * foo = Foo.new + * foo.method2 # => "MyModule Second method (instance)" + * foo.speak + * # => "MyModule constant value" * - * Assign the module to a constant (name starting uppercase) if you - * want to treat it like a regular module. */ static VALUE @@ -1898,11 +2219,13 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass) else { super = argv[0]; rb_check_inheritable(super); - if (super != rb_cBasicObject && !RCLASS_SUPER(super)) { + if (!RCLASS_INITIALIZED_P(super)) { rb_raise(rb_eTypeError, "can't inherit uninitialized class"); } } - RCLASS_SET_SUPER(klass, super); + rb_class_set_super(klass, super); + RCLASS_SET_MAX_IV_COUNT(klass, RCLASS_MAX_IV_COUNT(super)); + RCLASS_SET_ALLOCATOR(klass, RCLASS_ALLOCATOR(super)); rb_make_metaclass(klass, RBASIC(super)->klass); rb_class_inherited(super, klass); rb_mod_initialize_exec(klass); @@ -1944,19 +2267,9 @@ static VALUE class_call_alloc_func(rb_alloc_func_t allocator, VALUE klass); */ static VALUE -rb_class_alloc_m(VALUE klass) -{ - rb_alloc_func_t allocator = class_get_alloc_func(klass); - if (!rb_obj_respond_to(klass, rb_intern("allocate"), 1)) { - rb_raise(rb_eTypeError, "calling %"PRIsVALUE".allocate is prohibited", - klass); - } - return class_call_alloc_func(allocator, klass); -} - -static VALUE rb_class_alloc(VALUE klass) { + RBIMPL_ASSERT_TYPE(klass, T_CLASS); rb_alloc_func_t allocator = class_get_alloc_func(klass); return class_call_alloc_func(allocator, klass); } @@ -1966,10 +2279,10 @@ class_get_alloc_func(VALUE klass) { rb_alloc_func_t allocator; - if (RCLASS_SUPER(klass) == 0 && klass != rb_cBasicObject) { + if (!RCLASS_INITIALIZED_P(klass)) { rb_raise(rb_eTypeError, "can't instantiate uninitialized class"); } - if (FL_TEST(klass, FL_SINGLETON)) { + if (RCLASS_SINGLETON_P(klass)) { rb_raise(rb_eTypeError, "can't create instance of singleton class"); } allocator = rb_get_alloc_func(klass); @@ -1979,6 +2292,15 @@ class_get_alloc_func(VALUE klass) return allocator; } +// Might return NULL. +rb_alloc_func_t +rb_zjit_class_get_alloc_func(VALUE klass) +{ + assert(RCLASS_INITIALIZED_P(klass)); + assert(!RCLASS_SINGLETON_P(klass)); + return rb_get_alloc_func(klass); +} + static VALUE class_call_alloc_func(rb_alloc_func_t allocator, VALUE klass) { @@ -1988,9 +2310,7 @@ class_call_alloc_func(rb_alloc_func_t allocator, VALUE klass) obj = (*allocator)(klass); - if (rb_obj_class(obj) != rb_class_real(klass)) { - rb_raise(rb_eTypeError, "wrong instance allocation"); - } + RUBY_ASSERT(rb_obj_class(obj) == rb_class_real(klass)); return obj; } @@ -2059,12 +2379,12 @@ rb_class_new_instance(int argc, const VALUE *argv, VALUE klass) * BasicObject.superclass #=> nil * *-- - * Returns the superclass of \a klass. Equivalent to \c Class\#superclass in Ruby. + * Returns the superclass of `klass`. Equivalent to `Class#superclass` in Ruby. * * It skips modules. - * \param[in] klass a Class object - * \return the superclass, or \c Qnil if \a klass does not have a parent class. - * \sa rb_class_get_superclass + * @param[in] klass a Class object + * @return the superclass, or `Qnil` if `klass` does not have a parent class. + * @sa rb_class_get_superclass *++ */ @@ -2073,15 +2393,22 @@ rb_class_superclass(VALUE klass) { RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS)); - VALUE super = RCLASS_SUPER(klass); + VALUE *superclasses = RCLASS_SUPERCLASSES(klass); + size_t superclasses_depth = RCLASS_SUPERCLASS_DEPTH(klass); - if (!super) { - if (klass == rb_cBasicObject) return Qnil; + if (klass == rb_cBasicObject) return Qnil; + + if (!superclasses) { + RUBY_ASSERT(!RCLASS_SUPER(klass)); rb_raise(rb_eTypeError, "uninitialized class"); } + + if (!superclasses_depth) { + return Qnil; + } else { - super = RCLASS_SUPERCLASSES(klass)[RCLASS_SUPERCLASS_DEPTH(klass) - 1]; - RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS)); + VALUE super = superclasses[superclasses_depth - 1]; + RUBY_ASSERT(RB_TYPE_P(super, T_CLASS)); return super; } } @@ -2089,13 +2416,13 @@ rb_class_superclass(VALUE klass) VALUE rb_class_get_superclass(VALUE klass) { - return RCLASS(klass)->super; + return RCLASS_SUPER(klass); } -static const char bad_instance_name[] = "`%1$s' is not allowed as an instance variable name"; -static const char bad_class_name[] = "`%1$s' is not allowed as a class variable name"; +static const char bad_instance_name[] = "'%1$s' is not allowed as an instance variable name"; +static const char bad_class_name[] = "'%1$s' is not allowed as a class variable name"; static const char bad_const_name[] = "wrong constant name %1$s"; -static const char bad_attr_name[] = "invalid attribute name `%1$s'"; +static const char bad_attr_name[] = "invalid attribute name '%1$s'"; #define wrong_constant_name bad_const_name /*! \private */ @@ -2926,7 +3253,7 @@ rb_mod_cvar_defined(VALUE obj, VALUE iv) static VALUE rb_mod_singleton_p(VALUE klass) { - return RBOOL(RB_TYPE_P(klass, T_CLASS) && FL_TEST(klass, FL_SINGLETON)); + return RBOOL(RCLASS_SINGLETON_P(klass)); } /*! \private */ @@ -2975,19 +3302,12 @@ convert_type_with_id(VALUE val, const char *tname, ID method, int raise, int ind VALUE r = rb_check_funcall(val, method, 0, 0); if (UNDEF_P(r)) { if (raise) { - const char *msg = - ((index < 0 ? conv_method_index(rb_id2name(method)) : index) - < IMPLICIT_CONVERSIONS) ? - "no implicit conversion of" : "can't convert"; - const char *cname = NIL_P(val) ? "nil" : - val == Qtrue ? "true" : - val == Qfalse ? "false" : - NULL; - if (cname) - rb_raise(rb_eTypeError, "%s %s into %s", msg, cname, tname); - rb_raise(rb_eTypeError, "%s %"PRIsVALUE" into %s", msg, - rb_obj_class(val), - tname); + if ((index < 0 ? conv_method_index(rb_id2name(method)) : index) < IMPLICIT_CONVERSIONS) { + rb_no_implicit_conversion(val, tname); + } + else { + rb_cant_convert(val, tname); + } } return Qnil; } @@ -3003,17 +3323,6 @@ convert_type(VALUE val, const char *tname, const char *method, int raise) return convert_type_with_id(val, tname, m, raise, i); } -/*! \private */ -NORETURN(static void conversion_mismatch(VALUE, const char *, const char *, VALUE)); -static void -conversion_mismatch(VALUE val, const char *tname, const char *method, VALUE result) -{ - VALUE cname = rb_obj_class(val); - rb_raise(rb_eTypeError, - "can't convert %"PRIsVALUE" to %s (%"PRIsVALUE"#%s gives %"PRIsVALUE")", - cname, tname, cname, method, rb_obj_class(result)); -} - VALUE rb_convert_type(VALUE val, int type, const char *tname, const char *method) { @@ -3022,7 +3331,7 @@ rb_convert_type(VALUE val, int type, const char *tname, const char *method) if (TYPE(val) == type) return val; v = convert_type(val, tname, method, TRUE); if (TYPE(v) != type) { - conversion_mismatch(val, tname, method, v); + rb_cant_convert_invalid_return(val, tname, method, v); } return v; } @@ -3036,7 +3345,7 @@ rb_convert_type_with_id(VALUE val, int type, const char *tname, ID method) if (TYPE(val) == type) return val; v = convert_type_with_id(val, tname, method, TRUE, -1); if (TYPE(v) != type) { - conversion_mismatch(val, tname, RSTRING_PTR(rb_id2str(method)), v); + rb_cant_convert_invalid_return(val, tname, rb_id2name(method), v); } return v; } @@ -3051,13 +3360,13 @@ rb_check_convert_type(VALUE val, int type, const char *tname, const char *method v = convert_type(val, tname, method, FALSE); if (NIL_P(v)) return Qnil; if (TYPE(v) != type) { - conversion_mismatch(val, tname, method, v); + rb_cant_convert_invalid_return(val, tname, method, v); } return v; } /*! \private */ -MJIT_FUNC_EXPORTED VALUE +VALUE rb_check_convert_type_with_id(VALUE val, int type, const char *tname, ID method) { VALUE v; @@ -3067,7 +3376,7 @@ rb_check_convert_type_with_id(VALUE val, int type, const char *tname, ID method) v = convert_type_with_id(val, tname, method, FALSE, -1); if (NIL_P(v)) return Qnil; if (TYPE(v) != type) { - conversion_mismatch(val, tname, RSTRING_PTR(rb_id2str(method)), v); + rb_cant_convert_invalid_return(val, tname, rb_id2name(method), v); } return v; } @@ -3080,14 +3389,22 @@ ALWAYS_INLINE(static VALUE rb_to_integer_with_id_exception(VALUE val, const char static inline VALUE rb_to_integer_with_id_exception(VALUE val, const char *method, ID mid, int raise) { + // We need to pop the lazily pushed frame when not raising an exception. + rb_control_frame_t *current_cfp; VALUE v; if (RB_INTEGER_TYPE_P(val)) return val; + current_cfp = GET_EC()->cfp; + rb_yjit_lazy_push_frame(GET_EC()->cfp->pc); v = try_to_int(val, mid, raise); - if (!raise && NIL_P(v)) return Qnil; + if (!raise && NIL_P(v)) { + GET_EC()->cfp = current_cfp; + return Qnil; + } if (!RB_INTEGER_TYPE_P(v)) { - conversion_mismatch(val, "Integer", method, v); + rb_cant_convert_invalid_return(val, "Integer", method, v); } + GET_EC()->cfp = current_cfp; return v; } #define rb_to_integer(val, method, mid) \ @@ -3162,7 +3479,7 @@ rb_convert_to_integer(VALUE val, int base, int raise_exception) } else if (NIL_P(val)) { if (!raise_exception) return Qnil; - rb_raise(rb_eTypeError, "can't convert nil into Integer"); + rb_cant_convert(val, "Integer"); } tmp = rb_protect(rb_check_to_int, val, NULL); @@ -3222,125 +3539,28 @@ rb_opts_exception_p(VALUE opts, int default_value) return default_value; } -#define opts_exception_p(opts) rb_opts_exception_p((opts), TRUE) - -/* - * call-seq: - * Integer(object, base = 0, exception: true) -> integer or nil - * - * Returns an integer converted from +object+. - * - * Tries to convert +object+ to an integer - * using +to_int+ first and +to_i+ second; - * see below for exceptions. - * - * With a non-zero +base+, +object+ must be a string or convertible - * to a string. - * - * ==== numeric objects - * - * With integer argument +object+ given, returns +object+: - * - * Integer(1) # => 1 - * Integer(-1) # => -1 - * - * With floating-point argument +object+ given, - * returns +object+ truncated to an intger: - * - * Integer(1.9) # => 1 # Rounds toward zero. - * Integer(-1.9) # => -1 # Rounds toward zero. - * - * ==== string objects - * - * With string argument +object+ and zero +base+ given, - * returns +object+ converted to an integer in base 10: - * - * Integer('100') # => 100 - * Integer('-100') # => -100 - * - * With +base+ zero, string +object+ may contain leading characters - * to specify the actual base (radix indicator): - * - * Integer('0100') # => 64 # Leading '0' specifies base 8. - * Integer('0b100') # => 4 # Leading '0b', specifies base 2. - * Integer('0x100') # => 256 # Leading '0x' specifies base 16. - * - * With a positive +base+ (in range 2..36) given, returns +object+ - * converted to an integer in the given base: - * - * Integer('100', 2) # => 4 - * Integer('100', 8) # => 64 - * Integer('-100', 16) # => -256 - * - * With a negative +base+ (in range -36..-2) given, returns +object+ - * converted to an integer in the radix indicator if exists or - * +-base+: - * - * Integer('0x100', -2) # => 256 - * Integer('100', -2) # => 4 - * Integer('0b100', -8) # => 4 - * Integer('100', -8) # => 64 - * Integer('0o100', -10) # => 64 - * Integer('100', -10) # => 100 - * - * +base+ -1 is equal the -10 case. - * - * When converting strings, surrounding whitespace and embedded underscores - * are allowed and ignored: - * - * Integer(' 100 ') # => 100 - * Integer('-1_0_0', 16) # => -256 - * - * ==== other classes - * - * Examples with +object+ of various other classes: - * - * Integer(Rational(9, 10)) # => 0 # Rounds toward zero. - * Integer(Complex(2, 0)) # => 2 # Imaginary part must be zero. - * Integer(Time.now) # => 1650974042 - * - * ==== keywords - * - * With optional keyword argument +exception+ given as +true+ (the default): - * - * - Raises TypeError if +object+ does not respond to +to_int+ or +to_i+. - * - Raises TypeError if +object+ is +nil+. - * - Raise ArgumentError if +object+ is an invalid string. - * - * With +exception+ given as +false+, an exception of any kind is suppressed - * and +nil+ is returned. - * - */ - static VALUE -rb_f_integer(int argc, VALUE *argv, VALUE obj) +rb_f_integer1(rb_execution_context_t *ec, VALUE obj, VALUE arg) { - VALUE arg = Qnil, opts = Qnil; - int base = 0; + return rb_convert_to_integer(arg, 0, TRUE); +} - if (argc > 1) { - int narg = 1; - VALUE vbase = rb_check_to_int(argv[1]); - if (!NIL_P(vbase)) { - base = NUM2INT(vbase); - narg = 2; - } - if (argc > narg) { - VALUE hash = rb_check_hash_type(argv[argc-1]); - if (!NIL_P(hash)) { - opts = rb_extract_keywords(&hash); - if (!hash) --argc; - } - } - } - rb_check_arity(argc, 1, 2); - arg = argv[0]; +static VALUE +rb_f_integer(rb_execution_context_t *ec, VALUE obj, VALUE arg, VALUE base, VALUE exception) +{ + int exc = rb_bool_expected(exception, "exception", TRUE); + return rb_convert_to_integer(arg, NUM2INT(base), exc); +} - return rb_convert_to_integer(arg, base, opts_exception_p(opts)); +static bool +is_digit_char(unsigned char c, int base) +{ + int i = ruby_digit36_to_number_table[c]; + return (i >= 0 && i < base); } static double -rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error) +rb_cstr_to_dbl_raise(const char *p, rb_encoding *enc, int badcheck, int raise, int *error) { const char *q; char *end; @@ -3351,6 +3571,7 @@ rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error) #define OutOfRange() ((end - p > max_width) ? \ (w = max_width, ellipsis = "...") : \ (w = (int)(end - p), ellipsis = "")) + /* p...end has been parsed with strtod, should be ASCII-only */ if (!p) return 0.0; q = p; @@ -3379,23 +3600,37 @@ rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error) char *e = init_e; char prev = 0; int dot_seen = FALSE; + int base = 10; + char exp_letter = 'e'; switch (*p) {case '+': case '-': prev = *n++ = *p++;} if (*p == '0') { prev = *n++ = '0'; - while (*++p == '0'); + switch (*++p) { + case 'x': case 'X': + prev = *n++ = 'x'; + base = 16; + exp_letter = 'p'; + if (*++p != '0') break; + /* fallthrough */ + case '0': /* squeeze successive zeros */ + while (*++p == '0'); + break; + } } while (p < end && n < e) prev = *n++ = *p++; while (*p) { if (*p == '_') { /* remove an underscore between digits */ - if (n == buf || !ISDIGIT(prev) || (++p, !ISDIGIT(*p))) { + if (n == buf || + !is_digit_char(prev, base) || + !is_digit_char(*++p, base)) { if (badcheck) goto bad; break; } } prev = *p++; - if (e == init_e && (prev == 'e' || prev == 'E' || prev == 'p' || prev == 'P')) { + if (e == init_e && (rb_tolower(prev) == exp_letter)) { e = buf + sizeof(buf) - 1; *n++ = prev; switch (*p) {case '+': case '-': prev = *n++ = *p++;} @@ -3403,6 +3638,10 @@ rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error) prev = *n++ = '0'; while (*++p == '0'); } + + /* reset base to decimal for underscore check of + * binary exponent part */ + base = 10; continue; } else if (ISSPACE(prev)) { @@ -3412,7 +3651,7 @@ rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error) break; } } - else if (prev == '.' ? dot_seen++ : !ISDIGIT(prev)) { + else if (prev == '.' ? dot_seen++ : !is_digit_char(prev, base)) { if (badcheck) goto bad; break; } @@ -3446,7 +3685,8 @@ rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error) bad: if (raise) { - rb_invalid_str(q, "Float()"); + VALUE s = rb_enc_str_new_cstr(q, enc); + rb_raise(rb_eArgError, "invalid value for Float(): %+"PRIsVALUE, s); UNREACHABLE_RETURN(nan("")); } else { @@ -3458,7 +3698,7 @@ rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error) double rb_cstr_to_dbl(const char *p, int badcheck) { - return rb_cstr_to_dbl_raise(p, badcheck, TRUE, NULL); + return rb_cstr_to_dbl_raise(p, NULL, badcheck, TRUE, NULL); } static double @@ -3470,6 +3710,7 @@ rb_str_to_dbl_raise(VALUE str, int badcheck, int raise, int *error) VALUE v = 0; StringValue(str); + rb_must_asciicompat(str); s = RSTRING_PTR(str); len = RSTRING_LEN(str); if (s) { @@ -3488,9 +3729,11 @@ rb_str_to_dbl_raise(VALUE str, int badcheck, int raise, int *error) s = p; } } - ret = rb_cstr_to_dbl_raise(s, badcheck, raise, error); + ret = rb_cstr_to_dbl_raise(s, rb_enc_get(str), badcheck, raise, error); if (v) ALLOCV_END(v); + else + RB_GC_GUARD(str); return ret; } @@ -3530,18 +3773,6 @@ rat2dbl_without_to_f(VALUE x) } /*! \endcond */ -static inline void -conversion_to_float(VALUE val) -{ - special_const_to_float(val, "can't convert ", " into Float"); -} - -static inline void -implicit_conversion_to_float(VALUE val) -{ - special_const_to_float(val, "no implicit conversion to float from ", ""); -} - static int to_float(VALUE *valp, int raise_exception) { @@ -3555,7 +3786,7 @@ to_float(VALUE *valp, int raise_exception) return T_FLOAT; } else if (raise_exception) { - conversion_to_float(val); + rb_cant_convert(val, "Float"); } } else { @@ -3635,8 +3866,7 @@ static VALUE numeric_to_float(VALUE val) { if (!rb_obj_is_kind_of(val, rb_cNumeric)) { - rb_raise(rb_eTypeError, "can't convert %"PRIsVALUE" into Float", - rb_obj_class(val)); + rb_cant_convert(val, "Float"); } return rb_convert_type_with_id(val, T_FLOAT, "Float", id_to_f); } @@ -3680,7 +3910,7 @@ rb_num_to_dbl(VALUE val) return rb_float_flonum_value(val); } else { - conversion_to_float(val); + rb_cant_convert(val, "Float"); } } else { @@ -3714,7 +3944,7 @@ rb_num2dbl(VALUE val) return rb_float_flonum_value(val); } else { - implicit_conversion_to_float(val); + rb_no_implicit_conversion(val, "Float"); } } else { @@ -3726,7 +3956,7 @@ rb_num2dbl(VALUE val) case T_RATIONAL: return rat2dbl_without_to_f(val); case T_STRING: - rb_raise(rb_eTypeError, "no implicit conversion to float from string"); + rb_no_implicit_conversion(val, "Float"); default: break; } @@ -3756,7 +3986,7 @@ rb_String(VALUE val) * * String([0, 1, 2]) # => "[0, 1, 2]" * String(0..5) # => "0..5" - * String({foo: 0, bar: 1}) # => "{:foo=>0, :bar=>1}" + * String({foo: 0, bar: 1}) # => "{foo: 0, bar: 1}" * * Raises +TypeError+ if +object+ cannot be converted to a string. */ @@ -3820,7 +4050,7 @@ rb_Hash(VALUE val) if (NIL_P(tmp)) { if (RB_TYPE_P(val, T_ARRAY) && RARRAY_LEN(val) == 0) return rb_hash_new(); - rb_raise(rb_eTypeError, "can't convert %s into Hash", rb_obj_classname(val)); + rb_cant_convert(val, "Hash"); } return tmp; } @@ -3841,7 +4071,7 @@ rb_Hash(VALUE val) * * Examples: * - * Hash({foo: 0, bar: 1}) # => {:foo=>0, :bar=>1} + * Hash({foo: 0, bar: 1}) # => {foo: 0, bar: 1} * Hash(nil) # => {} * Hash([]) # => {} * @@ -3928,10 +4158,7 @@ rb_obj_dig(int argc, VALUE *argv, VALUE obj, VALUE notfound) * into +format_string+. * * For details on +format_string+, see - * {Format Specifications}[rdoc-ref:format_specifications.rdoc]. - * - * Kernel#format is an alias for Kernel#sprintf. - * + * {Format Specifications}[rdoc-ref:language/format_specifications.rdoc]. */ static VALUE @@ -3940,6 +4167,12 @@ f_sprintf(int c, const VALUE *v, VALUE _) return rb_f_sprintf(c, v); } +static VALUE +rb_f_loop_size(VALUE self, VALUE args, VALUE eobj) +{ + return DBL2NUM(HUGE_VAL); +} + /* * Document-class: Class * @@ -4002,57 +4235,51 @@ f_sprintf(int c, const VALUE *v, VALUE _) */ -/* Document-class: BasicObject +/* + * Document-class: BasicObject * - * BasicObject is the parent class of all classes in Ruby. It's an explicit - * blank class. + * +BasicObject+ is the parent class of all classes in Ruby. + * In particular, +BasicObject+ is the parent class of class Object, + * which is itself the default parent class of every Ruby class: * - * BasicObject can be used for creating object hierarchies independent of - * Ruby's object hierarchy, proxy objects like the Delegator class, or other - * uses where namespace pollution from Ruby's methods and classes must be - * avoided. + * class Foo; end + * Foo.superclass # => Object + * Object.superclass # => BasicObject * - * To avoid polluting BasicObject for other users an appropriately named - * subclass of BasicObject should be created instead of directly modifying - * BasicObject: + * +BasicObject+ is the only class that has no parent: * - * class MyObjectSystem < BasicObject - * end + * BasicObject.superclass # => nil * - * BasicObject does not include Kernel (for methods like +puts+) and - * BasicObject is outside of the namespace of the standard library so common - * classes will not be found without using a full class path. + * Class +BasicObject+ can be used to create an object hierarchy + * (e.g., class Delegator) that is independent of Ruby's object hierarchy. + * Such objects: * - * A variety of strategies can be used to provide useful portions of the - * standard library to subclasses of BasicObject. A subclass could - * <code>include Kernel</code> to obtain +puts+, +exit+, etc. A custom - * Kernel-like module could be created and included or delegation can be used - * via #method_missing: + * - Do not have namespace "pollution" from the many methods + * provided in class Object and its included module Kernel. + * - Do not have definitions of common classes, + * and so references to such common classes must be fully qualified + * (+::String+, not +String+). * - * class MyObjectSystem < BasicObject - * DELEGATE = [:puts, :p] + * A variety of strategies can be used to provide useful portions + * of the Standard Library in subclasses of +BasicObject+: * - * def method_missing(name, *args, &block) - * return super unless DELEGATE.include? name - * ::Kernel.send(name, *args, &block) - * end + * - The immediate subclass could <tt>include Kernel</tt>, + * which would define methods such as +puts+, +exit+, etc. + * - A custom Kernel-like module could be created and included. + * - Delegation can be used via #method_missing: * - * def respond_to_missing?(name, include_private = false) - * DELEGATE.include?(name) or super - * end - * end + * class MyObjectSystem < BasicObject + * DELEGATE = [:puts, :p] * - * Access to classes and modules from the Ruby standard library can be - * obtained in a BasicObject subclass by referencing the desired constant - * from the root like <code>::File</code> or <code>::Enumerator</code>. - * Like #method_missing, #const_missing can be used to delegate constant - * lookup to +Object+: + * def method_missing(name, *args, &block) + * return super unless DELEGATE.include? name + * ::Kernel.send(name, *args, &block) + * end * - * class MyObjectSystem < BasicObject - * def self.const_missing(name) - * ::Object.const_get(name) + * def respond_to_missing?(name, include_private = false) + * DELEGATE.include?(name) + * end * end - * end * * === What's Here * @@ -4066,8 +4293,11 @@ f_sprintf(int c, const VALUE *v, VALUE _) * - #__send__: Calls the method identified by the given symbol. * - #equal?: Returns whether +self+ and the given object are the same object. * - #instance_eval: Evaluates the given string or block in the context of +self+. - * - #instance_exec: Executes the given block in the context of +self+, - * passing the given arguments. + * - #instance_exec: Executes the given block in the context of +self+, passing the given arguments. + * - #method_missing: Called when +self+ is called with a method it does not define. + * - #singleton_method_added: Called when a singleton method is added to +self+. + * - #singleton_method_removed: Called when a singleton method is removed from +self+. + * - #singleton_method_undefined: Called when a singleton method is undefined in +self+. * */ @@ -4091,10 +4321,10 @@ f_sprintf(int c, const VALUE *v, VALUE _) * * == What's Here * - * First, what's elsewhere. \Class \Object: + * First, what's elsewhere. Class \Object: * - * - Inherits from {class BasicObject}[rdoc-ref:BasicObject@What-27s+Here]. - * - Includes {module Kernel}[rdoc-ref:Kernel@What-27s+Here]. + * - Inherits from {class BasicObject}[rdoc-ref:BasicObject@Whats+Here]. + * - Includes {module Kernel}[rdoc-ref:Kernel@Whats+Here]. * * Here, class \Object provides methods for: * @@ -4115,7 +4345,7 @@ f_sprintf(int c, const VALUE *v, VALUE _) * - #instance_of?: Returns whether +self+ is an instance of the given class. * - #instance_variable_defined?: Returns whether the given instance variable * is defined in +self+. - * - #method: Returns the Method object for the given method in +self+. + * - #method: Returns the +Method+ object for the given method in +self+. * - #methods: Returns an array of symbol names of public and protected methods * in +self+. * - #nil?: Returns +false+. (Only +nil+ responds +true+ to method <tt>nil?</tt>.) @@ -4125,12 +4355,12 @@ f_sprintf(int c, const VALUE *v, VALUE _) * of the private methods in +self+. * - #protected_methods: Returns an array of the symbol names * of the protected methods in +self+. - * - #public_method: Returns the Method object for the given public method in +self+. + * - #public_method: Returns the +Method+ object for the given public method in +self+. * - #public_methods: Returns an array of the symbol names * of the public methods in +self+. * - #respond_to?: Returns whether +self+ responds to the given method. * - #singleton_class: Returns the singleton class of +self+. - * - #singleton_method: Returns the Method object for the given singleton method + * - #singleton_method: Returns the +Method+ object for the given singleton method * in +self+. * - #singleton_methods: Returns an array of the symbol names * of the singleton methods in +self+. @@ -4157,7 +4387,7 @@ f_sprintf(int c, const VALUE *v, VALUE _) * and frozen state. * - #define_singleton_method: Defines a singleton method in +self+ * for the given symbol method-name and block or proc. - * - #display: Prints +self+ to the given \IO stream or <tt>$stdout</tt>. + * - #display: Prints +self+ to the given IO stream or <tt>$stdout</tt>. * - #dup: Returns a shallow unfrozen copy of +self+. * - #enum_for (aliased as #to_enum): Returns an Enumerator for +self+ * using the using the given method, arguments, and block. @@ -4173,27 +4403,6 @@ f_sprintf(int c, const VALUE *v, VALUE _) * */ -/*! - *-- - * \private - * Initializes the world of objects and classes. - * - * At first, the function bootstraps the class hierarchy. - * It initializes the most fundamental classes and their metaclasses. - * - \c BasicObject - * - \c Object - * - \c Module - * - \c Class - * After the bootstrap step, the class hierarchy becomes as the following - * diagram. - * - * \image html boottime-classes.png - * - * Then, the function defines classes, modules and methods as usual. - * \ingroup class - *++ - */ - void InitVM_Object(void) { @@ -4209,7 +4418,6 @@ InitVM_Object(void) #endif rb_define_private_method(rb_cBasicObject, "initialize", rb_obj_initialize, 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_define_method(rb_cBasicObject, "!", rb_obj_not, 0); @@ -4232,7 +4440,7 @@ InitVM_Object(void) * * == What's Here * - * \Module \Kernel provides methods that are useful for: + * Module \Kernel provides methods that are useful for: * * - {Converting}[rdoc-ref:Kernel@Converting] * - {Querying}[rdoc-ref:Kernel@Querying] @@ -4300,7 +4508,7 @@ InitVM_Object(void) * - #print: Prints the given objects to standard output without a newline. * - #printf: Prints the string resulting from applying the given format string * to any additional arguments. - * - #putc: Equivalent to <tt.$stdout.putc(object)</tt> for the given object. + * - #putc: Equivalent to <tt>$stdout.putc(object)</tt> for the given object. * - #puts: Equivalent to <tt>$stdout.puts(*objects)</tt> for the given objects. * - #readline: Similar to #gets, but raises an exception at the end of file. * - #readlines: Returns an array of the remaining lines from the current input. @@ -4390,6 +4598,7 @@ InitVM_Object(void) rb_define_method(rb_mKernel, "to_s", rb_any_to_s, 0); rb_define_method(rb_mKernel, "inspect", rb_obj_inspect, 0); + rb_define_private_method(rb_mKernel, "instance_variables_to_inspect", rb_obj_instance_variables_to_inspect, 0); rb_define_method(rb_mKernel, "methods", rb_obj_methods, -1); /* in class.c */ 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); /* in class.c */ @@ -4409,15 +4618,13 @@ InitVM_Object(void) rb_define_global_function("sprintf", f_sprintf, -1); rb_define_global_function("format", f_sprintf, -1); - rb_define_global_function("Integer", rb_f_integer, -1); - rb_define_global_function("String", rb_f_string, 1); rb_define_global_function("Array", rb_f_array, 1); rb_define_global_function("Hash", rb_f_hash, 1); rb_cNilClass = rb_define_class("NilClass", rb_cObject); rb_cNilClass_to_s = rb_fstring_enc_lit("", rb_usascii_encoding()); - rb_gc_register_mark_object(rb_cNilClass_to_s); + rb_vm_register_global_object(rb_cNilClass_to_s); rb_define_method(rb_cNilClass, "to_s", rb_nil_to_s, 0); rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0); rb_define_method(rb_cNilClass, "to_h", nil_to_h, 0); @@ -4440,12 +4647,12 @@ InitVM_Object(void) rb_define_method(rb_cModule, "<=", rb_class_inherited_p, 1); rb_define_method(rb_cModule, ">", rb_mod_gt, 1); 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_alias(rb_cModule, "inspect", "to_s"); 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, "set_temporary_name", rb_mod_set_temporary_name, 1); /* in variable.c */ rb_define_method(rb_cModule, "ancestors", rb_mod_ancestors, 0); /* in class.c */ rb_define_method(rb_cModule, "attr", rb_mod_attr, -1); @@ -4488,8 +4695,8 @@ InitVM_Object(void) rb_define_method(rb_cModule, "deprecate_constant", rb_mod_deprecate_constant, -1); /* in variable.c */ rb_define_method(rb_cModule, "singleton_class?", rb_mod_singleton_p, 0); - rb_define_method(rb_singleton_class(rb_cClass), "allocate", rb_class_alloc_m, 0); - rb_define_method(rb_cClass, "allocate", rb_class_alloc_m, 0); + rb_define_method(rb_singleton_class(rb_cClass), "allocate", rb_class_alloc, 0); + rb_define_method(rb_cClass, "allocate", rb_class_alloc, 0); rb_define_method(rb_cClass, "new", rb_class_new_instance_pass_kw, -1); rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1); rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0); @@ -4502,7 +4709,7 @@ InitVM_Object(void) rb_cTrueClass = rb_define_class("TrueClass", rb_cObject); rb_cTrueClass_to_s = rb_fstring_enc_lit("true", rb_usascii_encoding()); - rb_gc_register_mark_object(rb_cTrueClass_to_s); + rb_vm_register_global_object(rb_cTrueClass_to_s); rb_define_method(rb_cTrueClass, "to_s", rb_true_to_s, 0); rb_define_alias(rb_cTrueClass, "inspect", "to_s"); rb_define_method(rb_cTrueClass, "&", true_and, 1); @@ -4514,7 +4721,7 @@ InitVM_Object(void) rb_cFalseClass = rb_define_class("FalseClass", rb_cObject); rb_cFalseClass_to_s = rb_fstring_enc_lit("false", rb_usascii_encoding()); - rb_gc_register_mark_object(rb_cFalseClass_to_s); + rb_vm_register_global_object(rb_cFalseClass_to_s); rb_define_method(rb_cFalseClass, "to_s", rb_false_to_s, 0); rb_define_alias(rb_cFalseClass, "inspect", "to_s"); rb_define_method(rb_cFalseClass, "&", false_and, 1); @@ -4532,6 +4739,7 @@ void Init_Object(void) { id_dig = rb_intern_const("dig"); + id_instance_variables_to_inspect = rb_intern_const("instance_variables_to_inspect"); InitVM(Object); } |
