From: "mame (Yusuke Endoh)" Date: 2012-12-12T21:28:26+09:00 Subject: [ruby-dev:46729] [ruby-trunk - Feature #6993] Class#allocate の仕様変更(Cレベル) Issue #6993 has been updated by mame (Yusuke Endoh). @agrimm: Thank you for the reporting! My understanding is that this issue will be fixed in the ruby-prof side. So, currently, we plan to include this incompatibility "as is" in Ruby 2.0.0. But, if the impact is bigger than we expect (i.e., if this affects other existing code except ruby-prof), we may revert this. Note that we can NOT fix this incompatibility just by restoring the ID_ALLOCATOR macro definition. As far as I know, this is a side effect of the improvement of class allocation. But sorry, I don't understand the improvement itself in depth. -- Yusuke Endoh ---------------------------------------- Feature #6993: Class#allocate の仕様変更(Cレベル) https://bugs.ruby-lang.org/issues/6993#change-34659 Author: ko1 (Koichi Sasada) Status: Closed Priority: Normal Assignee: nobu (Nobuyoshi Nakada) Category: core Target version: 2.0.0 =begin  ささだです.  現在,Class#new を呼び出すと,Class#allocate が呼ばれます.Class#allocate は,次のような特徴を持つ,ちょっと特殊なメソッドになっています. * 普通に定義しても Class#new からは使われない * 実際に動かす処理 func は rb_define_alloc_func(klass, func) として登録する * func は ID_ALLOCATOR という特殊なメソッド名で登録される(対応するシンボル名はなし,つまり rb_id2name(ID_ALLOCATOR) は NULL を返す * func は rb_funcall(klass, ID_ALLOCATOR, ...) で呼ばれる これは,変な allocator を定義出来ないようにするための処置だったと思います(多分). 他にも, * backtrace には現れない * set_trace_func ではスキップする という特殊な処理をしており,Ruby からは見えないようになっています.ただし,set_trace_func には現れませんが,C で trace_func を登録すると呼べてしまう,という中途半端な感じになっています. これについて,中田さんと協議したんですが,そもそも allocator function はメソッド呼び出し(rb_funcall)で呼ばないでもいいんでないか,という結論を得ました.具体的には,rb_classext_t に allocator function を登録するようにして,それを呼び出す,ということになります. あり得る問題点としては,allocator function から super が出来ない,という話がありました.ただし,そんなことやる奴はいないだろう,ということで allocator function の制限とするのがいいのではないか,という議論になりました. 副次的な効果として,allocator function のためにメソッドフレームを積む必要がなくなり,ユーザ定義クラスの生成が若干速くなる,ということがあります. なお,もう一方の選択肢としては,allocator function を backtrace や set_trace_func などで特別扱いしない,というものがありましたが,今まで見えなかったものが見えると互換性的にまずいかもしれない,という話がありました. というわけで,こんな感じで(中田さんが)進めようと思うのですが,何かお気づきの点がありましたらご指摘下さい. =end -- http://bugs.ruby-lang.org/