com gtk/php-gtk: GtkEntryCompletion::set_match_func( ) When using it, it leaks memory the same way we had for set_visible_func. I already reported a bug: http://bugzilla.gnome.org/show _bug.cgi?id=345107 and expect it to be fixed in the near future.: ext/gtk+/gtk .overrides

[email protected] (David Soria Parra)
Newsgroups php.gtk.cvs
Message-ID <[email protected]>
Commit:    33e6a2c53b73dfea11ba183b2c23f3058031d108
Author:    Christian Weiske <[email protected]>         Fri, 16 Jun 2006 15:05:18 +0000
Parents:   36514d930085fe3ee34b28d421cbd4be68ae51d9
Branches:  master

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

Log:
GtkEntryCompletion::set_match_func()
When using it, it leaks memory the same way we had for set_visible_func.
I already reported a bug: http://bugzilla.gnome.org/show_bug.cgi?id=345107
and expect it to be fixed in the near future.

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


Diff:
33e6a2c53b73dfea11ba183b2c23f3058031d108
diff --git a/ext/gtk+/gtk.overrides b/ext/gtk+/gtk.overrides
index c43fa5d..dc2fef5 100644
--- a/ext/gtk+/gtk.overrides
+++ b/ext/gtk+/gtk.overrides
@@ -4,6 +4,7 @@ headers
 #include "php_gtk_api.h"
 #include "ext/standard/file.h"
 static void phpg_about_dialog_activate_link_func_marshal (GtkAboutDialog *about, const gchar *link, gpointer data);
+static gboolean phpg_entry_completion_match_func_marshal (GtkEntryCompletion *completion, const gchar *key, GtkTreeIter *iter, gpointer data);
 static gboolean phpg_tree_view_row_separator_func_marshal (GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
 static void phpg_icon_view_foreach_func_marshal (GtkIconView *icon_view, GtkTreePath *path, gpointer data);
 
@@ -1837,6 +1838,107 @@ PHP_METHOD
 
 %% }}}
 
+%% {{{ GtkEntryCompletion
+
+%%
+add-arginfo GtkEntryCompletion set_match_func
+static
+ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
+    ZEND_ARG_INFO(0, callback)
+ZEND_END_ARG_INFO();
+
+%%
+override gtk_entry_completion_set_match_func
+static gboolean phpg_entry_completion_match_func_marshal (GtkEntryCompletion *completion, const gchar *key, GtkTreeIter *iter, gpointer data)
+{
+    phpg_cb_data_t *cbd = (phpg_cb_data_t *) data;
+    zval *retval = NULL;
+    zval ***args = NULL;
+    int n_args = 0;
+    char *callback_name;
+    zval *php_completion = NULL, *php_iter = NULL, *php_key;
+    gboolean matches = FALSE;
+    gchar *cp_key;
+    gsize cp_len;
+    zend_bool free_result;
+    TSRMLS_FETCH();
+
+    if (!zend_is_callable(cbd->callback, 0, &callback_name)) {
+        php_error(E_WARNING, "Unable to invoke callback '%s' specified in %s on line %ld", callback_name, cbd->src_filename, cbd->src_lineno);
+        efree(callback_name);
+        return 0;
+    }
+
+    phpg_gobject_new(&php_completion,       (GObject*)completion   TSRMLS_CC);
+    phpg_gboxed_new(&php_iter, GTK_TYPE_TREE_ITER, iter, TRUE, TRUE TSRMLS_CC);
+
+    cp_key = phpg_from_utf8(key, strlen(key), &cp_len, &free_result TSRMLS_CC);
+    if (!cp_key) {
+        php_error(E_WARNING, "Could not convert key from UTF-8");
+        return FALSE;
+    }
+    MAKE_STD_ZVAL(php_key);
+    ZVAL_STRINGL(php_key, (char*)cp_key, cp_len, 1);
+    if (free_result) {
+        g_free(cp_key);
+    }
+
+    args = php_gtk_hash_as_array_offset(cbd->user_args, 3, &n_args);
+    args[0] = &php_completion;
+    args[1] = &php_key;
+    args[2] = &php_iter;
+
+    call_user_function_ex(EG(function_table), NULL, cbd->callback, &retval, n_args, args, 0, NULL TSRMLS_CC);
+
+    zval_ptr_dtor(&php_completion);
+    zval_ptr_dtor(&php_key);
+    zval_ptr_dtor(&php_iter);
+
+    if (retval) {
+        matches = zend_is_true(retval);
+        zval_ptr_dtor(&retval);
+    } else {
+        matches = FALSE;
+    }
+
+    phpg_handle_marshaller_exception(TSRMLS_C);
+
+    efree(callback_name);
+    efree(args);
+
+    return matches;
+}
+
+PHP_METHOD
+{
+    zval *php_callback, *extra;
+    phpg_cb_data_t *cb_data;
+    GtkEntryCompletionMatchFunc callback;
+
+    NOT_STATIC_METHOD();
+
+    if (!php_gtk_parse_varargs(ZEND_NUM_ARGS(), 1, &extra, "V", &php_callback))
+        return;
+
+    if (php_callback) {
+        if (Z_TYPE_P(php_callback) == IS_NULL) {
+            cb_data  = NULL;
+            callback = NULL;
+        } else {
+            zval_add_ref(&php_callback);
+            cb_data  = phpg_cb_data_new(php_callback, extra TSRMLS_CC);
+            callback = (GtkEntryCompletionMatchFunc)phpg_entry_completion_match_func_marshal;
+        }
+    }
+
+    gtk_entry_completion_set_match_func(GTK_ENTRY_COMPLETION(PHPG_GOBJECT(this_ptr)),
+                                                           callback,
+                                                           cb_data, phpg_cb_data_destroy);
+}
+
+
+%% }}}
+
 %% {{{ GtkFileSelection
 
 %%
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.