summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
Diffstat (limited to 'object.c')
-rw-r--r--object.c2319
1 files changed, 1097 insertions, 1222 deletions
diff --git a/object.c b/object.c
index 705ba7ff1c..0a8ce4dc0f 100644
--- a/object.c
+++ b/object.c
@@ -31,14 +31,30 @@
#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"
#include "probes.h"
#include "ruby/encoding.h"
#include "ruby/st.h"
#include "ruby/util.h"
#include "ruby/assert.h"
#include "builtin.h"
+#include "shape.h"
+#include "yjit.h"
+
+/* Flags of RObject
+ *
+ * 1: ROBJECT_EMBED
+ * The object has its instance variables embedded (the array of
+ * instance variables directly follow the object, rather than being
+ * on a separately allocated buffer).
+ * if !SHAPE_IN_BASIC_FLAGS
+ * 4-19: SHAPE_FLAG_MASK
+ * Shape ID for the object.
+ * endif
+ */
/*!
* \addtogroup object
@@ -78,11 +94,17 @@ static VALUE rb_cFalseClass_to_s;
/*! \endcond */
+size_t
+rb_obj_embedded_size(uint32_t numiv)
+{
+ return offsetof(struct RObject, as.ary) + (sizeof(VALUE) * numiv);
+}
+
VALUE
rb_obj_hide(VALUE obj)
{
if (!SPECIAL_CONST_P(obj)) {
- RBASIC_CLEAR_CLASS(obj);
+ RBASIC_CLEAR_CLASS(obj);
}
return obj;
}
@@ -91,26 +113,63 @@ VALUE
rb_obj_reveal(VALUE obj, VALUE klass)
{
if (!SPECIAL_CONST_P(obj)) {
- RBASIC_SET_CLASS(obj, klass);
+ RBASIC_SET_CLASS(obj, klass);
+ }
+ return obj;
+}
+
+VALUE
+rb_class_allocate_instance(VALUE klass)
+{
+ uint32_t index_tbl_num_entries = RCLASS_EXT(klass)->max_iv_count;
+
+ size_t size = rb_obj_embedded_size(index_tbl_num_entries);
+ if (!rb_gc_size_allocatable_p(size)) {
+ size = sizeof(struct RObject);
+ }
+
+ NEWOBJ_OF(o, struct RObject, klass,
+ T_OBJECT | ROBJECT_EMBED | (RGENGC_WB_PROTECTED_OBJECT ? FL_WB_PROTECTED : 0), size, 0);
+ VALUE obj = (VALUE)o;
+
+ RUBY_ASSERT(rb_shape_get_shape(obj)->type == SHAPE_ROOT);
+
+ // Set the shape to the specific T_OBJECT shape.
+ ROBJECT_SET_SHAPE_ID(obj, (shape_id_t)(rb_gc_size_pool_id_for_size(size) + FIRST_T_OBJECT_SHAPE_ID));
+
+#if RUBY_DEBUG
+ RUBY_ASSERT(!rb_shape_obj_too_complex(obj));
+ VALUE *ptr = ROBJECT_IVPTR(obj);
+ for (size_t i = 0; i < ROBJECT_IV_CAPACITY(obj); i++) {
+ ptr[i] = Qundef;
}
+#endif
+
return obj;
}
VALUE
rb_obj_setup(VALUE obj, VALUE klass, VALUE type)
{
- RBASIC(obj)->flags = type;
+ VALUE ignored_flags = RUBY_FL_PROMOTED | RUBY_FL_SEEN_OBJ_ID;
+ 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
+ *
+ * Returns +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.
+ * Like Object#==, if +object+ 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
@@ -123,8 +182,8 @@ rb_equal(VALUE obj1, VALUE obj2)
if (obj1 == obj2) return Qtrue;
result = rb_equal_opt(obj1, obj2);
- if (result == Qundef) {
- result = rb_funcall(obj1, id_eq, 1, obj2);
+ if (UNDEF_P(result)) {
+ result = rb_funcall(obj1, id_eq, 1, obj2);
}
return RBOOL(RTEST(result));
}
@@ -134,12 +193,12 @@ rb_eql(VALUE obj1, VALUE obj2)
{
VALUE result;
- if (obj1 == obj2) return Qtrue;
+ if (obj1 == obj2) return TRUE;
result = rb_eql_opt(obj1, obj2);
- if (result == Qundef) {
- result = rb_funcall(obj1, id_eql, 1, obj2);
+ if (UNDEF_P(result)) {
+ result = rb_funcall(obj1, id_eql, 1, obj2);
}
- return RBOOL(RTEST(result));
+ return RTEST(result);
}
/**
@@ -183,7 +242,7 @@ rb_eql(VALUE obj1, VALUE obj2)
* \private
*++
*/
-MJIT_FUNC_EXPORTED VALUE
+VALUE
rb_obj_equal(VALUE obj1, VALUE obj2)
{
return RBOOL(obj1 == obj2);
@@ -201,10 +260,10 @@ VALUE rb_obj_hash(VALUE obj);
*++
*/
-MJIT_FUNC_EXPORTED VALUE
+VALUE
rb_obj_not(VALUE obj)
{
- return RTEST(obj) ? Qfalse : Qtrue;
+ return RBOOL(!RTEST(obj));
}
/**
@@ -217,19 +276,19 @@ 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 RTEST(result) ? Qfalse : Qtrue;
+ return rb_obj_not(result);
}
VALUE
rb_class_real(VALUE cl)
{
while (cl &&
- ((RBASIC(cl)->flags & FL_SINGLETON) || BUILTIN_TYPE(cl) == T_ICLASS)) {
- cl = RCLASS_SUPER(cl);
+ (RCLASS_SINGLETON_P(cl) || BUILTIN_TYPE(cl) == T_ICLASS)) {
+ cl = RCLASS_SUPER(cl);
}
return cl;
}
@@ -264,36 +323,68 @@ rb_obj_singleton_class(VALUE obj)
}
/*! \private */
-MJIT_FUNC_EXPORTED void
+void
rb_obj_copy_ivar(VALUE dest, VALUE obj)
{
- VALUE *dst_buf = 0;
- VALUE *src_buf = 0;
- uint32_t len = ROBJECT_EMBED_LEN_MAX;
+ RUBY_ASSERT(!RB_TYPE_P(obj, T_CLASS) && !RB_TYPE_P(obj, T_MODULE));
- if (RBASIC(obj)->flags & ROBJECT_EMBED) {
- src_buf = ROBJECT(obj)->as.ary;
+ RUBY_ASSERT(BUILTIN_TYPE(dest) == BUILTIN_TYPE(obj));
+ rb_shape_t * src_shape = rb_shape_get_shape(obj);
- // embedded -> embedded
- if (RBASIC(dest)->flags & ROBJECT_EMBED) {
- dst_buf = ROBJECT(dest)->as.ary;
- }
- // embedded -> extended
- else {
- dst_buf = ROBJECT(dest)->as.heap.ivptr;
+ if (rb_shape_obj_too_complex(obj)) {
+ // obj is TOO_COMPLEX so we can copy its iv_hash
+ st_table *table = st_copy(ROBJECT_IV_HASH(obj));
+ rb_obj_convert_to_too_complex(dest, table);
+
+ 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;
+
+ if (!src_num_ivs) {
+ 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);
+
+ if (initial_shape->size_pool_index != src_shape->size_pool_index) {
+ RUBY_ASSERT(initial_shape->type == SHAPE_T_OBJECT);
+
+ shape_to_set_on_dest = rb_shape_rebuild_shape(initial_shape, src_shape);
+ if (UNLIKELY(rb_shape_id(shape_to_set_on_dest) == OBJ_TOO_COMPLEX_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_convert_to_too_complex(dest, table);
+
+ return;
}
}
- // extended -> extended
- else {
- uint32_t src_len = ROBJECT(obj)->as.heap.numiv;
- uint32_t dst_len = ROBJECT(dest)->as.heap.numiv;
- len = src_len < dst_len ? src_len : dst_len;
- dst_buf = ROBJECT(dest)->as.heap.ivptr;
- src_buf = ROBJECT(obj)->as.heap.ivptr;
+ RUBY_ASSERT(src_num_ivs <= shape_to_set_on_dest->capacity || rb_shape_id(shape_to_set_on_dest) == OBJ_TOO_COMPLEX_SHAPE_ID);
+ 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);
}
- MEMCPY(dst_buf, src_buf, VALUE, len);
+ MEMCPY(dest_buf, src_buf, VALUE, src_num_ivs);
+
+ // Fire write barriers
+ for (uint32_t i = 0; i < src_num_ivs; i++) {
+ RB_OBJ_WRITTEN(dest, Qundef, dest_buf[i]);
+ }
+
+ rb_shape_set_shape(dest, shape_to_set_on_dest);
}
static void
@@ -303,12 +394,12 @@ init_copy(VALUE dest, VALUE obj)
rb_raise(rb_eTypeError, "[bug] frozen object (%s) allocated", rb_obj_classname(dest));
}
RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR);
+ // 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_gc_copy_attributes(dest, obj);
rb_copy_generic_ivar(dest, obj);
- rb_gc_copy_finalizer(dest, obj);
if (RB_TYPE_P(obj, T_OBJECT)) {
- rb_obj_copy_ivar(dest, obj);
+ rb_obj_copy_ivar(dest, obj);
}
}
@@ -325,10 +416,10 @@ special_object_p(VALUE obj)
case T_SYMBOL:
case T_RATIONAL:
case T_COMPLEX:
- /* not a comprehensive list */
- return TRUE;
+ /* not a comprehensive list */
+ return TRUE;
default:
- return FALSE;
+ return FALSE;
}
}
@@ -352,7 +443,7 @@ rb_obj_clone2(rb_execution_context_t *ec, VALUE obj, VALUE freeze)
{
VALUE kwfreeze = obj_freeze_opt(freeze);
if (!special_object_p(obj))
- return mutable_obj_clone(obj, kwfreeze);
+ return mutable_obj_clone(obj, kwfreeze);
return immutable_obj_clone(obj, kwfreeze);
}
@@ -372,12 +463,12 @@ rb_get_freeze_opt(int argc, VALUE *argv)
VALUE kwfreeze = Qnil;
if (!keyword_ids[0]) {
- CONST_ID(keyword_ids[0], "freeze");
+ CONST_ID(keyword_ids[0], "freeze");
}
rb_scan_args(argc, argv, "0:", &opt);
if (!NIL_P(opt)) {
- rb_get_kwargs(opt, keyword_ids, 0, 1, &kwfreeze);
- if (kwfreeze != Qundef)
+ rb_get_kwargs(opt, keyword_ids, 0, 1, &kwfreeze);
+ if (!UNDEF_P(kwfreeze))
kwfreeze = obj_freeze_opt(kwfreeze);
}
return kwfreeze;
@@ -387,23 +478,20 @@ static VALUE
immutable_obj_clone(VALUE obj, VALUE kwfreeze)
{
if (kwfreeze == Qfalse)
- rb_raise(rb_eArgError, "can't unfreeze %"PRIsVALUE,
- rb_obj_class(obj));
+ rb_raise(rb_eArgError, "can't unfreeze %"PRIsVALUE,
+ rb_obj_class(obj));
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)) {
- rb_singleton_class_attached(singleton, clone);
+ if (RCLASS_SINGLETON_P(singleton)) {
+ rb_singleton_class_attached(singleton, clone);
}
init_copy(clone, obj);
@@ -411,14 +499,25 @@ mutable_obj_clone(VALUE obj, VALUE kwfreeze)
switch (kwfreeze) {
case Qnil:
rb_funcall(clone, id_init_clone, 1, obj);
- RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
+ RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
+ if (CHILLED_STRING_P(obj)) {
+ STR_CHILL_RAW(clone);
+ }
+ else if (RB_OBJ_FROZEN(obj)) {
+ rb_shape_t * next_shape = rb_shape_transition_shape_frozen(clone);
+ if (!rb_shape_obj_too_complex(clone) && next_shape->type == SHAPE_OBJ_TOO_COMPLEX) {
+ rb_evict_ivars_to_hash(clone);
+ }
+ else {
+ rb_shape_set_shape(clone, next_shape);
+ }
+ }
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);
}
@@ -427,14 +526,22 @@ mutable_obj_clone(VALUE obj, VALUE kwfreeze)
argv[1] = freeze_true_hash;
rb_funcallv_kw(clone, id_init_clone, 2, argv, RB_PASS_KEYWORDS);
RBASIC(clone)->flags |= FL_FREEZE;
- break;
+ rb_shape_t * next_shape = rb_shape_transition_shape_frozen(clone);
+ // If we're out of shapes, but we want to freeze, then we need to
+ // evacuate this clone to a hash
+ if (!rb_shape_obj_too_complex(clone) && next_shape->type == SHAPE_OBJ_TOO_COMPLEX) {
+ rb_evict_ivars_to_hash(clone);
}
- case Qfalse:
- {
+ else {
+ rb_shape_set_shape(clone, next_shape);
+ }
+ break;
+ }
+ 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);
}
@@ -443,7 +550,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");
}
@@ -451,6 +558,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)
{
@@ -458,6 +572,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
@@ -503,13 +626,10 @@ rb_obj_dup(VALUE obj)
VALUE dup;
if (special_object_p(obj)) {
- return 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);
}
/*
@@ -535,18 +655,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
@@ -555,18 +669,18 @@ rb_obj_init_copy(VALUE obj, VALUE orig)
if (obj == orig) return obj;
rb_check_frozen(obj);
if (TYPE(obj) != TYPE(orig) || rb_obj_class(obj) != rb_obj_class(orig)) {
- rb_raise(rb_eTypeError, "initialize_copy should take same class object");
+ rb_raise(rb_eTypeError, "initialize_copy should take same class object");
}
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
@@ -576,14 +690,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
@@ -627,34 +741,32 @@ rb_inspect(VALUE obj)
rb_encoding *enc = rb_default_internal_encoding();
if (enc == NULL) enc = rb_default_external_encoding();
if (!rb_enc_asciicompat(enc)) {
- if (!rb_enc_str_asciionly_p(str))
- return rb_str_escape(str);
- return str;
+ if (!rb_enc_str_asciionly_p(str))
+ return rb_str_escape(str);
+ return str;
}
if (rb_enc_get(str) != enc && !rb_enc_str_asciionly_p(str))
- return rb_str_escape(str);
+ return rb_str_escape(str);
return str;
}
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;
/* need not to show internal data */
if (CLASS_OF(value) == 0) return ST_CONTINUE;
if (!rb_is_instance_id(id)) return ST_CONTINUE;
if (RSTRING_PTR(str)[0] == '-') { /* first element */
- RSTRING_PTR(str)[0] = '#';
- rb_str_cat2(str, " ");
+ RSTRING_PTR(str)[0] = '#';
+ rb_str_cat2(str, " ");
}
else {
- rb_str_cat2(str, ", ");
+ rb_str_cat2(str, ", ");
}
- rb_str_catf(str, "%"PRIsVALUE"=%+"PRIsVALUE,
- rb_id2str(id), value);
+ rb_str_catf(str, "%"PRIsVALUE"=", rb_id2str(id));
+ rb_str_buf_append(str, rb_inspect(value));
return ST_CONTINUE;
}
@@ -663,10 +775,10 @@ static VALUE
inspect_obj(VALUE obj, VALUE str, int recur)
{
if (recur) {
- rb_str_cat2(str, " ...");
+ rb_str_cat2(str, " ...");
}
else {
- rb_ivar_foreach(obj, inspect_i, str);
+ rb_ivar_foreach(obj, inspect_i, str);
}
rb_str_cat2(str, ">");
RSTRING_PTR(str)[0] = '#';
@@ -705,14 +817,14 @@ static VALUE
rb_obj_inspect(VALUE obj)
{
if (rb_ivar_count(obj) > 0) {
- VALUE str;
- VALUE c = rb_class_name(CLASS_OF(obj));
+ VALUE str;
+ VALUE c = rb_class_name(CLASS_OF(obj));
- str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void*)obj);
- return rb_exec_recursive(inspect_obj, obj, str);
+ str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void*)obj);
+ return rb_exec_recursive(inspect_obj, obj, str);
}
else {
- return rb_any_to_s(obj);
+ return rb_any_to_s(obj);
}
}
@@ -723,10 +835,10 @@ class_or_module_required(VALUE c)
case T_MODULE:
case T_CLASS:
case T_ICLASS:
- break;
+ break;
default:
- rb_raise(rb_eTypeError, "class or module required");
+ rb_raise(rb_eTypeError, "class or module required");
}
return c;
}
@@ -757,6 +869,26 @@ rb_obj_is_instance_of(VALUE obj, VALUE c)
return RBOOL(rb_obj_class(obj) == c);
}
+// 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)
+{
+ RUBY_ASSERT(RB_TYPE_P(c, T_CLASS));
+ RUBY_ASSERT(RB_TYPE_P(cl, T_CLASS));
+
+ size_t c_depth = RCLASS_SUPERCLASS_DEPTH(c);
+ size_t cl_depth = RCLASS_SUPERCLASS_DEPTH(cl);
+ VALUE *classes = RCLASS_SUPERCLASSES(cl);
+
+ // If c's inheritance chain is longer, it cannot be an ancestor
+ // We are checking for a proper superclass so don't check if they are equal
+ if (cl_depth <= c_depth)
+ return Qfalse;
+
+ // Otherwise check that c is in cl's inheritance chain
+ return RBOOL(classes[c_depth] == c);
+}
/*
* call-seq:
@@ -791,19 +923,54 @@ rb_obj_is_kind_of(VALUE obj, VALUE c)
{
VALUE cl = CLASS_OF(obj);
+ RUBY_ASSERT(RB_TYPE_P(cl, T_CLASS));
+
+ // Fastest path: If the object's class is an exact match we know `c` is a
+ // class without checking type and can return immediately.
+ if (cl == c) return Qtrue;
+
// Note: YJIT needs this function to never allocate and never raise when
// `c` is a class or a module.
- c = class_or_module_required(c);
- return RBOOL(class_search_ancestor(cl, RCLASS_ORIGIN(c)));
+
+ if (LIKELY(RB_TYPE_P(c, T_CLASS))) {
+ // Fast path: Both are T_CLASS
+ return class_search_class_ancestor(cl, c);
+ }
+ else if (RB_TYPE_P(c, T_ICLASS)) {
+ // First check if we inherit the includer
+ // If we do we can return true immediately
+ VALUE includer = RCLASS_INCLUDER(c);
+ if (cl == includer) return Qtrue;
+
+ // Usually includer is a T_CLASS here, except when including into an
+ // already included Module.
+ // If it is a class, attempt the fast class-to-class check and return
+ // true if there is a match.
+ if (RB_TYPE_P(includer, T_CLASS) && class_search_class_ancestor(cl, includer))
+ return Qtrue;
+
+ // We don't include the ICLASS directly, so must check if we inherit
+ // the module via another include
+ return RBOOL(class_search_ancestor(cl, RCLASS_ORIGIN(c)));
+ }
+ else if (RB_TYPE_P(c, T_MODULE)) {
+ // Slow path: check each ancestor in the linked list and its method table
+ return RBOOL(class_search_ancestor(cl, RCLASS_ORIGIN(c)));
+ }
+ else {
+ rb_raise(rb_eTypeError, "class or module required");
+ UNREACHABLE_RETURN(Qfalse);
+ }
}
+
static VALUE
class_search_ancestor(VALUE cl, VALUE c)
{
while (cl) {
- if (cl == c || RCLASS_M_TBL(cl) == RCLASS_M_TBL(c))
- return cl;
- cl = RCLASS_SUPER(cl);
+ if (cl == c || RCLASS_M_TBL(cl) == RCLASS_M_TBL(c))
+ return cl;
+ cl = RCLASS_SUPER(cl);
}
return 0;
}
@@ -1005,6 +1172,28 @@ rb_class_search_ancestor(VALUE cl, VALUE c)
*/
#define rb_obj_singleton_method_undefined rb_obj_dummy1
+/* Document-method: const_added
+ *
+ * call-seq:
+ * const_added(const_name)
+ *
+ * Invoked as a callback whenever a constant is assigned on the receiver
+ *
+ * module Chatty
+ * def self.const_added(const_name)
+ * super
+ * puts "Added #{const_name.inspect}"
+ * end
+ * FOO = 1
+ * end
+ *
+ * <em>produces:</em>
+ *
+ * Added :FOO
+ *
+ */
+#define rb_obj_mod_const_added rb_obj_dummy1
+
/*
* Document-method: extended
*
@@ -1102,98 +1291,6 @@ rb_obj_dummy1(VALUE _x, VALUE _y)
/*
* call-seq:
- * obj.tainted? -> false
- *
- * Returns false. This method is deprecated and will be removed in Ruby 3.2.
- */
-
-VALUE
-rb_obj_tainted(VALUE obj)
-{
- rb_warn_deprecated_to_remove_at(3.2, "Object#tainted?", NULL);
- return Qfalse;
-}
-
-/*
- * call-seq:
- * obj.taint -> obj
- *
- * Returns object. This method is deprecated and will be removed in Ruby 3.2.
- */
-
-VALUE
-rb_obj_taint(VALUE obj)
-{
- rb_warn_deprecated_to_remove_at(3.2, "Object#taint", NULL);
- return obj;
-}
-
-
-/*
- * call-seq:
- * obj.untaint -> obj
- *
- * Returns object. This method is deprecated and will be removed in Ruby 3.2.
- */
-
-VALUE
-rb_obj_untaint(VALUE obj)
-{
- rb_warn_deprecated_to_remove_at(3.2, "Object#untaint", NULL);
- return obj;
-}
-
-/*
- * call-seq:
- * obj.untrusted? -> false
- *
- * Returns false. This method is deprecated and will be removed in Ruby 3.2.
- */
-
-VALUE
-rb_obj_untrusted(VALUE obj)
-{
- rb_warn_deprecated_to_remove_at(3.2, "Object#untrusted?", NULL);
- return Qfalse;
-}
-
-/*
- * call-seq:
- * obj.untrust -> obj
- *
- * Returns object. This method is deprecated and will be removed in Ruby 3.2.
- */
-
-VALUE
-rb_obj_untrust(VALUE obj)
-{
- rb_warn_deprecated_to_remove_at(3.2, "Object#untrust", NULL);
- return obj;
-}
-
-
-/*
- * call-seq:
- * obj.trust -> obj
- *
- * Returns object. This method is deprecated and will be removed in Ruby 3.2.
- */
-
-VALUE
-rb_obj_trust(VALUE obj)
-{
- rb_warn_deprecated_to_remove_at(3.2, "Object#trust", NULL);
- return obj;
-}
-
-void
-rb_obj_infect(VALUE victim, VALUE carrier)
-{
- rb_warn_deprecated_to_remove_at(3.2, "rb_obj_infect", NULL);
-}
-
-/*
- * call-seq:
* obj.freeze -> obj
*
* Prevents further modifications to <i>obj</i>. A
@@ -1220,10 +1317,10 @@ VALUE
rb_obj_freeze(VALUE obj)
{
if (!OBJ_FROZEN(obj)) {
- OBJ_FREEZE(obj);
- if (SPECIAL_CONST_P(obj)) {
- rb_bug("special consts should be frozen.");
- }
+ OBJ_FREEZE(obj);
+ if (SPECIAL_CONST_P(obj)) {
+ rb_bug("special consts should be frozen.");
+ }
}
return obj;
}
@@ -1238,17 +1335,47 @@ 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
+ *
+ * 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;
@@ -1257,12 +1384,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
@@ -1274,12 +1402,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
@@ -1289,10 +1418,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
@@ -1302,10 +1434,17 @@ nil_inspect(VALUE obj)
}
/*
- * call-seq:
- * nil =~ other -> nil
+ * call-seq:
+ * nil =~ object -> nil
+ *
+ * Returns +nil+.
+ *
+ * This method makes it useful to write:
+ *
+ * while gets =~ /re/
+ * # ...
+ * end
*
- * Dummy pattern matching -- always returns nil.
*/
static VALUE
@@ -1314,24 +1453,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;
@@ -1340,10 +1493,14 @@ rb_true_to_s(VALUE obj)
/*
* call-seq:
- * true & obj -> true or false
+ * 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
@@ -1354,18 +1511,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
@@ -1377,17 +1537,20 @@ 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
true_xor(VALUE obj, VALUE obj2)
{
- return RTEST(obj2)?Qfalse:Qtrue;
+ return rb_obj_not(obj2);
}
@@ -1408,22 +1571,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)
{
@@ -1432,24 +1600,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
*
- * Exclusive Or---If <i>obj</i> is <code>nil</code> or
- * <code>false</code>, returns <code>false</code>; otherwise, returns
- * <code>true</code>.
+ * Returns +false+ if +object+ is +nil+ or +false+, +true+ otherwise:
+ *
+ * nil ^ nil # => false
+ * nil ^ false # => false
+ * nil ^ Object.new # => true
*
*/
@@ -1457,9 +1631,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
@@ -1479,33 +1654,12 @@ rb_true(VALUE obj)
*/
-MJIT_FUNC_EXPORTED VALUE
+VALUE
rb_false(VALUE obj)
{
return Qfalse;
}
-
-/*
- * call-seq:
- * obj =~ other -> nil
- *
- * This method is deprecated.
- *
- * This is not only useless but also troublesome because it may hide a
- * type error.
- */
-
-static VALUE
-rb_obj_match(VALUE obj1, VALUE obj2)
-{
- if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) {
- rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "deprecated Object#=~ is called on %"PRIsVALUE
- "; it always returns nil", rb_obj_class(obj1));
- }
- return Qnil;
-}
-
/*
* call-seq:
* obj !~ other -> true or false
@@ -1518,7 +1672,7 @@ static VALUE
rb_obj_not_match(VALUE obj1, VALUE obj2)
{
VALUE result = rb_funcall(obj1, id_match, 1, obj2);
- return RTEST(result) ? Qfalse : Qtrue;
+ return rb_obj_not(result);
}
@@ -1544,7 +1698,7 @@ static VALUE
rb_obj_cmp(VALUE obj1, VALUE obj2)
{
if (rb_equal(obj1, obj2))
- return INT2FIX(0);
+ return INT2FIX(0);
return Qnil;
}
@@ -1585,37 +1739,37 @@ 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)) {
- VALUE s = rb_usascii_str_new2("#<Class:");
- VALUE v = rb_ivar_get(klass, id__attached__);
+ if (RCLASS_SINGLETON_P(klass)) {
+ VALUE s = rb_usascii_str_new2("#<Class:");
+ VALUE v = RCLASS_ATTACHED_OBJECT(klass);
- if (CLASS_OR_MODULE_P(v)) {
- rb_str_append(s, rb_inspect(v));
- }
- else {
- rb_str_append(s, rb_any_to_s(v));
- }
- rb_str_cat2(s, ">");
+ if (CLASS_OR_MODULE_P(v)) {
+ rb_str_append(s, rb_inspect(v));
+ }
+ else {
+ rb_str_append(s, rb_any_to_s(v));
+ }
+ rb_str_cat2(s, ">");
- return s;
+ return s;
}
refined_class = rb_refinement_module_get_refined_class(klass);
if (!NIL_P(refined_class)) {
- VALUE s = rb_usascii_str_new2("#<refinement:");
-
- rb_str_concat(s, rb_inspect(refined_class));
- rb_str_cat2(s, "@");
- CONST_ID(id_defined_at, "__defined_at__");
- defined_at = rb_attr_get(klass, id_defined_at);
- rb_str_concat(s, rb_inspect(defined_at));
- rb_str_cat2(s, ">");
- return s;
+ VALUE s = rb_usascii_str_new2("#<refinement:");
+
+ rb_str_concat(s, rb_inspect(refined_class));
+ rb_str_cat2(s, "@");
+ CONST_ID(id_defined_at, "__defined_at__");
+ defined_at = rb_attr_get(klass, id_defined_at);
+ rb_str_concat(s, rb_inspect(defined_at));
+ rb_str_cat2(s, ">");
+ return s;
}
return rb_class_name(klass);
}
@@ -1667,17 +1821,41 @@ VALUE
rb_class_inherited_p(VALUE mod, VALUE arg)
{
if (mod == arg) return Qtrue;
- if (!CLASS_OR_MODULE_P(arg) && !RB_TYPE_P(arg, T_ICLASS)) {
- rb_raise(rb_eTypeError, "compared with non class/module");
- }
- if (class_search_ancestor(mod, RCLASS_ORIGIN(arg))) {
- return Qtrue;
+
+ if (RB_TYPE_P(arg, T_CLASS) && RB_TYPE_P(mod, T_CLASS)) {
+ // comparison between classes
+ size_t mod_depth = RCLASS_SUPERCLASS_DEPTH(mod);
+ size_t arg_depth = RCLASS_SUPERCLASS_DEPTH(arg);
+ if (arg_depth < mod_depth) {
+ // check if mod < arg
+ return RCLASS_SUPERCLASSES(mod)[arg_depth] == arg ?
+ Qtrue :
+ Qnil;
+ }
+ else if (arg_depth > mod_depth) {
+ // check if mod > arg
+ return RCLASS_SUPERCLASSES(arg)[mod_depth] == mod ?
+ Qfalse :
+ Qnil;
+ }
+ else {
+ // Depths match, and we know they aren't equal: no relation
+ return Qnil;
+ }
}
- /* not mod < arg; check if mod > arg */
- if (class_search_ancestor(arg, mod)) {
- return Qfalse;
+ else {
+ if (!CLASS_OR_MODULE_P(arg) && !RB_TYPE_P(arg, T_ICLASS)) {
+ rb_raise(rb_eTypeError, "compared with non class/module");
+ }
+ if (class_search_ancestor(mod, RCLASS_ORIGIN(arg))) {
+ return Qtrue;
+ }
+ /* not mod < arg; check if mod > arg */
+ if (class_search_ancestor(arg, mod)) {
+ return Qfalse;
+ }
+ return Qnil;
}
- return Qnil;
}
/*
@@ -1685,7 +1863,9 @@ rb_class_inherited_p(VALUE mod, VALUE arg)
* mod < other -> true, false, or nil
*
* Returns true if <i>mod</i> is a subclass of <i>other</i>. Returns
- * <code>nil</code> if there's no relationship between the two.
+ * <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".)
*
@@ -1715,7 +1895,7 @@ static VALUE
rb_mod_ge(VALUE mod, VALUE arg)
{
if (!CLASS_OR_MODULE_P(arg)) {
- rb_raise(rb_eTypeError, "compared with non class/module");
+ rb_raise(rb_eTypeError, "compared with non class/module");
}
return rb_class_inherited_p(arg, mod);
@@ -1726,7 +1906,9 @@ rb_mod_ge(VALUE mod, VALUE arg)
* mod > other -> true, false, or nil
*
* Returns true if <i>mod</i> is an ancestor of <i>other</i>. Returns
- * <code>nil</code> if there's no relationship between the two.
+ * <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".)
*
@@ -1758,13 +1940,13 @@ rb_mod_cmp(VALUE mod, VALUE arg)
if (mod == arg) return INT2FIX(0);
if (!CLASS_OR_MODULE_P(arg)) {
- return Qnil;
+ return Qnil;
}
cmp = rb_class_inherited_p(mod, arg);
if (NIL_P(cmp)) return Qnil;
if (cmp) {
- return INT2FIX(-1);
+ return INT2FIX(-1);
}
return INT2FIX(1);
}
@@ -1800,7 +1982,6 @@ static VALUE rb_mod_initialize_exec(VALUE module);
static VALUE
rb_mod_initialize(VALUE module)
{
- rb_module_check_initializable(module);
return rb_mod_initialize_exec(module);
}
@@ -1808,7 +1989,7 @@ static VALUE
rb_mod_initialize_exec(VALUE module)
{
if (rb_block_given_p()) {
- rb_mod_module_exec(1, &module, module);
+ rb_mod_module_exec(1, &module, module);
}
return Qnil;
}
@@ -1861,17 +2042,17 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass)
VALUE super;
if (RCLASS_SUPER(klass) != 0 || klass == rb_cBasicObject) {
- rb_raise(rb_eTypeError, "already initialized class");
+ rb_raise(rb_eTypeError, "already initialized class");
}
if (rb_check_arity(argc, 0, 1) == 0) {
- super = rb_cObject;
+ super = rb_cObject;
}
else {
super = argv[0];
- rb_check_inheritable(super);
- if (super != rb_cBasicObject && !RCLASS_SUPER(super)) {
- rb_raise(rb_eTypeError, "can't inherit uninitialized class");
- }
+ rb_check_inheritable(super);
+ if (super != rb_cBasicObject && !RCLASS_SUPER(super)) {
+ rb_raise(rb_eTypeError, "can't inherit uninitialized class");
+ }
}
RCLASS_SET_SUPER(klass, super);
rb_make_metaclass(klass, RBASIC(super)->klass);
@@ -1886,7 +2067,7 @@ void
rb_undefined_alloc(VALUE klass)
{
rb_raise(rb_eTypeError, "allocator undefined for %"PRIsVALUE,
- klass);
+ klass);
}
static rb_alloc_func_t class_get_alloc_func(VALUE klass);
@@ -1938,14 +2119,14 @@ class_get_alloc_func(VALUE klass)
rb_alloc_func_t allocator;
if (RCLASS_SUPER(klass) == 0 && klass != rb_cBasicObject) {
- rb_raise(rb_eTypeError, "can't instantiate uninitialized class");
+ rb_raise(rb_eTypeError, "can't instantiate uninitialized class");
}
- if (FL_TEST(klass, FL_SINGLETON)) {
- rb_raise(rb_eTypeError, "can't create instance of singleton class");
+ if (RCLASS_SINGLETON_P(klass)) {
+ rb_raise(rb_eTypeError, "can't create instance of singleton class");
}
allocator = rb_get_alloc_func(klass);
if (!allocator) {
- rb_undefined_alloc(klass);
+ rb_undefined_alloc(klass);
}
return allocator;
}
@@ -1960,7 +2141,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");
+ rb_raise(rb_eTypeError, "wrong instance allocation");
}
return obj;
}
@@ -2009,13 +2190,7 @@ rb_class_new_instance_kw(int argc, const VALUE *argv, VALUE klass, int kw_splat)
VALUE
rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
{
- VALUE obj;
- Check_Type(klass, T_CLASS);
-
- obj = rb_class_alloc(klass);
- rb_obj_call_init_kw(obj, argc, argv, RB_NO_KEYWORDS);
-
- return obj;
+ return rb_class_new_instance_kw(argc, argv, klass, RB_NO_KEYWORDS);
}
/**
@@ -2036,31 +2211,35 @@ 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
*++
*/
VALUE
rb_class_superclass(VALUE klass)
{
+ RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS));
+
VALUE super = RCLASS_SUPER(klass);
if (!super) {
- if (klass == rb_cBasicObject) return Qnil;
- rb_raise(rb_eTypeError, "uninitialized class");
+ if (klass == rb_cBasicObject) return Qnil;
+ rb_raise(rb_eTypeError, "uninitialized class");
}
- while (RB_TYPE_P(super, T_ICLASS)) {
- super = RCLASS_SUPER(super);
+
+ if (!RCLASS_SUPERCLASS_DEPTH(klass)) {
+ return Qnil;
}
- if (!super) {
- return Qnil;
+ else {
+ super = RCLASS_SUPERCLASSES(klass)[RCLASS_SUPERCLASS_DEPTH(klass) - 1];
+ RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS));
+ return super;
}
- return super;
}
VALUE
@@ -2069,10 +2248,10 @@ rb_class_get_superclass(VALUE klass)
return RCLASS(klass)->super;
}
-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 */
@@ -2082,15 +2261,15 @@ static const char bad_attr_name[] = "invalid attribute name `%1$s'";
check_setter_id(obj, &(name), rb_is_##type##_id, rb_is_##type##_name, message, strlen(message))
static ID
check_setter_id(VALUE obj, VALUE *pname,
- int (*valid_id_p)(ID), int (*valid_name_p)(VALUE),
- const char *message, size_t message_len)
+ int (*valid_id_p)(ID), int (*valid_name_p)(VALUE),
+ const char *message, size_t message_len)
{
ID id = rb_check_id(pname);
VALUE name = *pname;
if (id ? !valid_id_p(id) : !valid_name_p(name)) {
- rb_name_err_raise_str(rb_fstring_new(message, message_len),
- obj, name);
+ rb_name_err_raise_str(rb_fstring_new(message, message_len),
+ obj, name);
}
return id;
}
@@ -2136,9 +2315,9 @@ rb_mod_attr_reader(int argc, VALUE *argv, VALUE klass)
VALUE names = rb_ary_new2(argc);
for (i=0; i<argc; i++) {
- ID id = id_for_attr(klass, argv[i]);
- rb_attr(klass, id, TRUE, FALSE, TRUE);
- rb_ary_push(names, ID2SYM(id));
+ ID id = id_for_attr(klass, argv[i]);
+ rb_attr(klass, id, TRUE, FALSE, TRUE);
+ rb_ary_push(names, ID2SYM(id));
}
return names;
}
@@ -2162,14 +2341,14 @@ VALUE
rb_mod_attr(int argc, VALUE *argv, VALUE klass)
{
if (argc == 2 && (argv[1] == Qtrue || argv[1] == Qfalse)) {
- ID id = id_for_attr(klass, argv[0]);
- VALUE names = rb_ary_new();
-
- rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, "optional boolean argument is obsoleted");
- rb_attr(klass, id, 1, RTEST(argv[1]), TRUE);
- rb_ary_push(names, ID2SYM(id));
- if (argv[1] == Qtrue) rb_ary_push(names, ID2SYM(rb_id_attrset(id)));
- return names;
+ ID id = id_for_attr(klass, argv[0]);
+ VALUE names = rb_ary_new();
+
+ rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, "optional boolean argument is obsoleted");
+ rb_attr(klass, id, 1, RTEST(argv[1]), TRUE);
+ rb_ary_push(names, ID2SYM(id));
+ if (argv[1] == Qtrue) rb_ary_push(names, ID2SYM(rb_id_attrset(id)));
+ return names;
}
return rb_mod_attr_reader(argc, argv, klass);
}
@@ -2192,9 +2371,9 @@ rb_mod_attr_writer(int argc, VALUE *argv, VALUE klass)
VALUE names = rb_ary_new2(argc);
for (i=0; i<argc; i++) {
- ID id = id_for_attr(klass, argv[i]);
- rb_attr(klass, id, FALSE, TRUE, TRUE);
- rb_ary_push(names, ID2SYM(rb_id_attrset(id)));
+ ID id = id_for_attr(klass, argv[i]);
+ rb_attr(klass, id, FALSE, TRUE, TRUE);
+ rb_ary_push(names, ID2SYM(rb_id_attrset(id)));
}
return names;
}
@@ -2224,11 +2403,11 @@ rb_mod_attr_accessor(int argc, VALUE *argv, VALUE klass)
VALUE names = rb_ary_new2(argc * 2);
for (i=0; i<argc; i++) {
- ID id = id_for_attr(klass, argv[i]);
+ ID id = id_for_attr(klass, argv[i]);
- rb_attr(klass, id, TRUE, TRUE, TRUE);
- rb_ary_push(names, ID2SYM(id));
- rb_ary_push(names, ID2SYM(rb_id_attrset(id)));
+ rb_attr(klass, id, TRUE, TRUE, TRUE);
+ rb_ary_push(names, ID2SYM(id));
+ rb_ary_push(names, ID2SYM(rb_id_attrset(id)));
}
return names;
}
@@ -2286,17 +2465,17 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
recur = (argc == 1) ? Qtrue : argv[1];
if (SYMBOL_P(name)) {
- if (!rb_is_const_sym(name)) goto wrong_name;
- id = rb_check_id(&name);
- if (!id) return rb_const_missing(mod, name);
- return RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id);
+ if (!rb_is_const_sym(name)) goto wrong_name;
+ id = rb_check_id(&name);
+ if (!id) return rb_const_missing(mod, name);
+ return RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id);
}
path = StringValuePtr(name);
enc = rb_enc_get(name);
if (!rb_enc_asciicompat(enc)) {
- rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
+ rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
}
pbeg = p = path;
@@ -2307,53 +2486,53 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
}
if (p + 2 < pend && p[0] == ':' && p[1] == ':') {
- mod = rb_cObject;
- p += 2;
- pbeg = p;
+ mod = rb_cObject;
+ p += 2;
+ pbeg = p;
}
while (p < pend) {
- VALUE part;
- long len, beglen;
-
- while (p < pend && *p != ':') p++;
-
- if (pbeg == p) goto wrong_name;
-
- id = rb_check_id_cstr(pbeg, len = p-pbeg, enc);
- beglen = pbeg-path;
-
- if (p < pend && p[0] == ':') {
- if (p + 2 >= pend || p[1] != ':') goto wrong_name;
- p += 2;
- pbeg = p;
- }
-
- if (!RB_TYPE_P(mod, T_MODULE) && !RB_TYPE_P(mod, T_CLASS)) {
- rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
- QUOTE(name));
- }
-
- if (!id) {
- part = rb_str_subseq(name, beglen, len);
- OBJ_FREEZE(part);
- if (!rb_is_const_name(part)) {
- name = part;
- goto wrong_name;
- }
- else if (!rb_method_basic_definition_p(CLASS_OF(mod), id_const_missing)) {
- part = rb_str_intern(part);
- mod = rb_const_missing(mod, part);
- continue;
- }
- else {
- rb_mod_const_missing(mod, part);
- }
- }
- if (!rb_is_const_id(id)) {
- name = ID2SYM(id);
- goto wrong_name;
- }
+ VALUE part;
+ long len, beglen;
+
+ while (p < pend && *p != ':') p++;
+
+ if (pbeg == p) goto wrong_name;
+
+ id = rb_check_id_cstr(pbeg, len = p-pbeg, enc);
+ beglen = pbeg-path;
+
+ if (p < pend && p[0] == ':') {
+ if (p + 2 >= pend || p[1] != ':') goto wrong_name;
+ p += 2;
+ pbeg = p;
+ }
+
+ if (!RB_TYPE_P(mod, T_MODULE) && !RB_TYPE_P(mod, T_CLASS)) {
+ rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
+ QUOTE(name));
+ }
+
+ if (!id) {
+ part = rb_str_subseq(name, beglen, len);
+ OBJ_FREEZE(part);
+ if (!rb_is_const_name(part)) {
+ name = part;
+ goto wrong_name;
+ }
+ else if (!rb_method_basic_definition_p(CLASS_OF(mod), id_const_missing)) {
+ part = rb_str_intern(part);
+ mod = rb_const_missing(mod, part);
+ continue;
+ }
+ else {
+ rb_mod_const_missing(mod, part);
+ }
+ }
+ if (!rb_is_const_id(id)) {
+ name = ID2SYM(id);
+ goto wrong_name;
+ }
#if 0
mod = rb_const_get_0(mod, id, beglen > 0 || !RTEST(recur), RTEST(recur), FALSE);
#else
@@ -2459,17 +2638,17 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
recur = (argc == 1) ? Qtrue : argv[1];
if (SYMBOL_P(name)) {
- if (!rb_is_const_sym(name)) goto wrong_name;
- id = rb_check_id(&name);
- if (!id) return Qfalse;
- return RTEST(recur) ? rb_const_defined(mod, id) : rb_const_defined_at(mod, id);
+ if (!rb_is_const_sym(name)) goto wrong_name;
+ id = rb_check_id(&name);
+ if (!id) return Qfalse;
+ return RTEST(recur) ? rb_const_defined(mod, id) : rb_const_defined_at(mod, id);
}
path = StringValuePtr(name);
enc = rb_enc_get(name);
if (!rb_enc_asciicompat(enc)) {
- rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
+ rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
}
pbeg = p = path;
@@ -2480,54 +2659,54 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
}
if (p + 2 < pend && p[0] == ':' && p[1] == ':') {
- mod = rb_cObject;
- p += 2;
- pbeg = p;
+ mod = rb_cObject;
+ p += 2;
+ pbeg = p;
}
while (p < pend) {
- VALUE part;
- long len, beglen;
-
- while (p < pend && *p != ':') p++;
-
- if (pbeg == p) goto wrong_name;
-
- id = rb_check_id_cstr(pbeg, len = p-pbeg, enc);
- beglen = pbeg-path;
-
- if (p < pend && p[0] == ':') {
- if (p + 2 >= pend || p[1] != ':') goto wrong_name;
- p += 2;
- pbeg = p;
- }
-
- if (!id) {
- part = rb_str_subseq(name, beglen, len);
- OBJ_FREEZE(part);
- if (!rb_is_const_name(part)) {
- name = part;
- goto wrong_name;
- }
- else {
- return Qfalse;
- }
- }
- if (!rb_is_const_id(id)) {
- name = ID2SYM(id);
- goto wrong_name;
- }
+ VALUE part;
+ long len, beglen;
+
+ while (p < pend && *p != ':') p++;
+
+ if (pbeg == p) goto wrong_name;
+
+ id = rb_check_id_cstr(pbeg, len = p-pbeg, enc);
+ beglen = pbeg-path;
+
+ if (p < pend && p[0] == ':') {
+ if (p + 2 >= pend || p[1] != ':') goto wrong_name;
+ p += 2;
+ pbeg = p;
+ }
+
+ if (!id) {
+ part = rb_str_subseq(name, beglen, len);
+ OBJ_FREEZE(part);
+ if (!rb_is_const_name(part)) {
+ name = part;
+ goto wrong_name;
+ }
+ else {
+ return Qfalse;
+ }
+ }
+ if (!rb_is_const_id(id)) {
+ name = ID2SYM(id);
+ goto wrong_name;
+ }
#if 0
mod = rb_const_search(mod, id, beglen > 0 || !RTEST(recur), RTEST(recur), FALSE);
- if (mod == Qundef) return Qfalse;
+ if (UNDEF_P(mod)) return Qfalse;
#else
if (!RTEST(recur)) {
- if (!rb_const_defined_at(mod, id))
- return Qfalse;
+ if (!rb_const_defined_at(mod, id))
+ return Qfalse;
if (p == pend) return Qtrue;
- mod = rb_const_get_at(mod, id);
- }
+ mod = rb_const_get_at(mod, id);
+ }
else if (beglen == 0) {
if (!rb_const_defined(mod, id))
return Qfalse;
@@ -2542,10 +2721,10 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
}
#endif
- if (p < pend && !RB_TYPE_P(mod, T_MODULE) && !RB_TYPE_P(mod, T_CLASS)) {
- rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
- QUOTE(name));
- }
+ if (p < pend && !RB_TYPE_P(mod, T_MODULE) && !RB_TYPE_P(mod, T_CLASS)) {
+ rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
+ QUOTE(name));
+ }
}
return Qtrue;
@@ -2736,7 +2915,7 @@ rb_obj_ivar_get(VALUE obj, VALUE iv)
ID id = id_for_var(obj, iv, instance);
if (!id) {
- return Qnil;
+ return Qnil;
}
return rb_ivar_get(obj, id);
}
@@ -2765,7 +2944,7 @@ rb_obj_ivar_get(VALUE obj, VALUE iv)
*/
static VALUE
-rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val)
+rb_obj_ivar_set_m(VALUE obj, VALUE iv, VALUE val)
{
ID id = id_for_var(obj, iv, instance);
if (!id) id = rb_intern_str(iv);
@@ -2798,7 +2977,7 @@ rb_obj_ivar_defined(VALUE obj, VALUE iv)
ID id = id_for_var(obj, iv, instance);
if (!id) {
- return Qfalse;
+ return Qfalse;
}
return rb_ivar_defined(obj, id);
}
@@ -2825,8 +3004,8 @@ rb_mod_cvar_get(VALUE obj, VALUE iv)
ID id = id_for_var(obj, iv, class);
if (!id) {
- rb_name_err_raise("uninitialized class variable %1$s in %2$s",
- obj, iv);
+ rb_name_err_raise("uninitialized class variable %1$s in %2$s",
+ obj, iv);
}
return rb_cvar_get(obj, id);
}
@@ -2882,7 +3061,7 @@ rb_mod_cvar_defined(VALUE obj, VALUE iv)
ID id = id_for_var(obj, iv, class);
if (!id) {
- return Qfalse;
+ return Qfalse;
}
return rb_cvar_defined(obj, id);
}
@@ -2903,7 +3082,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 */
@@ -2922,6 +3101,7 @@ static const struct conv_method_tbl {
M(a),
M(s),
M(i),
+ M(f),
M(r),
#undef M
};
@@ -2933,14 +3113,14 @@ conv_method_index(const char *method)
static const char prefix[] = "to_";
if (strncmp(prefix, method, sizeof(prefix)-1) == 0) {
- const char *const meth = &method[sizeof(prefix)-1];
- int i;
- for (i=0; i < numberof(conv_method_names); i++) {
- if (conv_method_names[i].method[0] == meth[0] &&
- strcmp(conv_method_names[i].method, meth) == 0) {
- return i;
- }
- }
+ const char *const meth = &method[sizeof(prefix)-1];
+ int i;
+ for (i=0; i < numberof(conv_method_names); i++) {
+ if (conv_method_names[i].method[0] == meth[0] &&
+ strcmp(conv_method_names[i].method, meth) == 0) {
+ return i;
+ }
+ }
}
return numberof(conv_method_names);
}
@@ -2949,23 +3129,23 @@ static VALUE
convert_type_with_id(VALUE val, const char *tname, ID method, int raise, int index)
{
VALUE r = rb_check_funcall(val, method, 0, 0);
- if (r == Qundef) {
- 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);
- }
- return Qnil;
+ 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);
+ }
+ return Qnil;
}
return r;
}
@@ -2975,7 +3155,7 @@ convert_type(VALUE val, const char *tname, const char *method, int raise)
{
int i = conv_method_index(method);
ID m = i < numberof(conv_method_names) ?
- conv_method_names[i].id : rb_intern(method);
+ conv_method_names[i].id : rb_intern(method);
return convert_type_with_id(val, tname, m, raise, i);
}
@@ -2986,8 +3166,8 @@ conversion_mismatch(VALUE val, const char *tname, const char *method, VALUE resu
{
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));
+ "can't convert %"PRIsVALUE" to %s (%"PRIsVALUE"#%s gives %"PRIsVALUE")",
+ cname, tname, cname, method, rb_obj_class(result));
}
VALUE
@@ -2998,7 +3178,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);
+ conversion_mismatch(val, tname, method, v);
}
return v;
}
@@ -3012,7 +3192,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);
+ conversion_mismatch(val, tname, RSTRING_PTR(rb_id2str(method)), v);
}
return v;
}
@@ -3027,13 +3207,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);
+ conversion_mismatch(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;
@@ -3043,7 +3223,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);
+ conversion_mismatch(val, tname, RSTRING_PTR(rb_id2str(method)), v);
}
return v;
}
@@ -3056,14 +3236,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);
}
+ GET_EC()->cfp = current_cfp;
return v;
}
#define rb_to_integer(val, method, mid) \
@@ -3144,6 +3332,9 @@ rb_convert_to_integer(VALUE val, int base, int raise_exception)
tmp = rb_protect(rb_check_to_int, val, NULL);
if (RB_INTEGER_TYPE_P(tmp)) return tmp;
rb_set_errinfo(Qnil);
+ if (!NIL_P(tmp = rb_check_string_type(val))) {
+ return rb_str_convert_to_inum(tmp, base, TRUE, raise_exception);
+ }
if (!raise_exception) {
VALUE result = rb_protect(rb_check_to_i, val, NULL);
@@ -3167,16 +3358,22 @@ rb_check_integer_type(VALUE val)
}
int
-rb_bool_expected(VALUE obj, const char *flagname)
+rb_bool_expected(VALUE obj, const char *flagname, int raise)
{
switch (obj) {
- case Qtrue: case Qfalse:
- break;
- default:
- rb_raise(rb_eArgError, "expected true or false as %s: %+"PRIsVALUE,
- flagname, obj);
+ case Qtrue:
+ return TRUE;
+ case Qfalse:
+ return FALSE;
+ default: {
+ static const char message[] = "expected true or false as %s: %+"PRIsVALUE;
+ if (raise) {
+ rb_raise(rb_eArgError, message, flagname, obj);
+ }
+ rb_warning(message, flagname, obj);
+ return !NIL_P(obj);
+ }
}
- return obj != Qfalse;
}
int
@@ -3185,71 +3382,21 @@ rb_opts_exception_p(VALUE opts, int default_value)
static const ID kwds[1] = {idException};
VALUE exception;
if (rb_get_kwargs(opts, kwds, 0, 1, &exception))
- return rb_bool_expected(exception, "exception");
+ return rb_bool_expected(exception, "exception", TRUE);
return default_value;
}
-#define opts_exception_p(opts) rb_opts_exception_p((opts), TRUE)
-
-/*
- * call-seq:
- * Integer(arg, base=0, exception: true) -> integer or nil
- *
- * Converts <i>arg</i> to an Integer.
- * Numeric types are converted directly (with floating point numbers
- * being truncated). <i>base</i> (0, or between 2 and 36) is a base for
- * integer string representation. If <i>arg</i> is a String,
- * when <i>base</i> is omitted or equals zero, radix indicators
- * (<code>0</code>, <code>0b</code>, and <code>0x</code>) are honored.
- * In any case, strings should consist only of one or more digits, except
- * for that a sign, one underscore between two digits, and leading/trailing
- * spaces are optional. This behavior is different from that of
- * String#to_i. Non string values will be converted by first
- * trying <code>to_int</code>, then <code>to_i</code>.
- *
- * Passing <code>nil</code> raises a TypeError, while passing a String that
- * does not conform with numeric representation raises an ArgumentError.
- * This behavior can be altered by passing <code>exception: false</code>,
- * in this case a not convertible value will return <code>nil</code>.
- *
- * Integer(123.999) #=> 123
- * Integer("0x1a") #=> 26
- * Integer(Time.new) #=> 1204973019
- * Integer("0930", 10) #=> 930
- * Integer("111", 2) #=> 7
- * Integer(" +1_0 ") #=> 10
- * Integer(nil) #=> TypeError: can't convert nil into Integer
- * Integer("x") #=> ArgumentError: invalid value for Integer(): "x"
- *
- * Integer("x", exception: false) #=> nil
- *
- */
-
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;
-
- 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];
+ return rb_convert_to_integer(arg, 0, TRUE);
+}
- return rb_convert_to_integer(arg, base, opts_exception_p(opts));
+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);
}
static double
@@ -3386,24 +3533,24 @@ rb_str_to_dbl_raise(VALUE str, int badcheck, int raise, int *error)
s = RSTRING_PTR(str);
len = RSTRING_LEN(str);
if (s) {
- if (badcheck && memchr(s, '\0', len)) {
+ if (badcheck && memchr(s, '\0', len)) {
if (raise)
rb_raise(rb_eArgError, "string for Float contains null byte");
else {
if (error) *error = 1;
return 0.0;
}
- }
- if (s[len]) { /* no sentinel somehow */
- char *p = ALLOCV(v, (size_t)len + 1);
- MEMCPY(p, s, char, len);
- p[len] = '\0';
- s = p;
- }
+ }
+ if (s[len]) { /* no sentinel somehow */
+ char *p = ALLOCV(v, (size_t)len + 1);
+ MEMCPY(p, s, char, len);
+ p[len] = '\0';
+ s = p;
+ }
}
ret = rb_cstr_to_dbl_raise(s, badcheck, raise, error);
if (v)
- ALLOCV_END(v);
+ ALLOCV_END(v);
return ret;
}
@@ -3435,11 +3582,11 @@ rat2dbl_without_to_f(VALUE x)
#define special_const_to_float(val, pre, post) \
switch (val) { \
case Qnil: \
- rb_raise_static(rb_eTypeError, pre "nil" post); \
+ rb_raise_static(rb_eTypeError, pre "nil" post); \
case Qtrue: \
- rb_raise_static(rb_eTypeError, pre "true" post); \
+ rb_raise_static(rb_eTypeError, pre "true" post); \
case Qfalse: \
- rb_raise_static(rb_eTypeError, pre "false" post); \
+ rb_raise_static(rb_eTypeError, pre "false" post); \
}
/*! \endcond */
@@ -3460,31 +3607,31 @@ to_float(VALUE *valp, int raise_exception)
{
VALUE val = *valp;
if (SPECIAL_CONST_P(val)) {
- if (FIXNUM_P(val)) {
- *valp = DBL2NUM(fix2dbl_without_to_f(val));
- return T_FLOAT;
- }
- else if (FLONUM_P(val)) {
- return T_FLOAT;
- }
- else if (raise_exception) {
- conversion_to_float(val);
- }
+ if (FIXNUM_P(val)) {
+ *valp = DBL2NUM(fix2dbl_without_to_f(val));
+ return T_FLOAT;
+ }
+ else if (FLONUM_P(val)) {
+ return T_FLOAT;
+ }
+ else if (raise_exception) {
+ conversion_to_float(val);
+ }
}
else {
- int type = BUILTIN_TYPE(val);
- switch (type) {
- case T_FLOAT:
- return T_FLOAT;
- case T_BIGNUM:
- *valp = DBL2NUM(big2dbl_without_to_f(val));
- return T_FLOAT;
- case T_RATIONAL:
- *valp = DBL2NUM(rat2dbl_without_to_f(val));
- return T_FLOAT;
- case T_STRING:
- return T_STRING;
- }
+ int type = BUILTIN_TYPE(val);
+ switch (type) {
+ case T_FLOAT:
+ return T_FLOAT;
+ case T_BIGNUM:
+ *valp = DBL2NUM(big2dbl_without_to_f(val));
+ return T_FLOAT;
+ case T_RATIONAL:
+ *valp = DBL2NUM(rat2dbl_without_to_f(val));
+ return T_FLOAT;
+ case T_STRING:
+ return T_STRING;
+ }
}
return T_NONE;
}
@@ -3500,7 +3647,7 @@ rb_convert_to_float(VALUE val, int raise_exception)
{
switch (to_float(&val, raise_exception)) {
case T_FLOAT:
- return val;
+ return val;
case T_STRING:
if (!raise_exception) {
int e = 0;
@@ -3540,7 +3687,7 @@ rb_f_float1(rb_execution_context_t *ec, VALUE obj, VALUE arg)
static VALUE
rb_f_float(rb_execution_context_t *ec, VALUE obj, VALUE arg, VALUE opts)
{
- int exception = rb_bool_expected(opts, "exception");
+ int exception = rb_bool_expected(opts, "exception", TRUE);
return rb_convert_to_float(arg, exception);
}
@@ -3548,8 +3695,8 @@ 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_raise(rb_eTypeError, "can't convert %"PRIsVALUE" into Float",
+ rb_obj_class(val));
}
return rb_convert_type_with_id(val, T_FLOAT, "Float", id_to_f);
}
@@ -3559,7 +3706,7 @@ rb_to_float(VALUE val)
{
switch (to_float(&val, TRUE)) {
case T_FLOAT:
- return val;
+ return val;
}
return numeric_to_float(val);
}
@@ -3569,7 +3716,7 @@ rb_check_to_float(VALUE val)
{
if (RB_FLOAT_TYPE_P(val)) return val;
if (!rb_obj_is_kind_of(val, rb_cNumeric)) {
- return Qnil;
+ return Qnil;
}
return rb_check_convert_type_with_id(val, T_FLOAT, "Float", id_to_f);
}
@@ -3585,32 +3732,32 @@ double
rb_num_to_dbl(VALUE val)
{
if (SPECIAL_CONST_P(val)) {
- if (FIXNUM_P(val)) {
- if (basic_to_f_p(rb_cInteger))
- return fix2dbl_without_to_f(val);
- }
- else if (FLONUM_P(val)) {
- return rb_float_flonum_value(val);
- }
- else {
- conversion_to_float(val);
- }
+ if (FIXNUM_P(val)) {
+ if (basic_to_f_p(rb_cInteger))
+ return fix2dbl_without_to_f(val);
+ }
+ else if (FLONUM_P(val)) {
+ return rb_float_flonum_value(val);
+ }
+ else {
+ conversion_to_float(val);
+ }
}
else {
- switch (BUILTIN_TYPE(val)) {
- case T_FLOAT:
- return rb_float_noflonum_value(val);
- case T_BIGNUM:
- if (basic_to_f_p(rb_cInteger))
- return big2dbl_without_to_f(val);
- break;
- case T_RATIONAL:
- if (basic_to_f_p(rb_cRational))
- return rat2dbl_without_to_f(val);
- break;
+ switch (BUILTIN_TYPE(val)) {
+ case T_FLOAT:
+ return rb_float_noflonum_value(val);
+ case T_BIGNUM:
+ if (basic_to_f_p(rb_cInteger))
+ return big2dbl_without_to_f(val);
+ break;
+ case T_RATIONAL:
+ if (basic_to_f_p(rb_cRational))
+ return rat2dbl_without_to_f(val);
+ break;
default:
- break;
- }
+ break;
+ }
}
val = numeric_to_float(val);
return RFLOAT_VALUE(val);
@@ -3620,29 +3767,29 @@ double
rb_num2dbl(VALUE val)
{
if (SPECIAL_CONST_P(val)) {
- if (FIXNUM_P(val)) {
- return fix2dbl_without_to_f(val);
- }
- else if (FLONUM_P(val)) {
- return rb_float_flonum_value(val);
- }
- else {
- implicit_conversion_to_float(val);
- }
+ if (FIXNUM_P(val)) {
+ return fix2dbl_without_to_f(val);
+ }
+ else if (FLONUM_P(val)) {
+ return rb_float_flonum_value(val);
+ }
+ else {
+ implicit_conversion_to_float(val);
+ }
}
else {
- switch (BUILTIN_TYPE(val)) {
- case T_FLOAT:
- return rb_float_noflonum_value(val);
- case T_BIGNUM:
- return big2dbl_without_to_f(val);
- case T_RATIONAL:
- return rat2dbl_without_to_f(val);
- case T_STRING:
- rb_raise(rb_eTypeError, "no implicit conversion to float from string");
+ switch (BUILTIN_TYPE(val)) {
+ case T_FLOAT:
+ return rb_float_noflonum_value(val);
+ case T_BIGNUM:
+ return big2dbl_without_to_f(val);
+ case T_RATIONAL:
+ return rat2dbl_without_to_f(val);
+ case T_STRING:
+ rb_raise(rb_eTypeError, "no implicit conversion to float from string");
default:
- break;
- }
+ break;
+ }
}
val = rb_convert_type_with_id(val, T_FLOAT, "Float", id_to_f);
return RFLOAT_VALUE(val);
@@ -3653,22 +3800,25 @@ rb_String(VALUE val)
{
VALUE tmp = rb_check_string_type(val);
if (NIL_P(tmp))
- tmp = rb_convert_type_with_id(val, T_STRING, "String", idTo_s);
+ tmp = rb_convert_type_with_id(val, T_STRING, "String", idTo_s);
return tmp;
}
/*
* call-seq:
- * String(arg) -> string
+ * String(object) -> object or new_string
*
- * Returns <i>arg</i> as a String.
+ * Returns a string converted from +object+.
*
- * First tries to call its <code>to_str</code> method, then its <code>to_s</code> method.
+ * Tries to convert +object+ to a string
+ * using +to_str+ first and +to_s+ second:
*
- * String(self) #=> "main"
- * String(self.class) #=> "Object"
- * String(123456) #=> "123456"
+ * String([0, 1, 2]) # => "[0, 1, 2]"
+ * String(0..5) # => "0..5"
+ * String({foo: 0, bar: 1}) # => "{:foo=>0, :bar=>1}"
+ *
+ * Raises +TypeError+ if +object+ cannot be converted to a string.
*/
static VALUE
@@ -3683,32 +3833,32 @@ rb_Array(VALUE val)
VALUE tmp = rb_check_array_type(val);
if (NIL_P(tmp)) {
- tmp = rb_check_to_array(val);
- if (NIL_P(tmp)) {
- return rb_ary_new3(1, val);
- }
+ tmp = rb_check_to_array(val);
+ if (NIL_P(tmp)) {
+ return rb_ary_new3(1, val);
+ }
}
return tmp;
}
/*
* call-seq:
- * Array(arg) -> array
+ * Array(object) -> object or new_array
+ *
+ * Returns an array converted from +object+.
+ *
+ * Tries to convert +object+ to an array
+ * using +to_ary+ first and +to_a+ second:
*
- * Returns +arg+ as an Array.
+ * Array([0, 1, 2]) # => [0, 1, 2]
+ * Array({foo: 0, bar: 1}) # => [[:foo, 0], [:bar, 1]]
+ * Array(0..4) # => [0, 1, 2, 3, 4]
*
- * First tries to call <code>to_ary</code> on +arg+, then <code>to_a</code>.
- * If +arg+ does not respond to <code>to_ary</code> or <code>to_a</code>,
- * returns an Array of length 1 containing +arg+.
+ * Returns +object+ in an array, <tt>[object]</tt>,
+ * if +object+ cannot be converted:
*
- * If <code>to_ary</code> or <code>to_a</code> returns something other than
- * an Array, raises a TypeError.
+ * Array(:foo) # => [:foo]
*
- * Array(["a", "b"]) #=> ["a", "b"]
- * Array(1..5) #=> [1, 2, 3, 4, 5]
- * Array(key: :value) #=> [[:key, :value]]
- * Array(nil) #=> []
- * Array(1) #=> [1]
*/
static VALUE
@@ -3728,25 +3878,33 @@ rb_Hash(VALUE val)
if (NIL_P(val)) return rb_hash_new();
tmp = rb_check_hash_type(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));
+ 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));
}
return tmp;
}
/*
* call-seq:
- * Hash(arg) -> hash
+ * Hash(object) -> object or new_hash
+ *
+ * Returns a hash converted from +object+.
+ *
+ * - If +object+ is:
+ *
+ * - A hash, returns +object+.
+ * - An empty array or +nil+, returns an empty hash.
*
- * Converts <i>arg</i> to a Hash by calling
- * <i>arg</i><code>.to_hash</code>. Returns an empty Hash when
- * <i>arg</i> is <tt>nil</tt> or <tt>[]</tt>.
+ * - Otherwise, if <tt>object.to_hash</tt> returns a hash, returns that hash.
+ * - Otherwise, returns TypeError.
+ *
+ * Examples:
+ *
+ * Hash({foo: 0, bar: 1}) # => {:foo=>0, :bar=>1}
+ * Hash(nil) # => {}
+ * Hash([]) # => {}
*
- * Hash([]) #=> {}
- * Hash(nil) #=> {}
- * Hash(key: :value) #=> {:key => :value}
- * Hash([1, 2, 3]) #=> TypeError
*/
static VALUE
@@ -3768,8 +3926,8 @@ dig_basic_p(VALUE obj, struct dig_method *cache)
{
VALUE klass = RBASIC_CLASS(obj);
if (klass != cache->klass) {
- cache->klass = klass;
- cache->basic = rb_method_basic_definition_p(klass, id_dig);
+ cache->klass = klass;
+ cache->basic = rb_method_basic_definition_p(klass, id_dig);
}
return cache->basic;
}
@@ -3778,8 +3936,8 @@ static void
no_dig_method(int found, VALUE recv, ID mid, int argc, const VALUE *argv, VALUE data)
{
if (!found) {
- rb_raise(rb_eTypeError, "%"PRIsVALUE" does not have #dig method",
- CLASS_OF(data));
+ rb_raise(rb_eTypeError, "%"PRIsVALUE" does not have #dig method",
+ CLASS_OF(data));
}
}
@@ -3790,31 +3948,31 @@ rb_obj_dig(int argc, VALUE *argv, VALUE obj, VALUE notfound)
struct dig_method hash = {Qnil}, ary = {Qnil}, strt = {Qnil};
for (; argc > 0; ++argv, --argc) {
- if (NIL_P(obj)) return notfound;
- if (!SPECIAL_CONST_P(obj)) {
- switch (BUILTIN_TYPE(obj)) {
- case T_HASH:
- if (dig_basic_p(obj, &hash)) {
- obj = rb_hash_aref(obj, *argv);
- continue;
- }
- break;
- case T_ARRAY:
- if (dig_basic_p(obj, &ary)) {
- obj = rb_ary_at(obj, *argv);
- continue;
- }
- break;
- case T_STRUCT:
- if (dig_basic_p(obj, &strt)) {
- obj = rb_struct_lookup(obj, *argv);
- continue;
- }
- break;
+ if (NIL_P(obj)) return notfound;
+ if (!SPECIAL_CONST_P(obj)) {
+ switch (BUILTIN_TYPE(obj)) {
+ case T_HASH:
+ if (dig_basic_p(obj, &hash)) {
+ obj = rb_hash_aref(obj, *argv);
+ continue;
+ }
+ break;
+ case T_ARRAY:
+ if (dig_basic_p(obj, &ary)) {
+ obj = rb_ary_at(obj, *argv);
+ continue;
+ }
+ break;
+ case T_STRUCT:
+ if (dig_basic_p(obj, &strt)) {
+ obj = rb_struct_lookup(obj, *argv);
+ continue;
+ }
+ break;
default:
break;
- }
- }
+ }
+ }
return rb_check_funcall_with_hook_kw(obj, id_dig, argc, argv,
no_dig_method, obj,
RB_NO_KEYWORDS);
@@ -3824,263 +3982,13 @@ rb_obj_dig(int argc, VALUE *argv, VALUE obj, VALUE notfound)
/*
* call-seq:
- * format(format_string [, arguments...] ) -> string
- * sprintf(format_string [, arguments...] ) -> string
- *
- * Returns the string resulting from applying <i>format_string</i> to
- * any additional arguments. Within the format string, any characters
- * other than format sequences are copied to the result.
- *
- * The syntax of a format sequence is as follows.
- *
- * %[flags][width][.precision]type
- *
- * A format
- * sequence consists of a percent sign, followed by optional flags,
- * width, and precision indicators, then terminated with a field type
- * character. The field type controls how the corresponding
- * <code>sprintf</code> argument is to be interpreted, while the flags
- * modify that interpretation.
- *
- * The field type characters are:
- *
- * Field | Integer Format
- * ------+--------------------------------------------------------------
- * b | Convert argument as a binary number.
- * | Negative numbers will be displayed as a two's complement
- * | prefixed with `..1'.
- * B | Equivalent to `b', but uses an uppercase 0B for prefix
- * | in the alternative format by #.
- * d | Convert argument as a decimal number.
- * i | Identical to `d'.
- * o | Convert argument as an octal number.
- * | Negative numbers will be displayed as a two's complement
- * | prefixed with `..7'.
- * u | Identical to `d'.
- * x | Convert argument as a hexadecimal number.
- * | Negative numbers will be displayed as a two's complement
- * | prefixed with `..f' (representing an infinite string of
- * | leading 'ff's).
- * X | Equivalent to `x', but uses uppercase letters.
- *
- * Field | Float Format
- * ------+--------------------------------------------------------------
- * e | Convert floating point argument into exponential notation
- * | with one digit before the decimal point as [-]d.dddddde[+-]dd.
- * | The precision specifies the number of digits after the decimal
- * | point (defaulting to six).
- * E | Equivalent to `e', but uses an uppercase E to indicate
- * | the exponent.
- * f | Convert floating point argument as [-]ddd.dddddd,
- * | where the precision specifies the number of digits after
- * | the decimal point.
- * g | Convert a floating point number using exponential form
- * | if the exponent is less than -4 or greater than or
- * | equal to the precision, or in dd.dddd form otherwise.
- * | The precision specifies the number of significant digits.
- * G | Equivalent to `g', but use an uppercase `E' in exponent form.
- * a | Convert floating point argument as [-]0xh.hhhhp[+-]dd,
- * | which is consisted from optional sign, "0x", fraction part
- * | as hexadecimal, "p", and exponential part as decimal.
- * A | Equivalent to `a', but use uppercase `X' and `P'.
- *
- * Field | Other Format
- * ------+--------------------------------------------------------------
- * c | Argument is the numeric code for a single character or
- * | a single character string itself.
- * p | The valuing of argument.inspect.
- * s | Argument is a string to be substituted. If the format
- * | sequence contains a precision, at most that many characters
- * | will be copied.
- * % | A percent sign itself will be displayed. No argument taken.
- *
- * The flags modifies the behavior of the formats.
- * The flag characters are:
- *
- * Flag | Applies to | Meaning
- * ---------+---------------+-----------------------------------------
- * space | bBdiouxX | Leave a space at the start of
- * | aAeEfgG | non-negative numbers.
- * | (numeric fmt) | For `o', `x', `X', `b' and `B', use
- * | | a minus sign with absolute value for
- * | | negative values.
- * ---------+---------------+-----------------------------------------
- * (digit)$ | all | Specifies the absolute argument number
- * | | for this field. Absolute and relative
- * | | argument numbers cannot be mixed in a
- * | | sprintf string.
- * ---------+---------------+-----------------------------------------
- * # | bBoxX | Use an alternative format.
- * | aAeEfgG | For the conversions `o', increase the precision
- * | | until the first digit will be `0' if
- * | | it is not formatted as complements.
- * | | For the conversions `x', `X', `b' and `B'
- * | | on non-zero, prefix the result with ``0x'',
- * | | ``0X'', ``0b'' and ``0B'', respectively.
- * | | For `a', `A', `e', `E', `f', `g', and 'G',
- * | | force a decimal point to be added,
- * | | even if no digits follow.
- * | | For `g' and 'G', do not remove trailing zeros.
- * ---------+---------------+-----------------------------------------
- * + | bBdiouxX | Add a leading plus sign to non-negative
- * | aAeEfgG | numbers.
- * | (numeric fmt) | For `o', `x', `X', `b' and `B', use
- * | | a minus sign with absolute value for
- * | | negative values.
- * ---------+---------------+-----------------------------------------
- * - | all | Left-justify the result of this conversion.
- * ---------+---------------+-----------------------------------------
- * 0 (zero) | bBdiouxX | Pad with zeros, not spaces.
- * | aAeEfgG | For `o', `x', `X', `b' and `B', radix-1
- * | (numeric fmt) | is used for negative numbers formatted as
- * | | complements.
- * ---------+---------------+-----------------------------------------
- * * | all | Use the next argument as the field width.
- * | | If negative, left-justify the result. If the
- * | | asterisk is followed by a number and a dollar
- * | | sign, use the indicated argument as the width.
- *
- * Examples of flags:
- *
- * # `+' and space flag specifies the sign of non-negative numbers.
- * sprintf("%d", 123) #=> "123"
- * sprintf("%+d", 123) #=> "+123"
- * sprintf("% d", 123) #=> " 123"
- *
- * # `#' flag for `o' increases number of digits to show `0'.
- * # `+' and space flag changes format of negative numbers.
- * sprintf("%o", 123) #=> "173"
- * sprintf("%#o", 123) #=> "0173"
- * sprintf("%+o", -123) #=> "-173"
- * sprintf("%o", -123) #=> "..7605"
- * sprintf("%#o", -123) #=> "..7605"
- *
- * # `#' flag for `x' add a prefix `0x' for non-zero numbers.
- * # `+' and space flag disables complements for negative numbers.
- * sprintf("%x", 123) #=> "7b"
- * sprintf("%#x", 123) #=> "0x7b"
- * sprintf("%+x", -123) #=> "-7b"
- * sprintf("%x", -123) #=> "..f85"
- * sprintf("%#x", -123) #=> "0x..f85"
- * sprintf("%#x", 0) #=> "0"
- *
- * # `#' for `X' uses the prefix `0X'.
- * sprintf("%X", 123) #=> "7B"
- * sprintf("%#X", 123) #=> "0X7B"
- *
- * # `#' flag for `b' add a prefix `0b' for non-zero numbers.
- * # `+' and space flag disables complements for negative numbers.
- * sprintf("%b", 123) #=> "1111011"
- * sprintf("%#b", 123) #=> "0b1111011"
- * sprintf("%+b", -123) #=> "-1111011"
- * sprintf("%b", -123) #=> "..10000101"
- * sprintf("%#b", -123) #=> "0b..10000101"
- * sprintf("%#b", 0) #=> "0"
- *
- * # `#' for `B' uses the prefix `0B'.
- * sprintf("%B", 123) #=> "1111011"
- * sprintf("%#B", 123) #=> "0B1111011"
- *
- * # `#' for `e' forces to show the decimal point.
- * sprintf("%.0e", 1) #=> "1e+00"
- * sprintf("%#.0e", 1) #=> "1.e+00"
- *
- * # `#' for `f' forces to show the decimal point.
- * sprintf("%.0f", 1234) #=> "1234"
- * sprintf("%#.0f", 1234) #=> "1234."
- *
- * # `#' for `g' forces to show the decimal point.
- * # It also disables stripping lowest zeros.
- * sprintf("%g", 123.4) #=> "123.4"
- * sprintf("%#g", 123.4) #=> "123.400"
- * sprintf("%g", 123456) #=> "123456"
- * sprintf("%#g", 123456) #=> "123456."
- *
- * The field width is an optional integer, followed optionally by a
- * period and a precision. The width specifies the minimum number of
- * characters that will be written to the result for this field.
- *
- * Examples of width:
- *
- * # padding is done by spaces, width=20
- * # 0 or radix-1. <------------------>
- * sprintf("%20d", 123) #=> " 123"
- * sprintf("%+20d", 123) #=> " +123"
- * sprintf("%020d", 123) #=> "00000000000000000123"
- * sprintf("%+020d", 123) #=> "+0000000000000000123"
- * sprintf("% 020d", 123) #=> " 0000000000000000123"
- * sprintf("%-20d", 123) #=> "123 "
- * sprintf("%-+20d", 123) #=> "+123 "
- * sprintf("%- 20d", 123) #=> " 123 "
- * sprintf("%020x", -123) #=> "..ffffffffffffffff85"
- *
- * For
- * numeric fields, the precision controls the number of decimal places
- * displayed. For string fields, the precision determines the maximum
- * number of characters to be copied from the string. (Thus, the format
- * sequence <code>%10.10s</code> will always contribute exactly ten
- * characters to the result.)
- *
- * Examples of precisions:
- *
- * # precision for `d', 'o', 'x' and 'b' is
- * # minimum number of digits <------>
- * sprintf("%20.8d", 123) #=> " 00000123"
- * sprintf("%20.8o", 123) #=> " 00000173"
- * sprintf("%20.8x", 123) #=> " 0000007b"
- * sprintf("%20.8b", 123) #=> " 01111011"
- * sprintf("%20.8d", -123) #=> " -00000123"
- * sprintf("%20.8o", -123) #=> " ..777605"
- * sprintf("%20.8x", -123) #=> " ..ffff85"
- * sprintf("%20.8b", -11) #=> " ..110101"
- *
- * # "0x" and "0b" for `#x' and `#b' is not counted for
- * # precision but "0" for `#o' is counted. <------>
- * sprintf("%#20.8d", 123) #=> " 00000123"
- * sprintf("%#20.8o", 123) #=> " 00000173"
- * sprintf("%#20.8x", 123) #=> " 0x0000007b"
- * sprintf("%#20.8b", 123) #=> " 0b01111011"
- * sprintf("%#20.8d", -123) #=> " -00000123"
- * sprintf("%#20.8o", -123) #=> " ..777605"
- * sprintf("%#20.8x", -123) #=> " 0x..ffff85"
- * sprintf("%#20.8b", -11) #=> " 0b..110101"
- *
- * # precision for `e' is number of
- * # digits after the decimal point <------>
- * sprintf("%20.8e", 1234.56789) #=> " 1.23456789e+03"
- *
- * # precision for `f' is number of
- * # digits after the decimal point <------>
- * sprintf("%20.8f", 1234.56789) #=> " 1234.56789000"
- *
- * # precision for `g' is number of
- * # significant digits <------->
- * sprintf("%20.8g", 1234.56789) #=> " 1234.5679"
- *
- * # <------->
- * sprintf("%20.8g", 123456789) #=> " 1.2345679e+08"
- *
- * # precision for `s' is
- * # maximum number of characters <------>
- * sprintf("%20.8s", "string test") #=> " string t"
+ * sprintf(format_string *objects) -> string
*
- * Examples:
+ * Returns the string resulting from formatting +objects+
+ * into +format_string+.
*
- * sprintf("%d %04x", 123, 123) #=> "123 007b"
- * sprintf("%08b '%4s'", 123, 123) #=> "01111011 ' 123'"
- * sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 hello"
- * sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"
- * sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 1.23:1.23"
- * sprintf("%u", -123) #=> "-123"
- *
- * For more complex formatting, Ruby supports a reference by name.
- * %<name>s style uses format style, but %{name} style doesn't.
- *
- * Examples:
- * sprintf("%<foo>d : %<bar>f", { :foo => 1, :bar => 2 })
- * #=> 1 : 2.000000
- * sprintf("%{foo}f", { :foo => 1 })
- * # => "1f"
+ * For details on +format_string+, see
+ * {Format Specifications}[rdoc-ref:format_specifications.rdoc].
*/
static VALUE
@@ -4089,6 +3997,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
*
@@ -4187,7 +4101,7 @@ f_sprintf(int c, const VALUE *v, VALUE _)
* end
*
* def respond_to_missing?(name, include_private = false)
- * DELEGATE.include?(name) or super
+ * DELEGATE.include?(name)
* end
* end
*
@@ -4207,25 +4121,16 @@ f_sprintf(int c, const VALUE *v, VALUE _)
*
* These are the methods defined for \BasicObject:
*
- * - ::new:: Returns a new \BasicObject instance.
- * - {!}[#method-i-21]:: Returns the boolean negation of +self+: +true+ or +false+.
- * - {!=}[#method-i-21-3D]:: Returns whether +self+ and the given object
- * are _not_ equal.
- * - {==}[#method-i-3D-3D]:: Returns whether +self+ and the given object
- * are equivalent.
- * - {__id__}[#method-i-__id__]:: Returns the integer object identifier for +self+.
- * - {__send__}[#method-i-__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.
- * - #method_missing:: Method called when an undefined method is called on +self+.
- * - #singleton_method_added:: Method called when a singleton method
- * is added to +self+.
- * - #singleton_method_removed:: Method called when a singleton method
- * is added removed from +self+.
- * - #singleton_method_undefined:: Method called when a singleton method
- * is undefined in +self+.
+ * - ::new: Returns a new \BasicObject instance.
+ * - #!: Returns the boolean negation of +self+: +true+ or +false+.
+ * - #!=: Returns whether +self+ and the given object are _not_ equal.
+ * - #==: Returns whether +self+ and the given object are equivalent.
+ * - #__id__: Returns the integer object identifier for +self+.
+ * - #__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.
*
*/
@@ -4251,106 +4156,84 @@ f_sprintf(int c, const VALUE *v, VALUE _)
*
* First, what's elsewhere. \Class \Object:
*
- * - Inherits from {class BasicObject}[BasicObject.html#class-BasicObject-label-What-27s+Here].
- * - Includes {module Kernel}[Kernel.html#module-Kernel-label-What-27s+Here].
+ * - Inherits from {class BasicObject}[rdoc-ref:BasicObject@What-27s+Here].
+ * - Includes {module Kernel}[rdoc-ref:Kernel@What-27s+Here].
*
* Here, class \Object provides methods for:
*
- * - {Querying}[#class-Object-label-Querying]
- * - {Instance Variables}[#class-Object-label-Instance+Variables]
- * - {Other}[#class-Object-label-Other]
+ * - {Querying}[rdoc-ref:Object@Querying]
+ * - {Instance Variables}[rdoc-ref:Object@Instance+Variables]
+ * - {Other}[rdoc-ref:Object@Other]
*
* === Querying
*
- * - {!~}[#method-i-21~]:: Returns +true+ if +self+ does not match the given object,
- * otherwise +false+.
- * - {<=>}[#method-i-3C-3D-3E]:: Returns 0 if +self+ and the given object +object+
- * are the same object, or if
- * <tt>self == object</tt>; otherwise returns +nil+.
- * - #===:: Implements case equality, effectively the same as calling #==.
- * - #eql?:: Implements hash equality, effectively the same as calling #==.
- * - #kind_of? (aliased as #is_a?):: Returns whether given argument is an ancestor
- * of the singleton class of +self+.
- * - #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+.
- * - #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>.)
- * - #object_id:: Returns an integer corresponding to +self+ that is unique
- * for the current process
- * - #private_methods:: Returns an array of the symbol names
- * 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_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
- * in +self+.
- * - #singleton_methods:: Returns an array of the symbol names
- * of the singleton methods in +self+.
- *
- * - #define_singleton_method:: Defines a singleton method in +self+
- * for the given symbol method-name and block or proc.
- * - #extend:: Includes the given modules in the singleton class of +self+.
- * - #public_send:: Calls the given public method in +self+ with the given argument.
- * - #send:: Calls the given method in +self+ with the given argument.
+ * - #!~: Returns +true+ if +self+ does not match the given object,
+ * otherwise +false+.
+ * - #<=>: Returns 0 if +self+ and the given object +object+ are the same
+ * object, or if <tt>self == object</tt>; otherwise returns +nil+.
+ * - #===: Implements case equality, effectively the same as calling #==.
+ * - #eql?: Implements hash equality, effectively the same as calling #==.
+ * - #kind_of? (aliased as #is_a?): Returns whether given argument is an ancestor
+ * of the singleton class of +self+.
+ * - #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+.
+ * - #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>.)
+ * - #object_id: Returns an integer corresponding to +self+ that is unique
+ * for the current process
+ * - #private_methods: Returns an array of the symbol names
+ * 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_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
+ * in +self+.
+ * - #singleton_methods: Returns an array of the symbol names
+ * of the singleton methods in +self+.
+ *
+ * - #define_singleton_method: Defines a singleton method in +self+
+ * for the given symbol method-name and block or proc.
+ * - #extend: Includes the given modules in the singleton class of +self+.
+ * - #public_send: Calls the given public method in +self+ with the given argument.
+ * - #send: Calls the given method in +self+ with the given argument.
*
* === Instance Variables
*
- * - #instance_variable_get:: Returns the value of the given instance variable
- * in +self+, or +nil+ if the instance variable is not set.
- * - #instance_variable_set:: Sets the value of the given instance variable in +self+
- * to the given object.
- * - #instance_variables:: Returns an array of the symbol names
- * of the instance variables in +self+.
- * - #remove_instance_variable:: Removes the named instance variable from +self+.
+ * - #instance_variable_get: Returns the value of the given instance variable
+ * in +self+, or +nil+ if the instance variable is not set.
+ * - #instance_variable_set: Sets the value of the given instance variable in +self+
+ * to the given object.
+ * - #instance_variables: Returns an array of the symbol names
+ * of the instance variables in +self+.
+ * - #remove_instance_variable: Removes the named instance variable from +self+.
*
* === Other
*
- * - #clone:: Returns a shallow copy of +self+, including singleton class
- * 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>.
- * - #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.
- * - #extend:: Includes the given modules in the singleton class of +self+.
- * - #freeze:: Prevents further modifications to +self+.
- * - #hash:: Returns the integer hash value for +self+.
- * - #inspect:: Returns a human-readable string representation of +self+.
- * - #itself:: Returns +self+.
- * - #public_send:: Calls the given public method in +self+ with the given argument.
- * - #send:: Calls the given method in +self+ with the given argument.
- * - #to_s:: Returns a string representation of +self+.
- *
- */
-
-/*!
- *--
- * \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.
+ * - #clone: Returns a shallow copy of +self+, including singleton class
+ * 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>.
+ * - #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.
+ * - #extend: Includes the given modules in the singleton class of +self+.
+ * - #freeze: Prevents further modifications to +self+.
+ * - #hash: Returns the integer hash value for +self+.
+ * - #inspect: Returns a human-readable string representation of +self+.
+ * - #itself: Returns +self+.
+ * - #method_missing: Method called when an undefined method is called on +self+.
+ * - #public_send: Calls the given public method in +self+ with the given argument.
+ * - #send: Calls the given method in +self+ with the given argument.
+ * - #to_s: Returns a string representation of +self+.
*
- * \image html boottime-classes.png
- *
- * Then, the function defines classes, modules and methods as usual.
- * \ingroup class
- *++
*/
void
@@ -4393,134 +4276,131 @@ InitVM_Object(void)
*
* \Module \Kernel provides methods that are useful for:
*
- * - {Converting}[#module-Kernel-label-Converting]
- * - {Querying}[#module-Kernel-label-Querying]
- * - {Exiting}[#module-Kernel-label-Exiting]
- * - {Exceptions}[#module-Kernel-label-Exceptions]
- * - {IO}[#module-Kernel-label-IO]
- * - {Procs}[#module-Kernel-label-Procs]
- * - {Tracing}[#module-Kernel-label-Tracing]
- * - {Subprocesses}[#module-Kernel-label-Subprocesses]
- * - {Loading}[#module-Kernel-label-Loading]
- * - {Yielding}[#module-Kernel-label-Yielding]
- * - {Random Values}[#module-Kernel-label-Random+Values]
- * - {Other}[#module-Kernel-label-Other]
+ * - {Converting}[rdoc-ref:Kernel@Converting]
+ * - {Querying}[rdoc-ref:Kernel@Querying]
+ * - {Exiting}[rdoc-ref:Kernel@Exiting]
+ * - {Exceptions}[rdoc-ref:Kernel@Exceptions]
+ * - {IO}[rdoc-ref:Kernel@IO]
+ * - {Procs}[rdoc-ref:Kernel@Procs]
+ * - {Tracing}[rdoc-ref:Kernel@Tracing]
+ * - {Subprocesses}[rdoc-ref:Kernel@Subprocesses]
+ * - {Loading}[rdoc-ref:Kernel@Loading]
+ * - {Yielding}[rdoc-ref:Kernel@Yielding]
+ * - {Random Values}[rdoc-ref:Kernel@Random+Values]
+ * - {Other}[rdoc-ref:Kernel@Other]
*
* === Converting
*
- * - {#Array}[#method-i-Array]:: Returns an Array based on the given argument.
- * - {#Complex}[#method-i-Complex]:: Returns a Complex based on the given arguments.
- * - {#Float}[#method-i-Float]:: Returns a Float based on the given arguments.
- * - {#Hash}[#method-i-Hash]:: Returns a Hash based on the given argument.
- * - {#Integer}[#method-i-Integer]:: Returns an Integer based on the given arguments.
- * - {#Rational}[#method-i-Rational]:: Returns a Rational
- * based on the given arguments.
- * - {#String}[#method-i-String]:: Returns a String based on the given argument.
+ * - #Array: Returns an Array based on the given argument.
+ * - #Complex: Returns a Complex based on the given arguments.
+ * - #Float: Returns a Float based on the given arguments.
+ * - #Hash: Returns a Hash based on the given argument.
+ * - #Integer: Returns an Integer based on the given arguments.
+ * - #Rational: Returns a Rational based on the given arguments.
+ * - #String: Returns a String based on the given argument.
*
* === Querying
*
- * - {#__callee__}[#method-i-__callee__]:: Returns the called name
- * of the current method as a symbol.
- * - {#__dir__}[#method-i-__dir__]:: Returns the path to the directory
- * from which the current method is called.
- * - {#__method__}[#method-i-__method__]:: Returns the name
- * of the current method as a symbol.
- * - #autoload?:: Returns the file to be loaded when the given module is referenced.
- * - #binding:: Returns a Binding for the context at the point of call.
- * - #block_given?:: Returns +true+ if a block was passed to the calling method.
- * - #caller:: Returns the current execution stack as an array of strings.
- * - #caller_locations:: Returns the current execution stack as an array
- * of Thread::Backtrace::Location objects.
- * - #class:: Returns the class of +self+.
- * - #frozen?:: Returns whether +self+ is frozen.
- * - #global_variables:: Returns an array of global variables as symbols.
- * - #local_variables:: Returns an array of local variables as symbols.
- * - #test:: Performs specified tests on the given single file or pair of files.
+ * - #__callee__: Returns the called name of the current method as a symbol.
+ * - #__dir__: Returns the path to the directory from which the current
+ * method is called.
+ * - #__method__: Returns the name of the current method as a symbol.
+ * - #autoload?: Returns the file to be loaded when the given module is referenced.
+ * - #binding: Returns a Binding for the context at the point of call.
+ * - #block_given?: Returns +true+ if a block was passed to the calling method.
+ * - #caller: Returns the current execution stack as an array of strings.
+ * - #caller_locations: Returns the current execution stack as an array
+ * of Thread::Backtrace::Location objects.
+ * - #class: Returns the class of +self+.
+ * - #frozen?: Returns whether +self+ is frozen.
+ * - #global_variables: Returns an array of global variables as symbols.
+ * - #local_variables: Returns an array of local variables as symbols.
+ * - #test: Performs specified tests on the given single file or pair of files.
*
* === Exiting
*
- * - #abort:: Exits the current process after printing the given arguments.
- * - #at_exit:: Executes the given block when the process exits.
- * - #exit:: Exits the current process after calling any registered
- * +at_exit+ handlers.
- * - #exit!:: Exits the current process without calling any registered
- * +at_exit+ handlers.
+ * - #abort: Exits the current process after printing the given arguments.
+ * - #at_exit: Executes the given block when the process exits.
+ * - #exit: Exits the current process after calling any registered
+ * +at_exit+ handlers.
+ * - #exit!: Exits the current process without calling any registered
+ * +at_exit+ handlers.
*
* === Exceptions
*
- * - #catch:: Executes the given block, possibly catching a thrown object.
- * - #raise (aliased as #fail):: Raises an exception based on the given arguments.
- * - #throw:: Returns from the active catch block waiting for the given tag.
+ * - #catch: Executes the given block, possibly catching a thrown object.
+ * - #raise (aliased as #fail): Raises an exception based on the given arguments.
+ * - #throw: Returns from the active catch block waiting for the given tag.
*
*
* === \IO
*
- * - #gets:: Returns and assigns to <tt>$_</tt> the next line from the current input.
- * - #open:: Creates an IO object connected to the given stream, file, or subprocess.
- * - #p:: Prints the given objects' inspect output to the standard output.
- * - #pp:: Prints the given objects in pretty form.
- * - #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.
- * - #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.
- * - #select:: Same as IO.select.
+ * - ::pp: Prints the given objects in pretty form.
+ * - #gets: Returns and assigns to <tt>$_</tt> the next line from the current input.
+ * - #open: Creates an IO object connected to the given stream, file, or subprocess.
+ * - #p: Prints the given objects' inspect output to the standard output.
+ * - #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.
+ * - #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.
+ * - #select: Same as IO.select.
*
* === Procs
*
- * - #lambda:: Returns a lambda proc for the given block.
- * - #proc:: Returns a new Proc; equivalent to Proc.new.
+ * - #lambda: Returns a lambda proc for the given block.
+ * - #proc: Returns a new Proc; equivalent to Proc.new.
*
* === Tracing
*
- * - #set_trace_func:: Sets the given proc as the handler for tracing,
- * or disables tracing if given +nil+.
- * - #trace_var:: Starts tracing assignments to the given global variable.
- * - #untrace_var:: Disables tracing of assignments to the given global variable.
+ * - #set_trace_func: Sets the given proc as the handler for tracing,
+ * or disables tracing if given +nil+.
+ * - #trace_var: Starts tracing assignments to the given global variable.
+ * - #untrace_var: Disables tracing of assignments to the given global variable.
*
* === Subprocesses
*
- * - #`cmd`:: Returns the standard output of running +cmd+ in a subshell.
- * - #exec:: Replaces current process with a new process.
- * - #fork:: Forks the current process into two processes.
- * - #spawn:: Executes the given command and returns its pid without waiting
- * for completion.
- * - #system:: Executes the given command in a subshell.
+ * - {\`command`}[rdoc-ref:Kernel#`]: Returns the standard output of running
+ * +command+ in a subshell.
+ * - #exec: Replaces current process with a new process.
+ * - #fork: Forks the current process into two processes.
+ * - #spawn: Executes the given command and returns its pid without waiting
+ * for completion.
+ * - #system: Executes the given command in a subshell.
*
* === Loading
*
- * - #autoload:: Registers the given file to be loaded when the given constant
- * is first referenced.
- * - #load:: Loads the given Ruby file.
- * - #require:: Loads the given Ruby file unless it has already been loaded.
- * - #require_relative:: Loads the Ruby file path relative to the calling file,
- * unless it has already been loaded.
+ * - #autoload: Registers the given file to be loaded when the given constant
+ * is first referenced.
+ * - #load: Loads the given Ruby file.
+ * - #require: Loads the given Ruby file unless it has already been loaded.
+ * - #require_relative: Loads the Ruby file path relative to the calling file,
+ * unless it has already been loaded.
*
* === Yielding
*
- * - #tap:: Yields +self+ to the given block; returns +self+.
- * - #then (aliased as #yield_self):: Yields +self+ to the block
- * and returns the result of the block.
+ * - #tap: Yields +self+ to the given block; returns +self+.
+ * - #then (aliased as #yield_self): Yields +self+ to the block
+ * and returns the result of the block.
*
* === \Random Values
*
- * - #rand:: Returns a pseudo-random floating point number
- * strictly between 0.0 and 1.0.
- * - #srand:: Seeds the pseudo-random number generator with the given number.
+ * - #rand: Returns a pseudo-random floating point number
+ * strictly between 0.0 and 1.0.
+ * - #srand: Seeds the pseudo-random number generator with the given number.
*
* === Other
*
- * - #eval:: Evaluates the given string as Ruby code.
- * - #loop:: Repeatedly executes the given block.
- * - #sleep:: Suspends the current thread for the given number of seconds.
- * - #sprintf (aliased as #format):: Returns the string resulting from applying
- * the given format string
- * to any additional arguments.
- * - #syscall:: Runs an operating system call.
- * - #trap:: Specifies the handling of system signals.
- * - #warn:: Issue a warning based on the given messages and options.
+ * - #eval: Evaluates the given string as Ruby code.
+ * - #loop: Repeatedly executes the given block.
+ * - #sleep: Suspends the current thread for the given number of seconds.
+ * - #sprintf (aliased as #format): Returns the string resulting from applying
+ * the given format string to any additional arguments.
+ * - #syscall: Runs an operating system call.
+ * - #trap: Specifies the handling of system signals.
+ * - #warn: Issue a warning based on the given messages and options.
*
*/
rb_mKernel = rb_define_module("Kernel");
@@ -4530,12 +4410,12 @@ InitVM_Object(void)
rb_define_private_method(rb_cModule, "extended", rb_obj_mod_extended, 1);
rb_define_private_method(rb_cModule, "prepended", rb_obj_mod_prepended, 1);
rb_define_private_method(rb_cModule, "method_added", rb_obj_mod_method_added, 1);
+ rb_define_private_method(rb_cModule, "const_added", rb_obj_mod_const_added, 1);
rb_define_private_method(rb_cModule, "method_removed", rb_obj_mod_method_removed, 1);
rb_define_private_method(rb_cModule, "method_undefined", rb_obj_mod_method_undefined, 1);
rb_define_method(rb_mKernel, "nil?", rb_false, 0);
rb_define_method(rb_mKernel, "===", case_equal, 1);
- rb_define_method(rb_mKernel, "=~", rb_obj_match, 1);
rb_define_method(rb_mKernel, "!~", rb_obj_not_match, 1);
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
rb_define_method(rb_mKernel, "hash", rb_obj_hash, 0); /* in hash.c */
@@ -4548,12 +4428,6 @@ InitVM_Object(void)
rb_define_method(rb_mKernel, "initialize_dup", rb_obj_init_dup_clone, 1);
rb_define_method(rb_mKernel, "initialize_clone", rb_obj_init_clone, -1);
- rb_define_method(rb_mKernel, "taint", rb_obj_taint, 0);
- rb_define_method(rb_mKernel, "tainted?", rb_obj_tainted, 0);
- rb_define_method(rb_mKernel, "untaint", rb_obj_untaint, 0);
- rb_define_method(rb_mKernel, "untrust", rb_obj_untrust, 0);
- rb_define_method(rb_mKernel, "untrusted?", rb_obj_untrusted, 0);
- rb_define_method(rb_mKernel, "trust", rb_obj_trust, 0);
rb_define_method(rb_mKernel, "freeze", rb_obj_freeze, 0);
rb_define_method(rb_mKernel, "to_s", rb_any_to_s, 0);
@@ -4565,10 +4439,10 @@ InitVM_Object(void)
rb_define_method(rb_mKernel, "public_methods", rb_obj_public_methods, -1); /* in class.c */
rb_define_method(rb_mKernel, "instance_variables", rb_obj_instance_variables, 0); /* in variable.c */
rb_define_method(rb_mKernel, "instance_variable_get", rb_obj_ivar_get, 1);
- rb_define_method(rb_mKernel, "instance_variable_set", rb_obj_ivar_set, 2);
+ rb_define_method(rb_mKernel, "instance_variable_set", rb_obj_ivar_set_m, 2);
rb_define_method(rb_mKernel, "instance_variable_defined?", rb_obj_ivar_defined, 1);
rb_define_method(rb_mKernel, "remove_instance_variable",
- rb_obj_remove_instance_variable, 1); /* in variable.c */
+ rb_obj_remove_instance_variable, 1); /* in variable.c */
rb_define_method(rb_mKernel, "instance_of?", rb_obj_is_instance_of, 1);
rb_define_method(rb_mKernel, "kind_of?", rb_obj_is_kind_of, 1);
@@ -4577,15 +4451,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);
@@ -4614,6 +4486,7 @@ InitVM_Object(void)
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);
@@ -4627,11 +4500,13 @@ InitVM_Object(void)
rb_define_method(rb_cModule, "initialize_clone", rb_mod_initialize_clone, -1);
rb_define_method(rb_cModule, "instance_methods", rb_class_instance_methods, -1); /* in class.c */
rb_define_method(rb_cModule, "public_instance_methods",
- rb_class_public_instance_methods, -1); /* in class.c */
+ rb_class_public_instance_methods, -1); /* in class.c */
rb_define_method(rb_cModule, "protected_instance_methods",
- rb_class_protected_instance_methods, -1); /* in class.c */
+ rb_class_protected_instance_methods, -1); /* in class.c */
rb_define_method(rb_cModule, "private_instance_methods",
- rb_class_private_instance_methods, -1); /* in class.c */
+ rb_class_private_instance_methods, -1); /* in class.c */
+ rb_define_method(rb_cModule, "undefined_instance_methods",
+ rb_class_undefined_instance_methods, 0); /* in class.c */
rb_define_method(rb_cModule, "constants", rb_mod_constants, -1); /* in variable.c */
rb_define_method(rb_cModule, "const_get", rb_mod_const_get, -1);
@@ -4639,13 +4514,13 @@ InitVM_Object(void)
rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, -1);
rb_define_method(rb_cModule, "const_source_location", rb_mod_const_source_location, -1);
rb_define_private_method(rb_cModule, "remove_const",
- rb_mod_remove_const, 1); /* in variable.c */
+ rb_mod_remove_const, 1); /* in variable.c */
rb_define_method(rb_cModule, "const_missing",
- rb_mod_const_missing, 1); /* in variable.c */
+ rb_mod_const_missing, 1); /* in variable.c */
rb_define_method(rb_cModule, "class_variables",
- rb_mod_class_variables, -1); /* in variable.c */
+ rb_mod_class_variables, -1); /* in variable.c */
rb_define_method(rb_cModule, "remove_class_variable",
- rb_mod_remove_cvar, 1); /* in variable.c */
+ rb_mod_remove_cvar, 1); /* in variable.c */
rb_define_method(rb_cModule, "class_variable_get", rb_mod_cvar_get, 1);
rb_define_method(rb_cModule, "class_variable_set", rb_mod_cvar_set, 2);
rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
@@ -4659,8 +4534,8 @@ InitVM_Object(void)
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);
- rb_define_method(rb_cClass, "descendants", rb_class_descendants, 0); /* in class.c */
rb_define_method(rb_cClass, "subclasses", rb_class_subclasses, 0); /* in class.c */
+ rb_define_method(rb_cClass, "attached_object", rb_class_attached_object, 0); /* in class.c */
rb_define_alloc_func(rb_cClass, rb_class_s_alloc);
rb_undef_method(rb_cClass, "extend_object");
rb_undef_method(rb_cClass, "append_features");
@@ -4668,7 +4543,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);
@@ -4680,7 +4555,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);