Bug 24493

Summary: [GTK] Misc patches for WebKitWebHistoryItem
Product: WebKit Reporter: Xan Lopez <xan.lopez>
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: jmalonzo, sandshrew, zecke
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Linux   
Attachments:
Description Flags
style.patch
ap: review+
hashtablefull.patch
ap: review+
dispose.patch
xan.lopez: review-
fixstyle.patch
zecke: review+
deref.patch
zecke: review+
disposeonce.patch
zecke: review+
add WebKitWebHistoryItem unit test zecke: review+

Description Xan Lopez 2009-03-10 10:08:04 PDT
Ditto.
Comment 1 Xan Lopez 2009-03-10 10:26:16 PDT
Created attachment 28439 [details]
style.patch

Fix coding style.
Comment 2 Xan Lopez 2009-03-10 10:26:50 PDT
Created attachment 28440 [details]
hashtablefull.patch

Use g_hash_table_new_full so we can save the manual unref on the values when removing them from the table.
Comment 3 Xan Lopez 2009-03-10 10:27:16 PDT
Created attachment 28441 [details]
dispose.patch

dispose can run more than once, so make sure we don't try to access the items hash table after it's potentially destroyed.
Comment 4 Alexey Proskuryakov 2009-03-10 10:28:58 PDT
Comment on attachment 28439 [details]
style.patch

r=me
Comment 5 Xan Lopez 2009-03-10 10:34:52 PDT
(In reply to comment #4)
> (From update of attachment 28439 [details] [review])
> r=me
> 

Landed in r41558, thanks.
Comment 6 Alexey Proskuryakov 2009-03-10 10:35:44 PDT
Comment on attachment 28440 [details]
hashtablefull.patch

r=me. It's a bit counter-intuitive that the table derefs the elements, but does not ref them automatically. Perhaps a comment would help.
Comment 7 Xan Lopez 2009-03-10 10:59:54 PDT
(In reply to comment #6)
> (From update of attachment 28440 [details] [review])
> r=me. It's a bit counter-intuitive that the table derefs the elements, but does
> not ref them automatically. Perhaps a comment would help.
> 

Mmm, well, the table can't magically know what function to use to do the opposite operation of the destroy function you pass, and besides you might now want to do it in all cases...
Comment 8 Xan Lopez 2009-03-10 11:00:41 PDT
(In reply to comment #7)
> (In reply to comment #6)
> > (From update of attachment 28440 [details] [review] [review])
> > r=me. It's a bit counter-intuitive that the table derefs the elements, but does
> > not ref them automatically. Perhaps a comment would help.
> > 
> 
> Mmm, well, the table can't magically know what function to use to do the
> opposite operation of the destroy function you pass, and besides you might now
> want to do it in all cases...
> 

s/now/not/ ...
Comment 9 Xan Lopez 2009-03-10 23:41:29 PDT
Created attachment 28466 [details]
fixstyle.patch

return foo? foo : NULL == return foo
Comment 10 Xan Lopez 2009-03-10 23:42:51 PDT
Created attachment 28467 [details]
deref.patch

Call deref() on our internal HistoryItem on dispose, as we always acquire it with a releaseRef() call to a PassRefPtr, which passes ownership.
Comment 11 Holger Freyther 2009-03-11 02:19:48 PDT
Comment on attachment 28441 [details]
dispose.patch


>  static void webkit_web_history_item_dispose(GObject* object)
>  {
>      WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object);
> -
> -    GHashTable* table = webkit_history_items();
> -
> -    g_hash_table_remove(table, core(webHistoryItem));
> -
> -    /* destroy table if empty */
> -    if (!g_hash_table_size(table))
> -        g_hash_table_destroy(table);
> +    static gboolean isDisposed = false;

this looks wrong. For every HistoryItem we will only dispose/clear the first time one instance of HistoryItem should get destroyed? What am I missing?
Comment 12 Xan Lopez 2009-03-11 02:23:00 PDT
(In reply to comment #11)
> (From update of attachment 28441 [details] [review])
> 
> >  static void webkit_web_history_item_dispose(GObject* object)
> >  {
> >      WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object);
> > -
> > -    GHashTable* table = webkit_history_items();
> > -
> > -    g_hash_table_remove(table, core(webHistoryItem));
> > -
> > -    /* destroy table if empty */
> > -    if (!g_hash_table_size(table))
> > -        g_hash_table_destroy(table);
> > +    static gboolean isDisposed = false;
> 
> this looks wrong. For every HistoryItem we will only dispose/clear the first
> time one instance of HistoryItem should get destroyed? What am I missing?
> 

Mmm, the point is to only remove ourselves from the global hash table, and destroy it if it's empty, once, as dispose can run several times for the same GObject.
Comment 13 Xan Lopez 2009-03-11 02:24:34 PDT
Uhh, ok, nevermind. We need a per instance flag in the private data :)
Comment 14 Xan Lopez 2009-03-11 02:30:26 PDT
Created attachment 28468 [details]
disposeonce.patch

Something like this.
Comment 15 Jan Alonzo 2009-03-11 04:18:09 PDT
*** Bug 19898 has been marked as a duplicate of this bug. ***
Comment 16 Jan Alonzo 2009-03-11 04:22:47 PDT
Created attachment 28473 [details]
add WebKitWebHistoryItem unit test

adding unit test to this bug
Comment 17 Holger Freyther 2009-03-11 06:40:59 PDT
Comment on attachment 28473 [details]
add WebKitWebHistoryItem unit test

Looks good. the only complain/question is to multiple programs vs. one program with multiple test suites
Comment 18 Holger Freyther 2009-03-11 07:26:47 PDT
Comment on attachment 28467 [details]
deref.patch

okay, sounds good..
Comment 19 Jan Alonzo 2009-03-11 12:27:11 PDT
(In reply to comment #17)
> (From update of attachment 28473 [details] [review])
> Looks good. the only complain/question is to multiple programs vs. one program
> with multiple test suites
> 

zecke, I think we should just split it. There's a bug about that at https://bugs.webkit.org/show_bug.cgi?id=24039

Thanks
Comment 20 Holger Freyther 2009-03-17 10:39:04 PDT
Comment on attachment 28473 [details]
add WebKitWebHistoryItem unit test


>  # Build unit test
> -noinst_PROGRAMS += Programs/UnitTests
> +noinst_PROGRAMS += Programs/UnitTests Programs/WebHistoryItemUnitTests

okay, this needs rediffing as of bug #24039.


> +static void
> +test_webkit_web_history_item_alternate_title(WebHistoryItemFixture* fixture,
> +                                             gconstpointer data)


inconsistency with the new lines...
Comment 21 Jan Alonzo 2009-03-20 13:26:42 PDT
(In reply to comment #17)
> (From update of attachment 28473 [details] [review])
> Looks good. the only complain/question is to multiple programs vs. one program
> with multiple test suites
> 

Landed in r41866.

Closing as all other patches have been committed.