From ff457c57c3ac469622c2fcd6bf9e66a55c1df678 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Fri, 10 Feb 2006 18:14:08 +0000 Subject: [PATCH] Class instantiation fixes. --- src/rb_evas.c | 20 +++++++++++----- src/rb_evas_object.c | 18 +++++++++++--- src/rb_evas_object.h | 5 +--- src/rb_gradient.c | 22 +++++------------ src/rb_image.c | 20 ++++------------ src/rb_line.c | 20 ++++------------ src/rb_polygon.c | 20 ++++------------ src/rb_rectangle.c | 20 ++++------------ src/rb_smart.c | 56 +++++++++++++++----------------------------- src/rb_text.c | 20 ++++------------ 10 files changed, 80 insertions(+), 141 deletions(-) diff --git a/src/rb_evas.c b/src/rb_evas.c index 96d26de..f1b433f 100644 --- a/src/rb_evas.c +++ b/src/rb_evas.c @@ -1,5 +1,5 @@ /* - * $Id: rb_evas.c 283 2005-03-15 17:59:03Z tilman $ + * $Id: rb_evas.c 354 2006-02-10 18:14:08Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -34,21 +34,27 @@ static void c_mark (RbEvas *e) rb_gc_mark (e->parent); } +static VALUE c_alloc (VALUE klass) +{ + RbEvas *evas = NULL; + + return Data_Make_Struct (cEvas, RbEvas, c_mark, free, evas); +} + VALUE TO_EVAS (VALUE parent, Evas *e) { VALUE self; - RbEvas *evas = NULL; if (NIL_P (parent) || !e) return Qnil; - self = Data_Make_Struct (cEvas, RbEvas, - c_mark, free, evas); + self = rb_class_new_instance (0, NULL, cEvas); + + GET_OBJ (self, RbEvas, evas); + evas->real = e; evas->parent = parent; - rb_obj_call_init (self, 0, NULL); - return self; } @@ -329,6 +335,8 @@ void Init_Evas (void) { cEvas = rb_define_class_under (mEvas, "Evas", rb_cObject); + rb_define_alloc_func (cEvas, c_alloc); + /* not publically instantiable yet */ rb_define_private_method (rb_singleton_class (cEvas), "new", NULL, 0); diff --git a/src/rb_evas_object.c b/src/rb_evas_object.c index 22b0315..a35477a 100644 --- a/src/rb_evas_object.c +++ b/src/rb_evas_object.c @@ -1,5 +1,5 @@ /* - * $Id: rb_evas_object.c 350 2006-02-08 21:13:34Z tilman $ + * $Id: rb_evas_object.c 354 2006-02-10 18:14:08Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -66,6 +66,19 @@ void c_evas_object_free (RbEvasObject *e, bool free_mem) free (e); } +static void c_free (RbEvasObject *e) +{ + c_evas_object_free (e, true); +} + +static VALUE c_alloc (VALUE klass) +{ + RbEvasObject *e; + + return Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark, + c_free, e); +} + /* :nodoc: */ static VALUE c_init (VALUE self, VALUE parent) { @@ -565,8 +578,7 @@ void Init_EvasObject (void) cEvasObject = rb_define_class_under (mEvas, "EvasObject", rb_cObject); - rb_define_private_method (rb_singleton_class (cEvasObject), - "new", NULL, 0); + rb_define_alloc_func (cEvasObject, c_alloc); rb_define_method (cEvasObject, "initialize", c_init, 1); rb_define_method (cEvasObject, "inspect", c_inspect, 0); rb_define_method (cEvasObject, "type", c_type_get, 0); diff --git a/src/rb_evas_object.h b/src/rb_evas_object.h index 99e0743..fb08ed0 100644 --- a/src/rb_evas_object.h +++ b/src/rb_evas_object.h @@ -1,5 +1,5 @@ /* - * $Id: rb_evas_object.h 304 2005-03-22 17:51:51Z tilman $ + * $Id: rb_evas_object.h 354 2006-02-10 18:14:08Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -34,9 +34,6 @@ typedef struct { void Init_EvasObject (void); -void c_evas_object_free (RbEvasObject *e, bool free_mem); -void c_evas_object_mark (RbEvasObject *e); - VALUE TO_EVAS_OBJECT (Evas_Object *o); #ifndef __RB_EVAS_OBJECT_C diff --git a/src/rb_gradient.c b/src/rb_gradient.c index 2129e01..0b31640 100644 --- a/src/rb_gradient.c +++ b/src/rb_gradient.c @@ -1,5 +1,5 @@ /* - * $Id: rb_gradient.c 58 2004-08-10 14:10:02Z tilman $ + * $Id: rb_gradient.c 354 2006-02-10 18:14:08Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -26,31 +26,21 @@ #include "rb_evas.h" #include "rb_evas_object.h" -static void c_free (RbEvasObject *e) -{ - c_evas_object_free (e, true); -} - /* * call-seq: * Evas::Gradient.new(evas) => gradient * * Creates an Evas::Gradient object. */ -static VALUE c_new (VALUE klass, VALUE evas) +static VALUE c_init (VALUE self, VALUE evas) { - VALUE self, argv[1]; - RbEvasObject *rect; - CHECK_CLASS (evas, cEvas); GET_OBJ (evas, RbEvas, e); + GET_OBJ (self, RbEvasObject, grad); - self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark, - c_free, rect); - rect->real = evas_object_gradient_add (e->real); + grad->real = evas_object_gradient_add (e->real); - argv[0] = evas; - rb_obj_call_init (self, 1, argv); + rb_call_super (1, &evas); return self; } @@ -128,7 +118,7 @@ void Init_Gradient (void) { VALUE c = rb_define_class_under (mEvas, "Gradient", cEvasObject); - rb_define_singleton_method (c, "new", c_new, 1); + rb_define_method (c, "initialize", c_init, 1); rb_define_method (c, "add_color", c_add_color, 5); rb_define_method (c, "clear_colors", c_clear_colors, 0); rb_define_method (c, "angle", c_angle_get, 0); diff --git a/src/rb_image.c b/src/rb_image.c index 7bd0f06..8e7f5ed 100644 --- a/src/rb_image.c +++ b/src/rb_image.c @@ -1,5 +1,5 @@ /* - * $Id: rb_image.c 284 2005-03-15 18:00:33Z tilman $ + * $Id: rb_image.c 354 2006-02-10 18:14:08Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -26,31 +26,21 @@ #include "rb_evas.h" #include "rb_evas_object.h" -static void c_free (RbEvasObject *e) -{ - c_evas_object_free (e, true); -} - /* * call-seq: * Evas::Image.new(evas) => img * * Creates an Evas::Image object. */ -static VALUE c_new (VALUE klass, VALUE evas) +static VALUE c_init (VALUE self, VALUE evas) { - VALUE self, argv[1]; - RbEvasObject *img; - CHECK_CLASS (evas, cEvas); GET_OBJ (evas, RbEvas, e); + GET_OBJ (self, RbEvasObject, img); - self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark, - c_free, img); img->real = evas_object_image_add (e->real); - argv[0] = evas; - rb_obj_call_init (self, 1, argv); + rb_call_super (1, &evas); return self; } @@ -269,7 +259,7 @@ void Init_Image (void) { VALUE c = rb_define_class_under (mEvas, "Image", cEvasObject); - rb_define_singleton_method (c, "new", c_new, 1); + rb_define_method (c, "initialize", c_init, 1); rb_define_method (c, "get_file", c_get_file, -1); rb_define_method (c, "set_file", c_set_file, -1); rb_define_method (c, "has_alpha?", c_has_alpha_get, 0); diff --git a/src/rb_line.c b/src/rb_line.c index 59986df..8600d22 100644 --- a/src/rb_line.c +++ b/src/rb_line.c @@ -1,5 +1,5 @@ /* - * $Id: rb_line.c 49 2004-08-01 10:17:39Z tilman $ + * $Id: rb_line.c 354 2006-02-10 18:14:08Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -26,25 +26,15 @@ #include "rb_evas.h" #include "rb_evas_object.h" -static void c_free (RbEvasObject *e) +static VALUE c_init (VALUE self, VALUE evas) { - c_evas_object_free (e, true); -} - -static VALUE c_new (VALUE klass, VALUE evas) -{ - VALUE self, argv[1]; - RbEvasObject *line; - CHECK_CLASS (evas, cEvas); GET_OBJ (evas, RbEvas, e); + GET_OBJ (self, RbEvasObject, line); - self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark, - c_free, line); line->real = evas_object_line_add (e->real); - argv[0] = evas; - rb_obj_call_init (self, 1, argv); + rb_call_super (1, &evas); return self; } @@ -82,7 +72,7 @@ void Init_Line (void) { VALUE c = rb_define_class_under (mEvas, "Line", cEvasObject); - rb_define_singleton_method (c, "new", c_new, 1); + rb_define_method (c, "initialize", c_init, 1); rb_define_method (c, "get_xy", c_get_xy, 0); rb_define_method (c, "set_xy", c_set_xy, 4); } diff --git a/src/rb_polygon.c b/src/rb_polygon.c index 9a8913c..39f1daf 100644 --- a/src/rb_polygon.c +++ b/src/rb_polygon.c @@ -1,5 +1,5 @@ /* - * $Id: rb_polygon.c 58 2004-08-10 14:10:02Z tilman $ + * $Id: rb_polygon.c 354 2006-02-10 18:14:08Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -26,31 +26,21 @@ #include "rb_evas.h" #include "rb_evas_object.h" -static void c_free (RbEvasObject *e) -{ - c_evas_object_free (e, true); -} - /* * call-seq: * Evas::Polygon.new(evas) => polygon * * Creates an new Evas::Polygon object. */ -static VALUE c_new (VALUE klass, VALUE evas) +static VALUE c_init (VALUE self, VALUE evas) { - VALUE self, argv[1]; - RbEvasObject *poly; - CHECK_CLASS (evas, cEvas); GET_OBJ (evas, RbEvas, e); + GET_OBJ (self, RbEvasObject, poly); - self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark, - c_free, poly); poly->real = evas_object_polygon_add (e->real); - argv[0] = evas; - rb_obj_call_init (self, 1, argv); + rb_call_super (1, &evas); return self; } @@ -92,7 +82,7 @@ void Init_Polygon (void) { VALUE c = rb_define_class_under (mEvas, "Polygon", cEvasObject); - rb_define_singleton_method (c, "new", c_new, 1); + rb_define_method (c, "initialize", c_init, 1); rb_define_method (c, "add_point", c_add_point, 2); rb_define_method (c, "clear_points", c_clear_points, 0); } diff --git a/src/rb_rectangle.c b/src/rb_rectangle.c index bf32908..e3d8ca1 100644 --- a/src/rb_rectangle.c +++ b/src/rb_rectangle.c @@ -1,5 +1,5 @@ /* - * $Id: rb_rectangle.c 58 2004-08-10 14:10:02Z tilman $ + * $Id: rb_rectangle.c 354 2006-02-10 18:14:08Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -26,31 +26,21 @@ #include "rb_evas.h" #include "rb_evas_object.h" -static void c_free (RbEvasObject *e) -{ - c_evas_object_free (e, true); -} - /* * call-seq: * Evas::Rectangle.new(evas) => rect * * Creates an Evas::Rectangle object. */ -static VALUE c_new (VALUE klass, VALUE evas) +static VALUE c_init (VALUE self, VALUE evas) { - VALUE self, argv[1]; - RbEvasObject *rect; - CHECK_CLASS (evas, cEvas); GET_OBJ (evas, RbEvas, e); + GET_OBJ (self, RbEvasObject, rect); - self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark, - c_free, rect); rect->real = evas_object_rectangle_add (e->real); - argv[0] = evas; - rb_obj_call_init (self, 1, argv); + rb_call_super (1, &evas); return self; } @@ -59,5 +49,5 @@ void Init_Rectangle (void) { VALUE c = rb_define_class_under (mEvas, "Rectangle", cEvasObject); - rb_define_singleton_method (c, "new", c_new, 1); + rb_define_method (c, "initialize", c_init, 1); } diff --git a/src/rb_smart.c b/src/rb_smart.c index b9379e0..4abce29 100644 --- a/src/rb_smart.c +++ b/src/rb_smart.c @@ -1,5 +1,5 @@ /* - * $Id: rb_smart.c 68 2004-08-16 15:42:19Z tilman $ + * $Id: rb_smart.c 354 2006-02-10 18:14:08Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -26,23 +26,9 @@ #include "rb_evas.h" #include "rb_evas_object.h" -#define RUBY_EVAS_SMART_OBJECT_KEY "__RB_EVAS_OBJECT_SMART_OBJECT" - -#define GET_EVAS_OBJECT(obj, o) \ - VALUE (obj); \ -\ - obj = (VALUE) evas_object_data_get (o, \ - RUBY_EVAS_SMART_OBJECT_KEY); \ - if (!obj) { \ - rb_raise (rb_eException, \ - "EvasObject Ruby object key missing"); \ - return; \ - } - #define SMART_CB_BODY(name) \ + VALUE self = TO_EVAS_OBJECT (o); \ static ID id; \ -\ - GET_EVAS_OBJECT (self, o); \ \ if (!id) \ id = rb_intern ("on_"#name); \ @@ -98,20 +84,25 @@ static void on_color_set (Evas_Object *o, int r, int g, int b, int a) INT2FIX (a)); } +static VALUE c_alloc (VALUE klass) +{ + Evas_Smart **smart = NULL; + + return Data_Make_Struct (klass, Evas_Smart *, NULL, free, smart); +} + /* * call-seq: * Evas::Smart.new(name) => smart * * Creates a Evas::Smart object with the given name. */ -static VALUE c_new (VALUE klass, VALUE name) +static VALUE c_init (VALUE self, VALUE name) { - VALUE self; - Evas_Smart **smart; + GET_OBJ (self, Evas_Smart *, smart); Check_Type (name, T_STRING); - self = Data_Make_Struct (klass, Evas_Smart *, NULL, free, smart); *smart = evas_smart_new (StringValuePtr (name), NULL, on_delete, on_layer_set, on_raise, on_lower, on_stack_above, @@ -119,16 +110,9 @@ static VALUE c_new (VALUE klass, VALUE name) on_show, on_hide, on_color_set, on_clip_set, on_clip_unset, NULL); - rb_obj_call_init (self, 0, NULL); - return self; } -static void c_object_free (RbEvasObject *e) -{ - c_evas_object_free (e, true); -} - /* * call-seq: * smart.new_object(class, evas) => smart_obj @@ -137,23 +121,20 @@ static void c_object_free (RbEvasObject *e) */ static VALUE c_new_object (VALUE self, VALUE klass, VALUE evas) { - VALUE obj, argv[1]; - RbEvasObject *smart; + VALUE obj; CHECK_CLASS (evas, cEvas); GET_OBJ (evas, RbEvas, e); GET_OBJ (self, Evas_Smart *, s); - obj = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark, - c_object_free, smart); - smart->real = evas_object_smart_add (e->real, *s); + obj = rb_obj_alloc (klass); - evas_object_data_set (smart->real, RUBY_EVAS_SMART_OBJECT_KEY, - (void *) obj); + GET_OBJ (obj, RbEvasObject, smart); + + smart->real = evas_object_smart_add (e->real, *s); - argv[0] = evas; - rb_obj_call_init (obj, 1, argv); + rb_obj_call_init (obj, 1, &evas); return obj; } @@ -162,6 +143,7 @@ void Init_Smart (void) { VALUE c = rb_define_class_under (mEvas, "Smart", rb_cObject); - rb_define_singleton_method (c, "new", c_new, 1); + rb_define_alloc_func (c, c_alloc); + rb_define_method (c, "initialize", c_init, 1); rb_define_method (c, "new_object", c_new_object, 2); } diff --git a/src/rb_text.c b/src/rb_text.c index 431e8ed..14b22fa 100644 --- a/src/rb_text.c +++ b/src/rb_text.c @@ -1,5 +1,5 @@ /* - * $Id: rb_text.c 143 2004-11-26 21:39:08Z tilman $ + * $Id: rb_text.c 354 2006-02-10 18:14:08Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -26,31 +26,21 @@ #include "rb_evas.h" #include "rb_evas_object.h" -static void c_free (RbEvasObject *e) -{ - c_evas_object_free (e, true); -} - /* * call-seq: * Evas::Text.new(evas) => text * * Creates an Evas::Text object. */ -static VALUE c_new (VALUE klass, VALUE evas) +static VALUE c_init (VALUE self, VALUE evas) { - VALUE self, argv[1]; - RbEvasObject *text; - CHECK_CLASS (evas, cEvas); GET_OBJ (evas, RbEvas, e); + GET_OBJ (self, RbEvasObject, text); - self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark, - c_free, text); text->real = evas_object_text_add (e->real); - argv[0] = evas; - rb_obj_call_init (self, 1, argv); + rb_call_super (1, &evas); return self; } @@ -172,7 +162,7 @@ void Init_Text (void) { VALUE c = rb_define_class_under (mEvas, "Text", cEvasObject); - rb_define_singleton_method (c, "new", c_new, 1); + rb_define_method (c, "initialize", c_init, 1); rb_define_method (c, "font_source", c_font_source_get, 0); rb_define_method (c, "font_source=", c_font_source_set, 1); rb_define_method (c, "get_font", c_get_font, 0); -- 2.30.2