Initialize parts and callbacks hashes on first usage.
[ruby-edje.git] / src / rb_edje.c
index 3dc7110083365d97ed91eb254ac33c86752b7c88..1605ceb4a210837debf895f23feb4016b0636614 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_edje.c 288 2005-03-15 18:09:01Z tilman $
+ * $Id: rb_edje.c 307 2005-03-23 17:30:30Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
@@ -36,8 +36,11 @@ static void c_mark (RbEdje *e)
 {
        c_evas_object_mark (&e->real);
 
-       rb_gc_mark (e->parts);
-       rb_gc_mark (e->callbacks);
+       if (!NIL_P (e->parts))
+               rb_gc_mark (e->parts);
+
+       if (!NIL_P (e->callbacks))
+               rb_gc_mark (e->callbacks);
 
        if (!NIL_P (e->on_text_changed_cb))
                rb_gc_mark (e->on_text_changed_cb);
@@ -70,8 +73,8 @@ static VALUE c_new (VALUE klass, VALUE evas)
        self = Data_Make_Struct (klass, RbEdje, c_mark, c_free, edje);
 
        edje->real.real = edje_object_add (e->real);
-       edje->parts = rb_hash_new ();
-       edje->callbacks = rb_ary_new ();
+       edje->parts = Qnil;
+       edje->callbacks = Qnil;
        edje->on_text_changed_cb = Qnil;
 
        argv[0] = evas;
@@ -207,6 +210,9 @@ static VALUE c_part_get (VALUE self, VALUE name)
                return Qnil;
        }
 
+       if (NIL_P (e->parts))
+               e->parts = rb_hash_new ();
+
        if (NIL_P (part = rb_hash_aref (e->parts, name))) {
                part = TO_PART (self, name);
                rb_hash_aset (e->parts, name, part);
@@ -224,6 +230,9 @@ static void on_text_changed (void *data, Evas_Object *eo,
 
        name = rb_str_new2 (part_name);
 
+       if (NIL_P (e->parts))
+               e->parts = rb_hash_new ();
+
        if (NIL_P (part = rb_hash_aref (e->parts, name))) {
                part = TO_PART (self, name);
                rb_hash_aset (e->parts, name, part);
@@ -315,6 +324,10 @@ static VALUE c_on_signal (int argc, VALUE *argv, VALUE self)
                return Qnil;
 
        cb = rb_block_proc ();
+
+       if (NIL_P (e->callbacks))
+               e->callbacks = rb_ary_new ();
+
        rb_ary_push (e->callbacks, cb);
 
        edje_object_signal_callback_add (e->real.real,