Re: Gee Problem with TreeMap



Is it a Vala Bug?

When I test this code, there's no problem at runtime:

using Gee;

class Container : Object
{
  public Gee.TreeMap<string,Object> map = new Gee.TreeMap<string,Object> ();
}
class Space : Object
{
  public string name { get; set; }
  public Space.named (string name) { this.name = name; }
}

class App : Object
{
 
  public static int main (string[] args)
  {
    var c = new Container ();
    var o1 = new Space.named ("Big");
    var o2 = new Space.named ("Small");
    c.map.set (o1.name, o1);
    c.map.set (o2.name, o2);
    foreach (Object o in c.map.values) {
      stdout.printf (@"VALUE: $(((Space) o).name)\n");
    }
    foreach (string k in c.map.keys) {
      stdout.printf (@"KEY: $(k) : VALUE: $(((Space) c.map.get (k)).name)\n");
    }
    return 0;
  }
}


2013/11/11 Daniel Espinosa <esodan gmail com>
Please tell me what is wrong!!!!

I'm using a TreeMap as a container inside a class that need to be subclassed from other.

My problem is when I try to run my program fails to try get values and its key.

I'm using valac-0.20, even using 0.18.1.

using Gee;

class Base : Object
{
  public string name { get; set; }
}

class Manager<V> : Base
{
  private Gee.TreeMap<string,V> map = new Gee.TreeMap<string,V> ();
  public new V get (string key)
  {
    return map.get (key);
  }
  public new void set (string key, V obj)
  {
    map.set (key, obj);
  }
  public Collection<V> values { owned get { return  map.values; } }
  public Collection<string> keys { owned get { return  map.keys; } }
}

class Space : Object
{
  public string name { get; set; }
  public Space.named (string name) { this.name = name; }
}

class User : Manager<Object> {}

class App
{
  public static int main (string[] args)
  {
    var u = new User ();
    var o1 = new Space.named ("Big");
    var o2 = new Space.named ("Small");
    u.set (o1.name, o1);
    u.set (o2.name, o2);
    foreach (Object o in u.values) {
      stdout.printf (@"VALUE: $(((Space) o).name)\n");
    }
    foreach (string k in u.keys) {
      stdout.printf (@"KEY: $(k) : VALUE: $(((Space) u.get (k)).name)\n");
    }
    return 0;
  }
}

compiling using
valac-0.20 --pkg gee-0.8 container-manager.vala

and runnig gets corruption on keys and fails to get values:

$ ./container-manager
VALUE: Big
VALUE: Small

(process:29479): GLib-GObject-WARNING **: invalid unclassed pointer in cast to `Space'

** (process:29479): CRITICAL **: string_to_string: assertion `self != NULL' failed

(process:29479): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed

(process:29479): GLib-GObject-WARNING **: invalid uninstantiatable type `<invalid>' in cast to `Space'

** (process:29479): CRITICAL **: string_to_string: assertion `self != NULL' failed

(process:29479): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed

(process:29479): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed

(process:29479): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed
KEY: Big : VALUE: KEY: Small : VALUE:

--
Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (en trámite, pero para los cuates: LIBRE)

_______________________________________________
libgee-list mailing list
libgee-list gnome org
https://mail.gnome.org/mailman/listinfo/libgee-list




--
Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (en trámite, pero para los cuates: LIBRE)


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