cvs: php-gtk / NEWS TODO /src php_gtk_object.c php_gtk_types.c
| From: | Andrei Zmievski | Date: | Thu, 03 May 2001 03:20:11 +0000 |
| Subject: | cvs: php-gtk / NEWS TODO /src php_gtk_object.c php_gtk_types.c | ||
| Groups: | php.gtk | ||
| Request: | Send a blank email to php-gtk+get-1607@lists.php.net to get a copy of this message | ||
andrei Wed May 2 20:20:11 2001 EDT
Modified files:
/php-gtk NEWS TODO
/php-gtk/src php_gtk_object.c php_gtk_types.c
Log:
Properly detect type mismatches and other errors when assigning to overloaded
properties.
Index: php-gtk/NEWS diff -u php-gtk/NEWS:1.19 php-gtk/NEWS:1.20 --- php-gtk/NEWS:1.19 Tue Apr 24 06:48:23 2001 +++ php-gtk/NEWS Wed May 2 20:20:11 2001 @@ -1,3 +1,6 @@ + - implemented object overloading emulation layer to correct for Zend + engine's problems, now it's possible to assign and read custom properties + on Gtk+ objects. (Andrei) - added GtkAspectFrame class definition. (Andrei) - optimized internal resource handling, this should save on memory. (Andrei) - fixed a bug that would corrupt object type when setting cascaded property. Index: php-gtk/TODO diff -u php-gtk/TODO:1.33 php-gtk/TODO:1.34 --- php-gtk/TODO:1.33 Wed Apr 25 06:31:41 2001 +++ php-gtk/TODO Wed May 2 20:20:11 2001 @@ -3,8 +3,6 @@ * Figure out what's up with getting/setting gc background/foreground colors and how to get RGB values from pixels. * Provide access to GTK version number. -* Implement the hack fix for $dialog->vbox->show() crash and assigning - properties to overloaded objects crash. * See what other object definitions might have been missed by h2def.py. * See if it's possible or needed to set GtkAdjustment properties (and similar ones). Index: php-gtk/src/php_gtk_object.c diff -u php-gtk/src/php_gtk_object.c:1.32 php-gtk/src/php_gtk_object.c:1.33 --- php-gtk/src/php_gtk_object.c:1.32 Wed May 2 11:29:08 2001 +++ php-gtk/src/php_gtk_object.c Wed May 2 20:20:11 2001 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: php_gtk_object.c,v 1.32 2001/05/02 18:29:08 andrei Exp $ */ +/* $Id: php_gtk_object.c,v 1.33 2001/05/03 03:20:11 andrei Exp $ */ #include "php_gtk.h" @@ -638,17 +638,17 @@ { zend_class_entry *ce; prop_setter_t *setter; - int found = FAILURE; + int result = FAILURE; if (Z_OBJCE_P(object)->handle_property_set) { - for (ce = Z_OBJCE_P(object); ce != NULL && found != SUCCESS; ce = ce->parent) { + for (ce = Z_OBJCE_P(object); ce != NULL && result != SUCCESS && result != PG_ERROR; ce = ce->parent) { if (zend_hash_index_find(&php_gtk_prop_setters, (long)ce, (void **)&setter) == SUCCESS) { - found = (*setter)(object, element, value); + result = (*setter)(object, element, value); } } } - return found; + return result; } zval php_gtk_get_property(zend_property_reference *property_reference) @@ -747,8 +747,10 @@ } if (element == stop_element) { - if (invoke_setter(*object, value, &element) == SUCCESS) + if ((setter_retval = invoke_setter(*object, value, &element)) == SUCCESS) return SUCCESS; + else if (setter_retval == PG_ERROR) + return FAILURE; else if ((getter_retval = invoke_getter(*object, &result, &element)) == SUCCESS) { php_error(E_WARNING, "Cannot assign to overloaded property '%s'", Z_STRVAL(overloaded_property->element)); Index: php-gtk/src/php_gtk_types.c diff -u php-gtk/src/php_gtk_types.c:1.30 php-gtk/src/php_gtk_types.c:1.31 --- php-gtk/src/php_gtk_types.c:1.30 Wed May 2 11:29:08 2001 +++ php-gtk/src/php_gtk_types.c Wed May 2 20:20:11 2001 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: php_gtk_types.c,v 1.30 2001/05/02 18:29:08 andrei Exp $ */ +/* $Id: php_gtk_types.c,v 1.31 2001/05/03 03:20:11 andrei Exp $ */ #include "php_gtk.h" @@ -1349,7 +1349,21 @@ { GdkGC *gc = PHP_GDK_GC_GET(object); char *prop_name = Z_STRVAL(((zend_overloaded_element *)(*element)->data)->element); + zend_bool type_mismatch = 0; + int i; + static char *props[] = { + "function", "fill", "subwindow_mode", "ts_x_origin", "ts_y_origin", + "clip_x_origin", "clip_y_origin", "graphics_exposures", "line_width", + "line_style", "cap_style", "join_style", "foreground", "background", + "font", "tile", "stipple", "clip_mask" }; + for (i = 0; i < sizeof(props)/sizeof(char *); i++) { + if (!strcmp(prop_name, props[i])) + break; + } + if (i == sizeof(props)/sizeof(char *)) + return FAILURE; + if (Z_TYPE_P(value) == IS_LONG) { int iv = Z_LVAL_P(value); GdkGCValues v; @@ -1379,30 +1393,22 @@ gdk_gc_set_line_attributes(gc, v.line_width, v.line_style, iv, v.join_style); else if (!strcmp(prop_name, "join_style")) gdk_gc_set_line_attributes(gc, v.line_width, v.line_style, v.cap_style, iv); - else { - php_error(E_WARNING, "'%s' property should be a long ", prop_name); - return FAILURE; - } + else + type_mismatch = 1; } else if (php_gtk_check_class(value, gdk_color_ce)) { GdkColor *c = PHP_GDK_COLOR_GET(value); if (!strcmp(prop_name, "foreground")) gdk_gc_set_foreground(gc, c); - else if (!strcmp(prop_name, "background")) { - GdkGCValues gcv; + else if (!strcmp(prop_name, "background")) gdk_gc_set_background(gc, c); - } - else { - php_error(E_WARNING, "'%s' property should be a GdkColor", prop_name); - return FAILURE; - } + else + type_mismatch = 1; } else if (php_gtk_check_class(value, gdk_font_ce)) { if (!strcmp(prop_name, "font")) gdk_gc_set_font(gc, PHP_GDK_FONT_GET(value)); - else { - php_error(E_WARNING, "'%s' property should be a GdkFont", prop_name); - return FAILURE; - } + else + type_mismatch = 1; } else if (php_gtk_check_class(value, gdk_window_ce) || Z_TYPE_P(value) == IS_NULL) { GdkWindow *w = (Z_TYPE_P(value) == IS_NULL) ? NULL : PHP_GDK_WINDOW_GET(value); @@ -1412,16 +1418,16 @@ gdk_gc_set_stipple(gc, w); else if (!strcmp(prop_name, "clip_mask")) gdk_gc_set_clip_mask(gc, w); - else { - php_error(E_WARNING, "'%s' property should be a GdkWindow or null", prop_name); - return FAILURE; - } - } else { - php_error(E_WARNING, "type mismatch trying to set '%s' property", prop_name); - return FAILURE; - } + else + type_mismatch = 1; + } else + type_mismatch = 1; - return SUCCESS; + if (type_mismatch) { + php_error(E_WARNING, "Type mismatch trying to set property '%s'", prop_name); + return PG_ERROR; + } else + return SUCCESS; } @@ -1960,6 +1966,7 @@ { zend_overloaded_element *property; zend_llist_element *next = (*element)->next; + char *prop_name = Z_STRVAL(((zend_overloaded_element *)(*element)->data)->element); int prop_index; if (next) { @@ -1969,7 +1976,7 @@ prop_index = Z_LVAL(property->element); if (prop_index < 0 || prop_index >= 5) { php_error(E_WARNING, "style index out of range"); - return FAILURE; + return PG_ERROR; } switch (type) { @@ -1978,7 +1985,7 @@ GdkColor *color_array = (GdkColor *)array; if (!php_gtk_check_class(value, gdk_color_ce)) { php_error(E_WARNING, "can only assign a GdkColor"); - return FAILURE; + return PG_ERROR; } color_array[prop_index] = *PHP_GDK_COLOR_GET(value); } @@ -1989,7 +1996,7 @@ GdkGC **gc_array = (GdkGC **)array; if (!php_gtk_check_class(value, gdk_gc_ce)) { php_error(E_WARNING, "can only assign a GdkGC"); - return FAILURE; + return PG_ERROR; } if (gc_array[prop_index]) gdk_gc_unref(gc_array[prop_index]); @@ -2002,7 +2009,7 @@ GdkWindow **pixmap_array = (GdkWindow **)array; if (!php_gtk_check_class(value, gdk_window_ce) && Z_TYPE_P(value) != IS_NULL) { php_error(E_WARNING, "can only assign a GdkPixmap or null"); - return FAILURE; + return PG_ERROR; } if (pixmap_array[prop_index]) gdk_pixmap_unref(pixmap_array[prop_index]); @@ -2017,10 +2024,14 @@ g_assert_not_reached(); break; } - } else - return FAILURE; - } else - return FAILURE; + } else { + php_error(E_WARNING, "property '%s' cannot be indexed by strings", prop_name); + return PG_ERROR; + } + } else { + php_error(E_WARNING, "cannot assign directly to '%s'", prop_name); + return PG_ERROR; + } return SUCCESS; } @@ -2037,21 +2048,21 @@ style->font = gdk_font_ref(PHP_GDK_FONT_GET(value)); } else { php_error(E_WARNING, "'%s' property should be a GdkFont", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "black")) { if (php_gtk_check_class(value, gdk_color_ce)) style->black = *PHP_GDK_COLOR_GET(value); else { php_error(E_WARNING, "'%s' property should be a GdkColor", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "white")) { if (php_gtk_check_class(value, gdk_color_ce)) style->white = *PHP_GDK_COLOR_GET(value); else { php_error(E_WARNING, "'%s' property should be a GdkColor", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "black_gc")) { if (php_gtk_check_class(value, gdk_gc_ce)) { @@ -2060,7 +2071,7 @@ style->black_gc = gdk_gc_ref(PHP_GDK_GC_GET(value)); } else { php_error(E_WARNING, "'%s' property should be a GdkGC", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "white_gc")) { if (php_gtk_check_class(value, gdk_gc_ce)) { @@ -2069,7 +2080,7 @@ style->white_gc = gdk_gc_ref(PHP_GDK_GC_GET(value)); } else { php_error(E_WARNING, "'%s' property should be a GdkGC", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "colormap")) { if (php_gtk_check_class(value, gdk_colormap_ce)) { @@ -2078,7 +2089,7 @@ style->colormap = gdk_colormap_ref(PHP_GDK_COLORMAP_GET(value)); } else { php_error(E_WARNING, "'%s' property should be a GdkColormap", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "fg")) { return style_helper_set(STYLE_COLOR_ARRAY, style->fg, value, element);
Index: php-gtk/NEWS diff -u php-gtk/NEWS:1.19 php-gtk/NEWS:1.20 --- php-gtk/NEWS:1.19 Tue Apr 24 06:48:23 2001 +++ php-gtk/NEWS Wed May 2 20:20:11 2001 @@ -1,3 +1,6 @@ + - implemented object overloading emulation layer to correct for Zend + engine's problems, now it's possible to assign and read custom properties + on Gtk+ objects. (Andrei) - added GtkAspectFrame class definition. (Andrei) - optimized internal resource handling, this should save on memory. (Andrei) - fixed a bug that would corrupt object type when setting cascaded property. Index: php-gtk/TODO diff -u php-gtk/TODO:1.33 php-gtk/TODO:1.34 --- php-gtk/TODO:1.33 Wed Apr 25 06:31:41 2001 +++ php-gtk/TODO Wed May 2 20:20:11 2001 @@ -3,8 +3,6 @@ * Figure out what's up with getting/setting gc background/foreground colors and how to get RGB values from pixels. * Provide access to GTK version number. -* Implement the hack fix for $dialog->vbox->show() crash and assigning - properties to overloaded objects crash. * See what other object definitions might have been missed by h2def.py. * See if it's possible or needed to set GtkAdjustment properties (and similar ones). Index: php-gtk/src/php_gtk_object.c diff -u php-gtk/src/php_gtk_object.c:1.32 php-gtk/src/php_gtk_object.c:1.33 --- php-gtk/src/php_gtk_object.c:1.32 Wed May 2 11:29:08 2001 +++ php-gtk/src/php_gtk_object.c Wed May 2 20:20:11 2001 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: php_gtk_object.c,v 1.32 2001/05/02 18:29:08 andrei Exp $ */ +/* $Id: php_gtk_object.c,v 1.33 2001/05/03 03:20:11 andrei Exp $ */ #include "php_gtk.h" @@ -638,17 +638,17 @@ { zend_class_entry *ce; prop_setter_t *setter; - int found = FAILURE; + int result = FAILURE; if (Z_OBJCE_P(object)->handle_property_set) { - for (ce = Z_OBJCE_P(object); ce != NULL && found != SUCCESS; ce = ce->parent) { + for (ce = Z_OBJCE_P(object); ce != NULL && result != SUCCESS && result != PG_ERROR; ce = ce->parent) { if (zend_hash_index_find(&php_gtk_prop_setters, (long)ce, (void **)&setter) == SUCCESS) { - found = (*setter)(object, element, value); + result = (*setter)(object, element, value); } } } - return found; + return result; } zval php_gtk_get_property(zend_property_reference *property_reference) @@ -747,8 +747,10 @@ } if (element == stop_element) { - if (invoke_setter(*object, value, &element) == SUCCESS) + if ((setter_retval = invoke_setter(*object, value, &element)) == SUCCESS) return SUCCESS; + else if (setter_retval == PG_ERROR) + return FAILURE; else if ((getter_retval = invoke_getter(*object, &result, &element)) == SUCCESS) { php_error(E_WARNING, "Cannot assign to overloaded property '%s'", Z_STRVAL(overloaded_property->element)); Index: php-gtk/src/php_gtk_types.c diff -u php-gtk/src/php_gtk_types.c:1.30 php-gtk/src/php_gtk_types.c:1.31 --- php-gtk/src/php_gtk_types.c:1.30 Wed May 2 11:29:08 2001 +++ php-gtk/src/php_gtk_types.c Wed May 2 20:20:11 2001 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: php_gtk_types.c,v 1.30 2001/05/02 18:29:08 andrei Exp $ */ +/* $Id: php_gtk_types.c,v 1.31 2001/05/03 03:20:11 andrei Exp $ */ #include "php_gtk.h" @@ -1349,7 +1349,21 @@ { GdkGC *gc = PHP_GDK_GC_GET(object); char *prop_name = Z_STRVAL(((zend_overloaded_element *)(*element)->data)->element); + zend_bool type_mismatch = 0; + int i; + static char *props[] = { + "function", "fill", "subwindow_mode", "ts_x_origin", "ts_y_origin", + "clip_x_origin", "clip_y_origin", "graphics_exposures", "line_width", + "line_style", "cap_style", "join_style", "foreground", "background", + "font", "tile", "stipple", "clip_mask" }; + for (i = 0; i < sizeof(props)/sizeof(char *); i++) { + if (!strcmp(prop_name, props[i])) + break; + } + if (i == sizeof(props)/sizeof(char *)) + return FAILURE; + if (Z_TYPE_P(value) == IS_LONG) { int iv = Z_LVAL_P(value); GdkGCValues v; @@ -1379,30 +1393,22 @@ gdk_gc_set_line_attributes(gc, v.line_width, v.line_style, iv, v.join_style); else if (!strcmp(prop_name, "join_style")) gdk_gc_set_line_attributes(gc, v.line_width, v.line_style, v.cap_style, iv); - else { - php_error(E_WARNING, "'%s' property should be a long ", prop_name); - return FAILURE; - } + else + type_mismatch = 1; } else if (php_gtk_check_class(value, gdk_color_ce)) { GdkColor *c = PHP_GDK_COLOR_GET(value); if (!strcmp(prop_name, "foreground")) gdk_gc_set_foreground(gc, c); - else if (!strcmp(prop_name, "background")) { - GdkGCValues gcv; + else if (!strcmp(prop_name, "background")) gdk_gc_set_background(gc, c); - } - else { - php_error(E_WARNING, "'%s' property should be a GdkColor", prop_name); - return FAILURE; - } + else + type_mismatch = 1; } else if (php_gtk_check_class(value, gdk_font_ce)) { if (!strcmp(prop_name, "font")) gdk_gc_set_font(gc, PHP_GDK_FONT_GET(value)); - else { - php_error(E_WARNING, "'%s' property should be a GdkFont", prop_name); - return FAILURE; - } + else + type_mismatch = 1; } else if (php_gtk_check_class(value, gdk_window_ce) || Z_TYPE_P(value) == IS_NULL) { GdkWindow *w = (Z_TYPE_P(value) == IS_NULL) ? NULL : PHP_GDK_WINDOW_GET(value); @@ -1412,16 +1418,16 @@ gdk_gc_set_stipple(gc, w); else if (!strcmp(prop_name, "clip_mask")) gdk_gc_set_clip_mask(gc, w); - else { - php_error(E_WARNING, "'%s' property should be a GdkWindow or null", prop_name); - return FAILURE; - } - } else { - php_error(E_WARNING, "type mismatch trying to set '%s' property", prop_name); - return FAILURE; - } + else + type_mismatch = 1; + } else + type_mismatch = 1; - return SUCCESS; + if (type_mismatch) { + php_error(E_WARNING, "Type mismatch trying to set property '%s'", prop_name); + return PG_ERROR; + } else + return SUCCESS; } @@ -1960,6 +1966,7 @@ { zend_overloaded_element *property; zend_llist_element *next = (*element)->next; + char *prop_name = Z_STRVAL(((zend_overloaded_element *)(*element)->data)->element); int prop_index; if (next) { @@ -1969,7 +1976,7 @@ prop_index = Z_LVAL(property->element); if (prop_index < 0 || prop_index >= 5) { php_error(E_WARNING, "style index out of range"); - return FAILURE; + return PG_ERROR; } switch (type) { @@ -1978,7 +1985,7 @@ GdkColor *color_array = (GdkColor *)array; if (!php_gtk_check_class(value, gdk_color_ce)) { php_error(E_WARNING, "can only assign a GdkColor"); - return FAILURE; + return PG_ERROR; } color_array[prop_index] = *PHP_GDK_COLOR_GET(value); } @@ -1989,7 +1996,7 @@ GdkGC **gc_array = (GdkGC **)array; if (!php_gtk_check_class(value, gdk_gc_ce)) { php_error(E_WARNING, "can only assign a GdkGC"); - return FAILURE; + return PG_ERROR; } if (gc_array[prop_index]) gdk_gc_unref(gc_array[prop_index]); @@ -2002,7 +2009,7 @@ GdkWindow **pixmap_array = (GdkWindow **)array; if (!php_gtk_check_class(value, gdk_window_ce) && Z_TYPE_P(value) != IS_NULL) { php_error(E_WARNING, "can only assign a GdkPixmap or null"); - return FAILURE; + return PG_ERROR; } if (pixmap_array[prop_index]) gdk_pixmap_unref(pixmap_array[prop_index]); @@ -2017,10 +2024,14 @@ g_assert_not_reached(); break; } - } else - return FAILURE; - } else - return FAILURE; + } else { + php_error(E_WARNING, "property '%s' cannot be indexed by strings", prop_name); + return PG_ERROR; + } + } else { + php_error(E_WARNING, "cannot assign directly to '%s'", prop_name); + return PG_ERROR; + } return SUCCESS; } @@ -2037,21 +2048,21 @@ style->font = gdk_font_ref(PHP_GDK_FONT_GET(value)); } else { php_error(E_WARNING, "'%s' property should be a GdkFont", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "black")) { if (php_gtk_check_class(value, gdk_color_ce)) style->black = *PHP_GDK_COLOR_GET(value); else { php_error(E_WARNING, "'%s' property should be a GdkColor", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "white")) { if (php_gtk_check_class(value, gdk_color_ce)) style->white = *PHP_GDK_COLOR_GET(value); else { php_error(E_WARNING, "'%s' property should be a GdkColor", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "black_gc")) { if (php_gtk_check_class(value, gdk_gc_ce)) { @@ -2060,7 +2071,7 @@ style->black_gc = gdk_gc_ref(PHP_GDK_GC_GET(value)); } else { php_error(E_WARNING, "'%s' property should be a GdkGC", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "white_gc")) { if (php_gtk_check_class(value, gdk_gc_ce)) { @@ -2069,7 +2080,7 @@ style->white_gc = gdk_gc_ref(PHP_GDK_GC_GET(value)); } else { php_error(E_WARNING, "'%s' property should be a GdkGC", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "colormap")) { if (php_gtk_check_class(value, gdk_colormap_ce)) { @@ -2078,7 +2089,7 @@ style->colormap = gdk_colormap_ref(PHP_GDK_COLORMAP_GET(value)); } else { php_error(E_WARNING, "'%s' property should be a GdkColormap", prop_name); - return FAILURE; + return PG_ERROR; } } else if (!strcmp(prop_name, "fg")) { return style_helper_set(STYLE_COLOR_ARRAY, style->fg, value, element);