Backport #8238

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

Added by Mark Titorenko about 1 year ago. Updated 8 months ago.

[ruby-core:54105]
Status:Closed
Priority:High
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 42726
Added by Tomoyuki Chikanaga 8 months 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 1 year ago

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

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 1 year 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 8 months ago

  • Target version set to 2.1.0

#4 Updated by Nobuyoshi Nakada 8 months 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

  • vminsnhelper.c (vmcall_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 8 months 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 8 months 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