From: Daniel A. <dat...@us...> - 2009-10-06 06:14:32
|
Update of /cvsroot/gtkspell/gtkspell2/gtkspell In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22338/gtkspell Modified Files: gtkspell.c Log Message: Fix Bug #2642198 (Enchant Broker should be a singleton) to allow caching of dictionaries for multiple instances. Index: gtkspell.c =================================================================== RCS file: /cvsroot/gtkspell/gtkspell2/gtkspell/gtkspell.c,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** gtkspell.c 6 Oct 2009 05:34:25 -0000 1.36 --- gtkspell.c 6 Oct 2009 06:14:23 -0000 1.37 *************** *** 21,24 **** --- 21,27 ---- static const int quiet = 0; + static EnchantBroker *broker = NULL; + static int broker_ref_cnt; + struct _GtkSpell { GtkTextView *view; *************** *** 27,31 **** GtkTextMark *mark_insert_end; gboolean deferred_check; - EnchantBroker *broker; EnchantDict *speller; GtkTextMark *mark_click; --- 30,33 ---- *************** *** 458,462 **** languages_cb_struct.langs = NULL; ! enchant_broker_list_dicts(spell->broker, dict_describe_cb, &languages_cb_struct); langs = languages_cb_struct.langs; --- 460,464 ---- languages_cb_struct.langs = NULL; ! enchant_broker_list_dicts(broker, dict_describe_cb, &languages_cb_struct); langs = languages_cb_struct.langs; *************** *** 584,594 **** } - if (!spell->broker) - spell->broker = enchant_broker_init(); - if (!lang) lang = "en"; ! dict = enchant_broker_request_dict(spell->broker, lang); if (!dict) { --- 586,593 ---- } if (!lang) lang = "en"; ! dict = enchant_broker_request_dict(broker, lang); if (!dict) { *************** *** 599,603 **** if (spell->speller) ! enchant_broker_free_dict(spell->broker, spell->speller); spell->speller = dict; --- 598,602 ---- if (spell->speller) ! enchant_broker_free_dict(broker, spell->speller); spell->speller = dict; *************** *** 681,690 **** g_assert(spell == NULL); /* attach to the widget */ spell = g_new0(GtkSpell, 1); spell->view = view; if (!gtkspell_set_language_internal(spell, lang, error)) { ! if (spell->broker) ! enchant_broker_free(spell->broker); g_free(spell); return NULL; --- 680,702 ---- g_assert(spell == NULL); + /* We don't need to worry about thread safety. + * Stuff shouldn't be attaching to a GtkTextView from anything other + * than the mainloop thread */ + if (!broker) { + broker = enchant_broker_init(); + broker_ref_cnt = 0; + } + broker_ref_cnt++; + + /* attach to the widget */ spell = g_new0(GtkSpell, 1); spell->view = view; if (!gtkspell_set_language_internal(spell, lang, error)) { ! broker_ref_cnt--; ! if (broker_ref_cnt == 0) { ! enchant_broker_free(broker); ! broker = NULL; ! } g_free(spell); return NULL; *************** *** 768,776 **** ! if (spell->broker) { if (spell->speller) { ! enchant_broker_free_dict(spell->broker, spell->speller); } - enchant_broker_free(spell->broker); } g_signal_handlers_disconnect_matched(spell->view, --- 780,792 ---- ! if (broker) { if (spell->speller) { ! enchant_broker_free_dict(broker, spell->speller); ! } ! broker_ref_cnt--; ! if (broker_ref_cnt == 0) { ! enchant_broker_free(broker); ! broker = NULL; } } g_signal_handlers_disconnect_matched(spell->view, |