Re: [Vala] List behavior with new operator



Jurg,

     This one isn't quite fixed yet (as of revision 122).  The ownership issue is fixed though.  I combined both reported List errors into one test case:


using GLib;

namespace Error1and2 {

        public class ListTest {

                public ref  List<string> listtest() {

                       // New constructor form.
                        var s = new List<string>();

                        s.append("S Number 1");
                        s.append("S Number 2");
                        s.append("S Number 3");
                        s.append("S Number 4");

                        return s;
                }
        }

        static int main(string[] args) {

                ListTest l = new ListTest();

                int x=1;
                var listtest = l.listtest();
                foreach(string s1 in listtest) {
                        stdout.printf("%d - %s\n",x++,s1);
                }

        }
}

The results are as follows:

1 - (null)
2 - S Number 1
3 - S Number 2
4 - S Number 3
5 - S Number 4

The list remains populated upon return so factory methods with lists can now be used.  But we're still getting an extra null entry in the List.

Cayle



On 9/2/06, Jürg Billeter <j bitron ch> wrote:
On Mon, 2006-08-28 at 11:52 +0200, Jürg Billeter wrote:
> On Sam, 2006-08-26 at 21:57 -0500, Cayle Graumann wrote:
> > I've discovered something:  If you use a List object, be sure not to
> > use the new operator followed by append.  It adds a null object to the
> > list, that will cause you to get failed assertions when you iterate
> > through the List.
> [...]
> > I don't know if this is something fixable in Vala because it seems the
> > result of the way GList is implemented in GLib, but maybe something
> > can be done with the new operator so as not to actually create a null
> > object.  I would image this behavior holds true for some of the other
> > GLib container classes as well.
>
> Will probably special case the constructor of GList and GSList to just
> return null, thanks for the report.

Fixed in SVN.

Jürg




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]