From: Kazuhiro N. <zn...@mb...> - 2004-03-14 12:23:23
|
西山和広です。 In <200...@mb...> On Sun, 14 Mar 2004 20:50:07 +0900 Kazuhiro NISHIYAMA <zn...@mb...> wrote: > とりあえず気がついた範囲内でgconfd-2が落ちないようにすることを > 優先するパッチだったので書き忘れていたのですが、 > > * 空のlistをセットできない(list_typeが決まらない) > * 長さ2のlistがセットできない(必ずpairになる) > > という問題があります。 > > 調べていて気づいたのですが、pairというのは > # http://www.gnome.gr.jp/docs/gconf-1.0.x-refs/gconf-gconf-value.html > | GCONF_VALUE_PAIR GConfValue のペアです。つまり最初の > | フィールド (car) と二番目のフィールド (cdr) は異なる型を > | 持ちます。 > ということであのパッチで長さ2のリストをpairにするように > してしまったのは間違いでした。すいません。 > > それから > | GCONF_VALUE_LIST GConfValue の並びです。つまり、 > | GConfValue の要素はプリミティブな型(リストでもペアでも > | ない)で、全ての要素は同じ型でなければなりません。 > ということでネストした配列が通ってしまうのもダメだったようです。 このあたりを直してみました。 空のlistをセットできないというのはそのままです。 pairかlistかどうかをrubyレベルで取得できないので unittest.rbでちゃんとpairやlistとしてセットできているか どうかのテストが出来ていません。 =================================================================== RCS file: /cvsroot/ruby-gnome2/ruby-gnome2/gconf/src/rbgconf-util.c,v retrieving revision 1.5 diff -u -p -r1.5 rbgconf-util.c --- src/rbgconf-util.c 14 Mar 2004 01:19:24 -0000 1.5 +++ src/rbgconf-util.c 14 Mar 2004 11:53:12 -0000 @@ -55,6 +55,16 @@ rb_ary_to_gconfval_list(ary_val, list_ty Check_Type(ary_val, T_ARRAY); n = RARRAY(ary_val)->len; for (i = 0; i < n; i++) { + if (TYPE(rb_ary_entry(ary_val, i)) == T_ARRAY) { + GSList *i; + for (i = list; i != NULL; i = i->next) { + gconf_value_free((GConfValue *)i->data); + } + g_slist_free(list); + + rb_raise(rb_eArgError, + "must not be nested array"); + } val = rb_value_to_gconf_value(rb_ary_entry(ary_val, i)); /* uh, oh. not all elements were of the same type. */ @@ -103,15 +113,10 @@ rb_value_to_gconf_value(val) GSList *list; list = rb_ary_to_gconfval_list(val, &type); - if (type == GCONF_VALUE_INVALID) { - GSList *i; - for (i = list; i != NULL; i = i->next) { - gconf_value_free((GConfValue *)i->data); - } - g_slist_free(list); - - rb_raise(rb_eArgError, - "all elements must be of same type"); + if (type != GCONF_VALUE_INVALID) { + gval = gconf_value_new(GCONF_VALUE_LIST); + gconf_value_set_list_type(gval, type); + gconf_value_set_list_nocopy(gval, list); } else if (g_slist_length(list) == 2) { gval = gconf_value_new(GCONF_VALUE_PAIR); gconf_value_set_car_nocopy(gval, @@ -120,9 +125,14 @@ rb_value_to_gconf_value(val) (GConfValue *)g_slist_nth_data(list, 1)); g_slist_free(list); } else { - gval = gconf_value_new(GCONF_VALUE_LIST); - gconf_value_set_list_type(gval, type); - gconf_value_set_list_nocopy(gval, list); + GSList *i; + for (i = list; i != NULL; i = i->next) { + gconf_value_free((GConfValue *)i->data); + } + g_slist_free(list); + + rb_raise(rb_eArgError, + "all elements must be of same type"); } break; } Index: tests/unittest.rb =================================================================== RCS file: /cvsroot/ruby-gnome2/ruby-gnome2/gconf/tests/unittest.rb,v retrieving revision 1.1 diff -u -p -r1.1 unittest.rb --- tests/unittest.rb 14 Mar 2004 01:19:24 -0000 1.1 +++ tests/unittest.rb 14 Mar 2004 11:53:12 -0000 @@ -55,13 +55,6 @@ class TestDigest < Test::Unit::TestCase end def test_pair - t([true, false]) - t(%w(foo bar)) - t([1, 2]) - t([0.5, 0.25]) - end - - def test_invalid_pair ae([0.5, 1]) ae([1, 1.5]) ae([true, "foo"]) @@ -69,19 +62,35 @@ class TestDigest < Test::Unit::TestCase ae([true, 0]) end + def test_invalid_pair + ae([[1, 2], [3, 4]]) + ae([[1, 2.0], [3, 4.0]]) + ae([1, [2, 3.0]]) + ae([[1, 2.0], 3.0]) + end + def test_empty_array ae([]) end def test_array + t([true, false]) + t(%w(foo bar)) + t([1, 2]) + t([0.5, 0.25]) t([true,false,true]) - ae([true, 1, 2.0]) - ae([true,false,[true]]) t(%w(foo bar baz)) t([1, 2, 3]) t([1.0, 2.0, 3.0]) + end + + def test_invalid_array + ae([true, 1, 2.0]) + ae([true,false,[true]]) ae([1, 2.0, 3]) ae([1.0, 2, 3.0]) + ae([[1, 2], [3, 4], [5, 6]]) + ae([1, 2, [3, 4], [5, 6]]) end def test_unset -- |ZnZ(ゼット エヌ ゼット) |西山和広(Kazuhiro NISHIYAMA) |