JoshCheek / seeing_is_believing

Displays the results of every line of code in your file
1.3k stars 54 forks source link

Impressive explosion #99

Closed JoshCheek closed 7 years ago

JoshCheek commented 7 years ago
require 'fiddle'
class Object
  def pop_class
    selfptr  = Fiddle::Pointer[__id__*2]
    classptr = (selfptr+8).ptr
    selfptr[8, 8] = classptr[16, 8]
    classptr.to_value
  end
end

C1  = Class.new     { def head() :C1_superclass_of_C2 end }
C2  = Class.new(C1) { def head() :C2_original_class end }
M1  = Module.new    { def head() :class_that_includes_mod1_into_C2 end }
C2.include(M1)
M2  = Module.new    { def head() :class_that_includes_mod2_into_singleton end }
list = C2.new.extend(M2)
list.instance_eval  { def head() :singleton_class end }

Fiddle::Pointer[list.__id__*2].+(8).ptr.+(472).ptr.to_value # => 24440
# 584

list.singleton_class.ancestors # => [#<Class:#<C2:0x007fb99401ba08>>, M2, C2, M1, C1, Object, PP::ObjectMixin, Kernel, BasicObject]

list.head       # => :singleton_class
list.pop_class  # => #<Class:#<C2:0x007fb99401ba08>>
list.head       # => :class_that_includes_mod2_into_singleton
list.pop_class  # => #<no inspect available>
list.head       # => :C2_original_class
list.pop_class  # => C2
list.head       # => :class_that_includes_mod1_into_C2
list.pop_class  # => #<no inspect available>
list.head       # => :C1_superclass_of_C2
list.pop_class  # => C1
list.head       # => NoMethodError: undefined method `head' for #<Object:0x007fb99401ba08>

# ~> NoMethodError
# ~> undefined method `head' for #<Object:0x007fb99401ba08>
# ~>
# ~> /var/folders/7g/mbft22555w3_2nqs_h1kbglw0000gn/T/seeing_is_believing_temp_dir20161224-17657-1fcowsj/program.rb:34:in `<main>'

__END__
o.m
ptr = Fiddle::Pointer[o.__id__*2]
ptr[8, 8] = ptr.+(8).ptr[0, 8]
o.m

o = C.new
ptr = Fiddle::Pointer.new(
  C.object_id * 2
)
ptr.to_value

[C.object_id * 2].pack('Q')

ptr
.ref
.ref
.ref
.ptr
.ptr
.ptr

# ~> NoMethodError
# ~> undefined method `use' for main:Object
# ~>
# ~> /var/folders/7g/mbft22555w3_2nqs_h1kbglw0000gn/T/seeing_is_believing_temp_dir20161224-16046-1bgqgf2/program.rb:2:in `<main>'/Users/josh/.gem/ruby/2.3.1/gems/seeing_is_believing-3.1.0/lib/seeing_is_believing/binary.rb:61:in `call': undefined method `zero?' for nil:NilClass (NoMethodError)
    from /Users/josh/.gem/ruby/2.3.1/gems/seeing_is_believing-3.1.0/bin/seeing_is_believing:6:in `<top (required)>'
    from /Users/josh/.gem/ruby/2.3.1/bin/seeing_is_believing:22:in `load'
    from /Users/josh/.gem/ruby/2.3.1/bin/seeing_is_believing:22:in `<main>'
JoshCheek commented 7 years ago

Whatever this was, it's not reproduced by this issue.