|
From: Kentaro F. <ke...@fu...> - 2013-05-11 17:07:56
|
Clutter バインディングを色々試していて、ちょっとおかしな挙動を見付け
ました。
clutter-color.c では、from_hls や from_string という関数が定義されています。
void clutter_color_from_string(ClutterColor *color, const gchar *str)
この第一引数には out 属性が付与されており、caller-allocates として処理
されています。実際、gir を見るとメソッドではなく関数として定義されて
います。
ところが何が悪いのか、Ruby 側では Clutter::Color.from_string() は引数
を String 一つのみ要求しており、上記定義とは異なっています。
この from_string に適当な文字列(例: "rgba(0, 0, 0, 0)")を与えると
Segmentation Fault を引き起こします。同様の問題が from_hls の方でも
起きています。
Ruby での Gobject introspection の扱いがよくわかっていないのですが、
第一引数が、クラスメソッドが定義されているクラスと同じクラスで、
かつ caller-allocates の時に、なにか問題が起きているのではないで
しょうか。
なお、clutter/color.rb では
def hlsa(hue, luminance, saturation, alpha)
color = new(0,0,0,0)
color.from_hls(hue, luminance, saturation)
color.alpha = alpha
color
end
というクラスメソッドが定義されていますが、from_hls がクラスメソッド
として処理されているため、method が見付からないというエラーが出てい
ます。
irb(main):001:0> require 'clutter'
=> true
irb(main):002:0> Clutter.init
=> true
irb(main):003:0> Clutter::Color.hls(0, 0,0)
NoMethodError: undefined method `from_hls' for #<Clutter::Color:0x318d2d0 ptr=0x1895fb0 own=true>
from /var/lib/gems/1.9.1/gems/clutter-2.0.0/lib/clutter/color.rb:43:in `hlsa'
from /var/lib/gems/1.9.1/gems/clutter-2.0.0/lib/clutter/color.rb:38:in `hls'
from (irb):3
from /usr/bin/irb1.9.1:12:in `<main>'
#私としては from_* みたいなクラスメソッドは clutter 側で、callee-allocates
#で実装するのがこの場合の筋だとは思いますが。
こちらの環境は
Ubuntu 12.10
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
libclutter-1.0-0 - version 1.12.0-0ubuntu1
Ruby/gobject-introspection, Ruby/clutter - version 2.0.0 (gem最新版)
となっております。
また、上記以外で、サンプルが動かなかったものについて修正を試みた
ものがあります。
https://github.com/fukuchi/ruby-gnome2/commit/6628e038891d9a77832c47ddc93c52c8ef5a2d4c#clutter/sample/canvas.rb
https://github.com/fukuchi/ruby-gnome2/commit/9655f1e60f23e3bf8080007c700ba542f4d954cb#clutter/sample/drop-action.rb
これらの挙動は、もしかして git 最新版では異なるものでしょうか?
----------------------------------------------------------
Kentaro FUKUCHI | 福地健太郎 (明治大学総合数理学部 准教授)
E-mail: ke...@fu...
Web: http://fukuchi.org/
研究室: http://fukuchilab.org/
|