To: vim_dev@googlegroups.com Subject: Patch 8.0.1466 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1466 Problem: Older GTK versions don't have gtk_entry_get_text_length(). Solution: Add a function with #ifdefs to take care of GTK version differences. (Kazunobu Kuriyama, closes #2605) Files: src/gui_gtk.c *** ../vim-8.0.1465/src/gui_gtk.c 2018-01-28 15:36:38.474736247 +0100 --- src/gui_gtk.c 2018-02-04 14:32:06.686519713 +0100 *************** *** 2144,2149 **** --- 2144,2180 ---- return (const char *)*buffer; } + /* + * Returns the number of characters in GtkEntry. + */ + static unsigned long + entry_get_text_length(GtkEntry *entry) + { + g_return_val_if_fail(entry != NULL, 0); + g_return_val_if_fail(GTK_IS_ENTRY(entry) == TRUE, 0); + + #if GTK_CHECK_VERSION(2,18,0) + /* 2.18 introduced a new object GtkEntryBuffer to handle text data for + * GtkEntry instead of letting each instance of the latter have its own + * storage for that. The code below is almost identical to the + * implementation of gtk_entry_get_text_length() for the versions >= 2.18. + */ + return gtk_entry_buffer_get_length(gtk_entry_get_buffer(entry)); + #elif GTK_CHECK_VERSION(2,14,0) + /* 2.14 introduced a new function to avoid memory management bugs which can + * happen when gtk_entry_get_text() is used without due care and attention. + */ + return gtk_entry_get_text_length(entry); + #else + /* gtk_entry_get_text() returns the pointer to the storage allocated + * internally by the widget. Accordingly, use the one with great care: + * Don't free it nor modify the contents it points to; call the function + * every time you need the pointer since its value may have been changed + * by the widget. */ + return g_utf8_strlen(gtk_entry_get_text(entry), -1); + #endif + } + static void find_replace_dialog_create(char_u *arg, int do_replace) { *************** *** 2198,2207 **** * For :promptrepl dialog, give it to 'with' entry if 'what' has an * non-empty entry; otherwise, to 'what' entry. */ gtk_widget_grab_focus(frdp->what); ! if (do_replace && gtk_entry_get_text_length(GTK_ENTRY(frdp->what))) gtk_widget_grab_focus(frdp->with); - vim_free(entry_text); return; } --- 2229,2237 ---- * For :promptrepl dialog, give it to 'with' entry if 'what' has an * non-empty entry; otherwise, to 'what' entry. */ gtk_widget_grab_focus(frdp->what); ! if (do_replace && entry_get_text_length(GTK_ENTRY(frdp->what)) > 0) gtk_widget_grab_focus(frdp->with); vim_free(entry_text); return; } *** ../vim-8.0.1465/src/version.c 2018-02-03 22:35:35.515505254 +0100 --- src/version.c 2018-02-04 14:32:38.266289832 +0100 *************** *** 773,774 **** --- 773,776 ---- { /* Add new patch number below this line */ + /**/ + 1466, /**/ -- I'd like to meet the man who invented sex and see what he's working on now. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///