Bug 100751 - [EFL][WK2] Common ref and unref functions for EFL WK2 objects
Summary: [EFL][WK2] Common ref and unref functions for EFL WK2 objects
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit EFL (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mikhail Pozdnyakov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-30 06:20 PDT by Mikhail Pozdnyakov
Modified: 2012-11-02 03:15 PDT (History)
10 users (show)

See Also:


Attachments
patch (19.32 KB, patch)
2012-10-31 06:24 PDT, Mikhail Pozdnyakov
no flags Details | Formatted Diff | Diff
patch v2 (19.94 KB, patch)
2012-11-01 07:14 PDT, Mikhail Pozdnyakov
no flags Details | Formatted Diff | Diff
patch v3 (19.85 KB, patch)
2012-11-01 07:42 PDT, Mikhail Pozdnyakov
kenneth: review+
Details | Formatted Diff | Diff
patch v4 (19.63 KB, patch)
2012-11-01 08:59 PDT, Mikhail Pozdnyakov
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mikhail Pozdnyakov 2012-10-30 06:20:37 PDT
As all the ref-counting EWK classes are inherited from WTF::RefCounted
it is possible now to have generic REF/UNREF functions in the public API instead of 
having separate pair of such functions for every object.
Comment 1 Mikhail Pozdnyakov 2012-10-31 06:24:53 PDT
Created attachment 171634 [details]
patch
Comment 2 Chris Dumez 2012-10-31 06:50:38 PDT
Comment on attachment 171634 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=171634&action=review

Still not sure how I feel about this change, but here is some initial feedback:

> Source/WebKit2/PlatformEfl.cmake:61
> +    UIProcess/API/efl/ewk_ref_counted.cpp

You need to add "ewk_ref_counted.h" to the installable headers below in the same file.

> Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list_item.cpp:62
> +    if (const EwkBackForwardListItem* impl = ewkCastToType<EwkBackForwardListItem>(item))

Maybe we could have a macro.

Something like EWK_GET_IMPL_OR_RETURN(item, 0);

> Source/WebKit2/UIProcess/API/efl/ewk_ref_counted.h:50
> +EAPI Ewk_Ref_Counted *ewk_ref_counted_ref(Ewk_Ref_Counted *object);

Why not simply ewk_ref() / ewk_unref()?

> Source/WebKit2/UIProcess/API/efl/ewk_ref_counted_private.h:34
> +    virtual const char* instClassName() const = 0;

"inst"? What does it stand for? We usually try to avoid abbreviations.
Comment 3 Gyuyoung Kim 2012-10-31 18:30:10 PDT
The referencing count files(ewk_ref_counted.h | cpp) are placed to Source/WTF/wtf. Why these files should be place to WebKit2's UIProcess side ? If we can move these files to there, I think we can use this functionality in all EFL places.
Comment 4 Chris Dumez 2012-10-31 22:49:02 PDT
(In reply to comment #3)
> The referencing count files(ewk_ref_counted.h | cpp) are placed to Source/WTF/wtf. Why these files should be place to WebKit2's UIProcess side ? If we can move these files to there, I think we can use this functionality in all EFL places.

AFAIK, they need to be in the API folder because they are part of the public API (e.g. ewe_ref_counted_ref() is in ewk_ref_counted.h).
Comment 5 Gyuyoung Kim 2012-10-31 22:57:49 PDT
(In reply to comment #4)
> (In reply to comment #3)
> > The referencing count files(ewk_ref_counted.h | cpp) are placed to Source/WTF/wtf. Why these files should be place to WebKit2's UIProcess side ? If we can move these files to there, I think we can use this functionality in all EFL places.
> 
> AFAIK, they need to be in the API folder because they are part of the public API (e.g. ewe_ref_counted_ref() is in ewk_ref_counted.h).

I think we can try this. Anyway, this might to be new item on other bug later.
Comment 6 Thiago Marcos P. Santos 2012-11-01 02:55:19 PDT
Comment on attachment 171634 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=171634&action=review

> Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp:89
>  static inline void freeEinaList(Eina_List* list)
>  {
>      void* data = 0;
>      EINA_LIST_FREE(list, data)
> -        ewk_back_forward_list_item_unref(static_cast<Ewk_Back_Forward_List_Item*>(data));
> +        ewk_ref_counted_unref(static_cast<Ewk_Back_Forward_List_Item*>(data));
>  }
>  
>  TEST_F(EWK2UnitTestBase, ewk_back_forward_list_current_item_get)

Would be nice if we could have more unit tests for these functions.
Comment 7 Mikhail Pozdnyakov 2012-11-01 05:57:15 PDT
(In reply to comment #6)
> (From update of attachment 171634 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=171634&action=review
> 
> > Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp:89
> >  static inline void freeEinaList(Eina_List* list)
> >  {
> >      void* data = 0;
> >      EINA_LIST_FREE(list, data)
> > -        ewk_back_forward_list_item_unref(static_cast<Ewk_Back_Forward_List_Item*>(data));
> > +        ewk_ref_counted_unref(static_cast<Ewk_Back_Forward_List_Item*>(data));
> >  }
> >  
> >  TEST_F(EWK2UnitTestBase, ewk_back_forward_list_current_item_get)
> 
> Would be nice if we could have more unit tests for these functions.

we will have these functions checked for every ref counted object we have
Comment 8 Mikhail Pozdnyakov 2012-11-01 07:14:29 PDT
Created attachment 171840 [details]
patch v2

Used macro as proposed by Chris, used Ewk_Object as proposed by Kenneth. Thanks for feedback.
Comment 9 Kenneth Rohde Christiansen 2012-11-01 07:18:14 PDT
Comment on attachment 171840 [details]
patch v2

View in context: https://bugs.webkit.org/attachment.cgi?id=171840&action=review

> Source/WebKit2/UIProcess/API/efl/ewk_object_private.h:62
> +template <class T>
> +inline const T* ewkObjectCast(const Ewk_Object* object)
> +{
> +    return ewkObjectCastCheck<T>(object) ? static_cast<const T*>(object) : 0;
> +}

as all casts are of the style some_cast maybe we should do the same?

ewk_object_cast() it might even make sense to expose to C++ developers
Comment 10 Mikhail Pozdnyakov 2012-11-01 07:22:13 PDT
(In reply to comment #9)
> (From update of attachment 171840 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=171840&action=review
> 
> > Source/WebKit2/UIProcess/API/efl/ewk_object_private.h:62
> > +template <class T>
> > +inline const T* ewkObjectCast(const Ewk_Object* object)
> > +{
> > +    return ewkObjectCastCheck<T>(object) ? static_cast<const T*>(object) : 0;
> > +}
> 
> as all casts are of the style some_cast maybe we should do the same?
> 
> ewk_object_cast() it might even make sense to expose to C++ developers

no problem :)
Comment 11 Mikhail Pozdnyakov 2012-11-01 07:42:47 PDT
Created attachment 171852 [details]
patch v3

Took Kenneth feedback into consideration.
Comment 12 Chris Dumez 2012-11-01 08:29:40 PDT
Comment on attachment 171852 [details]
patch v3

View in context: https://bugs.webkit.org/attachment.cgi?id=171852&action=review

> Source/WebKit2/ChangeLog:28
> +        * UIProcess/API/efl/ewk_back_forward_list_private.h:

ewk_object seems to be missing from the changelog?

> Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list_item.cpp:62
> +    EWK_OBJ_CONST_IMPL_GET_OR_RETURN_VAL(EwkBackForwardListItem, item, impl, 0);

Do we really need to distinguish CONST and non-CONST macros? We end up with 4 macros this way.

Also do we really need to use Yoda style for internal macros?

How about EWK_OBJ_GET_IMPL_OR_RETURN_VAL()

> Source/WebKit2/UIProcess/API/efl/ewk_object_private.h:85
> +#define EWK_OBJ_CONST_IMPL_GET_OR_RETURN_VAL(ImplClass, object, impl, ...) \

Doesn't VA_ARGS work with 0 arguments? Then we would need only 2 macros.
Comment 13 Chris Dumez 2012-11-01 08:32:52 PDT
Comment on attachment 171852 [details]
patch v3

View in context: https://bugs.webkit.org/attachment.cgi?id=171852&action=review

>> Source/WebKit2/UIProcess/API/efl/ewk_object_private.h:85
>> +#define EWK_OBJ_CONST_IMPL_GET_OR_RETURN_VAL(ImplClass, object, impl, ...) \
> 
> Doesn't VA_ARGS work with 0 arguments? Then we would need only 2 macros.

Actually, in Ewk_view, we don't differentiate and we need only one macro (leveraging VA_ARGS):
EWK_VIEW_IMPL_GET_OR_RETURN()

No need for EWK_VIEW_IMPL_GET_OR_RETURN_VAL().

Sadly, this macro uses Yoda style too :(
Comment 14 Mikhail Pozdnyakov 2012-11-01 08:45:38 PDT
(In reply to comment #13)
> (From update of attachment 171852 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=171852&action=review
> 
> >> Source/WebKit2/UIProcess/API/efl/ewk_object_private.h:85
> >> +#define EWK_OBJ_CONST_IMPL_GET_OR_RETURN_VAL(ImplClass, object, impl, ...) \
> > 
> > Doesn't VA_ARGS work with 0 arguments? Then we would need only 2 macros.
> 
> Actually, in Ewk_view, we don't differentiate and we need only one macro (leveraging VA_ARGS):
> EWK_VIEW_IMPL_GET_OR_RETURN()
> 
> No need for EWK_VIEW_IMPL_GET_OR_RETURN_VAL().
> 
> Sadly, this macro uses Yoda style too :(

It's consistent with yoda style from other macros there, but they all can be changed off course
Comment 15 Mikhail Pozdnyakov 2012-11-01 08:59:13 PDT
Created attachment 171864 [details]
patch v4

Changed ewk_object_cast semantics, removed all extra macros. Thank you Kenneth and Chris!
Comment 16 Chris Dumez 2012-11-01 09:03:42 PDT
Comment on attachment 171864 [details]
patch v4

Looks better now. Thank you.
Comment 17 Thiago Marcos P. Santos 2012-11-01 09:19:20 PDT
(In reply to comment #7)
> (In reply to comment #6)
> > (From update of attachment 171634 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=171634&action=review
> > 
> > > Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp:89
> > >  static inline void freeEinaList(Eina_List* list)
> > >  {
> > >      void* data = 0;
> > >      EINA_LIST_FREE(list, data)
> > > -        ewk_back_forward_list_item_unref(static_cast<Ewk_Back_Forward_List_Item*>(data));
> > > +        ewk_ref_counted_unref(static_cast<Ewk_Back_Forward_List_Item*>(data));
> > >  }
> > >  
> > >  TEST_F(EWK2UnitTestBase, ewk_back_forward_list_current_item_get)
> > 
> > Would be nice if we could have more unit tests for these functions.
> 
> we will have these functions checked for every ref counted object we have

I would write specific unit tests just for that. WTF has its own unit tests, but some may argue that is tested all around WebKit code.

The point of having separated unit tests is: it will make it easier to isolate a problem, check for leaks, measure performance, etc.
Comment 18 Mikhail Pozdnyakov 2012-11-02 01:31:56 PDT
(In reply to comment #17)
> (In reply to comment #7)
> > (In reply to comment #6)
> > > (From update of attachment 171634 [details] [details] [details])
> > > View in context: https://bugs.webkit.org/attachment.cgi?id=171634&action=review
> > > 
> > > > Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp:89
> > > >  static inline void freeEinaList(Eina_List* list)
> > > >  {
> > > >      void* data = 0;
> > > >      EINA_LIST_FREE(list, data)
> > > > -        ewk_back_forward_list_item_unref(static_cast<Ewk_Back_Forward_List_Item*>(data));
> > > > +        ewk_ref_counted_unref(static_cast<Ewk_Back_Forward_List_Item*>(data));
> > > >  }
> > > >  
> > > >  TEST_F(EWK2UnitTestBase, ewk_back_forward_list_current_item_get)
> > > 
> > > Would be nice if we could have more unit tests for these functions.
> > 
> > we will have these functions checked for every ref counted object we have
> 
> I would write specific unit tests just for that. WTF has its own unit tests, but some may argue that is tested all around WebKit code.
> 
> The point of having separated unit tests is: it will make it easier to isolate a problem, check for leaks, measure performance, etc.

Ewk_Object is abstract class and it cannot live apart from an inherited object , so I guess those inherited objects should be tested including ref/unref functions.
Comment 19 Kenneth Rohde Christiansen 2012-11-02 01:58:20 PDT
Comment on attachment 171864 [details]
patch v4

I think we can do the tests separate from this
Comment 20 WebKit Review Bot 2012-11-02 02:24:51 PDT
Comment on attachment 171864 [details]
patch v4

Clearing flags on attachment: 171864

Committed r133278: <http://trac.webkit.org/changeset/133278>
Comment 21 WebKit Review Bot 2012-11-02 02:24:56 PDT
All reviewed patches have been landed.  Closing bug.
Comment 22 Mikhail Pozdnyakov 2012-11-02 03:15:55 PDT
Bug for unit tests:
https://bugs.webkit.org/show_bug.cgi?id=101037