mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* time.c (time_plus): must detect result overflow.
* time.c (time_minus): ditto. * time.c (time_new_internal): round usec overflow and underflow here. * time.c (time_plus): move operand overflow/underflow check to time_new_internal(). * time.c (time_minus): ditto. * time.c (time_cmp): should consider tv_usec too. * time.c (time_gmtime): time_modify() should be called even if tm struct is not calculated yet. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9e8553e5cc
commit
b3144a7a0e
3 changed files with 117 additions and 77 deletions
110
lib/singleton.rb
110
lib/singleton.rb
|
@ -44,60 +44,64 @@
|
|||
# of a previous state of ``the instance'' - see third example.
|
||||
#
|
||||
module Singleton
|
||||
def Singleton.included (klass)
|
||||
# should this be checked?
|
||||
# raise TypeError.new "..." if klass.type == Module
|
||||
class << klass
|
||||
def inherited(sub_klass)
|
||||
# @__instance__ takes on one of the following values
|
||||
# * nil - before (and after a failed) creation
|
||||
# * false - during creation
|
||||
# * sub_class instance - after a successful creation
|
||||
sub_klass.instance_eval { @__instance__ = nil }
|
||||
def sub_klass.instance
|
||||
unless @__instance__.nil?
|
||||
# is the extra flexiblity having the hook method
|
||||
# _wait() around ever useful?
|
||||
_wait()
|
||||
# check for instance creation
|
||||
return @__instance__ if @__instance__
|
||||
end
|
||||
Thread.critical = true
|
||||
unless @__instance__
|
||||
@__instance__ = false
|
||||
Thread.critical = false
|
||||
begin
|
||||
@__instance__ = new
|
||||
ensure
|
||||
if @__instance__
|
||||
define_method(:instance) {@__instance__ }
|
||||
else
|
||||
# failed instance creation
|
||||
@__instance__ = nil
|
||||
end
|
||||
end
|
||||
else
|
||||
Thread.critical = false
|
||||
end
|
||||
return @__instance__
|
||||
end
|
||||
end
|
||||
def _load(str)
|
||||
instance
|
||||
end
|
||||
def _wait
|
||||
sleep(0.05) while false.equal?(@__instance__)
|
||||
end
|
||||
private :new, :allocate
|
||||
# hook methods are also marked private
|
||||
private :_load,:_wait
|
||||
end
|
||||
klass.inherited klass
|
||||
end
|
||||
private
|
||||
def _dump(depth)
|
||||
return ""
|
||||
def Singleton.included (klass)
|
||||
# should this be checked?
|
||||
# raise TypeError.new "..." if klass.type == Module
|
||||
klass.module_eval {
|
||||
undef_method :clone
|
||||
undef_method :dup
|
||||
}
|
||||
class << klass
|
||||
def inherited(sub_klass)
|
||||
# @__instance__ takes on one of the following values
|
||||
# * nil - before (and after a failed) creation
|
||||
# * false - during creation
|
||||
# * sub_class instance - after a successful creation
|
||||
sub_klass.instance_eval { @__instance__ = nil }
|
||||
def sub_klass.instance
|
||||
unless @__instance__.nil?
|
||||
# is the extra flexiblity having the hook method
|
||||
# _wait() around ever useful?
|
||||
_wait()
|
||||
# check for instance creation
|
||||
return @__instance__ if @__instance__
|
||||
end
|
||||
Thread.critical = true
|
||||
unless @__instance__
|
||||
@__instance__ = false
|
||||
Thread.critical = false
|
||||
begin
|
||||
@__instance__ = new
|
||||
ensure
|
||||
if @__instance__
|
||||
define_method(:instance) {@__instance__ }
|
||||
else
|
||||
# failed instance creation
|
||||
@__instance__ = nil
|
||||
end
|
||||
end
|
||||
else
|
||||
Thread.critical = false
|
||||
end
|
||||
return @__instance__
|
||||
end
|
||||
end
|
||||
def _load(str)
|
||||
instance
|
||||
end
|
||||
def _wait
|
||||
sleep(0.05) while false.equal?(@__instance__)
|
||||
end
|
||||
private :new, :allocate
|
||||
# hook methods are also marked private
|
||||
private :_load,:_wait
|
||||
end
|
||||
klass.inherited klass
|
||||
end
|
||||
private
|
||||
def _dump(depth)
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue