Use ecore_evas_data_set/get to store a pointer to self.
authorTilman Sauerbeck <tilman@code-monkey.de>
Thu, 2 Sep 2004 17:06:54 +0000 (17:06 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 2 Sep 2004 17:06:54 +0000 (17:06 +0000)
This means the global objects hash isn't needed anymore.

src/ecore_evas/rb_ecore_evas.c

index 2cd312577dcffd45d8596c4ba3e90c58f52d0a7d..9b2ad29a2bd77a657f19c8c1a6b75dff4aaac389 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_ecore_evas.c 77 2004-08-19 17:39:29Z tilman $
+ * $Id: rb_ecore_evas.c 110 2004-09-02 17:06:54Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
 #include "rb_ecore_evas_main.h"
 #include "rb_ecore_evas.h"
 
+#define RUBY_ECORE_EVAS_KEY "__RB_ECORE_EVAS_KEY"
+
 #define CALLBACK_DEFINE_HANDLER(name) \
        static void on_##name (Ecore_Evas *real) \
        { \
-               VALUE self = rb_hash_aref (objects, INT2NUM ((long) real)); \
+               VALUE self; \
                VALUE cb; \
 \
+               self = (VALUE) ecore_evas_data_get (real, \
+                                                   RUBY_ECORE_EVAS_KEY); \
                GET_OBJ (self, RbEcoreEvas, ee); \
 \
                cb = rb_hash_aref (ee->callbacks, rb_str_new2 (#name)); \
@@ -56,7 +60,6 @@
                return Qnil;
 
 VALUE cEcoreEvas;
-static VALUE objects;
 
 /* called by the child classes */
 void c_ecore_evas_mark (RbEcoreEvas *ee)
@@ -87,7 +90,7 @@ static VALUE c_init (int argc, VALUE *argv, VALUE self)
        ee->evas = Qnil;
        ee->callbacks = rb_hash_new ();
 
-       rb_hash_aset (objects, INT2NUM ((long) ee->real), self);
+       ecore_evas_data_set (ee->real, RUBY_ECORE_EVAS_KEY, (void *) self);
 
        return Qnil;
 }
@@ -526,7 +529,6 @@ static VALUE c_delete (VALUE self)
        rb_gc_start ();
 
        ecore_evas_free (ee->real);
-       rb_hash_aset (objects, INT2NUM ((long) ee->real), Qnil);
        ee->real = NULL;
 
        return Qnil;
@@ -724,7 +726,4 @@ void Init_EcoreEvas (void)
        rb_define_method (cEcoreEvas, "on_mouse_out", c_on_mouse_out, 0);
        rb_define_method (cEcoreEvas, "on_pre_render", c_on_pre_render, 0);
        rb_define_method (cEcoreEvas, "on_post_render", c_on_post_render, 0);
-
-       objects = rb_hash_new ();
-       rb_global_variable (&objects);
 }