Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: finalize.rb
#--
[0] Fix | Delete
# finalizer.rb -
[1] Fix | Delete
# $Release Version: 0.3$
[2] Fix | Delete
# $Revision: 1.4 $
[3] Fix | Delete
# $Date: 1998/02/27 05:34:33 $
[4] Fix | Delete
# by Keiju ISHITSUKA
[5] Fix | Delete
#++
[6] Fix | Delete
#
[7] Fix | Delete
# Usage:
[8] Fix | Delete
#
[9] Fix | Delete
# add dependency R_method(obj, dependant)
[10] Fix | Delete
# add(obj, dependant, method = :finalize, *opt)
[11] Fix | Delete
# add_dependency(obj, dependant, method = :finalize, *opt)
[12] Fix | Delete
#
[13] Fix | Delete
# delete dependency R_method(obj, dependant)
[14] Fix | Delete
# delete(obj_or_id, dependant, method = :finalize)
[15] Fix | Delete
# delete_dependency(obj_or_id, dependant, method = :finalize)
[16] Fix | Delete
#
[17] Fix | Delete
# delete dependency R_*(obj, dependant)
[18] Fix | Delete
# delete_all_dependency(obj_or_id, dependant)
[19] Fix | Delete
#
[20] Fix | Delete
# delete dependency R_method(*, dependant)
[21] Fix | Delete
# delete_by_dependant(dependant, method = :finalize)
[22] Fix | Delete
#
[23] Fix | Delete
# delete dependency R_*(*, dependant)
[24] Fix | Delete
# delete_all_by_dependant(dependant)
[25] Fix | Delete
#
[26] Fix | Delete
# delete all dependency R_*(*, *)
[27] Fix | Delete
# delete_all
[28] Fix | Delete
#
[29] Fix | Delete
# finalize the dependant connected by dependency R_method(obj, dependtant).
[30] Fix | Delete
# finalize(obj_or_id, dependant, method = :finalize)
[31] Fix | Delete
# finalize_dependency(obj_or_id, dependant, method = :finalize)
[32] Fix | Delete
#
[33] Fix | Delete
# finalize all dependants connected by dependency R_*(obj, dependtant).
[34] Fix | Delete
# finalize_all_dependency(obj_or_id, dependant)
[35] Fix | Delete
#
[36] Fix | Delete
# finalize the dependant connected by dependency R_method(*, dependtant).
[37] Fix | Delete
# finalize_by_dependant(dependant, method = :finalize)
[38] Fix | Delete
#
[39] Fix | Delete
# finalize all dependants connected by dependency R_*(*, dependant).
[40] Fix | Delete
# finalize_all_by_dependant(dependant)
[41] Fix | Delete
#
[42] Fix | Delete
# finalize all dependency registered to the Finalizer.
[43] Fix | Delete
# finalize_all
[44] Fix | Delete
#
[45] Fix | Delete
# stop invoking Finalizer on GC.
[46] Fix | Delete
# safe{..}
[47] Fix | Delete
#
[48] Fix | Delete
[49] Fix | Delete
module Finalizer
[50] Fix | Delete
RCS_ID='-$Id: finalize.rb,v 1.4 1998/02/27 05:34:33 keiju Exp keiju $-'
[51] Fix | Delete
[52] Fix | Delete
class <<self
[53] Fix | Delete
# @dependency: {id => [[dependant, method, *opt], ...], ...}
[54] Fix | Delete
[55] Fix | Delete
# add dependency R_method(obj, dependant)
[56] Fix | Delete
def add_dependency(obj, dependant, method = :finalize, *opt)
[57] Fix | Delete
ObjectSpace.call_finalizer(obj)
[58] Fix | Delete
method = method.intern unless method.kind_of?(Integer)
[59] Fix | Delete
assoc = [dependant, method].concat(opt)
[60] Fix | Delete
if dep = @dependency[obj.object_id]
[61] Fix | Delete
dep.push assoc
[62] Fix | Delete
else
[63] Fix | Delete
@dependency[obj.object_id] = [assoc]
[64] Fix | Delete
end
[65] Fix | Delete
end
[66] Fix | Delete
alias add add_dependency
[67] Fix | Delete
[68] Fix | Delete
# delete dependency R_method(obj, dependant)
[69] Fix | Delete
def delete_dependency(id, dependant, method = :finalize)
[70] Fix | Delete
id = id.object_id unless id.kind_of?(Integer)
[71] Fix | Delete
method = method.intern unless method.kind_of?(Integer)
[72] Fix | Delete
for assoc in @dependency[id]
[73] Fix | Delete
assoc.delete_if do
[74] Fix | Delete
|d, m, *o|
[75] Fix | Delete
d == dependant && m == method
[76] Fix | Delete
end
[77] Fix | Delete
@dependency.delete(id) if assoc.empty?
[78] Fix | Delete
end
[79] Fix | Delete
end
[80] Fix | Delete
alias delete delete_dependency
[81] Fix | Delete
[82] Fix | Delete
# delete dependency R_*(obj, dependant)
[83] Fix | Delete
def delete_all_dependency(id, dependant)
[84] Fix | Delete
id = id.object_id unless id.kind_of?(Integer)
[85] Fix | Delete
method = method.intern unless method.kind_of?(Integer)
[86] Fix | Delete
for assoc in @dependency[id]
[87] Fix | Delete
assoc.delete_if do
[88] Fix | Delete
|d, m, *o|
[89] Fix | Delete
d == dependant
[90] Fix | Delete
end
[91] Fix | Delete
@dependency.delete(id) if assoc.empty?
[92] Fix | Delete
end
[93] Fix | Delete
end
[94] Fix | Delete
[95] Fix | Delete
# delete dependency R_method(*, dependant)
[96] Fix | Delete
def delete_by_dependant(dependant, method = :finalize)
[97] Fix | Delete
method = method.intern unless method.kind_of?(Integer)
[98] Fix | Delete
for id in @dependency.keys
[99] Fix | Delete
delete(id, dependant, method)
[100] Fix | Delete
end
[101] Fix | Delete
end
[102] Fix | Delete
[103] Fix | Delete
# delete dependency R_*(*, dependant)
[104] Fix | Delete
def delete_all_by_dependant(dependant)
[105] Fix | Delete
for id in @dependency.keys
[106] Fix | Delete
delete_all_dependency(id, dependant)
[107] Fix | Delete
end
[108] Fix | Delete
end
[109] Fix | Delete
[110] Fix | Delete
# finalize the depandant connected by dependency R_method(obj, dependtant)
[111] Fix | Delete
def finalize_dependency(id, dependant, method = :finalize)
[112] Fix | Delete
id = id.object_id unless id.kind_of?(Integer)
[113] Fix | Delete
method = method.intern unless method.kind_of?(Integer)
[114] Fix | Delete
for assocs in @dependency[id]
[115] Fix | Delete
assocs.delete_if do
[116] Fix | Delete
|d, m, *o|
[117] Fix | Delete
d.send(m, id, *o) if ret = d == dependant && m == method
[118] Fix | Delete
ret
[119] Fix | Delete
end
[120] Fix | Delete
@dependency.delete(id) if assoc.empty?
[121] Fix | Delete
end
[122] Fix | Delete
end
[123] Fix | Delete
alias finalize finalize_dependency
[124] Fix | Delete
[125] Fix | Delete
# finalize all dependants connected by dependency R_*(obj, dependtant)
[126] Fix | Delete
def finalize_all_dependency(id, dependant)
[127] Fix | Delete
id = id.object_id unless id.kind_of?(Integer)
[128] Fix | Delete
method = method.intern unless method.kind_of?(Integer)
[129] Fix | Delete
for assoc in @dependency[id]
[130] Fix | Delete
assoc.delete_if do
[131] Fix | Delete
|d, m, *o|
[132] Fix | Delete
d.send(m, id, *o) if ret = d == dependant
[133] Fix | Delete
end
[134] Fix | Delete
@dependency.delete(id) if assoc.empty?
[135] Fix | Delete
end
[136] Fix | Delete
end
[137] Fix | Delete
[138] Fix | Delete
# finalize the dependant connected by dependency R_method(*, dependtant)
[139] Fix | Delete
def finalize_by_dependant(dependant, method = :finalize)
[140] Fix | Delete
method = method.intern unless method.kind_of?(Integer)
[141] Fix | Delete
for id in @dependency.keys
[142] Fix | Delete
finalize(id, dependant, method)
[143] Fix | Delete
end
[144] Fix | Delete
end
[145] Fix | Delete
[146] Fix | Delete
# finalize all dependants connected by dependency R_*(*, dependtant)
[147] Fix | Delete
def finalize_all_by_dependant(dependant)
[148] Fix | Delete
for id in @dependency.keys
[149] Fix | Delete
finalize_all_dependency(id, dependant)
[150] Fix | Delete
end
[151] Fix | Delete
end
[152] Fix | Delete
[153] Fix | Delete
# finalize all dependants registered to the Finalizer.
[154] Fix | Delete
def finalize_all
[155] Fix | Delete
for id, assocs in @dependency
[156] Fix | Delete
for dependant, method, *opt in assocs
[157] Fix | Delete
dependant.send(method, id, *opt)
[158] Fix | Delete
end
[159] Fix | Delete
assocs.clear
[160] Fix | Delete
end
[161] Fix | Delete
end
[162] Fix | Delete
[163] Fix | Delete
# method to call finalize_* safely.
[164] Fix | Delete
def safe
[165] Fix | Delete
old_status = Thread.critical
[166] Fix | Delete
Thread.critical = true
[167] Fix | Delete
ObjectSpace.remove_finalizer(@proc)
[168] Fix | Delete
begin
[169] Fix | Delete
yield
[170] Fix | Delete
ensure
[171] Fix | Delete
ObjectSpace.add_finalizer(@proc)
[172] Fix | Delete
Thread.critical = old_status
[173] Fix | Delete
end
[174] Fix | Delete
end
[175] Fix | Delete
[176] Fix | Delete
private
[177] Fix | Delete
[178] Fix | Delete
# registering function to ObjectSpace#add_finalizer
[179] Fix | Delete
def final_of(id)
[180] Fix | Delete
if assocs = @dependency.delete(id)
[181] Fix | Delete
for dependant, method, *opt in assocs
[182] Fix | Delete
dependant.send(method, id, *opt)
[183] Fix | Delete
end
[184] Fix | Delete
end
[185] Fix | Delete
end
[186] Fix | Delete
[187] Fix | Delete
end
[188] Fix | Delete
@dependency = Hash.new
[189] Fix | Delete
@proc = proc{|id| final_of(id)}
[190] Fix | Delete
ObjectSpace.add_finalizer(@proc)
[191] Fix | Delete
end
[192] Fix | Delete
[193] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function