careful, your last few suggestions became real libs/apis

On Fri, 6 Dec 2013 18:25:50 -0200
Iván Briano <sachi...@gmail.com> wrote:

> EINA_CHECK_IF_THE_POINTER_IS_NULL_AND_IF_NOT_ASSUME_IT_S_NOT_A_STRAY_POINTER_AND_TRY_TO_FREE_IT_WITH_GIVEN_FUNCTION_THEN_SET_THE_POINTER_TO_NULL_TO_AVOID_MISUSAGE_LATER_ON()
> 
> On Fri, Dec 6, 2013 at 6:18 PM, David Seikel <onef...@gmail.com> wrote:
> > On Fri, 6 Dec 2013 17:26:21 -0200 Gustavo Sverzut Barbieri
> > <barbi...@gmail.com> wrote:
> >
> >> On Fri, Dec 6, 2013 at 10:42 AM, David Seikel <onef...@gmail.com>
> >> wrote:
> >> > On Fri, 6 Dec 2013 10:12:09 -0200 Gustavo Sverzut Barbieri
> >> > <barbi...@gmail.com> wrote:
> >> >
> >> >> On Thu, Dec 5, 2013 at 10:23 PM, Daniel Juyung Seo
> >> >> <seojuyu...@gmail.com> wrote:
> >> >> > Dear all, this is Daniel Juyung Seo.
> >> >> >
> >> >> > I propose EFL_SAFE_FREE macro for efl.
> >> >> > It looks like:
> >> >> >
> >> >> >   # define EFL_SAFE_FREE(_h, _fn) do { if (_h) { _fn((void*)_h);
> >> >> > _h = NULL; } } while (0)
> >> >> >
> >> >> > As I have been using ELM_SAFE_FREE for months, I found out that
> >> >> > this macro is quite useful in terms of code readability, reducing
> >> >> > human mistakes, and using much smaller number of lines with the
> >> >> > same functionality.
> >> >> >
> >> >> > Enlightenment has
> >> >> > # define E_FREE_FUNC(_h, _fn) do { if (_h) { _fn((void*)_h); _h =
> >> >> > NULL; } } while (0)
> >> >> >
> >> >> > Elementary has
> >> >> > #define ELM_SAFE_FREE(_h, _fn) do { if (_h) { _fn((void*)_h); _h
> >> >> > = NULL; } } while (0)
> >> >> >
> >> >> > So why not efl?
> >> >> >
> >> >> > By using EFL_SAFE_FREE, this (Old) code will reborn as a (New)
> >> >> > code. 5 lines down to 1 line.
> >> >> > (Old)
> >> >> >    if (svr->until_deletion)
> >> >> >      {
> >> >> >         ecore_timer_del(svr->until_deletion);
> >> >> >         svr->until_deletion = NULL;
> >> >> >      }
> >> >> >
> >> >> > (New)
> >> >> >    EFL_SAFE_FREE(svr->until_deletion, ecore_timer_del);
> >> >>
> >> >> bad name as there is nothing save in it.
> >> >>
> >> >> EINA_FREE_AND_NULL(ptr, freefunc) would be more descriptive, code
> >> >> is the same. Or:
> >> >>
> >> >> EINA_FREE_AND_NULL(ptr) // does free()
> >> >> EINA_DISPOSE_AND_NULL(ptr, disposefunc) // generic version
> >> >>
> >> >> I'm not a native speaker, eventually there is a better name for the
> >> >> second one.
> >> >
> >> > Safe, as in "this is the safe way to do it", nothing to do with
> >> > saving things.
> >>
> >> i know, but what is safe in it? Because it checks for null before
> >> calling the function? If you take libc "free()" this is not required,
> >> so it's no big deal. The set to NULL is also something not always
> >> desired, if you're cleaning up a local variable all tools
> >> (gcc/clang/coverity) will report dead assignment. Tools won't report
> >> but it's also not needed (or desired) if you clean a member of a
> >> struct that is also being deleted.
> >
> > I wasn't commenting on it's safety, just on the difference between the
> > words 'safe' and 'save', since you pointed out you are not a native
> > English speaker.  So your statement "there is nothing save in it" was
> > not relevant if you meant "there is nothing saved in it".  Looks like
> > you meant "there is nothing safe in it".
> >
> > Should be only one of these macros, and it should be at the EINA level,
> > so every one can use it.  Are we stuck with existing API here though?
> >
> > How about EINA_NUKE_FROM_ORBIT, it's the only safe way.  B-)
> >
> > --
> > A big old stinking pile of genius that no one wants
> > coz there are too many silver coated monkeys in the world.

------------------------------------------------------------------------------
Sponsored by Intel(R) XDK 
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to