Project

General

Profile

Feature #17660 ยป 0001-Expose-information-about-which-basic-methods-have-be.patch

tenderlovemaking (Aaron Patterson), 02/27/2021 12:31 AM

View differences:

vm.c
3333 3333
    return Qnil;
3334 3334
}
3335 3335

  
3336
static void
3337
check_and_record_bop(ID mid, VALUE klass, VALUE redefines, short bv, short mask)
3338
{
3339
    if (bv & mask) {
3340
        VALUE redefined_method_ids;
3341

  
3342
        if (RTEST(rb_hash_has_key(redefines, klass))) {
3343
            redefined_method_ids = rb_hash_aref(redefines, klass);
3344
        } else {
3345
            redefined_method_ids = rb_ary_new();
3346
            rb_hash_aset(redefines, klass, redefined_method_ids);
3347
        }
3348

  
3349
        rb_ary_push(redefined_method_ids, rb_id2sym(mid));
3350
    }
3351
}
3352

  
3353
static void
3354
check_bop(ID mid, enum ruby_basic_operators bop, VALUE redefines)
3355
{
3356
    if (ruby_vm_redefined_flag[bop]) {
3357
        short bv = ruby_vm_redefined_flag[bop];
3358
        check_and_record_bop(mid, rb_cInteger, redefines, bv, INTEGER_REDEFINED_OP_FLAG);
3359
        check_and_record_bop(mid, rb_cFloat, redefines, bv, FLOAT_REDEFINED_OP_FLAG);
3360
        check_and_record_bop(mid, rb_cString, redefines, bv, STRING_REDEFINED_OP_FLAG);
3361
        check_and_record_bop(mid, rb_cArray, redefines, bv, ARRAY_REDEFINED_OP_FLAG);
3362
        check_and_record_bop(mid, rb_cHash, redefines, bv, HASH_REDEFINED_OP_FLAG);
3363
        check_and_record_bop(mid, rb_cSymbol, redefines, bv, SYMBOL_REDEFINED_OP_FLAG);
3364
        check_and_record_bop(mid, rb_cRegexp, redefines, bv, REGEXP_REDEFINED_OP_FLAG);
3365
        check_and_record_bop(mid, rb_cNilClass, redefines, bv, NIL_REDEFINED_OP_FLAG);
3366
        check_and_record_bop(mid, rb_cTrueClass, redefines, bv, TRUE_REDEFINED_OP_FLAG);
3367
        check_and_record_bop(mid, rb_cFalseClass, redefines, bv, FALSE_REDEFINED_OP_FLAG);
3368
        check_and_record_bop(mid, rb_cProc, redefines, bv, PROC_REDEFINED_OP_FLAG);
3369
    }
3370
}
3371

  
3372
static VALUE
3373
vm_redefined_methods(VALUE mod)
3374
{
3375
    VALUE redefines = rb_hash_new();
3376

  
3377
#define OP(mid_, bop_) (check_bop(id##mid_, BOP_##bop_, redefines))
3378
    OP(PLUS, PLUS);
3379
    OP(MINUS, MINUS);
3380
    OP(MULT, MULT);
3381
    OP(DIV, DIV);
3382
    OP(MOD, MOD);
3383
    OP(Eq, EQ);
3384
    OP(Eqq, EQQ);
3385
    OP(LT, LT);
3386
    OP(LE, LE);
3387
    OP(GT, GT);
3388
    OP(GE, GE);
3389
    OP(LTLT, LTLT);
3390
    OP(AREF, AREF);
3391
    OP(ASET, ASET);
3392
    OP(Length, LENGTH);
3393
    OP(Size, SIZE);
3394
    OP(EmptyP, EMPTY_P);
3395
    OP(Succ, SUCC);
3396
    OP(EqTilde, MATCH);
3397
    OP(Freeze, FREEZE);
3398
    OP(UMinus, UMINUS);
3399
    OP(Max, MAX);
3400
    OP(Min, MIN);
3401
    OP(Call, CALL);
3402
    OP(And, AND);
3403
    OP(Or, OR);
3404
    OP(NilP, NIL_P);
3405
#undef OP
3406

  
3407
    return redefines;
3408
}
3409

  
3336 3410
void
3337 3411
Init_VM(void)
3338 3412
{
......
3356 3430
    rb_undef_alloc_func(rb_cRubyVM);
3357 3431
    rb_undef_method(CLASS_OF(rb_cRubyVM), "new");
3358 3432
    rb_define_singleton_method(rb_cRubyVM, "stat", vm_stat, -1);
3433
    rb_define_singleton_method(rb_cRubyVM, "redefined_methods", vm_redefined_methods, 0);
3359 3434
#if USE_DEBUG_COUNTER
3360 3435
    rb_define_singleton_method(rb_cRubyVM, "reset_debug_counters", rb_debug_counter_reset, 0);
3361 3436
    rb_define_singleton_method(rb_cRubyVM, "show_debug_counters", rb_debug_counter_show, 0);