From: Charlie Somerville Date: 2013-02-14T09:38:32+09:00 Subject: [ruby-core:52236] Re: [ruby-trunk - Feature #7839] Symbol.freeze_symbols --511c31d7_7d5e18f8_88 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Thursday, 14 February 2013 at 11:30 AM, Aaron Patterson wrote: > Yes, this is probably not thread safe, but if people *know* it's not > thread safe, then they can lock: > > begin > Symbol.lock > Symbol.freeze_symbols > YAML.load(...) > ensure > Symbol.thaw_symbols > Symbol.unlock > end I think this is a perfect contender for a block. There can be a global 'symbol_freeze_count' that is incremented when the block enters, and decremented on the way out. For example: Symbol.frozen do :foo # ok because this is symbol-ified by the parser beforehand eval ":foo" # exception "foo".to_sym # exception end This is better because it is re-entrant, unlike a pair of 'freeze' and 'thaw' methods. --511c31d7_7d5e18f8_88 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
On T= hursday, 14 =46ebruary 2013 at 11:30 AM, Aaron Patterson wrote:
Yes, this is probably not thread safe, but= if people *know* it's not
thread safe, then they can lock:

begin
Symbol.lock
= Symbol.freeze=5Fsymbols
YAML.load(...)
e= nsure
Symbol.thaw=5Fsymbols
Symbol.unlock=
end
I think this is a perfec= t contender for a block. There can be a global 'symbol=5Ffreeze=5Fcount' = that is incremented when the block enters, and decremented on the way out= .

=46or example:

  Symbol.frozen do
    :foo =23 ok beca= use this is symbol-ified by the parser beforehand
   = eval =22:foo=22 =23 exception
    =22foo=22.to=5Fsym= =23 exception
  end

This is bett= er because it is re-entrant, unlike a pair of 'freeze' and 'thaw' methods= .
--511c31d7_7d5e18f8_88--