カビゴン餌やり失敗部
This account is not set to public on notestock.
ATR音素バランス文「あらゆる現実をすべて自分の方へねじ曲げたのだ」の出典がしれっと明らかにされてる!!!
https://ja.shuheikato.info/other/atr503_source
USE_FLONUMが落ちてる場合は20 (0x14) が特殊値じゃなくなる https://github.com/ruby/ruby/blob/1a6a7c699c4f66396d3f314423fee515ab8b4b19/include/ruby/internal/special_consts.h#L97-L117
で、USE_FLONUMはsizeof(*void) >= sizeof(double) の時に立つので、実質的に64bit判定みたいになってる
https://github.com/ruby/ruby/blob/1a6a7c699c4f66396d3f314423fee515ab8b4b19/include/ruby/internal/special_consts.h#L44-L48
つまり32bit環境でObjectSpace._id2ref(20)が返してくるのはたまたまこのIDが振られた普通のインスタンスで、これが Encoding::UTF_8っぽい
__id__の実装見つからないんだけどどうなってるんだろう。なんか実際のVALUEから上位bitをクリアしてそうな気がするけど
@ahiru そう。Rubyは内部的に(void*)を同じ大きさの整数 (unsigned longかunsigned long long) として扱ってて、さらに動的に確保するメモリのアドレスは必ず下位8bitが0になるようにアラインメントしてる。そうすることで逆に下位8bitがセットされてたら特殊値を表すことにして、小さい整数やプリミティブ分の容量を節約してる
Encoding::UTF_8が小さいidなのは、文字列を作るとString.encodingとしてEncoding::UTF_8が必要になることが影響していると思うけど詳しいことはよくわからん
マジかこれ、いつからだ?
> Unlike in the old days,
* an object's object ID (that a user can query using `Object#object_id`)
* is no longer its physical address represented using Ruby level integers.
* It is now a monotonic-increasing integer unrelated to the underlying
* memory arrangement.
id_table.cってやつがそれっぽいから9年前?ていうかRubyの仕組みを真面目に勉強してたのそんなに前なのか……
https://github.com/ruby/ruby/blame/1a6a7c699c4f66396d3f314423fee515ab8b4b19/id_table.c
object_idの仕様は2.xのどこかで変わったらしい(なんで曖昧なんだよ)
> In the old
* days this function was a purely arithmetic operation that maps the
* underlying memory address where the object resides into a Ruby's integer.
* Some time around 2.x this changed.