Re: patch: GtkScaleButton::__construct

From: Date: Sun, 18 Nov 2007 01:37:54 +0000
Subject: Re: patch: GtkScaleButton::__construct
References: 1 2  Groups: php.gtk.dev 
Request: Send a blank email to php-gtk-dev+get-4023@lists.php.net to get a copy of this message
This patch has a couple of problems.
+%% +headers +static void phpg_scale_button_set_icons_marshal(GtkScaleButton *, zval *);
Please don't use _marshal suffix for helper function like these. This suffix should be reserved only for callback marshallers.
+%% +override gtk_scale_button_new +PHP_METHOD +{
+    gint iconsize;
+    gdouble min, max, step;
+    GtkWidget *obj;
+    zval *iconlist = NULL;
+
+    if(!php_gtk_parse_args(ZEND_NUM_ARGS(),"iddd|a",&iconsize,&min,&max,&step,&iconlist)) {
+        return;
+    }
+
+    obj = gtk_scale_button_new(iconsize,min,max,step,NULL);
While this works, it's not how the objects should be constructed. You need to use g_object_newv() along with phpg_gtype_from_zval() in order for the resulting object to have the correct gtype in case this code runs on a subclass of GtkScaleButton. See GtkButton constructor for example and also PyGTK implementation.
+
+    if(listlen > 0) {
+        list = g_malloc0(sizeof(gchar **) * (listlen + 1));
+
This should be "sizeof(gchar*)".
iter = 0; +
+        //. building null terminated gchar array for the constructor.
+        zend_hash_internal_pointer_reset(Z_ARRVAL_P(iconlist));
+        while(zend_hash_get_current_data(Z_ARRVAL_P(iconlist),(void **)&iconname) == SUCCESS) {
+            if(Z_TYPE_PP(iconname) == IS_STRING) {
+                list[iter++] = g_strdup(Z_STRVAL_PP(iconname));
+            } else {
+                php_error_docref(NULL TSRMLS_CC,E_WARNING,"each item in icon array is to be a string");
+            }
+
+            zend_hash_move_forward(Z_ARRVAL_P(iconlist));
+        } list[iter] = NULL;
+
+    } else {
+        list = NULL;
+    }
+
+    gtk_scale_button_set_icons(
+        GTK_SCALE_BUTTON(button),
+        (const gchar **)list
+    );
+
+    if(list) {
+        g_strfreev(list);
+    }
Do we need to duplicate the strings when adding them to the list? It looks like gtk_scale_button_set_icons() does its own duplication internally (since you free your strings with g_strfreev). -Andrei

« previous php.gtk.dev (#4023) next »