Backport #8238

Prepending any module to DateTime causes infiinite loop when using zone-related methods

Added by Mark Titorenko about 2 years ago. Updated almost 2 years ago.

[ruby-core:54105]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

Description

Prepending a Module to DateTime and then inspecting or trying to use any of the methods associated with the timezone causes what appears to be an inifinite loop.

The following code demonstrates the issue:

require 'date'
DateTime.instance_eval { prepend Module.new }
DateTime.now.offset

A cursory inspection shows that similar results (or lack of!) are yielded from #zone, #hour, #minute etc. though #year, #month and #day appear unaffected:

2.0.0p0 :001 > require 'date'
=> true
2.0.0p0 :002 > DateTime.instance_eval { prepend Module.new }
=> DateTime
2.0.0p0 :003 > d = DateTime.now; nil
=> nil
2.0.0p0 :004 > d.year
=> 2013
2.0.0p0 :005 > d.month
=> 4
2.0.0p0 :006 > d.day
=> 8
2.0.0p0 :007 > d.minute
C

Associated revisions

Revision 42724
Added by Nobuyoshi Nakada almost 2 years ago

vm_insnhelper.c: fix zsuper in prepended

  • vm_insnhelper.c (vm_call_method): a method entry refers the based class/module, so should search superclass from the origin i-class where the entry belongs to, to get rid of infinite loop when zsuper in a prepended class/module. [Bug #8238]

Revision 42726
Added by Tomoyuki Chikanaga almost 2 years ago

merge revision(s) 42724: [Backport #8238]

* vm_insnhelper.c (vm_call_method): a method entry refers the based
  class/module, so should search superclass from the origin i-class
  where the entry belongs to, to get rid of infinite loop when zsuper
  in a prepended class/module.   [Bug #8238]

History

#1 Updated by Tomoyuki Chikanaga about 2 years ago

  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to Nobuyoshi Nakada
  • Priority changed from Normal to 5

Hello, Mark
Thank you for your reporting.

I can reproduce it with trunk(r40190) and 2.0.0-dev(patchlevel 120) and wrote smaller reproducive code. It is not an issue of Date/DateTime but method search.

class A
def m
end
private :m
end

class B < A
public :m
prepend Module.new
end

B.new.m

#2 Updated by Mark Titorenko about 2 years ago

nagachika san

Thank you for your further diagnosis of this problem. A method search issue certainly sounds like it warrants a High priority! I am working around my particular instance of this problem by falling back to an include approach for now.

Cheers,

Mark.

#3 Updated by Yui NARUSE almost 2 years ago

  • Target version set to 2.1.0

#4 Updated by Nobuyoshi Nakada almost 2 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42724.
Mark, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


vm_insnhelper.c: fix zsuper in prepended

  • vm_insnhelper.c (vm_call_method): a method entry refers the based class/module, so should search superclass from the origin i-class where the entry belongs to, to get rid of infinite loop when zsuper in a prepended class/module. [Bug #8238]

#5 Updated by Tomoyuki Chikanaga almost 2 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby trunk to Backport200
  • Category deleted (core)
  • Status changed from Closed to Assigned
  • Assignee changed from Nobuyoshi Nakada to Tomoyuki Chikanaga
  • Target version deleted (2.1.0)

#6 Updated by Tomoyuki Chikanaga almost 2 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r42726.
Mark, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 42724: [Backport #8238]

* vm_insnhelper.c (vm_call_method): a method entry refers the based
  class/module, so should search superclass from the origin i-class
  where the entry belongs to, to get rid of infinite loop when zsuper
  in a prepended class/module.   [Bug #8238]

Also available in: Atom PDF