com gtk/php-gtk: Fix construction of GtkListStore() with 0 columns.: ext/gtk+/gtktreeview.overrides

[email protected] (David Soria Parra)
Newsgroups php.gtk.cvs
Message-ID <[email protected]>
Commit:    9995336afa0d41c4208c5f2967119dd09763cd13
Author:    Andrei Zmievski <[email protected]>         Sat, 8 Apr 2006 18:48:28 +0000
Parents:   25e154313eaee7701131a368d0308fddcc512ce4
Branches:  master

Link:       http://git.php.net/?p=gtk/php-gtk.git;a=commitdiff;h=9995336afa0d41c4208c5f2967119dd09763cd13

Log:
Fix construction of GtkListStore() with 0 columns.

Changed paths:
  M  ext/gtk+/gtktreeview.overrides


Diff:
9995336afa0d41c4208c5f2967119dd09763cd13
diff --git a/ext/gtk+/gtktreeview.overrides b/ext/gtk+/gtktreeview.overrides
index 3f10b51..ff5777f 100644
--- a/ext/gtk+/gtktreeview.overrides
+++ b/ext/gtk+/gtktreeview.overrides
@@ -206,22 +206,22 @@ PHP_METHOD
     if (argc > 0) {
         args = php_gtk_func_args(argc);
         column_types = emalloc(argc * sizeof(GType));
-    }
 
-    for (i = 0; i < argc; i++) {
-        column_types[i] = phpg_gtype_from_zval(*args[i]);
-        if (column_types[i] == 0) {
-            efree(column_types);
-            PHPG_THROW_CONSTRUCT_EXCEPTION(GtkListStore);
+        for (i = 0; i < argc; i++) {
+            column_types[i] = phpg_gtype_from_zval(*args[i]);
+            if (column_types[i] == 0) {
+                efree(column_types);
+                PHPG_THROW_CONSTRUCT_EXCEPTION(GtkListStore);
+            }
         }
-    }
-    
-    wrapped_obj = g_object_newv(phpg_gtype_from_zval(this_ptr), 0, NULL);
-    gtk_list_store_set_column_types(GTK_LIST_STORE(wrapped_obj), argc, column_types);
 
-    if (argc > 0) {
+        wrapped_obj = g_object_newv(phpg_gtype_from_zval(this_ptr), 0, NULL);
+        gtk_list_store_set_column_types(GTK_LIST_STORE(wrapped_obj), argc, column_types);
+
         efree(column_types);
         efree(args);
+    } else {
+        wrapped_obj = g_object_new(phpg_gtype_from_zval(this_ptr), NULL);
     }
 
     if (!wrapped_obj) {
@@ -246,6 +246,12 @@ PHP_METHOD
     }
     
     n = zend_hash_num_elements(Z_ARRVAL_P(php_types));
+
+    if (n == 0) {
+        php_error(E_WARNING, "number of columns has to be > 0");
+        return;
+    }
+
     column_types = safe_emalloc(n, sizeof(GType), 0);
     for (i = 0, zend_hash_internal_pointer_reset(Z_ARRVAL_P(php_types));
          zend_hash_get_current_data(Z_ARRVAL_P(php_types), (void**)&item) == SUCCESS;
@@ -547,22 +553,22 @@ PHP_METHOD
     if (argc > 0) {
         args = php_gtk_func_args(argc);
         column_types = emalloc(argc * sizeof(GType));
-    }
 
-    for (i = 0; i < argc; i++) {
-        column_types[i] = phpg_gtype_from_zval(*args[i]);
-        if (column_types[i] == 0) {
-            efree(column_types);
-            PHPG_THROW_CONSTRUCT_EXCEPTION(GtkTreeStore);
+        for (i = 0; i < argc; i++) {
+            column_types[i] = phpg_gtype_from_zval(*args[i]);
+            if (column_types[i] == 0) {
+                efree(column_types);
+                PHPG_THROW_CONSTRUCT_EXCEPTION(GtkTreeStore);
+            }
         }
-    }
-    
-    wrapped_obj = g_object_newv(phpg_gtype_from_zval(this_ptr), 0, NULL);
-    gtk_tree_store_set_column_types(GTK_TREE_STORE(wrapped_obj), argc, column_types);
 
-    if (argc > 0) {
+        wrapped_obj = g_object_newv(phpg_gtype_from_zval(this_ptr), 0, NULL);
+        gtk_tree_store_set_column_types(GTK_TREE_STORE(wrapped_obj), argc, column_types);
+
         efree(column_types);
         efree(args);
+    } else {
+        wrapped_obj = g_object_new(phpg_gtype_from_zval(this_ptr), NULL);
     }
 
     if (!wrapped_obj) {
@@ -587,6 +593,12 @@ PHP_METHOD
     }
     
     n = zend_hash_num_elements(Z_ARRVAL_P(php_types));
+
+    if (n == 0) {
+        php_error(E_WARNING, "number of columns has to be > 0");
+        return;
+    }
+
     column_types = safe_emalloc(n, sizeof(GType), 0);
     for (i = 0, zend_hash_internal_pointer_reset(Z_ARRVAL_P(php_types));
          zend_hash_get_current_data(Z_ARRVAL_P(php_types), (void**)&item) == SUCCESS;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.